<template>
  <div class="signUp">
    <div class="content">
      <div class="signUp_titile">营地报名</div>
      <div>
        <Breadcrumb :statusNum="status"> </Breadcrumb>
      </div>
    </div>
    <Confirm v-if="type == 'examInfo'" :statusNum="status"> </Confirm>
    <Invitation
      v-else-if="type == 'invitation'"
      :statusNum="status"
      @getstatus="statuss"
    >
    </Invitation>
    <ReferInfo v-else-if="type == 'referInfo'" @getstatus="statuss">
    </ReferInfo>
    <Pass v-else-if="type == 'check'" @getstatus="statuss"> </Pass>
    <Paying v-else-if="type == 'pay'" @getstatus="statuss"> </Paying>
    <Success v-else-if="type == 'success'" @getstatus="statuss"> </Success>
  </div>
</template>

<script>
/* eslint-disable */
import Breadcrumb from "c/breadcrumb";
import Confirm from "c/index/SignUp/confirm";
import Invitation from "c/index/SignUp/invitation";
import ReferInfo from "c/index/SignUp/referInfo";
import Pass from "c/index/SignUp/pass";
import Paying from "c/index/SignUp/paying";
import Success from "c/index/SignUp/success";
import { signUpInit } from "r/index/signUp";

export default {
  name: "signUp",
  components: {
    Breadcrumb,
    Confirm,
    Invitation,
    ReferInfo,
    Pass,
    Paying,
    Success,
  },
  data() {
    return {
      type: "examInfo",
      status: "", //进度
      // statuss:''
      doubt_code: window.localStorage.getItem("doubt_code"),
      doubt_info: window.localStorage.getItem("doubt_info"),
      doubt_check: window.localStorage.getItem("doubt_check"),
    };
  },
  created() {
    this.type = this.$route.params.type;
    // console.log(this.$route);
    this.signUpInit();
  },
  watch: {
    $route: {
      handler(val) {
        const that = this;
        if (val.path.indexOf("signUp") != -1) {
          that.type = val.params.type;
        }
      },
      deep: true,
    },
    status(val) {
      console.log(111, val);
    },
  },
  methods: {
    // 点击邀请码下一步传来的status
    statuss(val) {
      console.log(val, "val");
      // this.statuss = val;

      // this.signUpInit();
    },
    signUpInit() {
      // console.log(111);
      signUpInit({}).then((res) => {
        console.log(res, "signUpInit");
        if (res.data.code != 200) {
          return this.$message.error(res.data.message);
        }
        this.status = res.data.status;

        // doubt_code，doubt_info，doubt_check。0为不填写，1为填写
        if (this.status == 0) {
          this.type = "examInfo";
        } else if (this.status == 1) {
          //  是否填写邀请码
          if (this.doubt_code == 0) {
            this.type = "referInfo";
            this.status = 2;
          } else {
            this.type = "invitation";
            // this.status = 2;
          }
        } else if (this.status == 2) {
          // 是否填写个人资料
          if (this.doubt_info == 0) {
             this.type = "check";
            this.status = 3;
          } else {
          
              this.type = "referInfo";
          }
        } else if (this.status == 3) {
          // 是否审核个人资料
          if (this.doubt_check == 0) {
            this.type = "pay";
            this.status = 4;
          } else {
            this.type = "check";
            // this.status = 3;
          }
        } else if (this.status == 4) {
          if (res.data.examine_status == 0) {
            this.type = "check";
            this.status = 3;
          } else if (res.data.examine_status == 1) {
            // console.log(333);
            this.type = "pay";
            this.status = 4;
          } else if (res.data.examine_status == 2) {
            this.type = "referInfo";
            this.status = 2;
            return this.$message.error(res.data.examine_reason);
          }
        } else if (this.status == 5) {
          this.type = "pay";
        } else if (this.status == 6) {
          this.type = "success";
        }
        // console.log(this.status)
        //审核报名资料状态

        //订单支付金额
        window.localStorage.setItem("has_amount", res.data.has_amount);

        window.localStorage.setItem("campsite_id", res.data.campsite_id);
        window.localStorage.setItem("order_no", res.data.order_no);
      });
    },
  },
};
</script>

<style lang="scss" >
.flex {
  display: flex;
}

.signUp {
  background: #ffffff;
  width: 856px;
  .signUp_titile {
    font-size: 24px;
    font-weight: 500;
    color: #1b1419;
    line-height: 24px;
    margin-bottom: 40px;
  }
  .content {
    padding: 50px;
  }
}
</style>
