relatedBusiness.vue 8.0 KB

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