receptionRecording.js 4.06 KB
// packageCrew/pages/receptionRecording/receptionRecording.js
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/'
import { getRecordingList } from "~/api/crew/index"
import dayjs from 'dayjs'
Page({

  /**
   * 页面的初始数据
   */
  data: {
		IMG_URL,
		detailInfo: {},
		initTimeDimension: -1,
		initStartDate: '',
		initEndDate: '',
		dateReady: false,
		detailItems: [{
			label: '手机号码',
			key: 'storeManagerPhone'
		}, {
			label: '入职时间',
			key: 'entryDate',
			width: '290rpx'
		}, {
			label: '归属业务',
			key: 'business',
			inline: true
		}],
		staticsItems: [{
			label: '录音',
			key: 'totalRecordings'
		}, {
			label: '成交数',
			key: 'dealCount'
		}, {
			label: '战败数',
			key: 'defeatCount'
		}],
		staticDate: {},
		pageNum: 1,
		nothing: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
		let query = {}
		try {
			const decoded = decodeURIComponent(options.query || '')
			query = JSON.parse(decoded)
		} catch (e) {
			query = {}
		}
		console.log(query, '1111111')
		this.setData({
			detailInfo: query,
			initTimeDimension: Number(query?.timeDimension ?? query?.dateType ?? -1),
			initStartDate: query?.startDate || '',
			initEndDate: query?.endDate || '',
			dateReady: true
		})
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
		this.setData({
			list: [],
      pageNum: 1,
      flag: false,
			nothing: false,
		}, () => {
			this.getReceptionList()
		})
	},
	
	search(e) {
		this.setData({
      list: [],
      pageNum: 1,
      flag: false,
			nothing: false,
			startStr: e.detail.startDay?.replace(/\//g, '-'),
			endStr: e.detail.endDay?.replace(/\//g, '-')
    }, () => {
			this.getReceptionList()
		})
	},
	
  getReceptionList() {
		const seq = (this._reqSeq = (this._reqSeq || 0) + 1)
		let { pageNum, startStr, endStr, detailInfo, nothing } = this.data
		let params = {
			pageNum,
			pageSize: 10,
			startDate: startStr,
			endDate: endStr,
			phoneNumber: detailInfo?.storeManagerPhone,
			bizs: detailInfo.scene ? detailInfo.scene : ''
		}
		if (nothing) return
		wx.$util.showLoading()
		getRecordingList(params).then(res => {
			if (seq !== this._reqSeq) return
			wx.$util.hideLoading()
			let { code, data, message } = res
			if (code == 0) {
				data.dateSummaryList?.forEach(val => {
					val.receptionStaticInfoDTOList = []
					val.staticDateStr = `${new Date(val.date).getMonth() + 1}月${new Date(val.date).getDate()}日`
					data?.recordingList?.forEach(subVal => {
						subVal.totalDuration = subVal.recordingDuration
						if (val.date == dayjs(subVal.receptionTime).format('YYYY-MM-DD')) {
							val.receptionStaticInfoDTOList.push(subVal)
						}
					})
				})
				let list = data.dateSummaryList
				let total = data.totalCount
				if (total != 0) {
					this.setData({
						[`list[${pageNum - 1}]`]: list
					})
				}
				this.setData({
					total,
					flag: true,
					triggered: false,
					pageNum: pageNum + 1,
					nothing: total == this.data.list.flatMap(inner => inner).reduce((sum, item) => sum + (item.receptionStaticInfoDTOList?.length || 0), 0),
					staticDate: data?.summary || {}
				}, () => {
					const query = wx.createSelectorQuery().in(this)
					query.select('.content').boundingClientRect()
					query.exec(res => {
						this.setData({contentHeight: res[0]?.height})
					})
				})
			} else {
				wx.$util.showToast(message)
			}
		}).catch(() => {
			if (seq !== this._reqSeq) return
			wx.$util.hideLoading()
		})
  },
	
	// 触底加载更多
  onBottomRefresh() {
    this.getReceptionList()
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})