relatedBusiness.vue 7.4 KB

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