addAdjustDialog.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. :visible="addAdjustDialogFlag"
  6. :title="title"
  7. :append-to-body="true"
  8. :close-on-click-modal="false"
  9. width="70%"
  10. :maxable="true"
  11. :resizable="true"
  12. @close="handleClose"
  13. >
  14. <div style="margin-bottom: 20px;">
  15. <!-- <el-alert
  16. title="目前冲差功能仅适用于销售订单已审核,未执行发货的情况"
  17. type="warning"
  18. center
  19. show-icon>
  20. </el-alert> -->
  21. </div>
  22. <el-form
  23. ref="form"
  24. :model="form"
  25. :rules="rules"
  26. class="el-form-box"
  27. label-width="160px"
  28. >
  29. <headerTitle title="基本信息"></headerTitle>
  30. <el-row :gutter="20">
  31. <el-col :span="8">
  32. <el-form-item labelWidth="100px" label="冲差单编码" prop="orderNo">
  33. <el-input
  34. clearable
  35. v-model="form.orderNo"
  36. disabled
  37. placeholder="自动生成"
  38. />
  39. </el-form-item>
  40. </el-col>
  41. <el-col :span="8">
  42. <el-form-item
  43. labelWidth="100px"
  44. label="冲差类型"
  45. prop="type"
  46. >
  47. <DictSelection
  48. dictName="冲差类型"
  49. disabled
  50. clearable
  51. v-model="form.type"
  52. >
  53. </DictSelection>
  54. </el-form-item>
  55. </el-col>
  56. <el-col :span="8">
  57. <el-form-item
  58. labelWidth="100px"
  59. label="冲差原因"
  60. prop="reason"
  61. >
  62. <DictSelection
  63. dictName="冲差原因"
  64. clearable
  65. v-model="form.reason"
  66. >
  67. </DictSelection>
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="8">
  71. <el-form-item labelWidth="100px" label="冲差方式" prop="method">
  72. <DictSelection
  73. dictName="冲差方式"
  74. disabled
  75. clearable
  76. v-model="form.method"
  77. >
  78. </DictSelection>
  79. </el-form-item>
  80. </el-col>
  81. <el-col :span="8">
  82. <el-form-item
  83. labelWidth="100px"
  84. label="调整类型"
  85. prop="adjustType"
  86. >
  87. <DictSelection
  88. dictName="调整类型"
  89. clearable
  90. v-model="form.adjustType"
  91. >
  92. </DictSelection>
  93. </el-form-item>
  94. </el-col>
  95. <el-col :span="8">
  96. <el-form-item labelWidth="100px" label="冲差范围" prop="rangeType">
  97. <DictSelection
  98. dictName="冲差范围"
  99. clearable
  100. v-model="form.rangeType"
  101. >
  102. </DictSelection>
  103. </el-form-item>
  104. </el-col>
  105. </el-row>
  106. <el-row>
  107. <el-col :span="16">
  108. <el-form-item labelWidth="100px" label="调整说明" prop="remark">
  109. <el-input
  110. clearable
  111. v-model="form.remark"
  112. type="textarea"
  113. rows="1"
  114. placeholder="请输入"
  115. />
  116. </el-form-item>
  117. </el-col>
  118. <el-col :span="8">
  119. <el-form-item labelWidth="100px" prop="files" label="附件">
  120. <fileMain v-model="form.files"></fileMain>
  121. </el-form-item>
  122. </el-col>
  123. </el-row>
  124. <headerTitle title="物品清单" style="margin-top: 30px"></headerTitle>
  125. <inventoryTableDetails
  126. ref="inventoryTableDetailsRef"
  127. :isDiscountTotalPrice="true"
  128. :isSelected="true"
  129. :selectedIds="selectIds"
  130. @selection-change="handleSelectionChange"
  131. ></inventoryTableDetails>
  132. <headerTitle
  133. title="冲差信息"
  134. style="margin-top: 30px"
  135. ></headerTitle>
  136. <inventoryTable
  137. ref="inventoryTableRef"
  138. @changePrice="handleChangePrice"
  139. @setCountAmount="setCountAmount"
  140. ></inventoryTable>
  141. <div style="margin-top: 20px;">
  142. <el-row :gutter="20">
  143. <el-col :span="8">
  144. <el-form-item label-width="100px" label="总差异金额:" prop="differenceAmount">
  145. <el-input
  146. clearable
  147. v-model="form.differenceAmount"
  148. disabled
  149. placeholder="请输入"
  150. />
  151. </el-form-item>
  152. </el-col>
  153. <el-col :span="8">
  154. <el-form-item label-width="100px" label="总金额:" prop="adjustAmount">
  155. <el-input
  156. clearable
  157. disabled
  158. v-model="form.adjustAmount"
  159. placeholder="请输入"
  160. />
  161. </el-form-item>
  162. </el-col>
  163. <el-col :span="8">
  164. <el-form-item label-width="115px" label="优惠后总金额:" prop="adjustDiscountAmount">
  165. <el-input
  166. clearable
  167. type="number"
  168. v-model="form.adjustDiscountAmount"
  169. placeholder="请输入"
  170. @input="discountInput"
  171. />
  172. </el-form-item>
  173. </el-col>
  174. </el-row>
  175. </div>
  176. </el-form>
  177. <div slot="footer" class="footer">
  178. <el-button type="primary" @click="save" v-click-once>保存</el-button>
  179. <el-button
  180. type="primary"
  181. v-if="isNeed_process_is_close"
  182. @click="save('sub')"
  183. v-click-once
  184. >提交</el-button
  185. >
  186. <el-button @click="cancel">返回</el-button>
  187. </div>
  188. <process-submit-dialog
  189. :isNotNeedProcess="false"
  190. :processSubmitDialogFlag.sync="processSubmitDialogFlag"
  191. v-if="processSubmitDialogFlag"
  192. ref="processSubmitDialogRef"
  193. @reload="reload"
  194. ></process-submit-dialog>
  195. </ele-modal>
  196. </template>
  197. <script>
  198. import { acceptUnpackoptions } from '@/enum/dict';
  199. import fileUpload from '@/components/upload/fileUpload';
  200. import dictMixins from '@/mixins/dictMixins';
  201. import deptSelect from '@/components/CommomSelect/dept-select.vue';
  202. import personSelect from '@/components/CommomSelect/person-select.vue';
  203. import parentList from '@/views/saleManage/contact/components/parentList.vue';
  204. import inventoryTable from './inventoryTable.vue';
  205. import { copyObj } from '@/utils/util';
  206. import { getWarehouseListByIds } from '@/api/purchasingManage/returnGoods';
  207. import fileMain from '@/components/addDoc/index.vue';
  208. import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
  209. import orderListDialog from '@/views/saleManage/saleOrder/invoice/components/orderListDialog.vue';
  210. import inventoryTable1 from '@/BIZComponents/inventoryTable.vue';
  211. import inventoryTableDetails from '@/BIZComponents/inventoryTableDetails.vue';
  212. import {
  213. getSaleOrderDetail,
  214. } from '@/api/saleManage/saleorder';
  215. import { addCreate, getInfo, updateInfo } from '@/api/saleManage/adjustmentNote‌';
  216. export default {
  217. mixins: [dictMixins],
  218. components: {
  219. orderListDialog,
  220. processSubmitDialog,
  221. fileMain,
  222. fileUpload,
  223. deptSelect,
  224. inventoryTable,
  225. inventoryTable1,
  226. parentList,
  227. personSelect,
  228. inventoryTableDetails
  229. },
  230. //客户管理数据
  231. props: {
  232. addAdjustDialogFlag: {
  233. type: Boolean,
  234. default: false
  235. },
  236. saleOrderData: {
  237. type: Object,
  238. default: () => {
  239. return {};
  240. }
  241. }
  242. },
  243. data() {
  244. let formDef = {
  245. orderNo: '',
  246. type: '1',
  247. method: '1',
  248. reason: '1',
  249. rangeType: '',
  250. adjustType: '1',
  251. sourceType: '1',
  252. sourceNo: '',
  253. sourceId: '',
  254. files: [],
  255. differenceAmount: '',
  256. amount: '',
  257. discountAmount: '',
  258. sourceNo: '',
  259. sourceId: '',
  260. adjustAmount: '',
  261. adjustDiscountAmount: '',
  262. detailList: [],
  263. originalList: [],
  264. };
  265. return {
  266. visible: false,
  267. processSubmitDialogFlag: false,
  268. title: '',
  269. row: {},
  270. activeName: 'base',
  271. formDef,
  272. form: copyObj(formDef),
  273. orderForm: {},
  274. rules: {
  275. type: [
  276. { required: true, message: '请选择', trigger: 'change' }
  277. ],
  278. method: [{ required: true, message: '请选择', trigger: 'change' }],
  279. reason: [{ required: true, message: '请选择', trigger: 'change' }],
  280. rangeType: [{ required: true, message: '请选择', trigger: 'change' }],
  281. adjustType: [{ required: true, message: '请选择', trigger: 'change' }],
  282. // files: [{ required: true, message: '请上传附件', trigger: 'change' }],
  283. adjustDiscountAmount: [{ required: true, message: '请输入', trigger: 'change' }],
  284. },
  285. // 提交状态
  286. loading: false,
  287. // 是否是修改
  288. isUpdate: false,
  289. businessId: '',
  290. orderId: '',
  291. productList: [],
  292. adjustData: [],
  293. selectIds: [],
  294. };
  295. },
  296. async created() {
  297. },
  298. computed: {
  299. totalAmount() {
  300. let allcountAmount = 0;
  301. let totalAmount =
  302. (this.$refs.inventoryTableRef &&
  303. this.$refs.inventoryTableRef.totalAmount) ||
  304. 0;
  305. if (this.form.returnSourceType == 1) {
  306. if (this.form.type === '10') {
  307. allcountAmount = Number(totalAmount);
  308. }
  309. if (this.form.type === '20') {
  310. allcountAmount =
  311. Number(totalAmount) +
  312. Number(
  313. this.$refs.inventoryTableref1 &&
  314. this.$refs.inventoryTableref1.getPrice()[0]
  315. );
  316. }
  317. if (this.form.type === '30') {
  318. allcountAmount =
  319. Number(totalAmount) + Number(this.form.redressAmount || 0);
  320. }
  321. if (this.form.type === '40') {
  322. allcountAmount =
  323. this.$refs.inventoryTableref1 &&
  324. this.$refs.inventoryTableref1.getPrice()[0];
  325. }
  326. if (this.form.type === '50') {
  327. allcountAmount = Number(this.form.redressAmount || 0);
  328. }
  329. } else {
  330. allcountAmount = Number(totalAmount);
  331. }
  332. return parseFloat(allcountAmount).toFixed(2);
  333. }
  334. },
  335. methods: {
  336. // 选择需要冲差的产品
  337. handleSelectionChange(list) {
  338. // this.form.productList = val;
  339. console.log('select------list', list);
  340. // 创建深拷贝避免引用关系
  341. this.adjustData = JSON.parse(JSON.stringify(list))?.map(item => ({
  342. ...item,
  343. price: item.singlePrice,
  344. adjustPrice: item.singlePrice,
  345. quantity: item.saleCount,
  346. adjustDiscountPrice: item.discountSinglePrice,
  347. adjustDiscountAmount: item.discountTotalPrice,
  348. adjustAmount: item.totalPrice,
  349. sourceDetailId: item.id,
  350. discountPrice: item.discountSinglePrice,
  351. unTaxPrice: item.notaxSinglePrice,
  352. }));
  353. if (this.$refs.inventoryTableRef) {
  354. // 获取当前inventoryTable中已有的数据
  355. const currentData = this.$refs.inventoryTableRef.form.datasource || [];
  356. // 创建一个映射,记录已存在的数据
  357. const existingItemsMap = {};
  358. currentData.forEach(item => {
  359. if (item.productCode) {
  360. existingItemsMap[item.productCode] = item;
  361. }
  362. });
  363. // 合并数据,保留已编辑的单价等信息
  364. this.adjustData.forEach(item => {
  365. if (existingItemsMap[item.productCode]) {
  366. // 保留已编辑的字段
  367. const existingItem = existingItemsMap[item.productCode];
  368. item.priceDifference = existingItem.priceDifference !== undefined ? existingItem.priceDifference : item.priceDifference;
  369. item.adjustPrice = existingItem.adjustPrice !== undefined ? existingItem.adjustPrice : item.adjustPrice;
  370. item.quantity = existingItem.quantity !== undefined ? existingItem.quantity : item.quantity;
  371. item.adjustDiscountPrice = existingItem.adjustDiscountPrice !== undefined ? existingItem.adjustDiscountPrice : item.adjustDiscountPrice;
  372. item.adjustDiscountAmount = existingItem.adjustDiscountAmount !== undefined ? existingItem.adjustDiscountAmount : item.adjustDiscountAmount;
  373. item.adjustAmount = existingItem.adjustAmount !== undefined ? existingItem.adjustAmount : item.adjustAmount;
  374. item.unTaxPrice = existingItem.unTaxPrice !== undefined ? existingItem.unTaxPrice : item.unTaxPrice;
  375. // 移除已处理的项
  376. delete existingItemsMap[item.productCode];
  377. }
  378. });
  379. this.form.detailList = this.adjustData;
  380. // 调用putTableValue方法更新表格数据
  381. this.$refs.inventoryTableRef.putTableValue(this.form);
  382. }
  383. },
  384. // 计算总金额和优惠总金额
  385. setCountAmount(allPrice, diffPriceTotal) {
  386. console.log('allPrice~~~', allPrice, diffPriceTotal);
  387. this.form.adjustAmount = allPrice;
  388. this.form.adjustDiscountAmount = allPrice;
  389. this.form.differenceAmount = diffPriceTotal;
  390. },
  391. // 优惠后总金额修改产品折让单价
  392. discountInput() {
  393. console.log('this.form.adjustDiscountAmount~~~', this.form.adjustDiscountAmount, this.form.adjustAmount);
  394. this.$refs.inventoryTableRef.discountInputByOrder(this.form.adjustDiscountAmount, this.form.adjustAmount);
  395. },
  396. //删除产品
  397. remove(row) {
  398. if (this.form.productList.length === 1)
  399. return this.$message.error('必须要留一个产品');
  400. let index = this.form.productList.findIndex((n) => n.key == row.key);
  401. if (index !== -1) {
  402. this.form.productList.splice(index, 1);
  403. }
  404. },
  405. // 处理单价差异变化,更新单价
  406. handleChangePrice(obj) {
  407. this.form.differenceAmount = obj.total;
  408. },
  409. //打开新增编辑弹框
  410. async open(type, row) {
  411. console.log(type)
  412. this.title = type === 'add' ? '新增' : '修改';
  413. this.isUpdate = type != 'add';
  414. this.row = row;
  415. this.visible = true;
  416. console.log('row~~~~~~~~~~333', row);
  417. if (row && row?.id && !this.isUpdate) {
  418. console.log('add!!!')
  419. await this.getSaleOrderDetail(row?.id);
  420. } else {
  421. console.log('update!!!')
  422. const data = await getInfo(row?.id);
  423. if (data) {
  424. // this.$nextTick(() => {
  425. const tempdata = {
  426. // ...data,
  427. totalPrice: row.amount,
  428. discountTotalPrice: row.discountAmount,
  429. productList: data.originalList
  430. }
  431. this.businessId = data.id;
  432. this.adjustData = data.detailList;
  433. this.selectIds = this.adjustData.map(item => item.sourceDetailId);
  434. this.form = data;
  435. console.log('tempdata~~~', this.form, data);
  436. this.$refs.inventoryTableRef && this.$refs.inventoryTableRef.putTableValue(data);
  437. this.$refs.inventoryTableDetailsRef &&
  438. this.$refs.inventoryTableDetailsRef.putTableValue(tempdata);
  439. // });
  440. }
  441. }
  442. },
  443. //获取销售订单详情
  444. async getSaleOrderDetail(id) {
  445. // this.businessId = id;
  446. this.loading = true;
  447. const data = await getSaleOrderDetail(id);
  448. this.loading = false;
  449. this.orderForm = data;
  450. console.log('data~~~订单详情', data);
  451. if (data) {
  452. this.form.sourceNo = data.orderNo;
  453. this.form.sourceId = data.id;
  454. // this.form.amount = data.totalAmount;
  455. // this.form.discountAmount = data.payAmount;
  456. this.$nextTick(() => {
  457. this.$refs.inventoryTableDetailsRef &&
  458. this.$refs.inventoryTableDetailsRef.putTableValue(data);
  459. });
  460. }
  461. },
  462. getValidate() {
  463. let proAll = [
  464. new Promise((resolve, reject) => {
  465. this.$refs.form.validate((valid) => {
  466. if (!valid) {
  467. reject(false);
  468. } else {
  469. resolve(true);
  470. }
  471. });
  472. })
  473. ];
  474. proAll.push(
  475. new Promise((resolve, reject) => {
  476. this.$refs.inventoryTableRef.validateForm((valid) => {
  477. if (!valid) {
  478. reject(false);
  479. } else {
  480. resolve(true);
  481. }
  482. });
  483. })
  484. );
  485. return Promise.all(proAll);
  486. },
  487. async save(type) {
  488. try {
  489. await this.getValidate();
  490. // 表单验证通过,执行保存操作
  491. this.loading = true;
  492. if (!this.isUpdate) {
  493. delete this.form.id;
  494. }
  495. let data = this.$refs.inventoryTableRef.getTableValue();
  496. // let redressProductList =
  497. // (this.$refs.inventoryTableref1 &&
  498. // this.$refs.inventoryTableref1.getTableValue()) ||
  499. // [];
  500. console.log('data!!!!!!', data);
  501. if (
  502. data.productList.length === 0
  503. ) {
  504. return this.$message.error('至少选择一个冲差产品');
  505. }
  506. // let orderIds = [...data.productList, ...redressProductList].map(
  507. // (item) => item.orderId
  508. // );
  509. // let orderNos = [...data.productList, ...redressProductList].map(
  510. // (item) => item.orderNo
  511. // );
  512. // this.form.repliedFiles = this.form.repliedFiles || [];
  513. // this.form.replied = this.form.repliedFiles.length > 0 ? 1 : 0;
  514. // this.form.typeName = this.getDictValue('退货类型', this.form.type);
  515. let commitData = Object.assign({}, this.form, {
  516. detailList: data.productList,
  517. originalList: this.orderForm.productList,
  518. });
  519. // let productListData = [];
  520. // data.productList.forEach((item) => {
  521. // if (!item.totalCount) {
  522. // productListData.push(item.productName);
  523. // }
  524. // });
  525. // console.log(productListData);
  526. // if (productListData.length) {
  527. // return this.$message.error(
  528. // productListData.toString() + ' 退货数量不能为空!'
  529. // );
  530. // }
  531. if (this.isUpdate) {
  532. updateInfo(commitData)
  533. .then(async (res) => {
  534. this.loading = false;
  535. this.$message.success('修改成功');
  536. if (type === 'sub') {
  537. let storemanIds = '';
  538. let ids = commitData.detailList.map(
  539. (item) => item.warehouseId
  540. );
  541. let warehouseList = await getWarehouseListByIds(ids || []);
  542. storemanIds = warehouseList.map((item) => item.ownerId);
  543. await this.adjustSubmit(res, storemanIds.toString());
  544. return;
  545. }
  546. this.cancel();
  547. this.$emit('done');
  548. })
  549. .catch((e) => {
  550. //this.loading = false;
  551. });
  552. } else {
  553. addCreate(commitData)
  554. .then(async (res) => {
  555. this.loading = false;
  556. this.$message.success('新增成功');
  557. if (type === 'sub') {
  558. // let storemanIds = '';
  559. // let ids = commitData.detailList.map(
  560. // (item) => item.warehouseId
  561. // );
  562. // let warehouseList = await getWarehouseListByIds(ids || []);
  563. // storemanIds = warehouseList.map((item) => item.ownerId);
  564. this.adjustSubmit(res);
  565. this.$emit('done');
  566. return;
  567. }
  568. this.cancel();
  569. this.$emit('done');
  570. })
  571. .catch((e) => {
  572. //this.loading = false;
  573. });
  574. }
  575. } catch (error) {
  576. console.log(error);
  577. // 表单验证未通过,不执行保存操作
  578. }
  579. },
  580. async adjustSubmit(res) {
  581. const data = await getInfo(
  582. this.businessId || res
  583. );
  584. this.processSubmitDialogFlag = true;
  585. this.$nextTick(() => {
  586. let params = {
  587. businessId: this.businessId || res,
  588. businessKey: 'punch_slip_order_approve',
  589. formCreateUserId: data.createUserId,
  590. variables: {
  591. // returnSourceType: data.returnSourceType,
  592. // storemanIds: storemanIds.toString(),
  593. businessCode: data.orderNo,
  594. businessName: '销售订单冲差',
  595. businessType: '冲差单'
  596. }
  597. };
  598. this.$refs.processSubmitDialogRef.init(params);
  599. });
  600. },
  601. reload() {
  602. this.cancel();
  603. this.$emit('done');
  604. },
  605. // 处理对话框关闭事件
  606. handleClose() {
  607. this.cancel();
  608. },
  609. cancel() {
  610. this.$nextTick(() => {
  611. // 关闭后,销毁所有的表单数据
  612. // this.$refs['otherForm'] && this.$refs['otherForm'].resetFields();
  613. this.$refs['form'] && this.$refs['form'].resetFields();
  614. // this.$store.commit('order/clearUserData');
  615. this.form = copyObj(this.formDef);
  616. // 通过$emit更新父组件中的addAdjustDialogFlag值,避免直接修改prop
  617. this.$emit('update:addAdjustDialogFlag', false);
  618. });
  619. }
  620. }
  621. };
  622. </script>
  623. <style scoped lang="scss">
  624. .TotalAmount {
  625. font-size: 16px;
  626. padding-right: 30px;
  627. }
  628. .headbox {
  629. display: flex;
  630. justify-content: flex-start;
  631. align-items: center;
  632. .amount {
  633. font-size: 14px;
  634. font-weight: bold;
  635. margin-right: 20px;
  636. }
  637. }
  638. </style>