attestation.vue 8.8 KB

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