relatedBusiness.vue 8.2 KB

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