plan-edit-dialog.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  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" placeholder="请选择" style="width: 100%" :disabled="type == 'detail'">
  10. <el-option v-for="item in demandTypeList" :key="item.dictCode" :label="item.dictValue"
  11. :value="item.dictCode">
  12. </el-option>
  13. </el-select>
  14. </el-form-item>
  15. </el-col>
  16. <el-col :span="8">
  17. <el-form-item label="计划名称" prop="name">
  18. <el-input placeholder="请选择" v-model="formData.name" :readonly="type == 'detail'"></el-input>
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="8">
  22. <el-form-item label="备注" prop="remark">
  23. <el-input placeholder="备注" v-model="formData.remark" :readonly="type == 'detail'"></el-input>
  24. </el-form-item>
  25. </el-col>
  26. </el-row>
  27. </el-form>
  28. <el-form :model="formData" ref="tableForm">
  29. <ele-pro-table ref="table" :needPage="false" :columns="columns" row-key="id" :expanded-row-keys="expandedRowKeys">
  30. <template v-slot:toolbar>
  31. <el-button size="small" type="primary" icon="el-icon-plus" class="ele-btn-icon" @click="saleAdd"
  32. v-if="type != 'detail'">
  33. 添加销售订单
  34. </el-button>
  35. </template>
  36. <template v-slot:code="{ row }">
  37. <el-input placeholder="请输入" readonly :value="row.code || row.salesOrderCode"></el-input>
  38. </template>
  39. <template v-slot:bomId="{ row }">
  40. <el-select v-model="row.bomId" placeholder="请选择" style="width: 100%" :disabled="type == 'detail'"
  41. @change="changeVersions(row)">
  42. <el-option v-for="item in row.bomCategoryList" :key="item.id" :label="'V' + item.versions + '.0'"
  43. :value="item.id">
  44. </el-option>
  45. </el-select>
  46. </template>
  47. <template v-slot:action="{ row, $index }" v-if="type != 'detail'">
  48. <template>
  49. <el-link type="primary" :underline="false" @click="categorySelect(row)">
  50. 添加物料
  51. </el-link>
  52. <el-popconfirm class="ele-action" title="确定要删除此销售订单吗?" @confirm="remove(row, $index)">
  53. <template v-slot:reference>
  54. <el-link type="danger" :underline="false" icon="el-icon-delete">
  55. 删除
  56. </el-link>
  57. </template>
  58. </el-popconfirm>
  59. </template>
  60. </template>
  61. <!-- 展开内容 -->
  62. <template v-slot:expand="{ row, $index }">
  63. <div class="batch-actions" v-if="row.materialList.length > 0">
  64. <el-button @click="batchUpdateDeliveryMethod">批量修改到货方式</el-button>
  65. </div>
  66. <div style="
  67. width: calc(100% - 95px);
  68. min-height: 60px;
  69. margin-left: 95px;
  70. " v-if="row.materialList.length > 0">
  71. <ele-pro-table :toolbar="false" toolsTheme="none" ref="table2" :need-page="false"
  72. :datasource="row.materialList" :columns="columns2" :key="row.sort + '-' + row.materialList.sort"
  73. @selection-change="handleSelectionChange">
  74. <template v-slot:sort="{ $index }">
  75. {{ $index + 1 }}
  76. </template>
  77. <template v-slot:unit="{ row }">
  78. {{ row.unit }}
  79. </template>
  80. <template v-slot:demandQuantity="{ row }">
  81. <el-input v-model="row.demandQuantity" placeholder="请输入" :readonly="type == 'detail'" @input="
  82. (value) =>
  83. (row.demandQuantity = value.replace(
  84. /^(-)*(\d+)\.(\d\d\d\d\d\d).*$/,
  85. '$1$2.$3'
  86. ))
  87. "></el-input>
  88. </template>
  89. <template v-slot:purchasingCycle="{ row }">
  90. {{ row.purchasingCycle }}{{ row.purchasingCycleUnit }}
  91. </template>
  92. <template v-slot:purchaseQuantity="{ row }">
  93. <el-input v-model="row.purchaseQuantity" placeholder="请输入" :readonly="type == 'detail'" @input="
  94. (value) =>
  95. (row.purchaseQuantity = value.replace(
  96. /^(-)*(\d+)\.(\d\d\d\d\d\d).*$/,
  97. '$1$2.$3'
  98. ))
  99. "></el-input>
  100. </template>
  101. <template v-slot:deliveryMethod="{ row, $index }">
  102. <el-select clearable class="ele-block" v-model="row.deliveryMethod" placeholder="请选择"
  103. :disabled="type == 'detail'">
  104. <el-option label="一次性到货" :value="1" @click.native="row.timeList = null" />
  105. <el-option label="分批到货" :value="2" @click.native="
  106. handleMethod(row, $index);
  107. row.requireDeliveryTime = null;
  108. " />
  109. </el-select>
  110. </template>
  111. <template v-slot:requireDeliveryTime="{ row, $index }">
  112. <el-date-picker style="width: 100%" clearable v-model="row.requireDeliveryTime" type="date"
  113. v-show="row.deliveryMethod == 1" value-format="yyyy-MM-dd" placeholder="请选择日期" :pickerOptions="{
  114. disabledDate: (time) =>
  115. time.getTime() <
  116. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  117. }" :readonly="type == 'detail'">
  118. </el-date-picker>
  119. <el-link type="primary" :underline="false" v-show="row.deliveryMethod == 2"
  120. @click.native="handleMethod(row, $index)">
  121. 设置分批时间
  122. </el-link>
  123. </template>
  124. <template v-slot:imgUrl="{ row }">
  125. <fileUpload v-model="row.imgUrl" module="main" :showLib="false" :limit="1"
  126. :disabled="type == 'detail'" />
  127. </template>
  128. <template v-slot:files="{ row }">
  129. <fileUpload v-model="row.files" module="main" :showLib="false" :limit="1"
  130. :disabled="type == 'detail'" />
  131. </template>
  132. <template v-slot:action="{ row }" v-if="type != 'detail'">
  133. <el-popconfirm class="ele-action" title="确定要删除当前物料吗?" @confirm="remove2(row)">
  134. <template v-slot:reference>
  135. <el-link type="danger" :underline="false" icon="el-icon-delete">
  136. 删除
  137. </el-link>
  138. </template>
  139. </el-popconfirm>
  140. </template>
  141. </ele-pro-table>
  142. </div>
  143. </template>
  144. </ele-pro-table>
  145. </el-form>
  146. <div slot="footer" v-if="type != 'detail'">
  147. <el-button @click="cancel">取消</el-button>
  148. <el-button type="primary" @click="confirm">保存</el-button>
  149. </div>
  150. <saleOrderPop ref="saleOrderRef" @chooseOrder="chooseOrder"></saleOrderPop>
  151. <ProductModal ref="productRefs" @chooseModal="chooseModal" />
  152. <ProductionVersion ref="versionRefs" @changeProduct="changeProduct"></ProductionVersion>
  153. <timeDialog ref="timeDialogRef" @chooseTime="chooseTime"></timeDialog>
  154. <ele-modal :visible.sync="batchVisible" title="批量选择" width="25vw" append-to-body @close="handleCancel"
  155. :maxable="true">
  156. <el-form :model="formData2" label-width="100px">
  157. <el-form-item label="到货方式" prop="deliveryMethod">
  158. <el-select clearable v-model="formData2.deliveryMethod" placeholder="请选择">
  159. <el-option label="一次性到货" :value="1" />
  160. <el-option label="分批到货" :value="2" @click.native="
  161. handleMethod();
  162. " />
  163. </el-select>
  164. </el-form-item>
  165. <el-form-item label="要求到货时间" prop="requireDeliveryTime">
  166. <el-date-picker clearable v-model="formData2.requireDeliveryTime" type="date"
  167. v-show="formData2.deliveryMethod == 1" value-format="yyyy-MM-dd" placeholder="请选择日期" :pickerOptions="{
  168. disabledDate: (time) =>
  169. time.getTime() <
  170. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  171. }">
  172. </el-date-picker>
  173. <el-link type="primary" :underline="false" v-show="formData2.deliveryMethod == 2"
  174. @click.native="handleMethod()">
  175. 设置分批时间
  176. </el-link>
  177. </el-form-item>
  178. </el-form>
  179. <template v-slot:footer>
  180. <el-button @click="handleCancel">取消</el-button>
  181. <el-button type="primary" @click="handleConfirm">确认</el-button>
  182. </template>
  183. </ele-modal>
  184. </ele-modal>
  185. </template>
  186. <script>
  187. import saleOrderPop from './saleOrderPop.vue';
  188. import ProductModal from './ProductModal.vue';
  189. import {
  190. listBomBySalesOrderIdsOverride,
  191. listBomByBomVersionId,
  192. listBomBySalesOrderId,
  193. save,
  194. getById
  195. } from '@/api/materialPlan/index';
  196. import ProductionVersion from '@/components/CreatePlan/ProductionVersion2.vue';
  197. import fileUpload from '@/components/upload/fileUpload';
  198. import timeDialog from './timeDialog.vue';
  199. import dictMixins from '@/mixins/dictMixins';
  200. export default {
  201. components: {
  202. saleOrderPop,
  203. ProductModal,
  204. ProductionVersion,
  205. fileUpload,
  206. timeDialog
  207. },
  208. mixins: [dictMixins],
  209. data() {
  210. return {
  211. formData2: {
  212. deliveryMethod: 1,
  213. requireDeliveryTime: '',
  214. timeList: []
  215. },
  216. batchVisible: false,
  217. multipleSelection: [],
  218. visible: false,
  219. type: 'add',
  220. tableData: [],
  221. xsId: null,
  222. formData: {
  223. demandType: '1',
  224. name: '',
  225. remark: '',
  226. detailRemoveIds: [],
  227. materialRemoveIds: [],
  228. orderType: 1
  229. },
  230. demandTypeList: [
  231. {
  232. dictCode: '1',
  233. dictValue: '生产性物资采购'
  234. },
  235. {
  236. dictCode: '6',
  237. dictValue: '外协自供料采购'
  238. },
  239. {
  240. dictCode: '7',
  241. dictValue: '外协客供料采购'
  242. }
  243. ],
  244. expandedRowKeys: [],
  245. rules: {
  246. demandType: [
  247. {
  248. required: true,
  249. message: '请选择需求类型',
  250. trigger: ['blur', 'change']
  251. }
  252. ],
  253. name: [
  254. {
  255. required: true,
  256. message: '请输入配料计划名称',
  257. trigger: ['blur', 'change']
  258. }
  259. ]
  260. }
  261. };
  262. },
  263. computed: {
  264. // 表格列配置
  265. columns() {
  266. const list = [
  267. {
  268. width: 45,
  269. type: 'expand',
  270. columnKey: 'materialList',
  271. align: 'center',
  272. slot: 'expand'
  273. },
  274. {
  275. width: 50,
  276. label: '序号',
  277. type: 'index',
  278. align: 'center',
  279. slot: 'index'
  280. },
  281. {
  282. prop: 'purchaseType',
  283. label: '采购类型',
  284. align: 'center',
  285. showOverflowTooltip: true,
  286. minWidth: 120,
  287. sortable: true,
  288. formatter: (row) => {
  289. return row.purchaseType == '1' ? '未采购' : '已采购';
  290. }
  291. },
  292. {
  293. prop: 'code',
  294. label: '销售订单号',
  295. slot: 'code',
  296. showOverflowTooltip: true,
  297. align: 'center',
  298. minWidth: 170,
  299. sortable: true
  300. },
  301. {
  302. prop: 'customerName',
  303. label: '客户名称',
  304. align: 'center',
  305. showOverflowTooltip: true
  306. },
  307. {
  308. prop: 'serialNo',
  309. label: '客户代号',
  310. align: 'center',
  311. showOverflowTooltip: true
  312. },
  313. {
  314. prop: 'productCode',
  315. label: '编码',
  316. align: 'center',
  317. showOverflowTooltip: true,
  318. minWidth: 140
  319. },
  320. {
  321. prop: 'productName',
  322. label: '名称',
  323. align: 'center',
  324. minWidth: 120
  325. },
  326. {
  327. prop: 'model',
  328. label: '型号',
  329. align: 'center',
  330. minWidth: 120
  331. },
  332. {
  333. prop: 'brandNo',
  334. label: '牌号',
  335. align: 'center'
  336. },
  337. {
  338. prop: 'deliveryTime',
  339. label: '交付日期',
  340. align: 'center',
  341. showOverflowTooltip: true
  342. },
  343. {
  344. prop: 'contractNum',
  345. label: '订单数量',
  346. align: 'center'
  347. },
  348. {
  349. prop: 'lackNum',
  350. label: '欠交数量',
  351. align: 'center'
  352. },
  353. {
  354. prop: 'bomId',
  355. label: '选择BOM版本',
  356. slot: 'bomId',
  357. align: 'center',
  358. minWidth: 110
  359. },
  360. this.type != 'detail'
  361. ? {
  362. columnKey: 'action',
  363. label: '操作',
  364. width: 150,
  365. align: 'center',
  366. resizable: false,
  367. slot: 'action',
  368. showOverflowTooltip: true
  369. }
  370. : ''
  371. ].filter(Boolean);
  372. return list;
  373. },
  374. columns2() {
  375. const list = [
  376. {
  377. columnKey: 'selection',
  378. type: 'selection',
  379. width: 50,
  380. align: 'center',
  381. fixed: 'left'
  382. },
  383. {
  384. width: 50,
  385. label: '序号',
  386. prop: 'sort',
  387. slot: 'sort',
  388. align: 'center',
  389. fixed: 'left'
  390. },
  391. {
  392. label: '物料名称',
  393. prop: 'name',
  394. align: 'center',
  395. minWidth: 120,
  396. fixed: 'left'
  397. },
  398. {
  399. label: '物料编码',
  400. prop: 'code',
  401. align: 'center',
  402. minWidth: 120,
  403. fixed: 'left'
  404. },
  405. {
  406. label: '牌号',
  407. prop: 'brandNum',
  408. align: 'center'
  409. },
  410. {
  411. prop: 'specification',
  412. label: '规格',
  413. align: 'center',
  414. showOverflowTooltip: true,
  415. minWidth: 110
  416. },
  417. {
  418. label: '型号',
  419. prop: 'modelType',
  420. align: 'center'
  421. },
  422. {
  423. prop: 'inventoryQuantity',
  424. label: '库存',
  425. showOverflowTooltip: true
  426. },
  427. {
  428. prop: 'secureInventory',
  429. label: '安全库存',
  430. showOverflowTooltip: true
  431. },
  432. {
  433. prop: 'lockQuantity',
  434. label: '锁库数量',
  435. showOverflowTooltip: true
  436. },
  437. {
  438. prop: 'inTransitNum',
  439. label: '在途数量',
  440. showOverflowTooltip: true
  441. },
  442. {
  443. prop: 'inTransitOrdersNum',
  444. label: '在途已关联数量',
  445. showOverflowTooltip: true
  446. },
  447. {
  448. prop: 'availableQuantity',
  449. label: '可用数量',
  450. showOverflowTooltip: true
  451. },
  452. {
  453. prop: 'unit',
  454. label: '计量单位',
  455. showOverflowTooltip: true,
  456. action: 'unit',
  457. slot: 'unit'
  458. },
  459. {
  460. label: '需求数量',
  461. slot: 'demandQuantity',
  462. action: 'demandQuantity',
  463. align: 'center',
  464. minWidth: 120
  465. },
  466. {
  467. label: '采购数量',
  468. slot: 'purchaseQuantity',
  469. action: 'purchaseQuantity',
  470. align: 'center',
  471. minWidth: 120
  472. },
  473. {
  474. label: '采购周期',
  475. slot: 'purchasingCycle',
  476. action: 'purchasingCycle',
  477. align: 'center',
  478. minWidth: 160
  479. },
  480. {
  481. label: '到货方式',
  482. slot: 'deliveryMethod',
  483. action: 'deliveryMethod',
  484. align: 'center',
  485. minWidth: 140
  486. },
  487. {
  488. label: '要求到货时间',
  489. slot: 'requireDeliveryTime',
  490. action: 'requireDeliveryTime',
  491. align: 'center',
  492. minWidth: 180
  493. },
  494. {
  495. label: '图纸',
  496. slot: 'imgUrl',
  497. action: ' imgUrl',
  498. align: 'center',
  499. minWidth: 140
  500. },
  501. {
  502. label: '附件',
  503. slot: 'files',
  504. action: ' files',
  505. align: 'center',
  506. minWidth: 140
  507. },
  508. this.type != 'detail'
  509. ? {
  510. columnKey: 'action',
  511. label: '操作',
  512. width: 80,
  513. align: 'center',
  514. resizable: false,
  515. slot: 'action',
  516. showOverflowTooltip: true
  517. }
  518. : ''
  519. ].filter(Boolean);
  520. return list;
  521. }
  522. },
  523. created() { },
  524. methods: {
  525. async open(type, row) {
  526. this.type = type;
  527. if (type == 'add') {
  528. // this.formData.demandType = '';
  529. this.formData.name = '';
  530. this.formData.remark = '';
  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 }).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. this.formData.detailRemoveIds = [];
  800. this.formData.materialRemoveIds = [];
  801. this.$refs.table.setData([]);
  802. this.$refs.formRef.resetFields();
  803. },
  804. }
  805. };
  806. </script>
  807. <style lang="scss" scoped>
  808. :deep(.el-table__expanded-cell) {
  809. padding-bottom: 30px !important;
  810. border-bottom: 12px solid #ccffcc !important;
  811. }
  812. .batch-actions {
  813. text-align: right;
  814. margin: 10px;
  815. }
  816. </style>