bind.vue 4.64 KB
<template>
  <div v-if="showBind" class="third-bind-wrapper">
    <div class="bind-dialog">
      <div class="under-row">
        <i class="iconfont iconphone2"></i>
        <div class="select-block">
          <CubeSelect class="area-code-select" v-model="code" :options="options" :title="selectTitle"></CubeSelect>
        </div>
        <CubeInput class="bind-input" v-model="phone" placeholder="请输入手机号"></CubeInput>
      </div>
      <div class="under-row">
        <i class="iconfont iconyanzhengma"></i>
        <CubeInput class="bind-input" v-model="smsCode" placeholder="请输入验证码"></CubeInput>
        <CubeButton class="send-sms-btn" :disabled="!!sendBtnText" @click="sendSMS">{{sendBtnText || '获取验证码'}}</CubeButton>
      </div>
      <div class="submit-row">
        <CubeButton class="bind-btn" @click="bindSubmit">登录</CubeButton>
      </div>
    </div>
  </div>
</template>

<script>

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

const areaList = [{
      value: '+61',
      name: '澳大利亚'
  }, {
      value: '+82',
      text: '韩国'
  }, {
      value: '+1',
      text: '加拿大'
  }, {
      value: '+60',
      text: '马来西亚'
  }, {
      value: '+1',
      text: '美国'
  }, {
      value: '+81',
      text: '日本'
  }, {
      value: '+65',
      text: '新加坡'
  }, {
      value: '+44',
      text: '英国'
  }, {
      value: '+86',
      text: '中国'
  }, {
      value: '+853',
      text: '中国澳门'
  }, {
      value: '+886',
      text: '中国台湾'
  }, {
      value: '+852',
      text: '中国香港'
  }];

export default {
  name: 'ThirdBind',
  data() {
    return {
      showBind: false,
      code: '+86',
      options: areaList,
      selectTitle: '选择国家和地区',
      phone: '',
      smsCode: '',
      sendBtnText: ''
    }
  },
  methods: {
    ...mapActions(['sendBindSms', 'submitThirdBind']),
    show() {
      this.bindCode = this.$route.query.bind_code;
      this.showBind = true;
    },
    close() {
      this.showBind = false;
    },
    toast(msg, time = 2000) {
      this.$createToast && this.$createToast({
        txt: msg,
        type: 'txt',
        time
      }).show();
    },
    sendSMS() {
      let total = 60;
      let timer = setInterval(() => {
        if (--total) {
          this.sendBtnText = '重新获取 ' + total;
        } else {
          this.sendBtnText = '';
          clearInterval(timer);
        }
      }, 1000);
      this.sendBtnText = '重新获取 ' + total;

      this.sendBindSms({
        mobile: this.phone,
        bindCode: this.bindCode
      });
    },
    bindSubmit() {
      if (this.phone && this.smsCode) {
        this.submitThirdBind({
          mobile: this.phone,
          code: this.smsCode,
          bindCode: this.bindCode
        }).then(res => {
          if (res.code === 200) {
            this.close();
          } else {
            this.toast(res.message);
          }
        });
      } else {
        this.toast(this.phone ?  '请输入短信验证码' : '请输入手机号');
      }
    }
  },
  components: {
    CubeInput: Input,
    CubeSelect: Select,
    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;
  height: 600px;
  padding: 100px 60px;
  font-size: 24px;
  box-sizing: border-box;
  background-color: #fff;
  color: #444;
}

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

.iconfont {
  font-size: 40px;
  margin-right: 10px;
  vertical-align: middle;
}

.select-block {
  min-width: 130px;
  position: relative;
  margin-right: 10px;

  &:after {
    content: "";
    width: 1px;
    background-color: #eaeaea;
    position: absolute;
    right: 0;
    top: 30%;
    bottom: 30%;
  }
}

.area-code-select {
  display: inline-block;

  &:after {
    border: 0;
  }

  /deep/ .cube-select-text {
    font-size: 12px;
  }
}

.bind-input {
  flex-grow: 1;

  &:after {
    border: 0;
  }

  /deep/ .cube-input-field {
    font-size: 12px;
  }
}

.send-sms-btn {
  width: 180px;
  height: 54px;
  line-height: 54px;
  padding: 0;
  font-size: 12px;
  border-radius: 27px;
  transform: scale(0.9);

  &:after {
    border: 0;
  }
}

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

.bind-btn {
  height: 120px;
  font-size: 28px;
  background: #022c46;

  &.cube-btn_disabled {
    background: #ccc;
  }
}
</style>