monthlyPlan.js 2.18 KB
// packageIndex/pages/monthlyPlan/monthlyPlan.js
import api from '~/api/index/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
		navBarHeight: 84,
		orderObj: {
			taskContext: ''
		}
	},
	
	navbarReady(e) {
    let navBarHeight = e.detail.height
    this.setData({
      navBarHeight
    })
	},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
		this.setData({
			pageQuery: options
		})
		if (options.taskStatus == 2) {
			this.getDetail(options.id)
		}
  },

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

  },

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

	},

	getDetail(id) {
		api.getTaskDetail({id}).then(res => {
			let { code, data, message } = res
			if (code == 0) {
				let taskContextLength = data.taskContext?.length
				this.setData({
					taskContextLength
				}, () => {
					this.setData({
						orderObj: data || {}
					})
				})
			} else {
				wx.$util.showToast(message)
			}
		})
	},

	taskContextInput(e) {
		let val = e.detail.value || ""
    if (val.length > 1000) {
      val = val.substring(0, 1000)
    }
    this.setData({ 
      'orderObj.taskContext': val, 
      taskContextLength: val.length 
    })
	},

	submit() {
		let { orderObj, pageQuery } = this.data
		if (!orderObj.taskContext) return wx.$util.showToast('请完成所有必填项')
		let params = {
			id: pageQuery?.id,
			taskType: 2,
			taskContext: orderObj.taskContext
		}
		wx.$util.showLoading()
		api.submitMonthPlan(params).then(res => {
			wx.$util.hideLoading()
			let { code, message } = res
			if (code == 0) {
				wx.$util.showToast('操作成功')
				this.back()
			} else {
				wx.$util.showToast(message)
			}
		}).catch(() => {
			wx.$util.hideLoading()
		})
	},

	back() {
		wx.navigateBack()
	},

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

  },

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

  },

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

  },

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

  },

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

  }
})