bindProcess.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <div
  3. class="mainContentBox"
  4. style="padding: 0; box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1)"
  5. >
  6. <div class="header">
  7. <div class="title">绑定工序</div>
  8. <el-space>
  9. <el-button :icon="Back" size="small" @click="back">返回</el-button>
  10. <!-- <el-button type="primary" :icon="Download" size="small">下载</el-button>-->
  11. <el-button
  12. :type="isChanged ? 'danger' : 'primary'"
  13. :icon="Document"
  14. size="small"
  15. @click="saveFlow"
  16. >保存</el-button
  17. >
  18. </el-space>
  19. </div>
  20. <div class="binContainer">
  21. <div class="processTree">
  22. <el-scrollbar >
  23. <el-collapse v-model="activeNames">
  24. <el-collapse-item
  25. v-for="(pProcess, pIndex) in list1"
  26. :key="pProcess.workSection"
  27. :name="pIndex"
  28. >
  29. <template #title>
  30. <div class="title2">
  31. {{ getNameByDictType(pProcess.workSection) }}
  32. </div>
  33. </template>
  34. <div class="treeChild">
  35. <VueDraggable
  36. v-model="pProcess.baseOperationList"
  37. :animation="150"
  38. :group="{ name: 'people', pull: 'clone', put: false }"
  39. :sort="false"
  40. :clone="clone"
  41. >
  42. <div
  43. class="childItem"
  44. v-for="(item, index) in pProcess?.baseOperationList"
  45. :key="item.id"
  46. >
  47. {{ item.operationName }}
  48. </div>
  49. </VueDraggable>
  50. </div>
  51. </el-collapse-item>
  52. </el-collapse>
  53. </el-scrollbar>
  54. </div>
  55. <div class="flowBox">
  56. <el-scrollbar style="padding-bottom: 20px;">
  57. <VueDraggable
  58. v-model="list2"
  59. :animation="150"
  60. group="people"
  61. @update="onUpdate"
  62. style="min-width: 400px"
  63. @add="onClone"
  64. >
  65. <div
  66. v-for="(item, index) in list2"
  67. :key="item.uuid"
  68. class="flowItem"
  69. @click="clickFlowItem(item, index)"
  70. >
  71. <div class="indexLabel">工序 {{ index + 1 }}</div>
  72. <div :class="getFlowNameClass(index)">
  73. {{ item?.operationVO?.operationName }}
  74. </div>
  75. <div>
  76. <Delete class="flowDelete" @click.stop="clickDelete(index)" />
  77. </div>
  78. <Bottom class="arrow" v-show="index < list2.length - 1" />
  79. </div>
  80. </VueDraggable>
  81. </el-scrollbar>
  82. </div>
  83. <div class="detailInfo">
  84. <div v-if="selectIndex > -1 && !isChanged">
  85. <avue-form
  86. ref="formRef"
  87. :option="formOption"
  88. v-model="currentProcess"
  89. style="padding: 10px; background-color: white"
  90. />
  91. <div class="editProcces">
  92. <el-button type="primary" :icon="Grid" @click="editProComponent"
  93. >编辑工序组件</el-button
  94. >
  95. </div>
  96. </div>
  97. <div v-else class="tipContent">{{ tipContent }}</div>
  98. </div>
  99. </div>
  100. </div>
  101. </template>
  102. <script setup>
  103. import {
  104. Back,
  105. Download,
  106. Document,
  107. Delete,
  108. Bottom,
  109. Grid,
  110. } from "@element-plus/icons-vue";
  111. import { VueDraggable } from "vue-draggable-plus";
  112. import { processTreeList } from "@/api/craft/process/index";
  113. import { useCommonStoreHook, useDictionaryStore } from "@/store";
  114. import {
  115. processesByRouteId,
  116. saveProcessInRoute,
  117. updateProcess,
  118. } from "@/api/craft/route/index";
  119. import { v4 as uuidv4 } from "uuid";
  120. import { formOption } from "./bindConfig";
  121. import { ElMessage } from "element-plus";
  122. const router = useRouter();
  123. const route = useRoute();
  124. // 数据字典相关
  125. const { dicts } = useDictionaryStore();
  126. // 顶部====================
  127. const back = () => {
  128. router.back();
  129. };
  130. const download = () => {};
  131. // 左侧工序树====================
  132. const activeNames = ref([0]);
  133. const handleChange = (val) => {};
  134. const list1 = ref([]);
  135. // 由于工序和(工序-工艺)模型字段不同,需要自定义克隆
  136. const clone = (origin) => {
  137. const data = JSON.parse(JSON.stringify(origin));
  138. return {
  139. created: "",
  140. creator: "",
  141. deleted: 0,
  142. deptId: "",
  143. id: null,
  144. uuid: uuidv4(),
  145. nextOperationId: "", //下一工序id
  146. operationId: "", // 当前工序id
  147. operationSort: 0, //当前工序排序号
  148. operationVO: data,
  149. orgId: "",
  150. processRouteId: route.params.id, //工艺路线id
  151. updated: "",
  152. updator: "",
  153. virtualCode: "",
  154. };
  155. };
  156. // 保存中间的工序列表
  157. const saveFlow = async () => {
  158. for (let i = 0; i < list2.value.length; i++) {
  159. list2.value[i].operationSort = i;
  160. list2.value[i].operationId = list2.value[i]?.operationVO?.id;
  161. list2.value[i].operation = list2.value[i]?.operationVO; //后端入参和返回不一样,在这里处理一下。
  162. if (i === list2.value.length - 1) {
  163. list2.value[i].nextOperationId = null;
  164. } else {
  165. list2.value[i].nextOperationId = list2.value[i + 1]?.operationVO?.id;
  166. }
  167. }
  168. let p = {
  169. processRouteId: route.params.id,
  170. routeOpList: list2.value,
  171. };
  172. let res = await saveProcessInRoute(p);
  173. // Elmessage.success("保存成功");
  174. loadProcessesFlow();
  175. };
  176. const loadTreeData = () => {
  177. processTreeList().then((res) => {
  178. list1.value = res.data ?? [];
  179. });
  180. };
  181. // 中间列表====================
  182. const list2 = ref([]);
  183. const selectIndex = ref(-1);
  184. const isChanged = ref(true); //如果中间列表发生了改变则不显示右侧信息
  185. // 点击中间列表事件,需要设置index和值
  186. const clickFlowItem = (item, index) => {
  187. if (isChanged.value) {
  188. ElMessage.warning("请先保存工序列表");
  189. return;
  190. }
  191. selectIndex.value = index;
  192. currentProcess.value = item.operationVO;
  193. };
  194. const clickDelete = (index) => {
  195. list2.value.splice(index, 1);
  196. onUpdate();
  197. };
  198. const onClone = () => {
  199. isChanged.value = true;
  200. tipContent.value = "请先保存工序列表,再选择工序进行编辑";
  201. };
  202. const onUpdate = () => {
  203. // 中间发生了改变调用
  204. selectIndex.value = -1;
  205. isChanged.value = true;
  206. tipContent.value = "请先保存工序列表,再选择工序进行编辑";
  207. };
  208. const getFlowNameClass = (index) => {
  209. return index === selectIndex.value ? "nameLabelSelect" : "nameLabelCommon";
  210. };
  211. const loadProcessesFlow = async () => {
  212. const res = await processesByRouteId(route.params.id);
  213. list2.value = res.data ?? [];
  214. isChanged.value = false;
  215. tipContent.value = "请选择需要编辑的工序";
  216. };
  217. // 右侧具体信息====================
  218. const formRef = ref(null);
  219. const currentProcess = ref({});
  220. const tipContent = ref("");
  221. const handleSubmit = () => {};
  222. const editProComponent = async () => {
  223. // saveFlow();
  224. let res = await updateProcess(currentProcess.value);
  225. ElMessage.success("保存成功");
  226. router.push({
  227. path: `/base/craftManagement/processCom/${currentProcess.value.id}`,
  228. query: { prodtCode: route.query.prodtCode, routeId: route.query.routeId },
  229. });
  230. };
  231. // 全局=======
  232. onMounted(() => {
  233. loadTreeData();
  234. loadProcessesFlow();
  235. });
  236. const getNameByDictType = (dictValue) => {
  237. let str = "";
  238. dicts?.workshop_section?.forEach((element) => {
  239. if (element?.dictValue === dictValue) {
  240. str = element?.dictLabel ?? "===";
  241. }
  242. });
  243. return str;
  244. };
  245. </script>
  246. <style lang="scss" scoped>
  247. .binContainer {
  248. height: calc(100vh - 165px);
  249. background-color: #f5f7f9;
  250. overflow-y: scroll;
  251. // background-color: white;
  252. padding: 0;
  253. display: flex;
  254. }
  255. .header {
  256. height: 50px;
  257. display: flex;
  258. background-color: #f5f7f9;
  259. justify-content: space-between;
  260. align-items: center;
  261. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  262. }
  263. .processTree {
  264. width: 220px;
  265. height: 100%;
  266. border-right: 1px solid rgba(0, 0, 0, 0.1);
  267. .treeChild {
  268. background: #f2f2f2;
  269. padding: 20px 8px 10px 8px;
  270. .childItem {
  271. width: 100%;
  272. height: 28px;
  273. background: #ffffff;
  274. border-radius: 4px 4px 4px 4px;
  275. border: 1px solid rgba(35, 32, 50, 0.1);
  276. margin-bottom: 10px;
  277. text-align: center;
  278. }
  279. }
  280. }
  281. .flowBox {
  282. flex: 1;
  283. display: flex;
  284. justify-content: center;
  285. overflow-y: auto;
  286. padding-top: 47px;
  287. padding-bottom: 47px;
  288. .flowContain {
  289. width: 400px;
  290. min-height: 200px;
  291. }
  292. .flowItem {
  293. height: 50px;
  294. width: 400px;
  295. margin-bottom: 20px;
  296. display: flex;
  297. justify-content: space-between;
  298. position: relative;
  299. .indexLabel {
  300. line-height: 50px;
  301. font-size: 14px;
  302. color: #6e7993;
  303. text-align: left;
  304. }
  305. .nameLabelCommon {
  306. width: 299px;
  307. line-height: 50px;
  308. background: #ffffff;
  309. box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.5);
  310. border-radius: 4px 4px 4px 4px;
  311. border: 1px solid #232032;
  312. text-align: center;
  313. }
  314. .nameLabelSelect {
  315. width: 299px;
  316. line-height: 50px;
  317. background: rgba(10, 89, 247, 0.2);
  318. box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.5);
  319. border-radius: 4px 4px 4px 4px;
  320. border: 2px solid #0a59f7;
  321. text-align: center;
  322. }
  323. .flowDelete {
  324. width: 1em;
  325. height: 1em;
  326. color: red;
  327. visibility: hidden;
  328. }
  329. .arrow {
  330. position: absolute;
  331. width: 10px;
  332. height: 18px;
  333. top: 50px;
  334. left: 50%;
  335. }
  336. }
  337. .flowItem:hover {
  338. .flowDelete {
  339. visibility: visible;
  340. }
  341. }
  342. }
  343. .detailInfo {
  344. width: 320px;
  345. height: 100%;
  346. border-left: 1px solid rgba(0, 0, 0, 0.1);
  347. .editProcces {
  348. display: flex;
  349. justify-content: center;
  350. margin-top: 15px;
  351. }
  352. }
  353. .title {
  354. line-height: 44px;
  355. color: #6f7991;
  356. font-size: 14px;
  357. font-weight: bold;
  358. text-align: left;
  359. margin-left: 20px;
  360. }
  361. .title2 {
  362. color: #232032;
  363. font-size: 14px;
  364. text-align: left;
  365. margin-left: 19px;
  366. }
  367. .tipContent {
  368. width: 100%;
  369. text-align: center;
  370. margin-top: 20px;
  371. color: #e6a23c;
  372. }
  373. </style>
  374. <style>
  375. .el-collapse-item__content {
  376. padding: 0;
  377. }
  378. </style>