<template>
  <div class="login">
    <div class="contents">
      <!-- 头部logo -->
      <div class="header">
        <img src="@/assets/hongqi.png" alt="logo" />
        <div class="title">让理想飞扬</div>
      </div>
      <!-- 主体表单 -->
      <div class="main">
        <wInput
          type="text"
          maxlength="11"
          placeholder="用户名/电话"
          v-model="phoneData"
        ></wInput>
        <wInput
          type="password"
          maxlength="11"
          placeholder="密码"
          v-model="passData"
          :isShowPass="true"
        ></wInput>
      </div>
      <wButton
        text="登 录"
        :rotate="isRotate"
        @click.native="startLogin()"
        class="wbutton"
      ></wButton>

      <!-- 底部信息 -->
      <div class="footer">
        <div style="color: #fff;font-size: 14px;cursor:pointer;" @click="toKefu">找回密码</div>
        <span>|</span>
        <router-link to="register">注册账号</router-link>
      </div>
    </div>

    <!-- 网站底部信息 -->
    <div class="site-footer">
      <div class="footer-links">
        <a href="#" class="footer-link">网站声明</a>
        <span class="divider">|</span>
        <a href="#" class="footer-link">隐私政策</a>
        <span class="divider">|</span>
        <a href="#" class="footer-link">中国一汽</a>
      </div>
      <div class="copyright">© 2020中国第一汽车集团有限公司版权所有</div>
      <div class="beian">
        <a href="https://beian.miit.gov.cn/" target="_blank" class="beian-link">吉ICP备17008829号-1</a>
      </div>
      <div class="police-beian">
        <!-- <img src="@/assets/beian.png" alt="备案图标" class="beian-icon" /> -->
        <a href="http://www.beian.gov.cn/portal/registerSystemInfo" target="_blank" class="beian-link">
          吉公网安备 22017102000237 号
        </a>
      </div>
    </div>
  </div>
</template>

<script>
import wInput from "../components/watch-login/watch-input.vue"; //input
import wButton from "../components/watch-login/watch-button.vue"; //button
import { Toast } from "vant";
import { getUserInfo, getLink } from '@/api/home';
export default {
  data() {
    return {
      phoneData: "", // 账号
      passData: "", // 密码
      smsCode: "", // 短信验证码
      lang: "zh", // 语言
      countryCode: "+86", // 国家代码
      isRotate: false, // 是否加载旋转
      link: '', // 新增客服链接
    };
  },
  mounted() {
    this.getUserInfo();
    this.getLink();
  },
  methods: {
    async getUserInfo() {
      const res = await getUserInfo();
      this.userInfo = res.data;
    },
    async getLink() {
      const res = await getLink();
      if (res.data && res.data.link && res.data.link[0] && res.data.link[0].value) {
        this.link = res.data.link[0].value;
      } else {
        this.link = '';
      }
    },
    toKefu() {
      if (this.link) {
        window.open(this.link, '_blank');
      } else {
        Toast('未获取到客服链接');
      }
    },
    async startLogin() {
      if (this.isRotate) {
        return false;
      }
      if (!this.phoneData) {
        Toast("账号不能为空");
        return;
      }
      if (this.passData.length < 6) {
        Toast("密码不少于6位");
        return;
      }
      this.isRotate = true;
      try {
        let data = {
          account: this.phoneData,
          password: this.passData,
          sms_code: this.smsCode,
          lang: this.lang,
          country_code: this.countryCode
        };
        await this.$store.dispatch("Login", data);
        this.isRotate = false;
       
        this.$router.replace("home");
      } catch (error) {
        this.isRotate = false;
      }
    },
  },
  components: {
    wInput,
    wButton
  }
};
</script>

<style lang="scss" scoped>
.login {
  height: 100%;
  width: 100%;
  background: url('~@/assets/dabag.png') no-repeat center center;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.contents {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding-bottom: 180px;
}

.header {
  width: 144px;
  height: 104px;
  margin-top: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #fff;
  padding: 20px;
  border-radius: 50px 50px 50px 50px;
  img {
    width: 80px;
    width: 80px;
    object-fit: cover;
    
  }
}

.title {
  font-size: 10px;
  color: #000;
  margin-top: 16px;
  font-weight: 500;
  letter-spacing: 4px;
}

.main {
  width: 100%;
  max-width: 320px;
  margin: 20px 0 0 0;
}

.wbutton {
  margin-top: 40px;
  width: 100%;
  max-width: 320px;
}

.footer {
  margin-top: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  
  a {
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    opacity: 0.9;
    transition: opacity 0.3s;
    
    &:hover {
      opacity: 1;
    }
  }
  
  span {
    color: #fff;
    opacity: 0.5;
  }
}

/* 网站底部样式 */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 15px 0;
  background: rgba(0, 0, 0, 0.5);
  text-align: center;
}

.footer-links {
  margin-bottom: 10px;
  
  .footer-link {
    color: #fff;
    text-decoration: none;
    font-size: 12px;
    opacity: 0.8;
    transition: opacity 0.3s;
    
    &:hover {
      opacity: 1;
    }
  }
  
  .divider {
    color: #fff;
    opacity: 0.5;
    margin: 0 8px;
  }
}

.copyright {
  color: #fff;
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 8px;
}

.beian {
  margin-bottom: 8px;
  
  .beian-link {
    color: #fff;
    text-decoration: none;
    font-size: 12px;
    opacity: 0.8;
    transition: opacity 0.3s;
    
    &:hover {
      opacity: 1;
    }
  }
}

.police-beian {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  
  .beian-icon {
    width: 14px;
    height: 14px;
  }
  
  .beian-link {
    color: #fff;
    text-decoration: none;
    font-size: 12px;
    opacity: 0.8;
    transition: opacity 0.3s;
    
    &:hover {
      opacity: 1;
    }
  }
}
</style>

<style>
@import url("../components/watch-login/css/icon.css");
</style>

