relatedBusiness.vue 7.8 KB

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