specialTask.js 2.6 KB
// packageIndex/pages/specialTask/specialTask.js
import dayjs from 'dayjs'
import api from '~/api/index/index'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/'
Page({

  /**
   * 页面的初始数据
   */
  data: {
		IMG_URL,
		navBarHeight: 84,
		statusMap: {
			0: {name: '待完成', color: '#2C66F7', background: '#2c66f71a'},
			1: {name: '进行中', color: '#FF9D0A', background: '#ff9d0a1a'},
			2: {name: '已完成', color: '#35C376', background: '#35c3761a'},
		},
		detailInfo: {},
		orderObj: {
			taskContext: ''
		}
	},
	
	navbarReady(e) {
    let navBarHeight = e.detail.height
    this.setData({
      navBarHeight
    })
	},

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

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

  },

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

	},

	getDetail(options) {
		api.getTaskDetail({id: options.id}).then(res => {
			let { code, data, message } = res
			if (code == 0) {
				let taskContextLength = data.taskContext?.length
				data.createTime = dayjs(data.createTime).format('YYYY-MM-DD HH:mm:ss')
				this.setData({
					taskContextLength
				}, () => {
					this.setData({
						orderObj: data || {}
					})
				})
			} else {
				wx.$util.showToast(message)
			}
		})
	},

	taskContextInput(e) {
		let val = e.detail.value || ""
    if (val.length > 500) {
      val = val.substring(0, 500)
		}
    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: 4,
			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() {

  }
})