journalRecord.mock.js 5.92 KB
import { buildJournalDetailJsonContent } from "../views/residentManage/journalRecord/fixtures/journalDetailEcho.sample.js";
import { mapOverviewPageResponse } from "./adapters/journalRecord/mapOverviewRow";
import { mapDetailResponse } from "./adapters/journalRecord/mapDetailResponse";
import { mapMerchantListResponse } from "./adapters/journalRecord/mapMerchantList";
import { mapMerchantStaffListResponse } from "./adapters/journalRecord/mapMerchantStaffList";

const MERCHANT_NAME = "深圳市鹏程汽车有限公司";

const STORE_LIST = [
	{ merchantId: "1001", merchantName: MERCHANT_NAME, sceneType: 1 },
	{ merchantId: "1002", merchantName: "广州天河汽车销售服务有限公司", sceneType: 1 },
	{ merchantId: "1003", merchantName: "东莞南城汽车贸易有限公司", sceneType: 0 },
	{ merchantId: "1004", merchantName: "佛山顺德智行汽车销售有限公司", sceneType: 1 },
	{ merchantId: "1005", merchantName: "惠州惠城汽车服务有限公司", sceneType: 0 },
];

const STAFF_LIST = [
	{ staffUuid: "staff-uuid-001", staffName: "袁春梅" },
	{ staffUuid: "staff-uuid-002", staffName: "韩文" },
	{ staffUuid: "staff-uuid-003", staffName: "刘明杰" },
	{ staffUuid: "staff-uuid-004", staffName: "王芳" },
	{ staffUuid: "staff-uuid-005", staffName: "张伟" },
	{ staffUuid: "staff-uuid-006", staffName: "李娜" },
	{ staffUuid: "staff-uuid-007", staffName: "陈静" },
	{ staffUuid: "staff-uuid-008", staffName: "赵强" },
	{ staffUuid: "staff-uuid-009", staffName: "孙丽" },
	{ staffUuid: "staff-uuid-010", staffName: "周涛" },
];

function delay(result, ms = 300) {
	return new Promise((resolve) => {
		setTimeout(() => resolve(result), ms);
	});
}

function paginate(list, params) {
	const { currentPage = 1, pageSize = 10 } = params;
	const start = (currentPage - 1) * pageSize;
	return {
		list: list.slice(start, start + pageSize),
		total: list.length,
		pageNum: currentPage,
		pageSize,
	};
}

function filterStaffList(list, params) {
	let result = [ ...list ];
	if (params.merchantId) {
		result = result.filter((item) => item.merchantId === params.merchantId);
	}
	if (params.staffName) {
		result = result.filter((item) => item.staffName === params.staffName);
	}
	return result;
}

function buildStaffDailyList(params) {
	return STAFF_LIST.map((item, index) => ({
		id: `staff-daily-${index + 1}`,
		staffUuid: item.staffUuid,
		staffName: item.staffName,
		merchantId: STORE_LIST[index % STORE_LIST.length].merchantId,
		merchantName: STORE_LIST[index % STORE_LIST.length].merchantName,
		sceneType: index % 2 === 0 ? "1" : "0",
		onBreak: index % 3 === 0 ? "调休" : "在岗",
		createdDate: "2026-06-12 14:41:00",
		reportStatus: 0,
		reportDate: params.reportDate,
		templateType: 1,
	}));
}

function buildStoreDailyList(params) {
	return STORE_LIST.map((store, index) => ({
		id: `store-daily-${index + 1}`,
		merchantId: store.merchantId,
		merchantName: store.merchantName,
		sceneType: String(store.sceneType),
		staffCount: 3,
		staffName: index % 3 === 0 ? "" : STAFF_LIST[index % STAFF_LIST.length].staffName,
		createdDate: "2026-06-12 14:41:00",
		reportStatus: index % 3 === 0 ? 0 : 1,
		reportDate: params.reportDate,
		templateType: 2,
	}));
}

function buildNegotiationList(params) {
	return STAFF_LIST.map((item, index) => ({
		id: `negotiation-${index + 1}`,
		staffUuid: item.staffUuid,
		staffName: item.staffName,
		merchantId: STORE_LIST[index % STORE_LIST.length].merchantId,
		merchantName: STORE_LIST[index % STORE_LIST.length].merchantName,
		sceneType: index % 2 === 0 ? "0" : "1",
		onBreak: "在岗",
		createdDate: "2026-06-12 14:41:00",
		reportStatus: 1,
		reportDate: params.reportDate,
		templateType: 3,
	}));
}

function buildDetailMeta(journalType, reportDate) {
	const metaMap = {
		staffDaily: {
			journalType: "staffDaily",
			staffName: "高思琪",
			merchantName: MERCHANT_NAME,
			sceneType: "1",
			templateType: 1,
		},
		storeDaily: {
			journalType: "storeDaily",
			staffName: "",
			merchantName: MERCHANT_NAME,
			sceneType: "1",
			templateType: 2,
		},
		negotiation: {
			journalType: "negotiation",
			staffName: "高思琪",
			merchantName: MERCHANT_NAME,
			sceneType: "0",
			templateType: 3,
		},
	};
	return {
		...(metaMap[journalType] || metaMap.staffDaily),
		reportDate: reportDate || "2026-03-30",
		reportTemplateId: "mock-template-001",
		baseSceneCode: 110201,
		jsonContent: buildJournalDetailJsonContent(),
	};
}

const DETAIL_MAP = {
	"staff-daily-1": buildDetailMeta("staffDaily", "2026-03-30"),
	"store-daily-1": buildDetailMeta("storeDaily", "2026-03-30"),
	"negotiation-1": buildDetailMeta("negotiation", "2026-03-30"),
};

export function mockDailyReportMerchantList(params) {
	return delay(mapMerchantListResponse({ list: STORE_LIST }));
}

export function mockDailyReportMerchantStaffList(params) {
	let list = STAFF_LIST.map((item, index) => ({
		...item,
		merchantId: STORE_LIST[index % STORE_LIST.length].merchantId,
	}));
	if (params.merchantId) {
		list = list.filter((item) => item.merchantId === params.merchantId);
	}
	return delay(mapMerchantStaffListResponse({ list }));
}

export function mockDailyReportOverviewPage(params) {
	const { templateType } = params;
	let list = [];
	if (templateType === 1) {
		list = filterStaffList(buildStaffDailyList(params), params);
	} else if (templateType === 2) {
		list = buildStoreDailyList(params);
		if (params.merchantId) {
			list = list.filter((item) => item.merchantId === params.merchantId);
		}
	} else if (templateType === 3) {
		list = filterStaffList(buildNegotiationList(params), params);
	} else {
		list = filterStaffList(buildStaffDailyList(params), params);
	}
	return delay(mapOverviewPageResponse(paginate(list, params)));
}

export function mockDailyReportDetailSelect(params) {
	const { id, journalType, reportDate } = params;
	let detail = DETAIL_MAP[id];
	if (!detail) {
		detail = {
			id,
			...buildDetailMeta(journalType || "staffDaily", reportDate),
		};
	}
	return delay(mapDetailResponse({ ...detail, id: id || detail.id }, params));
}