relatedBusiness.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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="商机名称">
  12. <template #default="scope">
  13. <el-button link type="primary" size="large" @click="toDetail(scope.row)">{{
  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. import router from '@/router';
  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 toDetail(row: any) {
  84. router.push({
  85. path: `/business/detail`,
  86. query: { id: row.id }
  87. })
  88. }
  89. function editBusiness(visibles: boolean) {
  90. businessTemplateRef.value?.getData().then((res: any) => {
  91. let productTableListData = relatedProductsRef?.value?.returnData()
  92. if (!productTableListData || judgmentaAmounteEqual({ ...businessTemplateValue.value, ...res }, productTableListData)) {
  93. return
  94. }
  95. productTableListData.forEach((item: any) => {
  96. delete item.id
  97. })
  98. let newForm = {
  99. ...res,
  100. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  101. businessItemProductList: productTableListData ? JSON.stringify(productTableListData) : []
  102. }
  103. allLoading.businessSaveLading = true
  104. post(UPDATEINSET, { ...businessTemplateValue.value, ...newForm }).then((_res) => {
  105. allVisible.newBusinessisible = visibles
  106. globalPopup?.showSuccess('保存成功')
  107. emits('refreshData')
  108. }).finally(() => {
  109. allLoading.businessSaveLading = false
  110. })
  111. }).catch((_err: any) => {
  112. console.log(_err)
  113. globalPopup?.showError('请填写完整')
  114. })
  115. }
  116. function editNewBusiness() {
  117. showVisible('newBusinessisible')
  118. allLoading.generateFormLading = true
  119. businessTemplateValue.value = { customerId: information.value.id }
  120. productTableListValue.value = []
  121. setTimeout(() => {
  122. businessTemplateRef.value && businessTemplateRef.value.reset()
  123. businessTemplateKey.value++
  124. allLoading.generateFormLading = false
  125. }, 500)
  126. }
  127. async function getSystemField() {
  128. const datas = await get(GETGENERATEFOEM)
  129. let newConfig = JSON.parse(datas.data[0].config)
  130. newConfig.list = setTemplateDataDisable(newConfig.list, ['customerId'])
  131. businessTemplate.value = newConfig
  132. }
  133. function showVisible(type: keyof typeof allVisible) {
  134. allVisible[type] = true
  135. }
  136. function closeVisible(type: keyof typeof allVisible) {
  137. allVisible[type] = false
  138. }
  139. function getProductTableList() {
  140. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  141. if (res.code == 'ok') {
  142. const { record, total } = res.data
  143. productTableList.value = record.map((item: any) => {
  144. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  145. return {
  146. id,
  147. productId: id,
  148. productName,
  149. productCode,
  150. unit,
  151. unitName,
  152. price,
  153. type,
  154. typeName,
  155. inventory,
  156. quantity: '',
  157. discount: '',
  158. totalPrice: ''
  159. }
  160. })
  161. }
  162. })
  163. }
  164. watchEffect(() => {
  165. const { data } = props
  166. information.value = data
  167. relatedTaskstable.value = (data.businessOpportunitys || [])
  168. })
  169. // 生命周期钩子
  170. onMounted(() => {
  171. getProductTableList()
  172. getSystemField()
  173. });
  174. </script>
  175. <style scoped lang="scss">
  176. .relatedTasks {
  177. .title {
  178. font-size: 18px;
  179. color: #000
  180. }
  181. }
  182. </style>