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