stationStaffPerformance.js 3.88 KB
import { schemaList, schemaCommonBrandList } from "./stationStaffPerformance.data.js";
import { brandTypeList } from "~/packageIndex/constant/performance.js";
import { getSupervisorStaffApi, getSupervisorStoreByMerchantApi } from "~/packageIndex/api/performance.js";
const IMG_URL = "https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/";
import dayjs from "dayjs";
Page({
	data: {
		IMG_URL,
		pageTitle: "驻店人员业绩列表",
		merchantName: undefined,
		navBarHeight: 84,
		brandTypeList: [],
		schemaList: [],
		originList: [],
		list: [],
		query: {
			statDimension: "1",
			dateType: 0,
			filterKey: "",
			merchantId: undefined,
		},
	},
	navbarReady(e) {
		this.setData({
			navBarHeight: e.detail.height,
		});
	},

	onRoute(options) {
		wx.$track.setTrackData(0, "data_guard_view_stationed_sales_list", {}, "");

		console.log("options", options);
		if (options.merchantId && options.merchantName) {
			if (options.pageTitle) {
				this.setData({
					pageTitle: options.pageTitle,
				});
			}
			const query = options?.query || {};
			this.setData({
				brandTypeList: [
					{
						key: query.statDimension,
						label: `${query.statDimension === "1" ? "问界鸿蒙" : "通用品牌"}-${options.merchantName}`,
					},
				],
				schemaList: String(query.statDimension) === "1" ? schemaList : schemaCommonBrandList,
				merchantName: options.merchantName,
				query: {
					...this.data.query,
					...query,
					dateType: Number(query.dateType),
					merchantId: options.merchantId,
				},
			});
			return;
		}
		this.setData({
			brandTypeList: wx.$util.deepClone(brandTypeList),
			schemaList: schemaList,

			query: {
				...this.data.query,

				dateType: 0,
				startDate: dayjs().startOf("day").format("YYYY-MM-DD"),
				endDate: dayjs().endOf("day").format("YYYY-MM-DD"),
			},
		});
	},
	// onLoad(options) {
	// 	console.log("options", options);
	// },

	onReady() {},

	onShow() {},

	filterData(list) {
		if (!this.data.query.filterKey.trim()) {
			return list || this.data.originList;
		}
		return (list || this.data.originList).filter((item) => item?.employeeName?.includes(this.data.query.filterKey));
	},
	async getData() {
		wx.$util.showLoading();
		this.setData({
			originList: [],
			list: [],
		});
		try {
			let userInfo = wx.$util.getUserInfo();

			const api = this.data.query.merchantId ? getSupervisorStoreByMerchantApi : getSupervisorStaffApi;

			const { data } = await api({
				supervisorId: userInfo.uuid,
				...this.data.query,
			});

			this.setData({
				originList: data,
				list: this.filterData(data),
			});
		} finally {
			wx.$util.hideLoading();
		}
	},

	async handleBrandTabChange({ detail }) {
		const schemaLists = String(detail.key) === "1" ? schemaList : schemaCommonBrandList;

		this.setData({
			schemaList: schemaLists,
			query: {
				...this.data.query,
				statDimension: detail.key,
			},
		});
		await this.getData();
	},
	async handleSearch({ detail }) {
		console.log("handleSearch");
		this.setData({
			query: {
				...this.data.query,
				startDate: detail.startDay?.replace(/\//g, "-"),
				endDate: detail.endDay?.replace(/\//g, "-"),
				dateType: detail.timeDimension,
			},
		});
		await this.getData();
	},

	handleFilterKeyChange({ detail }) {
		wx.$util.showLoading();
		this.setData({
			query: {
				...this.data.query,
				filterKey: detail,
			},
		});
		this.setData(
			{
				list: this.filterData(),
			},
			function () {
				wx.$util.hideLoading();
			},
		);
	},
	handleTapItem() {},

	handleBack() {
		wx.navigateBack();
	},

	onHide() {},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	async onPullDownRefresh() {
		try {
			await this.getData();
		} finally {
			wx.stopPullDownRefresh();
		}
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {},
});