addAccountDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. :append-to-body="true"
  8. :close-on-click-modal="false"
  9. :maxable="true"
  10. :resizable="true"
  11. width="85%"
  12. :before-close="cancel"
  13. >
  14. <div v-loading="loading">
  15. <!--销售表单-->
  16. <sale-form
  17. @handleSearch="handleSearch"
  18. :dataForm.sync="dataForm"
  19. :datasource.sync="datasource"
  20. :contactData="contactData"
  21. :saleOrderData="saleOrderData"
  22. :recorpayList.sync="recorpayList"
  23. :dialogType="dialogType"
  24. ref="saleFormRef"
  25. ></sale-form>
  26. <headerTitle title="对账明细" style="margin-top: 30px">
  27. <template v-slot>
  28. <el-row style="font-weight: 700; color: red">
  29. <span>订单总金额:</span>
  30. <span>{{ dataForm.orderTotalAmount || 0 }}</span>
  31. <el-divider direction="vertical"></el-divider>
  32. <span>已对账金额:</span>
  33. <span>{{ dataForm.amountCompletePrice || 0 }}</span>
  34. <el-divider direction="vertical"></el-divider>
  35. <span>未对账金额:</span>
  36. <span>{{ dataForm.amountUnCompletePrice || 0 }}</span>
  37. <el-divider direction="vertical"></el-divider>
  38. <span>本次对账总金额:</span>
  39. <span>{{ dataForm.amountTotalPrice || 0 }}</span>
  40. </el-row>
  41. </template>
  42. </headerTitle>
  43. <!-- <recorpayTableList
  44. ref="recorpayListRef"
  45. :dataForm="dataForm"
  46. :recorpayList.sync="recorpayList"
  47. :dialogType="dialogType"
  48. ></recorpayTableList> -->
  49. <inventoryTable
  50. ref="inventoryTableref"
  51. :dataForm="dataForm"
  52. :datasource.sync="datasource"
  53. :dialogType="dialogType"
  54. @changeDiscountPrice="changeDiscountPrice"
  55. ></inventoryTable>
  56. </div>
  57. <div slot="footer" class="footer">
  58. <el-button
  59. v-if="dialogType !== 'view'"
  60. type="primary"
  61. @click="save"
  62. v-click-once
  63. >保存
  64. </el-button>
  65. <el-button
  66. v-if="dialogType !== 'view'"
  67. type="primary"
  68. @click="save('sub')"
  69. v-click-once
  70. >提交
  71. </el-button>
  72. <el-button @click="cancel">返回</el-button>
  73. </div>
  74. <process-submit-dialog
  75. :processSubmitDialogFlag.sync="processSubmitDialogFlag"
  76. v-if="processSubmitDialogFlag"
  77. ref="processSubmitDialogRef"
  78. @reload="reload"
  79. ></process-submit-dialog>
  80. </ele-modal>
  81. </template>
  82. <script>
  83. import InventoryTable from './inventoryTable.vue';
  84. import recorpayTableList from './recorpayTableList.vue';
  85. import saleForm from './saleForm.vue';
  86. import {
  87. getStatementRecordListAPI,
  88. infoAccountStatementAPI,
  89. saveAccountStatementAPI,
  90. createAccountStatementAPI,
  91. updateAccountStatementAPI,
  92. accountstatementInfoAPI,
  93. accountstatementUpdateAPI
  94. } from '@/api/saleManage/accountstatement';
  95. import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
  96. export default {
  97. name: 'addAccountDialog',
  98. components: {
  99. processSubmitDialog,
  100. InventoryTable,
  101. saleForm,
  102. recorpayTableList
  103. },
  104. //客户管理数据
  105. props: {
  106. addAccountDialogFlag: {
  107. type: Boolean,
  108. default: false
  109. },
  110. contactData: {
  111. type: Object,
  112. default: () => {
  113. return {};
  114. }
  115. },
  116. saleOrderData: {
  117. type: Object,
  118. default: () => {
  119. return {};
  120. }
  121. }
  122. },
  123. data() {
  124. return {
  125. fullscreen: false,
  126. loading: false,
  127. saveLoading: false,
  128. datasource: [],
  129. recorpayList: [],
  130. dataForm: {
  131. sourceType: 1,
  132. dateType: 1,
  133. queryDimension: 1,
  134. dateValue: '',
  135. contactId: '',
  136. contactName: '',
  137. sourceName: '',
  138. sourceId: '',
  139. type: '',
  140. year: '',
  141. quarter: '',
  142. month: '',
  143. dateTimeRange: [],
  144. orderNo: '',
  145. orderId: '',
  146. id: '',
  147. startDate: '',
  148. endDate: '',
  149. repliedFiles: []
  150. },
  151. title: '',
  152. processSubmitDialogFlag: false,
  153. dialogType: '',
  154. businessId: ''
  155. };
  156. },
  157. computed: {},
  158. methods: {
  159. changeDiscountPrice(price, tableIndex) {
  160. console.log('price~~~', price, tableIndex)
  161. this.datasource[tableIndex].statementAmount = price;
  162. this.datasource[tableIndex].unStatementAmount = price;
  163. console.log('this.datasource', this.datasource)
  164. this.dataForm.amountTotalPrice = this.datasource.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100;
  165. this.dataForm.amountUnCompletePrice = this.datasource.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100;
  166. },
  167. open(dialogType, row, type = '') {
  168. this.dialogType = dialogType;
  169. this.title =
  170. dialogType == 'add'
  171. ? '新增'
  172. : dialogType == 'update'
  173. ? '修改'
  174. : '详情';
  175. this.dataForm.type = type;
  176. this.$nextTick(() => {
  177. if (this.contactData.id) {
  178. this.$refs.saleFormRef.getCusInfo(this.contactData);
  179. }
  180. if (this.saleOrderData.id) {
  181. this.$refs.saleFormRef.getOrderInfo(this.saleOrderData);
  182. }
  183. });
  184. if (this.dialogType !== 'add') {
  185. this.businessId = row.id;
  186. this.getInfo(row);
  187. }
  188. },
  189. //获取对账单详情
  190. async getInfo(row) {
  191. let data = await accountstatementInfoAPI(row.id);
  192. // this.recorpayList = data.recorpayList || [];
  193. // 解决小数精度丢失问题,使用分进行计算
  194. data.orderTotalAmount = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.orderAmount * 100), 0) / 100;
  195. data.amountTotalPrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100;
  196. data.amountCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.statementedAmount * 100), 0) / 100;
  197. data.amountUnCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100;
  198. data.orderList = data.orderList.map(item => {
  199. item.deliveryProducts = item.deliveryProducts.map(i => {
  200. return {
  201. ...i,
  202. taxRate: i.taxRate || 0,
  203. discountRatio: i.discountRatio || 100,
  204. singlePrice: i.singlePrice || 0,
  205. }
  206. })
  207. return item;
  208. })
  209. this.datasource = data.orderList || [];
  210. this.dataForm = data;
  211. switch (this.dataForm.dateType) {
  212. case 1:
  213. // this.dataForm.year = this.dataForm.dateValue;
  214. this.$set(this.dataForm, 'year', this.dataForm.dateValue);
  215. break;
  216. case 2:
  217. //2023年-四季度
  218. let data = this.dataForm.dateValue.split('年-');
  219. this.$set(this.dataForm, 'year', data[0]);
  220. this.$set(this.dataForm, 'quarter', data[1]);
  221. break;
  222. case 3:
  223. this.$set(this.dataForm, 'month', this.dataForm.dateValue);
  224. break;
  225. default:
  226. this.dataForm.dateValue = '';
  227. this.$set(this.dataForm, 'dateTimeRange', [
  228. this.dataForm.startDate,
  229. this.dataForm.endDate
  230. ]);
  231. }
  232. this.$forceUpdate();
  233. },
  234. //关闭弹窗
  235. cancel() {
  236. this.$emit('update:addAccountDialogFlag', false);
  237. },
  238. //查询获取订单数据
  239. async handleSearch(params) {
  240. console.log('this.$refs.inventoryTableRef~~~', this.$refs.inventoryTableref);
  241. let searchQuery = {
  242. endDate: params.endDate,
  243. sourceId: params.sourceId,
  244. sourceType: params.sourceType,
  245. startDate: params.startDate,
  246. queryDimension: params.queryDimension,
  247. type: 1
  248. };
  249. // const searchQuery = ["SALES20251225007","SALES20251225005","SALES20251225009"];
  250. this.loading = true;
  251. try {
  252. let data = await getStatementRecordListAPI(searchQuery);
  253. console.log(data, 'data');
  254. this.loading = false;
  255. data = data.map(item => {
  256. item.deliveryProducts = item.deliveryProducts.map(i => {
  257. return {
  258. ...i,
  259. taxRate: i.taxRate || 0,
  260. discountRatio: i.discountRatio || 100,
  261. singlePrice: i.singlePrice || 0,
  262. }
  263. })
  264. return item;
  265. })
  266. this.datasource = data || [];
  267. console.log(this.datasource, 'this.datasource~~~');
  268. // this.recorpayList = data.recorpayList || [];
  269. this.dataForm = {
  270. ...this.dataForm,
  271. // amountPayablePrice: data.amountPayablePrice,
  272. // amountReceivablePrice: data.amountReceivablePrice,
  273. // amountTotalPrice: data.amountTotalPrice,
  274. // amountPayablePass: data.amountPayablePass,
  275. // amountReceivablePass: data.amountReceivablePass
  276. orderTotalAmount: data.reduce((pre, cur) => pre + Math.round(+cur.orderAmount * 100), 0) / 100,
  277. amountTotalPrice: data.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100,
  278. amountCompletePrice: data.reduce((pre, cur) => pre + Math.round(+cur.statementedAmount * 100), 0) / 100,
  279. amountUnCompletePrice: data.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100
  280. };
  281. this.$forceUpdate();
  282. } catch (error) {
  283. this.loading = false;
  284. }
  285. // if (!this.datasource.length) this.$message.warning('暂无订单信息');
  286. },
  287. //保存
  288. async save(is) {
  289. if (!this.datasource.length)
  290. return this.$message.warning('暂无对账信息');
  291. try {
  292. // 校验 inventoryTableref 组件的表单
  293. await this.$refs.inventoryTableref.getValidForm();
  294. let api =
  295. this.dialogType == 'add'
  296. ? createAccountStatementAPI
  297. : accountstatementUpdateAPI;
  298. let params = {
  299. ...this.dataForm,
  300. orderList: this.datasource,
  301. // recorpayList: this.recorpayList
  302. };
  303. this.saveLoading = true;
  304. let data = await api(params);
  305. if (is == 'sub') {
  306. await this.submitApprove(data);
  307. return;
  308. // await submitAccountStatementApproveAPI({
  309. // businessId: data,
  310. // type: this.dataForm.type
  311. // });
  312. }
  313. this.$message.success('操作成功');
  314. this.reload();
  315. this.saveLoading = false;
  316. } catch (error) {
  317. console.error('保存失败:', error);
  318. // 错误提示已经在 getValidForm 方法中处理
  319. this.saveLoading = false;
  320. }
  321. },
  322. async submitApprove(res) {
  323. console.log(res, 'res~~~');
  324. console.log(this.businessId || res, 'this.businessId || res');
  325. const data = await accountstatementInfoAPI(this.businessId || res);
  326. console.log(data, 'data~~~');
  327. this.processSubmitDialogFlag = true;
  328. this.$nextTick(() => {
  329. const params = {
  330. businessId: data.id,
  331. businessKey: 'sales_account_statement_approve',
  332. formCreateUserId: data.createUserId,
  333. variables: {
  334. type: data.type,
  335. businessCode: data.statementNo,
  336. businessName: data.contactName,
  337. businessType: '对账单'
  338. }
  339. // callBackMethodType : '1',
  340. // callBackMethod : 'proTargetPlanApproveApiImpl.updatePlanApprovalStatus',
  341. // pcHandle : '/bpm/handleTask/components/project-manage/plan-manage/submit.vue',
  342. // pcView : '/bpm/handleTask/components/project-manage/plan-manage/detailDialog.vue',
  343. // miniHandle : '',
  344. // miniView : '',
  345. };
  346. this.$refs.processSubmitDialogRef.init(params);
  347. });
  348. },
  349. reload() {
  350. this.cancel();
  351. //刷新主页面
  352. this.$emit('done');
  353. }
  354. }
  355. };
  356. </script>
  357. <style scoped lang="scss">
  358. ::v-deep.el-divider {
  359. margin: 10px;
  360. font-weight: bold;
  361. }
  362. </style>