trainingExperience.js 3.28 KB
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/'
import dayjs from 'dayjs'
import api from '~/api/crew/index'
Component({
  properties: {
    detailInfo: {
      type: Object,
      value: {},
    },
		initTimeDimension: {
			type: Number,
			value: -1
		},
		initStartDate: {
			type: String,
			value: ''
		},
		initEndDate: {
			type: String,
			value: ''
		},
  },
  data: {
		IMG_URL,
		topStats: [
			{ label: '学习时长', key: 'studyHours' },
			{ label: '完成课程数', key: 'completedCourses' },
			{ label: '带教次数', key: 'coachingTimes' }
		],
		tabs: [
			{ key: 'course', label: '课程学习' },
			{ key: 'coach', label: '督导带教' }
		],
		activeTab: 0,
		list: []
	},
  methods: {
		_beginListRequest() {
			this._listReqSeq = (this._listReqSeq || 0) + 1
			return this._listReqSeq
		},
		_isLatestListRequest(seq) {
			return seq === this._listReqSeq
		},
		_beginTopRequest() {
			this._topReqSeq = (this._topReqSeq || 0) + 1
			return this._topReqSeq
		},
		_isLatestTopRequest(seq) {
			return seq === this._topReqSeq
		},
		reloadData() {
			this.getData()
			this.getStaticsData()
		},
		search(e) {
			this.setData({
				startDate: e.detail.startDay?.replace(/\//g, '-'),
				endDate: e.detail.endDay?.replace(/\//g, '-'),
			}, () => {
				this.getData()
				this.getStaticsData()
			})
			this.triggerEvent('datesave', {
				scope: 'trainingExperience',
				timeDimension: e.detail.timeDimension,
				startDate: e.detail.startDay,
				endDate: e.detail.endDay
			}, { bubbles: true, composed: true })
		},
		getStaticsData() {
			const seq = this._beginTopRequest()
			let { detailInfo, startDate, endDate } = this.data
			let params = {
				businessType: detailInfo.scene || undefined,
				startDate,
				endDate,
				sortField: 1,
				sortOrder: 0,
				storeManagerPhone: detailInfo?.employeePhone
			}
			api.getTrainingStaffList(params).then(res => {
				if (!this._isLatestTopRequest(seq)) return
				let { code, data, message } = res
				if (code == 0) {
					this.setData({
						topInfo: data[0] || {}
					})
				} else {
					wx.$util.showToast(message)
				}
			})
		},
		getData() {
			const seq = this._beginListRequest()
			let { activeTab, detailInfo, startDate, endDate } = this.data
			let params = {
				businessType: detailInfo?.scene,
				storeManagerPhone: detailInfo.employeePhone,
				startDate,
				endDate,
				trainingType: activeTab + 1
			}
			wx.$util.showLoading()
			api.getTrainingExperienceList(params).then(res => {
				if (!this._isLatestListRequest(seq)) return
				wx.$util.hideLoading()
				let { code, data, message } = res
				if (code == 0) {
					data?.forEach(val => {
						val.completedTime = dayjs(val.completedTime).format('YYYY-MM-DD HH:mm:ss')
					})
					this.setData({
						list: data
					})
				}	else {
					wx.$util.showToast(message)
				}
			}).catch(() => {
				if (!this._isLatestListRequest(seq)) return
				wx.$util.hideLoading()
			})
		},
		onTabTap(e) {
			const { index } = e.currentTarget.dataset || {}
			if (index == this.data.activeTab) return
			this.setData({ activeTab: index, list: [] }, () => {
				this.getData()
			})
		},
		onViewItem(e) {
			const { item } = e.currentTarget.dataset || {}
			wx.navigateTo({
				url: `/packageCrew/pages/mentoring/mentoring?id=${item.taskId}`,
			})
		}
	},
})