bind.vue 4.72 KB
<template>
  <div v-if="dialogEnable" class="third-bind-wrapper">
    <div class="bind-dialog">
      <p class="bind-title">关联有货UFO账户</p>
      <div class="under-row">
        <div class="left-row-title">
          <span @click="chooseArea">{{code}}</span>
          <span class="iconfont icondownn"></span>
        </div>
        <CubeInput class="bind-input" :class="phone ? '' : 'bind-input-phone'" v-model="phone"></CubeInput>
      </div>
      <div class="under-row">
        <div class="left-row-title">
          验证码
        </div>
        <CubeInput class="bind-input" :class="smsCode ? '' : 'bind-input-code'" v-model="smsCode"></CubeInput>
        <CubeButton class="send-sms-btn" :disabled="!!sendBtnText" @click="sendSMS">{{sendBtnText || '获取验证码'}}</CubeButton>
      </div>
      <div class="submit-row">
        <CubeButton class="bind-btn" :disabled="submitDisable" @click="bindSubmit">登录</CubeButton>
      </div>
    </div>
  </div>
</template>

<script>

import { Button, Input } from 'cube-ui';
import { mapActions, mapState } from 'vuex';

export default {
  name: 'ThirdBind',
  data() {
    return {
      showBind: false,
      code: '+86',
      phone: '',
      smsCode: '',
      sendBtnText: '',
      binded: false
    }
  },
  computed: {
    dialogEnable() {
      return this.showBind && !this.binded;
    },
    submitDisable() {
      return !(this.phone && this.smsCode);
    }
  },
  methods: {
    ...mapActions(['sendBindSms', 'submitThirdBind']),
    open() {
      this.bindCode = this.$route.query.bind_code;
      this.phone = '';
      this.smsCode = '';
      this.clearSendTimer();
      this.show();
    },
    close() {
      this.showBind = false;
    },
    show() {
      this.showBind = true;
    },
    toast(msg, time = 2000) {
      this.$createToast && this.$createToast({
        txt: msg,
        type: 'txt',
        time
      }).show();
    },
    chooseArea() {
      this.$router.push({
        name: 'passport.area'
      });
    },
    changeArea(code) {
      code && (this.code = code);
    },
    sendSMS() {
      let total = 60;

      this.timer = setInterval(() => {
        if (--total) {
          this.sendBtnText = '重发' + total;
        } else {
          this.clearSendTimer();
        }
      }, 1000);
      this.sendBtnText = '重发' + total;

      this.sendBindSms({
        mobile: this.phone,
        bindCode: this.bindCode
      });
    },
    clearSendTimer() {
      this.sendBtnText = '';
      clearInterval(this.timer);
    },
    bindSubmit() {
      if (this.phone && this.smsCode) {
        this.submitThirdBind({
          mobile: this.phone,
          code: this.smsCode,
          bindCode: this.bindCode
        }).then(res => {
          if (res.code === 200) {
            this.binded = true;
            this.close();
          } else {
            this.toast(res.message);
          }
        });
      } else {
        this.toast(this.phone ?  '请输入短信验证码' : '请输入手机号');
      }
    }
  },
  components: {
    CubeInput: Input,
    CubeButton: Button
  }
};
</script>

<style lang="scss" scoped>
.third-bind-wrapper {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 99;
  display: flex;
  justify-content: center;
  align-items: center;
}

.bind-dialog {
  width: 670px;
  padding: 64px 48px 80px;
  font-size: 28px;
  box-sizing: border-box;
  background-color: #fff;
}

.bind-title {
  font-size: 48px;
  line-height: 66px;
  font-weight: 500;
  margin-bottom: 32px;
}

.under-row {
  line-height: 120px;
  border-bottom: 1px solid #eaeaea;
  display: flex;
  justify-content: center;
  align-items: center;

  .left-row-title {
    width: 150px;
    flex-shrink: 0;
    color: #999;
  }

  .iconfont {
    font-size: 28px;
  }
}

.bind-input {
  flex-grow: 1;

  &:after {
    width: auto;
    height: auto;
    border: 0;
    font-size: 28px;
    line-height: 40px;
    transform: scale(1);
    top: 50%;
    margin-top: -20px;
    color: #ccc;
    font-weight: 300;
  }

  /deep/ .cube-input-field {
    font-size: 20px;
    padding: 10px 0;
    color: #000;
    font-weight: 500;
  }
}

.bind-input-phone:after {
  content: "请输入手机号";
}

.bind-input-code:after {
  content: "请输入验证码";
}

.send-sms-btn {
  width: 180px;
  height: 54px;
  line-height: 54px;
  font-size: 28px;
  padding: 0;
  text-align: right;
  background: none;
  color: #000;
  margin-left: 10px;

  &.cube-btn_disabled {
    color: #999;
  }

  &:after {
    border: 0;
  }
}

.submit-row {
  margin-top: 80px;
}

.bind-btn {
  height: 90px;
  font-size: 28px;
  background: #022c46;
  border-radius: 46px;

  &.cube-btn_disabled {
    background: #ccc;
  }

  &:after {
    border: 0;
  }
}
</style>