index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <CustomerDetailsHeader :customer="customer" :loading="loading">
  3. <el-button
  4. v-if="permissionListRef?.validateWrite"
  5. v-hasPermi="['crm:customer:update']"
  6. type="primary"
  7. @click="openForm"
  8. >
  9. 编辑
  10. </el-button>
  11. <el-button v-if="permissionListRef?.validateOwnerUser" type="primary" @click="transfer">
  12. 转移
  13. </el-button>
  14. <el-button v-if="permissionListRef?.validateWrite" @click="handleUpdateDealStatus">
  15. 更改成交状态
  16. </el-button>
  17. <el-button
  18. v-if="customer.lockStatus && permissionListRef?.validateOwnerUser"
  19. @click="handleUnlock"
  20. >
  21. 解锁
  22. </el-button>
  23. <el-button
  24. v-if="!customer.lockStatus && permissionListRef?.validateOwnerUser"
  25. @click="handleLock"
  26. >
  27. 锁定
  28. </el-button>
  29. <el-button v-if="!customer.ownerUserId" type="primary" @click="handleReceive"> 领取</el-button>
  30. <el-button v-if="!customer.ownerUserId" type="primary" @click="handleDistributeForm">
  31. 分配
  32. </el-button>
  33. <el-button
  34. v-if="customer.ownerUserId && permissionListRef?.validateOwnerUser"
  35. @click="handlePutPool"
  36. >
  37. 放入公海
  38. </el-button>
  39. </CustomerDetailsHeader>
  40. <el-col>
  41. <el-tabs>
  42. <el-tab-pane label="跟进记录">
  43. <FollowUpList :biz-id="customerId" :biz-type="BizTypeEnum.CRM_CUSTOMER" />
  44. </el-tab-pane>
  45. <el-tab-pane label="基本信息">
  46. <CustomerDetailsInfo :customer="customer" />
  47. </el-tab-pane>
  48. <el-tab-pane label="联系人" lazy>
  49. <ContactList :biz-id="customer.id!" :biz-type="BizTypeEnum.CRM_CUSTOMER" />
  50. </el-tab-pane>
  51. <el-tab-pane label="团队成员">
  52. <PermissionList
  53. ref="permissionListRef"
  54. :biz-id="customer.id!"
  55. :biz-type="BizTypeEnum.CRM_CUSTOMER"
  56. :show-action="!permissionListRef?.isPool || false"
  57. @quit-team="close"
  58. />
  59. </el-tab-pane>
  60. <el-tab-pane label="商机" lazy>
  61. <BusinessList :biz-id="customer.id!" :biz-type="BizTypeEnum.CRM_CUSTOMER" />
  62. </el-tab-pane>
  63. <el-tab-pane label="合同" lazy>
  64. <ContractList :biz-id="customer.id!" :biz-type="BizTypeEnum.CRM_CUSTOMER" />
  65. </el-tab-pane>
  66. <el-tab-pane label="回款" lazy>
  67. <ReceivablePlanList :customer-id="customer.id!" @crate-receivable="crateReceivable" />
  68. <ReceivableList ref="receivableListRef" :customer-id="customer.id!" />
  69. </el-tab-pane>
  70. <el-tab-pane label="操作日志">
  71. <OperateLogV2 :log-list="logList" />
  72. </el-tab-pane>
  73. </el-tabs>
  74. </el-col>
  75. <!-- 表单弹窗:添加/修改 -->
  76. <CustomerForm ref="formRef" @success="getCustomer" />
  77. <CustomerDistributeForm ref="distributeForm" @success="getCustomer" />
  78. <CrmTransferForm ref="transferFormRef" @success="getCustomer" />
  79. </template>
  80. <script lang="ts" setup>
  81. import { useTagsViewStore } from '@/store/modules/tagsView'
  82. import * as CustomerApi from '@/api/crm/customer'
  83. import CustomerForm from '@/views/crm/customer/CustomerForm.vue'
  84. import CustomerDetailsInfo from './CustomerDetailsInfo.vue' // 客户明细 - 详细信息
  85. import CustomerDetailsHeader from './CustomerDetailsHeader.vue' // 客户明细 - 头部
  86. import ContactList from '@/views/crm/contact/components/ContactList.vue' // 联系人列表
  87. import ContractList from '@/views/crm/contract/components/ContractList.vue' // 合同列表
  88. import BusinessList from '@/views/crm/business/components/BusinessList.vue' // 商机列表
  89. import ReceivableList from '@/views/crm/receivable/components/ReceivableList.vue' // 回款列表
  90. import ReceivablePlanList from '@/views/crm/receivable/plan/components/ReceivablePlanList.vue' // 回款计划列表
  91. import PermissionList from '@/views/crm/permission/components/PermissionList.vue' // 团队成员列表(权限)
  92. import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue'
  93. import FollowUpList from '@/views/crm/followup/index.vue'
  94. import { BizTypeEnum } from '@/api/crm/permission'
  95. import type { OperateLogV2VO } from '@/api/system/operatelog'
  96. import { getOperateLogPage } from '@/api/crm/operateLog'
  97. import CustomerDistributeForm from '@/views/crm/customer/pool/CustomerDistributeForm.vue'
  98. defineOptions({ name: 'CrmCustomerDetail' })
  99. const customerId = ref(0) // 客户编号
  100. const loading = ref(true) // 加载中
  101. const message = useMessage() // 消息弹窗
  102. const { delView } = useTagsViewStore() // 视图操作
  103. const { push, currentRoute } = useRouter() // 路由
  104. const permissionListRef = ref<InstanceType<typeof PermissionList>>() // 团队成员列表 Ref
  105. /** 获取详情 */
  106. const customer = ref<CustomerApi.CustomerVO>({} as CustomerApi.CustomerVO) // 客户详情
  107. const getCustomer = async () => {
  108. loading.value = true
  109. try {
  110. customer.value = await CustomerApi.getCustomer(customerId.value)
  111. await getOperateLog()
  112. } finally {
  113. loading.value = false
  114. }
  115. }
  116. /** 编辑客户 */
  117. const formRef = ref<InstanceType<typeof CustomerForm>>() // 客户表单 Ref
  118. const openForm = () => {
  119. formRef.value?.open('update', customerId.value)
  120. }
  121. /** 更新成交状态操作 */
  122. const handleUpdateDealStatus = async () => {
  123. const dealStatus = !customer.value.dealStatus
  124. try {
  125. // 更新状态的二次确认
  126. await message.confirm(`确定更新成交状态为【${dealStatus ? '已成交' : '未成交'}】吗?`)
  127. // 发起更新
  128. await CustomerApi.updateCustomerDealStatus(customerId.value, dealStatus)
  129. message.success(`更新成交状态成功`)
  130. // 刷新数据
  131. await getCustomer()
  132. } catch {}
  133. }
  134. /** 客户转移 */
  135. const transferFormRef = ref<InstanceType<typeof CrmTransferForm>>() // 客户转移表单 ref
  136. const transfer = () => {
  137. transferFormRef.value?.open('客户转移', customerId.value, CustomerApi.transferCustomer)
  138. }
  139. /** 锁定客户 */
  140. const handleLock = async () => {
  141. await message.confirm(`确定锁定客户【${customer.value.name}】 吗?`)
  142. await CustomerApi.lockCustomer(unref(customerId.value), true)
  143. message.success(`锁定客户【${customer.value.name}】成功`)
  144. await getCustomer()
  145. }
  146. /** 解锁客户 */
  147. const handleUnlock = async () => {
  148. await message.confirm(`确定解锁客户【${customer.value.name}】 吗?`)
  149. await CustomerApi.lockCustomer(unref(customerId.value), false)
  150. message.success(`解锁客户【${customer.value.name}】成功`)
  151. await getCustomer()
  152. }
  153. /** 领取客户 */
  154. const handleReceive = async () => {
  155. await message.confirm(`确定领取客户【${customer.value.name}】 吗?`)
  156. await CustomerApi.receiveCustomer([unref(customerId.value)])
  157. message.success(`领取客户【${customer.value.name}】成功`)
  158. await getCustomer()
  159. }
  160. /** 分配客户 */
  161. const distributeForm = ref<InstanceType<typeof CustomerDistributeForm>>() // 分配客户表单 Ref
  162. const handleDistributeForm = async () => {
  163. distributeForm.value?.open(customerId.value)
  164. }
  165. /** 客户放入公海 */
  166. const handlePutPool = async () => {
  167. await message.confirm(`确定将客户【${customer.value.name}】放入公海吗?`)
  168. await CustomerApi.putCustomerPool(unref(customerId.value))
  169. message.success(`客户【${customer.value.name}】放入公海成功`)
  170. // 加载
  171. close()
  172. }
  173. /** 获取操作日志 */
  174. const logList = ref<OperateLogV2VO[]>([]) // 操作日志列表
  175. const getOperateLog = async () => {
  176. if (!customerId.value) {
  177. return
  178. }
  179. const data = await getOperateLogPage({
  180. bizType: BizTypeEnum.CRM_CUSTOMER,
  181. bizId: customerId.value
  182. })
  183. logList.value = data.list
  184. }
  185. /** 从回款计划创建回款 */
  186. const receivableListRef = ref<InstanceType<typeof ReceivableList>>() // 回款列表 Ref
  187. const crateReceivable = (planData: any) => {
  188. receivableListRef.value?.crateReceivable(planData)
  189. }
  190. const close = () => {
  191. delView(unref(currentRoute))
  192. push({ name: 'CrmCustomer' })
  193. }
  194. /** 初始化 */
  195. const { params } = useRoute()
  196. onMounted(() => {
  197. if (!params.id) {
  198. message.warning('参数错误,客户不能为空!')
  199. close()
  200. return
  201. }
  202. customerId.value = params.id as unknown as number
  203. getCustomer()
  204. })
  205. </script>