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
// pages/perfectInformation/index.js
const $$ = require('../../utils/util');
 
// 保存信息
function setUserInfoApi(submitData) {
  return $$.request({
    url: 'paUser/perfectInfo',
    type: 'post',
    submitData,
    service: 'cust'
  });
}
 
Page({
  /**
   * 页面的初始数据
   */
  copySubmitData: {}, // 数据复制
  isCheck: false,
  data: {
    submitData: {
      trueName: '',
      mobile: '',
      sex: '09_00003-1',
      sexName: '男',
      idcardType: '09_00015-1',
      idcardTypeName: '身份证',
      idcard: '',
      city: '',
      cityName: '',
      area: '',
      areaName: '',
      road: '',
      roadName: '',
      village: '',
      villageName: '',
      addr: '',
    },
    popup: {}, // 下拉弹出框数据
    isCheck: false, // 是否只是查看
    isImproveData: false, // 是否是完善资料进入,则不显示身份证的修改
  },
 
  // 展示弹出层
  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 = [
        ['city', 'cityName'],
        ['area', 'areaName'],
        ['road', 'roadName'],
      ];
      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({
      submitData: this.data.submitData,
      popup: this.data.popup
    });
  },
 
  // 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
        }
      });
    }
  },
 
  // 验证
  checkSubmitData() {
    if (this.data.submitData.mobile && !$$.mobileRegExp(this.data.submitData.mobile)) {
      $$.showToast({
        title: '请输入正确的手机号码'
      });
      return false;
    }
    let userInfo = wx.getStorageSync('userInfo');
    let that = this;
    if (userInfo.realStatus === '1' && this.data.submitData.trueName !== this.copySubmitData.trueName) {
      $$.showModal({
        content: '您修改了姓名,修改后需重新实名认证,是否继续操作?',
        success: (res) => {
          if (res.confirm) {
            userInfo.realStatus = '99';
            wx.setStorageSync('userInfo', userInfo);
            that.handleSave();
          }
        },
      });
      return false;
    }
    if (userInfo.realStatus === '1' && this.data.submitData.idcard !== this.copySubmitData.idcard) {
      $$.showModal({
        content: '您修改了身份证号码,修改后需重新实名认证,是否继续操作?',
        success: (res) => {
          if (res.confirm) {
            userInfo.realStatus = '99';
            wx.setStorageSync('userInfo', userInfo);
            that.handleSave();
          }
        },
      });
      return false;
    }
    that.handleSave();
  },
 
  // 保存
  async handleSave() {
    $$.showLoading();
    const res = await setUserInfoApi(this.data.submitData);
    $$.hideLoading();
    if (res.type) {
      $$.showToast({
        title: '操作成功',
        icon: 'success'
      });
      await $$.sleep();
      wx.navigateBack({
        delta: 1,
      });
    }
  },
 
  // 获取个人信息
  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];
      }
    });
    if (this.isCheck && this.data.submitData.idcardType === '09_00015-1') {
      this.data.submitData.idcard = `${this.data.submitData.idcard?.substring(0, 6)}********${this.data.submitData.idcard?.substring(14)}`;
    }
    this.setData({
      submitData: this.data.submitData
    });
    this.copySubmitData = Object.assign({}, 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) {
    this.setData({
      isCheck: !!options.isCheck,
      isImproveData: !!options.type
    });
    this.isCheck = !!options.isCheck;
  },
});