plan-edit-dialog.vue 33 KB

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