UploadInfor.vue 20 KB

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