generateContractsDialog1.vue 3.9 KB

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