coursePush.js 2.42 KB
// packageLearningCenter/pages/coursePush/coursePush.js
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import api from '~/api/learningCenter/index'
import indexApi from '~/api/index/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
		IMG_URL,
		courseInfo: {},
		orderObj: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
		this.setData({
			courseInfo: options
		})
		// 获取督导员工数据
		this.getStaffList()
  },

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

  },

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

	},

	getStaffList() {
		indexApi.getSupervisorStaffList({}).then(res => {
			let { code, data, message } = res
			if (code == 0) {
				this.setData({
					staffList: data
				})
			} else {
				wx.$util.showToast(message)
			}
		})
	},
	
	chooseSelect() {
		let { orderObj, staffList } = this.data
		this.setData({
      showSelectPopup: true,
      selectOptions: staffList,
      selectValues: orderObj.coursePushList?.map(val => { return val.staffPhone })
    })
	},

	handlePopupConfirm(e) {
		let { items } = e.detail
    this.setData({
			[`orderObj.coursePushList`]: items
    }, () => {
			this.hideSelectPopup()
		})
	},

	hideSelectPopup() {
		this.setData({
			showSelectPopup: false
		})
	},

	submit() {
		let { orderObj, courseInfo } = this.data
		if (!orderObj.coursePushList?.length) return wx.$util.showToast('请选择推送人员')
		let params = {
			coursePushList: orderObj.coursePushList?.map(val => {
				return {
					storeManagerPhone: val.staffPhone,
					storeManagerName: val.staffName,
					bcCourseId: courseInfo?.courseId,
					bcCourseName: courseInfo?.title
				}
			})
		}
		wx.$util.showLoading()
		api.submitCoursePush(params).then(res => {
			wx.$util.hideLoading()
			let { code, message } = res
			if (code == 0) {
				wx.navigateBack()
			} else {
				wx.$util.showToast(message)
			}
		}).catch(() => {
			wx.$util.hideLoading()
		})
	},

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

  },

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

  },

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

  },

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

  },

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

  }
})