approve.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view>
  3. <view class="app-bg">
  4. <image src="/static/img/tream_bg.png"></image>
  5. </view>
  6. <view class="app-h">
  7. <uni-nav-bar color="#fff" :border="false" statusBar backgroundColor="transparent" left-icon="left" @clickLeft="utils.navigateBack()" fixed title="实名认证"></uni-nav-bar>
  8. </view>
  9. <view class="app-body">
  10. <view class="input-view">
  11. <view class="form-item fx-r fx-bc">
  12. <view class="label">姓名</view>
  13. <view class="input">
  14. <input type="text" v-model="name" placeholder="请输入姓名" />
  15. </view>
  16. </view>
  17. <view class="form-item fx-r fx-bc">
  18. <view class="label">身份证号码</view>
  19. <view class="input">
  20. <input type="idcard" v-model="idcard" placeholder="请输入身份证号码" />
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view style="padding: 0px 40px;margin-top: 40px;">
  26. <view class="btn" @tap="formSubmit">实名认证</view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import {mapState,mapMutations} from 'vuex';
  32. // #ifdef APP
  33. const aliyunVerify = uni.requireNativePlugin('AP-FaceDetectModule');
  34. // #endif
  35. export default {
  36. computed: mapState(['user']),
  37. data() {
  38. return {
  39. name:"",
  40. idcard : ""
  41. }
  42. },
  43. onLoad(options) {
  44. // #ifdef H5
  45. try{
  46. var url = new URL(window.location.href);
  47. var dataUrl = url.searchParams.get('response');
  48. if(dataUrl != null){
  49. var dataAr = JSON.parse(decodeURIComponent(dataUrl));
  50. if(dataAr.code == 1000) {
  51. uni.redirectTo({ url:"approve_ok"});
  52. } else if(dataAr.code == 1003) {
  53. uni.redirectTo({ url:"approve_error?error=您取消实名认证"});
  54. } else {
  55. uni.redirectTo({ url:"approve_error?error=验证失败,理由:" + dataAr.reason });
  56. // uni.showModal({title: '系统提示',content: "",showCancel: false});
  57. }
  58. }
  59. }catch(ex){
  60. console.log(ex);
  61. }
  62. // #endif
  63. },
  64. methods: {
  65. formSubmit:function(e){
  66. if(!this.utils.isDefine(this.name)){
  67. this.utils.Tip("输入正确的姓名");
  68. return;
  69. }
  70. if(!this.utils.isDefine(this.idcard)){
  71. this.utils.Tip("请输入身份证号码");
  72. return;
  73. }
  74. var regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  75. if(!regIdNo.test(this.idcard)){
  76. this.utils.Tip("请输入正确身份证号码");
  77. return;
  78. }
  79. let post = {name : this.name,idcard : this.idcard};
  80. // #ifdef H5
  81. post.metaInfo = JSON.stringify(window.getMetaInfo());
  82. post.url = window.location.href;
  83. // #endif
  84. // #ifdef APP
  85. post.metaInfo = aliyunVerify.getMetaInfo();
  86. let p = uni.getSystemInfoSync().platform;
  87. if (p === "ios") {
  88. post.metaInfo = JSON.stringify(post.metaInfo);
  89. }
  90. post.url = "";
  91. // #endif
  92. this.utils.loadIng("提交中..")
  93. this
  94. .request
  95. .post("setUserCert",post)
  96. .then(res => {
  97. uni.hideLoading();
  98. if(res.code == 200) {
  99. // #ifdef APP
  100. aliyunVerify.verify({
  101. "certifyId":res.data.id,
  102. },
  103. function(response){
  104. if(response.code == 1000) {
  105. uni.redirectTo({
  106. url:"approve_ok"
  107. });
  108. return;
  109. }
  110. if (res.code == 1001) {
  111. this.utils.showAlert({content:"验证失败,系统错误请重启APP重新验证"});
  112. return;
  113. }
  114. if (res.code == 1003) {
  115. return;
  116. }
  117. if (res.code == 2002) {
  118. this.utils.showAlert({content:"网络错误请检查是否开启网络连接"});
  119. return;
  120. }
  121. if (res.code == 2003) {
  122. this.utils.showAlert({content:"设备时间错误,请校验时候后重试"});
  123. return;
  124. }
  125. if (res.code == 2003) {
  126. this.utils.showAlert({content:"刷脸失败"});
  127. return;
  128. }
  129. //
  130. this.utils.showAlert({content:"验证失败,可能你当前手机环境存在异常!请更换在尝试。"});
  131. }
  132. );
  133. // #endif
  134. // #ifdef H5
  135. location.href = res.data.url;
  136. // #endif
  137. } else {
  138. uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
  139. }
  140. })
  141. .catch(res => {
  142. uni.hideLoading();
  143. that.utils.showModal("加载失败,重新点击尝试!");
  144. });
  145. }
  146. },
  147. }
  148. </script>
  149. <style lang="scss">
  150. .app-bg{
  151. position: absolute;
  152. image{width: 100vw;height: 45vw;}
  153. }
  154. .app-h{
  155. height: 45vw;
  156. }
  157. .app-body{
  158. .input-view{
  159. box-shadow: 0 2px 16px 1px rgba(89, 89, 89, .24) !important;
  160. background-color: #fff !important;
  161. margin-top: -80px !important;
  162. border-radius: 5px !important;
  163. padding: 0 15px;
  164. position: relative;
  165. z-index: 99;
  166. width: calc(100% - 40px - 30px);
  167. margin-left: 20px;
  168. .form-item{
  169. padding: 10px 0;
  170. font-size: 14px;
  171. color: #303133;
  172. line-height: 36px;
  173. .label{
  174. width: 100px;
  175. }
  176. .input{width: calc(100% - 100px);}
  177. }
  178. }
  179. }
  180. .btn{
  181. background: #DB292B;
  182. border-radius: 60rpx;
  183. text-align: center;
  184. font-weight: bold;
  185. font-size: 28rpx;
  186. padding: 30rpx 0;
  187. color: #FAFAFA;
  188. }
  189. </style>