index.vue 21 KB

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