plan-edit-dialog.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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 fileUpload from '@/components/upload/fileUpload';
  199. import timeDialog from './timeDialog.vue';
  200. import dictMixins from '@/mixins/dictMixins';
  201. export default {
  202. components: {
  203. saleOrderPop,
  204. ProductModal,
  205. ProductionVersion,
  206. fileUpload,
  207. timeDialog
  208. },
  209. mixins: [dictMixins],
  210. data() {
  211. return {
  212. formData2: {
  213. deliveryMethod: 1,
  214. requireDeliveryTime: '',
  215. timeList: []
  216. },
  217. batchVisible: false,
  218. multipleSelection: [],
  219. visible: false,
  220. type: 'add',
  221. tableData: [],
  222. xsId: null,
  223. formData: {
  224. demandType: '1',
  225. name: '',
  226. remark: '',
  227. detailRemoveIds: [],
  228. materialRemoveIds: [],
  229. orderType: 1
  230. },
  231. demandTypeList: [
  232. {
  233. dictCode: '1',
  234. dictValue: '生产性物资采购'
  235. },
  236. {
  237. dictCode: '6',
  238. dictValue: '外协自供料采购'
  239. },
  240. {
  241. dictCode: '7',
  242. dictValue: '外协客供料采购'
  243. }
  244. ],
  245. expandedRowKeys: [],
  246. rules: {
  247. demandType: [
  248. {
  249. required: true,
  250. message: '请选择需求类型',
  251. trigger: ['blur', 'change']
  252. }
  253. ],
  254. name: [
  255. {
  256. required: true,
  257. message: '请输入配料计划名称',
  258. trigger: ['blur', 'change']
  259. }
  260. ]
  261. }
  262. };
  263. },
  264. computed: {
  265. // 表格列配置
  266. columns() {
  267. const list = [
  268. {
  269. width: 45,
  270. type: 'expand',
  271. columnKey: 'materialList',
  272. align: 'center',
  273. slot: 'expand'
  274. },
  275. {
  276. width: 50,
  277. label: '序号',
  278. type: 'index',
  279. align: 'center',
  280. slot: 'index'
  281. },
  282. {
  283. prop: 'purchaseType',
  284. label: '采购类型',
  285. align: 'center',
  286. showOverflowTooltip: true,
  287. minWidth: 120,
  288. sortable: true,
  289. formatter: (row) => {
  290. return row.purchaseType == '1' ? '未采购' : '已采购';
  291. }
  292. },
  293. {
  294. prop: 'code',
  295. label: '销售订单号',
  296. slot: 'code',
  297. showOverflowTooltip: true,
  298. align: 'center',
  299. minWidth: 170,
  300. sortable: true
  301. },
  302. {
  303. prop: 'customerName',
  304. label: '客户名称',
  305. align: 'center',
  306. showOverflowTooltip: true
  307. },
  308. {
  309. prop: 'serialNo',
  310. label: '客户代号',
  311. align: 'center',
  312. showOverflowTooltip: true
  313. },
  314. {
  315. prop: 'productCode',
  316. label: '编码',
  317. align: 'center',
  318. showOverflowTooltip: true,
  319. minWidth: 140
  320. },
  321. {
  322. prop: 'productName',
  323. label: '名称',
  324. align: 'center',
  325. minWidth: 120
  326. },
  327. {
  328. prop: 'model',
  329. label: '型号',
  330. align: 'center',
  331. minWidth: 120
  332. },
  333. {
  334. prop: 'brandNo',
  335. label: '牌号',
  336. align: 'center'
  337. },
  338. {
  339. prop: 'deliveryTime',
  340. label: '交付日期',
  341. align: 'center',
  342. showOverflowTooltip: true
  343. },
  344. {
  345. prop: 'contractNum',
  346. label: '订单数量',
  347. align: 'center'
  348. },
  349. {
  350. prop: 'lackNum',
  351. label: '欠交数量',
  352. align: 'center'
  353. },
  354. {
  355. prop: 'bomId',
  356. label: '选择BOM版本',
  357. slot: 'bomId',
  358. align: 'center',
  359. minWidth: 110
  360. },
  361. this.type != 'detail'
  362. ? {
  363. columnKey: 'action',
  364. label: '操作',
  365. width: 150,
  366. align: 'center',
  367. resizable: false,
  368. slot: 'action',
  369. showOverflowTooltip: true
  370. }
  371. : ''
  372. ].filter(Boolean);
  373. return list;
  374. },
  375. columns2() {
  376. const list = [
  377. {
  378. columnKey: 'selection',
  379. type: 'selection',
  380. width: 50,
  381. align: 'center',
  382. fixed: 'left'
  383. },
  384. {
  385. width: 50,
  386. label: '序号',
  387. prop: 'sort',
  388. slot: 'sort',
  389. align: 'center',
  390. fixed: 'left'
  391. },
  392. {
  393. label: '物料名称',
  394. prop: 'name',
  395. align: 'center',
  396. minWidth: 120,
  397. fixed: 'left'
  398. },
  399. {
  400. label: '物料编码',
  401. prop: 'code',
  402. align: 'center',
  403. minWidth: 120,
  404. fixed: 'left'
  405. },
  406. {
  407. label: '牌号',
  408. prop: 'brandNum',
  409. align: 'center'
  410. },
  411. {
  412. prop: 'specification',
  413. label: '规格',
  414. align: 'center',
  415. showOverflowTooltip: true,
  416. minWidth: 110
  417. },
  418. {
  419. label: '型号',
  420. prop: 'modelType',
  421. align: 'center'
  422. },
  423. {
  424. prop: 'inventoryQuantity',
  425. label: '库存',
  426. showOverflowTooltip: true
  427. },
  428. {
  429. prop: 'secureInventory',
  430. label: '安全库存',
  431. showOverflowTooltip: true
  432. },
  433. {
  434. prop: 'lockQuantity',
  435. label: '锁库数量',
  436. showOverflowTooltip: true
  437. },
  438. {
  439. prop: 'inTransitNum',
  440. label: '在途数量',
  441. showOverflowTooltip: true
  442. },
  443. {
  444. prop: 'inTransitOrdersNum',
  445. label: '在途已关联数量',
  446. showOverflowTooltip: true
  447. },
  448. {
  449. prop: 'availableQuantity',
  450. label: '可用数量',
  451. showOverflowTooltip: true
  452. },
  453. {
  454. prop: 'unit',
  455. label: '计量单位',
  456. showOverflowTooltip: true,
  457. action: 'unit',
  458. slot: 'unit'
  459. },
  460. {
  461. label: '需求数量',
  462. slot: 'demandQuantity',
  463. action: 'demandQuantity',
  464. align: 'center',
  465. minWidth: 120
  466. },
  467. {
  468. label: '采购数量',
  469. slot: 'purchaseQuantity',
  470. action: 'purchaseQuantity',
  471. align: 'center',
  472. minWidth: 120
  473. },
  474. {
  475. label: '采购周期',
  476. slot: 'purchasingCycle',
  477. action: 'purchasingCycle',
  478. align: 'center',
  479. minWidth: 160
  480. },
  481. {
  482. label: '到货方式',
  483. slot: 'deliveryMethod',
  484. action: 'deliveryMethod',
  485. align: 'center',
  486. minWidth: 140
  487. },
  488. {
  489. label: '要求到货时间',
  490. slot: 'requireDeliveryTime',
  491. action: 'requireDeliveryTime',
  492. align: 'center',
  493. minWidth: 180
  494. },
  495. {
  496. label: '图纸',
  497. slot: 'imgUrl',
  498. action: ' imgUrl',
  499. align: 'center',
  500. minWidth: 140
  501. },
  502. {
  503. label: '附件',
  504. slot: 'files',
  505. action: ' files',
  506. align: 'center',
  507. minWidth: 140
  508. },
  509. this.type != 'detail'
  510. ? {
  511. columnKey: 'action',
  512. label: '操作',
  513. width: 80,
  514. align: 'center',
  515. resizable: false,
  516. slot: 'action',
  517. showOverflowTooltip: true
  518. }
  519. : ''
  520. ].filter(Boolean);
  521. return list;
  522. }
  523. },
  524. created() { },
  525. methods: {
  526. async open(type, row) {
  527. this.type = type;
  528. this.formData.demandType = '1';
  529. if (this.type == 'add') {
  530. this.formData.demandType = '1';
  531. }
  532. this.formData.orderType = 1;
  533. this.visible = true;
  534. if (row) {
  535. this.getDetail(row.id);
  536. } else {
  537. this.$nextTick(() => {
  538. this.$refs.table.setData([]);
  539. });
  540. }
  541. },
  542. getDetail(id) {
  543. getById(id).then((res) => {
  544. this.$set(this.formData, 'demandType', res.demandType);
  545. this.$set(this.formData, 'name', res.name);
  546. this.$set(this.formData, 'remark', res.remark);
  547. this.formData['id'] = res.id;
  548. if (res.salesOrderList) {
  549. this.$refs.table.setData([...res.salesOrderList]);
  550. // 展开所有行
  551. this.expandedRowKeys = this.$refs.table
  552. .getData()
  553. ?.map((item) => item.id);
  554. }
  555. this.$nextTick(() => {
  556. this.$refs.table.toggleRowExpansionAll();
  557. this.$forceUpdate();
  558. });
  559. });
  560. },
  561. saleAdd() {
  562. this.tableData = this.$refs.table.getData();
  563. this.$refs.saleOrderRef.open(this.tableData);
  564. },
  565. chooseOrder(list) {
  566. let salesOrderIds = [];
  567. list.map((m) => {
  568. salesOrderIds.push(m.id);
  569. return {
  570. ...m
  571. };
  572. });
  573. if (salesOrderIds.length > 0) {
  574. listBomBySalesOrderIdsOverride({ salesOrderIds: salesOrderIds, demandType: this.formData.demandType }).then(
  575. (res) => {
  576. res.forEach((m) => {
  577. console.log(m, 'm');
  578. if (m.materialList.length > 0) {
  579. m.materialList.forEach((p) => {
  580. p.detailId = m.id;
  581. });
  582. }
  583. });
  584. console.log(res, 'res')
  585. this.$refs.table.setData([...this.tableData, ...res]);
  586. this.$nextTick(() => {
  587. this.$refs.table.toggleRowExpansionAll();
  588. this.$forceUpdate();
  589. });
  590. }
  591. );
  592. }
  593. },
  594. categorySelect(row) {
  595. this.$refs.productRefs.open(row.materialList, row, this.type);
  596. },
  597. remove(row, index) {
  598. this.formData.detailRemoveIds.push(row.id);
  599. let _arr = this.$refs.table.getData() || [];
  600. _arr.splice(index, 1);
  601. this.$refs.table.setData([..._arr]);
  602. },
  603. chooseModal(data, current) {
  604. data.map((m) => {
  605. m.detailId = current.id;
  606. delete m.id;
  607. return {
  608. ...m
  609. };
  610. });
  611. console.log(data, 'data');
  612. let tableList = [];
  613. tableList = this.$refs.table.getData();
  614. tableList.forEach((e) => {
  615. if (e.id == current.id) {
  616. if (e.materialList.length == 0) {
  617. e.materialList = data;
  618. } else {
  619. e.materialList = [...e.materialList, ...data];
  620. }
  621. }
  622. });
  623. console.log(tableList);
  624. this.$refs.table.setData([...tableList]);
  625. this.$forceUpdate();
  626. },
  627. remove2(row) {
  628. const data = this.$refs.table.getData() ?? [];
  629. this.formData.materialRemoveIds.push(row.categoryId);
  630. data.forEach((e) => {
  631. if (row.detailId == e.id) {
  632. e.materialList = e.materialList.filter(
  633. (d) => d.categoryId !== row.categoryId
  634. );
  635. }
  636. });
  637. this.$refs.table.setData([...data]);
  638. this.$forceUpdate();
  639. },
  640. changeVersions(row) {
  641. console.log(row, 'row')
  642. listBomByBomVersionId({ bomId: row.bomId, contractNum: row.contractNum, demandType: this.formData.demandType, salesCode: row.code, salesId: row.id }).then(
  643. (res) => {
  644. console.log(res, 'res')
  645. row.materialList = res || [];
  646. // this.$nextTick(() => {
  647. // this.$refs.table.toggleRowExpansionAll();
  648. // this.$forceUpdate();
  649. // });
  650. }
  651. );
  652. },
  653. //选择工艺路线
  654. openVersion(row) {
  655. this.xsId = row.id;
  656. this.$refs.versionRefs.open();
  657. },
  658. changeProduct(data) {
  659. const param = {
  660. salesOrderIds: [this.xsId],
  661. produceRoutingId: data.id
  662. };
  663. listBomBySalesOrderId(param).then((res) => {
  664. if (!res) return;
  665. const tableList = this.$refs.table.getData();
  666. tableList
  667. .forEach((e) => {
  668. if (e.id == this.xsId) {
  669. e.materialList = res.map((m) => {
  670. m.detailId = this.xsId;
  671. return {
  672. ...m
  673. };
  674. });
  675. this.$nextTick(() => {
  676. this.$refs.table.setData([...tableList]);
  677. this.$refs.table.toggleRowExpansionAll();
  678. });
  679. }
  680. })
  681. .catch((error) => {
  682. console.error('Failed to change product:', error);
  683. });
  684. });
  685. },
  686. // ---------------------------
  687. // 批量修改到货方式
  688. batchUpdateDeliveryMethod() {
  689. if (this.multipleSelection.length === 0) {
  690. this.$message.warning('请选择要修改的行');
  691. return;
  692. }
  693. this.formData2 = {
  694. deliveryMethod: 1,
  695. requireDeliveryTime: '',
  696. timeList: []
  697. };
  698. this.batchVisible = true;
  699. },
  700. // 处理表格选中行的变化
  701. handleSelectionChange(selection) {
  702. console.log(selection, 'sssssssselectionsssssss');
  703. this.multipleSelection = selection;
  704. },
  705. handleCancel() {
  706. this.batchVisible = false
  707. },
  708. handleConfirm() {
  709. const { deliveryMethod, requireDeliveryTime } = this.formData2;
  710. const tableData = this.$refs.table.getData();
  711. // 创建深拷贝的 timeList 模板(假设当前表单中已填写了分批时间)
  712. const timeListTemplate = JSON.parse(JSON.stringify(this.formData2.timeList));
  713. tableData.forEach((item) => {
  714. item.materialList.forEach((m) => {
  715. if (this.multipleSelection.some((selected) => selected.categoryId === m.categoryId)) {
  716. this.$set(m, 'deliveryMethod', deliveryMethod);
  717. if (deliveryMethod === 1) {
  718. //一次性到货逻辑
  719. this.$set(m, 'requireDeliveryTime', requireDeliveryTime)
  720. this.$set(m, 'timeList', null)
  721. } else if (deliveryMethod === 2) {
  722. this.$set(m, 'timeList', JSON.parse(JSON.stringify(timeListTemplate)));
  723. }
  724. }
  725. });
  726. });
  727. this.$refs.table.setData([...tableData]);
  728. this.batchVisible = false;
  729. },
  730. handleMethod(row, index) {
  731. console.log(index, 'index')
  732. if (row) {
  733. this.multipleSelection = [];
  734. }
  735. this.$refs.timeDialogRef.open(row || {}, index);
  736. },
  737. chooseTime(current, timeList, currentIndex) {
  738. const tableList = this.$refs.table.getData();
  739. if (current && current.categoryId) {
  740. // 单独修改逻辑:直接操作当前物料的 timeList
  741. tableList.forEach(item => {
  742. if (item.id === current.detailId) {
  743. const material = item.materialList[currentIndex];
  744. this.$set(material, 'timeList', JSON.parse(JSON.stringify(timeList)));
  745. }
  746. });
  747. } else if (this.multipleSelection.length > 0) {
  748. // 批量修改逻辑
  749. tableList.forEach(item => {
  750. item.materialList.forEach(material => {
  751. if (this.multipleSelection.some(selected => selected.categoryId === material.categoryId)) {
  752. this.$set(material, 'deliveryMethod', this.formData2.deliveryMethod)
  753. this.$set(material, 'timeList', JSON.parse(JSON.stringify(timeList)));
  754. }
  755. });
  756. });
  757. this.$refs.timeDialogRef.handleClose()
  758. this.batchVisible = false;
  759. }
  760. this.$refs.table.setData([...tableList]);
  761. },
  762. confirm() {
  763. this.$refs.formRef.validate(async (value) => {
  764. if (value) {
  765. let _arr = this.$refs.table.getData() ?? [];
  766. if (_arr.length == 0) {
  767. this.$message.info('请添加销售订单');
  768. return false;
  769. }
  770. let _arr2 = [];
  771. _arr2 = _arr.map((m) => {
  772. if (
  773. Object.prototype.hasOwnProperty.call(m, 'salesOrderId') &&
  774. m.salesOrderId
  775. ) {
  776. } else {
  777. m.salesOrderId = m.id;
  778. m.salesOrderCode = m.code;
  779. delete m.id;
  780. delete m.code;
  781. }
  782. return {
  783. ...m
  784. };
  785. });
  786. this.formData['type'] = 1;
  787. this.formData['salesOrderList'] = _arr2;
  788. this.formData.baitingType = 2;
  789. await save(this.formData);
  790. this.$message.success('保存成功!');
  791. this.$emit('success');
  792. this.cancel();
  793. }
  794. });
  795. },
  796. cancel() {
  797. this.visible = false;
  798. this.formData = {
  799. demandType: '1', // 增加默认值重置
  800. name: '',
  801. remark: '',
  802. detailRemoveIds: [],
  803. materialRemoveIds: [],
  804. orderType: 1
  805. };
  806. this.$refs.table.setData([]);
  807. this.$refs.formRef.resetFields();
  808. },
  809. }
  810. };
  811. </script>
  812. <style lang="scss" scoped>
  813. :deep(.el-table__expanded-cell) {
  814. padding-bottom: 30px !important;
  815. border-bottom: 12px solid #ccffcc !important;
  816. }
  817. .batch-actions {
  818. text-align: right;
  819. margin: 10px;
  820. }
  821. </style>