index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <view class="content">
  3. <!-- <view class="bgimg">
  4. <image class="img" src="https://zhibo.liuniu946.com/img/bgRz.png" mode="widthFix"></image>
  5. </view> -->
  6. <view class='list userBox' v-if="!upDataLoding">
  7. <view class='item acea-row row-between-wrapper'>
  8. <view class="title">姓名</view>
  9. <view class='input'>
  10. <input class="inputText" type='text' name='name' v-model='form.name' maxlength="16"></input>
  11. </view>
  12. </view>
  13. <view class='item acea-row row-between-wrapper'>
  14. <view class="title">身份证</view>
  15. <view class='input acea-row row-between-wrapper'>
  16. <input class="inputText" type='text' name='card' v-model='form.card'></input>
  17. </view>
  18. </view>
  19. </view>
  20. <button v-if="!upDataLoding" class="add-btn" @click="pushData('add')">提交</button>
  21. <view v-else class="titleType">
  22. <text v-if="renus">
  23. 已通过实名认证
  24. </text>
  25. <text v-else>
  26. 已提交资料请等待审核结果
  27. </text>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. realName,
  34. checkUser,
  35. rate
  36. } from '@/api/user.js';
  37. // #ifdef APP
  38. const aliyunVerify = uni.requireNativePlugin('AP-FaceDetectModule');
  39. // #endif
  40. import {
  41. HTTP_REQUEST_URL
  42. } from '@/config/app.js';
  43. export default {
  44. data() {
  45. return {
  46. loding: false, //判断是否在点击中
  47. form: {
  48. name: '',
  49. card: '',
  50. // img: ''
  51. },
  52. upFileLoding: false, //防止上传图片时多次重复点击
  53. upDataLoding: false, //判断是否上传过数据
  54. renus: false, //判断是否已经通过实名认证
  55. };
  56. },
  57. onLoad(option) {
  58. this.init();
  59. },
  60. methods: {
  61. init() {
  62. const that = this;
  63. uni.showLoading({
  64. title: '数据获取中',
  65. mask: true
  66. });
  67. // 获取数据判断是否已经验证过
  68. rate({})
  69. .then(e => {
  70. // 如果已经提交数据跳转验证页
  71. if (e.data.is_auth == 1) {
  72. that.upDataLoding = true;
  73. console.log(1);
  74. that.getYz();
  75. } else {
  76. uni.hideLoading()
  77. }
  78. if (e.data.is_auth == 2) {
  79. that.upDataLoding = true;
  80. that.renus = true;
  81. that.$util.Tips({
  82. title: `已通过实名认证`
  83. });
  84. }
  85. if (e.data.is_auth == 3) {
  86. that.$api.msg(e.data.off);
  87. }
  88. })
  89. .catch(e => {
  90. uni.hideLoading()
  91. });
  92. },
  93. // 获取验证
  94. getYz() {
  95. const that = this;
  96. // #ifdef H5
  97. let metaInfo = JSON.stringify(window.getMetaInfo());
  98. let router = getApp().$router;
  99. // #endif
  100. // #ifdef APP
  101. console.log(aliyunVerify,'aliyunVerify');
  102. let metaInfo = aliyunVerify.getMetaInfo();
  103. let p = uni.getSystemInfoSync().platform;
  104. if (p === "ios") {
  105. metaInfo = JSON.stringify(metaInfo);
  106. }
  107. // #endif
  108. checkUser({
  109. metaInfo: metaInfo,
  110. // #ifdef H5
  111. url: HTTP_REQUEST_URL+'/pages/user/approve'
  112. // #endif
  113. }).then(({
  114. data
  115. }) => {
  116. uni.hideLoading()
  117. // #ifdef H5
  118. window.location.href = data.url + ""
  119. // #endif
  120. // #ifdef APP
  121. that.aliyunVerify(data.id)
  122. // #endif
  123. console.log(data, 'data');
  124. }).catch((err) => {
  125. uni.hideLoading()
  126. })
  127. },
  128. // #ifdef APP
  129. // 调用刷脸认证
  130. aliyunVerify(id) {
  131. const that = this;
  132. aliyunVerify.verify({
  133. "certifyId": id, // 填写从服务端获取的certifyId
  134. },
  135. function(res) {
  136. if (res.code == 1000) {
  137. uni.showLoading({
  138. title: '刷脸成功,等待通过',
  139. mask: true
  140. });
  141. setTimeout(() => {
  142. that.init();
  143. }, 3000)
  144. } else {
  145. if (res.code == 1001) {
  146. uni.showModal({
  147. title: '提示',
  148. content: '系统错误请重启APP重新验证',
  149. showCancel: false,
  150. });
  151. }
  152. if (res.code == 1003) {
  153. uni.showModal({
  154. title: '提示',
  155. content: '验证取消是否重新验证?',
  156. success: re => {
  157. if (re.confirm) {
  158. that.aliyunVerify(id)
  159. }
  160. },
  161. });
  162. }
  163. if (res.code == 2002) {
  164. uni.showModal({
  165. title: '提示',
  166. content: '网络错误请检查是否开启网络连接',
  167. showCancel: false,
  168. });
  169. }
  170. if (res.code == 2003) {
  171. uni.showModal({
  172. title: '提示',
  173. content: '设备时间错误,请校验时候后重试',
  174. showCancel: false,
  175. });
  176. }
  177. if (res.code == 2006) {
  178. uni.showModal({
  179. title: '提示',
  180. content: '刷脸失败,是否重试?',
  181. success: re => {
  182. if (re.confirm) {
  183. that.aliyunVerify(id)
  184. }
  185. },
  186. });
  187. }
  188. }
  189. }
  190. );
  191. },
  192. // #endif
  193. upImg(e) {
  194. const that = this;
  195. if (that.upFileLoding) {
  196. return
  197. }
  198. that.upFileLoding = true;
  199. setTimeout(() => {
  200. that.upFileLoding = false;
  201. }, 1000);
  202. upload({
  203. filename: ''
  204. }).then(data => {
  205. this.form.img = data[0].url;
  206. }).catch((err) => {
  207. console.log(err);
  208. })
  209. },
  210. ToIndex() {
  211. let obj = this;
  212. let ur = uni.getStorageSync('present') || '/pages/index/index';
  213. // 用于处理缓存bug
  214. if (ur == 'pages/product/product') {
  215. ur = '/pages/index/index';
  216. }
  217. uni.switchTab({
  218. url: ur,
  219. fail(e) {
  220. uni.navigateTo({
  221. url: ur,
  222. fail(e) {
  223. uni.navigateTo({
  224. url: '/pages/index/index'
  225. });
  226. }
  227. });
  228. }
  229. });
  230. },
  231. pushData() {
  232. const that = this;
  233. const da = that.form;
  234. // 判断是否已经提交过数据
  235. if (that.upDataLoding) {
  236. that.init();
  237. return
  238. }
  239. if (that.loding) {
  240. return;
  241. }
  242. if (!da.name) {
  243. uni.showModal({
  244. title: '提示',
  245. content: '请填写真实姓名',
  246. showCancel: false
  247. });
  248. return;
  249. }
  250. if (!da.card) {
  251. uni.showModal({
  252. title: '提示',
  253. content: '请填写身份证',
  254. showCancel: false
  255. });
  256. return;
  257. }
  258. // if (!da.img) {
  259. // uni.showModal({
  260. // title: '提示',
  261. // content: '请选择图片',
  262. // showCancel: false
  263. // });
  264. // return;
  265. // }
  266. const data = {
  267. // cidimg: da.img,
  268. rname: da.name,
  269. cid: da.card
  270. };
  271. uni.showLoading({
  272. title: '审核中',
  273. mask: true
  274. });
  275. that.loding = true;
  276. // 上传
  277. realName(data)
  278. .then(e => {
  279. // 判断是否已经上传过数据
  280. that.upDataLoding = true;
  281. that.getYz();
  282. that.loding = false;
  283. console.log(e);
  284. })
  285. .catch(e => {
  286. that.loding = false;
  287. console.log(e);
  288. uni.hideLoading();
  289. });
  290. }
  291. }
  292. };
  293. </script>
  294. <style lang="scss" scoped>
  295. .content {
  296. height: 100%;
  297. padding: 0 30rpx;
  298. }
  299. .list {
  300. border-radius: 20rpx;
  301. overflow: hidden;
  302. .item:nth-child(1) {
  303. border-bottom: 1px solid #e4e7ed;
  304. }
  305. .item {
  306. padding: 30rpx 0;
  307. }
  308. .input {
  309. text-align: right;
  310. flex-grow: 1;
  311. }
  312. }
  313. .add-btn {
  314. display: flex;
  315. align-items: center;
  316. justify-content: center;
  317. width: 690rpx;
  318. height: 80rpx;
  319. margin: 60rpx auto;
  320. font-size: 32rpx;
  321. color: #fff;
  322. background: #ff0000;
  323. border-radius: 10rpx;
  324. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  325. }
  326. .bgimg {
  327. text-align: center;
  328. width: 1200rpx;
  329. margin-left: -260rpx;
  330. height: 400rpx;
  331. background: #ff0000;
  332. border-bottom-right-radius: 999999rpx;
  333. border-bottom-left-radius: 999999rpx;
  334. .img {
  335. width: 400rpx;
  336. margin-top: 50rpx;
  337. }
  338. }
  339. .titleType {
  340. margin-top: -250rpx !important;
  341. text-align: center;
  342. color: #FFF;
  343. font-size: 32rpx;
  344. text-shadow: 4rpx 4rpx 6rpx #666;
  345. letter-spacing: 0.5em;
  346. font-weight: bold;
  347. }
  348. .userBox {
  349. box-shadow: 0px 2px 16px 1px rgba(89, 89, 89, 0.24) !important;
  350. background-color: white !important;
  351. margin-top: 30rpx;
  352. padding: 0 30rpx;
  353. .inputText {
  354. width: 100%;
  355. }
  356. .title {
  357. width: 150rpx;
  358. }
  359. }
  360. .imglist /deep/ * {
  361. margin-left: auto !important;
  362. margin-right: auto !important;
  363. }
  364. </style>