<template>
  <div >
    <van-nav-bar
      title="登录"      
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
      style="background-color:#ececec;"
    />

    <van-form @submit="onSubmit">
    <van-field
      v-model="username"
      name="用户名"
      label="用户名"
      placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
      v-model="password"
      type="password"
      name="密码"
      label="密码"
      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    />
    <div style="margin: 16px;">
      <van-button round block type="info" native-type="submit">提交</van-button>
    </div>
  </van-form>
  </div>
</template>

<script>
import {login} from '@/common/api/loginApi.js'
export default {
  name: 'login',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    onSubmit () {
      console.info('username', this.username)
      console.info('passowrd', this.password)
      var data = {userId: this.username, password: this.password, dNo: '', dToken: ''}
      login(data).then((res) => {
        console.info('res', res);
        let obj=res;
        //console.info('result',obj.result);
        if(!obj.result){
          this.$toast(obj.msg);
          return;
        }
        //设置状态中的各种值
        this.$store.commit('setResult',obj.result);
        this.$store.commit('setCode',obj.code);
        this.$store.commit('setMsg',obj.msg);
        this.$store.commit('setData',obj.data); 
        this.$router.push('/getproject');
      });
    },
    onClickLeft () {
      // this.$toast('返回')
      console.info('left')
    },
    onClickRight () {
      // this.$toast('按钮')
    }

  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
