UploadInfor.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. <template>
  2. <div class="upload_infor">
  3. <form>
  4. <div class="dataName">
  5. <span>资料名称</span
  6. ><input
  7. type="text"
  8. class="inputStyle focusStyle"
  9. v-model="inforName"
  10. @focus="hideTip"
  11. @blur="checkName()"
  12. />
  13. <p v-show="tipFlag">{{ tipText }}</p>
  14. </div>
  15. <div class="inforDes">
  16. <span>资料描述</span
  17. ><textarea
  18. name="inforDes"
  19. cols="40"
  20. rows="4"
  21. class="focusStyle"
  22. v-model="inforDes"
  23. ></textarea>
  24. </div>
  25. <div class="selectType">
  26. <p>选择类型</p>
  27. <div>
  28. <span>素材时间</span>
  29. <input
  30. type="month"
  31. :min="localMonth"
  32. class="inputStyle"
  33. v-model="materialTime"
  34. @change="materialTimeChange"
  35. />
  36. <span style="margin-left: 30px">经销商范围</span>
  37. <select class="selectStyle" v-model="scope" autocomplete="off">
  38. <option value="1">共通</option>
  39. <option value="0">部分</option>
  40. </select>
  41. </div>
  42. </div>
  43. <div v-show="scope === '0'">
  44. <p>权限设置</p>
  45. <div class="addByArea">
  46. <span>按区域添加</span>
  47. <div v-for="(item, index) in areaList" :key="index">
  48. <input
  49. type="checkbox"
  50. :value="item"
  51. v-model="checkedBoxList"
  52. @click="clickCheckbox(index)"
  53. /><span>{{ item }}</span>
  54. </div>
  55. <button @click.prevent="addByArea">添加</button>
  56. </div>
  57. <div class="addByCustomize">
  58. <span>自定义添加</span>
  59. <input
  60. id="dlr"
  61. list="dlrs"
  62. class="inputStyle"
  63. v-model="addByCustomize"
  64. placeholder="DLR Code / 经销商"
  65. />
  66. <datalist id="dlrs">
  67. <option v-for="(item, index) in dlrList" :key="index" :value="item">
  68. {{ item }}
  69. </option>
  70. </datalist>
  71. <button @click.prevent="addBySelf">添加</button>
  72. </div>
  73. <div class="addByGroup">
  74. <span>按小组添加</span>
  75. <div class="selectBox">
  76. <div class="group_select" @click="showOption">
  77. <p>请选择</p>
  78. <img src="../../img/select_arrow.png" />
  79. </div>
  80. <div class="optionBox" v-if="optionFlag">
  81. <ul>
  82. <li v-for="(item, index) in groupList" :key="index">
  83. <p>{{ item.groupName }}</p>
  84. <img
  85. src="../../img/add.png"
  86. @click="addGroup(index)"
  87. v-if="item.flag"
  88. />
  89. <img
  90. src="../../img/delete.png"
  91. @click="deleteGroup(index)"
  92. v-else
  93. />
  94. </li>
  95. </ul>
  96. </div>
  97. </div>
  98. <button @click.prevent="addByGroup">添加</button>
  99. </div>
  100. </div>
  101. </form>
  102. <div v-show="scope === '0'">
  103. <div class="count">
  104. <Count :sum="sum" />
  105. </div>
  106. <div class="table">
  107. <UpLoadTable
  108. :tableData="tableData"
  109. @change_icon="changeIcon"
  110. :pageSize="pageSize"
  111. :currentPage="currentPage"
  112. />
  113. </div>
  114. <div class="page" v-show="sum > 0">
  115. <Tablepage
  116. :totalPage="totalPage"
  117. :currentPage="currentPage"
  118. @change_page="changePage"
  119. @jump_page="jumpPage"
  120. />
  121. </div>
  122. </div>
  123. <div class="uploadFile">
  124. <p>附件</p>
  125. <label for="fileInput" @change="getFileInfo($event)"
  126. >导入<input type="file" name="fileName" id="fileInput" multiple
  127. /></label>
  128. <div class="fileDes">
  129. <p v-for="(item, index) in fileDes" :key="index">{{ item }}</p>
  130. </div>
  131. </div>
  132. <button @click="submit" class="submitBtn">提交</button>
  133. <TipModal
  134. :tipFlag="tipModalFlag"
  135. :tipText="tipModalText"
  136. @close_tip_modal="closeTipModal"
  137. />
  138. </div>
  139. </template>
  140. <script>
  141. import UpLoadTable from "./components/UploadInforTable";
  142. import Count from "../../components/Count";
  143. import Tablepage from "../../components/TablePage";
  144. import TipModal from "../../components/TipModal";
  145. export default {
  146. props: {
  147. isManufacturer: {
  148. type: String,
  149. default: "distributor",
  150. },
  151. },
  152. components: {
  153. UpLoadTable,
  154. Count,
  155. Tablepage,
  156. TipModal,
  157. },
  158. watch: {},
  159. data() {
  160. return {
  161. allDataNameList: [],
  162. tipFlag: false, // 是否展示提示
  163. tipText: "资料名称不能重复,请重新输入",
  164. inforName: "",
  165. inforDes: "",
  166. materialTime: "",
  167. scope: "1", //1为共通 , 0为部分
  168. checkedBoxList: [], // 多选框选中的值
  169. addByCustomize: "",
  170. dlrList: [], // 自定义添加
  171. addGroupList: [], // 添加的小组
  172. optionFlag: false, // 是否展示按小组添加的选择栏
  173. fileDes: [], // 上传的文件名
  174. file: "", //上传的文件
  175. // 表格配置
  176. sum: 0, // 一共有多少条数据
  177. pageSize: 20, // 每页展示的数据
  178. currentPage: 1,
  179. areaList: [], // 按区域添加
  180. groupList: [], // 按小组添加
  181. localMonth: "",
  182. tableData: [], // 表格显示的数据
  183. allDlr: [], // 所有经销商数据
  184. idList: [],
  185. tipModalFlag: false,
  186. tipModalText: "",
  187. };
  188. },
  189. computed: {
  190. // 表格总页数
  191. totalPage() {
  192. return Math.ceil(this.sum / this.pageSize);
  193. },
  194. },
  195. methods: {
  196. // 检查名字是否重复 失去焦点判断
  197. checkName: function () {
  198. let include = this.allDataNameList.indexOf(this.inforName);
  199. if (!this.inforName) {
  200. this.tipText = "资料名不能为空";
  201. this.tipFlag = true;
  202. return;
  203. } else if (include > 0) {
  204. this.tipText = "资料名称不能重复,请重新输入";
  205. this.tipFlag = true;
  206. return;
  207. }
  208. },
  209. // 名字不重复,隐藏提示
  210. hideTip: function () {
  211. this.tipText = "资料名称不能重复,请重新输入";
  212. this.tipFlag = false;
  213. },
  214. // 素材时间变化
  215. materialTimeChange: function () {
  216. // this.materialTime = this.localMonth.replace('-', '/');
  217. console.log(this.materialTime);
  218. },
  219. // 显示隐藏按小组添加下拉框
  220. showOption() {
  221. this.optionFlag = !this.optionFlag;
  222. },
  223. // 保证多选框东区和其他的多选框互斥
  224. clickCheckbox(i) {
  225. let list = this.checkedBoxList;
  226. let include = list.indexOf("东区");
  227. console.log(i, include);
  228. // if (i === 0) {
  229. // this.checkedBoxList = [];
  230. // return;
  231. // }
  232. // if (include >= 0) {
  233. // this.checkedBoxList.splice(0, 1);
  234. // }
  235. },
  236. // 点击按区域添加button
  237. addByArea: function () {
  238. if (this.checkedBoxList.length !== 0) {
  239. let strReq = this.checkedBoxList.join(",");
  240. let req = {
  241. localArea: strReq,
  242. };
  243. this.getAllDlr(req);
  244. }
  245. },
  246. // 自定义添加
  247. addBySelf: function () {
  248. if (this.addByCustomize) {
  249. let dataObj = {
  250. queryParams: this.addByCustomize,
  251. };
  252. this.getAllDlr(dataObj, false, true);
  253. }
  254. },
  255. // 按小组添加,增加小组
  256. addGroup: function (index) {
  257. this.groupList[index].flag = !this.groupList[index].flag;
  258. },
  259. // 按小组添加,删除小组
  260. deleteGroup: function (index) {
  261. this.groupList[index].flag = !this.groupList[index].flag;
  262. },
  263. // 点击按小组添加 添加按钮
  264. addByGroup: function () {
  265. this.addGroupList = [];
  266. this.groupList.forEach((element) => {
  267. if (!element.flag) {
  268. this.addGroupList.push(element.id);
  269. }
  270. });
  271. if (this.addGroupList.length !== 0) {
  272. let strReq = this.addGroupList.join(",");
  273. let req = {
  274. groupId: strReq,
  275. };
  276. this.getAllDlr(req);
  277. this.optionFlag = false;
  278. } else {
  279. alert("没有选择一个或多个小组");
  280. }
  281. },
  282. // 筛选
  283. changeIcon: function (i) {
  284. let index = (this.currentPage - 1) * this.pageSize + i;
  285. this.allDlr[index].flag = !this.allDlr[index].flag;
  286. },
  287. // 选中经销商的id 组成列表
  288. dlrIdList: function () {
  289. this.idList = [];
  290. this.allDlr.forEach((element) => {
  291. if (element.flag) {
  292. this.idList.push(element.id);
  293. }
  294. });
  295. },
  296. // 关闭提示框
  297. closeTipModal: function () {
  298. this.tipModalFlag = false;
  299. this.$router.push({path:'/uploadRecord'});
  300. },
  301. // 获取某一页面的数据,展示在表格
  302. changePage: function (page) {
  303. this.currentPage = page;
  304. this.tableData = this.allDlr.slice(
  305. (this.currentPage - 1) * this.pageSize,
  306. this.currentPage * this.pageSize
  307. );
  308. },
  309. // 点击上一页,下一页,首页,尾页
  310. jumpPage: function (item) {
  311. switch (item) {
  312. case 1:
  313. this.currentPage = 1;
  314. break;
  315. case 2:
  316. this.currentPage = this.currentPage - 1;
  317. break;
  318. case 3:
  319. this.currentPage = this.currentPage + 1;
  320. break;
  321. case 4:
  322. this.currentPage = this.totalPage;
  323. break;
  324. }
  325. this.tableData = this.allDlr.slice(
  326. (this.currentPage - 1) * this.pageSize,
  327. this.currentPage * this.pageSize
  328. );
  329. },
  330. // 点击提交,检查名字是否重复,获取数据
  331. submit: function () {
  332. this.checkName();
  333. if (!this.tipFlag) {
  334. if (!this.inforDes) {
  335. alert("资料描述不能为空");
  336. return;
  337. }
  338. if (!this.materialTime) {
  339. alert("素材时间不能为空");
  340. return;
  341. }
  342. if (!this.file) {
  343. alert("请导入附件");
  344. return;
  345. }
  346. this.dlrIdList();
  347. this.submitRequest();
  348. }
  349. },
  350. // 获取文件名
  351. getFileInfo: function (event) {
  352. this.file = event.target.files;
  353. console.log(this.file);
  354. this.fileDes = [];
  355. this.file.forEach((item) => {
  356. this.fileDes.push(item.name);
  357. });
  358. },
  359. // 获取当前的月份
  360. getLocalMonth: function () {
  361. let data = new Date();
  362. let year = data.getFullYear();
  363. let month = data.getMonth() + 1;
  364. if (month < 10) {
  365. month = "0" + month;
  366. } else {
  367. month = month + "";
  368. }
  369. this.localMonth = year + "-" + month;
  370. },
  371. // 提交接口
  372. submitRequest: function () {
  373. let paramData = new FormData();
  374. this.file.forEach((item) => {
  375. paramData.append("file", item);
  376. });
  377. paramData.append("dataName", this.inforName);
  378. paramData.append("dataDesc", this.inforDes);
  379. paramData.append("sourceTime", this.materialTime);
  380. paramData.append("dealerScope", this.scope);
  381. console.log(this.scope, 111);
  382. if (this.scope === "0") {
  383. paramData.append("dealerList", this.idList);
  384. console.log(1111, this.idList);
  385. }
  386. console.log(paramData.getAll("dataName"));
  387. this.$http
  388. .uploadFile("/firmsUpload", paramData)
  389. .then((res) => {
  390. if (res.data && res.data.code === 200) {
  391. this.tipModalFlag = true;
  392. this.tipModalText = "上传成功!";
  393. } else {
  394. alert("上传失败,请重试");
  395. console.log(res);
  396. }
  397. })
  398. .catch((err) => {
  399. alert("上传失败,请重试");
  400. console.log(err);
  401. });
  402. },
  403. // 获取所有资料名称
  404. getAllDataName: function () {
  405. this.$http({
  406. method: "post",
  407. url: "/firmsUploadList",
  408. })
  409. .then((res) => {
  410. if (res.data && res.data.code === 200) {
  411. (this.allDataNameList = []),
  412. res.data.data.forEach((item) => {
  413. this.allDataNameList.push(item.informationName);
  414. });
  415. } else {
  416. console.log(res);
  417. }
  418. })
  419. .catch((err) => {
  420. console.log(err);
  421. });
  422. },
  423. // 获取所有经销商信息接口
  424. getAllDlr: function (data = {}, flag, addBySelfFlag) {
  425. this.$http({
  426. method: "post",
  427. url: "/sys/agent/selectAgentInfoPage",
  428. data: data,
  429. })
  430. .then((res) => {
  431. console.log(res);
  432. this.tableData = [];
  433. let nowSum = this.sum;
  434. if (res.data && res.data.code === 200) {
  435. // created时,获取自定义添加datalist下拉框的值
  436. if (flag) {
  437. this.dlrList = [];
  438. let allDlrList = res.data.data;
  439. allDlrList.forEach((item) => {
  440. this.dlrList.push(item.dlrName);
  441. this.dlrList.push(item.dlrCode);
  442. });
  443. } else {
  444. // 整合数据, 主要目的是加一个 flag,在用户点击筛选的时候,好判断
  445. res.data.data.forEach((item) => {
  446. this.allDlr.push({
  447. id: item.id,
  448. dlrCode: item.dlrCode,
  449. dlrName: item.dlrName,
  450. localArea: item.localArea,
  451. flag: true,
  452. });
  453. });
  454. // 去重
  455. let hash = {};
  456. this.allDlr = this.allDlr.reduce(function (item, next) {
  457. hash[next.id] ? "" : (hash[next.id] = true && item.push(next));
  458. return item;
  459. }, []);
  460. this.sum = this.allDlr.length;
  461. // 添加以后跳到最后一页
  462. this.currentPage = this.totalPage;
  463. let startData = (this.currentPage - 1) * this.pageSize;
  464. let endData = this.currentPage * this.pageSize;
  465. this.tableData = this.allDlr.slice(startData, endData);
  466. // 自定义添加 提示
  467. let include = this.dlrList.indexOf(this.addByCustomize);
  468. if (include < 0 && addBySelfFlag) {
  469. alert('没有找到该经销商');
  470. return
  471. }
  472. if (this.sum === nowSum && addBySelfFlag) {
  473. alert("该经销商已在列表中,不用重复添加");
  474. return
  475. }
  476. }
  477. } else {
  478. console.log(res);
  479. }
  480. })
  481. .catch((err) => {
  482. console.log(err);
  483. });
  484. },
  485. // 获取小组接口
  486. selectGroupList: function () {
  487. this.$http({
  488. method: "post",
  489. url: "/sys/group/selectGroupList",
  490. data: {},
  491. })
  492. .then((res) => {
  493. if (res.data && res.data.code === 200) {
  494. this.groupList = [];
  495. res.data.data.forEach((item) => {
  496. this.groupList.push({
  497. id: item.id,
  498. groupName: item.groupName,
  499. flag: true,
  500. });
  501. });
  502. } else {
  503. console.log(res);
  504. }
  505. })
  506. .catch((err) => {
  507. console.log(err);
  508. });
  509. },
  510. // 获取 所有区域 接口
  511. getAreaList: function () {
  512. this.$http({
  513. method: "post",
  514. url: "/sys/agent/selectAgentAreaInfoList",
  515. })
  516. .then((res) => {
  517. if (res.data && res.data.code === 200) {
  518. this.areaList = res.data.data;
  519. } else {
  520. console.log(res);
  521. }
  522. })
  523. .catch((err) => {
  524. console.log(err);
  525. });
  526. },
  527. },
  528. mounted() {
  529. this.getLocalMonth();
  530. },
  531. created() {
  532. // if (this.isManufacturer === 'distributor') {
  533. // this.$router.replace({ path: "/inforList" });
  534. // }
  535. this.getAllDlr({}, true);
  536. this.getAllDataName();
  537. this.selectGroupList();
  538. this.getAreaList();
  539. },
  540. beforeCreate() {
  541. }
  542. };
  543. </script>
  544. <style scoped lang="less">
  545. .upload_infor {
  546. form {
  547. border: 1px solid #ccc;
  548. padding: 10px;
  549. }
  550. .dataName {
  551. p {
  552. margin-left: 65px;
  553. font-size: 10px;
  554. color: rgb(206, 84, 84);
  555. }
  556. }
  557. .inforDes {
  558. margin: 10px 0 0 0;
  559. span {
  560. vertical-align: top;
  561. margin-right: 17px;
  562. }
  563. textarea {
  564. border: 1px solid #ccc;
  565. border-radius: 3px;
  566. color: #555555;
  567. font-size: 12px;
  568. }
  569. }
  570. .selectType {
  571. margin-top: 10px;
  572. margin-bottom: 10px;
  573. div {
  574. margin-left: 65px;
  575. }
  576. }
  577. .selectStyle {
  578. margin-left: 20px;
  579. margin-right: 20px;
  580. padding: 4px 6px;
  581. height: 28px;
  582. width: 144px;
  583. border: 1px solid #ccc;
  584. color: #555555;
  585. font-size: 12px;
  586. }
  587. .addByArea {
  588. margin: 10px 0 0 65px;
  589. display: flex;
  590. height: 28px;
  591. align-items: center;
  592. span {
  593. margin-right: 10px;
  594. }
  595. div {
  596. margin-right: 18px;
  597. height: 18px;
  598. input {
  599. width: 12px;
  600. height: 12px;
  601. vertical-align: middle;
  602. margin-top: -2px;
  603. border: 1px solid #ccc;
  604. }
  605. span {
  606. margin-left: 2px;
  607. height: 18px;
  608. line-height: 18px;
  609. }
  610. }
  611. button {
  612. height: 28px;
  613. }
  614. }
  615. .addByCustomize {
  616. margin: 10px 0 0 65px;
  617. button {
  618. height: 28px;
  619. }
  620. input {
  621. // background: url('../../img/search.svg') no-repeat center left;
  622. // background-size: 21px 25px;
  623. background-color: #fff;
  624. }
  625. }
  626. .addByGroup {
  627. margin: 10px 0 0 65px;
  628. display: flex;
  629. align-items: center;
  630. .selectBox {
  631. position: relative;
  632. margin-left: 17px;
  633. .group_select {
  634. width: 124px;
  635. height: 28px;
  636. border: 1px solid #ccc;
  637. background-color: #fff;
  638. padding: 0 10px;
  639. display: flex;
  640. justify-content: space-between;
  641. align-items: center;
  642. p {
  643. font-size: 12px;
  644. height: 28px;
  645. line-height: 28px;
  646. color: #555555;
  647. }
  648. img {
  649. width: 16px;
  650. height: 16px;
  651. }
  652. &:hover {
  653. cursor: pointer;
  654. }
  655. }
  656. img {
  657. width: 144px;
  658. height: 28px;
  659. &:hover {
  660. cursor: pointer;
  661. }
  662. }
  663. .optionBox {
  664. position: absolute;
  665. top: 28px;
  666. left: 0;
  667. border: 1px solid #ccc;
  668. border-top: none;
  669. width: 142px;
  670. background-color: #fff;
  671. border-radius: 5px;
  672. ul {
  673. width: 144px;
  674. padding-bottom: 6px;
  675. display: flex;
  676. flex-direction: column;
  677. align-items: center;
  678. li {
  679. width: 132px;
  680. height: 28px;
  681. font-size: 12px;
  682. color: #555555;
  683. display: flex;
  684. align-items: center;
  685. border-bottom: 1px solid #ccc;
  686. display: flex;
  687. justify-content: space-between;
  688. padding-right: 5px;
  689. img {
  690. width: 20px;
  691. height: 20px;
  692. &:hover {
  693. cursor: pointer;
  694. }
  695. }
  696. }
  697. }
  698. }
  699. }
  700. button {
  701. height: 28px;
  702. }
  703. }
  704. .table {
  705. margin-top: 10px;
  706. }
  707. .count {
  708. display: flex;
  709. justify-content: flex-end;
  710. }
  711. .uploadFile {
  712. display: flex;
  713. margin-top: 35px;
  714. height: 30px;
  715. align-items: center;
  716. p {
  717. margin-right: 20px;
  718. height: 20px;
  719. line-height: 20px;
  720. }
  721. .fileDes {
  722. margin-left: 20px;
  723. width: 500px;
  724. overflow: hidden;
  725. overflow: hidden; /* 超出一行文字自动隐藏 */
  726. text-overflow: ellipsis; /* 文字隐藏后添加省略号 */
  727. white-space: nowrap; /* 强制不换行 */
  728. }
  729. label {
  730. height: 30px;
  731. line-height: 30px;
  732. width: 56px;
  733. background-color: #0056a0;
  734. color: #fff;
  735. text-align: center;
  736. font-size: 14px;
  737. input {
  738. display: none;
  739. }
  740. }
  741. }
  742. .submitBtn {
  743. margin-top: 50px;
  744. }
  745. }
  746. .inputStyle {
  747. margin-left: 17px;
  748. width: 130px;
  749. height: 18px;
  750. line-height: 18px;
  751. padding: 4px 6px;
  752. border: 1px solid #ccc;
  753. color: #555555;
  754. font-size: 12px;
  755. }
  756. .focusStyle {
  757. border: 1px solid #ccc;
  758. line-height: 20px;
  759. color: #555555;
  760. outline: none;
  761. }
  762. .focusStyle:focus {
  763. animation: shadowAni 200ms linear forwards;
  764. }
  765. @keyframes shadowAni {
  766. 0% {
  767. border-color: #cccccc;
  768. box-shadow: inset 0px 0px 0 #ccc;
  769. }
  770. 100% {
  771. border-color: #75b9f0;
  772. box-shadow: 0px 0px 10px #75b9f0;
  773. }
  774. }
  775. </style>