relatedBusiness.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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="addBusiness()">新建商机</el-button>
  7. </div>
  8. </div>
  9. <div class="flex-1 overflow-auto pt-3">
  10. <el-table :data="relatedTaskstable" border height="300" style="width: 100%;">
  11. <el-table-column prop="name" label="商机名称">
  12. <template #default="scope">
  13. <el-button link type="primary" size="large" @click="toBusDetal(scope.row)">{{
  14. scope.row.name
  15. }}</el-button>
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="customerName" label="客户名称" width="140" />
  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="170" />
  22. <el-table-column prop="stageValue" label="商机阶段" width="130" />
  23. <el-table-column prop="creatorName" label="创建人" width="130" />
  24. <el-table-column prop="createTime" label="创建时间" width="130" />
  25. </el-table>
  26. </div>
  27. <!-- 弹窗 -->
  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()"
  34. :loading="allLoading.businessSaveLading">保存</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. </div>
  45. </el-dialog>
  46. </div>
  47. </template>
  48. <script lang="ts" setup>
  49. import { ref, reactive, onMounted, onUnmounted, defineExpose, inject, watchEffect } from 'vue'
  50. import { GenerateForm } from '@zmjs/form-design';
  51. import { get, post } from '@/utils/request';
  52. import { useRouter, useRoute } from "vue-router";
  53. import RelatedProducts from '@/components/relatedProducts/relatedProducts.vue'
  54. import { formatDateTime } from '@/utils/times';
  55. import { GETGENERATEFOEM, UPDATEINSET } from '@/pages/business/api';
  56. import { GETTABLELIST } from '@/pages/product/api';
  57. import { judgmentaAmounteEqual } from '@/utils/tools';
  58. const router = useRouter()
  59. const globalPopup = inject<GlobalPopup>('globalPopup')
  60. const emits = defineEmits(['refreshData']);
  61. const props = defineProps<{
  62. data: any
  63. }>()
  64. const information = ref<any>({})
  65. const relatedTaskstable = ref([])
  66. const businessTemplateRef = ref<typeof GenerateForm>() // 自定义表单dom
  67. const relatedProductsRef = ref<typeof RelatedProducts>()
  68. const productTableList = ref([])
  69. const businessTemplateValue = ref({})
  70. const businessTemplateKey = ref(1)
  71. const businessTemplate = ref({
  72. config: {},
  73. list: []
  74. }) // 自定义表单数据
  75. const allLoading = reactive({
  76. newBusinessSaveLading: false,
  77. businessSaveLading: false,
  78. generateFormLading: false
  79. })
  80. const allVisible = reactive({
  81. newBusinessisible: false
  82. })
  83. function toBusDetal(row: any) {
  84. router.push({
  85. path: `/business/detail`,
  86. query: { id: row.id }
  87. })
  88. }
  89. function editBusiness() {
  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. let newForm = {
  96. ...res,
  97. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  98. businessItemProductList: productTableListData ? JSON.stringify(productTableListData) : []
  99. }
  100. allLoading.businessSaveLading = true
  101. post(UPDATEINSET, { ...businessTemplateValue.value, ...newForm }).then((_res) => {
  102. allVisible.newBusinessisible = false
  103. globalPopup?.showSuccess('保存成功')
  104. emits('refreshData')
  105. }).finally(() => {
  106. allLoading.businessSaveLading = false
  107. })
  108. }).catch((_err: any) => {
  109. console.log(_err)
  110. globalPopup?.showError('请填写完整')
  111. })
  112. }
  113. function addBusiness() {
  114. showVisible('newBusinessisible')
  115. allLoading.generateFormLading = true
  116. businessTemplateValue.value = {
  117. customerId: information.value.customId,
  118. contactsId: information.value.id
  119. }
  120. setTimeout(() => {
  121. businessTemplateRef.value && businessTemplateRef.value.reset()
  122. businessTemplateKey.value++
  123. allLoading.generateFormLading = false
  124. }, 500)
  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. watchEffect(() => {
  133. const { data } = props
  134. information.value = data
  135. relatedTaskstable.value = data.businessOpportunityList
  136. });
  137. async function getSystemField() {
  138. const res = await get(GETGENERATEFOEM)
  139. let config = JSON.parse(res.data[0].config)
  140. config.list.forEach((item: any) => {
  141. if (item.type == "grid") {
  142. item.columns.forEach((column: any) => {
  143. column.list.forEach((newColumn: any) => {
  144. if (newColumn.model == 'customerId' || newColumn.model == "contactsId") {
  145. newColumn.options.disabled = true
  146. }
  147. })
  148. })
  149. }
  150. })
  151. businessTemplate.value = config
  152. }
  153. function getProductTableList() {
  154. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  155. if (res.code == 'ok') {
  156. const { record, total } = res.data
  157. productTableList.value = record.map((item: any) => {
  158. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  159. return {
  160. id,
  161. productId: id,
  162. productName,
  163. productCode,
  164. unit,
  165. unitName,
  166. price,
  167. type,
  168. typeName,
  169. inventory,
  170. quantity: '',
  171. discount: '',
  172. totalPrice: ''
  173. }
  174. })
  175. }
  176. })
  177. }
  178. // 生命周期钩子
  179. onMounted(() => {
  180. getSystemField()
  181. getProductTableList()
  182. });
  183. </script>
  184. <style scoped lang="scss"></style>