index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <doc-alert title="【客户】客户管理、公海客户" url="https://doc.iocoder.cn/crm/customer/" />
  3. <doc-alert title="【通用】数据权限" url="https://doc.iocoder.cn/crm/permission/" />
  4. <ContentWrap>
  5. <!-- 搜索工作栏 -->
  6. <el-form
  7. ref="queryFormRef"
  8. :inline="true"
  9. :model="queryParams"
  10. class="-mb-15px"
  11. label-width="68px"
  12. >
  13. <el-form-item label="客户名称" prop="name">
  14. <el-input
  15. v-model="queryParams.name"
  16. class="!w-240px"
  17. clearable
  18. placeholder="请输入客户名称"
  19. @keyup.enter="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="手机" prop="mobile">
  23. <el-input
  24. v-model="queryParams.mobile"
  25. class="!w-240px"
  26. clearable
  27. placeholder="请输入手机"
  28. @keyup.enter="handleQuery"
  29. />
  30. </el-form-item>
  31. <el-form-item label="所属行业" prop="industryId">
  32. <el-select
  33. v-model="queryParams.industryId"
  34. class="!w-240px"
  35. clearable
  36. placeholder="请选择所属行业"
  37. >
  38. <el-option
  39. v-for="dict in getIntDictOptions(DICT_TYPE.CRM_CUSTOMER_INDUSTRY)"
  40. :key="dict.value"
  41. :label="dict.label"
  42. :value="dict.value"
  43. />
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item label="客户级别" prop="level">
  47. <el-select
  48. v-model="queryParams.level"
  49. class="!w-240px"
  50. clearable
  51. placeholder="请选择客户级别"
  52. >
  53. <el-option
  54. v-for="dict in getIntDictOptions(DICT_TYPE.CRM_CUSTOMER_LEVEL)"
  55. :key="dict.value"
  56. :label="dict.label"
  57. :value="dict.value"
  58. />
  59. </el-select>
  60. </el-form-item>
  61. <el-form-item label="客户来源" prop="source">
  62. <el-select
  63. v-model="queryParams.source"
  64. class="!w-240px"
  65. clearable
  66. placeholder="请选择客户来源"
  67. >
  68. <el-option
  69. v-for="dict in getIntDictOptions(DICT_TYPE.CRM_CUSTOMER_SOURCE)"
  70. :key="dict.value"
  71. :label="dict.label"
  72. :value="dict.value"
  73. />
  74. </el-select>
  75. </el-form-item>
  76. <el-form-item>
  77. <el-button @click="handleQuery">
  78. <Icon class="mr-5px" icon="ep:search" />
  79. 搜索
  80. </el-button>
  81. <el-button @click="resetQuery(undefined)">
  82. <Icon class="mr-5px" icon="ep:refresh" />
  83. 重置
  84. </el-button>
  85. <el-button v-hasPermi="['crm:customer:create']" type="primary" @click="openForm('create')">
  86. <Icon class="mr-5px" icon="ep:plus" />
  87. 新增
  88. </el-button>
  89. <el-button v-hasPermi="['crm:customer:import']" plain type="warning" @click="handleImport">
  90. <Icon icon="ep:upload" />
  91. 导入
  92. </el-button>
  93. <el-button
  94. v-hasPermi="['crm:customer:export']"
  95. :loading="exportLoading"
  96. plain
  97. type="success"
  98. @click="handleExport"
  99. >
  100. <Icon class="mr-5px" icon="ep:download" />
  101. 导出
  102. </el-button>
  103. </el-form-item>
  104. </el-form>
  105. </ContentWrap>
  106. <!-- 列表 -->
  107. <ContentWrap>
  108. <el-tabs v-model="activeName" @tab-click="handleTabClick">
  109. <el-tab-pane label="我负责的" name="1" />
  110. <el-tab-pane label="我参与的" name="2" />
  111. <el-tab-pane label="下属负责的" name="3" />
  112. </el-tabs>
  113. <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
  114. <el-table-column align="center" label="客户名称" fixed="left" prop="name" width="160">
  115. <template #default="scope">
  116. <el-link :underline="false" type="primary" @click="openDetail(scope.row.id)">
  117. {{ scope.row.name }}
  118. </el-link>
  119. </template>
  120. </el-table-column>
  121. <el-table-column align="center" label="客户来源" prop="source" width="100">
  122. <template #default="scope">
  123. <dict-tag :type="DICT_TYPE.CRM_CUSTOMER_SOURCE" :value="scope.row.source" />
  124. </template>
  125. </el-table-column>
  126. <el-table-column label="手机" align="center" prop="mobile" width="120" />
  127. <el-table-column label="电话" align="center" prop="telephone" width="130" />
  128. <el-table-column label="邮箱" align="center" prop="email" width="180" />
  129. <el-table-column align="center" label="客户级别" prop="level" width="135">
  130. <template #default="scope">
  131. <dict-tag :type="DICT_TYPE.CRM_CUSTOMER_LEVEL" :value="scope.row.level" />
  132. </template>
  133. </el-table-column>
  134. <el-table-column align="center" label="客户行业" prop="industryId" width="100">
  135. <template #default="scope">
  136. <dict-tag :type="DICT_TYPE.CRM_CUSTOMER_INDUSTRY" :value="scope.row.industryId" />
  137. </template>
  138. </el-table-column>
  139. <el-table-column
  140. :formatter="dateFormatter"
  141. align="center"
  142. label="下次联系时间"
  143. prop="contactNextTime"
  144. width="180px"
  145. />
  146. <el-table-column align="center" label="备注" prop="remark" width="200" />
  147. <el-table-column align="center" label="锁定状态" prop="lockStatus">
  148. <template #default="scope">
  149. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.lockStatus" />
  150. </template>
  151. </el-table-column>
  152. <el-table-column align="center" label="成交状态" prop="dealStatus">
  153. <template #default="scope">
  154. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.dealStatus" />
  155. </template>
  156. </el-table-column>
  157. <el-table-column
  158. :formatter="dateFormatter"
  159. align="center"
  160. label="最后跟进时间"
  161. prop="contactLastTime"
  162. width="180px"
  163. />
  164. <el-table-column align="center" label="最后跟进记录" prop="contactLastContent" width="200" />
  165. <el-table-column label="地址" align="center" prop="detailAddress" width="180" />
  166. <el-table-column align="center" label="距离进入公海天数" prop="poolDay" width="140">
  167. <template #default="scope"> {{ scope.row.poolDay }} 天</template>
  168. </el-table-column>
  169. <el-table-column align="center" label="负责人" prop="ownerUserName" width="100px" />
  170. <el-table-column align="center" label="所属部门" prop="ownerUserDeptName" width="100px" />
  171. <el-table-column
  172. :formatter="dateFormatter"
  173. align="center"
  174. label="更新时间"
  175. prop="updateTime"
  176. width="180px"
  177. />
  178. <el-table-column
  179. :formatter="dateFormatter"
  180. align="center"
  181. label="创建时间"
  182. prop="createTime"
  183. width="180px"
  184. />
  185. <el-table-column align="center" label="创建人" prop="creatorName" width="100px" />
  186. <el-table-column align="center" fixed="right" label="操作" min-width="150">
  187. <template #default="scope">
  188. <el-button
  189. v-hasPermi="['crm:customer:update']"
  190. link
  191. type="primary"
  192. @click="openForm('update', scope.row.id)"
  193. >
  194. 编辑
  195. </el-button>
  196. <el-button
  197. v-hasPermi="['crm:customer:delete']"
  198. link
  199. type="danger"
  200. @click="handleDelete(scope.row.id)"
  201. >
  202. 删除
  203. </el-button>
  204. </template>
  205. </el-table-column>
  206. </el-table>
  207. <!-- 分页 -->
  208. <Pagination
  209. v-model:limit="queryParams.pageSize"
  210. v-model:page="queryParams.pageNo"
  211. :total="total"
  212. @pagination="getList"
  213. />
  214. </ContentWrap>
  215. <!-- 表单弹窗:添加/修改 -->
  216. <CustomerForm ref="formRef" @success="getList" />
  217. <CustomerImportForm ref="importFormRef" @success="getList" />
  218. </template>
  219. <script lang="ts" setup>
  220. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  221. import { dateFormatter } from '@/utils/formatTime'
  222. import download from '@/utils/download'
  223. import * as CustomerApi from '@/api/crm/customer'
  224. import CustomerForm from './CustomerForm.vue'
  225. import CustomerImportForm from './CustomerImportForm.vue'
  226. import { TabsPaneContext } from 'element-plus'
  227. defineOptions({ name: 'CrmCustomer' })
  228. const message = useMessage() // 消息弹窗
  229. const { t } = useI18n() // 国际化
  230. const loading = ref(true) // 列表的加载中
  231. const total = ref(0) // 列表的总页数
  232. const list = ref([]) // 列表的数据
  233. const queryParams = reactive({
  234. pageNo: 1,
  235. pageSize: 10,
  236. sceneType: '1', // 默认和 activeName 相等
  237. name: '',
  238. mobile: '',
  239. industryId: undefined,
  240. level: undefined,
  241. source: undefined,
  242. pool: undefined
  243. })
  244. const queryFormRef = ref() // 搜索的表单
  245. const exportLoading = ref(false) // 导出的加载中
  246. const activeName = ref('1') // 列表 tab
  247. /** tab 切换 */
  248. const handleTabClick = (tab: TabsPaneContext) => {
  249. queryParams.sceneType = tab.paneName
  250. handleQuery()
  251. }
  252. /** 查询列表 */
  253. const getList = async () => {
  254. loading.value = true
  255. try {
  256. const data = await CustomerApi.getCustomerPage(queryParams)
  257. list.value = data.list
  258. total.value = data.total
  259. } finally {
  260. loading.value = false
  261. }
  262. }
  263. /** 搜索按钮操作 */
  264. const handleQuery = () => {
  265. queryParams.pageNo = 1
  266. getList()
  267. }
  268. /** 重置按钮操作 */
  269. const resetQuery = () => {
  270. queryFormRef.value.resetFields()
  271. handleQuery()
  272. }
  273. /** 打开客户详情 */
  274. const { currentRoute, push } = useRouter()
  275. const openDetail = (id: number) => {
  276. push({ name: 'CrmCustomerDetail', params: { id } })
  277. }
  278. /** 添加/修改操作 */
  279. const formRef = ref()
  280. const openForm = (type: string, id?: number) => {
  281. formRef.value.open(type, id)
  282. }
  283. /** 删除按钮操作 */
  284. const handleDelete = async (id: number) => {
  285. try {
  286. // 删除的二次确认
  287. await message.delConfirm()
  288. // 发起删除
  289. await CustomerApi.deleteCustomer(id)
  290. message.success(t('common.delSuccess'))
  291. // 刷新列表
  292. await getList()
  293. } catch {}
  294. }
  295. /** 导入按钮操作 */
  296. const importFormRef = ref<InstanceType<typeof CustomerImportForm>>()
  297. const handleImport = () => {
  298. importFormRef.value?.open()
  299. }
  300. /** 导出按钮操作 */
  301. const handleExport = async () => {
  302. try {
  303. // 导出的二次确认
  304. await message.exportConfirm()
  305. // 发起导出
  306. exportLoading.value = true
  307. const data = await CustomerApi.exportCustomer(queryParams)
  308. download.excel(data, '客户.xls')
  309. } catch {
  310. } finally {
  311. exportLoading.value = false
  312. }
  313. }
  314. /** 监听路由变化更新列表 */
  315. watch(
  316. () => currentRoute.value,
  317. () => {
  318. getList()
  319. }
  320. )
  321. /** 初始化 **/
  322. onMounted(() => {
  323. getList()
  324. })
  325. </script>