销售后的合并

This commit is contained in:
2026-03-14 13:51:02 +08:00
parent 4546481f48
commit 44e2e40e24
7 changed files with 2348 additions and 0 deletions

View File

@@ -0,0 +1,267 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible" width="600px">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="90px"
v-loading="formLoading"
>
<!-- 客户基本信息 -->
<el-divider content-position="left">客户信息</el-divider>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="客户名称" prop="customerName">
<el-select
v-model="formData.customerName"
placeholder="请选择客户"
clearable
filterable
@change="handleCustomerChange"
>
<el-option
v-for="customer in customerList"
:key="customer.id"
:label="customer.name"
:value="customer.name"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="联系方式" prop="contactInfo">
<el-input v-model="formData.contactInfo" placeholder="请输入联系方式" clearable />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="客户类型" prop="customerType">
<el-select v-model="formData.customerType" placeholder="请选择客户类型" clearable>
<el-option
v-for="item in customerTypeOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="客户用途" prop="customerUsage">
<el-input v-model="formData.customerUsage" placeholder="请输入客户用途" clearable />
</el-form-item>
</el-col>
</el-row>
<!-- 产品信息 -->
<el-divider content-position="left">产品信息</el-divider>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="产品名称" prop="productName">
<el-input v-model="formData.productName" placeholder="请输入产品名称" clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品评价" prop="productEvaluation">
<el-input
v-model="formData.productEvaluation"
placeholder="请输入产品评价"
type="textarea"
:rows="2"
clearable
/>
</el-form-item>
</el-col>
</el-row>
<!-- 服务评价 -->
<el-divider content-position="left">服务评价</el-divider>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="采购意愿" prop="repurchaseIntention">
<el-select v-model="formData.repurchaseIntention" placeholder="请选择采购意愿" clearable>
<el-option
v-for="item in repurchaseOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="服务评分" prop="serviceRating">
<el-rate
v-model="formData.serviceRating"
:max="5"
:allow-half="false"
:show-text="false"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitForm" :loading="formLoading">
确定
</el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { AfterSalesVisitApi, AfterSalesVisit } from '@/api/erp/aftersale/aftersalesvisit'
import { CustomerApi, CustomerVO } from '@/api/erp/sale/customer'
/** 售后回访 表单 */
defineOptions({ name: 'AfterSalesVisitForm' })
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中1修改时的数据加载2提交的按钮禁用
const formType = ref('') // 表单的类型create - 新增update - 修改
const formData = ref({
id: undefined,
customerName: undefined,
contactInfo: undefined,
customerUsage: undefined,
productName: undefined,
productEvaluation: undefined,
customerType: undefined,
repurchaseIntention: undefined,
serviceRating: undefined
})
// 客户类型选项
const customerTypeOptions = [
{ value: 'large_food_factory', label: '大型食品厂' },
{ value: 'small_food_factory', label: '中小型加工厂' },
{ value: 'distributor', label: '经销商' },
{ value: 'catering_chain', label: '餐饮连锁' },
{ value: 'government_unit', label: '机关单位' },
{ value: 'other', label: '其他' }
]
// 重复采购意愿选项
const repurchaseOptions = [
{ value: 'definitely', label: '一定会' },
{ value: 'probably', label: '应该会' },
{ value: 'uncertain', label: '不确定' },
{ value: 'unlikely', label: '可能不会' },
{ value: 'never', label: '肯定不会' }
]
const formRules = reactive({
customerName: [
{ required: true, message: '客户名称不能为空', trigger: 'blur' },
{ min: 2, max: 50, message: '客户名称长度应在2-50字符之间', trigger: 'blur' }
],
contactInfo: [
{ required: true, message: '联系方式不能为空', trigger: 'blur' },
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
],
productName: [
{ required: true, message: '产品名称不能为空', trigger: 'blur' },
{ min: 1, max: 100, message: '产品名称长度应在1-100字符之间', trigger: 'blur' }
],
customerType: [{ required: true, message: '请选择客户类型', trigger: 'change' }],
repurchaseIntention: [{ required: true, message: '请选择采购意愿', trigger: 'change' }],
serviceRating: [
{ required: true, message: '请给出服务评分', trigger: 'change' },
{ type: 'number', min: 0, max: 5, message: '评分应在0-5之间', trigger: 'change' }
]
})
const formRef = ref() // 表单 Ref
const customerList = ref<CustomerVO[]>([]) // 客户列表
/** 加载客户列表 */
const loadCustomerList = async () => {
try {
const data = await CustomerApi.getCustomerSimpleList()
customerList.value = data
} catch (error) {
console.error('加载客户列表失败:', error)
}
}
/** 处理客户选择 */
const handleCustomerChange = (customerName: string) => {
if (!customerName) {
formData.value.contactInfo = ''
return
}
const selectedCustomer = customerList.value.find(customer => customer.name === customerName)
if (selectedCustomer) {
// 自动填充联系方式,优先使用手机号,其次电话
formData.value.contactInfo = selectedCustomer.mobile || selectedCustomer.telephone || ''
}
}
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
// 修改时,设置数据
if (id) {
formLoading.value = true
try {
formData.value = await AfterSalesVisitApi.getAfterSalesVisit(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
const submitForm = async () => {
// 校验表单
await formRef.value.validate()
// 提交请求
formLoading.value = true
try {
const data = formData.value as unknown as AfterSalesVisit
if (formType.value === 'create') {
await AfterSalesVisitApi.createAfterSalesVisit(data)
message.success(t('common.createSuccess'))
} else {
await AfterSalesVisitApi.updateAfterSalesVisit(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
// 发送操作成功的事件
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
customerName: undefined,
contactInfo: undefined,
customerUsage: undefined,
productName: undefined,
productEvaluation: undefined,
customerType: undefined,
repurchaseIntention: undefined,
serviceRating: undefined
}
formRef.value?.resetFields()
}
/** 初始化 */
onMounted(() => {
loadCustomerList()
})
</script>

View File

@@ -0,0 +1,306 @@
<template>
<!-- 统计卡片 -->
<ContentWrap>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-4">
<SummaryCard title="总回访数" :value="total" icon="ep:user" icon-color="text-blue-600" icon-bg-color="bg-blue-100" />
<SummaryCard title="平均评分" :value="avgRating" :decimals="1" icon="ep:star" icon-color="text-yellow-600"
icon-bg-color="bg-yellow-100" />
<SummaryCard title="今日新增" :value="todayCount" icon="ep:calendar" icon-color="text-green-600"
icon-bg-color="bg-green-100" />
<SummaryCard title="五星评分" :value="fiveStarCount" icon="ep:star" icon-color="text-yellow-600"
icon-bg-color="bg-yellow-100" />
</div>
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="80px">
<el-form-item label="客户名称" prop="customerName">
<el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable @keyup.enter="handleQuery"
class="!w-200px" />
</el-form-item>
<el-form-item label="联系方式" prop="contactInfo">
<el-input v-model="queryParams.contactInfo" placeholder="请输入联系方式" clearable @keyup.enter="handleQuery"
class="!w-200px" />
</el-form-item>
<el-form-item label="产品名称" prop="productName">
<el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter="handleQuery"
class="!w-200px" />
</el-form-item>
<el-form-item label="客户类型" prop="customerType">
<el-select v-model="queryParams.customerType" placeholder="请选择客户类型" clearable class="!w-200px">
<el-option v-for="item in customerTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="采购意愿" prop="repurchaseIntention">
<el-select v-model="queryParams.repurchaseIntention" placeholder="请选择采购意愿" clearable class="!w-200px">
<el-option v-for="item in repurchaseOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
<el-date-picker v-model="queryParams.createTime" value-format="YYYY-MM-DD HH:mm:ss" type="daterange"
start-placeholder="开始日期" end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" class="!w-220px" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleQuery">
<Icon icon="ep:search" class="mr-5px" /> 搜索
</el-button>
<el-button @click="resetQuery">
<Icon icon="ep:refresh" class="mr-5px" /> 重置
</el-button>
</el-form-item>
</el-form>
<!-- 操作按钮 -->
<div class="flex flex-wrap gap-2 mb-4">
<el-button type="primary" plain @click="openForm('create')" v-hasPermi="['erp:after-sales-visit:create']">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button type="success" plain @click="handleExport" :loading="exportLoading"
v-hasPermi="['erp:after-sales-visit:export']">
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
<el-button type="danger" plain :disabled="isEmpty(checkedIds)" @click="handleDeleteBatch"
v-hasPermi="['erp:after-sales-visit:delete']">
<Icon icon="ep:delete" class="mr-5px" /> 批量删除
</el-button>
</div>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table row-key="id" v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"
@selection-change="handleRowCheckboxChange" class="mb-4">
<el-table-column type="selection" width="50" align="center" />
<el-table-column label="客户名称" min-width="120" prop="customerName" show-overflow-tooltip />
<el-table-column label="联系方式" min-width="120" prop="contactInfo" show-overflow-tooltip />
<el-table-column label="产品名称" min-width="120" prop="productName" show-overflow-tooltip />
<el-table-column label="客户类型" min-width="140" align="center">
<template #default="scope">
<el-tag :type="getCustomerTypeColor(scope.row.customerType)">
{{ getCustomerTypeLabel(scope.row.customerType) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="采购意愿" min-width="100" align="center">
<template #default="scope">
<span :class="getRepurchaseColor(scope.row.repurchaseIntention)">
{{ getRepurchaseLabel(scope.row.repurchaseIntention) }}
</span>
</template>
</el-table-column>
<el-table-column label="服务评分" width="120" align="center">
<template #default="scope">
<el-rate :model-value="scope.row.serviceRating" disabled :max="5" show-score text-color="#ff9900"
score-template="{value}" />
</template>
</el-table-column>
<el-table-column label="创建时间" width="160" align="center" prop="createTime" :formatter="dateFormatter" />
<el-table-column label="操作" width="140" align="center" fixed="right">
<template #default="scope">
<el-button link type="primary" size="small" @click="openForm('update', scope.row.id)"
v-hasPermi="['erp:after-sales-visit:update']">
<Icon icon="ep:edit" class="mr-1" />编辑
</el-button>
<el-button link type="danger" size="small" @click="handleDelete(scope.row.id)"
v-hasPermi="['erp:after-sales-visit:delete']">
<Icon icon="ep:delete" class="mr-1" />删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
@pagination="getList" />
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<AfterSalesVisitForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import { isEmpty } from '@/utils/is'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import SummaryCard from '@/components/SummaryCard/index.vue'
import { AfterSalesVisitApi, AfterSalesVisit } from '@/api/erp/aftersale/aftersalesvisit'
import AfterSalesVisitForm from './AfterSalesVisitForm.vue'
/** 售后回访 列表 */
defineOptions({ name: 'AfterSalesVisit' })
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化
const loading = ref(true) // 列表的加载中
const list = ref<AfterSalesVisit[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const activeNames = ref(['search']) // 折叠面板默认展开
// 客户类型选项
const customerTypeOptions = [
{ value: 'large_food_factory', label: '大型食品厂' },
{ value: 'small_food_factory', label: '中小型加工厂' },
{ value: 'distributor', label: '经销商' },
{ value: 'catering_chain', label: '餐饮连锁' },
{ value: 'government_unit', label: '机关单位' },
{ value: 'other', label: '其他' }
]
// 重复采购意愿选项
const repurchaseOptions = [
{ value: 'definitely', label: '一定会' },
{ value: 'probably', label: '应该会' },
{ value: 'uncertain', label: '不确定' },
{ value: 'unlikely', label: '可能不会' },
{ value: 'never', label: '肯定不会' }
]
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
customerName: undefined,
contactInfo: undefined,
customerUsage: undefined,
productName: undefined,
productEvaluation: undefined,
customerType: undefined,
repurchaseIntention: undefined,
serviceRating: undefined,
createTime: []
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await AfterSalesVisitApi.getAfterSalesVisitPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
// 重置评分查询条件
queryParams.serviceRating = undefined
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
// 删除的二次确认
await message.delConfirm()
// 发起删除
await AfterSalesVisitApi.deleteAfterSalesVisit(id)
message.success(t('common.delSuccess'))
// 刷新列表
await getList()
} catch { }
}
/** 批量删除售后回访 */
const handleDeleteBatch = async () => {
try {
// 删除的二次确认
await message.delConfirm()
await AfterSalesVisitApi.deleteAfterSalesVisitList(checkedIds.value);
message.success(t('common.delSuccess'))
await getList();
} catch { }
}
const checkedIds = ref<number[]>([])
const handleRowCheckboxChange = (records: AfterSalesVisit[]) => {
checkedIds.value = records.map((item) => item.id);
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
// 导出的二次确认
await message.exportConfirm()
// 发起导出
exportLoading.value = true
const data = await AfterSalesVisitApi.exportAfterSalesVisit(queryParams)
download.excel(data, '售后回访.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 统计数据计算 */
const avgRating = computed(() => {
if (list.value.length === 0) return 0
const sum = list.value.reduce((acc, item) => acc + (item.serviceRating || 0), 0)
return sum / list.value.length
})
const todayCount = computed(() => {
const today = new Date().toISOString().split('T')[0]
return list.value.filter(item => {
const createDate = new Date(item.createTime).toISOString().split('T')[0]
return createDate === today
}).length
})
const fiveStarCount = computed(() => {
return list.value.filter(item => (item.serviceRating || 0) === 5).length
})
/** 格式化函数 */
const getCustomerTypeLabel = (value: string) => {
const option = customerTypeOptions.find(item => item.value === value)
return option ? option.label : value
}
const getCustomerTypeColor = (value: string) => {
const colorMap = {
'large_food_factory': 'success',
'small_food_factory': 'info',
'distributor': 'warning',
'catering_chain': 'danger',
'government_unit': 'primary',
'other': ''
}
return colorMap[value as keyof typeof colorMap] || ''
}
const getRepurchaseLabel = (value: string) => {
const option = repurchaseOptions.find(item => item.value === value)
return option ? option.label : value
}
const getRepurchaseColor = (value: string) => {
const colorMap = {
'definitely': 'text-green-600 font-medium',
'probably': 'text-blue-600',
'uncertain': 'text-yellow-600',
'unlikely': 'text-orange-600',
'never': 'text-red-600'
}
return colorMap[value as keyof typeof colorMap] || ''
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>