crew.js 9.72 KB
// 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/'
Page({

  /**
   * 页面的初始数据
   */
  data: {
		IMG_URL,
		tabIndex: 0,
		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: 'shopCount',
			background: 'linear-gradient(90deg, #5E69FF 0%, #4079FF 100%)'
		}, {
			label: '总产值',
			key: 'totalValue',
			background: 'linear-gradient(90deg, #3D76FC 0%, #4DA6FF 100%)'
		}],
		AIContent: '',
		staticData: {},
		employeeList: [{
			staffName: '邹家平',
			staffPhone: '18971083546',
			chengjiao: 3,
			zhanbai: 8,
			luyin: 15,
			queshilv: 34.54,
			xuexi: 3,
			wancheng: 7,
			daijiao: 15,
			chanzhi: 43545600.45,
			kedan: 45600.45,
			zhuanhua: 34.54
		}, {
			staffName: '邹家平',
			staffPhone: '18971083546',
			chengjiao: 3,
			zhanbai: 8,
			luyin: 15,
			queshilv: 34.54,
			xuexi: 3,
			wancheng: 7,
			daijiao: 15,
			chanzhi: 43545600.45,
			kedan: 45600.45,
			zhuanhua: 34.54
		}, {
			staffName: '邹家平',
			staffPhone: '18971083546',
			chengjiao: 3,
			zhanbai: 8,
			luyin: 15,
			queshilv: 34.54,
			xuexi: 3,
			wancheng: 7,
			daijiao: 15,
			chanzhi: 43545600.45,
			kedan: 45600.45,
			zhuanhua: 34.54
		}, {
			staffName: '邹家平',
			staffPhone: '18971083546',
			chengjiao: 3,
			zhanbai: 8,
			luyin: 15,
			queshilv: 34.54,
			xuexi: 3,
			wancheng: 7,
			daijiao: 15,
			chanzhi: 43545600.45,
			kedan: 45600.45,
			zhuanhua: 34.54
		}]
	},

	onTabItemTap(e) {
    // 点击埋点
    // wx.$track.setTrackData(0, 'supervisor_crew_page', {}, '')
  },
	
	navbarReady(e) {
    let navBarHeight = e.detail.height
    this.setData({
      navBarHeight
    })
	},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
		this.getStaticsData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

	},

	search() {

	},

	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
	},

	getStaticsData() {
		// 假数据
		let data = {
			staffCount: 56,
			shopCount: 12,
			totalValue: 68954782.23
		}
		data.staffCount = this.formatThousands(data.staffCount)
		data.shopCount = this.formatThousands(data.shopCount)
		data.totalValue = this.formatThousands(data.totalValue)
		this.setData({staticData: data})
		// indexApi.getSupervisorStaticData({}).then(res => {
		// 	let { code, data, message } = res
		// 	if (code == 0) {
		// 		this.setData({staticData: data})
		// 	} else {
		// 		wx.$util.showToast(message)
		// 	}
		// })
	},
	
	// 切换类型
	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: 1,
			sortOrder: 1
		}, () => {
			const comp = this.selectComponent('#date')
			if (comp) comp.initLoad('date')
		})
	},

	// 切换业务
	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
		}, () => {
			const comp = this.selectComponent('#date')
			if (comp) comp.initLoad('date')
		})
	},
	// 排序变化
  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()
	},

	search(e) {
		this.setData({
			startStr: e.detail.startDay?.replace(/\//g, '-'),
			endStr: e.detail.endDay?.replace(/\//g, '-'),
			timeDimension: e.detail.timeDimension + 1
		})
		this.getAIAnalyse()
		this.getEmployeeRank()
	},
	getAIAnalyse() {
		let { startStr, endStr, timeDimension, tabIndex } = this.data
		// 假数据
		let data = {
			aiGenerateResult: '团队培训数据显示表面学习投入尚可,但知识体系构建严重不均,部分老顾问仅完成基础课程,在新产品与金融方案上存在明显知识断层,且带教记录空白,表明技能固化缺乏更新。与此同时,新人虽接受带教较多,但与其高战败率关联看,带教内容可能未精准击中其销售流程中的薄弱环节(如需求挖掘)。当前培训陷入“学用脱节”与“辅导泛化”的困境。建议立即进行针对性调整:第一,实施“短板课程强推计划”,根据上月战败主因(如竞品对比失利),强制相关顾问在3日内完成对应专题课程学习并通关测试;第二,改革带教模式,推行“数据驱动的精准带教”,督导需提前查阅带教对象的近期战败录音或低分项,带着具体问题(如“如何应对XX竞品的空间质疑”)进行陪访或演练,确保每次带教解决一个实际问题。通过“缺什么补什么”和“练什么考什么”,快速将培训转化为实战能力。团队培训数据显示表面学习投入尚可,但知识体系构建严重不均,部分老顾问仅完成基础课程,在新产品与金融方案上存在明显知识断层,且带教记录空白,表明技能固化缺乏更新。将“现状分析”与“建议”两部分自然融合为一段连贯文字,避免使用标题。整段文字需严格控制在500字以内,语言简洁、务实、指向明确。'
		}
		this.setData({
			AIContent: data?.aiGenerateResult
		})
		// api.getAIAnslyseData({
		// 	type: tabIndex + 1,
		// 	timeDimension: timeDimension,
		// 	startDate: startStr,
		// 	endDate: endStr
		// }).then(res => {
		// 	let { code, data, message } = res
		// 	if (code == 0) {
		// 		this.setData({
		// 			AIContent: data?.aiGenerateResult || ''
		// 		})
		// 	} else {
		// 		wx.$util.showToast(message)
		// 	}
		// })
	},
	// 获取员工排名数据
	getEmployeeRank() {
		let { tabIndex, sceneTabIndex, startStr, endStr, sortField, sortOrder, timeDimension } = this.data
		const event = ['getDashboardData', 'getDashboardBehavior', 'getTrainingStaffList']
		let params = tabIndex == 2 ? {
			businessType: sceneTabIndex > 0 ? sceneTabIndex : '',
			startDate: startStr,
			endDate: endStr,
			sortField,
			sortOrder
		} : {
			bizs: sceneTabIndex > 0 ? sceneTabIndex : '',
			dateType: timeDimension,
			startDate: startStr,
			endDate: endStr
		}
		wx.$util.showLoading()
		setTimeout(() => {
			wx.$util.hideLoading()
			// 假数据
			let data
			if (tabIndex == 0 || tabIndex == 1) {
				data = {
					employeeList: [{
						employeePhone: 15626599738,
						personalOutput: 43545600.53,
						personalUnitPrice: 15623.23,
						personalConversion: 56.23,
						employeeName: '张三',
						dealCount: 56,
						defeatCount: 80,
						recordingCount: 156,
						missingRate: 59,
						employeeId: 123
					}, {
						employeePhone: 15626599738,
						personalOutput: 43545600.53,
						personalUnitPrice: 15623.23,
						personalConversion: 56.23,
						employeeName: '张三',
						dealCount: 56,
						defeatCount: 80,
						recordingCount: 156,
						missingRate: 59,
						employeeId: 123
					}]
				}
			} else {
				data = [{
					employeeName: '张胜男',
					phone: 15623568956,
					studyHours: 15,
					completedCourses: 5,
					coachingTimes: 20
				}, {
					employeeName: '张胜男',
					phone: 15623568956,
					studyHours: 15,
					completedCourses: 5,
					coachingTimes: 20
				}, {
					employeeName: '张胜男',
					phone: 15623568956,
					studyHours: 15,
					completedCourses: 5,
					coachingTimes: 20
				}, {
					employeeName: '张胜男',
					phone: 15623568956,
					studyHours: 15,
					completedCourses: 5,
					coachingTimes: 20
				}]
			}
			this.setData({employeeList: data.employeeList || data})
		}, 300)
		console.log(params)
		api[event[tabIndex]](params).then(res => {

		})
	},
	// 跳转员工个人看板
  onEmployeeTap(e) {
		const employee = e.detail.employee
		// wx.$track.setTrackData(0, 'supervisor_staffDetail', {}, '')
		wx.navigateTo({
			url: `/packageCrew/pages/peopleOverview/peopleOverview?emloyeeId=${employee.employeeId}&scene=${this.data.sceneTabIndex}`,
		})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

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

  },

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

  }
})