index.vue 22 KB

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