attestation.vue 9.1 KB

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