<template>
  <basic-container>
    <div class="registerSteps">
     <!--

      <el-steps :active="active" align-center process-status="finish">
        <el-step title="用工单位信息"></el-step>
        <el-step title="法人认证"></el-step>
        <el-step title="等待审核"></el-step>
        <el-step title="完成认证"></el-step>
      </el-steps>-->
      <div class="pageContainer">
        <company-info
          v-model="form"
          v-show="active === 0"
          @submit="setCompany"
        ></company-info>
        <legal-person
          v-model="form"
          v-show="active === 1"
          @submit="setMaster"
          :go-back="goBack"
        ></legal-person>
        <waiting-check
          :status="form.status"
          :remarks="form.remarks"
          v-show="active === 2"
          @submit="
            () => {
              active = 0;
            }
          "
        ></waiting-check>
        <finish v-show="active === 3"></finish>
      </div>
    </div>
  </basic-container>
</template>

<script>
import { getBaseDetail } from "@/api/tenant/company";
import { submit } from "@/api/tenant/auth";
import CompanyInfo from "./companyInfo";
import LegalPerson from "./legalPerson";
import WaitingCheck from "./waitingCheck";
import finish from "./finish";

export default {
  components: {
    CompanyInfo,
    LegalPerson,
    WaitingCheck,
    finish,
  },
  data() {
    return {
      form: {
        companyName: "",
        companyTid: "",
        cityId: "",
        companyAddress: "",
        tradeId: "",
        authUrlId: "",
        masterName: "",
        masterIdentity: "",
        identityUrl4Id: "",
        identityUrl5Id: "",
        status: -1,
      },
      company: {},
      active: 0,
    };
  },
  created() {
    this.getInfo(() => {
      if (this.form.status === 1) {
        this.createTimer();
      }
    });
    if (this.auth === "1") {
      this.active = 2;
    }
    console.log('auth:'+this.active);
  },
  methods: {
    /*获取基本信息*/
    getInfo(cb) {
      getBaseDetail().then((res) => {
        console.log(res)
        this.form = res.data.data;
        cb && cb();
        if (this.form.status === 0) {
          this.active = 3;
        }
      });
    },
    goBack() {
      this.active--;
    },
    setCompany(info) {
      this.company = info;
      this.active = 1;
    },
    setMaster(info, cb) {
      this.master = info;
      submit({ ...this.company, ...info })
        .then(() => {
          cb && cb();
          this.$store.commit("SET_AUTH", "1");
          this.active = 2;
          this.form.status = 1;
          this.createTimer();
        })
        .catch((err) => {
          cb && cb(err);
        });
    },
    createTimer() {
      const timer = setInterval(() => {
        this.getInfo(() => {
          if (this.form.status !== 1) {
            clearInterval(timer);
          }
        });
      }, 60000);
    },
  },
  watch: {},
  computed: {
    auth() {
      return this.$store.state.user.auth;
    },
  },
};
</script>

<style>
.registerSteps,
.pageContainer {
  margin-top: 15px;
}
</style>