<template>
  <div class="page-redirect">
    <div class="redirect-page-status">
      <div
        v-if="isOrderEntry === 1"
        class="sign-contract-success"
      >
        <div class="icon">
          <image src="../../static/images/signing_success.png" />
        </div>
        <div class="tip">
          恭喜，已成功下单！
        </div>
      </div>
      <div
        v-else-if="isOrderEntry === 0"
        class="sign-contract-success"
      >
        <div class="icon">
          <image src="../../static/images/signing_fail.png" />
        </div>
        <div class="tip">
          支付失败！
        </div>
      </div>
      <div
        v-else-if="isSignSuccess === 1"
        class="sign-contract-success"
      >
        <div class="icon">
          <image src="../../static/images/signing_success.png" />
        </div>
        <div class="tip">
          恭喜，签约成功！
        </div>
      </div>
      <div
        v-else-if="isSignSuccess === 0"
        class="sign-contract-fail"
      >
        <div class="icon">
          <image src="../../static/images/signing_fail.png" />
        </div>
        <div class="tip">
          签约失败！
        </div>
      </div>
      <div
        v-else-if="isUpdateMobile === 1"
        class="mobile-success"
      >
        <div class="icon">
          <image src="../../static/images/set_phone_success.png" />
        </div>
        <div class="tip">
          恭喜，设置手机号成功！
        </div>
      </div>
      <div
        v-else-if="isSetPayPwd === 1"
        class="set-pay-pwd-success"
      >
        <div class="icon">
          <image src="../../static/images/set_password_success.png" />
        </div>
        <div class="tip">
          恭喜，密码设置成功！
        </div>
      </div>
      <div
        v-else-if="isBuyVip === 1"
        class="set-vipcard"
      >
        <div class="icon">
          <image src="../../static/images/set_VIPcard_success.png" />
        </div>
        <div class="tip">
          恭喜，购买会员成功！
        </div>
      </div>
      <div
        v-else-if="isBuyVip === 0"
        class="set-vipcard"
      >
        <div class="icon">
          <image src="../../static/images/set_VIPcard_fail.png" />
        </div>
        <div class="tip">
          购买失败！
        </div>
      </div>
    </div>
    <div
      class="back-app"
      @tap="onBackApp"
    >
      返回App
    </div>
  </div>
</template>

<script setup>

const urlSchemes = import.meta.env.VITE_APP_URL_SCHEMES
const isSignSuccess = ref(-1) // 是否签约成功 0:失败 1:成功
const isUpdateMobile = ref(-1) // 是否更新手机号 1:是
const isSetPayPwd = ref(-1) // 是否设置支付密码 1:是
const isBuyVip = ref(-1) // 是否购买会员 1:是
const isOrderEntry = ref(-1) // 是否订单进入且成功支付 1:支付成功 0：支付失败
onLoad((option) => {
  // 获取页面返回参数，并设置页面标题
  if (option.isOrderEntry && (Number(option.isOrderEntry) || Number(option.isOrderEntry) === 0)) {
    isOrderEntry.value = Number(option.isOrderEntry)
  } else if (option.isSignSuccess && (Number(option.isSignSuccess) || Number(option.isSignSuccess) === 0)) {
    // 判断是否为签约页面返回
    isSignSuccess.value = Number(option.isSignSuccess)
    uni.setNavigationBarTitle({
      title: '提现签约'
    })
  } else if (option.isUpdateMobile && Number(option.isUpdateMobile)) {
    // 判断是否为设置手机号页面返回
    isUpdateMobile.value = Number(option.isUpdateMobile)
    uni.setNavigationBarTitle({
      title: '设置手机号'
    })
  } else if (option.isSetPayPwd && Number(option.isSetPayPwd)) {
    // 判断是否为设置支付密码页面返回
    isSetPayPwd.value = Number(option.isSetPayPwd)
    uni.setNavigationBarTitle({
      title: '设置密码'
    })
  } else if (option.isBuyVip) {
    // 判断是否为购买Vip页面返回
    isBuyVip.value = Number(option.isBuyVip)
    uni.setNavigationBarTitle({
      title: '会员卡'
    })
  }
})

const onBackApp = () => {
  const platform = uni.getSystemInfoSync().platform
  if (platform === 'ios') {
    if (isBuyVip.value !== -1) {
      window.location.href = `cn.net.${urlSchemes}://app?isBuyVip=${isBuyVip.value}`
      return
    }
    window.location.href = `cn.net.${urlSchemes}://app`
  }
  if (platform === 'android') {
    if (isBuyVip.value !== -1) {
      window.location.href = `${urlSchemes}://app?isBuyVip=${isBuyVip.value}`
      return
    }
    window.location.href = `${urlSchemes}://app`
  }
}

</script>

<style lang="scss" scoped>
@use "./redirect.scss";
</style>
