approve.vue 8.9 KB

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