<template>
  <div id="login-2">
    <van-row>
      <van-col span="24" class="main">
        <van-form @submit="onSubmit" label-width="4em">
          <van-field v-model="form.code_phone" name="code_phone" label="账号" placeholder="账号" :rules="[{ required: true, message: '账号' }]" />
          <van-field v-model="form.passwd" type="password" name="passwd" label="密码" placeholder="密码" :rules="[{ required: true, message: '密码' }]" />
          <div style="margin: 16px">
            <van-button round block type="info" native-type="submit">登录</van-button>
          </div>
        </van-form>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: adminLogin } = createNamespacedHelpers('adminLogin');
export default {
  name: 'login-2',
  props: {},
  components: {},
  data: function () {
    return {
      form: {},
    };
  },
  created() {},
  methods: {
    ...adminLogin(['login']),
    async onSubmit(values) {
      let res = await this.login({ user: values });
      if (this.$checkRes(res)) {
        if (this.path) this.$router.push({ path: this.path });
        else this.$router.push({ path: '/account/index' });
      } else {
        this.$toast({ type: 'fail', message: res.errmsg });
      }
    },
  },
  computed: {
    ...mapState(['user']),
    path() {
      return this.$route.query.path;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped></style>
