attestation.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <view class="content">
  3. <view class="yz-wrap" v-if="stap == 1">
  4. <!-- <view class="yz-wrap"> -->
  5. <view class="top-wrap flex">
  6. <view class="top-left">
  7. 实名认证<text>*</text>
  8. </view>
  9. </view>
  10. <view class="sr-wrap flex">
  11. <view class="sr-tit">
  12. 姓名
  13. </view>
  14. <input type="text" class="sr-inp" placeholder="请输入姓名" v-model="name">
  15. </view>
  16. <view class="sr-wrap flex">
  17. <view class="sr-tit">
  18. 手机号
  19. </view>
  20. <input type="number" class="sr-inp" placeholder="请输入手机号" v-model="phone">
  21. </view>
  22. <view class="sr-wrap flex">
  23. <view class="sr-tit">
  24. 身份证号
  25. </view>
  26. <input type="idcard" class="sr-inp" placeholder="请输入身份证号" v-model="idcard">
  27. </view>
  28. <view class="sr-wrap flex">
  29. <view class="sr-tit">
  30. 推荐渠道
  31. </view>
  32. <input type="text" class="sr-inp" placeholder="请输入推荐渠道" v-model="code">
  33. <view class="sr-btn" @click="smget()">
  34. 扫码获取
  35. </view>
  36. </view>
  37. </view>
  38. <view class="yz-wrap" v-if="stap == 0">
  39. <view class="top-wrap flex">
  40. <view class="top-left">
  41. 上传身份证照片<text>*</text>
  42. </view>
  43. </view>
  44. <view class="sfz flex">
  45. <!-- #ifdef MP-WEIXIN -->
  46. <image class="" :src="sfzz||'/static/img/sfzz.png'" mode="widthFix"
  47. @click="navTo('/pages/shop/upimg?type=front')">
  48. </image>
  49. <image class="" :src="sfzf||'/static/img/sfzf.png'" mode="widthFix"
  50. @click="navTo('/pages/shop/upimg?type=side')">
  51. </image>
  52. <!-- #endif -->
  53. <!-- #ifdef H5 -->
  54. <image class="" :src="sfzz||'/static/img/sfzz.png'" mode="widthFix"
  55. @click="upsfz('sfzz')">
  56. </image>
  57. <image class="" :src="sfzf||'/static/img/sfzf.png'" mode="widthFix"
  58. @click="upsfz('sfzf')">
  59. </image>
  60. <!-- #endif -->
  61. <!-- #ifdef APP-PLUS -->
  62. <image class="" :src="sfzz||'/static/img/sfzz.png'" mode="widthFix"
  63. @click="upsfz('sfzz')">
  64. </image>
  65. <image class="" :src="sfzf||'/static/img/sfzf.png'" mode="widthFix"
  66. @click="upsfz('sfzf')">
  67. </image>
  68. <!-- #endif -->
  69. <view class="">
  70. 个人信息面
  71. </view>
  72. <view class="">
  73. 国徽面
  74. </view>
  75. </view>
  76. </view>
  77. <!-- <view class="yz-wrap">
  78. <view class="sr-wrap flex">
  79. <view class="sr-tit">
  80. 绑定邀请码
  81. </view>
  82. <input type="text" class="sr-inp" placeholder="请输入绑定邀请码(非必填)">
  83. </view>
  84. </view> -->
  85. <view class="base-buttom" @click="subsfz" v-if="stap == 0">
  86. 下一步
  87. </view>
  88. <template v-if="stap == 1">
  89. <view class="base-buttom" @click="stap = 0">
  90. 上一步
  91. </view>
  92. <view class="base-buttom" @click="sub">
  93. 提交认证
  94. </view>
  95. </template>
  96. </view>
  97. </template>
  98. <script>
  99. import { upload } from '@/api/order.js'
  100. import {
  101. certification,
  102. idcards
  103. } from '@/api/index.js'
  104. import {
  105. mapState
  106. } from "vuex"
  107. export default {
  108. data() {
  109. return {
  110. code: '', //推荐渠道
  111. stap: 0,
  112. sfzz: '',
  113. sfzf: '',
  114. name: '',
  115. phone: '',
  116. idcard: '',
  117. loading: false,
  118. }
  119. },
  120. onLoad() {
  121. },
  122. onShow() {
  123. this.phone = this.userInfo.phone || ''
  124. },
  125. computed: {
  126. // #ifdef H5
  127. ...mapState(['urlFile']),
  128. // #endif
  129. ...mapState('user', ['userInfo'])
  130. },
  131. onReachBottom() {
  132. },
  133. onReady() {
  134. },
  135. methods: {
  136. upsfz(name) {
  137. upload().then(res => {
  138. // this[name] = res[0].url
  139. this.$set(this,name,res[0].url)
  140. })
  141. },
  142. smget() {
  143. let that = this
  144. uni.scanCode({
  145. success: (res) => {
  146. that.code = res.result
  147. }
  148. })
  149. },
  150. upimgg(path, name) {
  151. let that = this
  152. that.upLoad(path).then((urldata) => {
  153. console.log(urldata, '这里')
  154. that[name] = urldata.url;
  155. })
  156. },
  157. navTo(url) {
  158. uni.navigateTo({
  159. url
  160. })
  161. },
  162. back() {
  163. uni.navigateBack()
  164. },
  165. getImage(res) {
  166. console.log(res)
  167. },
  168. subsfz() {
  169. console.log('这里');
  170. let that = this
  171. if (that.sfzz == '' || that.sfzf == '') {
  172. return that.$api.msg('请上传身份证信息')
  173. }
  174. console.log('哪里');
  175. uni.showLoading({
  176. title:'校验中...'
  177. })
  178. try{
  179. idcards({
  180. card_front: that.sfzz,
  181. card_back: that.sfzf
  182. }).then(res => {
  183. uni.hideLoading()
  184. console.log(res)
  185. that.name = res.data.name
  186. that.idcard = res.data.number
  187. that.stap = 1
  188. }).catch(err => {
  189. console.log(err);
  190. })
  191. }catch(e){
  192. console.log(e);
  193. //TODO handle the exception
  194. }
  195. },
  196. sub() {
  197. let that = this
  198. if (that.loading) {
  199. return
  200. }
  201. if (that.name == '') {
  202. that.$api.msg('请输入姓名')
  203. }
  204. if (that.phone == '') {
  205. that.$api.msg('请输入手机号码')
  206. }
  207. if (that.idcard == '') {
  208. that.$api.msg('请输入身份证号')
  209. }
  210. that.loading = true
  211. certification({
  212. name: that.name,
  213. id_number: that.idcard,
  214. phone_number: that.phone,
  215. code: that.code
  216. }).then(res => {
  217. uni.showToast({
  218. title: '提交成功',
  219. duration: 2000
  220. });
  221. setTimeout(() => {
  222. uni.switchTab({
  223. url: '/pages/user/user'
  224. })
  225. })
  226. console.log(res)
  227. that.loading = false
  228. }).catch(err => {
  229. that.loading = false
  230. })
  231. },
  232. upLoad(path) {
  233. uni.showLoading({
  234. title: '图片上传中',
  235. mask: true
  236. });
  237. console.log('图片上传中')
  238. return new Promise((resolve, error) => {
  239. uni.uploadFile({
  240. url: this.$store.state.baseURL + '/api/upload/image', //仅为示例,非真实的接口地址
  241. filePath: path,
  242. name: 'file',
  243. header: {
  244. "Authori-zation": 'Bearer ' + uni.getStorageSync('token')
  245. },
  246. success: (uploadFileRes) => {
  247. if ("string" === typeof uploadFileRes.data) {
  248. resolve(JSON.parse(uploadFileRes.data).data)
  249. } else {
  250. resolve(uploadFileRes.data.data)
  251. }
  252. },
  253. complete() {
  254. uni.hideLoading()
  255. }
  256. });
  257. })
  258. },
  259. chooseImage: function(index) {
  260. const _this = this
  261. return new Promise((ok, error) => {
  262. // 从相册/相机选择
  263. // 如需直接开相机或直接选相册,请只使用一个选项
  264. const sourceType = index === 0 ? ['camera'] : ['album']
  265. uni.chooseImage({
  266. count: 1, //默认9
  267. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  268. sourceType: sourceType,
  269. success: function(res) {
  270. ok(res.tempFilePaths[0])
  271. },
  272. fail(e) {
  273. uni.showModal({
  274. title: '文件打开错误',
  275. content: '请设置授权文件存储权限',
  276. showCancel: false,
  277. });
  278. error(e)
  279. }
  280. });
  281. })
  282. },
  283. onImg(type) {
  284. const _this = this
  285. return new Promise((ok, erro) => {
  286. // 判断是否需要选择
  287. if (type == 1) {
  288. uni.showActionSheet({
  289. itemList: ['拍照', '选择一张照片'],
  290. success: function(res) {
  291. console.log(res, '上传')
  292. _this.chooseImage(res.tapIndex).then((url) => {
  293. ok(url)
  294. }).catch((res) => {
  295. erro(res)
  296. })
  297. },
  298. fail: function(res) {
  299. erro(res)
  300. console.log(res.errMsg);
  301. }
  302. });
  303. }
  304. // 判断是否只需要拍照
  305. if (type == 2) {
  306. _this.chooseImage(0).then((url) => {
  307. ok(url)
  308. }).catch((res) => {
  309. erro(res)
  310. })
  311. }
  312. })
  313. },
  314. // 图片裁切
  315. /**
  316. * @param {Number} w 裁切宽度比例
  317. * @param {Number} h 裁切高度比例
  318. * @param {Number} mw 图片最小宽度
  319. * @param {Number} mh 图片最小高度
  320. * @param {String} url url修改
  321. */
  322. navCroper(w, h, type) {
  323. let that = this;
  324. let tt = (type == 'upimg' ? 2 : 1)
  325. this.onImg(tt).then((url) => {
  326. uni.navigateTo({
  327. url: `/pages/user_home/realName/cropper?width=${w}&height=${h}`,
  328. events: {
  329. uploadSuccess(res) {
  330. console.log(res, '这里')
  331. that.upLoad(res).then((urldata) => {
  332. console.log(urldata, '这里')
  333. that[type] = urldata.url;
  334. })
  335. }
  336. },
  337. success: function(res) {
  338. console.log(res, 'success');
  339. // 通过eventChannel向被打开页面传送数据
  340. res.eventChannel.emit('urlNext', {
  341. url
  342. })
  343. }
  344. })
  345. })
  346. },
  347. }
  348. }
  349. </script>
  350. <style lang="scss" scoped>
  351. page {
  352. padding-top: 1rpx;
  353. }
  354. .yz-wrap {
  355. background-color: #fff;
  356. margin: 20rpx 0;
  357. }
  358. .top-wrap {
  359. justify-content: space-between;
  360. padding: 0 25rpx;
  361. font-size: 32rpx;
  362. font-weight: bold;
  363. color: #00001A;
  364. height: 85rpx;
  365. .top-left {
  366. text {
  367. color: #FF6B2E;
  368. margin-left: 10rpx;
  369. }
  370. }
  371. .top-right {
  372. text {
  373. font-size: 25rpx;
  374. font-weight: 500;
  375. color: #999999;
  376. }
  377. image {
  378. height: 22rpx;
  379. margin-left: 10rpx;
  380. }
  381. }
  382. }
  383. .sr-wrap {
  384. border-top: #fafafa 1rpx solid;
  385. font-size: 32rpx;
  386. font-weight: 500;
  387. width: 690rpx;
  388. height: 114rpx;
  389. line-height: 114rpx;
  390. margin: auto;
  391. .sr-tit {
  392. width: 170rpx;
  393. flex-shrink: 0;
  394. color: #00001A;
  395. }
  396. .sr-inp {
  397. flex-grow: 1;
  398. }
  399. .sr-btn {
  400. flex-shrink: 0;
  401. color: $uni-color-primary;
  402. }
  403. }
  404. .sfz {
  405. padding: 30rpx;
  406. justify-content: space-between;
  407. flex-wrap: wrap;
  408. image {
  409. width: 332rpx;
  410. height: 207rpx;
  411. }
  412. view {
  413. width: 332rpx;
  414. text-align: center;
  415. font-size: 32rpx;
  416. color: #5C5C5C;
  417. }
  418. }
  419. .base-buttom {
  420. margin-top: 25rpx;
  421. }
  422. </style>