forked from nsjcy/frontEnd/nsjcy

LAPTOP-RI7D261L\Mr Ke
2020-03-09 a2d1b9886b00b5f4d4722c3379d3bd4f2f94b421
SunshineLnsMinApp/pages/zhghInfo/zhghInfo.js
@@ -1,26 +1,177 @@
// pages/zhghInfo/zhghInfo.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    data: {},
    add: app.globalData.imgUrl + '/image/add.svg',
    del: app.globalData.imgUrl + '/image/del.svg',
    evalList: {},
    id: "",
    status: 4,
    disabled: false,
    taskReport: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options.id)
    wx.showLoading();
    wx.request({
      url: app.globalData.url + '/api/social/find/' + options.id,
      success: function (res) {
        wx.hideLoading();
        console.log('res', res);
        if (res.data.code == 0) {
          var dataSet = res.data.data;
          var evalList1000 = dataSet.attachments || [];
          console.log('37', evalList1000)
          var evalList = {
            evalList1000,
          };
          for (var i in evalList) {
            evalList[i] = evalList[i].map(({
              imgPath: pic,
              attachmentId: id
            }) => ({
              pic,
              id
            }))
          }
          console.log('48', evalList)
          that.setData({
            data: {
              ...res.data.data,
              createTime: app.formatDate(res.data.data.createTime),
              startTime: app.formatDate(res.data.data.startTime),
              endTime: app.formatDate(res.data.data.endTime),
              status: res.data.data.status == 0 ? '未开始' : res.data.data.status == 1 ? '进行中' : res.data.data.status == 2 ? '已结束' : res.data.data.status == 99 ? '结束' : '(未知)'
            },
            id: res.data.data.id,
            evalList,
            taskReport: res.data.data.taskReport || ''
          })
        } else {
          wx.showToast({
            title: res.data.msg,
          })
        }
      }
    })
  },
  //输入框
  inputChange: function (e) {
    var taskReport = e.currentTarget.dataset.name;
    this.setData({
      taskReport
    })
  },
  // 跳转
  linkFunction: function () {
    wx.showToast({
      title: '提交成功',
      icon: 'success',
      duration: 2000
  //添加图片
  joinPicture: function (e) {
    console.log(e)
    var that = this;
    console.log(that)
    app.joinPicture(e, that, e.currentTarget.dataset.associatetypeid, that.data.id);
  },
  // 删除图片
  clearImg: function (e) {
    var that = this;
    app.clearImg(e, that);
  },
  //预览图片
  previewImage: function (e) {
    app.previewImage(e);
  },
  onPreview(e) {
    console.log('onPreview', e)
    const {
      file,
      fileList
    } = e.detail
    wx.previewImage({
      current: file.url,
      urls: fileList.map((n) => n.url),
    })
  },
  onRemove(e) {
    const {
      file,
      fileList
    } = e.detail;
    let that = this;
    var id = e.currentTarget.dataset['id'];
    console.log(id);
    let {
      supplyAttachmentList
    } = that.data.item;
    wx.showModal({
      content: '确定删除?',
      success: (res) => {
        if (res.confirm) {
          wx.showLoading();
          wx.request({
            url: app.globalData.url + '/api/v1/attachment/deleteByOwnerAtt',
            method: 'GET',
            data: {
              attId: file.id,
              owenId: id
            },
            success: function (res) {
              console.log('res', res);
              that.data.item.supplyAttachmentList = supplyAttachmentList.filter((n) => n.uid !== file.uid)
              that.setData({
                item: that.data.item
              })
              wx.hideLoading();
            }
          })
        }
      },
    })
  },
  // 提交
  linkFunction: function () {
    var that = this;
    wx.showLoading();
    wx.request({
      url: app.globalData.url + '/api/social/submitTask',
      method: 'GET',
      data: {
        taskId: that.data.id,
        userId: wx.getStorageSync('id'),
        taskReport:that.data.taskReport
      },
      success: function (res) {
        wx.hideLoading();
        console.log('res', res);
        if (res.data.code == 0) {
          wx.showToast({
            title: '提交成功',
            icon: 'success',
            duration: 2000
          })
          wx.navigateBack({
            delta: 1
          })
        } else {
          wx.showToast({
            title: res.data.msg,
          })
        }
      }
    })
  },
})