index.vue 19 KB

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