<template>
  <div id="backlogin">
    <div class="content">
      <div class="page-title">
        <p>中国国家博物馆建党百年展</p>
        <p>点播院线服务平台</p>
      </div>
      <el-form id="form" :model="form" :rules="rules" ref="loginForm">
        <el-form-item prop="username">
          <el-input
            v-model="form.username"
            type="text"
            placeholder="请输入用户名"
            autofocus
            clearable
          >
            <i class="icon-username icon-prefix" slot="prefix"> </i>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="form.password"
            type="password"
            placeholder="请输入密码"
            autofocus
            clearable
          >
            <i class="icon-pwd icon-prefix" slot="prefix"> </i>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            class="login"
            :disabled="flag"
            type="submit"
            @click="submitForm"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { loginOut } from "@/config/loginOut";
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur,change" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur,change" },
        ],
      },
      flag: false,
    };
  },
  mounted() {
    loginOut();
  },
  methods: {
    submitForm() {
      let _this = this;
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          _this.flag = true;
          let requestParams = {};
          requestParams.username = _this.form.username;
          requestParams.password = _this.form.password;
          let params = this.$qs.stringify(requestParams);
          _this
            .$https(
              {
                method: "post",
                url: "ajaxLogin",
              },
              params
            )
            .then((res) => {
              _this.flag = false;
              if (res.status == 200) {
                let resData = res.data;
                if (resData.resultCode == 200) {
                  _this.$message({
                    type: "success",
                    message: resData.message,
                  });
                  localStorage.setItem("user", resData.user.userName);
                  localStorage.setItem("backToken", resData.token);
                  localStorage.setItem(
                    "menuList",
                    JSON.stringify(resData.menuList)
                  );
                  _this.$router.push("index");
                } else {
                  _this.$message.error(res.data.message);
                }
              } else {
                _this.$message.error(res.data.message);
              }
            })
            .catch((error) => {
              _this.$message.error(error.message);
            });
        } else {
          this.flag = false;
          return false;
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
#backlogin {
  position: absolute;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background: #9b1f23 url("~@/assets/login/login_bg.png") no-repeat center/ 100%
    100%;
  .content {
    width: 33.33%;
    height: 100vh;
    background-color: @party-white;
    position: absolute;
    right: 13.5%;
    box-shadow: 0 0 20px 8px rgba(0, 0, 0, 0.2);
    &:before,
    &::after {
      display: inline-block;
      content: "";
      width: 100%;
      height: auto;
    }
    &:before {
      height: 100px;
      background: url("~@/assets/login/login_top01.png") no-repeat center/ 100%
        100%;
    }
    &:after {
      height: 130px;
      position: absolute;
      bottom: 0;
      left: 0;
      background: url("~@/assets/login/login_bt01.png") no-repeat center/ 100%
        100%;
    }
    .page-title {
      margin-top: 140px;
      p {
        text-align: center;
        font-weight: bold;
        font-size: 44px;
        color: @font-color;
        letter-spacing: 0;
        text-align: center;
        line-height: 66px;
        margin: 0;
        padding: 0;
      }
    }
    .icon-prefix {
      display: inline-block;
      width: 24px;
      height: 24px;
    }
    .icon-username {
      background: url("~@/assets/login/user.png") no-repeat center/ 100%;
    }
    .icon-pwd {
      background: url("~@/assets/login/pwd.png") no-repeat center/ 100%;
    }
    /deep/.el-form {
      // margin-top: 120px;
      text-align: center;
      z-index: 99;
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      bottom: 150px;
      .el-form-item {
        margin-bottom: 60px;
      }
      .el-input {
        width: 320px;
        height: 48px;
        .el-input__inner {
          height: 48px;
          line-height: 48px;
          background-color: @party-bg-gray;
          border-color: @party-bg-gray;
          padding-left: 68px;
          font-size: 18px;
        }
        .el-input__prefix {
          left: 20px;
          padding-top: 12px;
        }
      }
      .el-button.login {
        width: 320px;
        height: 48px;
        background: #a4151d;
        border-radius: 4px;
        color: @party-white;
        margin-top: 20px;
        span {
          font-size: 18px;
          font-weight: bold;
        }
        &:hover {
          opacity: 0.8;
        }
      }
    }
  }
}
@media (min-width: 1301px) and (max-width: 1600px) {
  #backlogin .content {
    .page-title {
      margin-top: 50px;
      p {
        font-size: 30px;
      }
    }
  }
}
@media screen and (max-width: 1300px) {
  #backlogin .content {
    .page-title {
      margin-top: 20px;
      p {
        font-size: 24px;
      }
    }
  }
}
</style>
