index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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. props.isSelect?{}: {
  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 { proxy } = getCurrentInstance();
  104. const props = defineProps({
  105. isSelect: {
  106. type: Boolean,
  107. default: false,
  108. },
  109. });
  110. const loading = ref(false);
  111. const submitLoading = ref(false);
  112. const sourceList = ref({
  113. data: [],
  114. pagination: {
  115. total: 3,
  116. pageNum: 1,
  117. pageSize: 10,
  118. },
  119. });
  120. let lineData = ref([
  121. {
  122. key: "1",
  123. label: "测试1",
  124. disabled: false,
  125. },
  126. {
  127. key: "2",
  128. label: "测试2",
  129. disabled: false,
  130. },
  131. {
  132. key: "3",
  133. label: "测试3",
  134. disabled: false,
  135. },
  136. {
  137. key: "4",
  138. label: "测试4",
  139. disabled: false,
  140. },
  141. ]);
  142. const taskData = ref([]);
  143. let selectLine = ref([]);
  144. let dialogVisible = ref(false);
  145. let openProduct = ref(false);
  146. let modalType = ref("add");
  147. let rules = ref({
  148. name: [{ required: true, message: "请输入产线名称", trigger: "blur" }],
  149. isBatchMode: [
  150. { required: true, message: "请选择批量模式", trigger: "change" },
  151. ],
  152. productionTaskId: [
  153. { required: true, message: "请选择生产任务", trigger: "change" },
  154. ],
  155. });
  156. const selectConfig = reactive([
  157. // {
  158. // label: "车间类型",
  159. // prop: "type",
  160. // data: [
  161. // {
  162. // label: "普通车间",
  163. // value: "1",
  164. // },
  165. // {
  166. // label: "半自动化车间",
  167. // value: "2",
  168. // },
  169. // {
  170. // label: "自动化车间",
  171. // value: "3",
  172. // },
  173. // ],
  174. // },
  175. ]);
  176. const config = computed(() => {
  177. return [
  178. {
  179. attrs: {
  180. label: "产线名称",
  181. prop: "name",
  182. width: 150,
  183. },
  184. },
  185. {
  186. attrs: {
  187. label: "产线路线",
  188. slot: "line",
  189. },
  190. },
  191. // {
  192. // attrs: {
  193. // label: "适用产品",
  194. // slot: "product",
  195. // },
  196. // },
  197. {
  198. attrs: {
  199. label: "产线说明",
  200. prop: "remarks",
  201. },
  202. },
  203. {
  204. attrs: {
  205. label: "操作",
  206. width: "120",
  207. align: "center",
  208. },
  209. // 渲染 el-button,一般用在最后一列。
  210. renderHTML(row) {
  211. return props.isSelect
  212. ? [
  213. {
  214. attrs: {
  215. label: "选择",
  216. type: "primary",
  217. text: true,
  218. },
  219. el: "button",
  220. click() {
  221. handleSelectRow(row);
  222. },
  223. },
  224. ]
  225. : [
  226. // {
  227. // attrs: {
  228. // label: "产品",
  229. // type: "primary",
  230. // text: true,
  231. // },
  232. // el: "button",
  233. // click() {
  234. // updateProduct(row);
  235. // },
  236. // },
  237. {
  238. attrs: {
  239. label: "修改",
  240. type: "primary",
  241. text: true,
  242. },
  243. el: "button",
  244. click() {
  245. getDtl(row);
  246. },
  247. },
  248. {
  249. attrs: {
  250. label: "删除",
  251. type: "danger",
  252. text: true,
  253. },
  254. el: "button",
  255. click() {
  256. // 弹窗提示是否删除
  257. ElMessageBox.confirm(
  258. "此操作将永久删除该数据, 是否继续?",
  259. "提示",
  260. {
  261. confirmButtonText: "确定",
  262. cancelButtonText: "取消",
  263. type: "warning",
  264. }
  265. ).then(() => {
  266. // 删除
  267. proxy
  268. .post("/technology/delete", {
  269. id: row.id,
  270. })
  271. .then((res) => {
  272. ElMessage({
  273. message: "删除成功",
  274. type: "success",
  275. });
  276. getList();
  277. });
  278. });
  279. },
  280. },
  281. ];
  282. },
  283. },
  284. ];
  285. });
  286. let formData = reactive({
  287. data: {
  288. name: "",
  289. processRouteList: [],
  290. remarks: "",
  291. },
  292. dataOne: {},
  293. });
  294. const formOption = reactive({
  295. inline: true,
  296. labelWidth: 100,
  297. itemWidth: 100,
  298. rules: [],
  299. });
  300. const byform = ref(null);
  301. const formConfig = computed(() => {
  302. return [
  303. {
  304. type: "title1",
  305. title: "基本信息",
  306. },
  307. {
  308. type: "input",
  309. prop: "name",
  310. label: "产线名称",
  311. },
  312. // {
  313. // type: "radio",
  314. // prop: "isBatchMode",
  315. // label: "批量模式",
  316. // data: [
  317. // {
  318. // dictKey: "0",
  319. // dictValue: "关闭批量模式",
  320. // },
  321. // {
  322. // dictKey: "1",
  323. // dictValue: "开启批量模式",
  324. // },
  325. // ],
  326. // fn: (val) => {
  327. // if (val == "0") {
  328. // formData.data.productionTaskId = "";
  329. // }
  330. // },
  331. // },
  332. // {
  333. // type: "select",
  334. // prop: "productionTaskId",
  335. // label: "生产任务",
  336. // data: taskData.value,
  337. // itemWidth: 100,
  338. // multiple: false,
  339. // isShow: formData.data.isBatchMode == "1",
  340. // },
  341. // {
  342. // type: "slot",
  343. // slotName: "lineSlot",
  344. // label: "产线路线",
  345. // },
  346. // {
  347. // type: "slot",
  348. // slotName: "productSlot",
  349. // label: "适用产品",
  350. // },
  351. {
  352. type: "input",
  353. prop: "remarks",
  354. label: "产线说明",
  355. itemType: "textarea",
  356. },
  357. ];
  358. });
  359. const formConfigOne = computed(() => {
  360. return [
  361. {
  362. type: "slot",
  363. slotName: "productSlot",
  364. label: "适用产品",
  365. },
  366. ];
  367. });
  368. const getList = async (req) => {
  369. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  370. loading.value = true;
  371. proxy
  372. .post("/technology/page", sourceList.value.pagination)
  373. .then((message) => {
  374. console.log(message);
  375. sourceList.value.data = message.rows;
  376. sourceList.value.pagination.total = message.total;
  377. setTimeout(() => {
  378. loading.value = false;
  379. }, 200);
  380. });
  381. };
  382. const getProcesses = () => {
  383. // proxy
  384. // .post("/productionProcesses/page", { pageNum: 1, pageSize: 9999 })
  385. // .then((res) => {
  386. // lineData.value = res.rows.map((x) => ({
  387. // key: x.id,
  388. // label: x.name,
  389. // disabled: false,
  390. // }));
  391. // });
  392. proxy
  393. .post("/produceOrderDetail/page", { pageNum: 1, pageSize: 9999 })
  394. .then((res) => {
  395. taskData.value = res.rows.map((x) => ({
  396. ...x,
  397. label: x.orderCode,
  398. value: x.id,
  399. }));
  400. });
  401. };
  402. const openModal = () => {
  403. dialogVisible.value = true;
  404. nodeObject.value = "";
  405. modalType.value = "add";
  406. formData.data = {
  407. isBatchMode: 0,
  408. };
  409. selectLine.value = [];
  410. };
  411. const vueFlowDom = ref(null);
  412. const nodeObject = ref("");
  413. const submitForm = () => {
  414. console.log("www");
  415. byform.value.handleSubmit((valid) => {
  416. const data = vueFlowDom.value.submitAll();
  417. if (!data) {
  418. return;
  419. }
  420. formData.data.nodeObject = data.nodeObject;
  421. submitLoading.value = true;
  422. proxy.post("/technology/" + modalType.value, formData.data).then(
  423. (res) => {
  424. ElMessage({
  425. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  426. type: "success",
  427. });
  428. dialogVisible.value = false;
  429. submitLoading.value = false;
  430. getList();
  431. },
  432. (err) => {
  433. submitLoading.value = false;
  434. }
  435. );
  436. });
  437. };
  438. const submitFormOne = () => {
  439. if (!productList.value.length > 0)
  440. return ElMessage({
  441. message: "请添加适用产品",
  442. type: "info",
  443. });
  444. formData.dataOne.productList = productList.value.map((x) => ({
  445. productId: x.id,
  446. }));
  447. //选择的产品数据
  448. submitLoading.value = true;
  449. proxy.post("/technology/editProduct", formData.dataOne).then(
  450. (res) => {
  451. ElMessage({
  452. message: "操作成功",
  453. type: "success",
  454. });
  455. dialogVisibleOne.value = false;
  456. submitLoading.value = false;
  457. getList();
  458. },
  459. (err) => {
  460. submitLoading.value = false;
  461. }
  462. );
  463. };
  464. const getDtl = (row) => {
  465. modalType.value = "edit";
  466. proxy.post("/technology/detail", { id: row.id }).then((res) => {
  467. nodeObject.value = res.nodeObject;
  468. // productList.value = res.applicableProductsList;
  469. // selectLine.value = res.processRouteList.map((x) => x.id);
  470. res.isBatchMode = res.isBatchMode + "";
  471. formData.data = res;
  472. dialogVisible.value = true;
  473. });
  474. };
  475. const dialogVisibleOne = ref(false);
  476. const updateProduct = (row) => {
  477. proxy.post("/technology/detail", { id: row.id }).then((res) => {
  478. productList.value = res.applicableProductsList;
  479. formData.dataOne = {
  480. id: row.id,
  481. productList: [],
  482. };
  483. dialogVisibleOne.value = true;
  484. });
  485. };
  486. const productList = ref([]);
  487. const handleSelect = (row) => {
  488. const flag = productList.value.some((x) => x.id === row.id);
  489. if (flag)
  490. return ElMessage({
  491. message: "该产品已选择",
  492. type: "info",
  493. });
  494. productList.value.push(row);
  495. return ElMessage({
  496. message: "选择成功",
  497. type: "success",
  498. });
  499. };
  500. const handleRemove = (index) => {
  501. productList.value.splice(index, 1);
  502. return ElMessage({
  503. message: "删除成功",
  504. type: "success",
  505. });
  506. };
  507. getList();
  508. getProcesses();
  509. // 以下是实现拖拽排序的处理方法
  510. const dragStar = (e, option) => {
  511. // if (!selectLine.value.includes(e.target.id)) return; //拖拽的数据如不是选择的数据直接return
  512. e.dataTransfer.setData("text/plain", option.key);
  513. e.dataTransfer.effectAllowed = "move";
  514. e.dataTransfer.dropEffect = "move";
  515. };
  516. const dragOver = (e, option) => {
  517. e.preventDefault();
  518. };
  519. const handleDrop = (e) => {
  520. // if (!selectLine.value.includes(e.target.id)) return; //拖拽的数据如不是选择的数据直接return
  521. e.preventDefault();
  522. const sourceKey = e.dataTransfer.getData("text/plain"); //获取拖动元素的key值
  523. const targetKey = e.target.id; //获取被互换元素的id值
  524. swapItems(sourceKey, targetKey);
  525. };
  526. // const findIndex = (target) => {
  527. // while (target && target.parentNode) {
  528. // let targetParent = target.parentNode;
  529. // const index = Array.from(targetParent.children).indexOf(target);
  530. // if (index !== -1) {
  531. // return index;
  532. // }
  533. // }
  534. // return -1;
  535. // };
  536. // 调换数据源位置
  537. const swapItems = (sourceKey, targetKey) => {
  538. const sourceIndex = selectLine.value.findIndex((x) => x === sourceKey);
  539. const targetIndex = selectLine.value.findIndex((x) => x === targetKey);
  540. const temp = selectLine.value[sourceIndex];
  541. selectLine.value[sourceIndex] = selectLine.value[targetIndex];
  542. selectLine.value[targetIndex] = temp;
  543. };
  544. const handleSelectRow = (row) => {
  545. proxy.$emit("selectTechnology", row);
  546. };
  547. </script>
  548. <style lang="scss" scoped>
  549. .tenant {
  550. padding: 20px;
  551. }
  552. .processChart {
  553. border: 1px solid #ccc;
  554. // padding: 20px;
  555. display: flex;
  556. justify-content: space-between;
  557. position: relative;
  558. .from {
  559. width: 230px;
  560. background: #fff;
  561. border-radius: 5px;
  562. padding: 15px;
  563. }
  564. .content {
  565. width: calc(100% - 230px);
  566. border-radius: 5px;
  567. padding: 15px;
  568. background: #fff;
  569. }
  570. }
  571. .chart-warp {
  572. width: 100%;
  573. // height: calc(100vh - 280px);
  574. }
  575. </style>