addAccountDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. :visible.sync="addAccountDialogFlag"
  6. :title="title"
  7. :close-on-click-modal="false"
  8. width="70%"
  9. :maxable="true"
  10. :resizable="true"
  11. :before-close="cancel"
  12. >
  13. <!--采购表单表单-->
  14. <purchase-form
  15. @handleSearch="handleSearch"
  16. :dataForm.sync="dataForm"
  17. :datasource.sync="datasource"
  18. :dialogType="dialogType"
  19. ></purchase-form>
  20. <!-- 应付信息 -->
  21. <headerTitle title="应付信息" style="margin-top: 30px"></headerTitle>
  22. <payables-info
  23. ref="payablesInfoRef"
  24. :dataForm.sync="dataForm"
  25. :payablesList="payablesList"
  26. :dialogType="dialogType"
  27. ></payables-info>
  28. <headerTitle title="对账明细" style="margin-top: 30px"> </headerTitle>
  29. <account-detail-table
  30. ref="accountDetailTableRef"
  31. :datasource.sync="datasource"
  32. :dialogType="dialogType"
  33. :queryDimension="dataForm.queryDimension"
  34. @totalChange="handleTotalChange"
  35. @countChange="handleCountChange"
  36. @statementAmountChange="handleStatementAmountChange"
  37. ></account-detail-table>
  38. <div slot="footer" class="footer">
  39. <el-button
  40. v-if="dialogType !== 'view'"
  41. type="primary"
  42. @click="save"
  43. v-click-once
  44. >保存</el-button
  45. >
  46. <el-button
  47. v-if="dialogType !== 'view'"
  48. type="primary"
  49. @click="save('sub')"
  50. v-click-once
  51. >提交</el-button
  52. >
  53. <el-button @click="cancel">返回</el-button>
  54. </div>
  55. <process-submit-dialog
  56. :processSubmitDialogFlag.sync="processSubmitDialogFlag"
  57. v-if="processSubmitDialogFlag"
  58. ref="processSubmitDialogRef"
  59. @reload="reload"
  60. ></process-submit-dialog>
  61. </ele-modal>
  62. </template>
  63. <script>
  64. // import recorpayTableList from '@/views/saleManage/saleOrder/accountstatement/components/recorpayTableList.vue';
  65. // import InventoryTable from './inventoryTable.vue';
  66. import InventoryTable from '@/views/saleManage/saleOrder/accountstatement/components/inventoryTable.vue';
  67. import purchaseForm from './purchaseForm.vue';
  68. import payablesInfo from './payablesInfo.vue';
  69. import {
  70. getStatementRecordSummaryAPI,
  71. createAccountStatementAPI,
  72. accountstatementInfoAPI,
  73. accountstatementUpdateAPI
  74. } from '@/api/saleManage/accountstatement';
  75. import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
  76. import { paymentTypeOp } from '@/enum/dict';
  77. import AccountDetailTable from '@/views/saleManage/saleOrder/accountstatement/components/accountDetailTable.vue';
  78. export default {
  79. name: 'addAccountDialog',
  80. props: ['addAccountDialogFlag'],
  81. components: {
  82. processSubmitDialog,
  83. InventoryTable,
  84. purchaseForm,
  85. payablesInfo,
  86. AccountDetailTable
  87. // recorpayTableList
  88. },
  89. data() {
  90. return {
  91. businessId: '',
  92. fullscreen: false,
  93. saveLoading: false,
  94. datasource: [],
  95. recorpayList: [],
  96. statPayable: null,
  97. // 应付信息初始明细(查询/编辑回填),由 payablesInfo 本地维护,提交时取回
  98. payablesList: [],
  99. dataForm: {
  100. sourceType: 1,
  101. dateType: 1,
  102. dateValue: '',
  103. contactId: '',
  104. contactName: '',
  105. sourceName: '',
  106. sourceId: '',
  107. type: '',
  108. year: '',
  109. quarter: '',
  110. month: '',
  111. dateTimeRange: [],
  112. orderNo: '',
  113. orderId: '',
  114. id: '',
  115. startDate: '',
  116. endDate: '',
  117. repliedFiles: [],
  118. queryDimension: 3,
  119. },
  120. title: '',
  121. processSubmitDialogFlag: false,
  122. dialogType: ''
  123. };
  124. },
  125. computed: {},
  126. methods: {
  127. handleTotalChange(total) {
  128. this.dataForm.amountTotalPrice = total;
  129. },
  130. handleCountChange(count) {
  131. this.dataForm.totalStatementCount = count;
  132. },
  133. // 明细表本次对账金额变化时,按销售单号同步到应收信息对应行
  134. handleStatementAmountChange(summaryMap) {
  135. if (this.$refs.payablesInfoRef) {
  136. this.$refs.payablesInfoRef.syncStatementAmount(summaryMap);
  137. }
  138. },
  139. open(dialogType, row, type = '') {
  140. this.businessId = row?.id || '';
  141. this.dialogType = dialogType;
  142. this.title =
  143. dialogType == 'add'
  144. ? '新增'
  145. : dialogType == 'update'
  146. ? '修改'
  147. : '详情';
  148. this.dataForm.type = type;
  149. if (this.dialogType !== 'add') {
  150. this.getInfo(row);
  151. }
  152. },
  153. //获取对账单详情
  154. async getInfo(row) {
  155. let data = await accountstatementInfoAPI(row.id);
  156. // this.recorpayList = data.recorpayList || [];
  157. // data.orderTotalAmount = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.orderAmount * 100), 0) / 100;
  158. // data.amountTotalPrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100;
  159. // data.amountCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.statementedAmount * 100), 0) / 100;
  160. // data.amountUnCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100;
  161. // this.datasource = data.orderList || [];
  162. // // 编辑详情回填应付信息(兼容 payablesList / statPayable 两种字段)
  163. // this.dataForm = data;
  164. this.datasource = data.productList || [];
  165. this.payablesList =
  166. (data.statPayable && data.statPayable.statPayableDetailList) ||
  167. [];
  168. // 保存查询到的完整 statPayable 对象,作为提交入参
  169. this.statPayable = data.statPayable || null;
  170. this.dataForm = {
  171. ...this.dataForm,
  172. ...data,
  173. };
  174. switch (this.dataForm.dateType) {
  175. case 1:
  176. this.$set(this.dataForm,'year',this.dataForm.dateValue)
  177. break;
  178. case 2:
  179. //2023年-四季度
  180. let data = this.dataForm.dateValue.split('年-');
  181. this.$set(this.dataForm,'year',data[0])
  182. this.$set(this.dataForm,'quarter',data[1])
  183. break;
  184. case 3:
  185. this.$set(this.dataForm,'month',this.dataForm.dateValue)
  186. break;
  187. default:
  188. this.dataForm.dateValue = '';
  189. this.$set(this.dataForm,'dateTimeRange',[
  190. this.dataForm.startDate,
  191. this.dataForm.endDate
  192. ])
  193. }
  194. this.$forceUpdate()
  195. },
  196. //关闭弹窗
  197. cancel() {
  198. this.$emit('update:addAccountDialogFlag', false);
  199. },
  200. //查询获取订单数据
  201. async handleSearch(params) {
  202. let searchQuery = {
  203. endDate: params.endDate,
  204. sourceId: params.sourceId,
  205. sourceType: params.sourceType,
  206. startDate: params.startDate,
  207. queryDimension: params.queryDimension,
  208. type: 2
  209. };
  210. let data = await getStatementRecordSummaryAPI(searchQuery);
  211. // this.recorpayList = data.recorpayList || [];
  212. this.datasource = data.productList || [];
  213. // 查询接口暂未返回预付信息时,先置空(由 payablesInfo 本地维护)
  214. this.payablesList =
  215. (data.statPayable && data.statPayable.statPayableDetailList) ||
  216. [];
  217. this.statPayable = data.statPayable || null;
  218. this.dataForm = {
  219. ...this.dataForm,
  220. ...data
  221. // amountPayablePrice: data.amountPayablePrice,
  222. // amountReceivablePrice: data.amountReceivablePrice,
  223. // amountTotalPrice: data.amountTotalPrice,
  224. // amountPayablePass: data.amountPayablePass,
  225. // amountReceivablePass: data.amountReceivablePass
  226. // orderTotalAmount: data.reduce((pre, cur) => pre + Math.round(+cur.orderAmount * 100), 0) / 100,
  227. // amountTotalPrice: data.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100,
  228. // amountCompletePrice: data.reduce((pre, cur) => pre + Math.round(+cur.statementedAmount * 100), 0) / 100,
  229. // amountUnCompletePrice: data.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100
  230. };
  231. // if (!this.datasource.length) this.$message.warning('暂无订单信息');
  232. },
  233. //保存
  234. async save(is) {
  235. if (!this.datasource.length)
  236. return this.$message.warning('暂无对账信息');
  237. try {
  238. // 校验明细表与应付信息表单
  239. await this.$refs.accountDetailTableRef.getValidForm();
  240. await this.$refs.payablesInfoRef.validate();
  241. let api =
  242. this.dialogType == 'add'
  243. ? createAccountStatementAPI
  244. : accountstatementUpdateAPI;
  245. // 提交时一次性取回应付信息(本地明细 + 汇总),不再实时回写
  246. const payablesData = this.$refs.payablesInfoRef.getSubmitData();
  247. // statPayable 为完整数据容器,保存时以它为基准组装应付明细与汇总
  248. const statPayable = {
  249. statPayableDetailList: payablesData.payablesList,
  250. statementAdvanceTotalPrice:
  251. payablesData.statementAdvanceTotalPrice,
  252. receivedTotalPrice: payablesData.receivedTotalPrice
  253. };
  254. this.statPayable = statPayable;
  255. const statementAdvanceTotalPrice =
  256. payablesData.statementAdvanceTotalPrice;
  257. const receivedTotalPrice = payablesData.receivedTotalPrice;
  258. let params = {
  259. ...this.dataForm,
  260. statementAdvanceTotalPrice,
  261. receivedTotalPrice,
  262. totalAdvanceConfirmAmount: statementAdvanceTotalPrice,
  263. totalPayableAmount: receivedTotalPrice,
  264. productList: this.datasource,
  265. statPayable
  266. };
  267. this.saveLoading = true;
  268. let data = await api(params);
  269. if (is == 'sub') {
  270. await this.submit(data);
  271. return;
  272. }
  273. this.$message.success('操作成功');
  274. this.reload();
  275. this.saveLoading = false;
  276. } catch (error) {
  277. console.error('保存失败:', error);
  278. this.saveLoading = false;
  279. }
  280. },
  281. async submit(res) {
  282. let data = await accountstatementInfoAPI(this.businessId || res);
  283. this.processSubmitDialogFlag = true;
  284. this.$nextTick(() => {
  285. let params = {
  286. businessId: data.id,
  287. businessKey: 'purchase_account_statement_approve',
  288. formCreateUserId: data.createUserId,
  289. variables: {
  290. businessCode: data.statementNo,
  291. type: data.type,
  292. businessName: data.contactName,
  293. businessType: '对账单'
  294. }
  295. // callBackMethodType : '1',
  296. // callBackMethod : 'proTargetPlanApproveApiImpl.updatePlanApprovalStatus',
  297. // pcHandle : '/bpm/handleTask/components/project-manage/plan-manage/submit.vue',
  298. // pcView : '/bpm/handleTask/components/project-manage/plan-manage/detailDialog.vue',
  299. // miniHandle : '',
  300. // miniView : '',
  301. };
  302. this.$refs.processSubmitDialogRef.init(params);
  303. });
  304. },
  305. // 对账明细本次对账金额变化时,按采购订单号同步到应付信息对应行
  306. handleDiscountPriceChange(statementAmount, tableIndex) {
  307. const order = this.datasource[tableIndex];
  308. if (!order || !order.orderNo) return;
  309. const summaryMap = { [order.orderNo]: statementAmount };
  310. if (this.$refs.payablesInfoRef) {
  311. this.$refs.payablesInfoRef.syncStatementAmount(summaryMap);
  312. }
  313. },
  314. reload() {
  315. this.cancel();
  316. //刷新主页面
  317. this.$emit('done');
  318. }
  319. }
  320. };
  321. </script>
  322. <style scoped lang="scss">
  323. ::v-deep.el-divider {
  324. margin: 10px;
  325. font-weight: bold;
  326. }
  327. </style>