bind.vue 6.0 KB

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