forked from nsjcy/frontEnd/nsjcy

liuwh
2020-03-10 800ffe29f328c84d4de46e8867ad3ca5cbae0d4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// 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) {
    console.log(e)
    var taskReport = e.detail.value;
    this.setData({
      taskReport
    })
  },
 
  //添加图片
  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,
          })
        }
      }
    })
 
   
  },
})