<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"></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";
import Cookie from "js-cookie";

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();
    // 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: {
    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(11111);
      // console.log(status_val, "11111");
      // console.log(isNexts, "2222");
      signUpInit({}).then((res) => {
        // console.log(22222);
        console.log(res, "signUpInit");
        if (res.data.code != 200) {
          // if (res.data.code == 400001) {
          //   this.status = 6;
          //   this.type = "success";
          // } 
          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");

        //订单支付金额
        let code =this.$store.state.indexIdentity
        window.localStorage.setItem("has_amount"+code, res.data.has_amount);
        window.localStorage.setItem("campsite_id"+code, res.data.campsite_id);
        window.localStorage.setItem("order_no"+code, res.data.order_no);
        window.localStorage.setItem("examine_status"+code, res.data.examine_status); //返回错误原因
        window.localStorage.setItem("examine_reason"+code, res.data.examine_reason); //资料审核状态
        // window.localStorage.setItem("achievement_path", res.data.achievement_path); //上传的图片
        const aPath = res.data.achievement_path;
        if (aPath) {
          let arr = aPath.split(",");
          let fileList = [];
          fileList = arr.map((item) => {
            let obj = {
              url: item,
            };
            return obj;
          });
          const code = this.$store.state.indexIdentity;
          window.localStorage.setItem(
            "sign_up_file_" + window.localStorage.getItem("phone" + code),
            JSON.stringify(fileList)
          ); //上传的图片
        }
      });
    },
  },
};
</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>
