feat(shopDealerApply):优化客户跟进记录功能

- 在 shopDealerApply model 中新增 comments 字段用于存储最后跟进内容
- 重构编辑页面的跟进记录展示方式,分为历史记录和新增记录两部分
- 历史记录支持按时间倒序展示并可删除单条记录
- 新增独立的跟进内容输入框和保存按钮,提升用户体验
- 保存新的跟进记录时同步更新主表的 comments 字段
- 调整列表页展示逻辑,在备注列同时显示最后跟进内容和更新时间
- 将列表页的"跟进情况"标题更改为"最后跟进情况"以准确表达含义
- 移除原有的限制最多10条跟进信息的逻辑- 优化代码结构和组件交互逻辑,提高可维护性
This commit is contained in:
2025-10-02 14:15:37 +08:00
parent 645d987f3b
commit 398737d46d
3 changed files with 371 additions and 400 deletions

View File

@@ -34,6 +34,7 @@ export interface ShopDealerApply {
auditTime?: string | number | Date;
// 驳回原因
rejectReason?: string;
comments?: string;
// 商城ID
tenantId?: number;
// 创建时间

View File

@@ -160,108 +160,101 @@
<span style="color: #1890ff; font-weight: 600;">跟进情况</span>
</a-divider>
<!-- 跟进情况列表 -->
<div v-if="form.applyStatus == 10">
<a-row :gutter="16" style="margin-bottom: 16px;">
<a-col :span="24">
<a-button
type="primary"
@click="addFollowUp"
:disabled="followUpList.length >= 10"
size="small"
>
新增
</a-button>
<span style="margin-left: 12px; color: #999; font-size: 12px;">
最多可添加10条跟进信息当前已添加{{ followUpList.length }}
</span>
</a-col>
</a-row>
<!-- 历史跟进记录 -->
<div v-if="form.applyStatus == 10 && historyRecords.length > 0">
<a-divider orientation="left" style="font-size: 14px; color: #666;">
历史跟进记录
</a-divider>
<div v-for="(record, index) in historyRecords" :key="record.id" style="margin-bottom: 16px; padding: 12px; background-color: #f5f5f5; border-radius: 4px;">
<div class="flex justify-between" style="font-weight: 500; margin-bottom: 8px;">
<div>跟进 #{{ historyRecords.length - index }} <span class="text-gray-400 px-4">{{ record.createTime }}</span></div>
<a-tag color="#f50" class="cursor-pointer" @click="remove(record)">删除</a-tag>
</div>
<div style="white-space: pre-wrap;">
{{ record.content }}
</div>
</div>
</div>
<div v-for="(item, index) in followUpList" :key="index"
style="margin-bottom: 16px; border: 1px solid #f0f0f0; padding: 12px; border-radius: 4px;">
<a-row :gutter="16">
<a-col :span="20">
<a-form-item
:label="`跟进内容${index + 1}`"
:name="['followUpList', index, 'content']"
>
<div v-if="item.status == 1" v-html="item.content"></div>
<!-- 新增跟进记录 -->
<div v-if="form.applyStatus == 10">
<a-divider orientation="left" style="font-size: 14px; color: #666;">
新增跟进记录
</a-divider>
<a-form-item :wrapper-col="{ span: 24 }">
<div class="flex flex-col gap-2">
<a-textarea
v-else
v-model:value="item.content"
:disabled="!isUpdate"
placeholder="请输入跟进内容"
:rows="2"
v-model:value="newFollowUpContent"
placeholder="请输入本次跟进内容"
:rows="4"
:maxlength="500"
style="width: 80%"
show-count
/>
</a-form-item>
</a-col>
<a-col :span="4" style="text-align: right;">
<div class="btn">
<a-button
type="link"
danger
@click="removeFollowUp(index)"
:disabled="followUpList.length <= 1"
type="primary"
@click="saveFollowUpRecord"
:loading="followUpLoading"
:disabled="!newFollowUpContent.trim()"
>
删除
保存跟进记录
</a-button>
</a-col>
</a-row>
</div>
</div>
</a-form-item>
</div>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import {ref, reactive, watch} from 'vue';
import {Form, message} from 'ant-design-vue';
import dayjs from 'dayjs';
import {assignObject} from 'ele-admin-pro';
import {addShopDealerApply, updateShopDealerApply} from '@/api/shop/shopDealerApply';
import {listShopDealerRecord, addShopDealerRecord} from '@/api/shop/shopDealerRecord';
import {ShopDealerApply} from '@/api/shop/shopDealerApply/model';
import {ShopDealerRecord} from '@/api/shop/shopDealerRecord/model';
import {FormInstance, RuleObject} from 'ant-design-vue/es/form';
import {hasRole} from "@/utils/permission";
import { ref, reactive, watch } from 'vue';
import { Form, message } from 'ant-design-vue';
import dayjs from 'dayjs';
import { assignObject } from 'ele-admin-pro';
import { addShopDealerApply, updateShopDealerApply } from '@/api/shop/shopDealerApply';
import {listShopDealerRecord, addShopDealerRecord, removeShopDealerRecord} from '@/api/shop/shopDealerRecord';
import { ShopDealerApply } from '@/api/shop/shopDealerApply/model';
import { ShopDealerRecord } from '@/api/shop/shopDealerRecord/model';
import { FormInstance, RuleObject } from 'ant-design-vue/es/form';
import { messageLoading } from 'ele-admin-pro';
import {hasRole} from "@/utils/permission";
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
const props = defineProps<{
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: ShopDealerApply | null;
}>();
}>();
const emit = defineEmits<{
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
// 提交状态
const loading = ref(false);
// 跟进记录保存状态
const followUpLoading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
// 跟进情况列表
const followUpList = ref<ShopDealerRecord[]>([
{
content: '',
status: 0,
sortNumber: 0
}
]);
// 历史跟进记录
const historyRecords = ref<ShopDealerRecord[]>([]);
// 表单数据
const form = reactive<ShopDealerApply>({
// 新的跟进内容
const newFollowUpContent = ref('');
// 表单数据
const form = reactive<ShopDealerApply>({
applyId: undefined,
userId: undefined,
nickName: undefined,
@@ -279,15 +272,15 @@ const form = reactive<ShopDealerApply>({
tenantId: undefined,
createTime: undefined,
updateTime: undefined
});
});
/* 更新visible */
const updateVisible = (value: boolean) => {
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
};
// 表单验证规则
const rules = reactive({
// 表单验证规则
const rules = reactive({
userId: [
{
required: true,
@@ -355,103 +348,79 @@ const rules = reactive({
trigger: 'change'
} as RuleObject
]
});
/* 添加跟进 */
const addFollowUp = () => {
if (followUpList.value.length >= 10) {
message.warning('最多只能添加10条跟进信息');
return;
}
followUpList.value.push({
content: '',
status: 0,
sortNumber: followUpList.value.length
});
};
/* 删除跟进 */
const removeFollowUp = (index: number) => {
if (followUpList.value.length <= 1) {
message.warning('至少保留一条跟进信息');
return;
}
followUpList.value.splice(index, 1);
};
/* 获取跟进记录 */
const fetchFollowUpRecords = async (dealerId: number) => {
/* 获取历史跟进记录 */
const fetchHistoryRecords = async (dealerId: number) => {
try {
// 先通过list接口获取所有记录然后过滤
const allRecords = await listShopDealerRecord({});
const records = allRecords.filter(record => record.dealerId === dealerId);
if (records && records.length > 0) {
followUpList.value = records.map(record => ({
...record,
status: record.status || 0,
sortNumber: record.sortNumber || 0
}));
} else {
// 如果没有记录,初始化一条空记录
followUpList.value = [
{
content: '',
status: 0,
sortNumber: 0
}
];
// 按创建时间倒序排列(最新的在前面)
historyRecords.value = records.sort((a, b) => {
if (a.createTime && b.createTime) {
return new Date(b.createTime).getTime() - new Date(a.createTime).getTime();
}
return 0;
});
} catch (error) {
console.error('获取跟进记录失败:', error);
message.error('获取跟进记录失败');
// 初始化一条空记录
followUpList.value = [
{
content: '',
status: 0,
sortNumber: 0
console.error('获取历史跟进记录失败:', error);
message.error('获取历史跟进记录失败');
historyRecords.value = [];
}
];
}
};
/* 保存跟进记录 */
const saveFollowUpRecords = async (dealerId: number) => {
try {
// 保存每条跟进记录
for (const record of followUpList.value) {
const recordData: any = {
...record,
dealerId: dealerId,
userId: form.userId,
status: 1
};
// 如果有ID则更新否则新增
if (record.id) {
// 更新逻辑如果API支持
await addShopDealerRecord(recordData);
} else {
// 新增逻辑
await addShopDealerRecord(recordData);
}
/* 保存新的跟进记录 */
const saveFollowUpRecord = async () => {
// 检查是否有客户ID
if (!form.applyId) {
message.warning('请先保存客户信息');
return;
}
// message.success('跟进记录保存成功');
// 检查是否有跟进内容
if (!newFollowUpContent.value.trim()) {
message.warning('请输入跟进内容');
return;
}
try {
followUpLoading.value = true;
const recordData: any = {
content: newFollowUpContent.value.trim(),
dealerId: form.applyId,
userId: form.userId,
status: 1, // 默认设置为已完成
sortNumber: 0
};
// 新增逻辑
await addShopDealerRecord(recordData);
message.success('跟进记录保存成功');
// 保存最后跟进内容到主表
await updateShopDealerApply({
...form,
comments: newFollowUpContent.value.trim()
})
// 清空输入框
newFollowUpContent.value = '';
// 重新加载历史记录
await fetchHistoryRecords(form.applyId);
} catch (error) {
console.error('保存跟进记录失败:', error);
message.error('保存跟进记录失败');
throw error;
} finally {
followUpLoading.value = false;
}
};
};
const {resetFields} = useForm(form, rules);
const { resetFields } = useForm(form, rules);
/* 处理审核状态变化 */
const handleStatusChange = (value: number) => {
/* 处理审核状态变化 */
const handleStatusChange = (value: number) => {
// 当状态改为审核通过或驳回时,自动设置审核时间为当前时间
if ((value === 20 || value === 30) && !form.auditTime) {
form.auditTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
@@ -461,10 +430,28 @@ const handleStatusChange = (value: number) => {
form.auditTime = undefined;
form.rejectReason = '';
}
};
};
/* 保存编辑 */
const save = () => {
/* 删除单个 */
const remove = (row: ShopDealerRecord) => {
const hide = messageLoading('请求中..', 0);
removeShopDealerRecord(row.id)
.then((msg) => {
hide();
message.success(msg);
// 重新加载历史记录
if(props.data?.applyId){
fetchHistoryRecords(props.data?.applyId);
}
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
@@ -482,16 +469,6 @@ const save = () => {
validateFields.push('auditTime');
}
// 如果是跟进中状态,需要验证跟进内容
if (form.applyStatus === 10) {
// 构造跟进内容的验证字段
const followUpFields: string[] = [];
followUpList.value.forEach((_, index) => {
followUpFields.push(`followUpList.${index}.content`);
});
validateFields.push(...followUpFields);
}
formRef.value
.validate(validateFields)
.then(async () => {
@@ -532,11 +509,6 @@ const save = () => {
const msg = await saveOrUpdate(formData);
message.success(msg);
// 如果是跟进中状态,保存跟进记录
if (formData.applyStatus === 10 && formData.applyId) {
await saveFollowUpRecords(formData.applyId);
}
updateVisible(false);
emit('done');
} catch (e: any) {
@@ -548,9 +520,9 @@ const save = () => {
.catch(() => {
loading.value = false;
});
};
};
watch(
watch(
() => props.visible,
async (visible) => {
if (visible) {
@@ -558,9 +530,9 @@ watch(
assignObject(form, props.data);
isUpdate.value = true;
// 如果是修改且状态为跟进中,获取跟进记录
// 如果是修改且状态为跟进中,获取历史跟进记录
if (props.data.applyId && props.data.applyStatus === 10) {
await fetchFollowUpRecords(props.data.applyId);
await fetchHistoryRecords(props.data.applyId);
}
} else {
// 重置为默认值
@@ -581,21 +553,16 @@ watch(
});
isUpdate.value = false;
// 重置跟进列表
followUpList.value = [
{
content: '',
status: 0,
sortNumber: 0
}
];
// 重置历史记录和新内容
historyRecords.value = [];
newFollowUpContent.value = '';
}
} else {
resetFields();
}
},
{immediate: true}
);
{ immediate: true }
);
</script>
<style lang="less" scoped>

View File

@@ -37,7 +37,10 @@
<div class="text-gray-600">{{ record.nickName }}</div>
<div class="text-gray-400">{{ record.phone }}</div>
<div class="text-gray-400">{{ record.rate }}</div>
</template>
<template v-if="column.key === 'comments'">
<div class="text-gray-400">{{ record.comments }}</div>
<div class="text-gray-400" v-if="record.comments">{{ record.updateTime }}</div>
</template>
<template v-if="column.key === 'createTime'">
<div class="flex flex-col">
@@ -159,7 +162,7 @@ const columns = ref<ColumnItem[]>([
key: 'customer'
},
{
title: '跟进情况',
title: '最后跟进情况',
dataIndex: 'comments',
key: 'comments',
align: 'left'