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

<script>
import loginDetail from '@/components/login.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
import _ from 'loadsh';
const { mapActions: mapSite } = createNamespacedHelpers('site');
const { mapActions: mapMarket } = createNamespacedHelpers('market');

export default {
  name: 'login',
  props: {},
  components: {
    loginDetail,
  },
  data: () => ({
    info: {},
    form: {},
    forms: {},
  }),
  created() {
    this.searchSite();
  },
  computed: {
    keyWord() {
      let meta = this.$route.meta;
      let main = meta.title || '';
      return main;
    },
  },
  methods: {
    ...mapSite(['showInfo']),
    ...mapMarket({ userFetch: 'fetch', userCreate: 'create', userUpdate: 'update' }),
    // 查询站点信息
    async searchSite() {
      let res = await this.showInfo();
      let object = JSON.parse(JSON.stringify(res.data));
      if (object) {
        this.$set(this, `info`, res.data);
      } else {
        this.$message.error(res.errmsg ? res.errmsg : 'error');
      }
    },
    async submitLogin(form) {
      console.log('登录');
    },
    async submitRegister(forms) {
      // let data = this.forms;
      // let res;
      // let msg;
      // if (data.id) {
      //   res = await this.userUpdate(data);
      //   msg = `${this.keyWord}修改成功`;
      // } else {
      //   res = await this.userCreate(data);
      //   msg = `${this.keyWord}注册成功`;
      // }
      // console.log(res);
      // if (this.$checkRes(res, msg)) this.$router.push({ path: '/login' });
      let data = this.forms;
      let res = await this.userCreate(data);
      let msg = `${this.keyWord}注册成功`;
      if (this.$checkRes(res, msg)) this.$router.push({ path: '/login' });
    },
  },
};
</script>

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