relatedBusiness.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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="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">{{
  14. scope.row.taskName
  15. }}</el-button>
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="priority" label="客户名称" width="130" />
  19. <el-table-column prop="status" label="负责人" width="130" />
  20. <el-table-column prop="executor" label="商机金额" width="130" />
  21. <el-table-column prop="startTime" label="预计成交时间" width="130" />
  22. <el-table-column prop="endTime" label="商机阶段" width="130" />
  23. <el-table-column prop="endTime" label="创建人" width="130" />
  24. <el-table-column prop="endTime" label="创建时间" width="130" />
  25. <el-table-column prop="endTime" label="修改时间" width="130" />
  26. </el-table>
  27. </div>
  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(false)" :loading="allLoading.businessSaveLading"
  34. :disabled="allLoading.newBusinessSaveLading">保存</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. :productTableListValue="productTableListValue" />
  45. </div>
  46. </el-dialog>
  47. </div>
  48. </template>
  49. <script lang="ts" setup>
  50. import { get, post } from '@/utils/request';
  51. import { ref, reactive, onMounted, onUnmounted, defineExpose, inject, watchEffect } from 'vue'
  52. import { GenerateForm } from '@zmjs/form-design';
  53. import RelatedProducts from '@/components/relatedProducts/relatedProducts.vue'
  54. import { GETTABLELIST } from '@/pages/product/api';
  55. import { GETGENERATEFOEM, UPDATEINSET } from '@/pages/business/api';
  56. import { setTemplateDataDisable } from '@/utils/tools';
  57. import { formatDateTime } from '@/utils/times';
  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 editBusiness(visibles: boolean) {
  84. businessTemplateRef.value?.getData().then((res: any) => {
  85. let productTableListData = relatedProductsRef?.value?.returnData() || []
  86. productTableListData.forEach((item: any) => {
  87. delete item.id
  88. })
  89. let newForm = {
  90. ...res,
  91. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  92. businessItemProductList: productTableListData ? JSON.stringify(productTableListData) : []
  93. }
  94. allLoading.businessSaveLading = true
  95. post(UPDATEINSET, { ...businessTemplateValue.value, ...newForm }).then((_res) => {
  96. allVisible.newBusinessisible = visibles
  97. globalPopup?.showSuccess('保存成功')
  98. emits('refreshData')
  99. }).finally(() => {
  100. allLoading.businessSaveLading = false
  101. })
  102. }).catch((_err: any) => {
  103. console.log(_err)
  104. globalPopup?.showError('请填写完整')
  105. })
  106. }
  107. function editNewBusiness() {
  108. showVisible('newBusinessisible')
  109. allLoading.generateFormLading = true
  110. businessTemplateValue.value = { customerId: information.value.id }
  111. productTableListValue.value = []
  112. setTimeout(() => {
  113. businessTemplateRef.value && businessTemplateRef.value.reset()
  114. businessTemplateKey.value++
  115. allLoading.generateFormLading = false
  116. }, 500)
  117. }
  118. async function getSystemField() {
  119. const datas = await get(GETGENERATEFOEM)
  120. let newConfig = JSON.parse(datas.data[0].config)
  121. newConfig.list = setTemplateDataDisable(newConfig.list, ['customerId'])
  122. businessTemplate.value = newConfig
  123. }
  124. function showVisible(type: keyof typeof allVisible) {
  125. allVisible[type] = true
  126. }
  127. function closeVisible(type: keyof typeof allVisible) {
  128. allVisible[type] = false
  129. }
  130. function getProductTableList() {
  131. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  132. if (res.code == 'ok') {
  133. const { record, total } = res.data
  134. productTableList.value = record.map((item: any) => {
  135. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  136. return {
  137. id,
  138. productId: id,
  139. productName,
  140. productCode,
  141. unit,
  142. unitName,
  143. price,
  144. type,
  145. typeName,
  146. inventory,
  147. quantity: '',
  148. discount: '',
  149. totalPrice: ''
  150. }
  151. })
  152. }
  153. })
  154. }
  155. watchEffect(() => {
  156. const { data } = props
  157. information.value = data
  158. relatedTaskstable.value = []
  159. })
  160. // 生命周期钩子
  161. onMounted(() => {
  162. getProductTableList()
  163. getSystemField()
  164. });
  165. </script>
  166. <style scoped lang="scss">
  167. .relatedTasks {
  168. .title {
  169. font-size: 18px;
  170. color: #000
  171. }
  172. }
  173. </style>