dashboardConfig.js 4.38 KB
/**
 * 首页看板 / 表格静态配置(自 index_mixins 抽离)
 */

export const STATIC_DATA_LIST = [
	{ label: '今日营业额', valueObj: 'merchantTodayTotal', tipsLabel: '今日成交量' },
	{ label: '本月营业额', valueObj: 'merchantMonthTotal', tipsLabel: '本月成交量' },
	{ label: '累计营业额', valueObj: 'merchantTotal', tipsLabel: '累计成交量' }
]

export const TOTAL_TABLE_SUM = [
	{ name: 'filmTimesTotalSum' },
	{ name: 'usedTotalSum' },
	{ name: 'experienceTotalSum' },
	{ name: 'upgradeTotalSum' },
	{ name: 'orderMoneyTotalSum' },
	{ name: 'customerUnitMoneySum' },
	{ name: 'upgradeRateSum' }
]

export const TABLE_OBJ = [
	{ name: '贴膜', unit: '/台', key: 'filmTimes', width: 'var(--fontSize110)' },
	{ name: '核销', unit: '/张', key: 'usedTotal', width: 'var(--fontSize110)' },
	{ name: '体验', unit: '/位', key: 'experienceTotal', width: 'var(--fontSize110)' },
	{ name: '转化', unit: '/单', key: 'upgradeTotal', width: 'var(--fontSize110)' },
	{ name: '营业额', unit: '', key: 'orderMoneyTotal', sort: false, width: 'var(--fontSize110)' },
	{ name: '客单价', unit: '', key: 'customerUnitMoney', width: 'var(--fontSize110)' },
	{ name: '转化率', unit: '', key: 'upgradeRate', width: 'var(--fontSize110)' }
]

export const ORDER_BY_TYPE_ENUM = {
	true: [1, 3, 13, 5, 7, 9, 11],
	false: [2, 4, 14, 6, 8, 10, 12]
}

export const WIDE_SUM_COLUMNS = ['orderMoneyTotalSum', 'customerUnitMoneySum']

export const CHANGE_BTN_DATA = [
	{ label: '本日', valueObj: 'staffTodayTotal', valueFn: 'merchantTodayTotal' },
	{ label: '本月', valueObj: 'staffMonthTotal', valueFn: 'merchantMonthTotal' },
	{ label: '累计', valueObj: 'staffTotal', valueFn: 'merchantTotal' }
]

export const DEFAULT_TOTAL_LIST = [
	{
		name: '已预约',
		itemName: 'totalInvited',
		index: 2,
		url: 'pages.tabDateIndex',
		icon: 'icon_14',
		activeIndex: 1,
		waitname: '待预约客户',
		waititemName: 'totalWaitToInvited',
		waiturl: 'pages.tabDateIndex',
		activeWIndex: 2
	},
	{
		name: '转化订单',
		itemName: 'totalUpgrade',
		index: 4,
		url: 'pages.index',
		icon: 'icon_17',
		activeIndex: 2
	},
	{
		name: '战败订单',
		itemName: 'totalNotUpgrade',
		index: 5,
		url: 'pages.index',
		icon: 'icon_16',
		activeIndex: 3
	},
	{
		name: '客单价',
		itemName: 'customerUnitPrice',
		unit: '¥',
		icon: 'icon_7',
		index: 6,
		url: 'tabOperating.index'
	}
]

export const TECHNICIAN_TOTAL_LIST = [
	{
		name: '窗膜(本月/累计)',
		itemName: 'currentMonthSunroofCount',
		waititemName: 'totalSunroofCount'
	},
	{
		name: '车衣(本月/累计)',
		itemName: 'currentMonthCarSeatCount',
		waititemName: 'totalCarSeatCount'
	},
	{
		name: '精品(本月/累计)',
		itemName: 'currentMonthPremiumCount',
		waititemName: 'totalPremiumCount'
	}
]

export const TABLE_BTN = [
	{ text: '今日', type: 'today', active: true },
	{ text: '本月', type: 'month' },
	{ text: '自定义', type: 'date' }
]

export const LOGIN_ROLE_LABEL = {
	1: '超管',
	2: '商户管理员',
	3: '区域运营',
	4: '驻店负责人',
	5: '广联销售',
	6: '飞行督导',
	7: '技师',
	8: '技师督导'
}

/** 深拷贝看板表格配置(避免运行时 mutate 污染模块常量) */
export function cloneDashboardTableConfig() {
	return {
		staticDataList: STATIC_DATA_LIST.map(x => ({ ...x })),
		totalTableSum: TOTAL_TABLE_SUM.map(x => ({ ...x })),
		tableObj: TABLE_OBJ.map(x => ({ ...x })),
		orderByTypeEnum: { ...ORDER_BY_TYPE_ENUM },
		changeBtnData: CHANGE_BTN_DATA.map(x => ({ ...x })),
		totalList: DEFAULT_TOTAL_LIST.map(x => ({ ...x })),
		technicianTotalList: TECHNICIAN_TOTAL_LIST.map(x => ({ ...x })),
		tableBtn: TABLE_BTN.map(x => ({ ...x })),
		loginRoleLabel: { ...LOGIN_ROLE_LABEL }
	}
}

/**
 * 根据合计列动态计算表格宽度
 */
export function computeTableWidth(totalTableSum = [], tableObj = []) {
	let sumWidth = 0
	totalTableSum.forEach((element, index) => {
		if (WIDE_SUM_COLUMNS.includes(element.name)) {
			const length = element.total?.toString().length || 0
			const labelWidth = length > 5 ? length * 20 : 118
			if (tableObj[index]) tableObj[index].width = labelWidth + 'rpx'
			sumWidth += labelWidth
		}
	})
	return 118 * 5 + 232 + 30 + sumWidth
}

/**
 * 产值完成率(百分比数值)
 */
export function computeRatePercent(outputValue = 0, targetValue = 0, round = (n, d) => n) {
	if (!targetValue) return 0
	const rate = round((outputValue / targetValue) * 100, 2)
	return rate
}