<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'" @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: "", //进度
      doubt_code: window.localStorage.getItem("doubt_code"),
      doubt_info: window.localStorage.getItem("doubt_info"),
      doubt_check: window.localStorage.getItem("doubt_check"),
      status_val: "",
    };
  },
  created() {
    this.type = this.$route.params.type;
    console.log(this.$route, "router");
    // this.statuss();
    this.signUpInit();
  },
  mounted() {
    this.signUpInit();
  },
  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: {
    // 点击下一步，触发父组件方法
    statuss(val) {
      console.log(val, "statuss");
      this.status_val = val;
      // if (this.status_val == 1) {
      //   this.type = "invitation";
      //    this.status = 1;
      // } else if (this.status_val == 2) {
      //   this.type = "referInfo";
      //    this.status = 3;
      // } else if (this.status_val == 3) {
      //   this.type = "check";
      // } else if (this.status_val == 4) {
      //   this.type = "pay";
      // } else if (this.status_val == 5) {
      //   this.type = "success";
      // }
      this.signUpInit(this.status_val);
    },
    // status=4,跳到审核页面；status=3时，根据doubt_check做判断
    signUpInit(status_val) {
      // console.log(status_val, "11111");
      signUpInit({}).then((res) => {
        console.log(res, "signUpInit");
        if (res.data.code != 200) {
          return this.$message.error(res.data.message);
        }
        this.status = res.data.status;
        // 点击下一步传值给status,更新
        if (status_val != null) {
          this.status = status_val;
        }
        // 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) {
          // 是否填写个人资料
          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) {
          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>
