<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in"  :bordered="false" style="border-radius:0px">
        <p   slot="title" @click.prevent="ispasslogin=false">
            <a href="#"> 验证码登录</a>
        </p>
           <p slot="extra" @click.prevent="ispasslogin=true">
            <a href="#" >密码登录</a>
        </p>

        <div class="form-con">
           <MobileForm v-if="!ispasslogin" @on-success-valid="handleSubmit" @onsendvcode="onsendvcode"></MobileForm>
          <login-form    v-if="ispasslogin" @on-success-valid="handleSubmit"></login-form>
     
          <p class="login-tip">验证码登录，如果不存在就自动完成注册</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import {
  sendVCode,
} from "@/api/user";
import LoginForm from '_c/login-form'
import MobileForm from '_c/phone-form'
import { mapActions } from 'vuex'
export default {
  data(){
    return{
      ispasslogin:false
    }
  },
  components: {
    LoginForm,
    MobileForm
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getUserInfo'
    ]),
    onsendvcode(obj){
          sendVCode(obj).then((res)=>{
            let ret=res.data
            console.log(res.data)
          })
    },
    handleSubmit (upobj) {
      this.handleLogin(upobj).then(res => {
         this.$router.push({
            name: this.$config.homeName
        })
      }).catch(err=>{
            this.$Notice.error({
                    title: '系统通知',
                    desc:  '账号或密码有误！'
                });
      })
    }
  }
}
</script>

<style>

</style>
