generateContractsDialog.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. :visible.sync="generateContractsDialogFlag"
  6. title="生成合同"
  7. :close-on-click-modal="false"
  8. append-to-body
  9. width="80%"
  10. :before-close="cancel"
  11. >
  12. <inquiryTable
  13. :radio="form.winnerId"
  14. v-for="item in form.supplierList"
  15. :key="item.supplierId"
  16. style="margin-top: 15px"
  17. status="Detail"
  18. v-if="item.resultList.some(i=>i.isWinner)"
  19. :obj="item"
  20. >
  21. <template #generateContracts>
  22. <el-button @click="handleGenerate(item)" type="primary" plain>生成合同</el-button>
  23. <span v-if="item.isGeneratedContract"
  24. style="color: red;margin-left: 5px;font-size: 11px">*已生成过合同,请注意</span>
  25. </template>
  26. </inquiryTable>
  27. <div slot="footer" class="footer">
  28. <el-button @click="cancel">返回</el-button>
  29. </div>
  30. </ele-modal>
  31. </template>
  32. <script>
  33. import inquiryTable from "@/views/purchasingManage/inquiryManage/components/inquiryTable.vue";
  34. import {generateContract, getpurchaseinquiry} from "@/api/purchasingManage/inquiryManage";
  35. import {contactDetail, contactTypeTree} from "@/api/saleManage/contact";
  36. export default {
  37. name: "generateContractsDialog",
  38. components: {inquiryTable},
  39. props: {
  40. generateContractsDialogFlag: {
  41. type: Boolean,
  42. default: false,
  43. },
  44. },
  45. data() {
  46. return {
  47. form: {
  48. supplierList: []
  49. },
  50. treeList: []
  51. };
  52. },
  53. methods: {
  54. async open(row) {
  55. await this.getInquiryData(row.id);
  56. await this.getTreeData();
  57. },
  58. async getInquiryData(id) {
  59. this.loading = true;
  60. const data = await getpurchaseinquiry(id);
  61. this.loading = false;
  62. if (data) {
  63. this.form = data;
  64. }
  65. },
  66. //获取合同分类
  67. async getTreeData() {
  68. try {
  69. this.treeLoading = true;
  70. const res = await contactTypeTree({ id: '20' });
  71. this.treeLoading = false;
  72. if (res?.code === '0') {
  73. this.treeList = res.data;
  74. return this.treeList;
  75. }
  76. } catch (error) {
  77. }
  78. this.treeLoading = false;
  79. },
  80. async handleGenerate(i) {
  81. let contractInfo = await generateContract({inquiryIds: [this.form.id], supplierId: i.supplierId});
  82. let contact = await contactDetail(contractInfo.contractVO.partbId);
  83. contractInfo.contractVO.contractName = contact.base.simpleName;
  84. await this.setContractInfo(contractInfo);
  85. },
  86. async setContractInfo(data) {
  87. if (data) {
  88. //获取优惠金额和总计的差价
  89. let diffPrice = Number(data.contractVO.totalPrice) - Number(data.contractVO.discountTotalPrice)
  90. data.productList.forEach((item) => {
  91. if (data.contractVO.discountTotalPrice === 0) {
  92. item.discountTotalPrice = 0
  93. item.discountSinglePrice = 0
  94. return
  95. }
  96. if (!data.contractVO.discountTotalPrice) {
  97. item.discountTotalPrice = item.totalPrice
  98. item.discountSinglePrice = item.singlePrice
  99. return
  100. }
  101. //获取详情每条的小计
  102. // 使用小计除以总价得出该条数据小计占比 在乘以差价或的该条数据应承担的差价 在小计-应承担差价获得折让后的小计
  103. item.discountTotalPrice = (Number(item.totalPrice) - Number(item.totalPrice) / Number(data.contractVO.totalPrice) * diffPrice).toFixed(2)
  104. //使用折让后的小计除以数量得到单价
  105. item.discountSinglePrice = (Number(item.discountTotalPrice) / Number(item.totalCount)).toFixed(2)
  106. })
  107. this.$emit('changeParent', {data});
  108. this.cancel();
  109. }
  110. },
  111. cancel() {
  112. this.$emit("update:generateContractsDialogFlag", false);
  113. },
  114. }
  115. }
  116. </script>
  117. <style scoped lang="scss">
  118. </style>