<template>
  <div id="login">
    <el-row>
      <el-col :span="24" class="style">
        <el-col :span="24" class="top">
          <top></top>
        </el-col>
        <el-col :span="24" class="menu">
          <div class="w_1200">
            <menus></menus>
          </div>
        </el-col>
        <el-col :span="24" class="main">
          <div class="w_1200">
            <el-col :span="24" class="info">
              <el-col :span="24" class="top">
                登录
              </el-col>
              <el-col :span="24" class="form">
                <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
                  <el-form-item label="手机号" prop="phone">
                    <el-input v-model="form.phone" placeholder="请输入手机号" maxlength="11"></el-input>
                  </el-form-item>
                  <el-form-item label="密码" prop="passwd">
                    <el-input v-model="form.passwd" placeholder="请输入密码" show-password></el-input>
                  </el-form-item>
                  <el-col :span="24" style="text-align:center;">
                    <el-button type="primary" @click="submitForm('form')">登录</el-button>
                    <el-button @click="$router.push({ path: '/register' })">注册</el-button>
                  </el-col>
                </el-form>
              </el-col>
            </el-col>
          </div>
        </el-col>
        <el-col :span="24" class="foot">
          <div class="w_1200">
            <foot></foot>
          </div>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import top from '@/layout/common/topInfo.vue';
import menus from '@/layout/common/menus.vue';
import foot from '@/layout/common/foot.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: login } = createNamespacedHelpers('login');
export default {
  name: 'login',
  props: {},
  components: {
    top,
    menus,
    foot,
  },
  data: function() {
    return {
      form: {},
      rules: {
        phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
        passwd: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      },
    };
  },
  created() {
    console.log(this.user);
  },
  methods: {
    ...login({ toLogin: 'login' }),
    submitForm(formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          let res = await this.toLogin({ user: this.form });
          if (res) {
            this.$router.push({ path: '/' });
          } else {
            // this.$router.push({ path: '/login' });
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  },
  computed: {
    ...mapState(['user']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped>
.w_1200 {
  width: 1200px;
  margin: 0 auto;
}
.style {
  .menu {
    height: 70px;
    margin: 0 0 10px 0;
  }
  .main {
    min-height: 600px;
    margin: 0 0 10px 0;
    .info {
      min-height: 600px;
      background: #fff;
      padding: 0 20px;
      .top {
        text-align: center;
        padding: 50px 0;
        font-size: 40px;
      }
      .form {
        padding: 0 200px 20px 200px;
      }
    }
  }
  .foot {
    height: 135px;
  }
}
</style>
