myactivity_report.js 3.5 KB
const app = getApp();
Page({


  data: {
    id: '',
    textareaNum: 0,
    name: '',
    work_content: '',
    date: '',
    join_reason: '', //加入理由
    imageList: []
  },

  //获取信息
  get_info() {
    let that = this
    let url = 'index/index/workReportInfo'
    let params = {
      id: that.data.id
    }
    if (this.data.user_id) {
      params.user_id = this.data.user_id
    }
    let header = {
      'XX-Token': wx.getStorageSync('token')
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      this.setData({
        name: res.name,
        work_content: res.work_content,
        date: res.time[0],

      })
    })
  },

  //汇报 
  textareaIn: function (e) {
    console.log(e)
    this.setData({
      textareaNum: e.detail.cursor,
      join_reason: e.detail.value

    })
  },
  // 图片上传
  ChooseImage: function () {
    var that = this
    var Count = 9
    wx.chooseImage({
      count: Count,
      success: function (res) {
        console.log(res.tempFilePaths)
        var i = 0;
        var imageList = {};
        for (i; i <= res.tempFilePaths.lengh; i++) {

        }
        that.setData({
          imageList: res.tempFilePaths
        })
      }
    })
  },
  deleteImg: function (e) {
    console.log(e.currentTarget.dataset.index)
    this.data.imageList.splice(e.currentTarget.dataset.index, 1)
    this.setData({
      imageList: this.data.imageList
    })
  },




  // 提交
  submit(e) {
    let that = this;

    if (that.data.imageList == '') {
      wx.showToast({
        title: '请选择图片',
        icon: 'none'
      })
      return

    } else if (that.data.join_reason == '') {
      wx.showToast({
        title: '请输入汇报内容',
        icon: 'none'
      })
      return
  
    }


    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let params = {
      id: that.data.id,
      work_report: that.data.join_reason,
      work_pic: that.data.imageList
    }

    wx.showModal({
      title: '提示',
      content: '请仔细核对信息,确认无误!',
      confirmText: '确认提交',
      cancelText: '我再想想',
      success(res) {
        if (res.confirm) {
          let url = '/index/index/sginIn';
          app.post(url, params, head).then((res) => {
            wx.showToast({
              title: '提交成功',
              mask: true,
              icon: 'none',
              // duration: 2000
            })
            setTimeout(function () {
              wx.navigateBack({
                delta: 0,
              })
            }, 1000)
            console.log('用户点击确定')

          }).catch(() => {})

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },




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


  onReady: function () {

  },

  onShow: function () {
    let that = this
    that.get_info()

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})