<template>
    <div class="container">
      <div class="mainBox">
        <div class="mainTitle">
          <img src="../assets/img/logo.png" alt="logo">
        </div>
        <div class="main">
          <Form ref="formInline" :model="formInline" :rules="ruleInline">
            <FormItem prop="user">
                <Input type="text" v-model="formInline.user" placeholder="用户名">
                    <Icon type="ios-person-outline" slot="prepend"></Icon>
                </Input>
            </FormItem>
            <FormItem prop="password">
                <Input type="password" v-model="formInline.password" placeholder="密码">
                    <Icon type="ios-lock-outline" slot="prepend"></Icon>
                </Input>
            </FormItem>
            <FormItem>
                <Button type="primary" @click="handleSubmit('formInline')" class="btnLogin">登录</Button>
            </FormItem>
        </Form>
          <p>
            <!-- <a class="left" @click="$router.push({path:'/register'})">注册新用户</a> -->
            <a class="left">注册新用户</a>
            <a class="right">忘记密码?</a></p>
        </div>
      </div>
    </div>
</template>

<script>
  import axios from './../assets/js/axios'
    export default {
        name: "Login",
        data(){
          return{
            formInline:{
              user:'18888888888',
              password:'123456'
            },
            ruleInline: {
                user: [
                    { required: true, message: '请输入用户名', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { type: 'string', min: 5, message: '密码长度不能小于5位', trigger: 'blur' }
                ]
            }
          }
        },
      mounted(){
       
      },
      methods:{
          handleSubmit(name) {
            let _this=this;
            this.$refs[name].validate((valid) => {
                if (valid) {
                  axios.post('/passport/login',{
                    appType:'1',
                    mobile:_this.formInline.user,
                    password:_this.formInline.password,
                    userType:'1'
                  }).then(res=>{
                    if(res){
                       _this.$Message.info(res.data.msg);
                      sessionStorage.setItem('adminToken',res.data.data.token);
                      axios.post('/common/common/selectDictDataList','post',{
                      }).then(res=>{
                        if(res){
                          let list=JSON.stringify(res.data.data);
                          localStorage.setItem('selectList',list);
                           _this.$router.push({path:'/index'});
                        }
                      })
                    }
                  })
                } else {
                    this.$Message.error('失败，请重新输入');
                }
            })
          }
      }
    }
</script>

<style scoped>
  .container{
    position: relative;
    height: 100%;
    width: 100%;
    background: url("./../assets/img/login.png") no-repeat;
    background-size: cover;
  }
  .mainBox{
    position: absolute;
    box-shadow: 0 0 25px #00507e;
    width: 554px;
    height: 420px;
    top:50%;
    left:50%;
    margin-top: -206px;
    margin-left: -277px;
    background-color: #fff;
    border-radius: 10px;
  }
  .mainTitle{
    height: 159px;
    line-height: 159px;
    background-color: #00507e;
    border-top-left-radius: 9px;
    border-top-right-radius: 9px;
  }
  .mainTitle img{
    margin: 52px 0 0 95px;
    width: 371px;
  }
  .main{
    height: 253px;
    text-align: center;
    padding: 50px 80px 0;
    font-size: 14px;
  }
  .btnLogin{
    width: 100%;
    background-color: #00507e;
    border: none;
    outline: none;
    color:#ffffff;
    cursor: pointer;
  }
</style>
