plan-edit-dialog.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. <template>
  2. <ele-modal :visible.sync="visible" @closed="cancel" :title="`${type == 'add' ? '创建' : '编辑'}配料计划`"
  3. custom-class="ele-dialog-form" :close-on-click-modal="false" :close-on-press-escape="false" width="80%"
  4. :maxable="true">
  5. <el-form :model="formData" ref="formRef" label-width="120px" class="ele-body" :rules="rules">
  6. <el-row :gutter="24">
  7. <el-col :span="8">
  8. <el-form-item label="需求类型" prop="demandType">
  9. <el-select v-model="formData.demandType" :key="formData.demandType" placeholder="请选择" style="width: 100%"
  10. :disabled="type == 'detail'">
  11. <el-option v-for="item in demandTypeList" :key="item.dictCode" :label="item.dictValue"
  12. :value="item.dictCode">
  13. </el-option>
  14. </el-select>
  15. </el-form-item>
  16. </el-col>
  17. <el-col :span="8">
  18. <el-form-item label="计划名称" prop="name">
  19. <el-input placeholder="请选择" v-model="formData.name" :readonly="type == 'detail'"></el-input>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="8">
  23. <el-form-item label="备注" prop="remark">
  24. <el-input placeholder="备注" v-model="formData.remark" :readonly="type == 'detail'"></el-input>
  25. </el-form-item>
  26. </el-col>
  27. </el-row>
  28. </el-form>
  29. <el-form :model="formData" ref="tableForm">
  30. <ele-pro-table ref="table" :needPage="false" :columns="columns" row-key="id" :expanded-row-keys="expandedRowKeys">
  31. <template v-slot:toolbar>
  32. <el-button size="small" type="primary" icon="el-icon-plus" class="ele-btn-icon" @click="saleAdd"
  33. v-if="type != 'detail'">
  34. 添加销售订单
  35. </el-button>
  36. </template>
  37. <template v-slot:code="{ row }">
  38. <el-input placeholder="请输入" readonly :value="row.code || row.salesOrderCode"></el-input>
  39. </template>
  40. <template v-slot:bomId="{ row }">
  41. <el-select v-model="row.bomId" placeholder="请选择" style="width: 100%" :disabled="type == 'detail'"
  42. @change="changeVersions(row)">
  43. <el-option v-for="item in row.bomCategoryList" :key="item.id" :label="'V' + item.versions + '.0'"
  44. :value="item.id">
  45. </el-option>
  46. </el-select>
  47. </template>
  48. <template v-slot:action="{ row, $index }" v-if="type != 'detail'">
  49. <template>
  50. <el-link type="primary" :underline="false" @click="categorySelect(row)">
  51. 添加物料
  52. </el-link>
  53. <el-popconfirm class="ele-action" title="确定要删除此销售订单吗?" @confirm="remove(row, $index)">
  54. <template v-slot:reference>
  55. <el-link type="danger" :underline="false" icon="el-icon-delete">
  56. 删除
  57. </el-link>
  58. </template>
  59. </el-popconfirm>
  60. </template>
  61. </template>
  62. <!-- 展开内容 -->
  63. <template v-slot:expand="{ row, $index }">
  64. <div class="batch-actions" v-if="row.materialList.length > 0">
  65. <el-button @click="batchUpdateDeliveryMethod">批量修改到货方式</el-button>
  66. </div>
  67. <div style="
  68. width: calc(100% - 95px);
  69. min-height: 60px;
  70. margin-left: 95px;
  71. " v-if="row.materialList.length > 0">
  72. <ele-pro-table :toolbar="false" toolsTheme="none" ref="table2" :need-page="false"
  73. :datasource="row.materialList" :columns="columns2" :key="row.sort + '-' + row.materialList.sort"
  74. @selection-change="handleSelectionChange">
  75. <template v-slot:sort="{ $index }">
  76. {{ $index + 1 }}
  77. </template>
  78. <template v-slot:unit="{ row }">
  79. {{ row.unit }}
  80. </template>
  81. <template v-slot:demandQuantity="{ row }">
  82. <el-input v-model="row.demandQuantity" placeholder="请输入" :readonly="type == 'detail'" @input="
  83. (value) =>
  84. (row.demandQuantity = value.replace(
  85. /^(-)*(\d+)\.(\d\d\d\d\d\d).*$/,
  86. '$1$2.$3'
  87. ))
  88. "></el-input>
  89. </template>
  90. <template v-slot:purchasingCycle="{ row }">
  91. {{ row.purchasingCycle }}{{ row.purchasingCycleUnit }}
  92. </template>
  93. <template v-slot:purchaseQuantity="{ row }">
  94. <el-input v-model="row.purchaseQuantity" placeholder="请输入" :readonly="type == 'detail'" @input="
  95. (value) =>
  96. (row.purchaseQuantity = value.replace(
  97. /^(-)*(\d+)\.(\d\d\d\d\d\d).*$/,
  98. '$1$2.$3'
  99. ))
  100. "></el-input>
  101. </template>
  102. <template v-slot:deliveryMethod="{ row, $index }">
  103. <el-select clearable class="ele-block" v-model="row.deliveryMethod" placeholder="请选择"
  104. :disabled="type == 'detail'">
  105. <el-option label="一次性到货" :value="1" @click.native="row.timeList = null" />
  106. <el-option label="分批到货" :value="2" @click.native="
  107. handleMethod(row, $index);
  108. row.requireDeliveryTime = null;
  109. " />
  110. </el-select>
  111. </template>
  112. <template v-slot:requireDeliveryTime="{ row, $index }">
  113. <el-date-picker style="width: 100%" clearable v-model="row.requireDeliveryTime" type="date"
  114. v-show="row.deliveryMethod == 1" value-format="yyyy-MM-dd" placeholder="请选择日期" :pickerOptions="{
  115. disabledDate: (time) =>
  116. time.getTime() <
  117. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  118. }" :readonly="type == 'detail'">
  119. </el-date-picker>
  120. <el-link type="primary" :underline="false" v-show="row.deliveryMethod == 2"
  121. @click.native="handleMethod(row, $index)">
  122. 设置分批时间
  123. </el-link>
  124. </template>
  125. <template v-slot:imgUrl="{ row }">
  126. <fileUpload v-model="row.imgUrl" module="main" :showLib="false" :limit="1"
  127. :disabled="type == 'detail'" />
  128. </template>
  129. <template v-slot:files="{ row }">
  130. <fileUpload v-model="row.files" module="main" :showLib="false" :limit="1"
  131. :disabled="type == 'detail'" />
  132. </template>
  133. <template v-slot:action="{ row }" v-if="type != 'detail'">
  134. <el-popconfirm class="ele-action" title="确定要删除当前物料吗?" @confirm="remove2(row)">
  135. <template v-slot:reference>
  136. <el-link type="danger" :underline="false" icon="el-icon-delete">
  137. 删除
  138. </el-link>
  139. </template>
  140. </el-popconfirm>
  141. </template>
  142. </ele-pro-table>
  143. </div>
  144. </template>
  145. </ele-pro-table>
  146. </el-form>
  147. <div slot="footer" v-if="type != 'detail'">
  148. <el-button @click="cancel">取消</el-button>
  149. <el-button type="primary" @click="confirm">保存</el-button>
  150. </div>
  151. <saleOrderPop ref="saleOrderRef" @chooseOrder="chooseOrder"></saleOrderPop>
  152. <ProductModal ref="productRefs" @chooseModal="chooseModal" />
  153. <ProductionVersion ref="versionRefs" @changeProduct="changeProduct"></ProductionVersion>
  154. <timeDialog ref="timeDialogRef" @chooseTime="chooseTime"></timeDialog>
  155. <ele-modal :visible.sync="batchVisible" title="批量选择" width="25vw" append-to-body @close="handleCancel"
  156. :maxable="true">
  157. <el-form :model="formData2" label-width="100px">
  158. <el-form-item label="到货方式" prop="deliveryMethod">
  159. <el-select clearable v-model="formData2.deliveryMethod" placeholder="请选择">
  160. <el-option label="一次性到货" :value="1" />
  161. <el-option label="分批到货" :value="2" @click.native="
  162. handleMethod();
  163. " />
  164. </el-select>
  165. </el-form-item>
  166. <el-form-item label="要求到货时间" prop="requireDeliveryTime">
  167. <el-date-picker clearable v-model="formData2.requireDeliveryTime" type="date"
  168. v-show="formData2.deliveryMethod == 1" value-format="yyyy-MM-dd" placeholder="请选择日期" :pickerOptions="{
  169. disabledDate: (time) =>
  170. time.getTime() <
  171. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  172. }">
  173. </el-date-picker>
  174. <el-link type="primary" :underline="false" v-show="formData2.deliveryMethod == 2"
  175. @click.native="handleMethod()">
  176. 设置分批时间
  177. </el-link>
  178. </el-form-item>
  179. </el-form>
  180. <template v-slot:footer>
  181. <el-button @click="handleCancel">取消</el-button>
  182. <el-button type="primary" @click="handleConfirm">确认</el-button>
  183. </template>
  184. </ele-modal>
  185. </ele-modal>
  186. </template>
  187. <script>
  188. import saleOrderPop from './saleOrderPop.vue';
  189. import ProductModal from './ProductModal.vue';
  190. import {
  191. listBomBySalesOrderIdsOverride,
  192. listBomByBomVersionId,
  193. listBomBySalesOrderId,
  194. save,
  195. getById
  196. } from '@/api/materialPlan/index';
  197. import ProductionVersion from '@/components/CreatePlan/ProductionVersion2.vue';
  198. import { getCode } from '@/api/codeManagement';
  199. import fileUpload from '@/components/addDoc/index.vue';
  200. import timeDialog from './timeDialog.vue';
  201. import dictMixins from '@/mixins/dictMixins';
  202. export default {
  203. components: {
  204. saleOrderPop,
  205. ProductModal,
  206. ProductionVersion,
  207. fileUpload,
  208. timeDialog
  209. },
  210. mixins: [dictMixins],
  211. data() {
  212. return {
  213. formData2: {
  214. deliveryMethod: 1,
  215. requireDeliveryTime: '',
  216. timeList: []
  217. },
  218. batchVisible: false,
  219. multipleSelection: [],
  220. visible: false,
  221. type: 'add',
  222. tableData: [],
  223. xsId: null,
  224. formData: {
  225. demandType: '1',
  226. name: '',
  227. remark: '',
  228. detailRemoveIds: [],
  229. materialRemoveIds: [],
  230. orderType: 1
  231. },
  232. demandTypeList: [
  233. {
  234. dictCode: '1',
  235. dictValue: '生产性物资采购'
  236. },
  237. {
  238. dictCode: '6',
  239. dictValue: '外协自供料采购'
  240. },
  241. {
  242. dictCode: '7',
  243. dictValue: '外协客供料采购'
  244. }
  245. ],
  246. expandedRowKeys: [],
  247. rules: {
  248. demandType: [
  249. {
  250. required: true,
  251. message: '请选择需求类型',
  252. trigger: ['blur', 'change']
  253. }
  254. ],
  255. name: [
  256. {
  257. required: true,
  258. message: '请输入配料计划名称',
  259. trigger: ['blur', 'change']
  260. }
  261. ]
  262. }
  263. };
  264. },
  265. computed: {
  266. // 表格列配置
  267. columns() {
  268. const list = [
  269. {
  270. width: 45,
  271. type: 'expand',
  272. columnKey: 'materialList',
  273. align: 'center',
  274. slot: 'expand'
  275. },
  276. {
  277. width: 50,
  278. label: '序号',
  279. type: 'index',
  280. align: 'center',
  281. slot: 'index'
  282. },
  283. {
  284. prop: 'purchaseType',
  285. label: '采购类型',
  286. align: 'center',
  287. showOverflowTooltip: true,
  288. minWidth: 120,
  289. sortable: true,
  290. formatter: (row) => {
  291. return row.purchaseType == '2' ? '已采购' : '未采购';
  292. }
  293. },
  294. {
  295. prop: 'code',
  296. label: '销售订单号',
  297. slot: 'code',
  298. showOverflowTooltip: true,
  299. align: 'center',
  300. minWidth: 170,
  301. sortable: true
  302. },
  303. {
  304. prop: 'customerName',
  305. label: '客户名称',
  306. align: 'center',
  307. showOverflowTooltip: true
  308. },
  309. {
  310. prop: 'serialNo',
  311. label: '客户代号',
  312. align: 'center',
  313. showOverflowTooltip: true
  314. },
  315. {
  316. prop: 'productCode',
  317. label: '编码',
  318. align: 'center',
  319. showOverflowTooltip: true,
  320. minWidth: 140
  321. },
  322. {
  323. prop: 'productName',
  324. label: '名称',
  325. align: 'center',
  326. minWidth: 120
  327. },
  328. {
  329. prop: 'model',
  330. label: '型号',
  331. align: 'center',
  332. minWidth: 120
  333. },
  334. {
  335. prop: 'brandNo',
  336. label: '牌号',
  337. align: 'center'
  338. },
  339. {
  340. prop: 'deliveryTime',
  341. label: '交付日期',
  342. align: 'center',
  343. showOverflowTooltip: true
  344. },
  345. {
  346. prop: 'contractNum',
  347. label: '订单数量',
  348. align: 'center'
  349. },
  350. {
  351. prop: 'lackNum',
  352. label: '欠交数量',
  353. align: 'center'
  354. },
  355. {
  356. prop: 'bomId',
  357. label: '选择BOM版本',
  358. slot: 'bomId',
  359. align: 'center',
  360. minWidth: 110
  361. },
  362. this.type != 'detail'
  363. ? {
  364. columnKey: 'action',
  365. label: '操作',
  366. width: 150,
  367. align: 'center',
  368. resizable: false,
  369. slot: 'action',
  370. showOverflowTooltip: true
  371. }
  372. : ''
  373. ].filter(Boolean);
  374. return list;
  375. },
  376. columns2() {
  377. const list = [
  378. {
  379. columnKey: 'selection',
  380. type: 'selection',
  381. width: 50,
  382. align: 'center',
  383. fixed: 'left'
  384. },
  385. {
  386. width: 50,
  387. label: '序号',
  388. prop: 'sort',
  389. slot: 'sort',
  390. align: 'center',
  391. fixed: 'left'
  392. },
  393. {
  394. label: '物料名称',
  395. prop: 'name',
  396. align: 'center',
  397. minWidth: 120,
  398. fixed: 'left'
  399. },
  400. {
  401. label: '物料编码',
  402. prop: 'code',
  403. align: 'center',
  404. minWidth: 120,
  405. fixed: 'left'
  406. },
  407. {
  408. label: '牌号',
  409. prop: 'brandNum',
  410. align: 'center'
  411. },
  412. {
  413. prop: 'specification',
  414. label: '规格',
  415. align: 'center',
  416. showOverflowTooltip: true,
  417. minWidth: 110
  418. },
  419. {
  420. label: '型号',
  421. prop: 'modelType',
  422. align: 'center'
  423. },
  424. {
  425. prop: 'inventoryQuantity',
  426. label: '库存',
  427. showOverflowTooltip: true
  428. },
  429. {
  430. prop: 'secureInventory',
  431. label: '安全库存',
  432. showOverflowTooltip: true
  433. },
  434. {
  435. prop: 'lockQuantity',
  436. label: '锁库数量',
  437. showOverflowTooltip: true
  438. },
  439. {
  440. prop: 'inTransitNum',
  441. label: '在途数量',
  442. showOverflowTooltip: true
  443. },
  444. {
  445. prop: 'inTransitOrdersNum',
  446. label: '在途已关联数量',
  447. showOverflowTooltip: true
  448. },
  449. {
  450. prop: 'availableQuantity',
  451. label: '可用数量',
  452. showOverflowTooltip: true
  453. },
  454. {
  455. prop: 'unit',
  456. label: '计量单位',
  457. showOverflowTooltip: true,
  458. action: 'unit',
  459. slot: 'unit'
  460. },
  461. {
  462. label: '需求数量',
  463. slot: 'demandQuantity',
  464. action: 'demandQuantity',
  465. align: 'center',
  466. minWidth: 120
  467. },
  468. {
  469. label: '采购数量',
  470. slot: 'purchaseQuantity',
  471. action: 'purchaseQuantity',
  472. align: 'center',
  473. minWidth: 120
  474. },
  475. {
  476. label: '采购周期',
  477. slot: 'purchasingCycle',
  478. action: 'purchasingCycle',
  479. align: 'center',
  480. minWidth: 160
  481. },
  482. {
  483. label: '到货方式',
  484. slot: 'deliveryMethod',
  485. action: 'deliveryMethod',
  486. align: 'center',
  487. minWidth: 140
  488. },
  489. {
  490. label: '要求到货时间',
  491. slot: 'requireDeliveryTime',
  492. action: 'requireDeliveryTime',
  493. align: 'center',
  494. minWidth: 180
  495. },
  496. {
  497. label: '图纸',
  498. slot: 'imgUrl',
  499. action: ' imgUrl',
  500. align: 'center',
  501. minWidth: 140
  502. },
  503. {
  504. label: '附件',
  505. slot: 'files',
  506. action: ' files',
  507. align: 'center',
  508. minWidth: 140
  509. },
  510. this.type != 'detail'
  511. ? {
  512. columnKey: 'action',
  513. label: '操作',
  514. width: 80,
  515. align: 'center',
  516. resizable: false,
  517. slot: 'action',
  518. showOverflowTooltip: true
  519. }
  520. : ''
  521. ].filter(Boolean);
  522. return list;
  523. }
  524. },
  525. created() { },
  526. methods: {
  527. async open(type, row) {
  528. this.type = type;
  529. this.formData.demandType = '1';
  530. if (this.type == 'add') {
  531. this.formData.demandType = '1';
  532. const name = await getCode('purchase_apply_plan_name');
  533. console.log(name, 'name')
  534. this.formData.name = name;
  535. }
  536. this.formData.orderType = 1;
  537. this.visible = true;
  538. if (row) {
  539. this.getDetail(row.id);
  540. } else {
  541. this.$nextTick(() => {
  542. this.$refs.table.setData([]);
  543. });
  544. }
  545. },
  546. getDetail(id) {
  547. getById(id).then((res) => {
  548. this.$set(this.formData, 'demandType', res.demandType);
  549. this.$set(this.formData, 'name', res.name);
  550. this.$set(this.formData, 'remark', res.remark);
  551. this.formData['id'] = res.id;
  552. if (res.salesOrderList) {
  553. this.$refs.table.setData([...res.salesOrderList]);
  554. // 展开所有行
  555. this.expandedRowKeys = this.$refs.table.getData()?.map((item) => item.id).filter(id => id != null);
  556. }
  557. this.$nextTick(() => {
  558. this.$refs.table.toggleRowExpansionAll();
  559. this.$forceUpdate();
  560. });
  561. });
  562. },
  563. saleAdd() {
  564. this.tableData = this.$refs.table.getData();
  565. this.$refs.saleOrderRef.open(this.tableData);
  566. },
  567. chooseOrder(list) {
  568. let salesOrderIds = [];
  569. const tableList = this.$refs.table.getData() || [];
  570. const existingIds = tableList.map(item => item.id);
  571. console.log(existingIds, '获取已存在的ID')
  572. const list1 = list.filter(item => !existingIds.includes(item.id));
  573. if (list1.length === 0) {
  574. this.$message.warning('所选订单已存在');
  575. return;
  576. }
  577. list1.forEach((m) => {
  578. salesOrderIds.push(m.id);
  579. });
  580. if (salesOrderIds.length > 0) {
  581. listBomBySalesOrderIdsOverride({ salesOrderIds: salesOrderIds, demandType: this.formData.demandType }).then(
  582. (res) => {
  583. res.forEach((m) => {
  584. console.log(m, 'm');
  585. if (m.materialList.length > 0) {
  586. m.materialList.forEach((p) => {
  587. p.detailId = m.id;
  588. });
  589. }
  590. });
  591. const finalData = res.filter(item =>
  592. !tableList.some(existing => existing.id === item.id)
  593. );
  594. console.log(finalData, 'finalData')
  595. this.$refs.table.setData([...tableList, ...finalData]);
  596. this.$nextTick(() => {
  597. this.expandedRowKeys = this.$refs.table.getData().map(item => item.id);
  598. this.$refs.table.toggleRowExpansionAll();
  599. });
  600. }
  601. );
  602. }
  603. },
  604. categorySelect(row) {
  605. this.$refs.productRefs.open(row.materialList, row, this.type);
  606. },
  607. remove(row, index) {
  608. this.formData.detailRemoveIds.push(row.id);
  609. let _arr = this.$refs.table.getData() || [];
  610. _arr.splice(index, 1);
  611. this.$refs.table.setData([..._arr]);
  612. },
  613. chooseModal(data, current) {
  614. data.map((m) => {
  615. m.detailId = current.id;
  616. delete m.id;
  617. return {
  618. ...m
  619. };
  620. });
  621. console.log(data, 'data');
  622. let tableList = [];
  623. tableList = this.$refs.table.getData();
  624. tableList.forEach((e) => {
  625. if (e.id == current.id) {
  626. if (e.materialList.length == 0) {
  627. e.materialList = data;
  628. } else {
  629. e.materialList = [...e.materialList, ...data];
  630. }
  631. }
  632. });
  633. console.log(tableList);
  634. this.$refs.table.setData([...tableList]);
  635. this.$forceUpdate();
  636. },
  637. remove2(row) {
  638. const data = this.$refs.table.getData() ?? [];
  639. this.formData.materialRemoveIds.push(row.categoryId);
  640. data.forEach((e) => {
  641. if (row.detailId == e.id) {
  642. e.materialList = e.materialList.filter(
  643. (d) => d.categoryId !== row.categoryId
  644. );
  645. }
  646. });
  647. this.$refs.table.setData([...data]);
  648. this.$forceUpdate();
  649. },
  650. changeVersions(row) {
  651. console.log(row, 'row')
  652. listBomByBomVersionId({ bomId: row.bomId, contractNum: row.contractNum, demandType: this.formData.demandType, salesCode: row.code, salesId: row.id }).then(
  653. (res) => {
  654. console.log(res, 'res')
  655. row.materialList = res || [];
  656. // this.$nextTick(() => {
  657. // this.$refs.table.toggleRowExpansionAll();
  658. // this.$forceUpdate();
  659. // });
  660. }
  661. );
  662. },
  663. //选择工艺路线
  664. openVersion(row) {
  665. this.xsId = row.id;
  666. this.$refs.versionRefs.open();
  667. },
  668. changeProduct(data) {
  669. const param = {
  670. salesOrderIds: [this.xsId],
  671. produceRoutingId: data.id
  672. };
  673. listBomBySalesOrderId(param).then((res) => {
  674. if (!res) return;
  675. const tableList = this.$refs.table.getData();
  676. tableList
  677. .forEach((e) => {
  678. if (e.id == this.xsId) {
  679. e.materialList = res.map((m) => {
  680. m.detailId = this.xsId;
  681. return {
  682. ...m
  683. };
  684. });
  685. this.$nextTick(() => {
  686. this.$refs.table.setData([...tableList]);
  687. this.$refs.table.toggleRowExpansionAll();
  688. });
  689. }
  690. })
  691. .catch((error) => {
  692. console.error('Failed to change product:', error);
  693. });
  694. });
  695. },
  696. // ---------------------------
  697. // 批量修改到货方式
  698. batchUpdateDeliveryMethod() {
  699. if (this.multipleSelection.length === 0) {
  700. this.$message.warning('请选择要修改的行');
  701. return;
  702. }
  703. this.formData2 = {
  704. deliveryMethod: 1,
  705. requireDeliveryTime: '',
  706. timeList: []
  707. };
  708. this.batchVisible = true;
  709. },
  710. // 处理表格选中行的变化
  711. handleSelectionChange(selection) {
  712. console.log(selection, 'sssssssselectionsssssss');
  713. this.multipleSelection = selection;
  714. },
  715. handleCancel() {
  716. this.batchVisible = false
  717. },
  718. handleConfirm() {
  719. const { deliveryMethod, requireDeliveryTime } = this.formData2;
  720. const tableData = this.$refs.table.getData();
  721. // 创建深拷贝的 timeList 模板(假设当前表单中已填写了分批时间)
  722. const timeListTemplate = JSON.parse(JSON.stringify(this.formData2.timeList));
  723. tableData.forEach((item) => {
  724. item.materialList.forEach((m) => {
  725. if (this.multipleSelection.some((selected) => selected.categoryId === m.categoryId)) {
  726. this.$set(m, 'deliveryMethod', deliveryMethod);
  727. if (deliveryMethod === 1) {
  728. //一次性到货逻辑
  729. this.$set(m, 'requireDeliveryTime', requireDeliveryTime)
  730. this.$set(m, 'timeList', null)
  731. } else if (deliveryMethod === 2) {
  732. this.$set(m, 'timeList', JSON.parse(JSON.stringify(timeListTemplate)));
  733. }
  734. }
  735. });
  736. });
  737. this.$refs.table.setData([...tableData]);
  738. this.batchVisible = false;
  739. },
  740. handleMethod(row, index) {
  741. console.log(index, 'index')
  742. if (row) {
  743. this.multipleSelection = [];
  744. }
  745. this.$refs.timeDialogRef.open(row || {}, index);
  746. },
  747. chooseTime(current, timeList, currentIndex) {
  748. const tableList = this.$refs.table.getData();
  749. if (current && current.categoryId) {
  750. // 单独修改逻辑:直接操作当前物料的 timeList
  751. tableList.forEach(item => {
  752. if (item.id === current.detailId) {
  753. const material = item.materialList[currentIndex];
  754. this.$set(material, 'timeList', JSON.parse(JSON.stringify(timeList)));
  755. }
  756. });
  757. } else if (this.multipleSelection.length > 0) {
  758. // 批量修改逻辑
  759. tableList.forEach(item => {
  760. item.materialList.forEach(material => {
  761. if (this.multipleSelection.some(selected => selected.categoryId === material.categoryId)) {
  762. this.$set(material, 'deliveryMethod', this.formData2.deliveryMethod)
  763. this.$set(material, 'timeList', JSON.parse(JSON.stringify(timeList)));
  764. }
  765. });
  766. });
  767. this.$refs.timeDialogRef.handleClose()
  768. this.batchVisible = false;
  769. }
  770. this.$refs.table.setData([...tableList]);
  771. },
  772. confirm() {
  773. this.$refs.formRef.validate(async (value) => {
  774. if (value) {
  775. let _arr = this.$refs.table.getData() ?? [];
  776. if (_arr.length == 0) {
  777. this.$message.info('请添加销售订单');
  778. return false;
  779. }
  780. let _arr2 = [];
  781. _arr2 = _arr.map((m) => {
  782. if (
  783. Object.prototype.hasOwnProperty.call(m, 'salesOrderId') &&
  784. m.salesOrderId
  785. ) {
  786. } else {
  787. m.salesOrderId = m.id;
  788. m.salesOrderCode = m.code;
  789. delete m.id;
  790. delete m.code;
  791. }
  792. return {
  793. ...m
  794. };
  795. });
  796. this.formData['type'] = 1;
  797. this.formData['salesOrderList'] = _arr2;
  798. this.formData.baitingType = 2;
  799. await save(this.formData);
  800. this.$message.success('保存成功!');
  801. this.$emit('success');
  802. this.cancel();
  803. }
  804. });
  805. },
  806. cancel() {
  807. this.visible = false;
  808. this.formData = {
  809. demandType: '1', // 增加默认值重置
  810. name: '',
  811. remark: '',
  812. detailRemoveIds: [],
  813. materialRemoveIds: [],
  814. orderType: 1
  815. };
  816. this.$refs.table.setData([]);
  817. this.$refs.formRef.resetFields();
  818. },
  819. }
  820. };
  821. </script>
  822. <style lang="scss" scoped>
  823. :deep(.el-table__expanded-cell) {
  824. padding-bottom: 30px !important;
  825. border-bottom: 12px solid #ccffcc !important;
  826. }
  827. .batch-actions {
  828. text-align: right;
  829. margin: 10px;
  830. }
  831. </style>