<style scoped>
.login-box-pc {
  width: 436px;
}
.login-box {
  padding: 30px 40px;
  background-clip: padding-box;
  background: #ffffff;
  border-radius: 18px;
}

.login-box .tw_logo {
  margin: 0 auto 20px;
  display: block;
  height: 45px;
  width: auto;
}

.login-box .tip-text {
  font-size: 16px;
  margin-bottom: 15px;
  color: #999;
  text-align: center;
}

.login-box .tip-text a {
  color: #00afff;
}

.login_row {
  width: 100%;
}

.form-group {
  position: relative;
  margin-bottom: 15px;
}

.login_labelName {
  margin-top: 34px;
  font-size: 16px;
  margin-bottom: 16px;
}

.form-group i {
  position: absolute;
  right: 6px;
  bottom: 0;
  z-index: 2;
  width: 46px;
  height: 46px;
  text-align: center;
  line-height: 46px;
  color: #999;
  font-size: 28px;
  cursor: pointer;
}

::v-deep .q-field__control {
  height: 46px !important;
}
.type-item {
  width: 50px;
  height: 50px;
  background: #f5f5f5;
  border-radius: 25px;
}
.type-item img {
  width: 28px;
  height: 28px;
}
</style>
<template>
  <div class="login">
    <div class="login-box" :class="$q.platform.is.desktop ? 'login-box-pc' : ''">
          <div class="f34 bold">注销账户</div>
        <div class="login_row">
          <q-input
            filled
            v-model="loginMsg.EMail"
            class="q-mt-xl"
            label="輸入郵箱"
            style="ime-mode: disabled"
            aria-autocomplete="off"
            :rules="[
              (val) =>
                /^[a-zA-Z0-9]+([-_.][A-Za-zd]+)*@([a-zA-Z0-9]+[-.])+[A-Za-zd]{2,5}$/.test(
                  val
                ) || '請輸入正確的郵箱地址',
            ]"
          >
            <template
              v-slot:after
            >
              <q-btn
                unelevated
                color="text-white bg-secondary"
                :disable="
                  !/^[a-zA-Z0-9]+([-_.][A-Za-zd]+)*@([a-zA-Z0-9]+[-.])+[A-Za-zd]{2,5}$/.test(
                    loginMsg.EMail
                  ) || cutDown > 0
                "
                style="height: 46px; margin-top: -10px"
                filled
                :loading="inSending"
                :label="
                  !isSend
                    ? '发送验证码'
                    : cutDown > 0
                    ? cutDown + '秒'
                    : '重新發送'
                "
                @click="sendVerify"
              />
            </template>
          </q-input>
          <div
            class="q-mt-md"
          >
            <verify-code
              :digit="6"
              hint="請輸入正確的驗證碼"
              ref="verify"
              v-model="loginMsg.Code"
            ></verify-code>
          </div>
          <div class="q-mb-xl">
            <q-btn
              color="primary"
              unelevated
              style="width: 100%; height: 50px; margin-top: 20px"
              filled
              :label="mylabel"
              @click="login"
            />
          </div>
        </div>
    </div>
  </div>
</template>

<script>
import QrcodeVue from "qrcode.vue";
import verifyCode from "src/components/auth/verifyCode.vue";
export default {
  name: "Login",
  components: {
    QrcodeVue,verifyCode
  },
  data() {
    return {
      isSend: false,
      tips: false,
      cutDown: 0,
      isAgree: false,
      isLogin: true,
      loginMsg: {
        EMail: "",
        Code: "",
      },
      // , 'google', 'facebook', 'apple'
      typeList: ["wechat"],
      logo: "",
      flag: 2,
      mylabel: "注销账户",
      inSending: false,
    };
  },
  created() {},
  mounted() {
  },
  methods: {
    sendVerify() {
      if(this.inSending || this.cutDown) return
      this.inSending = true
      if (this.verifyEmail()) {
        this.apipost('directCustomer_post_SendMail', {Mailbox: this.loginMsg.EMail, SendType: 4}, (res) => {
          this.inSending = false
          if (res.data.resultCode == 1) {
            this.isSend = true;
        this.cutDown = 60;
        this.startCutDown();
          } else {
            this.$q.notify({
              type: "negative",
              message: res.data.message,
              position: "top",
              timeout: 2000, // 以毫秒为单位; 0意味着没有超时
            });
          }
        }, null)
      } else {
        this.inSending = false
      }
    },
    startCutDown() {
      this.timer = setTimeout(() => {
        this.cutDown--;
        if (this.cutDown) {
          this.startCutDown();
        }
      }, 1000);
    },
    verifyEmail() {
      if (/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(this.loginMsg.EMail)) {
        this.tips = false;
        return true;
      } else {
        // 提示用户邮箱格式有误
        this.tips = true;
        return false;
      }
    },
    login() {
      if(this.mylabel === "提交中...") {
        return
      }
      
      if (this.loginMsg.EMail == "") {
        this.$q.notify({
          type: "negative",
          message: "请输入账号",
          position: "top",
          timeout: 2000, // 以毫秒为单位; 0意味着没有超时
        });
        return;
      }
      if (this.loginMsg.Code == "") {
        this.$q.notify({
          type: "negative",
          message: "请输入邮箱验证码",
          position: "top",
          timeout: 2000, // 以毫秒为单位; 0意味着没有超时
        });
        return;
      }
      this.mylabel = "提交中...";
      this.apipost(
        'b2c_post_SetAccountCancel',
        this.loginMsg,
        (res) => {
          this.mylabel = "注销账户";
          if (res.data.resultCode == 1) {
            this.CommonJump("/login", {});
          } else {
            this.$q.notify({
              type: "negative",
              message: res.data.message,
              position: "top",
              timeout: 2000, // 以毫秒为单位; 0意味着没有超时
            });
          }
        },
        (err) => {}
      );
    },
  },
};
</script>
