<template>
  <div id="login">
    <el-row>
      <el-col :span="24" class="main">
        <div class="w_1200">
          <el-col :span="24" class="one">
            <el-col :span="24" class="one_1">
              <el-col :span="24" class="txt"><h3>商城管理登陆</h3></el-col>
              <el-col :span="24" class="form">
                <el-form :model="form" :rules="rules" ref="form">
                  <el-form-item label="" prop="account">
                    <el-input placeholder="账号" v-model="form.account" @keyup.enter.native="onSubmit('form')">
                      <i slot="prefix" class="el-input__icon el-icon-user-solid"></i>
                    </el-input>
                  </el-form-item>
                  <el-form-item label="" prop="password">
                    <el-input placeholder="密码" v-model="form.password" type="password" auto-complete="off" @keyup.enter.native="onSubmit('form')">
                      <i slot="prefix" class="el-input__icon el-icon-lock"></i>
                    </el-input>
                  </el-form-item>
                  <!-- <el-form-item label="" prop="code">
                    <el-input placeholder="验证码" v-model="form.code" style="width: 75%" @keyup.enter.native="onSubmit('form')" disabled>
                      <i slot="prefix" class="el-input__icon el-icon-folder-checked"></i>
                    </el-input>
                    <el-image :src="img" class="yzm"></el-image>
                  </el-form-item> -->
                  <el-form-item class="btn">
                    <el-button type="primary" @click="onSubmit('form')">登录</el-button>
                  </el-form-item>
                </el-form>
              </el-col>
            </el-col>
          </el-col>
          <el-col :span="24" class="two"> </el-col>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const _ = require('lodash');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: maU } = createNamespacedHelpers('admin');
export default {
  name: 'login',
  props: {},
  components: {},
  data: function () {
    return {
      form: {},
      rules: {
        account: [{ required: true, message: '用户名不能为空', trigger: 'blur' }],
        password: [{ required: true, message: '密码不能为空', trigger: 'blur' }],
        code: [{ required: false, message: '验证码不能为空', trigger: 'blur' }],
      },
      // 验证码
      img: require('@a/yzm.gif'),
    };
  },
  created() {},
  methods: {
    ...maU(['login']),
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          const res = await this.login(this.form);
          if (!res) {
            this.$message({ type: `error`, message: `登陆失败` });
          } else {
            if (res.errcode !== 0) {
              this.$message({ type: 'error', message: `${res.errmsg}` });
            } else {
              this.$router.push({ path: '/' });
            }
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  background: url('~@/assets/login-background.jpg');
  height: 100vh;
  overflow: hidden;
  .one {
    .one_1 {
      width: 400px;
      padding: 25px 25px 5px 25px;
      border-radius: 6px;
      background: #fff;
      margin: 35vh 75vh;
      .txt {
        text-align: center;
        color: #707070;
        margin: 0 0 15px 0;
      }
      .yzm {
        float: right;
        width: 80px;
        height: 37px;
      }
      .btn {
        .el-button {
          width: 100%;
        }
      }
    }
  }
  .two {
    text-align: center;
    p {
      position: absolute;
      bottom: 15px;
      width: 1200px;
      color: #fff;
      font-family: Arial;
      font-size: 12px;
      letter-spacing: 1px;
    }
  }
}
</style>
