Commit bbedc131 by Lin

refactor(receptionCenter): 清理和优化接待中心组件逻辑

- 移除未使用的客户档案列表相关代码,简化组件结构
- 更新接待记录编辑页面的提交逻辑,确保加载状态正确管理
- 优化客户列表Tab的props定义,增加默认值处理
- 清理冗余的错误处理逻辑,提升代码可读性和维护性
1 parent ad1e649b
......@@ -37,7 +37,6 @@
<view class="reception-list-wrapper" v-if="isPortrait != true || mainTabIndex == 1">
<!-- ✅ 性能优化:始终渲染组件,内部通过 showListSkeleton 控制骨架屏 -->
<ReceptionCustomerListTab
:customer-list="customerList"
:reception-record-list="receptionRecordList"
:show-list-skeleton="showListSkeleton"
:reception-list-loading-more="receptionListLoadingMore"
......@@ -45,7 +44,6 @@
:filter-tab-index="filterTabIndex"
:submitted-result-tab-index="submittedResultTabIndex"
:unsubmitted-pending-tab-index="unsubmittedPendingTabIndex"
@entry-delete="onListCustomerEntryDelete"
@scroll-lower="onListScrollToLower"
@filter-tab-change="onFilterTabChange"
@submitted-result-change="onSubmittedResultChange"
......@@ -66,7 +64,7 @@ import { type ComponentPublicInstance, type Ref, computed, nextTick, onMounted,
// ✅ 从 uview-unix 模块导入 UnTabItem 类型(根据官方文档)
import { type UnTabItem } from "@/uni_modules/uview-unix";
import { get } from "@/utils/common.uts"; // ✅ 导入 get 函数用于安全访问 JSONObject
import { getCustomerFileList, getMerchantPerformance, getList} from "@/api/receiption.uts";
import { getMerchantPerformance, getList} from "@/api/receiption.uts";
import TabBarShell from "@/components/HomeFrame/tabbar/TabBarShell.uvue";
import { updateOrientation, useOrientation, useScreenVars } from "@/services/adapter/hooks/index.uts";
// ✅ 数据库相关导入(用于本地未提交记录)
......@@ -80,7 +78,7 @@ import DashboardSkeleton from "./skeleton/DashboardSkeleton.uvue";
import ListSkeleton from "./skeleton/ListSkeleton.uvue";
import ReceptionCustomerListTab from "./tabs/ReceptionCustomerListTab.uvue";
import ReceptionDashboardTab from "./tabs/ReceptionDashboardTab.uvue";
import { getCurrentMonthRange, getMockPerformanceData, getNum, getStr, getTodayDayRangeStrings, mergeByKey, resolveHasMore } from "./types/reception-center-helpers.uts";
import { getCurrentMonthRange, getMockPerformanceData, getStr } from "./types/reception-center-helpers.uts";
import { type ObjOrNull,toObj } from "@/utils/common.uts";
/** 与 layout-root 同源合并规则:common → 方向 → resolutions(pages/receptionCenter/styles/index.vars.uts) */
......@@ -170,9 +168,6 @@ const dashboardReceptionRecordsAll = ref<UTSJSONObject[]>([]);
/** 业绩看板拉取分页大小(单次请求条数,循环直至 total 拿全) */
const DASHBOARD_RECEPTION_FETCH_PAGE_SIZE = 100;
// 客户档案列表(客户录入 Tab,接口 dj.api.smartcarlife.customervisits.customerInfoPage)
const customerList = ref<UTSJSONObject[]>([]);
// 接待复盘列表(接待复盘 Tab,接口 dj.api.smartcarlife.reception.customer.page)
const receptionRecordList = ref<UTSJSONObject[]>([]);
......@@ -192,12 +187,6 @@ watch(
);
// ⚠️ 临时保留:分页变量(待后续重构移到子组件)
/** 客户档案分页(customerInfoPage) */
const CUSTOMER_FILE_PAGE_SIZE = 10;
const customerFilePageNum = ref(1);
/** 客户录入列表:触底加载更多 */
const customerListLoadingMore = ref(false);
const customerListHasMore = ref(true);
/** 接待复盘分页(reception.customer.page) */
const RECEPTION_PAGE_SIZE = 10;
const receptionPageNum = ref(1);
......@@ -213,7 +202,6 @@ const unsubmittedPendingTabIndex = ref(0);
const submittedResultTabIndex = ref(0);
let getPerformanceDataImpl: () => Promise<void> = async (): Promise<void> => {};
let getCustomerListImpl: (append: boolean) => Promise<void> = async (_append: boolean): Promise<void> => {};
let getReceptionRecordListImpl: (append: boolean) => Promise<void> = async (_append: boolean): Promise<void> => {};
......@@ -298,10 +286,6 @@ function getPerformanceData(): Promise<void> {
return getPerformanceDataImpl();
}
function getCustomerList(append: boolean): Promise<void> {
return getCustomerListImpl(append);
}
function getReceptionRecordList(append: boolean): Promise<void> {
return getReceptionRecordListImpl(append);
}
......@@ -445,62 +429,6 @@ function onUnsubmittedPendingChange(index: number): void {
// channelType == 1 => 问界/鸿蒙
const isHarmonyValue = ref(false);
function onListCustomerEntryDelete(item: UTSJSONObject): void {
const idStr = getStr(item, "id");
const list = customerList.value;
const next: UTSJSONObject[] = [];
let i = 0;
while (i < list.length) {
if (getStr(list[i], "id") != idStr) {
next.push(list[i]);
}
i++;
}
customerList.value = next;
uni.showToast({ title: "已删除", icon: "none" });
}
/**
* 从登录态取门店 merchantId 与场景业务类型(与 FormAdd 一致:sceneType==0 为 1,否则 2)。
* 缺登录或门店号时返回 null,调用方跳过请求。
*/
function getLoginShopMerchantAndSceneBussiness(): null | UTSJSONObject {
// 兼容登录态 userInfo 以 object / JSON string 两种方式存储
const rawUser = storage.parse("userInfo");
const merchantId = rawUser.shopMerchantId;
if (merchantId == null || `${merchantId}` == "") {
return null;
}
const sceneTypeRaw = rawUser.sceneType;
const sceneTypeNum = sceneTypeRaw != null ? (sceneTypeRaw as number) : 1;
const sceneBussiness = sceneTypeNum == 0 ? 1 : 2;
return {
merchantId,
sceneBussiness,
} as UTSJSONObject;
}
/** 当日到店:与 receiption.uts 中 customerInfoPage 示例时间格式一致 */
// 客户档案列表请求参数(预录列表:分页 + 今日到店时传 startTime/endTime)
function getDefaultCustomerFileParams(): null | UTSJSONObject {
const ctx = getLoginShopMerchantAndSceneBussiness();
if (ctx == null) {
return null;
}
const params = {
"pageNum": customerFilePageNum.value,
"pageSize": CUSTOMER_FILE_PAGE_SIZE,
"receptionStatus": 1,
"merchantId": ctx.merchantId,
"bussinessScene": ctx.sceneBussiness as number,
} as UTSJSONObject;
// ✅ 默认添加今日时间范围(子组件内部管理筛选状态)
const range = getTodayDayRangeStrings();
params.startTime = range.startTime;
params.endTime = range.endTime;
return params;
}
// 页面加载/模块切换时请求门店业绩数据
getPerformanceDataImpl = async (): Promise<void> => {
// 兼容登录态 userInfo 以 object / JSON string 两种方式存储
......@@ -591,87 +519,7 @@ async function fetchAllReceptionRecordsForDashboard(): Promise<void> {
}
}
/** ✅ 性能优化:异步分批处理列表数据,避免阻塞主线程 */
function processListDataAsync(listRaw: Array<any>, batchSize: number = 15): Promise<UTSJSONObject[]> {
return new Promise((resolve) => {
const result: UTSJSONObject[] = [];
// ✅ 简化处理:直接转换,避免复杂的异步分批导致崩溃
for (let i = 0; i < listRaw.length; i++) {
result.push(listRaw[i] as UTSJSONObject);
}
resolve(result);
});
}
/** append=false 首屏/筛选重置替换列表;append=true 触底追加下一页(pageNum 先 +1 再请求,失败回退) */
getCustomerListImpl = async (append: boolean): Promise<void> => {
// ✅ 前置检查:加载更多时的边界条件
if (append && (customerListHasMore.value != true || customerListLoadingMore.value == true)) {
return;
}
// ✅ 页码管理:追加时+1,失败时回退
let pageBumped = false;
if (append) {
customerFilePageNum.value++;
pageBumped = true;
} else {
customerListHasMore.value = true;
}
// ✅ 获取请求参数
const fileParams = getDefaultCustomerFileParams();
if (fileParams == null) {
if (pageBumped) customerFilePageNum.value--;
return;
}
// ✅ 统一置位 loading 状态
customerListLoadingMore.value = true;
try {
const res = await getCustomerFileList(fileParams);
const resObj = res as UTSJSONObject;
// ✅ 统一错误处理
if (`${resObj.code}` != "0") {
throw new Error(resObj.message != null && `${resObj.message}` != "" ? `${resObj.message}` : "接待列表加载失败");
}
const bizData = resObj.data as null | UTSJSONObject;
if (bizData == null) {
throw new Error("数据为空");
}
const listRaw = bizData.list;
if (listRaw == null || !Array.isArray(listRaw)) {
throw new Error("列表数据格式错误");
}
// ✅ 性能优化:异步分批处理数据
const arr = await processListDataAsync(listRaw as Array<any>, 15);
// ✅ 更新列表数据
customerList.value = append ? mergeByKey(customerList.value, arr, "id") : arr;
customerListHasMore.value = resolveHasMore(bizData, arr.length, customerList.value.length, CUSTOMER_FILE_PAGE_SIZE);
} catch (error) {
// ✅ 统一错误恢复
if (pageBumped) customerFilePageNum.value--;
if (!append) {
customerList.value = [];
customerListHasMore.value = false;
}
const msg = error instanceof Error ? error.message : "网络异常,请稍后重试";
uni.showToast({ title: msg, icon: "none" });
} finally {
customerListLoadingMore.value = false;
}
};
/** append=false 重置页码后整表替换;append=true 触底下一页合并(与 getCustomerList 一致) */
/** append=false 重置页码后整表替换;append=true 触底下一页合并 */
getReceptionRecordListImpl = async (append: boolean): Promise<void> => {
// ✅ 已提交状态下从 API 获取数据
if (append && (receptionListHasMore.value != true || receptionListLoadingMore.value == true)) {
......@@ -754,7 +602,6 @@ function reloadListsForReceptionCenter(): void {
const showSkeleton = true; // 因为下面一定会调用接口
showListSkeleton.value = true;
void nextTick(() => {
customerFilePageNum.value = 1;
receptionPageNum.value = 1;
void Promise.all([refreshReceptionListForCurrentFilter()]).finally(() => {
finalizeListTabReload(showSkeleton);
......@@ -811,7 +658,6 @@ onMounted(() => {
// 监听自定义事件,刷新列表(含本地未提交库)
uni.$on("refresh-reception-list", () => {
customerFilePageNum.value = 1;
void refreshReceptionListForCurrentFilter();
});
......
......@@ -383,7 +383,6 @@ async function loadFullRecordFromDb(recordId: string, fallbackObj: UTSJSONObject
fullRecordSnapshot.value = cloned
applyInitialRecord(cloned)
} catch (_e) {
uni.showToast({ title: '加载记录失败', icon: 'none' })
setSnapshotFromRecord(fallbackObj)
applyInitialRecord(fallbackObj)
}
......@@ -427,7 +426,7 @@ async function handleSubmit(): Promise<void> {
// return
// }
// submitLoading.value = true
submitLoading.value = true
// try {
const merged = buildMergedSubmitPayload(snap, formData.value)
console.log('merged', merged)
......@@ -436,6 +435,7 @@ async function handleSubmit(): Promise<void> {
uni.$emit('refresh-reception-list')
uni.showToast({ title: '保存成功', icon: 'success' })
uni.navigateBack()
submitLoading.value = false
}
/**
......
......@@ -157,7 +157,7 @@
</template>
<script setup lang="uts">
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted, ref, watch, withDefaults } from 'vue'
import { type UnPickerColumn, type UnPickerColumnItem, type UnPickerConfirmEvent } from '@/types/uview-unix-types.uts'
import ListCustomer from '../lists/ListCustomer.uvue'
import ListReception from '../lists/ListReception.uvue'
......@@ -180,11 +180,11 @@ type ReceptionListSubTabUIItem = {
caption: string
hidden: boolean
}
const props = defineProps<{
const props = withDefaults(defineProps<{
/** 横屏分栏时为 true:子 Tab + 筛选区不参与纵向滚动,固定在列表区域顶部 */
stickyHeader?: boolean
/** ✅ 核心数据:客户列表 */
customerList: UTSJSONObject[]
/** 客户预录/档案列表(父页暂无接口数据时可不传,默认空数组) */
customerList?: UTSJSONObject[]
/** ✅ 核心数据:接待记录列表 */
receptionRecordList: UTSJSONObject[]
/** ✅ 强制显示列表骨架屏(用于横竖屏切换、Tab 切换等场景) */
......@@ -199,7 +199,9 @@ const props = defineProps<{
submittedResultTabIndex?: number
/** ✅ 未提交子 Tab 索引(0=待上传,1=待提交) */
unsubmittedPendingTabIndex?: number
}>()
}>(), {
customerList: (): UTSJSONObject[] => [],
})
const emit = defineEmits<{
/** ✅ 核心事件:触底加载更多 */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!