realNameAuthentication.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <view class="content padding-b-30">
  3. <view class="listBox" @click="navCroper(480,640,'upimg')">
  4. <view class="list">
  5. <view class="flex listItem">
  6. <view class="titleBox">
  7. <view class="title">正面照</view>
  8. <view class="font-color-gray font-size-sm">
  9. 上传您的正面照
  10. </view>
  11. </view>
  12. <view class="right flex">
  13. <!-- #ifdef H5 -->
  14. <image class="userRenzheng" :src="upimg||this.urlFile + '/static/image/realUser.png'"
  15. mode="widthFix"></image>
  16. <!-- #endif -->
  17. <!-- #ifndef H5 -->
  18. <image class="userRenzheng" :src="upimg||'/static/image/realUser.png'" mode="widthFix"></image>
  19. <!-- #endif -->
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="listBox" @click="navCroper(400,300,'sfzZm')">
  25. <view class="list">
  26. <view class="flex listItem">
  27. <view class="titleBox">
  28. <view class="title">身份证正面</view>
  29. <view class="font-color-gray font-size-sm">
  30. 上传您的身份证正面
  31. </view>
  32. </view>
  33. <view class="right flex">
  34. <!-- #ifdef H5 -->
  35. <image class="userRenzheng" :src="sfzZm||this.urlFile + '/static/image/realZm.png'"
  36. mode="widthFix"></image>
  37. <!-- #endif -->
  38. <!-- #ifndef H5 -->
  39. <image class="userRenzheng" :src="sfzZm||'/static/image/realZm.png'" mode="widthFix"></image>
  40. <!-- #endif -->
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="listBox" @click="navCroper(400,300,'sfzFm')">
  46. <view class="list">
  47. <view class="flex listItem">
  48. <view class="titleBox">
  49. <view class="title">身份证反面</view>
  50. <view class="font-color-gray font-size-sm">
  51. 上传您的身份证反面
  52. </view>
  53. </view>
  54. <view class="right flex">
  55. <!-- #ifdef H5 -->
  56. <image class="userRenzheng" :src="sfzFm||this.urlFile + '/static/image/realBm.png'"
  57. mode="widthFix"></image>
  58. <!-- #endif -->
  59. <!-- #ifndef H5 -->
  60. <image class="userRenzheng" :src="sfzFm||'/static/image/realBm.png'" mode="widthFix"></image>
  61. <!-- #endif -->
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="listBox">
  67. <view class="list">
  68. <view class="flex listItem">
  69. <view class="flex titleBox">
  70. <text class="title">真实姓名</text>
  71. </view>
  72. <view class="right flex">
  73. <input class="input" v-model="name" type="text" placeholder="请填写真实姓名"
  74. placeholder-class="placeholder" />
  75. </view>
  76. </view>
  77. <view class="flex listItem">
  78. <view class="flex titleBox">
  79. <text class="title">身份证号</text>
  80. </view>
  81. <view class="right flex">
  82. <input class="input" v-model="cardId" type="text" placeholder="请填写身份证号"
  83. placeholder-class="placeholder" />
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <view class="base-buttom" :class="{ 'bg-gray': loding }" @click="loding ? '' : confirm()">提交</view>
  89. </view>
  90. </template>
  91. <script>
  92. import {
  93. real_name
  94. } from '@/api/user.js';
  95. import {
  96. mapState
  97. } from "vuex"
  98. export default {
  99. data() {
  100. return {
  101. name: '', //用户名称
  102. cardId: '', //身份证号
  103. upimg: '', //图片地址
  104. xyfImg: '', //信用分图片
  105. sfzZm: '', //身份证正面
  106. sfzFm: '', //身份证反面
  107. loding: false, //是否载入中
  108. };
  109. },
  110. onLoad(options) {},
  111. computed: {
  112. // #ifdef H5
  113. ...mapState(['urlFile']),
  114. // #endif
  115. ...mapState(['baseURL']),
  116. },
  117. methods: {
  118. upLoad(path) {
  119. uni.showLoading({
  120. title: '图片上传中',
  121. mask: true
  122. });
  123. return new Promise((resolve, error) => {
  124. uni.uploadFile({
  125. url: this.baseURL + '/api/upload/image', //仅为示例,非真实的接口地址
  126. filePath: path,
  127. name: 'file',
  128. header: {
  129. "Authori-zation": 'Bearer ' + uni.getStorageSync('token')
  130. },
  131. success: (uploadFileRes) => {
  132. if ("string" === typeof uploadFileRes.data) {
  133. resolve(JSON.parse(uploadFileRes.data).data)
  134. } else {
  135. resolve(uploadFileRes.data.data)
  136. }
  137. },
  138. complete() {
  139. uni.hideLoading()
  140. }
  141. });
  142. })
  143. },
  144. // 图片裁切
  145. /**
  146. * @param {Number} w 裁切宽度比例
  147. * @param {Number} h 裁切高度比例
  148. * @param {Number} mw 图片最小宽度
  149. * @param {Number} mh 图片最小高度
  150. * @param {String} url url修改
  151. */
  152. navCroper(w, h, type) {
  153. let that = this;
  154. let tt = (type=='upimg'?2:1)
  155. this.onImg(tt).then((url) => {
  156. uni.navigateTo({
  157. url: `./cropper?width=${w}&height=${h}`,
  158. events: {
  159. uploadSuccess(res) {
  160. that.upLoad(res).then((urldata) => {
  161. that[type] = urldata.url;
  162. })
  163. }
  164. },
  165. success: function(res) {
  166. // 通过eventChannel向被打开页面传送数据
  167. res.eventChannel.emit('urlNext', {
  168. url
  169. })
  170. }
  171. })
  172. })
  173. },
  174. onImg(type) {
  175. const _this = this
  176. return new Promise((ok, erro) => {
  177. // 判断是否需要选择
  178. if(type==1){
  179. uni.showActionSheet({
  180. itemList: ['拍照', '选择一张照片'],
  181. success: function(res) {
  182. _this.chooseImage(res.tapIndex).then((url) => {
  183. ok(url)
  184. }).catch((res) => {
  185. erro(res)
  186. })
  187. },
  188. fail: function(res) {
  189. erro(res)
  190. console.log(res.errMsg);
  191. }
  192. });
  193. }
  194. // 判断是否只需要拍照
  195. if(type==2){
  196. _this.chooseImage(0).then((url) => {
  197. ok(url)
  198. }).catch((res) => {
  199. erro(res)
  200. })
  201. }
  202. })
  203. },
  204. chooseImage: function(index) {
  205. const _this = this
  206. return new Promise((ok, error) => {
  207. // 从相册/相机选择
  208. // 如需直接开相机或直接选相册,请只使用一个选项
  209. const sourceType = index === 0 ? ['camera'] : ['album']
  210. uni.chooseImage({
  211. count: 1, //默认9
  212. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  213. sourceType: sourceType,
  214. success: function(res) {
  215. ok(res.tempFilePaths[0])
  216. },
  217. fail(e) {
  218. uni.showModal({
  219. title: '文件打开错误',
  220. content: '请设置授权文件存储权限',
  221. showCancel: false,
  222. });
  223. error(e)
  224. }
  225. });
  226. })
  227. },
  228. // 实名认证
  229. confirm(e) {
  230. if (!this.name) {
  231. uni.showModal({
  232. title: '错误',
  233. content: '请填写姓名',
  234. showCancel: false,
  235. });
  236. return
  237. }
  238. if (!this.cardId) {
  239. uni.showModal({
  240. title: '错误',
  241. content: '请填写身份证号',
  242. showCancel: false,
  243. });
  244. return
  245. }
  246. if (!this.upimg) {
  247. uni.showModal({
  248. title: '错误',
  249. content: '请上传正面照',
  250. showCancel: false,
  251. });
  252. return
  253. }
  254. if (!this.sfzZm) {
  255. uni.showModal({
  256. title: '错误',
  257. content: '请上传身份证正面照',
  258. showCancel: false,
  259. });
  260. return
  261. }
  262. if (!this.sfzFm) {
  263. uni.showModal({
  264. title: '错误',
  265. content: '请上传身份证反面照',
  266. showCancel: false,
  267. });
  268. return
  269. }
  270. /*
  271. if (!this.xyfImg) {
  272. uni.showModal({
  273. title: '错误',
  274. content: '上传您的信用分截图',
  275. showCancel: false,
  276. });
  277. return
  278. }*/
  279. this.loding = true;
  280. real_name({
  281. real_name: this.name,
  282. id_card: this.cardId,
  283. face_image: this.upimg.replace('data:image/jpeg;base64,', ''),
  284. id_card_front_image: this.sfzZm.replace('data:image/jpeg;base64,', ''),
  285. id_card_back_image: this.sfzFm.replace('data:image/jpeg;base64,', ''),
  286. pay_points: this.xyfImg.replace('data:image/jpeg;base64,', ''),
  287. })
  288. .then((e) => {
  289. this.loding = false;
  290. if (e.msg == '已实名') {
  291. uni.showModal({
  292. title: '提示',
  293. content: '恭喜您实名认证成功',
  294. showCancel: false,
  295. complete: () => {
  296. uni.switchTab({
  297. url: '/pages/userhome/user'
  298. })
  299. }
  300. });
  301. } else {
  302. this.$api.msg('认证失败');
  303. }
  304. })
  305. .catch(err => {
  306. this.loding = false;
  307. console.log(err);
  308. });
  309. }
  310. }
  311. };
  312. </script>
  313. <style lang="scss">
  314. .content,
  315. page {
  316. min-height: 100%;
  317. }
  318. .listBox {
  319. margin: $page-row-spacing;
  320. margin-top: 30rpx;
  321. border-radius: 20rpx;
  322. overflow: hidden;
  323. background-color: #FFFFFF;
  324. }
  325. .list {
  326. .input {
  327. text-align: right;
  328. font-size: $font-base;
  329. color: $color-gray;
  330. width: 100%;
  331. }
  332. .listItem {
  333. padding: 35rpx 40rpx;
  334. border-bottom: 1px solid $page-color-light;
  335. }
  336. .listIconImg {
  337. width: 36rpx;
  338. }
  339. .right {
  340. color: $font-color-light;
  341. font-size: $font-base;
  342. flex-grow: 1;
  343. justify-content: flex-end;
  344. .userRenzheng {
  345. width: 400rpx;
  346. }
  347. .img {
  348. width: 26rpx;
  349. }
  350. }
  351. .titleBox {
  352. .title {
  353. color: $font-color-base;
  354. font-size: $font-base;
  355. }
  356. }
  357. }
  358. .bg-gray {
  359. background-color: $color-gray;
  360. }
  361. .base-buttom {
  362. position: relative;
  363. bottom: auto;
  364. right: auto;
  365. left: auto;
  366. }
  367. </style>