attestation.vue 7.7 KB

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