relatedBusiness.vue 7.1 KB

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