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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// pages/xsjb/xsjb.js
import {
  $wuxForm
} from '../../templeteDist/wuxDist/index';
var app = getApp();
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    add: app.globalData.imgUrl + '/image/add.svg',
    del: app.globalData.imgUrl + '/image/del.svg',
    meetingWayList: [{
      value: '1',
      title: '违反犯罪暴力'
    }, {
      value: '2',
      title: '未违反犯罪暴力'
    }],
    meetingWayList1: [{
      value: '1',
      title: '匿名'
    }, {
      value: '2',
      title: '实名'
    }],
    uploadUrl: app.globalData.url + '/api/v1/attachment/materials',
    displaytipoffAction: '请选择',
    displaytipoffType: '请选择',
    thisData: {},
    evalList: {},
    disabled: true,
    showInfo: false,
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const id = options.id || 'new';
    let that = this;
    var userinfo = wx.getStorageSync("user");
    wx.showLoading();
    wx.request({
      url: app.globalData.url + '/api/tipoff/find',
      method: 'GET',
      data: {
        id,
      },
      success: function (res) {
        console.log('res', res);
        var dataSet = res.data;
        var evalList1000 = dataSet.attachments || [];
        var evalList = {
          evalList1000,
        };
        for (var i in evalList) {
          evalList[i] = evalList[i].map(({
            imgPath: pic,
            attachmentId: id
          }) => ({
            pic,
            id
          }))
        }
        const data = res.data || {}
        if (options.id) {
          that.setData({
            thisData: {
              ...data,
              createId: userinfo.id,
              businessType: 1
            },
            evalList,
            disabled: false,
            displaytipoffAction: data.tipoffAction == 1 ? '违反犯罪暴力' : data.tipoffAction == 2 ? '未违反犯罪暴力' : '请选择',
            displaytipoffType: data.tipoffType == 1 ? '匿名' : data.tipoffType == 2 ? '实名' : '请选择',
            showInfo: data.tipoffType == 2 ? true : false,
          })
        } else {
          that.setData({
            thisData: {
              ...data,
              createId: userinfo.id,
              businessType: 1
            },
            evalList,
          })
        }
        wx.hideLoading();
      }
    })
  },
 
  formSubmit(e) {
    console.log('Default Form Submit \n', e.detail.value)
  },
 
  inputOnchange(e) {
    const key = e.currentTarget.dataset.key;
    console.log(key)
    console.log(e)
    this.setData({
      thisData: {
        ...this.data.thisData,
        [key]: e.detail.value
      }
    })
  },
 
  onSubmit() {
    console.log(this.data.thisData)
    if(!this.data.thisData.tipoffObject){
      return app.showModal("请填写举报对象!");
    }
    if(!this.data.thisData.tipoffAction){
      return app.showModal("请选择举报行为!");
    }
    if(!this.data.thisData.tipoffAddress){
      return app.showModal("请填写发生地!");
    }
    if(!this.data.thisData.tipoffContent){
      return app.showModal("请填写具体事项!");
    }
    if(!this.data.evalList){
      return app.showModal("请上传证明材料!");
    }
    if(!this.data.thisData.tipoffType){
      return app.showModal("请选择方式!");
    }
    if(this.data.thisData.tipoffType=='2'){
      if(!this.data.thisData.createrName){
        return app.showModal("请填写姓名!");
      }
      if(!this.data.thisData.createrMobile){
        return app.showModal("请填写手机号码!");
      }
      if(!this.data.thisData.createrAddress){
        return app.showModal("请填写联系方式!");
      }
    }
    wx.request({
      url: app.globalData.url + '/api/tipoff/save',
      data: this.data.thisData,
      method: 'POST',
      header: {
        "Content-Type": "application/json"
      },
      success: function (res) {
        if (res.data.code == 0) {
          wx.showToast({
            title: '提交成功!',
            icon: 'success',
            duration: 2000
          })
          wx.navigateTo({
            url: '../zhwj/zhwj',
          })
        }
      }
    })
  },
 
  // 选择地理位置
  chooseLocation: function (e) {
    const that = this;
    wx.chooseLocation({
      success: function (res) {
        console.log('res', res);
        that.setData({
          thisData: {
            ...that.data.thisData,
            tipoffAddress: res.address
          }
        })
      }
    })
  },
 
  //添加图片
  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);
  },
 
 
  onPopupSelectChange(e) {
    let _this = this;
    var key = e.currentTarget.dataset['key'];
    console.log('key', key, e);
    if (key == 'tipoffType' && e.detail.value == '2') {
      this.setData({
        [key]: e.detail.value,
        [`display${key}`]: e.detail.label,
        showInfo:true,
        thisData: {
          ...this.data.thisData,
          [key]: e.detail.value,
        }
      });
    }else{
      this.setData({
        [key]: e.detail.value,
        [`display${key}`]: e.detail.label,
        thisData: {
          ...this.data.thisData,
          [key]: e.detail.value,
        }
      });
    }
 
  }
})