index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <template>
  2. <div class="h-full flex">
  3. <div class="p-5 w-80 pr-0">
  4. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col">
  5. <div class="flex-1 p-3 overflow-y-auto">
  6. <el-form :model="customerCriteriaForm" label-width="70px" style="max-width: 600px">
  7. <el-form-item label="客户名称">
  8. <el-input v-model="customerCriteriaForm.customName" clearable placeholder="请输入"></el-input>
  9. </el-form-item>
  10. <el-form-item label="客户来源">
  11. <el-select v-model="customerCriteriaForm.customSourceId" placeholder="请选择" clearable>
  12. <el-option v-for="item in fixedData.ClueSources" :key="item.id" :label="item.name" :value="item.id" />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="公司号码">
  16. <el-input v-model="customerCriteriaForm.telPhone" clearable placeholder="请输入"></el-input>
  17. </el-form-item>
  18. <el-form-item label="邮箱">
  19. <el-input v-model="customerCriteriaForm.email" clearable placeholder="请输入"></el-input>
  20. </el-form-item>
  21. <el-form-item label="客户行业">
  22. <el-select v-model="customerCriteriaForm.customerIndustryId" placeholder="请选择" clearable>
  23. <el-option v-for="item in fixedData.CustomIndustry" :key="item.id" :label="item.name"
  24. :value="item.id" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="客户级别">
  28. <el-select v-model="customerCriteriaForm.customerLevelId" placeholder="请选择" clearable>
  29. <el-option v-for="item in fixedData.CustomLevel" :key="item.id" :label="item.name" :value="item.id" />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="负责人">
  33. <el-select v-model="customerCriteriaForm.inchargerId" placeholder="请选择" clearable>
  34. <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item label="创建时间">
  38. <el-date-picker v-model="customerCriteriaForm.startTime" type="date" placeholder="请选择" :clearable="false"
  39. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  40. </el-form-item>
  41. <el-form-item label="">
  42. <el-date-picker v-model="customerCriteriaForm.endTime" type="date" placeholder="请选择" :clearable="false"
  43. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  44. </el-form-item>
  45. </el-form>
  46. </div>
  47. <div class="w-full flex p-3 shadow-[0_-3px_5px_0px_rgba(0,0,0,0.2)]">
  48. <El-button class="w-full" @click="resetTable()">重置</El-Button>
  49. <El-button type="primary" class="w-full" @click="searchTable()">搜索</El-Button>
  50. </div>
  51. </div>
  52. </div>
  53. <div class="flex-1 p-5 overflow-auto">
  54. <div class="bg-white w-full h-full p-3 shadow-md rounded-md flex flex-col">
  55. <div class="flex justify-end pb-3">
  56. <el-button type="primary" v-permission="['customerAdd']" @click="editCustomer(false)">新建客户</el-button>
  57. <el-button type="primary" @click="showVisible('batchTransferVisible')"
  58. :disabled="batchTableData.length <= 0">批量转移</el-button>
  59. <el-button type="primary" v-permission="['customerDelete']" @click="batchDeteleItem()" :disabled="batchTableData.length <= 0">批量删除</el-button>
  60. <el-button type="primary" v-permission="['customerRecycle']" @click="showVisible('deteleCustomerVisible')">回收站</el-button>
  61. <el-button type="primary" v-permission="['customerImport']" @click="showVisible('importVisible')">导入</el-button>
  62. <el-button type="primary" v-permission="['customerExport']" @click="exportCustomerTableList()"
  63. :loading="allLoading.exoprtLoading">导出</el-button>
  64. </div>
  65. <div class="flex-1 w-full overflow-hidden">
  66. <el-table ref="customerTableRef" :show-overflow-tooltip="tableShowOverflowTooltip" :data="customerTable" border v-loading="allLoading.customerTableLading"
  67. style="width: 100%;height: 100%;" @selection-change="changeBatch" @sort-change="sortChange">
  68. <el-table-column type="selection" width="55" />
  69. <el-table-column prop="customName" label="客户名称" width="180">
  70. <template #default="scope">
  71. <!-- <el-button link type="primary" size="large" @click.prevent="toCustomerTableDetail(scope.row)">{{
  72. scope.row.customName
  73. }}</el-button> -->
  74. <div class="table-text-textnowrap" @click.prevent="toCustomerTableDetail(scope.row)">{{ scope.row.customName }}</div>
  75. </template>
  76. </el-table-column>
  77. <el-table-column prop="customSourceValue" label="客户来源" width="180"></el-table-column>
  78. <el-table-column prop="companyPhone" label="公司电话" width="180"></el-table-column>
  79. <el-table-column prop="email" label="邮箱" width="200"></el-table-column>
  80. <el-table-column prop="customerIndustryValue" label="客户行业" width="180"></el-table-column>
  81. <el-table-column prop="customerLevelValue" label="客户级别" width="180" sortable="custom"></el-table-column>
  82. <el-table-column prop="inchargerName" label="负责人" width="190"></el-table-column>
  83. <el-table-column prop="creatorName" label="创建人" width="180"></el-table-column>
  84. <el-table-column prop="newCreateTime" label="创建时间" width="180"></el-table-column>
  85. <el-table-column label="操作" fixed="right" width="200" v-permission="['customerEdit', 'tasksAdd', 'customerDelete']">
  86. <template #default="scope">
  87. <el-button link type="primary" size="large" v-permission="['customerEdit']" @click="editCustomer(scope.row)">编辑</el-button>
  88. <el-button link type="primary" size="large" v-permission="['tasksAdd']" @click="newTask(scope.row)">新建任务</el-button>
  89. <el-button link type="danger" size="large" v-permission="['customerDelete']"
  90. @click="customerDeteleItem(scope.row.id, scope.row.customName)">删除</el-button>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. </div>
  95. <div class="flex justify-end pt-3">
  96. <el-pagination layout="total, prev, pager, next, sizes" :total="customerTotalTable"
  97. :hide-on-single-page="true" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  98. </div>
  99. </div>
  100. </div>
  101. <!-- 新建客户 -->
  102. <el-dialog v-model="allVisible.editCustomerVisible" width="1000" :show-close="false" top="10vh">
  103. <template #header="{ close, titleId, titleClass }">
  104. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  105. <h4 :id="titleId">{{ allText.editCustomerText }}</h4>
  106. <div>
  107. <el-button type="primary" :loading="allLoading.editCustomerSaveLoading" v-if="!customerTemplateValue.id"
  108. @click="editCustomerSave(true)">保存并新建</el-button>
  109. <el-button type="primary" :loading="allLoading.editCustomerSaveLoading"
  110. @click="editCustomerSave(false)">保存</el-button>
  111. <el-button @click="closeVisible('editCustomerVisible')">取消</el-button>
  112. </div>
  113. </div>
  114. </template>
  115. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3">
  116. <div class="ml-4 mr-4">
  117. <GenerateForm ref="customerTemplateRef" :data="customerTemplate" :value="customerTemplateValue"
  118. :key="customerTemplateRefKey" v-loading="allLoading.customerTemplateRefLoading" />
  119. </div>
  120. </div>
  121. </el-dialog>
  122. <!-- 批量转移 -->
  123. <el-dialog v-model="allVisible.batchTransferVisible" width="600" :show-close="false" top="10vh">
  124. <template #header="{ close, titleId, titleClass }">
  125. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  126. <h4 :id="titleId">{{ allText.transferText }}</h4>
  127. <div>
  128. <el-button type="primary" v-loading="allLoading.transferLoading" @click="transferBusiness()">转移</el-button>
  129. <el-button @click="allVisible.batchTransferVisible = false">取消</el-button>
  130. </div>
  131. </div>
  132. </template>
  133. <div class="scroll-bar m-6">
  134. <div class="flex mb-4">
  135. <div class="w-20 flex items-center justify-end pr-4">转移至:</div>
  136. <el-select v-model="transferPersonnel" placeholder="请选择" class="flex1">
  137. <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
  138. </el-select>
  139. </div>
  140. <div class="pl-3 text-[#e94a4a]">转移后,将看不到此客户</div>
  141. </div>
  142. </el-dialog>
  143. <el-dialog v-model="allVisible.importVisible" width="680" :show-close="false" top="10vh">
  144. <template #header="{ close, titleId, titleClass }">
  145. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  146. <h4 :id="titleId">导入产品</h4>
  147. <div class="flex">
  148. <el-upload class="upload-demo mr-3" :limit="1" :show-file-list="false" accept=".xlsx"
  149. :http-request="importBusiness">
  150. <el-button type="primary" :loading="allLoading.importLoading">导入</el-button>
  151. </el-upload>
  152. <el-button @click="allVisible.importVisible = false">取消</el-button>
  153. </div>
  154. </div>
  155. </template>
  156. <div class="p-8">
  157. <div class="ml-4 mr-4">
  158. <div class="flex items-center">1、点击下载 <el-link type="primary"
  159. @click="downloadTemplate(IMPORTMOD, allText.importText)">{{ allText.importText }}</el-link></div>
  160. <div class="mt-4">2、填写excel文件、客户名称必填</div>
  161. </div>
  162. </div>
  163. </el-dialog>
  164. <!-- 任务 -->
  165. <TaskModal :visible="allVisible.taskModalVisible" :edit-form="taskModalForm" :save-loading="taskLoading"
  166. @close="closeVisible('taskModalVisible')" @submit="submitForm" :title="'新建任务'"
  167. :disabled-list="['taskType', 'customId']" />
  168. <!-- 回收站 -->
  169. <DeteleBusiness :visibles="allVisible.deteleCustomerVisible" @closeVisible="closeVisible" />
  170. </div>
  171. </template>
  172. <script lang="ts" setup>
  173. import { ref, reactive, onMounted, inject } from "vue";
  174. import { MOD, GETSYSFILED, GETPERSONNEL, URL_TABLELIST, URL_TEMPLALE, URL_EDITSAVE, URL_DETELER, URL_CLAIM, IMPORTMOD, GETALLCLUE, URL_IMPORTEXELS, URL_EXPORTEXELS } from './api.ts'
  175. import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, getLastDayOfMonth, formatDate, getTemplateKey, createTaskFromType, confirmAction, downloadFile, downloadTemplate } from '@/utils/tools'
  176. import { post, get, uploadFile } from "@/utils/request";
  177. import { useRouter, useRoute } from "vue-router";
  178. import { GenerateForm } from '@zmjs/form-design';
  179. import { createTask } from "@/components/TaskModal/taskFunction";
  180. import { ElTable, UploadRequestOptions } from "element-plus";
  181. import { tableShowOverflowTooltip } from '@/utils/globalVariables'
  182. import TaskModal from '@/components/TaskModal/index.vue'
  183. import DeteleBusiness from './component/deteleTables.vue'
  184. // 定义类型
  185. interface fixedDataInterface {
  186. id: string | number,
  187. companyId: string | number,
  188. code: string,
  189. name: string,
  190. seq: string | number,
  191. }
  192. interface personnelInterface {
  193. id: string | number,
  194. name: string,
  195. phone: string,
  196. jobNumber: string
  197. }
  198. interface customerCriteriaFormType { // 线索筛选条件类型
  199. customName: string,
  200. customSourceId: string | number,
  201. telPhone: string,
  202. email: string,
  203. customerIndustryId: string | number,
  204. customerLevelId: string | number,
  205. inchargerId: string | number,
  206. isDesc?: string | number,
  207. startTime: string | number,
  208. endTime: string | number,
  209. pageIndex: string | number,
  210. pageFrom: string | number
  211. }
  212. // 定义变量
  213. const router = useRouter()
  214. const globalPopup = inject<GlobalPopup>('globalPopup')
  215. const customerCriteriaForm = reactive<customerCriteriaFormType>({ // 筛选条件form
  216. customName: '',
  217. customSourceId: '',
  218. telPhone: '',
  219. email: '',
  220. customerIndustryId: '',
  221. customerLevelId: '',
  222. inchargerId: '',
  223. isDesc: '',
  224. startTime: getFirstDayOfMonth(new Date()),
  225. endTime: formatDate(new Date()),
  226. pageIndex: 1,
  227. pageFrom: 10
  228. })
  229. const customerTable = ref([]) // 线索table数据
  230. const customerTotalTable = ref(0) // 线索 table 数据总数
  231. const allLoading = reactive({
  232. customerTableLading: false,
  233. editCustomerSaveLoading: false,
  234. customerTemplateRefLoading: false,
  235. transferLoading: false,
  236. exoprtLoading: false,
  237. importLoading: false
  238. })
  239. const allVisible = reactive({
  240. editCustomerVisible: false,
  241. taskModalVisible: false,
  242. deteleCustomerVisible: false,
  243. batchTransferVisible: false,
  244. importVisible: false
  245. })
  246. const allText = reactive({
  247. editCustomerText: '新建客户',
  248. transferText: '批量转移',
  249. importText: '客户导入模板.xlsx',
  250. exportText: '客户表导出.xlsx'
  251. })
  252. const fixedData = reactive({
  253. ClueSources: [] as fixedDataInterface[],
  254. CustomIndustry: [] as fixedDataInterface[],
  255. CustomLevel: [] as fixedDataInterface[],
  256. Personnel: [] as personnelInterface[]
  257. })
  258. const customerTemplate = ref({
  259. list: [],
  260. config: {}
  261. })
  262. const customerTemplateRef = ref<typeof GenerateForm>() // 自定义表单dom
  263. const customerTemplateValue = ref<any>({})
  264. const customerTemplateRefKey = ref(1)
  265. const taskModalForm = ref({})
  266. const taskLoading = ref<saveLoadingType>('1')
  267. const batchTableData = ref<any>([])
  268. const customerTableRef = ref<InstanceType<typeof ElTable>>()
  269. const transferPersonnel = ref('')
  270. // 定义方法
  271. function sortChange(data: any) {
  272. customerCriteriaForm.pageIndex = 1
  273. switch (data.order) {
  274. case 'ascending':
  275. customerCriteriaForm.isDesc = 1
  276. break
  277. case 'descending':
  278. customerCriteriaForm.isDesc = 0
  279. break
  280. default:
  281. customerCriteriaForm.isDesc = ''
  282. }
  283. getCustomerTable()
  284. }
  285. async function importBusiness(param: UploadRequestOptions) {
  286. allLoading.importLoading = true
  287. const formData = new FormData();
  288. formData.append('multipartFile', param.file)
  289. const res = await uploadFile(URL_IMPORTEXELS, formData).finally(() => {
  290. allLoading.importLoading = false
  291. })
  292. if (res.code == 'ok') {
  293. globalPopup?.showSuccess('导入成功' || '')
  294. getCustomerTable()
  295. return
  296. }
  297. globalPopup?.showError(res.msg || '')
  298. }
  299. function exportCustomerTableList() {
  300. allLoading.exoprtLoading = true
  301. let valueForm = getFromValue(customerCriteriaForm)
  302. post(URL_EXPORTEXELS, { ...valueForm }).then((res) => {
  303. downloadFile(res.data, allText.exportText)
  304. }).finally(() => {
  305. allLoading.exoprtLoading = false
  306. })
  307. }
  308. function transferBusiness() {
  309. const ids = batchTableData.value.map((item: any) => item.id).join(',')
  310. allLoading.transferLoading = true
  311. post(URL_CLAIM, { ids, inchargerId: transferPersonnel.value }).then(() => {
  312. transferPersonnel.value = ''
  313. globalPopup?.showSuccess('转移成功')
  314. closeVisible('batchTransferVisible')
  315. getCustomerTable()
  316. }).finally(() => {
  317. allLoading.transferLoading = false
  318. })
  319. }
  320. function batchDeteleItem() {
  321. const value = batchTableData.value.map((item: any) => item.id).join(',')
  322. const label = batchTableData.value.map((item: any) => item.customName).join(',')
  323. customerDeteleItem(value, label, true)
  324. }
  325. function customerDeteleItem(value: string | number, label: string, batch: boolean = false) {
  326. confirmAction(`确定${batch ? '批量' : ''}删除【${label}】客户吗?`).then(() => {
  327. post(URL_DETELER, { ids: value }).then(res => {
  328. if (res.code != 'ok') {
  329. globalPopup?.showError(res.msg)
  330. return
  331. }
  332. globalPopup?.showSuccess('删除成功')
  333. changeBatch(false)
  334. getCustomerTable()
  335. }).catch((err) => {
  336. globalPopup?.showError(err.msg)
  337. })
  338. })
  339. }
  340. function submitForm(submitData: any, isClose: boolean) {
  341. taskLoading.value = '2'
  342. createTask(submitData, isClose).then((res) => {
  343. const { saveLoading, isClose } = res
  344. taskLoading.value = saveLoading
  345. allVisible.taskModalVisible = isClose
  346. globalPopup?.showSuccess('新增成功')
  347. }).catch((err) => {
  348. const { saveLoading, isClose, message } = err
  349. taskLoading.value = saveLoading
  350. allVisible.taskModalVisible = isClose
  351. globalPopup?.showError(message)
  352. })
  353. }
  354. function newTask(item: any) {
  355. const { id } = item
  356. taskModalForm.value = { ...createTaskFromType(0), customId: id, }
  357. showVisible('taskModalVisible')
  358. }
  359. function editCustomerSave(flag: boolean) {
  360. customerTemplateRef.value?.getData().then((res: any) => {
  361. allLoading.editCustomerSaveLoading = true
  362. let formVal = {
  363. ...customerTemplateValue.value,
  364. ...res
  365. }
  366. delete formVal.createTime
  367. post(URL_EDITSAVE, { ...formVal }).then((_res) => {
  368. allVisible.editCustomerVisible = flag
  369. globalPopup?.showSuccess('保存成功')
  370. if (flag) {
  371. customerTemplateRef.value?.reset()
  372. }
  373. getCustomerTable()
  374. }).finally(() => {
  375. allLoading.editCustomerSaveLoading = false
  376. })
  377. }).catch((_err: any) => {
  378. console.log(_err)
  379. globalPopup?.showError('请填写完整')
  380. })
  381. }
  382. function editCustomer(row: any) { // row 有数据代表编辑
  383. if (row) {
  384. const { id, companyPhone, customName, inchargerId, createTime, customSourceId, customerIndustryId, customerLevelId, email, telPhone, customDesc, address, contactsName } = row
  385. const formVal = {
  386. id, customName, inchargerId, customerIndustryId, customerLevelId, email, customSourceId,
  387. createTime: formatDate(new Date(createTime)),
  388. telPhone, companyPhone,
  389. address,
  390. customDesc,
  391. contactsName
  392. }
  393. allLoading.customerTemplateRefLoading = true
  394. setTimeout(() => {
  395. customerTemplateRefKey.value++
  396. allLoading.customerTemplateRefLoading = false
  397. }, 1000);
  398. customerTemplateValue.value = formVal
  399. allText.editCustomerText = '编辑客户'
  400. } else { // 没有数据代表新建
  401. setTimeout(() => {
  402. console.log(customerTemplateRef.value)
  403. customerTemplateValue.value = {}
  404. customerTemplateRefKey.value++
  405. }, 200)
  406. allText.editCustomerText = '新增客户'
  407. }
  408. showVisible('editCustomerVisible')
  409. }
  410. function changeBatch(flag: boolean = true) {
  411. if (flag) {
  412. batchTableData.value = customerTableRef.value && customerTableRef.value.getSelectionRows()
  413. } else {
  414. batchTableData.value = []
  415. customerTableRef.value && customerTableRef.value.clearSelection()
  416. }
  417. }
  418. function toCustomerTableDetail(_row: any) {
  419. router.push({ path: `${MOD}/detail`, query: { id: _row.id } })
  420. }
  421. function searchTable() {
  422. getCustomerTable()
  423. }
  424. function resetTable() {
  425. let newResetForm = resetFromValue(customerCriteriaForm, { startTime: getFirstDayOfMonth(new Date()), endTime: formatDate(new Date()), pageIndex: 1, pageFrom: 10 })
  426. Object.assign(customerCriteriaForm, newResetForm)
  427. getCustomerTable()
  428. }
  429. function getCustomerTable() {
  430. let valueForm = getFromValue(customerCriteriaForm)
  431. allLoading.customerTableLading = true
  432. post(URL_TABLELIST, { ...valueForm }).then((res) => {
  433. const { data, total } = res.data
  434. customerTable.value = (data || []).map((item: any) => {
  435. return {
  436. ...item,
  437. newCreateTime: formatDate(new Date(item.createTime)),
  438. }
  439. })
  440. customerTotalTable.value = total
  441. }).finally(() => {
  442. allLoading.customerTableLading = false
  443. })
  444. }
  445. async function getSystemField() {
  446. const systemField = getAllListByCode(['线索来源', '客户行业', '客户级别'])
  447. for (let i in systemField) {
  448. const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  449. for (let key of Object.keys(fixedData)) {
  450. if (systemField[i] == key) {
  451. Object.assign(fixedData, { [key]: data })
  452. }
  453. }
  454. }
  455. const { data } = await post(GETPERSONNEL, {})
  456. fixedData.Personnel = data.map((item: any) => {
  457. const { id, name, phone, jobNumber } = item
  458. return {
  459. id, name, phone, jobNumber
  460. }
  461. })
  462. const res = await get(URL_TEMPLALE)
  463. customerTemplate.value = JSON.parse(res.data[0].config)
  464. }
  465. function showVisible(type: keyof typeof allVisible) {
  466. allVisible[type] = true
  467. }
  468. function closeVisible(type: keyof typeof allVisible) {
  469. allVisible[type] = false
  470. }
  471. function handleSizeChange(val: number) {
  472. customerCriteriaForm.pageIndex = 1
  473. customerCriteriaForm.pageFrom = val
  474. getCustomerTable()
  475. }
  476. function handleCurrentChange(val: number) {
  477. customerCriteriaForm.pageIndex = val
  478. getCustomerTable()
  479. }
  480. onMounted(() => {
  481. getSystemField()
  482. getCustomerTable()
  483. })
  484. </script>
  485. <style lang="scss" scoped></style>