attestation.vue 8.5 KB

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