<template>
  <view class="content">
    <button class="addEnterprise" type="primary" @click="toBaseInfo">
      {{ "新 增 工 商 主 体" }}
    </button>
    <button type="isSkip" class="skip" @click="isSkip = !isSkip">
      {{ "稍 后 创 建 " + ">>" }}
    </button>
  </view>
</template>

<script>
import { selectUserEntity } from "@/api/enterprise/userEntity";
export default {
  data() {
    return {
      haveEnterprise: false,
      isSkip: false,
    };
  },
  watch: {
    haveEnterprise: {
      handler: function (val, oldVal) {
        if (this.haveEnterprise === true) {
          this.isHav();
        }
      },
      deep: true,
    },
    isSkip: {
      handler: function (val, oldVal) {
        this.isHav();
      },
      deep: true,
    },
    routeOption: {},
  },
  created() {
    this.getEnterprise();
  },
  methods: {
    toBaseInfo() {
      uni.navigateTo({
        url: "/pages/formPages/enterprise/baseInfo/index",
      });
    },
    isHav() {
      if (this.haveEnterprise === true || this.isSkip === true) {
        if (JSON.parse(this.routeOption.revisePass) === true && this.haveEnterprise === true) {
          uni.reLaunch({
            url: '/pages/index?revisePass=true'
          })
        } else {
          uni.reLaunch({
            url: '/pages/index'
          })
        }
      }
    },
    getEnterprise() {
      selectUserEntity().then((response) => {
        if (response.data.length !== 0) {
          this.haveEnterprise = true;
        } else {
          this.haveEnterprise = false;
        }
      });
    },
    showSuccTip(option) {
      const _this = this;
      if (
        option.revisePass !== undefined &&
        JSON.parse(option.revisePass) === true
      ) {
        var failTimeout = setTimeout(function () {
          _this.$modal.msgSuccess("密码修改成功");
        }, 100);
      }
    },
  },

  onLoad(option) {
    this.routeOption =
    option.revisePass === undefined ? { revisePass: false } : option;
    this.showSuccTip(option);
  },
};
</script>

<style lang="scss" scoped>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: white;
  height: calc(100vh - calc(44px + var(--status-bar-height)));

  .addEnterprise {
    font-size: 20px;
  }

  .skip {
    border: 0px;
    background-color: white;
    position: absolute;
    bottom: 0px;
    right: 0px;
  }

  .skip::after {
    content: none;
  }

  .skip:hover {
    color: #00a2ff;
  }
}</style>
