123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- <template>
- <div class="h-full flex">
- <div class="p-5 w-80 pr-0">
- <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col">
- <div class="flex-1 p-3 overflow-y-auto">
- <el-form :model="customerCriteriaForm" label-width="70px" style="max-width: 600px">
- <el-form-item label="客户名称">
- <el-input v-model="customerCriteriaForm.customName" clearable placeholder="请输入"></el-input>
- </el-form-item>
- <el-form-item label="客户来源">
- <el-select v-model="customerCriteriaForm.customSourceId" placeholder="请选择" clearable>
- <el-option v-for="item in fixedData.CustomSources" :key="item.id" :label="item.name" :value="item.id" />
- </el-select>
- </el-form-item>
- <el-form-item label="公司号码">
- <el-input v-model="customerCriteriaForm.companyPhone" clearable placeholder="请输入"></el-input>
- </el-form-item>
- <el-form-item label="邮箱">
- <el-input v-model="customerCriteriaForm.email" clearable placeholder="请输入"></el-input>
- </el-form-item>
- <el-form-item label="客户行业">
- <el-select v-model="customerCriteriaForm.customerIndustryId" placeholder="请选择" clearable>
- <el-option v-for="item in fixedData.CustomIndustry" :key="item.id" :label="item.name"
- :value="item.id" />
- </el-select>
- </el-form-item>
- <el-form-item label="客户级别">
- <el-select v-model="customerCriteriaForm.customerLevelId" placeholder="请选择" clearable>
- <el-option v-for="item in fixedData.CustomLevel" :key="item.id" :label="item.name" :value="item.id" />
- </el-select>
- </el-form-item>
- <el-form-item label="负责人">
- <!-- <el-select v-model="customerCriteriaForm.inchargerId" placeholder="请选择" clearable>
- <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
- </el-select> -->
- <personnel-search v-model="customerCriteriaForm.inchargerId" :size="''" placeholder="请选择"></personnel-search>
- </el-form-item>
- <el-form-item label="创建时间">
- <el-date-picker v-model="customerCriteriaForm.startTime" type="date" placeholder="请选择" :clearable="false"
- format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
- </el-form-item>
- <el-form-item label="">
- <el-date-picker v-model="customerCriteriaForm.endTime" type="date" placeholder="请选择" :clearable="false"
- format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
- </el-form-item>
- </el-form>
- </div>
- <div class="w-full flex p-3 shadow-[0_-3px_5px_0px_rgba(0,0,0,0.2)]">
- <El-button class="w-full" @click="resetTable()">重置</El-Button>
- <El-button type="primary" class="w-full" @click="searchTable()">搜索</El-Button>
- </div>
- </div>
- </div>
- <div class="flex-1 p-5 overflow-auto">
- <div class="bg-white w-full h-full p-3 shadow-md rounded-md flex flex-col">
- <div class="flex justify-end pb-3">
- <el-button type="primary" v-permission="['customerAdd']" @click="editCustomer(false)">新建客户</el-button>
- <el-button type="primary" @click="showVisible('batchTransferVisible')"
- :disabled="batchTableData.length <= 0">批量转移</el-button>
- <el-button type="primary" v-permission="['customerDelete']" @click="batchDeteleItem()" :disabled="batchTableData.length <= 0">批量删除</el-button>
- <el-button type="primary" v-permission="['customerRecycle']" @click="showVisible('deteleCustomerVisible')">回收站</el-button>
- <el-button type="primary" v-permission="['customerImport']" @click="showVisible('importVisible')">导入</el-button>
- <el-button type="primary" v-permission="['customerExport']" @click="exportCustomerTableList()"
- :loading="allLoading.exoprtLoading">导出</el-button>
- </div>
- <div class="flex-1 w-full overflow-hidden">
- <el-table ref="customerTableRef" :show-overflow-tooltip="tableShowOverflowTooltip" :data="customerTable" border v-loading="allLoading.customerTableLading"
- style="width: 100%;height: 100%;" @selection-change="changeBatch" @sort-change="sortChange">
- <el-table-column type="selection" width="55" />
- <el-table-column prop="customName" label="客户名称" width="180">
- <template #default="scope">
- <!-- <el-button link type="primary" size="large" @click.prevent="toCustomerTableDetail(scope.row)">{{
- scope.row.customName
- }}</el-button> -->
- <div class="table-text-textnowrap" @click.prevent="toCustomerTableDetail(scope.row)">{{ scope.row.customName }}</div>
- </template>
- </el-table-column>
- <el-table-column prop="customSourceValue" label="客户来源" width="180"></el-table-column>
- <el-table-column prop="companyPhone" label="公司电话" width="180"></el-table-column>
- <el-table-column prop="email" label="邮箱" width="200"></el-table-column>
- <el-table-column prop="customerIndustryValue" label="客户行业" width="180"></el-table-column>
- <el-table-column prop="customerLevelValue" label="客户级别" width="180" sortable="custom"></el-table-column>
- <el-table-column prop="inchargerName" label="负责人" width="190">
- <template #default="scope">
- <TextTranslation translationTypes="userName" :translationValue="scope.row.inchargerName" v-if="scope.row.inchargerName"></TextTranslation>
- </template>
- </el-table-column>
- <el-table-column prop="creatorName" label="创建人" width="180">
- <template #default="scope">
- <TextTranslation translationTypes="userName" :translationValue="scope.row.creatorName"></TextTranslation>
- </template>
- </el-table-column>
- <el-table-column prop="newCreateTime" label="创建时间" width="180"></el-table-column>
- <el-table-column label="操作" fixed="right" width="200" v-permission="['customerEdit', 'tasksAdd', 'customerDelete']">
- <template #default="scope">
- <el-button link type="primary" size="large" v-permission="['customerEdit']" @click="editCustomer(scope.row)">编辑</el-button>
- <el-button link type="primary" size="large" v-permission="['tasksAdd']" @click="newTask(scope.row)">新建任务</el-button>
- <el-button link type="danger" size="large" v-permission="['customerDelete']"
- @click="customerDeteleItem(scope.row.id, scope.row.customName)">删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <div class="flex justify-end pt-3">
- <el-pagination layout="total, prev, pager, next, sizes" :total="customerTotalTable"
- :hide-on-single-page="true" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
- </div>
- </div>
- </div>
- <!-- 新建客户 -->
- <el-dialog v-model="allVisible.editCustomerVisible" width="1000" :show-close="false" top="10vh">
- <template #header="{ close, titleId, titleClass }">
- <div class="flex justify-between items-center border-b pb-3 dialog-header">
- <h4 :id="titleId">{{ allText.editCustomerText }}</h4>
- <div>
- <el-button type="primary" :loading="allLoading.editCustomerSaveLoading" v-if="!customerTemplateValue.id"
- @click="editCustomerSave(true)">保存并新建</el-button>
- <el-button type="primary" :loading="allLoading.editCustomerSaveLoading"
- @click="editCustomerSave(false)">保存</el-button>
- <el-button @click="closeVisible('editCustomerVisible')">取消</el-button>
- </div>
- </div>
- </template>
- <div class="h-[60vh] overflow-y-auto scroll-bar pt-3">
- <div class="ml-4 mr-4">
- <GenerateForm ref="customerTemplateRef" :data="customerTemplate" :value="customerTemplateValue"
- :key="customerTemplateRefKey" v-loading="allLoading.customerTemplateRefLoading" />
- </div>
- </div>
- </el-dialog>
- <!-- 批量转移 -->
- <el-dialog v-model="allVisible.batchTransferVisible" width="600" :show-close="false" top="10vh">
- <template #header="{ close, titleId, titleClass }">
- <div class="flex justify-between items-center border-b pb-3 dialog-header">
- <h4 :id="titleId">{{ allText.transferText }}</h4>
- <div>
- <el-button type="primary" v-loading="allLoading.transferLoading" @click="transferBusiness()">转移</el-button>
- <el-button @click="allVisible.batchTransferVisible = false">取消</el-button>
- </div>
- </div>
- </template>
- <div class="scroll-bar m-6">
- <div class="flex mb-4">
- <div class="w-20 flex items-center justify-end pr-4">转移至:</div>
- <!-- <el-select v-model="transferPersonnel" placeholder="请选择" class="flex1">
- <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
- </el-select> -->
- <personnel-search v-model="transferPersonnel" :size="''" placeholder="请选择"></personnel-search>
- </div>
- <div class="pl-3 text-[#e94a4a]">转移后,将看不到此客户</div>
- </div>
- </el-dialog>
- <el-dialog v-model="allVisible.importVisible" width="680" :show-close="false" top="10vh">
- <template #header="{ close, titleId, titleClass }">
- <div class="flex justify-between items-center border-b pb-3 dialog-header">
- <h4 :id="titleId">导入产品</h4>
- <div class="flex">
- <el-upload class="upload-demo mr-3" :limit="1" :show-file-list="false" accept=".xlsx"
- :http-request="importBusiness">
- <el-button type="primary" :loading="allLoading.importLoading">导入</el-button>
- </el-upload>
- <el-button @click="allVisible.importVisible = false">取消</el-button>
- </div>
- </div>
- </template>
- <div class="p-8">
- <div class="ml-4 mr-4">
- <div class="flex items-center">1、点击下载 <el-link type="primary"
- @click="downloadTemplate(IMPORTMOD, allText.importText)">{{ allText.importText }}</el-link></div>
- <div class="mt-4">2、填写excel文件、客户名称必填</div>
- </div>
- </div>
- </el-dialog>
- <!-- 任务 -->
- <TaskModal :visible="allVisible.taskModalVisible" :edit-form="taskModalForm" :save-loading="taskLoading"
- @close="closeVisible('taskModalVisible')" @submit="submitForm" :title="'新建任务'"
- :disabled-list="['taskType', 'customId']" />
- <!-- 回收站 -->
- <DeteleBusiness :visibles="allVisible.deteleCustomerVisible" @closeVisible="closeVisible" />
- </div>
- </template>
- <script lang="ts" setup>
- import { ref, reactive, onMounted, inject } from "vue";
- import { MOD, GETSYSFILED, GETPERSONNEL, URL_TABLELIST, URL_TEMPLALE, URL_EDITSAVE, URL_DETELER, URL_CLAIM, IMPORTMOD, GETALLCLUE, URL_IMPORTEXELS, URL_EXPORTEXELS } from './api.ts'
- import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, getLastDayOfMonth, formatDate, getTemplateKey, createTaskFromType, confirmAction, downloadFile, downloadTemplate } from '@/utils/tools'
- import { post, get, uploadFile } from "@/utils/request";
- import { useRouter, useRoute } from "vue-router";
- import { GenerateForm } from '@zmjs/form-design';
- import { createTask } from "@/components/TaskModal/taskFunction";
- import { ElTable, UploadRequestOptions } from "element-plus";
- import { tableShowOverflowTooltip } from '@/utils/globalVariables'
- import TaskModal from '@/components/TaskModal/index.vue'
- import DeteleBusiness from './component/deteleTables.vue'
- import personnelSearch from '@/components/translationComponent/personnelSearch/personnelSearch.vue';
- // 定义类型
- interface fixedDataInterface {
- id: string | number,
- companyId: string | number,
- code: string,
- name: string,
- seq: string | number,
- }
- interface personnelInterface {
- id: string | number,
- name: string,
- phone: string,
- jobNumber: string
- }
- interface customerCriteriaFormType { // 线索筛选条件类型
- customName: string,
- customSourceId: string | number,
- companyPhone: string,
- email: string,
- customerIndustryId: string | number,
- customerLevelId: string | number,
- inchargerId: string | number,
- isDesc?: string | number,
- startTime: string | number,
- endTime: string | number,
- pageIndex: string | number,
- pageFrom: string | number
- }
- // 定义变量
- const router = useRouter()
- const globalPopup = inject<GlobalPopup>('globalPopup')
- const customerCriteriaForm = reactive<customerCriteriaFormType>({ // 筛选条件form
- customName: '',
- customSourceId: '',
- companyPhone: '',
- email: '',
- customerIndustryId: '',
- customerLevelId: '',
- inchargerId: '',
- isDesc: '',
- startTime: getFirstDayOfMonth(new Date()),
- endTime: formatDate(new Date()),
- pageIndex: 1,
- pageFrom: 10
- })
- const customerTable = ref([]) // 线索table数据
- const customerTotalTable = ref(0) // 线索 table 数据总数
- const allLoading = reactive({
- customerTableLading: false,
- editCustomerSaveLoading: false,
- customerTemplateRefLoading: false,
- transferLoading: false,
- exoprtLoading: false,
- importLoading: false
- })
- const allVisible = reactive({
- editCustomerVisible: false,
- taskModalVisible: false,
- deteleCustomerVisible: false,
- batchTransferVisible: false,
- importVisible: false
- })
- const allText = reactive({
- editCustomerText: '新建客户',
- transferText: '批量转移',
- importText: '客户导入模板.xlsx',
- exportText: '客户表导出.xlsx'
- })
- const fixedData = reactive({
- CustomSources: [] as fixedDataInterface[],
- CustomIndustry: [] as fixedDataInterface[],
- CustomLevel: [] as fixedDataInterface[],
- Personnel: [] as personnelInterface[]
- })
- const customerTemplate = ref({
- list: [],
- config: {}
- })
- const customerTemplateRef = ref<typeof GenerateForm>() // 自定义表单dom
- const customerTemplateValue = ref<any>({})
- const customerTemplateRefKey = ref(1)
- const taskModalForm = ref({})
- const taskLoading = ref<saveLoadingType>('1')
- const batchTableData = ref<any>([])
- const customerTableRef = ref<InstanceType<typeof ElTable>>()
- const transferPersonnel = ref('')
- // 定义方法
- function sortChange(data: any) {
- customerCriteriaForm.pageIndex = 1
- switch (data.order) {
- case 'ascending':
- customerCriteriaForm.isDesc = 1
- break
- case 'descending':
- customerCriteriaForm.isDesc = 0
- break
- default:
- customerCriteriaForm.isDesc = ''
- }
- getCustomerTable()
- }
- async function importBusiness(param: UploadRequestOptions) {
- allLoading.importLoading = true
- const formData = new FormData();
- formData.append('multipartFile', param.file)
- const res = await uploadFile(URL_IMPORTEXELS, formData).finally(() => {
- allLoading.importLoading = false
- })
- if (res.code == 'ok') {
- globalPopup?.showSuccess('导入成功')
- getCustomerTable()
- return
- }
- globalPopup?.showError(res.msg || '')
- }
- function exportCustomerTableList() {
- allLoading.exoprtLoading = true
- let valueForm = getFromValue(customerCriteriaForm)
- post(URL_EXPORTEXELS, { ...valueForm }).then((res) => {
- downloadFile(res.data, allText.exportText)
- }).finally(() => {
- allLoading.exoprtLoading = false
- })
- }
- function transferBusiness() {
- const ids = batchTableData.value.map((item: any) => item.id).join(',')
- allLoading.transferLoading = true
- post(URL_CLAIM, { ids, inchargerId: transferPersonnel.value }).then(() => {
- transferPersonnel.value = ''
- globalPopup?.showSuccess('转移成功')
- closeVisible('batchTransferVisible')
- getCustomerTable()
- }).finally(() => {
- allLoading.transferLoading = false
- })
- }
- function batchDeteleItem() {
- const value = batchTableData.value.map((item: any) => item.id).join(',')
- const label = batchTableData.value.map((item: any) => item.customName).join(',')
- customerDeteleItem(value, label, true)
- }
- function customerDeteleItem(value: string | number, label: string, batch: boolean = false) {
- confirmAction(`确定${batch ? '批量' : ''}删除【${label}】客户吗?`).then(() => {
- post(URL_DETELER, { ids: value }).then(res => {
- if (res.code != 'ok') {
- globalPopup?.showError(res.msg)
- return
- }
- globalPopup?.showSuccess('删除成功')
- changeBatch(false)
- getCustomerTable()
- }).catch((err) => {
- globalPopup?.showError(err.msg)
- })
- })
- }
- function submitForm(submitData: any, isClose: boolean) {
- taskLoading.value = '2'
- createTask(submitData, isClose).then((res) => {
- const { saveLoading, isClose } = res
- taskLoading.value = saveLoading
- allVisible.taskModalVisible = isClose
- globalPopup?.showSuccess('新增成功')
- }).catch((err) => {
- const { saveLoading, isClose, message } = err
- taskLoading.value = saveLoading
- allVisible.taskModalVisible = isClose
- globalPopup?.showError(message)
- })
- }
- function newTask(item: any) {
- const { id } = item
- taskModalForm.value = { ...createTaskFromType(0), customId: id, }
- showVisible('taskModalVisible')
- }
- function editCustomerSave(flag: boolean) {
- customerTemplateRef.value?.getData().then((res: any) => {
- allLoading.editCustomerSaveLoading = true
- let formVal = {
- ...customerTemplateValue.value,
- ...res
- }
- delete formVal.createTime
- post(URL_EDITSAVE, { ...formVal }).then((_res) => {
- allVisible.editCustomerVisible = flag
- globalPopup?.showSuccess('保存成功')
- if (flag) {
- customerTemplateRef.value?.reset()
- }
- getCustomerTable()
- }).finally(() => {
- allLoading.editCustomerSaveLoading = false
- })
- }).catch((_err: any) => {
- console.log(_err)
- globalPopup?.showError('请填写完整')
- })
- }
- function editCustomer(row: any) { // row 有数据代表编辑
- if (row) {
- const { id, companyPhone, customName, inchargerId, createTime, customSourceId, customerIndustryId, customerLevelId, email, telPhone, customDesc, address, contactsName } = row
- const formVal = {
- id, customName, inchargerId, customerIndustryId, customerLevelId, email, customSourceId,
- createTime: formatDate(new Date(createTime)),
- telPhone, companyPhone,
- address,
- customDesc,
- contactsName
- }
- allLoading.customerTemplateRefLoading = true
- setTimeout(() => {
- customerTemplateRefKey.value++
- allLoading.customerTemplateRefLoading = false
- }, 1000);
- customerTemplateValue.value = formVal
- allText.editCustomerText = '编辑客户'
- } else { // 没有数据代表新建
- setTimeout(() => {
- console.log(customerTemplateRef.value)
- customerTemplateValue.value = {}
- customerTemplateRefKey.value++
- }, 200)
- allText.editCustomerText = '新增客户'
- }
- showVisible('editCustomerVisible')
- }
- function changeBatch(flag: boolean = true) {
- if (flag) {
- batchTableData.value = customerTableRef.value && customerTableRef.value.getSelectionRows()
- } else {
- batchTableData.value = []
- customerTableRef.value && customerTableRef.value.clearSelection()
- }
- }
- function toCustomerTableDetail(_row: any) {
- router.push({ path: `${MOD}/detail`, query: { id: _row.id } })
- }
- function searchTable() {
- getCustomerTable()
- }
- function resetTable() {
- let newResetForm = resetFromValue(customerCriteriaForm, { startTime: getFirstDayOfMonth(new Date()), endTime: formatDate(new Date()), pageIndex: 1, pageFrom: 10 })
- Object.assign(customerCriteriaForm, newResetForm)
- getCustomerTable()
- }
- function getCustomerTable() {
- let valueForm = getFromValue(customerCriteriaForm)
- allLoading.customerTableLading = true
- post(URL_TABLELIST, { ...valueForm }).then((res) => {
- const { data, total } = res.data
- customerTable.value = (data || []).map((item: any) => {
- return {
- ...item,
- newCreateTime: formatDate(new Date(item.createTime)),
- }
- })
- customerTotalTable.value = total
- }).finally(() => {
- allLoading.customerTableLading = false
- })
- }
- async function getSystemField() {
- const systemField = getAllListByCode(['客户来源', '客户行业', '客户级别'])
- console.log(systemField, '<==== 123')
- for (let i in systemField) {
- const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
- for (let key of Object.keys(fixedData)) {
- if (systemField[i] == key) {
- Object.assign(fixedData, { [key]: data })
- }
- }
- }
- const { data } = await post(GETPERSONNEL, {})
- fixedData.Personnel = data.map((item: any) => {
- const { id, name, phone, jobNumber } = item
- return {
- id, name, phone, jobNumber
- }
- })
- const res = await get(URL_TEMPLALE)
- customerTemplate.value = JSON.parse(res.data[0].config)
- }
- function showVisible(type: keyof typeof allVisible) {
- allVisible[type] = true
- }
- function closeVisible(type: keyof typeof allVisible) {
- allVisible[type] = false
- }
- function handleSizeChange(val: number) {
- customerCriteriaForm.pageIndex = 1
- customerCriteriaForm.pageFrom = val
- getCustomerTable()
- }
- function handleCurrentChange(val: number) {
- customerCriteriaForm.pageIndex = val
- getCustomerTable()
- }
- onMounted(() => {
- getSystemField()
- getCustomerTable()
- })
- </script>
- <style lang="scss" scoped></style>
|