UploadInfor.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. this.getAllDlr({}, true);
  532. this.getAllDataName();
  533. this.selectGroupList();
  534. this.getAreaList();
  535. },
  536. };
  537. </script>
  538. <style scoped lang="less">
  539. .upload_infor {
  540. form {
  541. border: 1px solid #ccc;
  542. padding: 10px;
  543. }
  544. .dataName {
  545. p {
  546. margin-left: 65px;
  547. font-size: 10px;
  548. color: rgb(206, 84, 84);
  549. }
  550. }
  551. .inforDes {
  552. margin: 10px 0 0 0;
  553. span {
  554. vertical-align: top;
  555. margin-right: 17px;
  556. }
  557. textarea {
  558. border: 1px solid #ccc;
  559. border-radius: 3px;
  560. color: #555555;
  561. font-size: 12px;
  562. }
  563. }
  564. .selectType {
  565. margin-top: 10px;
  566. margin-bottom: 10px;
  567. div {
  568. margin-left: 65px;
  569. }
  570. }
  571. .selectStyle {
  572. margin-left: 20px;
  573. margin-right: 20px;
  574. padding: 4px 6px;
  575. height: 28px;
  576. width: 144px;
  577. border: 1px solid #ccc;
  578. color: #555555;
  579. font-size: 12px;
  580. }
  581. .addByArea {
  582. margin: 10px 0 0 65px;
  583. display: flex;
  584. height: 28px;
  585. align-items: center;
  586. span {
  587. margin-right: 10px;
  588. }
  589. div {
  590. margin-right: 18px;
  591. height: 18px;
  592. input {
  593. width: 12px;
  594. height: 12px;
  595. vertical-align: middle;
  596. margin-top: -2px;
  597. border: 1px solid #ccc;
  598. }
  599. span {
  600. margin-left: 2px;
  601. height: 18px;
  602. line-height: 18px;
  603. }
  604. }
  605. button {
  606. height: 28px;
  607. }
  608. }
  609. .addByCustomize {
  610. margin: 10px 0 0 65px;
  611. button {
  612. height: 28px;
  613. }
  614. input {
  615. // background: url('../../img/search.svg') no-repeat center left;
  616. // background-size: 21px 25px;
  617. background-color: #fff;
  618. }
  619. }
  620. .addByGroup {
  621. margin: 10px 0 0 65px;
  622. display: flex;
  623. align-items: center;
  624. .selectBox {
  625. position: relative;
  626. margin-left: 17px;
  627. .group_select {
  628. width: 124px;
  629. height: 28px;
  630. border: 1px solid #ccc;
  631. background-color: #fff;
  632. padding: 0 10px;
  633. display: flex;
  634. justify-content: space-between;
  635. align-items: center;
  636. p {
  637. font-size: 12px;
  638. height: 28px;
  639. line-height: 28px;
  640. color: #555555;
  641. }
  642. img {
  643. width: 16px;
  644. height: 16px;
  645. }
  646. &:hover {
  647. cursor: pointer;
  648. }
  649. }
  650. img {
  651. width: 144px;
  652. height: 28px;
  653. &:hover {
  654. cursor: pointer;
  655. }
  656. }
  657. .optionBox {
  658. position: absolute;
  659. top: 28px;
  660. left: 0;
  661. border: 1px solid #ccc;
  662. border-top: none;
  663. width: 142px;
  664. background-color: #fff;
  665. border-radius: 5px;
  666. ul {
  667. width: 144px;
  668. padding-bottom: 6px;
  669. display: flex;
  670. flex-direction: column;
  671. align-items: center;
  672. li {
  673. width: 132px;
  674. height: 28px;
  675. font-size: 12px;
  676. color: #555555;
  677. display: flex;
  678. align-items: center;
  679. border-bottom: 1px solid #ccc;
  680. display: flex;
  681. justify-content: space-between;
  682. padding-right: 5px;
  683. img {
  684. width: 20px;
  685. height: 20px;
  686. &:hover {
  687. cursor: pointer;
  688. }
  689. }
  690. }
  691. }
  692. }
  693. }
  694. button {
  695. height: 28px;
  696. }
  697. }
  698. .table {
  699. margin-top: 10px;
  700. }
  701. .count {
  702. display: flex;
  703. justify-content: flex-end;
  704. }
  705. .uploadFile {
  706. display: flex;
  707. margin-top: 35px;
  708. height: 30px;
  709. align-items: center;
  710. p {
  711. margin-right: 20px;
  712. height: 20px;
  713. line-height: 20px;
  714. }
  715. .fileDes {
  716. margin-left: 20px;
  717. width: 500px;
  718. overflow: hidden;
  719. overflow: hidden; /* 超出一行文字自动隐藏 */
  720. text-overflow: ellipsis; /* 文字隐藏后添加省略号 */
  721. white-space: nowrap; /* 强制不换行 */
  722. }
  723. label {
  724. height: 30px;
  725. line-height: 30px;
  726. width: 56px;
  727. background-color: #0056a0;
  728. color: #fff;
  729. text-align: center;
  730. font-size: 14px;
  731. input {
  732. display: none;
  733. }
  734. }
  735. }
  736. .submitBtn {
  737. margin-top: 50px;
  738. }
  739. }
  740. .inputStyle {
  741. margin-left: 17px;
  742. width: 130px;
  743. height: 18px;
  744. line-height: 18px;
  745. padding: 4px 6px;
  746. border: 1px solid #ccc;
  747. color: #555555;
  748. font-size: 12px;
  749. }
  750. .focusStyle {
  751. border: 1px solid #ccc;
  752. line-height: 20px;
  753. color: #555555;
  754. outline: none;
  755. }
  756. .focusStyle:focus {
  757. animation: shadowAni 200ms linear forwards;
  758. }
  759. @keyframes shadowAni {
  760. 0% {
  761. border-color: #cccccc;
  762. box-shadow: inset 0px 0px 0 #ccc;
  763. }
  764. 100% {
  765. border-color: #75b9f0;
  766. box-shadow: 0px 0px 10px #75b9f0;
  767. }
  768. }
  769. </style>