123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <template>
- <view class="container">
- <view class="cu-form-group"
- style="margin: 30upx;border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
- <view class="title">手机号</view>
- <input type="number" :value="mobile" placeholder="请输入手机号" maxlength="11" data-key="mobile"
- @input="inputChange" />
- </view>
- <view class="cu-form-group"
- style="margin: 30upx;border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
- <text class="title">验证码</text>
- <input type="number" :value="code" placeholder="请输入验证码" maxlength="6" data-key="code" @input="inputChange"
- @confirm="toLogin" />
- <button class="send-msg" @click="sendMsg" :disabled="sending">{{ sendTime }}</button>
- </view>
- <button class="confirm-btn" @click="toLogin" :disabled="logining">立即绑定</button>
- </view>
- </view>
- </template>
- <script>
- import listCell from '@/components/com-input';
- export default {
- components: {
- listCell
- },
- data() {
- return {
- mobile: '',
- code: '',
- logining: false,
- sending: false,
- sendTime: '获取验证码',
- count: 60,
- }
- },
- methods: {
- inputChange(e) {
- const key = e.currentTarget.dataset.key;
- this[key] = e.detail.value;
- },
- navBack() {
- uni.navigateBack();
- },
- countDown() {
- const {
- count
- } = this;
- if (count === 1) {
- this.count = 60;
- this.sending = false;
- this.sendTime = '获取验证码'
- } else {
- this.count = count - 1;
- this.sending = true;
- this.sendTime = count - 1 + '秒后重新获取';
- setTimeout(this.countDown.bind(this), 1000);
- }
- },
- sendMsg() {
-
- const {
- mobile
- } = this;
- if (!mobile) {
- this.$queue.showToast("请输入手机号");
- } else if (mobile.length !== 11) {
- this.$queue.showToast("请输入正确的手机号");
- } else {
- this.$queue.showLoading("正在发送验证码...");
- this.$Request.getT('/app/Login/sendMsg/' + mobile + '/bind').then(res => {
- if (res.code === 0) {
- this.sending = true;
- this.$queue.showToast('验证码发送成功请注意查收');
- this.countDown();
- uni.hideLoading();
- } else {
- uni.hideLoading();
- uni.showModal({
- showCancel: false,
- title: '短信发送失败',
- content: res.msg ? res.msg : '请一分钟后再获取验证码'
- });
- }
- });
- }
- },
- toLogin() {
- let openId = this.$queue.getData('openid') ? this.$queue.getData('openid') : '';
- const {
- mobile,
- code
- } = this;
- let userId = this.$queue.getData("userId");
- if (!mobile) {
- this.$queue.showToast("请输入手机号");
- } else if (mobile.length !== 11) {
- this.$queue.showToast("请输入正确的手机号");
- } else if (!code) {
- this.$queue.showToast("请输入验证码");
- } else {
- this.$queue.showLoading("正在绑定中...");
- let data={
- msg:code,
- phone:mobile,
- userId:userId,
- openId: openId,
- }
- this.$Request.postT('/app/Login/registerCode',data).then(res => {
- if (res.code === 0) {
- this.$queue.setData("mobile", mobile);
- // this.$queue.showToast('修改成功');
- uni.setStorageSync('token', res.token)
- uni.setStorageSync('userInfo', res.user)
- uni.setStorageSync('userId', res.user.userId)
- uni.setStorageSync('invitationCode', res.user.invitationCode)
- uni.setStorageSync('userId', res.user.userId)
- uni.setStorageSync('openId', res.user.openId)
- uni.switchTab({
- url: '/pages/my/index'
- });
- } else {
- uni.showModal({
- showCancel: false,
- title: '绑定失败',
- content: res.msg,
- });
- }
- uni.hideLoading();
- })
- // this.$Request.postT("/app/updatePhone?msg=" + code + "&phone=" + mobile + "&userId=" + userId).then(
- // res => {
- // if (res.code === 0) {
- // this.$queue.setData("mobile", mobile);
- // this.$queue.showToast('修改成功');
- // uni.switchTab({
- // url: '/pages/my/index'
- // });
- // } else {
- // uni.showModal({
- // showCancel: false,
- // title: '绑定失败',
- // content: res.msg,
- // });
- // }
- // uni.hideLoading();
- // });
- }
- },
- },
- }
- </script>
- <style lang='scss'>
- page {
- background: #FFFFFF;
- }
- .send-msg {
- border-radius: 30px;
- color: white;
- height: 30px;
- font-size: 14px;
- line-height: 30px;
- background: #00B88F;
- }
- .container {
- top: 0;
- padding-top: 32upx;
- position: relative;
- width: 100%;
- height: 100%;
- overflow: hidden;
- background: #FFFFFF;
- }
- .confirm-btn {
- width: 600upx;
- height: 80upx;
- line-height: 80upx;
- border-radius: 60upx;
- margin-top: 32upx;
- background: #00B88F;
- color: #fff;
- font-size: 32upx;
- &:after {
- border-radius: 60px;
- }
- }
- </style>
|