<template>
  <div class="signUp">
    <div class="content">
      <div class="signUp_titile">营地报名</div>
      <div>
        <Breadcrumb :statusNum="status"> </Breadcrumb>
      </div>
    </div>
    <Confirm v-if="type == 'examInfo'" @getstatus="statuss"></Confirm>
    <Invitation
      v-else-if="type == 'invitation'"
      @getstatus="statuss"
    ></Invitation>
    <ReferInfo v-else-if="type == 'referInfo'" @getstatus="statuss"></ReferInfo>
    <Pass
      v-else-if="type == 'check'"
      @is_next="is_nextevent"
      :getExamine="getExamine"
    ></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: "", //进度
      doubt_code: window.localStorage.getItem("doubt_code"),
      doubt_info: window.localStorage.getItem("doubt_info"),
      doubt_check: window.localStorage.getItem("doubt_check"),
      status_val: "",
      getExamine: "",
      isNexts: "",
    };
  },
  created() {
    this.type = this.$route.params.type;
    // console.log(this.$route, "router");
    this.statuss();
  },

  watch: {
    $route: {
      handler(val) {
        // console.log(val, "routeval");
        const that = this;
        if (val.path.indexOf("signUp") != -1) {
          that.type = val.params.type;
        }
      },
      deep: true,
    },
    status(val) {
      // console.log(val, "status");
    },
  },
  methods: {
    is_nextevent(val) {
      this.isNexts = val;
      console.log(val, "isNexts");
      //  this.signUpInit(  this.isNexts );
      this.signUpInit(this.status_val);
    },
    // 点击下一步，触发父组件方法
    statuss(val) {
      // console.log(val, "statuss");
      this.status_val = val;

      this.signUpInit(this.status_val);
    },
    // status=4,跳到审核页面；status=3时，根据doubt_check做判断
    signUpInit(status_val) {
      // console.log(status_val, "11111");

      // console.log(isNexts, "2222");
      signUpInit({}).then((res) => {
        // console.log(res, "signUpInit");
        if (res.data.code != 200) {
          return this.$message.error(res.data.message);
        }
        this.status = res.data.status;
        // console.log(this.status, "11111");
        // 点击下一步传值给status,更新
        if (status_val != null) {
          this.status = status_val;
        } else {
          this.status = res.data.status;
          // console.log(this.status, "11111");
        }
        // 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 = 1;
          }
        } else if (this.status == 2) {
          // console.log(this.doubt_info, "doubt_info");
          // 是否填写个人资料
          if (this.doubt_info == 0) {
            this.type = "check";
            this.status = 3;
          } else {
            this.type = "referInfo";
            // this.status = 2;
          }
        } 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) {
          this.type = "check";
          this.status = 3;
          console.log(this.status, "this.status ");
          // console.log(this.isNexts ,'this.isNexts ')

          if (this.isNexts == 1) {
            // console.log(11111);
            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";
        }
        this.$emit("getStatus", this.type);
        this.getExamine = res.data.examine_status;
        // console.log(res.data.examine_status, "res.data.examine_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 28px;
  }
}
</style>
