index.vue 10.0 KB

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