index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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="filterCriteriaForm" label-width="70px" style="max-width: 600px">
  7. <el-form-item label="线索名称">
  8. <el-input v-model="filterCriteriaForm.clueName" clearable placeholder="请输入"></el-input>
  9. </el-form-item>
  10. <el-form-item label="线索来源">
  11. <el-select v-model="filterCriteriaForm.clueSourceId" placeholder="请选择" clearable filterable>
  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="filterCriteriaForm.phone" clearable placeholder="请输入"></el-input>
  17. </el-form-item>
  18. <el-form-item label="邮箱">
  19. <el-input v-model="filterCriteriaForm.email" clearable placeholder="请输入"></el-input>
  20. </el-form-item>
  21. <el-form-item label="客户行业">
  22. <el-select v-model="filterCriteriaForm.customerIndustryId" placeholder="请选择" filterable clearable>
  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="filterCriteriaForm.customerLevelId" placeholder="请选择" filterable clearable>
  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="filterCriteriaForm.inchargerId" placeholder="请选择" filterable clearable>
  33. <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
  34. </el-select> -->
  35. <personnel-search v-model="filterCriteriaForm.inchargerId" :size="''" placeholder="请选择"></personnel-search>
  36. </el-form-item>
  37. <el-form-item label="创建时间">
  38. <el-date-picker v-model="filterCriteriaForm.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="filterCriteriaForm.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="['threadAdd']" @click="editClue(false)">新建线索</el-button>
  57. <el-button type="primary" :disabled="batchTableData.length <= 0" @click="batchTransfer()">批量转移</el-button>
  58. <el-button type="primary" v-permission="['threadDelete']" :disabled="batchTableData.length <= 0" @click="batchDeletes()">批量删除</el-button>
  59. <el-button type="primary" v-permission="['threadRecycle']" @click="showDeteleClue(true)">回收站</el-button>
  60. <el-button type="primary" v-permission="['threadImport']" @click="dialogVisible.importVisible = true">导入</el-button>
  61. <el-button type="primary" v-permission="['threadExport']" @click="exportTheadTableList()" :loading="allLoading.exoprtLoading">导出</el-button>
  62. </div>
  63. <div class="flex-1 w-full overflow-hidden">
  64. <el-table :show-overflow-tooltip="tableShowOverflowTooltip" ref="clueTableRef" :data="clueTable" border v-loading="allLoading.clueTableLading"
  65. style="width: 100%;height: 100%;" @selection-change="changeBatch" @sort-change="sortChange">
  66. <el-table-column type="selection" width="55" />
  67. <el-table-column prop="clueName" label="线索名称" width="180">
  68. <template #default="scope">
  69. <div class="table-text-textnowrap" @click.prevent="toClueTableDetail(scope.row)">{{ scope.row.clueName }}</div>
  70. </template>
  71. </el-table-column>
  72. <el-table-column prop="clueSourceValue" label="线索来源" width="180"></el-table-column>
  73. <el-table-column prop="phone" label="电话号码" width="180"></el-table-column>
  74. <el-table-column prop="email" label="邮箱" width="180"></el-table-column>
  75. <el-table-column prop="customerIndustryValue" label="客户行业" width="180"></el-table-column>
  76. <el-table-column prop="customerLevelValue" label="客户级别" width="180" sortable="custom"></el-table-column>
  77. <el-table-column prop="inchargerName" label="负责人" width="190">
  78. <template #default="scope">
  79. <TextTranslation translationTypes="userName" :translationValue="scope.row.inchargerName" v-if="scope.row.inchargerName"</TextTranslation>
  80. </template>
  81. </el-table-column>
  82. <el-table-column prop="createName" label="创建人" width="180">
  83. <template #default="scope">
  84. <TextTranslation translationTypes="userName" :translationValue="scope.row.createName"></TextTranslation>
  85. </template>
  86. </el-table-column>
  87. <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
  88. <el-table-column label="操作" fixed="right" width="200" v-permission="['threadEdit', 'tasksAdd', 'threadDelete']">
  89. <template #default="scope">
  90. <el-button link type="primary" size="large" @click="editClue(scope.row)" v-permission="['threadEdit']">编辑</el-button>
  91. <!-- <el-button link type="primary" size="large"
  92. @click="dialogVisible.taskModalVisible = true">新建任务</el-button> -->
  93. <el-button link type="primary" size="large" @click="newTask(scope.row)" v-permission="['tasksAdd']">新建任务</el-button>
  94. <el-button link type="danger" size="large" @click.prevent="deleteRow(scope.row)" v-permission="['threadDelete']">删除</el-button>
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. </div>
  99. <div class="flex justify-end pt-3">
  100. <el-pagination layout="total, prev, pager, next, sizes" :page-size="filterCriteriaForm.pageFrom"
  101. @size-change="handleSizeChange" @current-change="handleCurrentChange" :total="clueTotalTable"
  102. :hide-on-single-page="true" />
  103. </div>
  104. </div>
  105. </div>
  106. <!-- 弹窗 -->
  107. <el-dialog v-model="dialogVisible.editClueDialogVisible" width="1000" :show-close="false" top="10vh">
  108. <template #header="{ close, titleId, titleClass }">
  109. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  110. <h4 :id="titleId">{{ allText.editClueText }}</h4>
  111. <div>
  112. <el-button type="primary" v-if="!editForm.id" :loading="allLoading.clueSaveLoading" @click="saveEditClue(true)">保存并新建</el-button>
  113. <el-button type="primary" :loading="allLoading.clueSaveLoading" @click="saveEditClue(false)">保存</el-button>
  114. <el-button @click="dialogVisible.editClueDialogVisible = false">取消</el-button>
  115. </div>
  116. </div>
  117. </template>
  118. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3" v-loading="allLoading.generateFormLading">
  119. <div class="ml-4 mr-4">
  120. <GenerateForm ref="generateForm" :data="clueTemplate" :value="editForm" :key="generateFormKey" />
  121. </div>
  122. </div>
  123. </el-dialog>
  124. <el-dialog v-model="dialogVisible.clueDialogVisible" width="600" :show-close="false" top="10vh">
  125. <template #header="{ close, titleId, titleClass }">
  126. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  127. <h4 :id="titleId">{{ allText.clueText }}</h4>
  128. <div>
  129. <el-button type="primary" v-loading="allLoading.clueLoading" @click="transferClues()">转移</el-button>
  130. <el-button @click="dialogVisible.clueDialogVisible = false">取消</el-button>
  131. </div>
  132. </div>
  133. </template>
  134. <div class="scroll-bar m-6">
  135. <div class="flex mb-4">
  136. <div class="w-20 flex items-center justify-end pr-4">转移至:</div>
  137. <!-- <el-select v-model="transferForm.transferValue" placeholder="请选择" class="flex1">
  138. <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
  139. </el-select> -->
  140. <personnel-search v-model="transferForm.transferValue" :size="''" placeholder="请选择"></personnel-search>
  141. </div>
  142. <div class="pl-3 text-[#e94a4a]">转移后,将看不到此线索</div>
  143. </div>
  144. </el-dialog>
  145. <DeteleTables :visibles="dialogVisible.deteleClueDialogVisible" @showDeteleClue="showDeteleClue" />
  146. <TaskModal :visible="dialogVisible.taskModalVisible" :edit-form="taskModalForm" :save-loading="taskLoading"
  147. @close="closeTaskModal" @submit="submitForm" :title="'新建任务'" :disabled-list="['taskType', 'clueId']" />
  148. <!-- 导入线索 -->
  149. <el-dialog v-model="dialogVisible.importVisible" width="680" :show-close="false" top="10vh">
  150. <template #header="{ close, titleId, titleClass }">
  151. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  152. <h4 :id="titleId">导入线索</h4>
  153. <div class="flex">
  154. <el-upload class="upload-demo mr-3" :limit="1" :show-file-list="false" accept=".xlsx"
  155. :http-request="importProducts">
  156. <el-button type="primary" :loading="allLoading.importLoading">导入</el-button>
  157. </el-upload>
  158. <el-button @click="dialogVisible.importVisible = false">取消</el-button>
  159. </div>
  160. </div>
  161. </template>
  162. <div class="p-8">
  163. <div class="ml-4 mr-4">
  164. <div class="flex items-center">1、点击下载 <el-link type="primary"
  165. @click="downloadTemplate(IMPORMOD, '线索导入模板.xlsx')">线索导入模板.xlsx</el-link></div>
  166. <div class="mt-4">2、填写excel文件、线索名称、线索来源必填</div>
  167. </div>
  168. </div>
  169. </el-dialog>
  170. </div>
  171. </template>
  172. <script lang="ts" setup>
  173. import { ref, reactive, onMounted, inject } from "vue";
  174. import { GETSYSFILED, MOD, IMPORMOD, GETPERSONNEL, GETTABLE, GETTEMPLATE, GETDETAIL, UNDATECLAIM, UNDATEFORM, DELTEROW, URL_IMPORTTHREAD, URL_EXPOERTHREAD } from './constant'
  175. import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, getLastDayOfMonth, formatDate, createTaskFromType, confirmAction, downloadTemplate, downloadFile } from '@/utils/tools'
  176. import { FormInstance, FormRules, ElMessageBox, ElTable, UploadRequestOptions } from 'element-plus'
  177. import { post, get, uploadFile } from "@/utils/request";
  178. import { useRouter, useRoute } from "vue-router";
  179. import { GenerateForm } from '@zmjs/form-design';
  180. import TaskModal from '@/components/TaskModal/index.vue'
  181. import DeteleTables from "./deteleTables.vue";
  182. import { createTask } from "@/components/TaskModal/taskFunction";
  183. import { tableShowOverflowTooltip } from '@/utils/globalVariables'
  184. import personnelSearch from '@/components/translationComponent/personnelSearch/personnelSearch.vue';
  185. // 定义类型
  186. interface fixedDataInterface {
  187. id: string | number,
  188. companyId: string | number,
  189. code: string,
  190. name: string,
  191. seq: string | number,
  192. }
  193. interface personnelInterface {
  194. id: string | number,
  195. name: string,
  196. phone: string,
  197. jobNumber: string
  198. }
  199. // 定义变量
  200. const route = useRoute()
  201. const router = useRouter()
  202. const globalPopup = inject<GlobalPopup>('globalPopup')
  203. const filterCriteriaForm = reactive<filterCriteriaFormType>({ // 筛选条件form
  204. clueName: '',
  205. clueSourceId: '',
  206. phone: '',
  207. email: '',
  208. customerIndustryId: '',
  209. customerLevelId: '',
  210. inchargerId: '',
  211. startTime: getFirstDayOfMonth(new Date()),
  212. endTime: formatDate(new Date()),
  213. isDesc: '',
  214. pageIndex: 1,
  215. pageFrom: 10
  216. })
  217. const generateFormKey = ref(1)
  218. const taskLoading = ref<saveLoadingType>('1')
  219. const allLoading = reactive({
  220. clueTableLading: false,
  221. generateFormLading: false,
  222. clueLoading: false,
  223. importLoading: false,
  224. exoprtLoading: false,
  225. clueSaveLoading: false
  226. })
  227. const dialogVisible = reactive({
  228. editClueDialogVisible: false,
  229. taskModalVisible: false,
  230. clueDialogVisible: false,
  231. deteleClueDialogVisible: false,
  232. importVisible: false
  233. })
  234. const allText = reactive({
  235. editClueText: '新建线索',
  236. clueText: '转移线索'
  237. })
  238. const fixedData = reactive({
  239. ClueSources: [] as fixedDataInterface[],
  240. CustomIndustry: [] as fixedDataInterface[],
  241. CustomLevel: [] as fixedDataInterface[],
  242. Personnel: [] as personnelInterface[],
  243. })
  244. const clueTable = ref([]) // 线索table数据
  245. const clueTotalTable = ref(0) // 线索 table 数据总数
  246. const clueTableRef = ref<InstanceType<typeof ElTable>>() // 线索table dom
  247. const generateForm: any = ref(null) // 模板
  248. const clueTemplate = ref({
  249. list: [],
  250. config: {}
  251. }) // 线索模板
  252. const editForm = ref<any>({}) // 编辑表单
  253. const taskModalForm = ref({}) // 任务弹窗表单
  254. const batchTableData = ref([])
  255. // 批量变量
  256. const transferForm = reactive({
  257. transferValue: '',
  258. batchTransferIds: '',
  259. })
  260. // 定义方法
  261. function sortChange(data: any) {
  262. filterCriteriaForm.pageIndex = 1
  263. switch (data.order) {
  264. case 'ascending':
  265. filterCriteriaForm.isDesc = 1
  266. break
  267. case 'descending':
  268. filterCriteriaForm.isDesc = 0
  269. break
  270. default:
  271. filterCriteriaForm.isDesc = ''
  272. }
  273. getClueTable()
  274. }
  275. function exportTheadTableList() {
  276. allLoading.exoprtLoading = true
  277. let valueForm = getFromValue(filterCriteriaForm)
  278. post(URL_EXPOERTHREAD, {...valueForm}).then((res) => {
  279. downloadFile(res.data, '线索表表导出.xlsx')
  280. }).finally(() => {
  281. allLoading.exoprtLoading = false
  282. })
  283. }
  284. function newTask(item: any) {
  285. const { id } = item
  286. taskModalForm.value = { ...createTaskFromType(3), clueId: id, }
  287. dialogVisible.taskModalVisible = true
  288. }
  289. function showDeteleClue(flag: boolean) {
  290. dialogVisible.deteleClueDialogVisible = flag
  291. }
  292. function transferClues() {
  293. const { transferValue, batchTransferIds } = transferForm
  294. const ids = batchTransferIds
  295. const inchargerId = transferValue
  296. if (!inchargerId) {
  297. globalPopup?.showWarning('请选择转移的人员')
  298. return
  299. }
  300. post(UNDATECLAIM, { ids, inchargerId }).then((res) => {
  301. if (res.code == 'ok') {
  302. globalPopup?.showSuccess('批量转移成功')
  303. dialogVisible.clueDialogVisible = false
  304. changeBatch(false)
  305. getClueTable()
  306. }
  307. })
  308. }
  309. function searchTable() {
  310. getClueTable()
  311. }
  312. function resetTable() {
  313. let newResetForm = resetFromValue(filterCriteriaForm, { startTime: getFirstDayOfMonth(new Date()), endTime: formatDate(new Date()), pageIndex: 1, pageFrom: 10 })
  314. Object.assign(filterCriteriaForm, newResetForm)
  315. getClueTable()
  316. }
  317. function closeTaskModal() {
  318. dialogVisible.taskModalVisible = false
  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. dialogVisible.taskModalVisible = isClose
  326. globalPopup?.showSuccess('新增成功')
  327. }).catch((err) => {
  328. const { saveLoading, isClose, message } = err
  329. taskLoading.value = saveLoading
  330. dialogVisible.taskModalVisible = isClose
  331. globalPopup?.showError(message)
  332. })
  333. }
  334. function editClue(item: any) {
  335. dialogVisible.editClueDialogVisible = true
  336. allLoading.generateFormLading = true
  337. setTimeout(() => {
  338. generateForm.value && generateForm.value.reset()
  339. generateFormKey.value++
  340. allLoading.generateFormLading = false
  341. }, 1000);
  342. if (!item) {
  343. allText.editClueText = '新建线索'
  344. editForm.value = {}
  345. return
  346. }
  347. editForm.value = JSON.parse(JSON.stringify(item))
  348. allText.editClueText = '编辑线索'
  349. }
  350. async function saveEditClue(flag: boolean) {
  351. const data = await generateForm.value.getData()
  352. let newData = { ...editForm.value, ...data }
  353. delete newData.createTime
  354. allLoading.clueSaveLoading = true
  355. post(UNDATEFORM, { ...newData }).then((res) => {
  356. if (res.code != 'ok') {
  357. globalPopup?.showError(res.msg)
  358. return
  359. }
  360. globalPopup?.showSuccess('保存成功')
  361. if (flag) {
  362. editForm.value = {}
  363. generateForm.value && generateForm.value.reset()
  364. generateFormKey.value++
  365. }
  366. dialogVisible.editClueDialogVisible = flag
  367. getClueTable()
  368. }).catch((_err) => {
  369. console.log(_err)
  370. }).finally(() => {
  371. allLoading.clueSaveLoading = false
  372. })
  373. }
  374. function deleteRow(row: any) {
  375. confirmAction(`确定删除【${row.clueName}】线索吗?`).then(() => {
  376. post(DELTEROW, { ids: row.id }).then(res => {
  377. if (res.code != 'ok') {
  378. globalPopup?.showError(res.msg)
  379. return
  380. }
  381. globalPopup?.showSuccess('删除成功')
  382. getClueTable()
  383. })
  384. })
  385. }
  386. async function importProducts(param: UploadRequestOptions) {
  387. allLoading.importLoading = true
  388. const formData = new FormData();
  389. formData.append('multipartFile', param.file)
  390. const res = await uploadFile(URL_IMPORTTHREAD, formData).finally(() => {
  391. allLoading.importLoading = false
  392. })
  393. allLoading.importLoading = false
  394. if (res.code == 'ok') {
  395. globalPopup?.showSuccess('导入成功' || '')
  396. getClueTable()
  397. return
  398. }
  399. globalPopup?.showError(res.msg || '')
  400. }
  401. function changeBatch(flag: boolean = true) {
  402. if (flag) {
  403. batchTableData.value = clueTableRef.value && clueTableRef.value.getSelectionRows()
  404. } else {
  405. batchTableData.value = []
  406. clueTableRef.value && clueTableRef.value.clearSelection()
  407. }
  408. }
  409. function batchTransfer() {
  410. const data = clueTableRef.value && clueTableRef.value.getSelectionRows()
  411. if (!data.length) {
  412. globalPopup?.showWarning('请选择数据')
  413. return
  414. }
  415. transferForm.batchTransferIds = data.map((item: any) => item.id).join(',')
  416. dialogVisible.clueDialogVisible = true
  417. }
  418. function batchDeletes() {
  419. const data = clueTableRef.value && clueTableRef.value.getSelectionRows()
  420. if (!data.length) {
  421. globalPopup?.showWarning('请选择数据')
  422. return
  423. }
  424. const str = data.map((item: any) => item.clueName).join(',')
  425. const ids = data.map((item: any) => item.id).join(',')
  426. confirmAction(`确定批量删除这些【${str}】线索吗?`, '', 'warning').then(() => {
  427. post(DELTEROW, { ids }).then(res => {
  428. if (res.code != 'ok') {
  429. globalPopup?.showError(res.msg)
  430. return
  431. }
  432. globalPopup?.showSuccess('删除成功')
  433. changeBatch(false)
  434. getClueTable()
  435. })
  436. })
  437. }
  438. function toClueTableDetail(row: any) {
  439. router.push({
  440. path: `${MOD}/detail`,
  441. query: { id: row.id }
  442. })
  443. }
  444. function getClueTable() {
  445. allLoading.clueTableLading = true
  446. let valueForm = getFromValue(filterCriteriaForm)
  447. post(GETTABLE, { ...valueForm }).then((res: any) => {
  448. let { data } = res
  449. for (let i in data.data) {
  450. data.data[i].createTime = formatDate(new Date(data.data[i].createTime))
  451. }
  452. clueTable.value = data.data
  453. clueTotalTable.value = data.total
  454. allLoading.clueTableLading = false
  455. }).catch((_error) => {
  456. allLoading.clueTableLading = false
  457. })
  458. }
  459. function handleSizeChange(val: number) {
  460. filterCriteriaForm.pageIndex = 1
  461. filterCriteriaForm.pageFrom = val
  462. getClueTable()
  463. }
  464. function handleCurrentChange(val: number) {
  465. filterCriteriaForm.pageIndex = val
  466. getClueTable()
  467. }
  468. async function getSystemField() {
  469. const systemField = getAllListByCode(['线索来源', '客户行业', '客户级别'])
  470. for (let i in systemField) {
  471. const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  472. for (let key of Object.keys(fixedData)) {
  473. if (systemField[i] == key) {
  474. Object.assign(fixedData, { [key]: data })
  475. }
  476. }
  477. }
  478. const { data } = await post(GETPERSONNEL, {})
  479. fixedData.Personnel = data.map((item: any) => {
  480. const { id, name, phone, jobNumber } = item
  481. return {
  482. id, name, phone, jobNumber
  483. }
  484. })
  485. const res = await get(GETTEMPLATE)
  486. clueTemplate.value = JSON.parse(res.data[0].config)
  487. }
  488. onMounted(() => {
  489. getSystemField()
  490. getClueTable()
  491. })
  492. </script>
  493. <style lang="scss" scoped></style>