<template>
  <div id="login">
    <login-detail :info="info" :form="form" @submitDate="submitLogin" :forms="forms" @submitDates="submitRegister"></login-detail>
  </div>
</template>

<script>
import loginDetail from '@/layout/login.vue';
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapMarket } = createNamespacedHelpers('market');
const { mapActions: login } = createNamespacedHelpers('login');
export default {
  name: 'login',
  props: {},
  components: { loginDetail },
  data: () => {
    return {
      info: {},
      form: {},
      forms: {},
    };
  },
  created() {},
  methods: {
    // ...mapSite(['showInfo', 'toGetUser']),
    ...mapMarket({ userFetch: 'fetch', userCreate: 'create', userUpdate: 'update' }),
    ...login({ toLogin: 'login' }),
    async submitLogin(form) {
      let res = await this.toLogin({ user: form });
      if (res.uid) {
        if (res.role == '2' || res.role == '3') this.$router.push('/enterprise/enterprisejb');
        else if (res.role == '5') this.$router.push('/hallList/index');
        else this.$router.push('/market/index');
      }
    },
    async submitRegister(forms) {
      let data = this.forms;
      let res = await this.userCreate(data);
      let msg = `注册成功`;
      this.$checkRes(res, msg);
    },
  },
  computed: {
    ...mapState(['user']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
    redirect_uri() {
      return `${this.$route.query.redirect_uri}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

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