index.js 6.6 KB
import api from '~/api/index/index'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/'
Page({
  /**
   * 页面的初始数据
   */
  data: {
		IMG_URL,
    navStyle: 'background-color: rgba(0,0,0,0);',
		navTitleStyle: 'font-weight: 600; font- size: 32rpx; color: #000;',
		navBarHeight: 0,
		userInfo: {},
		staticList: [{
			label: '驻店人员',
			width: '208',
			key: '',
			background: 'linear-gradient(90deg, #42CCCF 0%, #36D9A5 100%)'
		}, {
			label: '门店数量',
			width: '192',
			key: '',
			background: 'linear-gradient(90deg, #5E69FF 0%, #4079FF 100%)'
		}, {
			label: '总产值',
			key: '',
			background: 'linear-gradient(90deg, #3D76FC 0%, #4DA6FF 100%)'
		}],
		tabList: [{
			text: '每日任务'
		}, {
			text: '本周任务'
		}, {
			text: '月度任务'
		}, {
			text: '专项任务'
		}],
		statusMap: {
			1: {name: '待完成', color: '#2C66F7', background: '#2c66f71a'},
			2: {name: '进行中', color: '#FF9D0A', background: '#ff9d0a1a'},
			3: {name: '已完成', color: '#35C376', background: '#35c3761a'},
		},
		missionMap: {
			1: {name: '录音复盘'},
			2: {name: '人员带教'},
			3: {name: '督导日报'},
			4: {name: '本周复盘'},
			5: {name: '督导月度计划'},
			6: {name: '专项任务'},
		},
		list: [],
		scrollTop: 0,
		mockData: [{
			handleStatus: 1,
			missionType: 1,
			userName: '赵慧慧'
		}, {
			handleStatus: 3,
			missionType: 1,
			userName: '赵慧慧'
		}, {
			handleStatus: 1,
			missionType: 2,
			userName: '赵慧慧'
		}, {
			handleStatus: 3,
			missionType: 2,
			userName: '赵慧慧'
		}, {
			handleStatus: 1,
			missionType: 3,
			userName: '赵慧慧'
		}, {
			handleStatus: 3,
			missionType: 3,
			userName: '赵慧慧'
		}, {
			handleStatus: 1,
			missionType: 4,
			userName: '赵慧慧'
		}, {
			handleStatus: 3,
			missionType: 4,
			userName: '赵慧慧'
		}, {
			handleStatus: 1,
			missionType: 5,
			userName: '赵慧慧'
		}, {
			handleStatus: 3,
			missionType: 5,
			userName: '赵慧慧'
		}, {
			handleStatus: 1,
			missionType: 6,
			userName: '赵慧慧'
		}, {
			handleStatus: 3,
			missionType: 6,
			userName: '赵慧慧'
		}]
  },
  onTabItemTap(e) {
    // 点击埋点
    // wx.$track.setTrackData(0, 'supervisor_index_page', {}, '')
  },
  navbarReady(e) {
    let navBarHeight = e.detail.height
    this.setData({
      navBarHeight
    })
	},
	onScroll(e) {
		this.setData({
			scrollTop: e.detail.scrollTop
		})
		const {navBarHeight} = this.data
		const query = wx.createSelectorQuery().in(this)
		query.select('.data-container').boundingClientRect()
		query.exec(res => {
			this.setData({
				isSticky: res[0].top <= navBarHeight
			})
		})
	},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
		let userInfo = wx.$util.getUserInfo()
		this.setData({userInfo})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
		const query = wx.createSelectorQuery().in(this)
		query.select('.top-box').boundingClientRect()
		query.exec(res => {
			this.setData({
				topBoxHeight: res[0].height
			})
		})
	},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
		this.getList(true)
	},
	
	tabClick(e) {
		let eventCode = ['supervisor_dayTask_tab', 'supervisor_weeklyTask_tab', 'supervisor_monthlyTask_tab', 'supervisor_specificTask_tab']
		// 点击埋点
    // wx.$track.setTrackData(0, eventCode[e.detail], {}, '')
		this.setData({
			tabIndex: e.detail
		})
	},

	jump(e) {
		const { target } = e.currentTarget.dataset
		const pageUrl = {
			1: '/packageIndex/pages/recordingReview/recordingReview',
			2: '/packageCrew/pages/mentoring/mentoring',
			3: '/packageIndex/pages/dailySupervisionReport/dailySupervisionReport',
			4: '/packageIndex/pages/weeklyReview/weeklyReview',
			5: '/packageIndex/pages/monthlyPlan/monthlyPlan',
			6: '/packageIndex/pages/specialTask/specialTask'
		}
		const eventCode = {
			1: {view: 'supervisor_recording_view', execute: 'supervisor_recording_execute'},
			2: {view: 'supervisor_mentoring_view', execute: 'supervisor_mentoring_execute'},
			3: {view: 'supervisor_report_view', execute: 'supervisor_report_execute'},
			4: {view: 'supervisor_weeklyReview_view', execute: 'supervisor_weeklyReview_execute'},
			5: {view: 'supervisor_monthlyPlan_view', execute: 'supervisor_monthlyPlan_execute'},
			6: {view: 'supervisor_specificTask_view', execute: 'supervisor_specificTask_execute'},
		}
		let status = target.handleStatus != 3 ? 'execute' : 'view'
		console.log(eventCode[target.missionType][status])
		// wx.$track.setTrackData(0, eventCode[target.missionType][status], {}, '')
		wx.navigateTo({
			url: pageUrl[target.missionType],
		})
	},

	search(e) {
		this.setData({
      list: [],
      pageNum: 1,
      flag: false,
			nothing: false,
			startStr: e.detail.startDay,
			endStr: e.detail.endDay
    }, () => {
			this.getList(true)
		})
	},

	scrollonReachBottom() {
    this.getList()
  },

	// 获取列表数据
  getList(repload) {
    let { pageNum, nothing, startStr, endStr, tabIndex, topBoxHeight, scrollTop } = this.data
    if (nothing) return
    // wx.$util.showLoading()
    let params = {
      tabIndex,
      startStr,
      endStr,
      pageNum,
			pageSize: 10
		}
		setTimeout(() => {
			this.setData({
				list: this.data.mockData
			})
			if (scrollTop >= topBoxHeight && repload) {
				setTimeout(() => {
					this.setData({
						setScrollTop: topBoxHeight
					})
				}, 200)
			}
		}, 500)
    // api.getMissionList(params).then(res => {
    //   wx.$util.hideLoading()
    //   let total = 0
    //   let list = []
    //   let {
    //     code,
    //     data,
    //     message
    //   } = res
    //   data?.list?.forEach(val => {
    //     val.applyDate = dayjs(val.applyDate).format('YYYY-MM-DD HH:mm:ss')
    //   })
    //   if (code == 0) {
    //     list = data.list
    //     total = data.total
    //   } else {
    //     wx.$util.showToast(message)
    //   }
    //   if (total != 0) {
    //     this.setData({
    //       [`list[${pageNum - 1}]`]: list
    //     })
    //   }
    //   this.setData({
    //     total,
    //     flag: true,
    //     triggered: false,
    //     pageNum: pageNum + 1,
    //     nothing: pageNum == data?.pages
    //   })
    // })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

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

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  onShareTimeline: function () {}
})