relatedBusiness.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. 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. let newForm = {
  93. ...res,
  94. expectedTransactionDate: res.expectedTransactionDate ? formatDateTime(new Date(res.expectedTransactionDate)) : '',
  95. businessItemProductList: productTableListData ? JSON.stringify(productTableListData) : []
  96. }
  97. allLoading.businessSaveLading = true
  98. post(UPDATEINSET, { ...businessTemplateValue.value, ...newForm }).then((_res) => {
  99. allVisible.newBusinessisible = false
  100. globalPopup?.showSuccess('保存成功')
  101. emits('refreshData')
  102. }).finally(() => {
  103. allLoading.businessSaveLading = false
  104. })
  105. }).catch((_err: any) => {
  106. console.log(_err)
  107. globalPopup?.showError('请填写完整')
  108. })
  109. }
  110. function addBusiness() {
  111. showVisible('newBusinessisible')
  112. allLoading.generateFormLading = true
  113. businessTemplateValue.value = {
  114. customerId: information.value.customId,
  115. contactsId: information.value.id
  116. }
  117. setTimeout(() => {
  118. businessTemplateRef.value && businessTemplateRef.value.reset()
  119. businessTemplateKey.value++
  120. allLoading.generateFormLading = false
  121. }, 500)
  122. }
  123. function showVisible(type: keyof typeof allVisible) { // 显示弹窗
  124. allVisible[type] = true
  125. }
  126. function closeVisible(type: keyof typeof allVisible) {
  127. allVisible[type] = false
  128. }
  129. watchEffect(() => {
  130. const { data } = props
  131. information.value = data
  132. relatedTaskstable.value = data.businessOpportunityList
  133. });
  134. async function getSystemField() {
  135. const res = await get(GETGENERATEFOEM)
  136. let config = JSON.parse(res.data[0].config)
  137. config.list.forEach((item: any) => {
  138. if (item.type == "grid") {
  139. item.columns.forEach((column: any) => {
  140. column.list.forEach((newColumn: any) => {
  141. if (newColumn.model == 'customerId' || newColumn.model == "contactsId") {
  142. newColumn.options.disabled = true
  143. }
  144. })
  145. })
  146. }
  147. })
  148. businessTemplate.value = config
  149. }
  150. function getProductTableList() {
  151. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  152. if (res.code == 'ok') {
  153. const { record, total } = res.data
  154. productTableList.value = record.map((item: any) => {
  155. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  156. return {
  157. id,
  158. productId: id,
  159. productName,
  160. productCode,
  161. unit,
  162. unitName,
  163. price,
  164. type,
  165. typeName,
  166. inventory,
  167. quantity: '',
  168. discount: '',
  169. totalPrice: ''
  170. }
  171. })
  172. }
  173. })
  174. }
  175. // 生命周期钩子
  176. onMounted(() => {
  177. getSystemField()
  178. getProductTableList()
  179. });
  180. </script>
  181. <style scoped lang="scss"></style>