bind.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view style="height: 100%;">
  3. <image mode="widthFix" src="/pages2/static/login_bg.jpg" class="full_img"></image>
  4. <u-navbar title="关联学员身份" :border-bottom="false" background="{ background: '#ffffff',opacity:0.4; }" title-color="#ffffff" back-icon-color="#ffffff"></u-navbar>
  5. <view style="padding: 30rpx;">
  6. <view class="login_box">
  7. <u-form :model="form" ref="uForm" >
  8. <u-form-item ><u-input v-model="form.realname" placeholder="学员姓名"/></u-form-item>
  9. <u-form-item ><u-input v-model="form.idCard" type="idcard" placeholder="学员身份证号"/></u-form-item>
  10. </u-form>
  11. </view>
  12. <button :disabled="isUse" class="loginBtn" @click="jumpBind">
  13. 确定
  14. </button>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. code: '',
  23. form:{
  24. realname:'',
  25. idCard:''
  26. },
  27. codeTips: '',
  28. read:'',
  29. scanCode: '', // 获取扫码的路径最后面的6位标识码
  30. };
  31. },
  32. mounted() {},
  33. methods: {
  34. jumpBind(){
  35. let that = this
  36. if(!this.form.realname.trim()){
  37. this.$u.toast('请输入学员姓名');
  38. return
  39. }
  40. if(!this.form.idCard.trim()){
  41. this.$u.toast('请输入身份证卡号');
  42. return
  43. }
  44. let IDRe18 = /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
  45. let IDre15 = /^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/
  46. if( !IDRe18.test( this.form.idCard ) && !IDre15.test( this.form.idCard ) ) {
  47. this.$u.toast('请输入格式正确的身份证卡号');
  48. console.log(' 验证未通过 ')
  49. return
  50. }
  51. this.$set(this.form,'realname',this.form.realname.trim()) //去除姓名两头空格
  52. that.isUse = true
  53. // 绑定身份证号信息 /app/user/bind_idcard
  54. that.$api.bindId(this.form).then(
  55. res => {
  56. that.isUse = false
  57. if (res.data.code == 200) {
  58. uni.setStorageSync('user_account',uni.getStorageSync('user_account_temp'));
  59. uni.setStorageSync('token',uni.getStorageSync('token_temp'));
  60. uni.removeStorageSync('user_account_temp') //移除临时账号
  61. uni.removeStorageSync('token_temp') //移除临时token
  62. if (this.scanCode) { // pc扫码注册成功后提交/跳转
  63. this.$api.scanLoginCheck({
  64. scanCode: this.scanCode
  65. }).then((res) => {
  66. if (res.data.code == 200) {
  67. uni.navigateTo({
  68. url: '/pages4/login/pcLoginSuccess'
  69. })
  70. }
  71. })
  72. } else { // 跳转到首页是原来的逻辑
  73. uni.reLaunch({
  74. url:'/pages/index/index'
  75. })
  76. }
  77. this.$method.setUuid(new Date().valueOf() + "")
  78. that.$api.getInfo().then(resdata => {
  79. if(resdata.data.code == 200){
  80. that.$store.state.userInfo = resdata.data.data;
  81. }
  82. });
  83. } else {
  84. that.$u.toast(res.data.msg);
  85. }
  86. },
  87. err => {
  88. that.isUse = false
  89. }
  90. );
  91. },
  92. radioGroupChange(e) {
  93. console.log(e);
  94. },
  95. codeChange(text) {
  96. this.codeTips = text;
  97. },
  98. // 获取验证码
  99. getCode() {
  100. if(this.$refs.uCode.canGetCode) {
  101. // 模拟向后端请求验证码
  102. uni.showLoading({
  103. title: '正在获取验证码',
  104. mask: true
  105. })
  106. setTimeout(() => {
  107. uni.hideLoading();
  108. // 这里此提示会被this.start()方法中的提示覆盖
  109. this.$u.toast('验证码已发送');
  110. // 通知验证码组件内部开始倒计时
  111. this.$refs.uCode.start();
  112. }, 2000);
  113. } else {
  114. this.$u.toast('倒计时结束后再发送');
  115. }
  116. },
  117. sectionChange(index) {
  118. this.current = index;
  119. },
  120. getPhoneNumber(e) {
  121. let that = this;
  122. uni.checkSession({
  123. success () {
  124. //session_key 未过期,并且在本生命周期一直有效
  125. that.putInfo(e)
  126. },
  127. fail () {
  128. // session_key 已经失效,需要重新执行登录流程
  129. uni.login({
  130. provider: 'weixin',
  131. success: function(loginRes) {
  132. that.code = loginRes.code;
  133. that.putInfo(e)
  134. }
  135. });
  136. }
  137. })
  138. },
  139. putInfo(e){
  140. let that = this;
  141. if (e.detail.encryptedData) {
  142. let inviteCode = uni.getStorageSync("inviteCode")
  143. //用户同意授权
  144. var datas = {
  145. iv: e.detail.iv,
  146. encryptedData: e.detail.encryptedData,
  147. code: that.code
  148. };
  149. if(inviteCode){
  150. datas.inviteCode = inviteCode
  151. }
  152. that.$api.login(datas).then(
  153. res => {
  154. if (res.data.code == 200) {
  155. uni.setStorageSync('union_id', res.data.data.union_id);
  156. uni.setStorageSync('token', res.data.data.token);
  157. that.$api.getInfo().then(resdata => {
  158. if(resdata.data.code == 200){
  159. uni.navigateBack();
  160. that.$store.state.userInfo = resdata.data.data;
  161. }
  162. });
  163. } else {
  164. uni.showModal({
  165. title: '提示',
  166. content: res.data.msg,
  167. showCancel: false
  168. });
  169. }
  170. },
  171. err => {
  172. console.log(err);
  173. }
  174. );
  175. }
  176. }
  177. },
  178. onLoad(option) {
  179. console.log('注册:', option.scanCode)
  180. let that = this;
  181. option.scanCode && (this.scanCode = option.scanCode)
  182. // this.from = option.from; // this.from 看了页面没有用到,注释了
  183. uni.removeStorageSync('user_account') //移除临时账号
  184. uni.removeStorageSync('token')
  185. uni.login({
  186. provider: 'weixin',
  187. success: function(loginRes) {
  188. that.code = loginRes.code;
  189. }
  190. });
  191. }
  192. };
  193. </script>
  194. <style scoped>
  195. .wxBtn{
  196. position: fixed;
  197. bottom: 10%;
  198. width: 100%;
  199. left: 0;
  200. }
  201. /deep/ .wxBtn button::after{
  202. border: none;
  203. }
  204. .loginBtn{
  205. width: 526rpx;
  206. height: 80rpx;
  207. background: linear-gradient(90deg, #015EEA, #00C0FA);
  208. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  209. opacity: 0.6;
  210. border-radius: 40rpx;
  211. color: #FFFFFF;
  212. text-align: center;
  213. line-height: 80rpx;
  214. margin: 40rpx auto;
  215. }
  216. .wxloginBtn{
  217. background: url("/static/loginBtn.png") no-repeat;
  218. background-size:100% 100%;
  219. border:none;
  220. width: 100rpx;
  221. height: 100rpx;
  222. }
  223. /deep/page {
  224. background-color: #FFFFFF;
  225. height: 100%;
  226. width: 100%;
  227. }
  228. .login_box{
  229. width: 100%;
  230. height: 360rpx;
  231. background: #FFFFFF;
  232. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(1, 99, 235, 0.1);
  233. border-radius: 24rpx;
  234. margin-top: 30rpx;
  235. padding:40rpx 35rpx;
  236. }
  237. /deep/ .u-item-bg{
  238. border-radius: 32px !important;
  239. }
  240. /deep/ .u-subsection{
  241. border-radius: 32px !important;
  242. }
  243. .full_img {
  244. position: absolute;
  245. left: 0;
  246. display: block;
  247. width: 100%;
  248. z-index: -999;
  249. top: 0;
  250. }
  251. .head {
  252. height: 96rpx;
  253. width: 100%;
  254. line-height: 96rpx;
  255. margin-top: 40rpx;
  256. text-align: center;
  257. display: flex;
  258. position: relative;
  259. justify-content: center;
  260. }
  261. .icon {
  262. position: absolute;
  263. left: 30rpx;
  264. }
  265. </style>