relatedBusiness.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <div class="relatedTasks pl-4 pr-4 pt-3 pb-3 h-full flex flex-col">
  3. <div class="flex justify-between">
  4. <div class="title">相关商机</div>
  5. <div>
  6. <el-button type="primary" @click="editNewBusiness()">新建商机</el-button>
  7. </div>
  8. </div>
  9. <div class="flex-1 overflow-auto pt-3">
  10. <el-table :data="relatedTaskstable" border style="width: 100%;height: 300px;">
  11. <el-table-column prop="taskName" label="商机名称">
  12. <template #default="scope">
  13. <el-button link type="primary" size="large">{{
  14. scope.row.taskName
  15. }}</el-button>
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="priority" label="客户名称" width="130" />
  19. <el-table-column prop="status" label="负责人" width="130" />
  20. <el-table-column prop="executor" label="商机金额" width="130" />
  21. <el-table-column prop="startTime" label="预计成交时间" width="130" />
  22. <el-table-column prop="endTime" label="商机阶段" width="130" />
  23. <el-table-column prop="endTime" label="创建人" width="130" />
  24. <el-table-column prop="endTime" label="创建时间" width="130" />
  25. <el-table-column prop="endTime" label="修改时间" width="130" />
  26. </el-table>
  27. </div>
  28. <el-dialog v-model="allVisible.newBusinessisible" width="1000" :show-close="false" top="10vh">
  29. <template #header="{ close, titleId, titleClass }">
  30. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  31. <h4 :id="titleId">{{ '新建商机' }}</h4>
  32. <div>
  33. <el-button type="primary" @click="editBusiness(false)" :loading="allLoading.businessSaveLading"
  34. :disabled="allLoading.newBusinessSaveLading">保存</el-button>
  35. <el-button @click="closeVisible('newBusinessisible')">取消</el-button>
  36. </div>
  37. </div>
  38. </template>
  39. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3" v-loading="allLoading.generateFormLading">
  40. <GenerateForm ref="businessTemplateRef" :data="businessTemplate" :value="businessTemplateValue"
  41. :key="businessTemplateKey" />
  42. <div>相关产品</div>
  43. <RelatedProducts ref="relatedProductsRef" :productTableList="productTableList"
  44. :productTableListValue="productTableListValue" />
  45. </div>
  46. </el-dialog>
  47. </div>
  48. </template>
  49. <script lang="ts" setup>
  50. import { get, post } from '@/utils/request';
  51. import { ref, reactive, onMounted, onUnmounted, defineExpose, inject, watchEffect } from 'vue'
  52. import { GenerateForm } from '@zmjs/form-design';
  53. import RelatedProducts from '@/components/relatedProducts/relatedProducts.vue'
  54. import { GETTABLELIST } from '@/pages/product/api';
  55. import { GETGENERATEFOEM, UPDATEINSET } from '@/pages/business/api';
  56. import { judgmentaAmounteEqual, setTemplateDataDisable } from '@/utils/tools';
  57. import { formatDateTime } from '@/utils/times';
  58. const emits = defineEmits(['refreshData']);
  59. const globalPopup = inject<GlobalPopup>('globalPopup')
  60. const props = defineProps<{
  61. data: any
  62. }>()
  63. const information = ref<any>({})
  64. const relatedTaskstable = ref([])
  65. const relatedProductsRef = ref<typeof RelatedProducts>()
  66. const businessTemplateRef = ref<typeof GenerateForm>() // 自定义表单dom
  67. const businessTemplateValue = ref({})
  68. const businessTemplateKey = ref(1)
  69. const productTableList = ref([])
  70. const productTableListValue = ref([])
  71. const businessTemplate = ref({
  72. config: {},
  73. list: []
  74. }) // 自定义表单数据
  75. const allVisible = reactive({
  76. newBusinessisible: false
  77. })
  78. const allLoading = reactive({
  79. generateFormLading: false,
  80. newBusinessSaveLading: false,
  81. businessSaveLading: false
  82. })
  83. function editBusiness(visibles: boolean) {
  84. businessTemplateRef.value?.getData().then((res: any) => {
  85. let productTableListData = relatedProductsRef?.value?.returnData()
  86. if(!productTableListData || judgmentaAmounteEqual({ ...businessTemplateValue.value, ...res }, productTableListData)) {
  87. return
  88. }
  89. productTableListData.forEach((item: any) => {
  90. delete item.id
  91. })
  92. let newForm = {
  93. ...res,
  94. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  95. businessItemProductList: productTableListData ? JSON.stringify(productTableListData) : []
  96. }
  97. allLoading.businessSaveLading = true
  98. post(UPDATEINSET, { ...businessTemplateValue.value, ...newForm }).then((_res) => {
  99. allVisible.newBusinessisible = visibles
  100. globalPopup?.showSuccess('保存成功')
  101. emits('refreshData')
  102. }).finally(() => {
  103. allLoading.businessSaveLading = false
  104. })
  105. }).catch((_err: any) => {
  106. console.log(_err)
  107. globalPopup?.showError('请填写完整')
  108. })
  109. }
  110. function editNewBusiness() {
  111. showVisible('newBusinessisible')
  112. allLoading.generateFormLading = true
  113. businessTemplateValue.value = { customerId: information.value.id }
  114. productTableListValue.value = []
  115. setTimeout(() => {
  116. businessTemplateRef.value && businessTemplateRef.value.reset()
  117. businessTemplateKey.value++
  118. allLoading.generateFormLading = false
  119. }, 500)
  120. }
  121. async function getSystemField() {
  122. const datas = await get(GETGENERATEFOEM)
  123. let newConfig = JSON.parse(datas.data[0].config)
  124. newConfig.list = setTemplateDataDisable(newConfig.list, ['customerId'])
  125. businessTemplate.value = newConfig
  126. }
  127. function showVisible(type: keyof typeof allVisible) {
  128. allVisible[type] = true
  129. }
  130. function closeVisible(type: keyof typeof allVisible) {
  131. allVisible[type] = false
  132. }
  133. function getProductTableList() {
  134. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  135. if (res.code == 'ok') {
  136. const { record, total } = res.data
  137. productTableList.value = record.map((item: any) => {
  138. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  139. return {
  140. id,
  141. productId: id,
  142. productName,
  143. productCode,
  144. unit,
  145. unitName,
  146. price,
  147. type,
  148. typeName,
  149. inventory,
  150. quantity: '',
  151. discount: '',
  152. totalPrice: ''
  153. }
  154. })
  155. }
  156. })
  157. }
  158. watchEffect(() => {
  159. const { data } = props
  160. information.value = data
  161. relatedTaskstable.value = []
  162. })
  163. // 生命周期钩子
  164. onMounted(() => {
  165. getProductTableList()
  166. getSystemField()
  167. });
  168. </script>
  169. <style scoped lang="scss">
  170. .relatedTasks {
  171. .title {
  172. font-size: 18px;
  173. color: #000
  174. }
  175. }
  176. </style>