index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <template>
  2. <div>
  3. <FullPage
  4. title="工艺路线"
  5. :list="list"
  6. @init="init"
  7. :loading="loading"
  8. @searchData="init"
  9. @changePage="changePage"
  10. @changeSize="changeSize"
  11. :tableColums="tableColums"
  12. :tableData="tableData"
  13. :pageIndex="pageIndex"
  14. :total="total"
  15. >
  16. <div slot="titleButton" style="display: flex">
  17. <Upload
  18. name="your_file"
  19. :show-upload-list="false"
  20. :headers="headers"
  21. :on-error="uploadError"
  22. :on-success="uploadSuccess"
  23. :action="$store.state.ip + '/api/process_route_index_import'"
  24. >
  25. <Button type="success" ghost icon="md-exit" style="margin-right: 10px"
  26. >批量导入</Button
  27. >
  28. </Upload>
  29. <Button
  30. @click="exportData"
  31. type="warning"
  32. ghost
  33. icon="md-return-left"
  34. style="margin-right: 10px"
  35. >批量导出</Button
  36. >
  37. <Button @click="handleAddPL()" type="primary" ghost icon="md-add"
  38. >新增工艺路线</Button
  39. >
  40. </div>
  41. <div slot="navButton"></div>
  42. <template slot="set" slot-scope="{ row, index }">
  43. <div class="table-set">
  44. <a style="margin: 0 5px" @click="handleSet(row, index, 1)">复制</a>
  45. <a style="margin: 0 5px" @click="handleSet(row, index, 2)">编辑</a>
  46. <a style="margin: 0 5px" @click="handleSet(row, index, 3)">查看</a>
  47. <a style="margin: 0 5px; color: red" @click="handleSet(row, index, 4)"
  48. >删除</a
  49. >
  50. </div>
  51. </template>
  52. </FullPage>
  53. <Modal
  54. class-name="vertical-center-modal"
  55. width="80%"
  56. v-model="showModal"
  57. :mask-closable="false"
  58. :title="
  59. isAdd
  60. ? '工艺路线新增'
  61. : isCheck
  62. ? '工艺路线详情'
  63. : isCopy
  64. ? '工艺路线复制'
  65. : '工艺路线编辑'
  66. "
  67. >
  68. <div class="modal_process_route">
  69. <div>
  70. <span style="width: 100px">id: </span
  71. ><Input
  72. v-model="info.id"
  73. disabled
  74. placeholder="自动生成"
  75. style="width: 150px"
  76. size="small"
  77. />
  78. </div>
  79. <div>
  80. <span style="width: 100px">工艺路线名称: </span
  81. ><Input
  82. v-model="info.title"
  83. placeholder="请输入工艺路线名称"
  84. size="small"
  85. :disabled="isCheck"
  86. style="width: 250px"
  87. />
  88. </div>
  89. </div>
  90. <div class="modal_content">
  91. <div class="modal_content_left">
  92. <span>已选:</span>
  93. <SlickList
  94. :distance="10"
  95. :lockToContainerEdges="true"
  96. axis="x,y,xy"
  97. lockAxis="xy"
  98. v-model="selectTags"
  99. class="SortableList"
  100. @input="getChangeLists"
  101. >
  102. <SlickItem
  103. style="z-index: 9999"
  104. v-for="(item, key) of selectTags"
  105. :key="key"
  106. class="SortableItem"
  107. :index="key"
  108. >
  109. <Tooltip>
  110. <div slot="content">
  111. <p>工时:{{ item.time }}</p>
  112. <p>工价:{{ item.wages }}</p>
  113. <p>产能:{{ item.capacity }}</p>
  114. </div>
  115. <div class="tag-modal">
  116. <div class="before">{{ key + 1 }}</div>
  117. <Tag
  118. @on-close="closeTag(key, selectTags, item)"
  119. color="primary"
  120. type="border"
  121. closable
  122. >{{ item.title }}</Tag
  123. >
  124. </div>
  125. </Tooltip>
  126. </SlickItem>
  127. </SlickList>
  128. </div>
  129. <div class="modal_content_right">
  130. <div v-for="(item, index) of info.bps" :key="index">
  131. <div v-if="item.cld && item.cld.length > 0">
  132. <span style="font-weight:bold">{{ item.title }}</span>
  133. <div
  134. style="display: flex;justify-content: flex-start;flex-wrap: wrap;"
  135. >
  136. <div
  137. v-for="(_item, _index) in item.cld"
  138. :key="_index"
  139. :style="
  140. _item.p_id
  141. ? [{ 'margin-left': '10px' }]
  142. : [{ 'margin-left': '10px' }, { width: '100%' }]
  143. "
  144. >
  145. <div v-if="_item.cld && _item.cld.length > 0">
  146. <div>
  147. <div style="font-weight:bold;width:100%">
  148. {{ _item.title }}:
  149. </div>
  150. <div
  151. style="display: flex;justify-content: flex-start;flex-wrap: wrap;"
  152. >
  153. <div
  154. v-for="(__item, __index) in _item.cld"
  155. :key="__index"
  156. :style="
  157. __item.p_id
  158. ? [{ 'margin-left': '10px' }]
  159. : [{ 'margin-left': '10px' }, { width: '100%' }]
  160. "
  161. >
  162. <div v-if="__item.cld && __item.cld.length > 0">
  163. <span style="font-weight:bold"
  164. >{{ __item.title }}:</span
  165. >
  166. <div
  167. style="display: flex;justify-content: flex-start;flex-wrap: wrap;"
  168. >
  169. <Tooltip
  170. v-for="(___item, ___index) of __item.cld"
  171. :key="___index"
  172. >
  173. <div slot="content">
  174. <p>工时:{{ ___item.time }}</p>
  175. <p>工价:{{ ___item.wages }}</p>
  176. <p>产能:{{ ___item.capacity }}</p>
  177. </div>
  178. <Checkbox
  179. @on-change="
  180. changeCheck($event, ___item, selectTags)
  181. "
  182. v-model="___item.show"
  183. :disabled="isCheck"
  184. style="padding: 0px 5px"
  185. >{{ ___item.title }}</Checkbox
  186. >
  187. </Tooltip>
  188. </div>
  189. </div>
  190. <div v-else>
  191. <Tooltip v-if="__item.p_id">
  192. <div slot="content">
  193. <p>工时:{{ __item.time }}</p>
  194. <p>工价:{{ __item.wages }}</p>
  195. <p>产能:{{ __item.capacity }}</p>
  196. </div>
  197. <Checkbox
  198. @on-change="
  199. changeCheck($event, __item, selectTags)
  200. "
  201. v-model="__item.show"
  202. :disabled="isCheck"
  203. style="padding: 0px 5px"
  204. >{{ __item.title }}</Checkbox
  205. >
  206. </Tooltip>
  207. </div>
  208. </div>
  209. </div>
  210. </div>
  211. </div>
  212. <div v-else>
  213. <Tooltip v-if="_item.p_id">
  214. <div slot="content">
  215. <p>工时:{{ _item.time }}</p>
  216. <p>工价:{{ _item.wages }}</p>
  217. <p>产能:{{ _item.capacity }}</p>
  218. </div>
  219. <Checkbox
  220. @on-change="changeCheck($event, _item, selectTags)"
  221. v-model="_item.show"
  222. :disabled="isCheck"
  223. style="padding: 0px 5px"
  224. >{{ _item.title }}</Checkbox
  225. >
  226. </Tooltip>
  227. <!-- <span v-else>{{ _item.title }}</span> -->
  228. </div>
  229. </div>
  230. </div>
  231. </div>
  232. <!-- <div v-else>{{ item.title }}</div> -->
  233. </div>
  234. </div>
  235. </div>
  236. <div slot="footer">
  237. <Button @click="showModal = false" type="primary" ghost>取消</Button>
  238. <Button @click="saveTableData()" v-show="!isCheck" type="primary"
  239. >确定</Button
  240. >
  241. </div>
  242. </Modal>
  243. </div>
  244. </template>
  245. <script>
  246. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  247. // 例如:import 《组件名称》 from '《组件路径》';
  248. import { mapState } from "vuex";
  249. import { SlickList, SlickItem } from "vue-slicksort";
  250. export default {
  251. name: "ProcessLine",
  252. components: {
  253. SlickList,
  254. SlickItem,
  255. },
  256. props: {},
  257. // import引入的组件需要注入到对象中才能使用
  258. data() {
  259. // 这里存放数据
  260. return {
  261. list: [
  262. {
  263. title: "工艺路线名称",
  264. name: "Input",
  265. value: "",
  266. serverName: "title",
  267. placeholder: "请输入工艺路线名称",
  268. },
  269. ],
  270. tableColums: [
  271. {
  272. title: "序号",
  273. type: "index",
  274. align: "center",
  275. key: "id",
  276. width: "100",
  277. },
  278. { title: "工艺路线名称", align: "center", key: "title" },
  279. { title: "操作", align: "center", slot: "set", width: "220" },
  280. ],
  281. tableData: [],
  282. pageIndex: 1,
  283. total: 0,
  284. pageSize: 10,
  285. proxyObj: {},
  286. loading: false,
  287. showModal: false,
  288. processRouteId: "",
  289. processRouteName: "",
  290. selectTags: [], //已选列表
  291. headers: { Authorization: localStorage.getItem("token") },
  292. info: {
  293. title: "",
  294. price: "",
  295. parts_id: "",
  296. id: null,
  297. properties: [], //工序号
  298. procedure: [], //工艺属性id
  299. list: [],
  300. bps: [],
  301. procedure_id: "",
  302. },
  303. isCheck: false,
  304. isAdd: false,
  305. isCopy: false,
  306. };
  307. },
  308. // 生命周期 - 创建完成(可以访问当前this实例)
  309. created() {},
  310. // 生命周期 - 挂载完成(可以访问DOM元素)
  311. mounted() {
  312. this.axios("/api/bp_list").then((res) => {
  313. this.info.bps = res.data;
  314. });
  315. this.axios("/api/bpp_list").then((res) => {
  316. res.data.map((v) => {
  317. if (v.select) {
  318. v.cld.map((z) => {
  319. v.select.map((k) => {
  320. z.show = k == z.id ? true : false;
  321. });
  322. });
  323. } else {
  324. v.cld.map((v) => (v.show = false));
  325. }
  326. });
  327. this.info.list = res.data;
  328. });
  329. },
  330. methods: {
  331. handleAddPL() {
  332. this.isCheck = false;
  333. this.isAdd = true;
  334. this.info.id = "";
  335. this.info.title = "";
  336. this.info.procedure_id = "";
  337. this.selectTags = [];
  338. for (const key in this.info.bps) {
  339. const element = this.info.bps[key];
  340. element.cld &&
  341. element.cld.length > 0 &&
  342. element.cld.forEach((z) => {
  343. z.show = false;
  344. z.cld &&
  345. z.cld.length > 0 &&
  346. z.cld.forEach((elem) => {
  347. elem.show = false;
  348. elem.cld &&
  349. elem.cld.length > 0 &&
  350. elem.cld.forEach((el) => {
  351. el.show = false;
  352. });
  353. });
  354. });
  355. }
  356. this.showModal = true;
  357. },
  358. //1复制 2编辑 3查看 4删除
  359. handleSet(row, index, type) {
  360. this.isAdd = false;
  361. this.info.id = row.id;
  362. this.info.title = row.title;
  363. this.info.procedure_id = row.procedure_id;
  364. this.selectTags = [];
  365. const arr = this.info.procedure_id
  366. ? this.info.procedure_id.split(",")
  367. : [];
  368. for (const key in this.info.bps) {
  369. const el = this.info.bps[key];
  370. el.cld.forEach((z) => {
  371. z.show = false;
  372. z.cld &&
  373. z.cld.length > 0 &&
  374. z.cld.forEach((elem) => {
  375. elem.show = false;
  376. elem.cld &&
  377. elem.cld.length > 0 &&
  378. elem.cld.forEach((ele) => {
  379. ele.show = false;
  380. });
  381. });
  382. });
  383. }
  384. this.$nextTick(() => {
  385. arr.forEach((element) => {
  386. for (const key in this.info.bps) {
  387. const el = this.info.bps[key];
  388. for (const k in el.cld) {
  389. const e = el.cld[k];
  390. if (e.id == element) {
  391. e.show = true;
  392. e.p_id && this.selectTags.push(e);
  393. }
  394. e.cld &&
  395. e.cld.length > 0 &&
  396. e.cld.forEach((z) => {
  397. if (z.id == element) {
  398. z.show = true;
  399. z.p_id && this.selectTags.push(z);
  400. }
  401. z.cld &&
  402. z.cld.length > 0 &&
  403. z.cld.forEach((elem) => {
  404. if (elem.id == element) {
  405. elem.show = true;
  406. elem.p_id && this.selectTags.push(elem);
  407. }
  408. elem.cld &&
  409. elem.cld.length > 0 &&
  410. elem.cld.forEach((ele) => {
  411. if (ele.id == element) {
  412. ele.show = true;
  413. ele.p_id && this.selectTags.push(ele);
  414. }
  415. });
  416. });
  417. });
  418. }
  419. }
  420. });
  421. this.isCopy = false;
  422. switch (type) {
  423. case 1:
  424. this.showModal = true;
  425. this.isCopy = true;
  426. break;
  427. case 2:
  428. this.showModal = true;
  429. this.isCheck = false;
  430. break;
  431. case 3:
  432. this.showModal = true;
  433. this.isCheck = true;
  434. break;
  435. case 4:
  436. this.$Modal.confirm({
  437. title: "确认删除?",
  438. content: "此操作确认后不可恢复,请确认!",
  439. onOk: () => {
  440. this.axios({
  441. method: "post",
  442. url: "/api/technological_route_del",
  443. data: {
  444. id: row.id,
  445. },
  446. }).then((res) => {
  447. if (res.code == 200) {
  448. this.$Message.success(res.msg);
  449. this.showModal = false;
  450. this.getData(this.proxyObj);
  451. }
  452. });
  453. },
  454. onCancel: () => (this.showModal = false),
  455. });
  456. break;
  457. }
  458. });
  459. },
  460. init(row) {
  461. this.pageIndex = 1;
  462. row.page_index = this.pageIndex;
  463. row.page_size = this.pageSize;
  464. this.proxyObj = row;
  465. this.getData(row);
  466. },
  467. getData(row) {
  468. this.loading = true;
  469. this.axios("/api/technological_route", { params: row }).then((res) => {
  470. if (res.code == 200) {
  471. if (res.data.data.length == 0 && this.proxyObj.page_index > 1) {
  472. this.proxyObj.page_index--;
  473. this.getData(this.proxyObj);
  474. }
  475. this.loading = false;
  476. this.tableData = res.data.data;
  477. this.total = res.data.total;
  478. }
  479. });
  480. },
  481. getChangeLists(e) {},
  482. saveTableData() {
  483. // this.tableData = JSON.parse(JSON.stringify(this.selectTags));
  484. let temparr = [];
  485. this.selectTags.forEach((el) => {
  486. temparr.push(el.id);
  487. });
  488. this.axios({
  489. method: "post",
  490. url: "/api/technological_route_edit",
  491. data: {
  492. id: this.isCopy ? "" : this.info.id,
  493. title: this.info.title,
  494. procedure_id: temparr.join(","),
  495. },
  496. }).then((res) => {
  497. if (res.code == 200) {
  498. this.$Message.success(res.msg);
  499. this.init(this.proxyObj);
  500. this.showModal = false;
  501. }
  502. });
  503. },
  504. closeTag(key, arr, row) {
  505. //取消tag标签展示操作并同步下方的复选框ui同步
  506. if (!this.isCheck) {
  507. for (const key in this.info.bps) {
  508. const element = this.info.bps[key];
  509. element.cld.map((p) => {
  510. p.id == row.id ? (p.show = false) : "";
  511. p.cld &&
  512. p.cld.length > 0 &&
  513. p.cld.map((q) => {
  514. q.id == row.id ? (q.show = false) : "";
  515. q.cld &&
  516. q.cld.length > 0 &&
  517. q.cld.map((r) => {
  518. r.id == row.id ? (r.show = false) : "";
  519. r.cld &&
  520. r.cld.length > 0 &&
  521. r.cld.map((s) => {
  522. s.id == row.id ? (s.show = false) : "";
  523. });
  524. });
  525. });
  526. });
  527. }
  528. arr.splice(key, 1);
  529. return;
  530. }
  531. },
  532. changeCheck(e, item, selectArray) {
  533. //复选框选中与非选中同时同步tag标签跟随操作
  534. item.show = e;
  535. if (e) {
  536. selectArray.push(item);
  537. } else {
  538. let id = item.id;
  539. let id_index = selectArray.findIndex((v) => v.id == id);
  540. selectArray.splice(id_index, 1);
  541. }
  542. let temparr = [];
  543. this.selectTags.forEach((el) => {
  544. temparr.push(el.id);
  545. });
  546. },
  547. changePage(e) {
  548. this.pageIndex = e;
  549. this.proxyObj.page_index = this.pageIndex;
  550. this.getData(this.proxyObj);
  551. },
  552. changeSize(e) {
  553. this.pageSize = e;
  554. this.proxyObj.page_size = this.pageSize;
  555. this.getData(this.proxyObj);
  556. },
  557. async exportData() {
  558. const res = await this.axios("/api/process_route_export", {
  559. params: { ...this.proxyObj, page: 0 },
  560. });
  561. if (res.code == 200) {
  562. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`;
  563. location.href = url;
  564. }
  565. },
  566. uploadSuccess(res) {
  567. if (res.code == 200) {
  568. this.$Message.success(res.msg || "上传成功");
  569. } else {
  570. this.$Message.warning(res.msg || "上传失败");
  571. }
  572. this.getData(this.proxyObj);
  573. },
  574. uploadError(err) {
  575. this.$Message.error(err.msg || "上传失败");
  576. },
  577. },
  578. // 监听属性 类似于data概念
  579. computed: {
  580. ...mapState(["persimissionData"]),
  581. },
  582. // 监控data中的数据变化
  583. watch: {},
  584. beforeCreate() {}, // 生命周期 - 创建之前
  585. beforeMount() {}, // 生命周期 - 挂载之前
  586. beforeUpdate() {}, // 生命周期 - 更新之前
  587. updated() {}, // 生命周期 - 更新之后
  588. beforeDestroy() {}, // 生命周期 - 销毁之前
  589. destroyed() {}, // 生命周期 - 销毁完成
  590. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  591. };
  592. </script>
  593. <style lang="scss" scoped>
  594. .vertical-center-modal {
  595. display: flex;
  596. align-items: center;
  597. justify-content: center;
  598. .ivu-modal {
  599. top: 0;
  600. }
  601. }
  602. .modal_process_route {
  603. // div {
  604. display: flex;
  605. justify-content: space-around;
  606. align-items: center;
  607. margin: 5px 0;
  608. // }
  609. }
  610. .modal_content {
  611. display: flex;
  612. justify-content: space-around;
  613. height: 100%;
  614. .modal_content_left {
  615. max-width: 40%;
  616. min-width: 30%;
  617. border-right: 1px solid #d8d8d8;
  618. }
  619. .modal_content_right {
  620. width: 60%;
  621. max-height: 700px;
  622. padding-left: 10px;
  623. overflow: hidden;
  624. overflow-y: auto;
  625. font-size: 18px;
  626. }
  627. }
  628. .tag-modal {
  629. display: flex;
  630. align-items: center;
  631. .before {
  632. width: 20px;
  633. background: #3764ff;
  634. height: 24px;
  635. border-radius: 5px 0 0 5px;
  636. display: flex;
  637. justify-content: center;
  638. align-items: center;
  639. color: #fff;
  640. }
  641. }
  642. /deep/.ivu-modal-body {
  643. max-height: 800px;
  644. overflow: hidden;
  645. overflow-y: auto;
  646. }
  647. </style>