<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2018-10-10 14:44:45
 * @LastEditors  : 无尘
 * @LastEditTime : 2020-04-04 09:45:36
 -->
<template>
  <div class="login-wrap">
    <section>
      <div class="login-body-head border-box flex">
        <img class="login-body-logo" src="../../assets/logo.png" alt="logo" />
        <span class="login-body-title">好办管理后台</span>
      </div>
      <div class="login-body">
        <el-carousel arrow="always" height="262px" :autoplay="false" @change="changeEnterprise">
          <el-carousel-item v-for="item in enterpriseList" :key="item.wxEnterpriseId">
            <div class="info flex">
              <p class="info_img"><img :src="item.corpSquareLogoUrl" alt="" /></p>
              <p class="info_name">{{ item.corpName }}</p>
            </div>
          </el-carousel-item>
        </el-carousel>
        <el-button type="primary" @click="toIndex">登录</el-button>
      </div>
    </section>
  </div>
</template>
<script>
import { _debounce } from '@/common/js/public';
import errMsg from '@/common/js/error';
import { getRequest } from '@/api/api';

export default {
  name: 'login',
  data() {
    return {
      active: 0,
      enterpriseId: '', // 当前选择的 企业 id
      // 企业列表
      enterpriseList: [
        /*{
            enterpriseId  : '1231',
            logoUrl: require("../../assets/logo.png"),
            enterpriseName: '达摩网络'
          },*/
      ],

      // 登录
      numberCode: ''
    };
  },
  computed: {},
  methods: {
    /**
     * 处理路由跳转
     */
    toRouterView(val) {
      const that = this;
      // 模拟检查数据,有两个参数
      that.$router.push({
        path: val.path
      });
    },
    /**
     *  登录
     */
    toIndex: _debounce(function() {
      const that = this;
      that.toLogin();
    }, 500),

    /**
     *  登录 --- api
     */
    toLogin() {
      const that = this;
      const href = `${window.location.origin}/haoban-manage3-web/gic-login?wxEnterpriseId=${that.enterpriseList[that.active].wxEnterpriseId}&random=${that.$route.query.random}`;
      window.location.href = href;
    },
    changeEnterprise(val) {
      this.active = val;
    },
    getList() {
      getRequest(`/haoban-manage3-web/login-wx-enterprise-list?random=${this.$route.query.random}`, {})
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            this.enterpriseList = resData.result;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          this.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  mounted() {
    const that = this;
    if (this.$route.query.random) {
      that.getList();
    }
    if (!!localStorage.getItem('userInfos')) {
      localStorage.removeItem('userInfos');
    }
  },
  components: {}
};
</script>
<style lang="scss" scoped>
.login-wrap {
  width: 100%;
  min-height: 100vh;
  padding-top: 178px;
  box-sizing: border-box;
  background-image: linear-gradient(180deg, rgba(142, 166, 236, 0.11) 0%, rgba(142, 166, 236, 0) 100%);

  .login-body-head {
    justify-content: center;
    align-items: center;
    margin-bottom: 34px;
    .login-body-logo {
      width: 26px;
      margin-right: 13px;
    }
    .login-body-title {
      font-size: 16px;
      font-weight: 600;
      color: #2da8ff;
      line-height: 22px;
    }
  }
  .login-body {
    width: 430px;
    height: 283px;
    background: #ffffff;
    box-shadow: 0px 6px 8px 0px rgba(215, 218, 231, 0.49);
    border-radius: 8px;
    margin: 0 auto;
    >>> .el-carousel__indicators {
      display: none;
    }
    .info {
      padding-top: 70px;
      flex-direction: column;
      align-items: center;
      .info_img {
        width: 46px;
        height: 46px;
        border-radius: 100%;
        overflow: hidden;
        margin-bottom: 17px;
        img {
          width: 100%;
        }
      }
      .info_name {
        font-size: 14px;
        font-weight: 400;
        color: #303133;
        line-height: 20px;
      }
    }
  }
  .el-button {
    position: relative;
    top: -56px;
    z-index: 3;
    display: block;
    margin: 0 auto;
    width: 281px;
    height: 40px;
    background: #2f54eb;
    border-radius: 2px;
  }
}
</style>
