//index.js
//获取应用实例
const app = getApp()

Page({
  onShow() {
    wx.setNavigationBarTitle({
      title: '添加评论'
    })
  },
  data: {
    UserInfo: app.globalData.UserInfo,
    SubmitOff: true,
    FormData: {
      Comment: '',
      ImgList: []
    }
  },
  AddImage() { // 添加图片
    let _self = this
    wx.chooseImage({
      count: 4 - _self.data.FormData.ImgList.length,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        let aArr = _self.data.FormData.ImgList.slice(0)
        res.tempFilePaths.map((item) => {
          aArr.push(item)
        })
        _self.setData({
          FormData: {
            ..._self.data.FormData,
            ImgList: aArr
          }
        })
      }
    })
  },
  FormInput(e) { // 输入form数据
    this.setData({
      FormData: {
        ...this.data.FormData,
        [e.target.dataset.name]: e.detail.value
      }
    })
  },
  DeleteItem(e) { // 删除img
    let aArr = this.data.FormData.ImgList.slice(0)
    aArr.splice(e.target.dataset.index, 1)
    this.setData({
      FormData: {
        ...this.data.FormData,
        ImgList: aArr
      }
    })
  },
  SubmitForm() { // 发布
    if (this.data.SubmitOff) {
      this.setData({
        SubmitOff: false
      })
    }
  }
})