real-name-certification.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!-- 实名认证 -->
  2. <template>
  3. <view class="wrap">
  4. <view class="label">请上传身份证正反面</view>
  5. <view class="module-wrap">
  6. <view class="module">
  7. <view class="left-sidebar">
  8. <text>头像面</text>
  9. <text>上传您的身份证头像面</text>
  10. </view>
  11. <view class="right-sidebar" @tap="uploadImg('card_front')">
  12. <image v-if="params.card_front.length === 0" src="../../../static/add-2.png" class="add-img" mode=""></image>
  13. <image v-else :src="params.card_front" mode="" class="add-img"></image>
  14. </view>
  15. </view>
  16. <view class="module">
  17. <view class="left-sidebar">
  18. <text>国徽面</text>
  19. <text>上传您的身份证国徽面</text>
  20. </view>
  21. <view class="right-sidebar" @tap="uploadImg('card_back')">
  22. <image v-if="params.card_back.length === 0" src="../../../static/add-1.png" class="add-img" mode=""></image>
  23. <image v-else :src="params.card_back" mode="" class="add-img"></image>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="label">请完善您的个人信息</view>
  28. <view class="column">
  29. <view class="row">
  30. <text class="row-name">真实姓名</text>
  31. <input type="text" v-model="params.true_name" class="input" placeholder="请输入姓名" placeholder-class="placeholder" />
  32. </view>
  33. <view class="row">
  34. <text class="row-name">身份证号</text>
  35. <input type="text" v-model="params.id_card" class="input" placeholder="请输入身份证号" placeholder-class="placeholder" />
  36. </view>
  37. </view>
  38. <view class="btn-box">
  39. <button v-if="info.is_auth == 1" type="default" class="active" disabled>已认证</button>
  40. <button v-else type="default" class="active" @tap="userCertification()">认证</button>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import { uploadFiles } from '../../../common/request';
  46. import { validatorFun } from '../../../common/utils/util';
  47. import { userCenterUserCertification } from '../../../common/service.js';
  48. export default {
  49. data() {
  50. return {
  51. info: {},
  52. params: {
  53. card_front: '',
  54. card_back: '',
  55. true_name: '',
  56. id_card: '',
  57. },
  58. }
  59. },
  60. onLoad() {
  61. this.info = uni.getStorageSync('USER_INFO') || {};
  62. this.params.card_front = this.info.card_front || '';
  63. this.params.card_back = this.info.card_back || '';
  64. this.params.true_name = this.info.true_name || '';
  65. this.params.id_card = this.info.id_card || '';
  66. this.info.showPhone = this.info.phone.split('').map((n, i) => i > 2 && i < 7 ? '*' : n).join('');
  67. },
  68. methods: {
  69. userCertification() {
  70. const params = this.params;
  71. const errList = validatorFun(params, [
  72. ['card_front', ['notNull', '请上传您的身份证头像面']],
  73. ['card_back', ['notNull', '请上传您的身份证国徽面']],
  74. ['true_name', ['notNull', '请输入姓名']],
  75. ['id_card', ['notNull', '请输入身份证号']],
  76. ]);
  77. if (errList.length > 0) {
  78. return uni.showToast({
  79. icon: 'none',
  80. title: errList[0].errMsg,
  81. });
  82. }
  83. userCenterUserCertification({
  84. data: params,
  85. success: ({code, msg, data}) => {
  86. if (code == 1) {
  87. this.info.phone = params.phone;
  88. uni.setStorageSync('USER_INFO', info);
  89. this.params = {
  90. phone: '',
  91. code: '',
  92. };
  93. uni.showModal({
  94. title: '提示',
  95. content: '修改成功,请重新登录',
  96. showCancel: false,
  97. success: (res) => {
  98. if (res.confirm) {
  99. uni.removeStorageSync('session_key');
  100. uni.removeStorageSync('USER_INFO');
  101. uni.reLaunch({
  102. url: '/pages/index/index',
  103. });
  104. }
  105. }
  106. });
  107. } else {
  108. uni.showToast({
  109. icon: 'none',
  110. title: msg,
  111. });
  112. }
  113. },
  114. });
  115. },
  116. //上传图片
  117. uploadImg(key){
  118. uni.chooseImage({
  119. count: 1,
  120. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  121. sourceType: ['album', 'camera'],
  122. success: res => {
  123. uploadFiles({
  124. filePath: res.tempFilePaths[0],
  125. success: res => {
  126. const data = JSON.parse(res.data);
  127. console.log(data);
  128. if (res.statusCode === 200 && data.code == 1) {
  129. this.params[key]= data.data;
  130. } else {
  131. uni.showToast({
  132. icon: 'none',
  133. title: data.msg || res.msg,
  134. });
  135. }
  136. }
  137. });
  138. },
  139. });
  140. },
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. @import "./real-name-certification.css";
  146. </style>