index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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="1000"
  56. v-model="showModal"
  57. :title="isCheck ? '工艺路线详情' : '工艺路线编辑'"
  58. >
  59. <div class="modal_process_route">
  60. <div>
  61. <span style="width: 100px">id: </span
  62. ><Input
  63. v-model="info.id"
  64. disabled
  65. placeholder="自动生成"
  66. style="width: 150px"
  67. size="small"
  68. />
  69. </div>
  70. <div>
  71. <span style="width: 100px">工艺路线名称: </span
  72. ><Input
  73. v-model="info.title"
  74. placeholder="请输入工艺路线名称"
  75. size="small"
  76. :disabled="isCheck"
  77. style="width: 250px"
  78. />
  79. </div>
  80. </div>
  81. <div class="modal_content">
  82. <div class="modal_content_left">
  83. <span>已选:</span>
  84. <SlickList
  85. :distance="10"
  86. :lockToContainerEdges="true"
  87. axis="x,y,xy"
  88. lockAxis="xy"
  89. v-model="selectTags"
  90. class="SortableList"
  91. @input="getChangeLists"
  92. >
  93. <SlickItem
  94. style="z-index: 9999"
  95. v-for="(item, key) of selectTags"
  96. :key="key"
  97. class="SortableItem"
  98. :index="key"
  99. >
  100. <div class="tag-modal">
  101. <div class="before">{{ key + 1 }}</div>
  102. <Tag
  103. @on-close="closeTag(key, selectTags, item)"
  104. color="primary"
  105. type="border"
  106. closable
  107. >{{ item.title }}</Tag
  108. >
  109. </div>
  110. </SlickItem>
  111. </SlickList>
  112. </div>
  113. <div class="modal_content_right">
  114. <div
  115. v-for="(item, index) of info.bps"
  116. :key="index"
  117. :label="item.title"
  118. >
  119. <div v-for="(_item, _index) in item.cld" :key="_index" >
  120. <div v-if="_item.cld&&_item.cld.length>0" style="position:relative;left:0;top:0">{{ _item.title }}:</div>
  121. <Tooltip v-for="(__item, __index) of _item.cld" :key="__index">
  122. <div slot="content">
  123. <p>工时:{{ __item.time }}</p>
  124. <p>工价:{{ __item.wages }}</p>
  125. <p>产能:{{ __item.capacity }}</p>
  126. </div>
  127. <Checkbox
  128. @on-change="changeCheck($event, __item, selectTags)"
  129. v-model="__item.show"
  130. :disabled="isCheck"
  131. style="padding: 0px 5px"
  132. >{{ __item.title }}</Checkbox
  133. >
  134. </Tooltip>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. <div slot="footer">
  140. <Button @click="showModal = false" type="primary" ghost>取消</Button>
  141. <Button @click="saveTableData()" v-show="!isCheck" type="primary"
  142. >确定</Button
  143. >
  144. </div>
  145. </Modal>
  146. </div>
  147. </template>
  148. <script>
  149. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  150. // 例如:import 《组件名称》 from '《组件路径》';
  151. import { mapState } from "vuex";
  152. import { SlickList, SlickItem } from "vue-slicksort";
  153. export default {
  154. name: "ProcessLine",
  155. components: {
  156. SlickList,
  157. SlickItem,
  158. },
  159. props: {},
  160. // import引入的组件需要注入到对象中才能使用
  161. data() {
  162. // 这里存放数据
  163. return {
  164. list: [
  165. {
  166. title: "工艺路线名称",
  167. name: "Input",
  168. value: "",
  169. serverName: "title",
  170. placeholder: "请输入工艺路线名称",
  171. },
  172. ],
  173. tableColums: [
  174. {
  175. title: "序号",
  176. type: "index",
  177. align: "center",
  178. key: "id",
  179. width: "100",
  180. },
  181. { title: "工艺路线名称", align: "center", key: "title" },
  182. { title: "操作", align: "center", slot: "set", width: "220" },
  183. ],
  184. tableData: [],
  185. pageIndex: 1,
  186. total: 0,
  187. pageSize: 10,
  188. proxyObj: {},
  189. loading: false,
  190. showModal: false,
  191. processRouteId: "",
  192. processRouteName: "",
  193. selectTags: [], //已选列表
  194. headers: { Authorization: localStorage.getItem("token") },
  195. info: {
  196. title: "",
  197. price: "",
  198. parts_id: "",
  199. id: null,
  200. properties: [], //工序号
  201. procedure: [], //工艺属性id
  202. list: [],
  203. bps: [],
  204. procedure_id: "",
  205. },
  206. isCheck: false,
  207. };
  208. },
  209. // 生命周期 - 创建完成(可以访问当前this实例)
  210. created() {},
  211. // 生命周期 - 挂载完成(可以访问DOM元素)
  212. mounted() {
  213. this.axios("/api/bp_list").then((res) => {
  214. this.info.bps = res.data;
  215. });
  216. this.axios("/api/bpp_list").then((res) => {
  217. res.data.map((v) => {
  218. if (v.select) {
  219. v.cld.map((z) => {
  220. v.select.map((k) => {
  221. z.show = k == z.id ? true : false;
  222. });
  223. });
  224. } else {
  225. v.cld.map((v) => (v.show = false));
  226. }
  227. });
  228. this.info.list = res.data;
  229. });
  230. },
  231. methods: {
  232. handleAddPL() {
  233. this.isCheck = false;
  234. this.info.id = "";
  235. this.info.title = "";
  236. this.info.procedure_id = "";
  237. this.selectTags = [];
  238. for (const key in this.info.bps) {
  239. const element = this.info.bps[key];
  240. element.cld.forEach((z) => {
  241. z.show = false;
  242. });
  243. }
  244. this.showModal = true;
  245. },
  246. //1复制 2编辑 3查看 4删除
  247. handleSet(row, index, type) {
  248. this.info.id = row.id;
  249. this.info.title = row.title;
  250. this.info.procedure_id = row.procedure_id;
  251. this.selectTags = [];
  252. const arr = this.info.procedure_id
  253. ? this.info.procedure_id.split(",")
  254. : [];
  255. for (const key in this.info.bps) {
  256. const el = this.info.bps[key];
  257. el.cld.forEach((z) => {
  258. z.show = false;
  259. });
  260. }
  261. this.$nextTick(() => {
  262. arr.forEach((element) => {
  263. for (const key in this.info.bps) {
  264. const el = this.info.bps[key];
  265. for (const k in el.cld) {
  266. const e = el.cld[k];
  267. e.cld &&
  268. e.cld.forEach((z) => {
  269. if (z.id == element) {
  270. z.show = true;
  271. this.selectTags.push(z);
  272. }
  273. });
  274. }
  275. }
  276. });
  277. switch (type) {
  278. case 1:
  279. this.axios({
  280. method: "post",
  281. url: "/api/technological_route_edit",
  282. data: {
  283. title: row.title + "副本",
  284. procedure_id: this.info.procedure_id,
  285. },
  286. })
  287. .then((res) => {
  288. if (res.code == 200) {
  289. this.init(this.proxyObj);
  290. }
  291. })
  292. .catch((err) => {});
  293. break;
  294. case 2:
  295. this.showModal = true;
  296. this.isCheck = false;
  297. break;
  298. case 3:
  299. this.showModal = true;
  300. this.isCheck = true;
  301. break;
  302. case 4:
  303. this.$Modal.confirm({
  304. title: "确认删除?",
  305. content: "此操作确认后不可恢复,请确认!",
  306. onOk: () => {
  307. this.axios({
  308. method: "post",
  309. url: "/api/technological_route_del",
  310. data: {
  311. id: row.id,
  312. },
  313. })
  314. .then((res) => {
  315. this.$Message.success(res.msg);
  316. this.getData(this.proxyObj);
  317. this.showModal = false;
  318. })
  319. .catch((err) => {});
  320. },
  321. onCancel: () => (this.showModal = false),
  322. });
  323. break;
  324. }
  325. });
  326. },
  327. init(row) {
  328. this.pageIndex = 1;
  329. row.page_index = this.pageIndex;
  330. row.page_size = this.pageSize;
  331. this.proxyObj = row;
  332. this.getData(row);
  333. },
  334. getData(row) {
  335. this.loading = true;
  336. this.axios("/api/technological_route", { params: row }).then((res) => {
  337. this.loading = false;
  338. this.tableData = res.data.data;
  339. this.total = res.data.total;
  340. });
  341. },
  342. getChangeLists(e) {},
  343. saveTableData() {
  344. // this.tableData = JSON.parse(JSON.stringify(this.selectTags));
  345. let temparr = [];
  346. this.selectTags.forEach((el) => {
  347. temparr.push(el.id);
  348. });
  349. this.axios({
  350. method: "post",
  351. url: "/api/technological_route_edit",
  352. data: {
  353. id: this.info.id,
  354. title: this.info.title,
  355. procedure_id: temparr.join(","),
  356. },
  357. })
  358. .then((res) => {
  359. this.$Message.success(res.msg);
  360. this.init(this.proxyObj);
  361. })
  362. .catch((err) => {});
  363. },
  364. closeTag(key, arr, row) {
  365. //取消tag标签展示操作并同步下方的复选框ui同步
  366. if (this.isCheck) {
  367. } else {
  368. for (const key in this.info.bps) {
  369. const element = this.info.bps[key];
  370. element.cld.map((p) => {
  371. p.id == row.id ? (p.show = false) : "";
  372. });
  373. }
  374. arr.splice(key, 1);
  375. return;
  376. this.info.bps.map((v) => {
  377. v.cld.map((p) => {
  378. p.id == row.id ? (p.show = false) : "";
  379. });
  380. });
  381. }
  382. },
  383. changeCheck(e, item, selectArray) {
  384. //复选框选中与非选中同时同步tag标签跟随操作
  385. item.show = e;
  386. if (e) {
  387. selectArray.push(item);
  388. } else {
  389. let id = item.id;
  390. let id_index = selectArray.findIndex((v) => v.id == id);
  391. selectArray.splice(id_index, 1);
  392. }
  393. let temparr = [];
  394. this.selectTags.forEach((el) => {
  395. temparr.push(el.id);
  396. });
  397. },
  398. changePage(e) {
  399. this.pageIndex = e;
  400. this.proxyObj.page_index = this.pageIndex;
  401. this.getData(this.proxyObj);
  402. },
  403. changeSize(e) {
  404. this.pageSize = e;
  405. this.proxyObj.page_size = this.pageSize;
  406. this.getData(this.proxyObj);
  407. },
  408. async exportData() {
  409. const res = await this.axios("/api/process_route_index_export", {
  410. params: { ...this.proxyObj, page: 0 },
  411. });
  412. if (res.code == 200) {
  413. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`;
  414. location.href = url;
  415. }
  416. },
  417. uploadSuccess(res) {
  418. if (res.code == 200) {
  419. this.$Message.success(res.msg || "上传成功");
  420. } else {
  421. this.$Message.warning(res.msg || "上传失败");
  422. }
  423. this.getData(this.proxyObj);
  424. },
  425. uploadError(err) {
  426. this.$Message.error(err.msg || "上传失败");
  427. },
  428. },
  429. // 监听属性 类似于data概念
  430. computed: {
  431. ...mapState(["persimissionData"]),
  432. },
  433. // 监控data中的数据变化
  434. watch: {},
  435. beforeCreate() {}, // 生命周期 - 创建之前
  436. beforeMount() {}, // 生命周期 - 挂载之前
  437. beforeUpdate() {}, // 生命周期 - 更新之前
  438. updated() {}, // 生命周期 - 更新之后
  439. beforeDestroy() {}, // 生命周期 - 销毁之前
  440. destroyed() {}, // 生命周期 - 销毁完成
  441. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  442. };
  443. </script>
  444. <style lang="scss" scoped>
  445. .vertical-center-modal {
  446. display: flex;
  447. align-items: center;
  448. justify-content: center;
  449. .ivu-modal {
  450. top: 0;
  451. }
  452. }
  453. .modal_process_route {
  454. div {
  455. display: flex;
  456. justify-content: space-around;
  457. align-items: center;
  458. margin: 5px 0;
  459. }
  460. }
  461. .modal_content {
  462. display: flex;
  463. justify-content: space-around;
  464. .modal_content_left {
  465. width: 40%;
  466. }
  467. .modal_content_right {
  468. width: 60%;
  469. max-height: 500px;
  470. overflow: hidden;
  471. overflow-y: auto;
  472. }
  473. }
  474. .tag-modal {
  475. display: flex;
  476. align-items: center;
  477. .before {
  478. width: 20px;
  479. background: #3764ff;
  480. height: 24px;
  481. border-radius: 5px 0 0 5px;
  482. display: flex;
  483. justify-content: center;
  484. align-items: center;
  485. color: #fff;
  486. }
  487. }
  488. /deep/.ivu-modal-body {
  489. max-height: 500px;
  490. overflow: hidden;
  491. overflow-y: auto;
  492. }
  493. </style>