Commit 076453da by Jaxon

Merge branch 'feature/statistics' into 'SAAS+V5.8.2'

feat: 添加入口

See merge request !7
2 parents 09aa0375 fb39dac7
// pages/tab/crew/crew.js // pages/tab/crew/crew.js
import dayjs from 'dayjs' import dayjs from "dayjs";
import api from '~/api/crew/index' import api from "~/api/crew/index";
import indexApi from '~/api/index/index' import indexApi from "~/api/index/index";
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/' const IMG_URL = "https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/";
const sceneMaps = { // 1延保 2轻改 3权益 const sceneMaps = {
// 1延保 2轻改 3权益
1: 1, 1: 1,
2: 3, 2: 3,
3: 2 3: 2,
} };
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
...@@ -17,343 +17,371 @@ Page({ ...@@ -17,343 +17,371 @@ Page({
IMG_URL, IMG_URL,
navBarHeight: 84, navBarHeight: 84,
tabIndex: 0, tabIndex: 0,
tabList: [{ tabList: [
text: '业绩', {
value: 'performance' text: "业绩",
}, { value: "performance",
text: '行为', },
value: 'behavior' {
}, { text: "行为",
text: '培训', value: "behavior",
value: 'training' },
}], {
text: "培训",
value: "training",
},
],
sceneTabIndex: 0, sceneTabIndex: 0,
sceneTabList: [{ sceneTabList: [
text: '全部', {
icon: 'all-icon', text: "全部",
value: '' icon: "all-icon",
}, { value: "",
text: '延保', },
icon: 'yanbao-icon', {
value: '1' text: "延保",
}, { icon: "yanbao-icon",
text: '权益', value: "1",
icon: 'quanyi-icon', },
value: '2' {
}, { text: "权益",
text: '轻改', icon: "quanyi-icon",
icon: 'qinggai-icon', value: "2",
value: '3' },
}], {
staticList: [{ text: "轻改",
label: '驻店人员', icon: "qinggai-icon",
width: '208', value: "3",
key: 'staffCount', },
background: 'linear-gradient(90deg, #42CCCF 0%, #36D9A5 100%)' ],
}, { staticList: [
label: '门店数量', {
width: '192', label: "驻店人员",
key: 'storeCount', width: "208",
background: 'linear-gradient(90deg, #5E69FF 0%, #4079FF 100%)' key: "staffCount",
}, { background: "linear-gradient(90deg, #42CCCF 0%, #36D9A5 100%)",
label: '总产值', },
key: 'totalOutput', {
background: 'linear-gradient(90deg, #3D76FC 0%, #4DA6FF 100%)' label: "门店数量",
}], width: "192",
AIContent: '', key: "storeCount",
background: "linear-gradient(90deg, #5E69FF 0%, #4079FF 100%)",
},
{
label: "总产值",
key: "totalOutput",
background: "linear-gradient(90deg, #3D76FC 0%, #4DA6FF 100%)",
},
],
AIContent: "",
staticData: {}, staticData: {},
employeeList: [], employeeList: [],
mode: 'performance', mode: "performance",
sortField: 1, sortField: 1,
sortOrder: 1 sortOrder: 1,
}, },
onTabItemTap(e) { onTabItemTap(e) {
// 点击埋点 // 点击埋点
wx.$track.setTrackData(0, 'supervisor_crew_page', {}, '') wx.$track.setTrackData(0, "supervisor_crew_page", {}, "");
}, },
navbarReady(e) { navbarReady(e) {
let navBarHeight = e.detail.height let navBarHeight = e.detail.height;
this.setData({ this.setData({
navBarHeight navBarHeight,
}) });
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {},
},
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady() { onReady() {
const query = wx.createSelectorQuery().in(this) const query = wx.createSelectorQuery().in(this);
query.select('.top-box').boundingClientRect() query.select(".top-box").boundingClientRect();
query.exec(res => { query.exec((res) => {
this.setData({topBoxHeight: res[0]?.height}) this.setData({ topBoxHeight: res[0]?.height });
}) });
}, },
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
this.getAIAnalyse() this.getAIAnalyse();
this.getEmployeeRank() this.getEmployeeRank();
if (this.data.tabIndex == 2) { // 请求培训的统计数据 if (this.data.tabIndex == 2) {
this.getTrainingStaticsData() // 请求培训的统计数据
this.getTrainingStaticsData();
} }
}, },
formatThousands (v) { formatThousands(v) {
const s = String(v) const s = String(v);
if (!s) return s if (!s) return s;
const isNeg = s[0] === '-' const isNeg = s[0] === "-";
const raw = isNeg ? s.slice(1) : s const raw = isNeg ? s.slice(1) : s;
const [intPart, decPart] = raw.split('.') const [intPart, decPart] = raw.split(".");
const intFmt = String(intPart || '0').replace(/\B(?=(\d{3})+(?!\d))/g, ',') const intFmt = String(intPart || "0").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
const res = decPart ? `${intFmt}.${decPart}` : intFmt const res = decPart ? `${intFmt}.${decPart}` : intFmt;
return isNeg ? `-${res}` : res return isNeg ? `-${res}` : res;
}, },
// 切换类型 // 切换类型
changeTab(e) { changeTab(e) {
let { target } = e.currentTarget.dataset let { target } = e.currentTarget.dataset;
let { tabList } = this.data let { tabList } = this.data;
let eventCode = ['supervisor_performance_tab', 'supervisor_behavior_tab', 'supervisor_training_tab'] let eventCode = ["supervisor_performance_tab", "supervisor_behavior_tab", "supervisor_training_tab"];
const index = tabList?.findIndex(val => val.value == target.value) const index = tabList?.findIndex((val) => val.value == target.value);
wx.$track.setTrackData(0, eventCode[index], {}, '') wx.$track.setTrackData(0, eventCode[index], {}, "");
this.setData({ this.setData(
{
tabIndex: index, tabIndex: index,
mode: target.value, mode: target.value,
// sceneTabIndex: 0, // sceneTabIndex: 0,
sortField: index == 1 ? 4 : 1, // 行为排序初始为4成交数 sortField: index == 1 ? 4 : 1, // 行为排序初始为4成交数
sortOrder: 1 sortOrder: 1,
}, () => { },
() => {
// const comp = this.selectComponent('#date') // const comp = this.selectComponent('#date')
// if (comp) comp.initLoad('date') // if (comp) comp.initLoad('date')
const sortComp = this.selectComponent('#employee-ranking') const sortComp = this.selectComponent("#employee-ranking");
if (sortComp) sortComp.initLoad() if (sortComp) sortComp.initLoad();
setTimeout(() => { setTimeout(() => {
this.getAIAnalyse() this.getAIAnalyse();
this.getEmployeeRank() this.getEmployeeRank();
if (index == 2) { if (index == 2) {
this.getTrainingStaticsData() // 培训tab 多请求一次业绩接口获取统计数据 this.getTrainingStaticsData(); // 培训tab 多请求一次业绩接口获取统计数据
} }
}) });
}) },
);
}, },
// 切换业务 // 切换业务
changeSceneTab(e) { changeSceneTab(e) {
let { target } = e.currentTarget.dataset let { target } = e.currentTarget.dataset;
let { sceneTabList } = this.data let { sceneTabList } = this.data;
const index = sceneTabList?.findIndex(val => val.value == target.value) const index = sceneTabList?.findIndex((val) => val.value == target.value);
let eventCode = ['supervisor_warranty_tab', 'supervisor_benefits_tab', 'supervisor_lightMod_tab'] let eventCode = ["supervisor_warranty_tab", "supervisor_benefits_tab", "supervisor_lightMod_tab"];
wx.$track.setTrackData(0, eventCode[index], {}, '') wx.$track.setTrackData(0, eventCode[index], {}, "");
this.setData({ this.setData(
sceneTabIndex: index {
}, () => { sceneTabIndex: index,
this.getAIAnalyse() },
this.getEmployeeRank() () => {
this.getTrainingStaticsData() this.getAIAnalyse();
}) this.getEmployeeRank();
this.getTrainingStaticsData();
},
);
}, },
// 排序变化 // 排序变化
onEmployeeSortChange(e) { onEmployeeSortChange(e) {
const { rankfield, rankType } = e.detail const { rankfield, rankType } = e.detail;
wx.$track.setTrackData(0, `supervisor_${rankfield}_${rankType}`, {}, '') wx.$track.setTrackData(0, `supervisor_${rankfield}_${rankType}`, {}, "");
this.setData({ this.setData({
sortField: rankfield, sortField: rankfield,
sortOrder: rankType == 'desc' ? 1 : 0 sortOrder: rankType == "desc" ? 1 : 0,
}) });
this.getEmployeeRank() this.getEmployeeRank();
}, },
search(e) { search(e) {
this.setData({ this.setData({
startStr: e.detail.startDay?.replace(/\//g, '-'), startStr: e.detail.startDay?.replace(/\//g, "-"),
endStr: e.detail.endDay?.replace(/\//g, '-'), endStr: e.detail.endDay?.replace(/\//g, "-"),
timeDimension: e.detail.timeDimension timeDimension: e.detail.timeDimension,
}) });
this.getAIAnalyse() this.getAIAnalyse();
this.getEmployeeRank() this.getEmployeeRank();
this.getTrainingStaticsData() this.getTrainingStaticsData();
}, },
getAIAnalyse() { getAIAnalyse() {
let { startStr, endStr, timeDimension, tabIndex, sceneTabIndex } = this.data let { startStr, endStr, timeDimension, tabIndex, sceneTabIndex } = this.data;
const apievents = ['getDashboardAIResult', 'getBehaviorAIResult', 'getAIAnslyseData'] const apievents = ["getDashboardAIResult", "getBehaviorAIResult", "getAIAnslyseData"];
let params = tabIndex == 2 ? { let params =
tabIndex == 2
? {
type: tabIndex + 1, type: tabIndex + 1,
timeDimension: timeDimension + 1, timeDimension: timeDimension + 1,
startDate: startStr, startDate: startStr,
endDate: endStr endDate: endStr,
} : { }
: {
bizs: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : undefined, bizs: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : undefined,
dateType: timeDimension, dateType: timeDimension,
startDate: startStr, startDate: startStr,
endDate: endStr endDate: endStr,
} };
this.setData({AILoading: true, AIContent: ''}) this.setData({ AILoading: true, AIContent: "" });
api[apievents[tabIndex]](params).then(res => { api[apievents[tabIndex]](params)
this.setData({AILoading: false}) .then((res) => {
let { code, data, message } = res this.setData({ AILoading: false });
let { code, data, message } = res;
if (code == 0) { if (code == 0) {
if (tabIndex == 2) { if (tabIndex == 2) {
this.setData({ this.setData({
AIContent: data?.aiGenerateResult ? `${JSON.parse(data?.aiGenerateResult).current_analysis}${JSON.parse(data?.aiGenerateResult).suggestions}` : '', AIContent: data?.aiGenerateResult ? `${JSON.parse(data?.aiGenerateResult).current_analysis}${JSON.parse(data?.aiGenerateResult).suggestions}` : "",
}) });
} else { } else {
this.setData({ this.setData({
AIContent: data?.aiAnalysisSuggestion ? `${JSON.parse(data?.aiAnalysisSuggestion).current_analysis}${JSON.parse(data?.aiAnalysisSuggestion).suggestions}` : '', AIContent: data?.aiAnalysisSuggestion ? `${JSON.parse(data?.aiAnalysisSuggestion).current_analysis}${JSON.parse(data?.aiAnalysisSuggestion).suggestions}` : "",
}) });
} }
} else { } else {
wx.$util.showToast(message) wx.$util.showToast(message);
} }
}).catch(() => {
this.setData({AILoading: false})
}) })
.catch(() => {
this.setData({ AILoading: false });
});
}, },
getTrainingStaticsData() { getTrainingStaticsData() {
let { sceneTabIndex, startStr, endStr, sortField, sortOrder, timeDimension } = this.data let { sceneTabIndex, startStr, endStr, sortField, sortOrder, timeDimension } = this.data;
api.getDashboardData({ api
.getDashboardData({
bizs: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : undefined, bizs: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : undefined,
dateType: timeDimension, dateType: timeDimension,
startDate: startStr, startDate: startStr,
endDate: endStr, endDate: endStr,
sortField: 1, sortField: 1,
sortDirection: 1 sortDirection: 1,
}).then(res => { })
let { code, data, message } = res .then((res) => {
let { code, data, message } = res;
if (code == 0) { if (code == 0) {
if (data?.metrics) { if (data?.metrics) {
data.metrics.staffCount = (data.metrics.staffCount ?? '') === '' ? '-' : this.formatThousands(data.metrics.staffCount) data.metrics.staffCount = (data.metrics.staffCount ?? "") === "" ? "-" : this.formatThousands(data.metrics.staffCount);
data.metrics.storeCount = (data.metrics.storeCount ?? '') === '' ? '-' : this.formatThousands(data.metrics.storeCount) data.metrics.storeCount = (data.metrics.storeCount ?? "") === "" ? "-" : this.formatThousands(data.metrics.storeCount);
data.metrics.totalOutput = (data.metrics.totalOutput ?? '') === '' ? '-' : this.formatThousands(data.metrics.totalOutput) data.metrics.totalOutput = (data.metrics.totalOutput ?? "") === "" ? "-" : this.formatThousands(data.metrics.totalOutput);
} }
this.setData({ this.setData({
staticData: data?.metrics staticData: data?.metrics,
}) });
} else { } else {
wx.$util.showToast(message) wx.$util.showToast(message);
} }
}) });
}, },
getEmployeeRank(noAI) { getEmployeeRank(noAI) {
let { tabIndex, sceneTabIndex, startStr, endStr, sortField, sortOrder, timeDimension } = this.data let { tabIndex, sceneTabIndex, startStr, endStr, sortField, sortOrder, timeDimension } = this.data;
const sortComp = this.selectComponent('#employee-ranking') const sortComp = this.selectComponent("#employee-ranking");
if (sortComp) { if (sortComp) {
sortComp.clear() sortComp.clear();
} }
this.setData({ this.setData({
employeeList: [] employeeList: [],
}) });
const event = ['getDashboardData', 'getDashboardBehavior', 'getTrainingStaffList'] const event = ["getDashboardData", "getDashboardBehavior", "getTrainingStaffList"];
let params = tabIndex == 2 ? { let params =
tabIndex == 2
? {
businessType: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : undefined, businessType: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : undefined,
startDate: startStr, startDate: startStr,
endDate: endStr, endDate: endStr,
sortField, sortField,
sortOrder sortOrder,
} : { }
: {
bizs: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : undefined, bizs: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : undefined,
dateType: timeDimension, dateType: timeDimension,
startDate: startStr, startDate: startStr,
endDate: endStr, endDate: endStr,
sortField, sortField,
sortDirection: sortOrder sortDirection: sortOrder,
} };
wx.$util.showLoading() wx.$util.showLoading();
api[event[tabIndex]](params).then(res => { api[event[tabIndex]](params).then((res) => {
wx.$util.hideLoading() wx.$util.hideLoading();
let { code, data, message } = res let { code, data, message } = res;
if (code == 0) { if (code == 0) {
if (data?.metrics) { if (data?.metrics) {
data.metrics.staffCount = (data.metrics.staffCount ?? '') === '' ? '-' : this.formatThousands(data.metrics.staffCount) data.metrics.staffCount = (data.metrics.staffCount ?? "") === "" ? "-" : this.formatThousands(data.metrics.staffCount);
data.metrics.storeCount = (data.metrics.storeCount ?? '') === '' ? '-' : this.formatThousands(data.metrics.storeCount) data.metrics.storeCount = (data.metrics.storeCount ?? "") === "" ? "-" : this.formatThousands(data.metrics.storeCount);
data.metrics.totalOutput = (data.metrics.totalOutput ?? '') === '' ? '-' : this.formatThousands(data.metrics.totalOutput) data.metrics.totalOutput = (data.metrics.totalOutput ?? "") === "" ? "-" : this.formatThousands(data.metrics.totalOutput);
} }
switch(tabIndex) { switch (tabIndex) {
case 0: case 0:
this.setData({ this.setData({
staticData: data?.metrics, staticData: data?.metrics,
employeeList: data?.employeeList || [] employeeList: data?.employeeList || [],
}) });
break break;
case 1: case 1:
this.setData({ this.setData({
staticData: data?.metrics, staticData: data?.metrics,
employeeList: data?.employeeList || [] employeeList: data?.employeeList || [],
}) });
break break;
case 2: case 2:
data?.forEach(val => { data?.forEach((val) => {
val.employeePhone = val.phone val.employeePhone = val.phone;
}) });
this.setData({ this.setData({
employeeList: data || [] employeeList: data || [],
}) });
} }
} else { } else {
wx.$util.showToast(message) wx.$util.showToast(message);
} }
}) });
},
handleNavigatePerformance(e) {
const { key } = e.currentTarget.dataset;
const urlMap = {
staffCount: "/packageIndex/pages/stationStaffPerformance/stationStaffPerformance",
shopCount: "/packageIndex/pages/storePerformance/storePerformance",
};
const url = urlMap[key];
if (!url) return;
wx.navigateTo({ url });
}, },
// 跳转员工个人看板 // 跳转员工个人看板
onEmployeeTap(e) { onEmployeeTap(e) {
const employee = e.detail.employee const employee = e.detail.employee;
wx.$track.setTrackData(0, 'supervisor_staffDetail', {}, '') wx.$track.setTrackData(0, "supervisor_staffDetail", {}, "");
let { startStr, endStr, timeDimension, sceneTabIndex } = this.data let { startStr, endStr, timeDimension, sceneTabIndex } = this.data;
let query = { let query = {
...employee, ...employee,
scene: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : '', scene: sceneTabIndex > 0 ? sceneMaps[sceneTabIndex] : "",
startDate: startStr, startDate: startStr,
endDate: endStr, endDate: endStr,
timeDimension: timeDimension timeDimension: timeDimension,
} };
const encoded = encodeURIComponent(JSON.stringify(query)) const encoded = encodeURIComponent(JSON.stringify(query));
wx.navigateTo({ wx.navigateTo({
url: `/packageCrew/pages/peopleOverview/peopleOverview?query=${encoded}`, url: `/packageCrew/pages/peopleOverview/peopleOverview?query=${encoded}`,
}) });
}, },
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide() { onHide() {},
},
/** /**
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload() { onUnload() {},
},
/** /**
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh() { onPullDownRefresh() {},
},
/** /**
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom() { onReachBottom() {},
},
/** /**
* 用户点击右上角分享 * 用户点击右上角分享
*/ */
onShareAppMessage() { onShareAppMessage() {},
});
}
})
...@@ -7,38 +7,61 @@ ...@@ -7,38 +7,61 @@
</view> </view>
</navigation-bar> </navigation-bar>
<view class="bg"></view> <view class="bg"></view>
<view class="container" scroll-y style="padding-top: {{navBarHeight}}px;"> <view class="container"
scroll-y
style="padding-top: {{ navBarHeight }}px;">
<view class="top-box"> <view class="top-box">
<view class="tab"> <view class="tab">
<view class="tab-item {{tabIndex == index ? 'active' : ''}}" bindtap="changeTab" data-target="{{item}}" wx:for="{{tabList}}" wx:key="index">{{item.text}}</view> <view class="tab-item {{ tabIndex == index ? 'active' : '' }}"
bindtap="changeTab"
data-target="{{ item }}"
wx:for="{{ tabList }}"
wx:key="index">
{{ item.text }}
</view>
</view> </view>
<view class="scene-tab"> <view class="scene-tab">
<view class="scene-tab-item {{sceneTabIndex == index ? 'active' : ''}}" wx:for="{{sceneTabList}}" wx:key="index" bindtap="changeSceneTab" data-target="{{item}}"> <view class="scene-tab-item {{ sceneTabIndex == index ? 'active' : '' }}"
<image wx:if="{{sceneTabIndex == index}}" src="{{IMG_URL}}{{item.icon}}.png" mode=""/> wx:for="{{ sceneTabList }}"
{{item.text}} wx:key="index"
bindtap="changeSceneTab"
data-target="{{ item }}">
<image wx:if="{{ sceneTabIndex == index }}"
src="{{ IMG_URL }}{{ item.icon }}.png"
mode="" />
{{ item.text }}
</view> </view>
</view> </view>
<view class="date"> <view class="date">
<date-screen id="date" bind:search="search" setTrackData="{{true}}"></date-screen> <date-screen id="date"
bind:search="search"
setTrackData="{{ true }}"></date-screen>
</view> </view>
</view> </view>
<scroll-view scroll-y style="height: calc(100% - {{topBoxHeight}}px);"> <scroll-view scroll-y style="height: calc(100% - {{ topBoxHeight }}px);">
<view class="static-info"> <view class="static-info">
<view class="static-item" style="flex: {{item.width}}rpx 0 0;background: {{item.background}};" wx:for="{{staticList}}" wx:key="index"> <view class="static-item"
<view class="label">{{item.label}}</view> wx:for="{{ staticList }}"
<view class="value">{{staticData[item.key]}}</view> style="flex: {{ item.width }}rpx 0 0;background: {{ item.background }};"
</view> data-key="{{ item.key }}"
</view> bind:tap="handleNavigatePerformance"
<AI-analyse AIContent="{{AIContent}}" loading="{{AILoading}}" /> wx:key="index">
<employee-ranking <view class="label">
id="employee-ranking" {{ item.label }}
title-icon="{{IMG_URL}}staff-rank.png" </view>
mode="{{mode}}" <view class="value">
scene="{{sceneTabIndex}}" {{ staticData[item.key] }}
employee-list="{{employeeList}}" </view>
local-sort="{{false}}" </view>
</view>
<AI-analyse AIContent="{{ AIContent }}" loading="{{ AILoading }}" />
<employee-ranking id="employee-ranking"
title-icon="{{ IMG_URL }}staff-rank.png"
mode="{{ mode }}"
scene="{{ sceneTabIndex }}"
employee-list="{{ employeeList }}"
local-sort="{{ false }}"
bind:sortChange="onEmployeeSortChange" bind:sortChange="onEmployeeSortChange"
bind:employeeTap="onEmployeeTap" bind:employeeTap="onEmployeeTap" />
/>
</scroll-view> </scroll-view>
</view> </view>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!