xusd
7 days ago 998218675eb243d43912c203174a6b72b299c0f8
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// pages/addPerson/index.js
const $$ = require('../../utils/util');
const app = getApp();
import Toast from '../../components/vant/toast/toast';
Page({
 
  /**
   * 页面的初始数据
   */
  select: {}, // 下拉框数据
  data: {
    imgUrl: $$.url.img,
    popup: {
      formtype: '',
      index: 0,
    },
    personTypes: [{
      title: '自然人',
      imgUrl: $$.url.img + 'person-types_1.png',
      imgUrlActive: $$.url.img + 'person-types_1_active.png',
    }, {
      title: '法人',
      imgUrl: $$.url.img + 'person-types_2.png',
      imgUrlActive: $$.url.img + 'person-types_2_active.png',
    }, {
      title: '非法人组织',
      imgUrl: $$.url.img + 'person-types_3.png',
      imgUrlActive: $$.url.img + 'person-types_3_active.png',
    }],
    personTypesActive: 0, // 人员类型切换
    perType: '',
    formData: {
      trueName: '',
      mobile: '',
      certiType: '09_00015-1',
      certiTypeName: '身份证',
      certiNo: '',
      addr: '',
      placeAddr: '',
      workUnit: '',
      nation: '',
      nationName: '',
      sex: '09_00003-1',
      sexName: '男',
    }, //表单存储对象
    frData: {},
    ffrData: {}
  },
 
  // 保存
  handleNext(e) {
    let personTypesActive = this.data.personTypesActive;
    let data = {
      ...this.data.formData,
      perType: this.data.perType,
      agentCode: this.data.radio,
      perTypeName: this.data.perTypeName,
      perClass: personTypesActive === 0 ? '09_01001-1' : personTypesActive === 1 ? '09_01001-2' : personTypesActive === 2 ? '09_01001-3' : "",
      perClassName: personTypesActive === 0 ? '自然人' : personTypesActive === 1 ? '法人' : personTypesActive === 2 ? '非法人组织' : "",
    }
    // 获取当前页面栈
    var pages = getCurrentPages();
 
    // 上一个页面
    var prevPage = pages[pages.length - 2];
    // 直接设置数据对象到上一页面的data中
    prevPage.setData({
      oneData: data,
      editIndex: this.data.editIndex || false,
    });
 
    wx.navigateBack({
      delta: 1,
    })
 
  },
 
  // 选择法人或非法人组织
  selectUnit(e) {
    let type = e.currentTarget.dataset.type;
    // 法人信息  非法人组织
    if (type === 'person' || type === 'units') {
      wx.navigateTo({
        url: '../../pages/addUnit/index?type=' + type,
      });
    }
  },
 
  // 获取手机号码
  async _handleGetPhoneNumber(e) {
    let that = this;
    let phone = await that.selectComponent('#common-page').handleGetPhoneNumber(e.detail.code);
    that.data.formData.mobile = phone;
    that.setData({
      formData: that.data.formData
    });
  },
 
  // 身份证ocr
  handleOCR(e) {
    let that = this;
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      success(res2) {
        const tempFiles = res2.tempFiles[0];
        $$.showLoading();
        wx.uploadFile({
          url: `${$$.baseUrl}${$$.url.sys}/api/wechat/fileInfo/wecatRecognition`,
          filePath: tempFiles.tempFilePath,
          name: 'file',
          header: {
            Authorization: app.globalData.token
          },
          complete(res3) {
            $$.hideLoading();
            if (res3.errMsg === 'uploadFile:ok') {
              let {
                code,
                data
              } = JSON.parse(res3.data);
              if (code == -1) {
                $$.errorModal({
                  content: '识别失败'
                });
                return;
              }
              that.data.formData.certiNo = data?.ocrResult.certiNo;
              that.data.formData.certiType = data?.ocrResult.certiType;
              that.data.formData.certiTypeName = data?.ocrResult.certiTypeName;
              that.data.formData.trueName = data?.ocrResult.trueName;
              that.data.formData.placeAddr = data?.ocrResult.placeAddr;
              that.data.formData.sex = data?.ocrResult.sex;
              that.data.formData.sexName = data?.ocrResult.sexName;
              that.data.formData.nation = data?.ocrResult.nation;
              that.data.formData.nationName = data?.ocrResult.nationName;
              that.setData({
                formData: that.data.formData
              });
            }
          },
        });
      },
    });
  },
 
  // 表单修改
  handleChange(e) {
    let key = e.currentTarget.dataset.key,
      value = e.detail;
    if (key === 'sex') {
      this.data.formData[key] = value;
      this.data.formData[key + 'Name'] = value === '09_00003-2' ? '女' : value === '09_00003-1' ? '男' : '';
    } else {
      this.data.formData[key] = value;
    }
    this.setData({
      formData: this.data.formData
    });
  },
 
 
  // 人员类型切换
  _handleSelectData(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      personTypesActive: index
    })
    if (index === 1) {
      this.setData({
        ffrData: {},
        formData: {
          trueName: '',
          mobile: '',
          certiType: '09_00015-1',
          certiTypeName: '身份证',
          certiNo: '',
          addr: '',
          placeAddr: '',
          workUnit: '',
          nation: '',
          nationName: '',
          sex: '09_00003-1',
          sexName: '男',
        }
      })
    }
    if (index === 2) {
      this.setData({
        frData: {},
        formData: {
          trueName: '',
          mobile: '',
          certiType: '09_00015-1',
          certiTypeName: '身份证',
          certiNo: '',
          addr: '',
          placeAddr: '',
          workUnit: '',
          nation: '',
          nationName: '',
          sex: '09_00003-1',
          sexName: '男',
        }
      })
    }
  },
 
  // 下拉框选择开启
  handleShowPopup(e) {
    let type = e.currentTarget.dataset.type;
    let selectData = [];
    let selectOption = this.select[type];
    selectData = [{
      values: selectOption,
      defaultIndex: 0
    }];
    this.setData({
      popup: {
        formtype: e.currentTarget.dataset.key,
        index: e.currentTarget.dataset.index,
        visible: true,
        title: e.currentTarget.dataset.title,
        type: type,
        selectData: selectData,
      },
    });
  },
 
  // 关闭下拉框选择
  handleClosePopup() {
    this.data.popup.visible = false;
    this.setData({
      popup: this.data.popup
    });
  },
 
  // 下拉框选择确认
  handleConfirmPicker({
    detail
  }) {
    let formtype = this.data.popup.formtype;
    let value = detail.detail.value,
      arr = [];
    this.data.popup.visible = false;
    this.data.formData[formtype] = value[0].value;
    this.data.formData[formtype + 'Name'] = value[0].label;
    this.setData({
      popup: this.data.popup,
      formData: this.data.formData
    });
  },
 
  // 请求下拉框资源
  async getSelectOptionData() {
    const res = await $$.commonRequest({
      url: `${$$.url.assets}selectOption.json`,
      type: 'get'
    });
    if (res) {
      this.select.cardType = res.data.cardType || [];
      this.select.nation = res.data.nation || [];
    }
  },
 
 
  onChange(event) {
    console.log('event.detail', event.detail);
    this.setData({
      radio: event.detail,
    });
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let {
      perType,
      perTypeName,
      data,
      index,
      objs,
    } = options;
    let selectList = JSON.parse(objs)
    console.log('selectList', selectList);
    if (data) {
      data = JSON.parse(data);
      wx.setNavigationBarTitle({
        title: "修改" + data.perTypeName
      })
      this.setData({
        selectList,
        editIndex: index,
        radio: data.agentCode,
        formData: data,
        perType: data.perType,
        perTypeName: data.perTypeName,
        personTypesActive: data.perClass === '09_01001-1' ? 0 : data.perClass === '09_01001-2' ? 1 : data.perClass === '09_01001-3' ? 2 : 0,
      })
    } else {
      wx.setNavigationBarTitle({
        title: "添加" + perTypeName
      })
      this.setData({
        selectList,
        radio: selectList[0]?.agentCode,
        perType,
        perTypeName
      })
    }
    this.getSelectOptionData();
  },
 
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
})