index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <div class="pageIndexClass">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable :source="sourceList.data" :pagination="sourceList.pagination" :config="config" :loading="loading" highlight-current-row
  6. :selectConfig="selectConfig" :table-events="{
  7. //element talbe事件都能传
  8. select: select,
  9. }" :action-list="[
  10. {
  11. text: '添加产线',
  12. action: () => openModal('add'),
  13. },
  14. ]" @get-list="getList">
  15. <template #line="{ item }">
  16. <div style="width:100%">
  17. <span v-for="(x, i) in item.processRouteNameList" :key="i">
  18. {{ x }}
  19. <span style="margin: 0 3px" v-if="i + 1 < item.processRouteNameList.length"> ,
  20. </span>
  21. </span>
  22. </div>
  23. </template>
  24. <template #product="{ item }">
  25. <div style="width:100%">
  26. <span v-for="(x, i) in item.applicableProductsNameList" :key="i">
  27. {{ x }}
  28. <span v-if="i + 1 < item.applicableProductsNameList.length">,
  29. </span>
  30. </span>
  31. </div>
  32. </template>
  33. </byTable>
  34. </div>
  35. <el-dialog :title="modalType == 'add' ? '添加产线' : '编辑产线'" v-model="dialogVisible" width="95%" destroy-on-close>
  36. <div style="display:flex">
  37. <div style="width:350px">
  38. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform" v-loading="submitLoading">
  39. </byForm>
  40. <div style="text-align:center">
  41. <el-button @click="dialogVisible = false" size="default">取 消</el-button>
  42. <el-button type="primary" @click="submitForm" size="default" :loading="submitLoading">
  43. 确 定
  44. </el-button>
  45. </div>
  46. </div>
  47. <div style="width:calc(100% - 350px)">
  48. <div class="processChart" style="width:100%">
  49. <div class="from">
  50. <div class="commons-title">工序</div>
  51. </div>
  52. <div class="content">
  53. <div class="commons-title">产线路线</div>
  54. <div class="chart-warp">
  55. <vueFlow :nodeObject="nodeObject" ref="vueFlowDom"></vueFlow>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- <template #footer>
  62. </template> -->
  63. </el-dialog>
  64. <el-dialog v-model="openProduct" title="选择产品" width="70%" append-to-body>
  65. <SelectProduct @handleSelect="handleSelect" :isTechnology="'0'"></SelectProduct>
  66. <template #footer>
  67. <span class="dialog-footer">
  68. <el-button @click="openProduct = false">取消</el-button>
  69. </span>
  70. </template>
  71. </el-dialog>
  72. <el-dialog :title=" '产线适用产品'" v-model="dialogVisibleOne" width="50%" destroy-on-close>
  73. <byForm :formConfig="formConfigOne" :formOption="formOption" v-model="formData.dataOne" ref="byformOne" v-loading="submitLoading">
  74. <template #productSlot>
  75. <div>
  76. <el-button type="primary" @click="openProduct = true">
  77. 添加产品
  78. </el-button>
  79. <div style="margin-top: 15px" v-if="productList && productList.length > 0">
  80. <el-tag style="margin-right: 10px" type="info" closable v-for="(product, index) in productList" :key="product.id"
  81. @close="handleRemove(index)">{{ product.name }}({{ product.spec }})</el-tag>
  82. </div>
  83. </div>
  84. </template>
  85. </byForm>
  86. <template #footer>
  87. <el-button @click="dialogVisibleOne = false" size="default">取 消</el-button>
  88. <el-button type="primary" @click="submitFormOne" size="default" :loading="submitLoading">
  89. 确 定
  90. </el-button>
  91. </template>
  92. </el-dialog>
  93. </div>
  94. </template>
  95. <script setup>
  96. /* eslint-disable vue/no-unused-components */
  97. import { ElMessage, ElMessageBox } from "element-plus";
  98. import byTable from "@/components/byTable/index";
  99. import byForm from "@/components/byForm/index";
  100. import SelectProduct from "@/components/product/SelectProduct";
  101. import vueFlow from "@/views/production/project/processConfig/vueFlow.vue";
  102. import { computed, defineComponent, nextTick, ref, toRaw } from "vue";
  103. const loading = ref(false);
  104. const submitLoading = ref(false);
  105. const sourceList = ref({
  106. data: [],
  107. pagination: {
  108. total: 3,
  109. pageNum: 1,
  110. pageSize: 10,
  111. },
  112. });
  113. let lineData = ref([
  114. {
  115. key: "1",
  116. label: "测试1",
  117. disabled: false,
  118. },
  119. {
  120. key: "2",
  121. label: "测试2",
  122. disabled: false,
  123. },
  124. {
  125. key: "3",
  126. label: "测试3",
  127. disabled: false,
  128. },
  129. {
  130. key: "4",
  131. label: "测试4",
  132. disabled: false,
  133. },
  134. ]);
  135. const taskData = ref([]);
  136. let selectLine = ref([]);
  137. let dialogVisible = ref(false);
  138. let openProduct = ref(false);
  139. let modalType = ref("add");
  140. let rules = ref({
  141. name: [{ required: true, message: "请输入产线名称", trigger: "blur" }],
  142. isBatchMode: [
  143. { required: true, message: "请选择批量模式", trigger: "change" },
  144. ],
  145. productionTaskId: [
  146. { required: true, message: "请选择生产任务", trigger: "change" },
  147. ],
  148. });
  149. const { proxy } = getCurrentInstance();
  150. const selectConfig = reactive([
  151. // {
  152. // label: "车间类型",
  153. // prop: "type",
  154. // data: [
  155. // {
  156. // label: "普通车间",
  157. // value: "1",
  158. // },
  159. // {
  160. // label: "半自动化车间",
  161. // value: "2",
  162. // },
  163. // {
  164. // label: "自动化车间",
  165. // value: "3",
  166. // },
  167. // ],
  168. // },
  169. ]);
  170. const config = computed(() => {
  171. return [
  172. {
  173. attrs: {
  174. label: "产线名称",
  175. prop: "name",
  176. width: 150,
  177. },
  178. },
  179. {
  180. attrs: {
  181. label: "产线路线",
  182. slot: "line",
  183. },
  184. },
  185. // {
  186. // attrs: {
  187. // label: "适用产品",
  188. // slot: "product",
  189. // },
  190. // },
  191. {
  192. attrs: {
  193. label: "产线说明",
  194. prop: "remarks",
  195. },
  196. },
  197. {
  198. attrs: {
  199. label: "操作",
  200. width: "120",
  201. align: "center",
  202. },
  203. // 渲染 el-button,一般用在最后一列。
  204. renderHTML(row) {
  205. return [
  206. // {
  207. // attrs: {
  208. // label: "产品",
  209. // type: "primary",
  210. // text: true,
  211. // },
  212. // el: "button",
  213. // click() {
  214. // updateProduct(row);
  215. // },
  216. // },
  217. {
  218. attrs: {
  219. label: "修改",
  220. type: "primary",
  221. text: true,
  222. },
  223. el: "button",
  224. click() {
  225. getDtl(row);
  226. },
  227. },
  228. {
  229. attrs: {
  230. label: "删除",
  231. type: "danger",
  232. text: true,
  233. },
  234. el: "button",
  235. click() {
  236. // 弹窗提示是否删除
  237. ElMessageBox.confirm(
  238. "此操作将永久删除该数据, 是否继续?",
  239. "提示",
  240. {
  241. confirmButtonText: "确定",
  242. cancelButtonText: "取消",
  243. type: "warning",
  244. }
  245. ).then(() => {
  246. // 删除
  247. proxy
  248. .post("/technology/delete", {
  249. id: row.id,
  250. })
  251. .then((res) => {
  252. ElMessage({
  253. message: "删除成功",
  254. type: "success",
  255. });
  256. getList();
  257. });
  258. });
  259. },
  260. },
  261. ];
  262. },
  263. },
  264. ];
  265. });
  266. let formData = reactive({
  267. data: {
  268. name: "",
  269. processRouteList: [],
  270. remarks: "",
  271. },
  272. dataOne: {},
  273. });
  274. const formOption = reactive({
  275. inline: true,
  276. labelWidth: 100,
  277. itemWidth: 100,
  278. rules: [],
  279. });
  280. const byform = ref(null);
  281. const formConfig = computed(() => {
  282. return [
  283. {
  284. type: "title1",
  285. title: "基本信息",
  286. },
  287. {
  288. type: "input",
  289. prop: "name",
  290. label: "产线名称",
  291. },
  292. {
  293. type: "radio",
  294. prop: "isBatchMode",
  295. label: "批量模式",
  296. data: [
  297. {
  298. dictKey: "0",
  299. dictValue: "关闭批量模式",
  300. },
  301. {
  302. dictKey: "1",
  303. dictValue: "开启批量模式",
  304. },
  305. ],
  306. fn: (val) => {
  307. if (val == "0") {
  308. formData.data.productionTaskId = "";
  309. }
  310. },
  311. },
  312. {
  313. type: "select",
  314. prop: "productionTaskId",
  315. label: "生产任务",
  316. data: taskData.value,
  317. itemWidth: 100,
  318. multiple: false,
  319. isShow: formData.data.isBatchMode == "1",
  320. },
  321. // {
  322. // type: "slot",
  323. // slotName: "lineSlot",
  324. // label: "产线路线",
  325. // },
  326. // {
  327. // type: "slot",
  328. // slotName: "productSlot",
  329. // label: "适用产品",
  330. // },
  331. {
  332. type: "input",
  333. prop: "remarks",
  334. label: "产线说明",
  335. itemType: "textarea",
  336. },
  337. ];
  338. });
  339. const formConfigOne = computed(() => {
  340. return [
  341. {
  342. type: "slot",
  343. slotName: "productSlot",
  344. label: "适用产品",
  345. },
  346. ];
  347. });
  348. const getList = async (req) => {
  349. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  350. loading.value = true;
  351. proxy
  352. .post("/technology/page", sourceList.value.pagination)
  353. .then((message) => {
  354. console.log(message);
  355. sourceList.value.data = message.rows;
  356. sourceList.value.pagination.total = message.total;
  357. setTimeout(() => {
  358. loading.value = false;
  359. }, 200);
  360. });
  361. };
  362. const getProcesses = () => {
  363. // proxy
  364. // .post("/productionProcesses/page", { pageNum: 1, pageSize: 9999 })
  365. // .then((res) => {
  366. // lineData.value = res.rows.map((x) => ({
  367. // key: x.id,
  368. // label: x.name,
  369. // disabled: false,
  370. // }));
  371. // });
  372. proxy
  373. .post("/produceOrderDetail/page", { pageNum: 1, pageSize: 9999 })
  374. .then((res) => {
  375. taskData.value = res.rows.map((x) => ({
  376. ...x,
  377. label: x.orderCode,
  378. value: x.id,
  379. }));
  380. });
  381. };
  382. const openModal = () => {
  383. dialogVisible.value = true;
  384. nodeObject.value = "";
  385. modalType.value = "add";
  386. formData.data = {
  387. isBatchMode: 0,
  388. };
  389. selectLine.value = [];
  390. };
  391. const vueFlowDom = ref(null);
  392. const nodeObject = ref("");
  393. const submitForm = () => {
  394. console.log("www");
  395. byform.value.handleSubmit((valid) => {
  396. const data = vueFlowDom.value.submitAll();
  397. if (!data) {
  398. return;
  399. }
  400. formData.data.nodeObject = data.nodeObject;
  401. submitLoading.value = true;
  402. proxy.post("/technology/" + modalType.value, formData.data).then(
  403. (res) => {
  404. ElMessage({
  405. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  406. type: "success",
  407. });
  408. dialogVisible.value = false;
  409. submitLoading.value = false;
  410. getList();
  411. },
  412. (err) => {
  413. submitLoading.value = false;
  414. }
  415. );
  416. });
  417. };
  418. const submitFormOne = () => {
  419. if (!productList.value.length > 0)
  420. return ElMessage({
  421. message: "请添加适用产品",
  422. type: "info",
  423. });
  424. formData.dataOne.productList = productList.value.map((x) => ({
  425. productId: x.id,
  426. }));
  427. //选择的产品数据
  428. submitLoading.value = true;
  429. proxy.post("/technology/editProduct", formData.dataOne).then(
  430. (res) => {
  431. ElMessage({
  432. message: "操作成功",
  433. type: "success",
  434. });
  435. dialogVisibleOne.value = false;
  436. submitLoading.value = false;
  437. getList();
  438. },
  439. (err) => {
  440. submitLoading.value = false;
  441. }
  442. );
  443. };
  444. const getDtl = (row) => {
  445. modalType.value = "edit";
  446. proxy.post("/technology/detail", { id: row.id }).then((res) => {
  447. nodeObject.value = res.nodeObject;
  448. // productList.value = res.applicableProductsList;
  449. // selectLine.value = res.processRouteList.map((x) => x.id);
  450. formData.data = res;
  451. dialogVisible.value = true;
  452. });
  453. };
  454. const dialogVisibleOne = ref(false);
  455. const updateProduct = (row) => {
  456. proxy.post("/technology/detail", { id: row.id }).then((res) => {
  457. productList.value = res.applicableProductsList;
  458. formData.dataOne = {
  459. id: row.id,
  460. productList: [],
  461. };
  462. dialogVisibleOne.value = true;
  463. });
  464. };
  465. const productList = ref([]);
  466. const handleSelect = (row) => {
  467. const flag = productList.value.some((x) => x.id === row.id);
  468. if (flag)
  469. return ElMessage({
  470. message: "该产品已选择",
  471. type: "info",
  472. });
  473. productList.value.push(row);
  474. return ElMessage({
  475. message: "选择成功",
  476. type: "success",
  477. });
  478. };
  479. const handleRemove = (index) => {
  480. productList.value.splice(index, 1);
  481. return ElMessage({
  482. message: "删除成功",
  483. type: "success",
  484. });
  485. };
  486. getList();
  487. getProcesses();
  488. // 以下是实现拖拽排序的处理方法
  489. const dragStar = (e, option) => {
  490. // if (!selectLine.value.includes(e.target.id)) return; //拖拽的数据如不是选择的数据直接return
  491. e.dataTransfer.setData("text/plain", option.key);
  492. e.dataTransfer.effectAllowed = "move";
  493. e.dataTransfer.dropEffect = "move";
  494. };
  495. const dragOver = (e, option) => {
  496. e.preventDefault();
  497. };
  498. const handleDrop = (e) => {
  499. // if (!selectLine.value.includes(e.target.id)) return; //拖拽的数据如不是选择的数据直接return
  500. e.preventDefault();
  501. const sourceKey = e.dataTransfer.getData("text/plain"); //获取拖动元素的key值
  502. const targetKey = e.target.id; //获取被互换元素的id值
  503. swapItems(sourceKey, targetKey);
  504. };
  505. // const findIndex = (target) => {
  506. // while (target && target.parentNode) {
  507. // let targetParent = target.parentNode;
  508. // const index = Array.from(targetParent.children).indexOf(target);
  509. // if (index !== -1) {
  510. // return index;
  511. // }
  512. // }
  513. // return -1;
  514. // };
  515. // 调换数据源位置
  516. const swapItems = (sourceKey, targetKey) => {
  517. const sourceIndex = selectLine.value.findIndex((x) => x === sourceKey);
  518. const targetIndex = selectLine.value.findIndex((x) => x === targetKey);
  519. const temp = selectLine.value[sourceIndex];
  520. selectLine.value[sourceIndex] = selectLine.value[targetIndex];
  521. selectLine.value[targetIndex] = temp;
  522. };
  523. </script>
  524. <style lang="scss" scoped>
  525. .tenant {
  526. padding: 20px;
  527. }
  528. .processChart {
  529. border: 1px solid #ccc;
  530. // padding: 20px;
  531. display: flex;
  532. justify-content: space-between;
  533. position: relative;
  534. .from {
  535. width: 230px;
  536. background: #fff;
  537. border-radius: 5px;
  538. padding: 15px;
  539. }
  540. .content {
  541. width: calc(100% - 230px);
  542. border-radius: 5px;
  543. padding: 15px;
  544. background: #fff;
  545. }
  546. }
  547. .chart-warp {
  548. width: 100%;
  549. // height: calc(100vh - 280px);
  550. }
  551. </style>