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
// pages/realNameAuthentication/index.js
const $$ = require('../../utils/util');
 
// 实名认证
function realNameAuthenticationApi(submitData) {
  return $$.request({
    url: 'paUser/realAuth',
    type: 'post',
    submitData,
    service: 'cust'
  });
}
 
Page({
  /**
   * 页面的初始数据
   */
  backNum: 1, // 如果从完善资料进入则返回两级到个人中心
  data: {
    steps: ['完善信息', '刷脸认证'],
    submitData: {
      trueName: '',
      mobile: '',
      idcardType: '09_00015-1',
      idcardTypeName: '身份证',
      idcard: '',
      prov: '',
      provName: '',
      city: '',
      cityName: '',
      area: '',
      areaName: '',
      road: '',
      roadName: '',
      village: '',
      villageName: '',
      addr: '',
      agree: false,
    },
    popup: {}, // 下拉弹出框数据
  },
 
  // 展示弹出层
  handleShowPopup(e) {
    this.setData({
      popup: e.detail
    });
  },
 
  // 关闭弹出层
  handleClosePopup() {
    this.data.popup.visible = false;
    this.setData({
      popup: this.data.popup
    });
  },
 
  // 下拉框确认选择
  handleConfirmPicker({
    detail
  }) {
    let type = this.data.popup.type;
    let value = detail.detail.value;
    let arr = [];
    this.data.popup.visible = false;
    if (type === 'location') {
      arr = [
        ['prov', 'provName'],
        ['city', 'cityName'],
        ['area', 'areaName'],
        ['road', 'roadName'],
        ['village', 'villageName'],
      ];
      arr.forEach((x, t) => {
        this.data.submitData[x[0]] = value[t]?.value || '';
        this.data.submitData[x[1]] = value[t]?.label || '';
      });
    } else {
      if (type === 'cardType') {
        arr = ['idcardType', 'idcardTypeName'];
      } else if (type === 'sex') {
        arr = ['sex', 'sexName'];
      }
      arr.forEach((x, t) => {
        this.data.submitData[x] = value[t === 0 ? 'value' : 'label'];
      });
    }
    this.setData({
      popup: this.data.popup,
      submitData: this.data.submitData
    });
  },
 
  // form的change
  handleChange(e) {
    const {
      key,
      value
    } = e.detail;
    this.data.submitData[key] = value;
    this.setData({
      submitData: this.data.submitData
    });
  },
 
  // 修改picker的列时触发
  handleChangeColumns(e) {
    if (this.data.popup.type === 'location') {
      let selectData = $$.changeLocation(e, this.selectComponent('#personal-data-dom').location, this.data.popup.selectData);
      this.setData({
        popup: {
          ...this.data.popup,
          selectData
        }
      });
    }
  },
 
  // 进行刷脸认证
  handleRealName() {
    let submitData = this.data.submitData;
    let msg = '';
    if (!submitData.trueName) {
      msg = '请输入姓名';
    } else if (!submitData.idcard) {
      msg = '请输入证件号码';
    } else if (!$$.mobileRegExp(submitData.mobile)) {
      msg = '请输入正确的手机号码';
    } else if (!submitData.agree) {
      msg = '请勾选确认信息';
    }
    if (msg) {
      $$.showToast({
        title: msg
      });
      return false;
    }
    let that = this;
    wx.checkIsSupportFacialRecognition({
      success() {
        wx.startFacialRecognitionVerify({
          name: that.data.submitData.trueName,
          idCardNumber: that.data.submitData.idcard,
          success() {
            console.log('识别成功');
            that.realNameAuthentication();
          },
          fail() {
            $$.showToast({
              title: '抱歉!识别失败,请稍后重试'
            });
          },
        });
      },
      fail(res) {
        console.log(res);
        $$.showToast({
          title: '抱歉!请求失败,稍后重试'
        });
      },
    });
  },
 
  // 上传实名认证数据
  async realNameAuthentication() {
    $$.showLoading();
    const res = await realNameAuthenticationApi(this.data.submitData);
    $$.hideLoading();
    if (res.type) {
      this.getUserInfo()
      $$.showToast({
        icon: 'success',
        title: '实名认证成功'
      });
      wx.removeStorage({
        key: 'access_token'
      });
      await $$.sleep();
      wx.navigateBack({
        delta: this.backNum || 1,
      });
    }
  },
 
  // 获取个人信息
  async getUserInfo(e) {
    let data = e.detail || {};
    let keys = Object.keys(this.data.submitData);
    keys.forEach((x) => {
      if (data[x]) {
        this.data.submitData[x] = data[x];
      }
    });
    this.setData({
      submitData: this.data.submitData
    });
  },
 
  // 获取手机号码
  async handleGetPhoneNumber(e) {
    let phone = await this.selectComponent('#common-page').handleGetPhoneNumber(e.detail);
    this.data.submitData.mobile = phone;
    this.setData({
      submitData: this.data.submitData
    });
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.backNum) {
      this.backNum = 2;
    }
  },
});