<template>
  <div id="register">
    <admin-frame :usePage="false" topType="2" :leftArrow="false" :rightArrow="false" :useNav="false">
      <template v-slot:info>
        <van-col span="24" class="one">
          <register-1 :form="perForm" @onSubmit="onSubmit" @next="next" @reseat="reseat" v-if="active == '1'"></register-1>
          <register-2 :form="orgForm" @onSubmit="orgSubmit" @up="up" @reseat="reseat" v-else-if="active == '2'"></register-2>
        </van-col>
      </template>
    </admin-frame>
  </div>
</template>

<script>
import register1 from '@/layout/login/register-1.vue';
import register2 from '@/layout/login/register-2.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: personal } = createNamespacedHelpers('personal');
const { mapActions: organization } = createNamespacedHelpers('organization');
export default {
  name: 'register',
  props: {},
  components: {
    adminFrame,
    register1,
    register2,
  },
  data: function () {
    return {
      active: '1',
      perForm: { type: '4' },
      orgForm: {},
    };
  },
  async created() {},
  methods: {
    ...personal({ personalCreate: 'create' }),
    ...organization({ organizationCreate: 'create' }),
    async onSubmit(data) {
      let res = await this.personalCreate(data);
      if (this.$checkRes(res)) {
        this.$toast({ type: 'success', message: '注册成功，待管理员审核通过,方可登录' });
        this.$router.push({ path: '/login' });
      } else {
        this.$toast({ type: 'fail', message: res.errmsg });
      }
    },
    async orgSubmit(data) {
      let newData = { ...data, ...this.perForm };
      let res = await this.organizationCreate(newData);
      if (this.$checkRes(res)) {
        this.$toast({ type: 'success', message: '注册成功，待管理员审核通过,方可登录' });
      } else {
        this.$toast({ type: 'fail', message: res.errmsg });
      }
    },
    // 下一步
    next() {
      this.active = '2';
    },
    // 上一步
    up() {
      this.active = '1';
    },
    // 取消注册
    reseat() {
      this.$router.push({ path: '/login' });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

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