realNameAuthentication.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. // #ifdef H5
  120. console.log(path,'h5');
  121. // #endif
  122. uni.showLoading({
  123. title: '图片上传中',
  124. mask: true
  125. });
  126. return new Promise((resolve, error) => {
  127. uni.uploadFile({
  128. url: this.baseURL + '/api/upload/image', //仅为示例,非真实的接口地址
  129. filePath: path,
  130. name: 'file',
  131. header: {
  132. "Authori-zation": 'Bearer ' + uni.getStorageSync('token')
  133. },
  134. success: (uploadFileRes) => {
  135. if ("string" === typeof uploadFileRes.data) {
  136. resolve(JSON.parse(uploadFileRes.data).data)
  137. } else {
  138. resolve(uploadFileRes.data.data)
  139. }
  140. },
  141. complete() {
  142. uni.hideLoading()
  143. }
  144. });
  145. })
  146. },
  147. // 图片裁切
  148. /**
  149. * @param {Number} w 裁切宽度比例
  150. * @param {Number} h 裁切高度比例
  151. * @param {Number} mw 图片最小宽度
  152. * @param {Number} mh 图片最小高度
  153. * @param {String} url url修改
  154. */
  155. navCroper(w, h, type) {
  156. let that = this;
  157. let tt = (type=='upimg'?2:1)
  158. this.onImg(tt).then((url) => {
  159. uni.navigateTo({
  160. url: `./cropper?width=${w}&height=${h}`,
  161. events: {
  162. uploadSuccess(res) {
  163. that.upLoad(res).then((urldata) => {
  164. that[type] = urldata.url;
  165. })
  166. // console.log(e, '接受数据');
  167. }
  168. },
  169. success: function(res) {
  170. // 通过eventChannel向被打开页面传送数据
  171. res.eventChannel.emit('urlNext', {
  172. url
  173. })
  174. }
  175. })
  176. })
  177. },
  178. onImg(type) {
  179. const _this = this
  180. return new Promise((ok, erro) => {
  181. // 判断是否需要选择
  182. if(type==1){
  183. uni.showActionSheet({
  184. itemList: ['拍照', '选择一张照片'],
  185. success: function(res) {
  186. _this.chooseImage(res.tapIndex).then((url) => {
  187. ok(url)
  188. }).catch((res) => {
  189. erro(res)
  190. })
  191. },
  192. fail: function(res) {
  193. erro(res)
  194. console.log(res.errMsg);
  195. }
  196. });
  197. }
  198. // 判断是否只需要拍照
  199. if(type==2){
  200. _this.chooseImage(0).then((url) => {
  201. ok(url)
  202. }).catch((res) => {
  203. erro(res)
  204. })
  205. }
  206. })
  207. },
  208. chooseImage: function(index) {
  209. const _this = this
  210. return new Promise((ok, error) => {
  211. // 从相册/相机选择
  212. // 如需直接开相机或直接选相册,请只使用一个选项
  213. const sourceType = index === 0 ? ['camera'] : ['album']
  214. uni.chooseImage({
  215. count: 1, //默认9
  216. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  217. sourceType: sourceType,
  218. success: function(res) {
  219. ok(res.tempFilePaths[0])
  220. },
  221. fail(e) {
  222. uni.showModal({
  223. title: '文件打开错误',
  224. content: '请设置授权文件存储权限',
  225. showCancel: false,
  226. });
  227. error(e)
  228. }
  229. });
  230. })
  231. },
  232. // 实名认证
  233. confirm(e) {
  234. if (!this.name) {
  235. uni.showModal({
  236. title: '错误',
  237. content: '请填写姓名',
  238. showCancel: false,
  239. });
  240. return
  241. }
  242. if (!this.cardId) {
  243. uni.showModal({
  244. title: '错误',
  245. content: '请填写身份证号',
  246. showCancel: false,
  247. });
  248. return
  249. }
  250. if (!this.upimg) {
  251. uni.showModal({
  252. title: '错误',
  253. content: '请上传正面照',
  254. showCancel: false,
  255. });
  256. return
  257. }
  258. if (!this.sfzZm) {
  259. uni.showModal({
  260. title: '错误',
  261. content: '请上传身份证正面照',
  262. showCancel: false,
  263. });
  264. return
  265. }
  266. if (!this.sfzFm) {
  267. uni.showModal({
  268. title: '错误',
  269. content: '请上传身份证反面照',
  270. showCancel: false,
  271. });
  272. return
  273. }
  274. /*
  275. if (!this.xyfImg) {
  276. uni.showModal({
  277. title: '错误',
  278. content: '上传您的信用分截图',
  279. showCancel: false,
  280. });
  281. return
  282. }*/
  283. this.loding = true;
  284. real_name({
  285. real_name: this.name,
  286. id_card: this.cardId,
  287. face_image: this.upimg.replace('data:image/jpeg;base64,', ''),
  288. id_card_front_image: this.sfzZm.replace('data:image/jpeg;base64,', ''),
  289. id_card_back_image: this.sfzFm.replace('data:image/jpeg;base64,', ''),
  290. pay_points: this.xyfImg.replace('data:image/jpeg;base64,', ''),
  291. })
  292. .then((e) => {
  293. this.loding = false;
  294. if (e.msg == '已实名') {
  295. uni.showModal({
  296. title: '提示',
  297. content: '恭喜您实名认证成功',
  298. showCancel: false,
  299. complete: () => {
  300. uni.switchTab({
  301. url: '/pages/user/user'
  302. })
  303. }
  304. });
  305. } else {
  306. uni.showToast({
  307. title: '认证失败' ,
  308. icon:"none"
  309. })
  310. }
  311. })
  312. .catch(err => {
  313. this.loding = false;
  314. console.log(err);
  315. });
  316. }
  317. }
  318. };
  319. </script>
  320. <style lang="scss">
  321. .content,
  322. page {
  323. min-height: 100%;
  324. }
  325. .listBox {
  326. margin: $page-row-spacing;
  327. margin-top: 30rpx;
  328. border-radius: 20rpx;
  329. overflow: hidden;
  330. background-color: #FFFFFF;
  331. }
  332. .list {
  333. .input {
  334. text-align: right;
  335. font-size: $font-base;
  336. color: $color-gray;
  337. width: 100%;
  338. }
  339. .listItem {
  340. padding: 35rpx 40rpx;
  341. border-bottom: 1px solid $page-color-light;
  342. }
  343. .listIconImg {
  344. width: 36rpx;
  345. }
  346. .right {
  347. color: $font-color-light;
  348. font-size: $font-base;
  349. flex-grow: 1;
  350. justify-content: flex-end;
  351. .userRenzheng {
  352. width: 400rpx;
  353. }
  354. .img {
  355. width: 26rpx;
  356. }
  357. }
  358. .titleBox {
  359. .title {
  360. color: $font-color-base;
  361. font-size: $font-base;
  362. }
  363. }
  364. }
  365. .bg-gray {
  366. background-color: $color-gray;
  367. }
  368. .base-buttom {
  369. position: relative;
  370. bottom: auto;
  371. right: auto;
  372. left: auto;
  373. }
  374. </style>