UploadInfor.vue 17 KB

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