create.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. <template>
  2. <ele-modal
  3. :visible.sync="visible"
  4. v-if="visible"
  5. :title="title"
  6. width="75vw"
  7. append-to-body
  8. @close="cancel"
  9. :maxable="true"
  10. >
  11. <!-- <div class="switch" v-if="type == 'detail'">
  12. <div class="switch_left">
  13. <ul>
  14. <li
  15. v-for="item in tabOptions"
  16. :key="item.key"
  17. :class="{ active: activeComp == item.key }"
  18. @click="activeComp = item.key"
  19. >
  20. {{ item.name }}
  21. </li>
  22. </ul>
  23. </div>
  24. </div> -->
  25. <el-form
  26. ref="form"
  27. :model="form"
  28. :rules="rules"
  29. label-width="100px"
  30. class="create-form"
  31. >
  32. <headerTitle title="基本信息" style="margin-top: 15px"></headerTitle>
  33. <el-row :gutter="15">
  34. <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
  35. <el-form-item label="类型:" prop="type">
  36. <DictSelection
  37. dictName="请托类型"
  38. v-model="form.type"
  39. :disabled="type == 'detail'"
  40. ></DictSelection>
  41. </el-form-item>
  42. </el-col>
  43. <el-col :span="6">
  44. <el-form-item label="紧急程度:" prop="priority">
  45. <el-select
  46. style="width: 100%"
  47. v-model="form.priority"
  48. placeholder="请选择"
  49. clearable
  50. :disabled="type == 'detail'"
  51. >
  52. <el-option
  53. v-for="item in options"
  54. :key="item.value"
  55. :label="item.name"
  56. :value="item.value"
  57. >
  58. </el-option>
  59. </el-select>
  60. </el-form-item>
  61. </el-col>
  62. <el-col v-bind="styleResponsive ? { lg: 6, md: 24 } : { span: 6 }">
  63. <el-form-item label="名称:" prop="name">
  64. <el-input v-model="form.name" :disabled="type == 'detail'" />
  65. </el-form-item>
  66. </el-col>
  67. <el-col :span="6">
  68. <el-form-item label="请托部门:" prop="pleaseEntrustDeptName">
  69. <el-input v-model="form.pleaseEntrustDeptName" clearable disabled>
  70. </el-input>
  71. </el-form-item>
  72. </el-col>
  73. <el-col :span="6">
  74. <el-form-item label="请托人:" prop="pleaseEntrustUserId">
  75. <el-input v-model="form.pleaseEntrustUserName" clearable disabled />
  76. </el-form-item>
  77. </el-col>
  78. <el-col v-bind="styleResponsive ? { lg: 6, md: 8 } : { span: 6 }">
  79. <el-form-item label="所属工厂:" prop="factoriesName">
  80. <el-input v-model="form.factoriesName" style="width: 100%" disabled>
  81. </el-input>
  82. </el-form-item>
  83. </el-col>
  84. <el-col :span="6">
  85. <el-form-item label="受托工厂:" prop="beEntrustedFactoriesId">
  86. <el-select
  87. style="width: 100%"
  88. v-model="form.beEntrustedFactoriesId"
  89. placeholder="请选择"
  90. clearable
  91. :disabled="type == 'detail'"
  92. >
  93. <el-option
  94. v-for="item in factoryList"
  95. :key="item.id"
  96. :label="item.name"
  97. :value="item.id"
  98. @click.native="factoryListChange(item)"
  99. >
  100. </el-option>
  101. </el-select>
  102. </el-form-item>
  103. </el-col>
  104. <el-col :span="6">
  105. <el-form-item label="受托部门:" prop="beEntrustedDeptId">
  106. <deptSelect
  107. :disabled="type == 'detail'"
  108. v-model="form.beEntrustedDeptId"
  109. @changeGroup="beEntrustedDeptIdChange"
  110. />
  111. </el-form-item>
  112. </el-col>
  113. <el-col :span="6">
  114. <el-form-item label="是否尾工序:" prop="isLast">
  115. <el-radio-group v-model="form.isLast" :disabled="type == 'detail'">
  116. <el-radio :label="1">是</el-radio>
  117. <el-radio :label="0">否</el-radio>
  118. </el-radio-group>
  119. </el-form-item>
  120. </el-col>
  121. <!-- <el-col :span="6">
  122. <el-form-item label="完成时间:" prop="finishTime">
  123. <el-date-picker
  124. style="width: 100%"
  125. v-model="form.finishTime"
  126. type="date"
  127. value-format="yyyy-MM-dd"
  128. :disabled="type == 'detail'"
  129. ></el-date-picker>
  130. </el-form-item>
  131. </el-col>
  132. <el-col v-bind="styleResponsive ? { lg: 24, md: 24 } : { span: 24 }">
  133. <el-form-item label="需求描述:">
  134. <el-input
  135. v-model="form.describes"
  136. type="textarea"
  137. :rows="2"
  138. :disabled="type == 'detail'"
  139. />
  140. </el-form-item>
  141. </el-col> -->
  142. </el-row>
  143. <headerTitle title="产品信息" style="margin-top: 15px"></headerTitle>
  144. <el-button
  145. size="small"
  146. type="primary"
  147. icon="el-icon-plus"
  148. class="ele-btn-icon"
  149. @click="addOder"
  150. v-if="type != 'detail' && type != 'edit'"
  151. style="margin-bottom: 10px"
  152. >
  153. 新建
  154. </el-button>
  155. <el-button
  156. size="small"
  157. type="danger"
  158. icon="el-icon-delete"
  159. class="ele-btn-icon"
  160. @click="removeOder"
  161. v-if="type != 'detail' && type != 'edit'"
  162. plain
  163. style="margin-bottom: 10px"
  164. >
  165. 删除
  166. </el-button>
  167. <ele-pro-table
  168. ref="entrustCreateTable"
  169. :columns="columns"
  170. :datasource="orderList"
  171. :selection.sync="selection"
  172. :current.sync="current"
  173. highlight-current-row
  174. row-key="id"
  175. height="40vh"
  176. >
  177. <template v-slot:totalCountHead="{ column }">
  178. <div>
  179. <span class="is-required">{{ column.label }}</span>
  180. </div>
  181. </template>
  182. <template v-slot:taskIdHead="{ column }">
  183. <div>
  184. <span class="is-required">{{ column.label }}</span>
  185. </div>
  186. </template>
  187. <template v-slot:planDeliveryTimeHead="{ column }">
  188. <div>
  189. <span class="is-required">{{ column.label }}</span>
  190. </div>
  191. </template>
  192. <template v-slot:totalCount="{ row }">
  193. <el-input v-model="row.totalCount" :disabled="type == 'detail'">
  194. <template slot="append">{{ row.measuringUnit }}</template>
  195. </el-input>
  196. </template>
  197. <template v-slot:describes="{ row }">
  198. <el-input v-model="row.describes" :disabled="type == 'detail'">
  199. </el-input>
  200. </template>
  201. <template v-slot:taskId="{ row, $index }">
  202. <el-select
  203. clearable
  204. filterable
  205. style="width: 100%"
  206. v-model="row.taskId"
  207. placeholder="请选择"
  208. @change="taskListChange(row, $index)"
  209. :disabled="type == 'detail'"
  210. >
  211. <el-option
  212. v-for="item in row.taskList"
  213. :label="item.name"
  214. :value="item.id"
  215. :key="item.id"
  216. >
  217. </el-option>
  218. </el-select>
  219. </template>
  220. <template v-slot:planDeliveryTime="{ row }">
  221. <el-date-picker
  222. v-model="row.planDeliveryTime"
  223. type="datetime"
  224. placeholder="选择日期时间"
  225. format="yyyy-MM-dd HH:mm:ss"
  226. value-format="yyyy-MM-dd HH:mm:ss"
  227. :disabled="type == 'detail'"
  228. >
  229. </el-date-picker>
  230. </template>
  231. </ele-pro-table>
  232. </el-form>
  233. <template v-slot:footer v-if="type != 'detail'">
  234. <el-button @click="cancel">取消</el-button>
  235. <el-button type="primary" @click="save(1)"> 保存 </el-button>
  236. <el-button type="primary" @click="save(2)"> 提交 </el-button>
  237. </template>
  238. <!-- <detail
  239. v-if="activeComp === 'bpm' && form.processInstanceId"
  240. :id="form.processInstanceId"
  241. ></detail> -->
  242. <produceOrder ref="produceOrderRef" @choose="choose" />
  243. </ele-modal>
  244. </template>
  245. <script>
  246. import {
  247. save,
  248. addSubmit,
  249. pleaseEntrustDetail,
  250. update
  251. } from '@/api/entrust/index';
  252. import produceOrder from './produceOrder';
  253. import detail from '@/views/bpm/processInstance/detail.vue';
  254. import deptSelect from '@/components/CommomSelect/dept-select.vue';
  255. import { getProduceTaskList } from '@/api/aps';
  256. import warehouseDefinition from '@/api/warehouseManagement/warehouseDefinition';
  257. const defaultForm = function () {
  258. return {
  259. createTime: '', //创建时间
  260. code: '', //编码
  261. name: '', //名称
  262. workOrderCode: '', //工单编码
  263. pleaseEntrustUserId: '', //请托人id
  264. pleaseEntrustUserName: '', //请托人名称
  265. pleaseEntrustDeptId: '', //请托人部门id
  266. pleaseEntrustDeptName: '', //请托人部门名称
  267. beEntrustedDeptId: '', //受托人部门id
  268. beEntrustedDeptName: '', //受托人部门名称
  269. produceRoutingId: null,
  270. produceRoutingName: '',
  271. procedureList: [],
  272. pleaseEntrustObjList: [], //具体请托对象
  273. type: '', //类型
  274. status: '',
  275. describes: '', //描述
  276. finishTime: '', //完成时间
  277. processInstanceId: '', //流程实例id
  278. factoriesName: '',
  279. factoriesId: '',
  280. priority: '',
  281. beEntrustedFactoriesId: '', //受托工厂id
  282. beEntrustedFactoriesName: '', //受托工厂名称
  283. id: '',
  284. isLast: 0
  285. };
  286. };
  287. export default {
  288. components: { produceOrder, detail, deptSelect },
  289. data() {
  290. return {
  291. visible: false,
  292. loading: null,
  293. activeComp: 'main',
  294. planType: [
  295. { label: '所有计划类型', value: null },
  296. { label: '内销计划', value: '1' },
  297. { label: '外销计划', value: '2' },
  298. { label: '预制计划', value: '3' }
  299. ],
  300. options: [
  301. {
  302. name: '一般',
  303. value: 1
  304. },
  305. {
  306. name: '紧急',
  307. value: 2
  308. }
  309. ],
  310. tabOptions: [
  311. { key: 'main', name: '异常详情' },
  312. { key: 'bpm', name: '流程详情' }
  313. ],
  314. form: { ...defaultForm() },
  315. // 表单验证规则
  316. rules: {
  317. type: [{ required: true, message: '请选择', trigger: 'change' }],
  318. name: [{ required: true, message: '请输入', trigger: 'change' }],
  319. workOrderCode: [
  320. { required: true, message: '请选择', trigger: 'change' }
  321. ],
  322. beEntrustedDeptId: [
  323. { required: true, message: '请选择', trigger: 'change' }
  324. ],
  325. finishTime: [
  326. { required: true, message: '请选择', trigger: 'change' }
  327. ],
  328. beEntrustedFactoriesId: [
  329. { required: true, message: '请选择', trigger: 'change' }
  330. ],
  331. isLast: [{ required: true, message: '请选择', trigger: 'change' }]
  332. },
  333. type: '',
  334. title: '创建',
  335. produceTaskList: [],
  336. factoryList: [],
  337. orderList: [],
  338. selection: [],
  339. current: null,
  340. columns: [
  341. {
  342. width: 45,
  343. type: 'selection',
  344. columnKey: 'selection',
  345. align: 'center',
  346. reserveSelection: true
  347. },
  348. {
  349. columnKey: 'index',
  350. label: '序号',
  351. type: 'index',
  352. width: 55,
  353. align: 'center',
  354. showOverflowTooltip: true,
  355. fixed: 'left'
  356. },
  357. {
  358. prop: 'categoryName',
  359. label: '产品名称',
  360. align: 'center',
  361. minWidth: 110,
  362. showOverflowTooltip: true
  363. },
  364. // {
  365. // prop: 'apsWorkOrderCode',
  366. // label: '生产订单号',
  367. // slot: 'apsWorkOrderCode',
  368. // align: 'center',
  369. // minWidth: 110,
  370. // showOverflowTooltip: true
  371. // },
  372. {
  373. prop: 'productionPlanCode',
  374. label: '计划编号',
  375. align: 'center',
  376. minWidth: 110,
  377. showOverflowTooltip: true
  378. },
  379. {
  380. prop: 'brandNum',
  381. label: '牌号',
  382. align: 'center',
  383. minWidth: 110,
  384. showOverflowTooltip: true
  385. },
  386. {
  387. prop: 'batchNo',
  388. label: '批次号',
  389. align: 'center',
  390. minWidth: 110,
  391. showOverflowTooltip: true
  392. },
  393. {
  394. prop: 'describes',
  395. slot: 'describes',
  396. label: '需求描述',
  397. align: 'center',
  398. minWidth: 110,
  399. showOverflowTooltip: true
  400. },
  401. {
  402. prop: 'totalCount',
  403. slot: 'totalCount',
  404. label: '请托数量',
  405. align: 'center',
  406. minWidth: 140,
  407. showOverflowTooltip: true,
  408. headerSlot: 'totalCountHead'
  409. },
  410. {
  411. prop: 'planType',
  412. label: '计划类型',
  413. align: 'center',
  414. minWidth: 110,
  415. showOverflowTooltip: true,
  416. formatter: (row) => {
  417. const obj = this.planType.find((i) => i.value == row.planType);
  418. return obj && obj.label;
  419. }
  420. },
  421. {
  422. prop: 'workOrderCode',
  423. label: '生产工单号',
  424. align: 'center',
  425. minWidth: 110,
  426. showOverflowTooltip: true
  427. },
  428. {
  429. prop: 'specification',
  430. label: '规格',
  431. align: 'center',
  432. minWidth: 110,
  433. showOverflowTooltip: true
  434. },
  435. // {
  436. // prop: 'name',
  437. // label: '名称',
  438. // width: 130,
  439. // showOverflowTooltip: true,
  440. // align: 'center'
  441. // },
  442. {
  443. prop: 'modelType',
  444. label: '型号',
  445. align: 'center',
  446. minWidth: 110,
  447. showOverflowTooltip: true
  448. },
  449. {
  450. prop: 'produceRoutingName',
  451. label: '工艺路线',
  452. align: 'center',
  453. showOverflowTooltip: true
  454. },
  455. {
  456. prop: 'bomType',
  457. label: 'BOM分类',
  458. align: 'center',
  459. showOverflowTooltip: true,
  460. formatter: (row) => {
  461. if (row.bomType == 1) {
  462. return '产品(PBOM)';
  463. }
  464. if (row.bomType == 2) {
  465. return '加工(MBOM)';
  466. }
  467. if (row.bomType == 3) {
  468. return '装配(ABOM)';
  469. }
  470. return '';
  471. }
  472. },
  473. {
  474. prop: 'bomCategoryVersions',
  475. label: 'BOM版本',
  476. align: 'center',
  477. width: 130,
  478. showOverflowTooltip: true,
  479. formatter: (row) => {
  480. if (row.bomCategoryName) {
  481. return `${row.bomCategoryName} (V${row.bomCategoryVersions}.0)`;
  482. }
  483. return '';
  484. }
  485. },
  486. {
  487. prop: 'taskId',
  488. slot: 'taskId',
  489. label: '工序',
  490. align: 'center',
  491. minWidth: 150,
  492. showOverflowTooltip: true,
  493. headerSlot: 'taskIdHead'
  494. },
  495. {
  496. prop: 'categoryCode',
  497. label: '编码',
  498. align: 'center',
  499. showOverflowTooltip: true
  500. },
  501. {
  502. prop: 'planDeliveryTime',
  503. slot: 'planDeliveryTime',
  504. label: '完成日期',
  505. align: 'center',
  506. minWidth: 260,
  507. headerSlot: 'planDeliveryTimeHead'
  508. },
  509. {
  510. prop: 'planStartTime',
  511. label: '计划开始时间',
  512. align: 'center',
  513. showOverflowTooltip: true,
  514. minWidth: 130,
  515. sortable: true
  516. },
  517. {
  518. prop: 'planCompleteTime',
  519. label: '计划结束时间',
  520. align: 'center',
  521. showOverflowTooltip: true,
  522. minWidth: 130,
  523. sortable: true
  524. },
  525. {
  526. prop: 'startTime',
  527. label: '工单开始时间',
  528. align: 'center',
  529. showOverflowTooltip: true,
  530. minWidth: 130,
  531. sortable: true
  532. },
  533. {
  534. prop: 'completeTime',
  535. label: '工单结束时间',
  536. align: 'center',
  537. showOverflowTooltip: true,
  538. minWidth: 130,
  539. sortable: true
  540. }
  541. // {
  542. // prop: 'priority',
  543. // label: '优先级',
  544. // align: 'center',
  545. // minWidth: 120
  546. // }
  547. ]
  548. };
  549. },
  550. computed: {
  551. // 是否开启响应式布局
  552. styleResponsive() {
  553. return this.$store.state.theme.styleResponsive;
  554. }
  555. },
  556. created() {
  557. this.getFactoryList();
  558. },
  559. methods: {
  560. open(type, row) {
  561. this.visible = true;
  562. this.orderList = [];
  563. if (type == 'add') {
  564. this.form.pleaseEntrustDeptName =
  565. this.$store.state.user.info.groupName;
  566. this.form.pleaseEntrustDeptId = this.$store.state.user.info.groupId;
  567. this.form.pleaseEntrustUserName = this.$store.state.user.info.name;
  568. this.form.pleaseEntrustUserId = this.$store.state.user.info.userId;
  569. const data = this.factoryList.filter(
  570. (it) => it.factoryId == this.$store.state.user.info.factoryId
  571. );
  572. if (data.length != 0) {
  573. this.form.factoriesId = data[0].factoryId;
  574. this.form.factoriesName = data[0].factoryName;
  575. }
  576. } else if (type == 'edit' || type == 'detail') {
  577. this.getDetail(row.id);
  578. }
  579. this.type = type;
  580. this.title = type == 'add' ? '新增' : type == 'edit' ? '修改' : '详情';
  581. },
  582. addOder() {
  583. this.$refs.produceOrderRef.open(this.orderList);
  584. },
  585. async getDetail(id) {
  586. try {
  587. const res = await pleaseEntrustDetail(id);
  588. const data = res?.data || {};
  589. // 从 data 中结构需要的字段
  590. const {
  591. applyDeptName,
  592. applyDeptId,
  593. createUserName,
  594. createUserId,
  595. applyFactoriesId,
  596. applyFactoriesName,
  597. beEntrustedDeptId,
  598. beEntrustedDeptName,
  599. beEntrustedFactoriesName,
  600. beEntrustedFactoriesId,
  601. name,
  602. type,
  603. priority,
  604. id: dataId
  605. } = data;
  606. // 一次性合并到 form
  607. Object.assign(this.form, {
  608. pleaseEntrustDeptName: applyDeptName,
  609. pleaseEntrustDeptId: applyDeptId,
  610. pleaseEntrustUserName: createUserName,
  611. pleaseEntrustUserId: createUserId,
  612. factoriesId: applyFactoriesId,
  613. factoriesName: applyFactoriesName,
  614. beEntrustedDeptId,
  615. beEntrustedDeptName,
  616. beEntrustedFactoriesName,
  617. beEntrustedFactoriesId,
  618. name,
  619. type,
  620. priority,
  621. id: dataId
  622. });
  623. // 深拷贝时添加 taskList
  624. const newData = {
  625. ...this.deepCopy(data),
  626. taskList: []
  627. };
  628. this.orderList.push(newData);
  629. await this.getOrderTaskList();
  630. } catch (error) {
  631. console.error('加载委托详情失败:', error);
  632. }
  633. },
  634. removeOder() {
  635. this.$confirm('此操作将删除这些工单, 是否继续?', '提示', {
  636. confirmButtonText: '确定',
  637. cancelButtonText: '取消',
  638. type: 'warning'
  639. })
  640. .then(() => {
  641. for (let item of this.selection) {
  642. const index = this.orderList.findIndex((it) => it.id == item.id);
  643. this.orderList.splice(index, 1);
  644. }
  645. })
  646. .catch(() => {});
  647. },
  648. beEntrustedDeptIdChange(val, row) {
  649. this.form.beEntrustedDeptName = row.name;
  650. },
  651. factoryListChange(row) {
  652. this.form.beEntrustedFactoriesName = row.name;
  653. },
  654. async getFactoryList() {
  655. const { list } = await warehouseDefinition.getFactoryarea({
  656. pageNum: 1,
  657. size: 999,
  658. type: 1
  659. });
  660. this.factoryList = list || [];
  661. },
  662. cancel() {
  663. this.form = { ...defaultForm() };
  664. this.produceTaskList = [];
  665. this.visible = false;
  666. },
  667. choose(list) {
  668. if (!list || list.length === 0) {
  669. this.orderList = [];
  670. return;
  671. }
  672. const getKey = (item) => item.id;
  673. const newKeys = new Set(list.map(getKey));
  674. const oldKeys = new Set(this.orderList.map(getKey));
  675. const keptOldList = this.orderList.filter((oldItem) =>
  676. newKeys.has(getKey(oldItem))
  677. );
  678. const addedItems = list.filter((item) => !oldKeys.has(getKey(item)));
  679. const newList = addedItems.map((item) => {
  680. const copy = this.deepCopy(item);
  681. Object.assign(copy, {
  682. describes: '',
  683. totalCount: copy.formingNum,
  684. taskList: [],
  685. taskId: '',
  686. taskName: '',
  687. beEntrustedFactoriesId: '',
  688. beEntrustedFactoriesName: '',
  689. status: '',
  690. beEntrustedDeptName: '',
  691. beEntrustedDeptId: '',
  692. measuringUnit: copy.unit,
  693. categoryName: copy.productName,
  694. categoryCode: copy.productCode,
  695. workOrderId: copy.id,
  696. workOrderCode: copy.code,
  697. brandNum: copy.brandNo,
  698. modelType: copy.model,
  699. name: '',
  700. type: '',
  701. workOrderCode: copy.code,
  702. planDeliveryTime: copy.startTime,
  703. applyDeptId: this.form.pleaseEntrustDeptId,
  704. applyDeptName: this.form.pleaseEntrustDeptName,
  705. applyFactoriesId: this.form.factoriesId,
  706. applyFactoriesName: this.form.factoriesName
  707. });
  708. return copy;
  709. });
  710. this.orderList = [...keptOldList, ...newList];
  711. this.getOrderTaskList();
  712. },
  713. async getOrderTaskList() {
  714. for (const item of this.orderList) {
  715. const res = await getProduceTaskList({
  716. isDetail: true,
  717. pageNum: 1,
  718. routingId: item.produceRoutingId,
  719. size: -1
  720. });
  721. item.taskList = res.list;
  722. }
  723. },
  724. deepCopy(obj, hash = new WeakMap()) {
  725. if (obj === null) return null;
  726. if (obj instanceof Date) return new Date(obj);
  727. if (obj instanceof RegExp) return new RegExp(obj);
  728. if (typeof obj !== 'object' && typeof obj !== 'function') return obj;
  729. if (hash.has(obj)) return hash.get(obj);
  730. const result = Array.isArray(obj) ? [] : {};
  731. hash.set(obj, result);
  732. return Object.keys(obj).reduce((acc, key) => {
  733. acc[key] = this.deepCopy(obj[key], hash);
  734. return acc;
  735. }, result);
  736. },
  737. taskListChange(item, index) {
  738. const data = item.taskList.filter((it) => it.id == item.taskId);
  739. this.orderList[index].taskName = data[0].name;
  740. },
  741. save(type) {
  742. this.$refs.form.validate((valid) => {
  743. if (!valid) {
  744. return false;
  745. }
  746. if (this.orderList.length == 0) {
  747. return this.$message.warning('请添加产品信息');
  748. }
  749. for (let item of this.orderList) {
  750. if (!item.totalCount) {
  751. return this.$message.warning('请托数量不能为空');
  752. }
  753. if (!item.taskId) {
  754. return this.$message.warning('工序不能为空');
  755. }
  756. if (!item.planDeliveryTime) {
  757. return this.$message.warning('完成日期不能为空');
  758. }
  759. }
  760. this.orderList.forEach((item) => {
  761. item.beEntrustedFactoriesId = this.form.beEntrustedFactoriesId;
  762. item.beEntrustedFactoriesName = this.form.beEntrustedFactoriesName;
  763. item.beEntrustedDeptName = this.form.beEntrustedDeptName;
  764. item.beEntrustedDeptId = this.form.beEntrustedDeptId;
  765. item.isLast = this.form.isLast;
  766. item.name = this.form.name;
  767. item.type = this.form.type;
  768. item.status = type == 1 ? 0 : 1;
  769. item.approvalStatus = type == 1 ? 0 : 1;
  770. });
  771. let URL;
  772. const clearOrderIds = () => {
  773. this.orderList.forEach((it) => (it.id = ''));
  774. };
  775. if (type === 1) {
  776. URL = this.type === 'edit' ? update : save;
  777. } else {
  778. URL = addSubmit;
  779. }
  780. if (this.type === 'add' && (type !== 1 || type === 1)) {
  781. clearOrderIds();
  782. }
  783. this.loading = this.$loading({
  784. lock: true,
  785. text: '加载中',
  786. background: 'rgba(0, 0, 0, 0.7)'
  787. });
  788. URL(this.orderList)
  789. .then((res) => {
  790. this.loading.close();
  791. this.$message.success('成功');
  792. this.cancel();
  793. this.$emit('refresh');
  794. })
  795. .catch((e) => {
  796. this.loading.close();
  797. });
  798. });
  799. }
  800. }
  801. };
  802. </script>
  803. <style lang="scss" scoped>
  804. .basic-details-title {
  805. margin: 10px 0;
  806. }
  807. .add-product {
  808. width: 100%;
  809. display: flex;
  810. align-items: center;
  811. justify-content: flex-end;
  812. font-size: 30px;
  813. color: #1890ff;
  814. margin: 10px 0;
  815. cursor: pointer;
  816. }
  817. .create-form .el-form-item {
  818. margin-bottom: 15px !important;
  819. }
  820. </style>