bind.vue 6.8 KB

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