behaviorAnalysis.js 5.15 KB
import api from '~/api/crew/index'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/'
Component({
  properties: {
    detailInfo: {
      type: Object,
			value: {},
			observer: function(n) {
			}
		},
		selectedMerchantObj: {
			type: Object
		},
		merchantList: {
			type: Array
		},
		initTimeDimension: {
			type: Number,
			value: -1
		},
		initStartDate: {
			type: String,
			value: ''
		},
		initEndDate: {
			type: String,
			value: ''
		}
  },
  data: {
		IMG_URL,
		attendanceItems: [
			{ label: '打卡天数', key: 'checkInDays' },
			{ label: '迟到', key: 'late', valueClass: 'danger' },
			{ label: '早退', key: 'earlyLeave', valueClass: 'danger' },
			{ label: '旷工', key: 'absenteeism', valueClass: 'danger' }
		],
		dailyReportItems: [
			{ label: '已提交', key: 'submitted', subLabel: '日报完成率', subKey:'completionRate', subClass: 'success' },
			{ label: '未提交', key: 'notSubmitted' },
			{ label: '在岗', key: 'onDuty' },
			{ label: '调休', key: 'rest' }
		],
		receptionItems: [
			{ label: '实际交车数', key: 'actualDelivery' },
			{ label: '接待数量', key: 'receptionCount' },
			{ label: '未触客数', key: 'notTouched' }
		],
		weakTags: [
			{ label: '身份介绍:差', type: 'danger' },
			{ label: '场景塑造:差', type: 'danger' },
			{ label: '案例展示:差', type: 'danger' }
		],
		otherTags: [
			{ label: '逼单能力:一般', type: 'default' },
			{ label: '话题介入:一般', type: 'default' },
			{ label: '攻防能力:一般', type: 'default' },
			{ label: '服务意识:一般', type: 'default' },
			{ label: '专业知识:好', type: 'success' }
		],
		recordStatsRows: [
			[
				{ label: '录音', key: 'recordingCount' },
				{ label: '成交数', key: 'dealCount' },
				{ label: '战败数', key: 'defeatCount' },
				{ label: '成交率', key: 'dealRate' }
			],
			[
				{ label: '质检平均分', key: 'qualityScore' },
				{ label: '攻防平均分', key: 'attackDefenseScore' },
				{ label: '录音缺失率', key: 'recordingMissingRate' }
			]
		],
		tagRows: [{
			label: '弱项',
			class: 'danger',
			key: 'badList'
		}, {
			label: '其他项',
			key: 'ohterList'
		}],
		dressWarningItems: [{ label: '预警次数', key: 'warningCount' }],
		behaviorInfo: {}
	},
  methods: {
		_beginRequest() {
			this._reqSeq = (this._reqSeq || 0) + 1
			return this._reqSeq
		},
		_isLatestRequest(seq) {
			return seq === this._reqSeq
		},
		search(e) {
			this.setData({
				startStr: e.detail.startDay?.replace(/\//g, '-'),
				endStr: e.detail.endDay?.replace(/\//g, '-')
			}, () => {
				this.getData()
			})
			this.triggerEvent('datesave', {
				scope: 'behaviorAnalysis',
				timeDimension: e.detail.timeDimension,
				startDate: e.detail.startDay,
				endDate: e.detail.endDay
			}, { bubbles: true, composed: true })
		},
		safeObjectToLabelList(obj) {
			if (!obj || typeof obj !== 'object') {
				return []
			}
			let cleanObj = {};
			try {
				const jsonStr = JSON.stringify(obj)
				cleanObj = JSON.parse(jsonStr)
			} catch (e) {
				return []
			}
			const result = []
			try {
				const keys = Object.keys(cleanObj)
				for (let i = 0; i < keys.length; i++) {
					const key = keys[i]
					const value = cleanObj[key]
					const displayValue = (typeof value === 'object' && value !== null) 
						? JSON.stringify(value) 
						: String(value)
					result.push(`${key} : ${displayValue}`)
				}
			} catch (e) {
				return []
			}
			return result
		},
		getData() {
			const seq = this._beginRequest()
			let { detailInfo, startStr, endStr, selectedMerchantObj } = this.data
			let params = {
				phone: detailInfo.employeePhone,
				employeeId: selectedMerchantObj?.employeeId,
				merchantId: selectedMerchantObj?.merchantId,
				bizs: detailInfo.scene,
				startDate: startStr,
				endDate: endStr
			}
			wx.$util.showLoading()
			api.getEmployeebehaviorData(params).then(res => {
				if (!this._isLatestRequest(seq)) return
				wx.$util.hideLoading()
				let { code, data, message } = res
				if (code == 0) {
					data.recordingAnalysis.badList = this.safeObjectToLabelList(data.recordingAnalysis.badList)
					data.recordingAnalysis.ohterList = this.safeObjectToLabelList(data.recordingAnalysis.ohterList)
					this.setData({
						behaviorInfo: data
					})
				} else {
					wx.$util.showToast(message)
				}
			}).catch(() => {
				if (!this._isLatestRequest(seq)) return
				wx.$util.hideLoading()
			})
		},
		handleChangeMerchant() {
			this.triggerEvent('changeMerchant')
		},
		handleChangeMerchant(e) {
			let { merchantList, selectedMerchantObj } = this.data
			this.setData({
				showSelectPopup: true,
				selectOptions: merchantList,
				selectValue: selectedMerchantObj.merchantId ? [selectedMerchantObj.merchantId] : []
			})
		},
		handlePopupConfirm(e) {
			let { items } = e.detail
			let thisPage = wx.$router.getPageInstance()
			thisPage.setData({
				selectedMerchantObj: {
					merchantId:	items[0].merchantId,
					merchantName: items[0]?.merchantName,
					employeeId: items[0].employeeId
				}
			}, () => {
				this.getData()
			})
			this.hideSelectPopup()
		},
	
		hideSelectPopup() {
			this.setData({
				showSelectPopup: false
			})
		},
	},
})