bind.vue 5.8 KB

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