// shoppingGuid/page/pages/enlistInfo/enlistInfo.js
const wxService = require('../../../../utils/wxService')
wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    enlistList: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let taskId = this.options && this.options.id || 0
    let orderType = this.options && this.options.type || 2
    this.getTaskDetail(orderType, taskId)
  },
  //获取任务详情
  getTaskDetail(orderType, taskId) {
    wx.showLoading({
      title: '加载中'
    })
    wxService.post(`/marketing/shoppingguide/task/detail?orderType=${orderType}&taskId=${taskId}`).then(res => {
      if (res) {
        const { result, data } = res.data
        if (result == 0) {
          wx.hideLoading()
          if (data.task.startTime) {
            data.task.startTime = data.task.startTime.replace(/\-/g, '/');
          }
          if (data.task.endTime) {
            data.task.endTime = data.task.endTime.replace(/\-/g, '/');
          }

          let curStart = new Date(data.task.startTime)
          let curEnd = new Date(data.task.endTime)
          data.task.startTime = `${curStart.getMonth()}月${curStart.getDay()}日`
          data.task.endTime = `${curEnd.getMonth()}月${curEnd.getDay()}日`

          this.setData({
            enlistList: data || {}
          })
        }
      }
    })
  },
  //跳转到活动说明界面
  onTapToNotice() {
    let taskId = this.options && this.options.id || 0
    let orderType = this.options && this.options.type || 1;

    wx.navigateTo({
      url: `/shoppingGuid/page/pages/taskNotice/taskNotice?id=${taskId}&type=${orderType}`,
    });
  }
})