bind.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view style="height: 100%;">
  3. <image mode="widthFix" src="/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. };
  30. },
  31. mounted() {},
  32. methods: {
  33. jumpBind(){
  34. let that = this
  35. if(!this.form.realname.trim()){
  36. this.$u.toast('请输入学员姓名');
  37. return
  38. }
  39. if(!this.form.idCard.trim()){
  40. this.$u.toast('请输入身份证卡号');
  41. return
  42. }
  43. 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]$/
  44. 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}$/
  45. if( !IDRe18.test( this.form.idCard ) && !IDre15.test( this.form.idCard ) ) {
  46. this.$u.toast('请输入格式正确的身份证卡号');
  47. console.log(' 验证未通过 ')
  48. return
  49. }
  50. this.$set(this.form,'realname',this.form.realname.trim()) //去除姓名两头空格
  51. that.isUse = true
  52. that.$api.bindId(this.form).then(
  53. res => {
  54. that.isUse = false
  55. if (res.data.code == 200) {
  56. uni.setStorageSync('user_account',uni.getStorageSync('user_account_temp'));
  57. uni.setStorageSync('token',uni.getStorageSync('token_temp'));
  58. uni.removeStorageSync('user_account_temp') //移除临时账号
  59. uni.removeStorageSync('token_temp') //移除临时token
  60. uni.switchTab({
  61. url:'/pages/index/index'
  62. })
  63. } else {
  64. that.$u.toast(res.data.msg);
  65. }
  66. },
  67. err => {
  68. that.isUse = false
  69. }
  70. );
  71. },
  72. radioGroupChange(e) {
  73. console.log(e);
  74. },
  75. codeChange(text) {
  76. this.codeTips = text;
  77. },
  78. // 获取验证码
  79. getCode() {
  80. if(this.$refs.uCode.canGetCode) {
  81. // 模拟向后端请求验证码
  82. uni.showLoading({
  83. title: '正在获取验证码',
  84. mask: true
  85. })
  86. setTimeout(() => {
  87. uni.hideLoading();
  88. // 这里此提示会被this.start()方法中的提示覆盖
  89. this.$u.toast('验证码已发送');
  90. // 通知验证码组件内部开始倒计时
  91. this.$refs.uCode.start();
  92. }, 2000);
  93. } else {
  94. this.$u.toast('倒计时结束后再发送');
  95. }
  96. },
  97. sectionChange(index) {
  98. this.current = index;
  99. },
  100. getPhoneNumber(e) {
  101. let that = this;
  102. uni.checkSession({
  103. success () {
  104. //session_key 未过期,并且在本生命周期一直有效
  105. that.putInfo(e)
  106. },
  107. fail () {
  108. // session_key 已经失效,需要重新执行登录流程
  109. uni.login({
  110. provider: 'weixin',
  111. success: function(loginRes) {
  112. that.code = loginRes.code;
  113. that.putInfo(e)
  114. }
  115. });
  116. }
  117. })
  118. },
  119. putInfo(e){
  120. let that = this;
  121. if (e.detail.encryptedData) {
  122. let inviteCode = uni.getStorageSync("inviteCode")
  123. //用户同意授权
  124. var datas = {
  125. iv: e.detail.iv,
  126. encryptedData: e.detail.encryptedData,
  127. code: that.code
  128. };
  129. if(inviteCode){
  130. datas.inviteCode = inviteCode
  131. }
  132. that.$api.login(datas).then(
  133. res => {
  134. if (res.data.code == 200) {
  135. uni.setStorageSync('union_id', res.data.data.union_id);
  136. uni.setStorageSync('token', res.data.data.token);
  137. that.$api.getInfo().then(resdata => {
  138. if(resdata.data.code == 200){
  139. uni.navigateBack();
  140. that.$store.state.userInfo = resdata.data.data;
  141. }
  142. });
  143. } else {
  144. uni.showModal({
  145. title: '提示',
  146. content: res.data.msg,
  147. showCancel: false
  148. });
  149. }
  150. },
  151. err => {
  152. console.log(err);
  153. }
  154. );
  155. }
  156. }
  157. },
  158. onLoad(option) {
  159. let that = this;
  160. this.from = option.from;
  161. uni.login({
  162. provider: 'weixin',
  163. success: function(loginRes) {
  164. that.code = loginRes.code;
  165. }
  166. });
  167. }
  168. };
  169. </script>
  170. <style scoped>
  171. .wxBtn{
  172. position: fixed;
  173. bottom: 10%;
  174. width: 100%;
  175. left: 0;
  176. }
  177. /deep/ .wxBtn button::after{
  178. border: none;
  179. }
  180. .loginBtn{
  181. width: 526rpx;
  182. height: 80rpx;
  183. background: linear-gradient(90deg, #015EEA, #00C0FA);
  184. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  185. opacity: 0.6;
  186. border-radius: 40rpx;
  187. color: #FFFFFF;
  188. text-align: center;
  189. line-height: 80rpx;
  190. margin: 40rpx auto;
  191. }
  192. .wxloginBtn{
  193. background: url("/static/loginBtn.png") no-repeat;
  194. background-size:100% 100%;
  195. border:none;
  196. width: 100rpx;
  197. height: 100rpx;
  198. }
  199. /deep/page {
  200. background-color: #FFFFFF;
  201. height: 100%;
  202. width: 100%;
  203. }
  204. .login_box{
  205. width: 100%;
  206. height: 360rpx;
  207. background: #FFFFFF;
  208. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(1, 99, 235, 0.1);
  209. border-radius: 24rpx;
  210. margin-top: 30rpx;
  211. padding:40rpx 35rpx;
  212. }
  213. /deep/ .u-item-bg{
  214. border-radius: 32px !important;
  215. }
  216. /deep/ .u-subsection{
  217. border-radius: 32px !important;
  218. }
  219. .full_img {
  220. position: absolute;
  221. left: 0;
  222. display: block;
  223. width: 100%;
  224. z-index: -999;
  225. top: 0;
  226. }
  227. .head {
  228. height: 96rpx;
  229. width: 100%;
  230. line-height: 96rpx;
  231. margin-top: 40rpx;
  232. text-align: center;
  233. display: flex;
  234. position: relative;
  235. justify-content: center;
  236. }
  237. .icon {
  238. position: absolute;
  239. left: 30rpx;
  240. }
  241. </style>