<template>
	<view v-if="show" style="padding: 15px;">
		<!-- 等待审核 -->
		<view v-if="applyInfo?.status === '0'">
			<view class="d-flex flex-column align-center">
				<image src="/static/svg/submit.svg" style="height: 200px; width: "></image>
			</view>
			<view>
        您的企业账号申请<span class="color-primary font-size-20 font-weight-bold"> 正在审核中，</span>审核时间在1~3个工作日内，申请结果会以短信方式通知到您的手机上，请注意查收。
      </view>
      <view class="ss-m-t-30">
        <span>提交时间：{{ applyInfo.createTime }}</span>
      </view>
      <view style="width: 100%;">
        <view class="mt-5 mb-1">如有疑问请长按二维码添加下方企业微信联系我们：</view>
        <view style="width: 150px; height: 150px; margin: auto;">
					<image show-menu-by-longpress="true" src="https://minio.menduner.com/dev/menduner/contact.png" style="width: 150px; height: 150px;"></image>
        </view>
        <view class="text-center ml-5">潘青海先生（Peter Pan）</view>
      </view>
		</view>

		<!-- 审核不通过 -->
		<view v-else-if="applyInfo?.status === '2'" class="ss-m-b-100">
			<view class="ss-m-b-20 color-error">
        您的企业账号注册申请<span class="color-error font-size-20 font-weight-bold"> 审核不通过</span>
      </view>
			<view class="ss-m-b-20 color-error">具体原因如下：{{ applyInfo.reason }}</view>
      <view v-if="applyInfo.remark">备注：{{ applyInfo.remark }}</view>
      <view class="mt-5">
        <span>审核时间：{{ applyInfo.updateTime }}</span>
      </view>
      <view>
        <span>提交时间：{{ applyInfo.createTime }}</span>
      </view>
      <view style="width: 100%;">
        <view class="mt-5 mb-1">如有疑问请长按二维码添加下方企业微信联系我们：</view>
        <view style="width: 150px; height: 150px; margin: auto;">
          <image show-menu-by-longpress="true" src="https://minio.menduner.com/dev/menduner/contact.png" style="width: 150px; height: 150px;"></image>
        </view>
        <view class="text-center ml-5">潘青海先生（Peter Pan）</view>
      </view>
		</view>
		
		<!-- 提交企业注册以后跳转显示页面 -->
		<view v-else>
			<view class="d-flex flex-column align-center">
				<image src="/static/svg/submit.svg" style="height: 200px; width: "></image>
			</view>
			<view style="text-align: center;"><span class="color-primary font-size-20 font-weight-bold">您的企业注册申请已提交</span></view>
      <view class="mt-5">审核时间预计在1~3个工作日内，申请结果会以短信方式通知到您的手机上，请注意查收。</view>
      <view style="width: 100%;">
        <view class="mt-5 mb-1">如有疑问请长按二维码添加下方企业微信联系我们：</view>
        <view style="width: 150px; height: 150px; margin: auto;">
					<image show-menu-by-longpress="true" src="https://minio.menduner.com/dev/menduner/contact.png" style="width: 150px; height: 150px;"></image>
        </view>
        <view class="text-center ml-5">潘青海先生（Peter Pan）</view>
      </view>
		</view>

		<view class="d-flex align-center">
			<!-- <button :class="{'second-button': applyInfo.status === '2', 'send-button': applyInfo.status !== '2'}" @tap="handleToHome">回到首页</button> -->
			<button v-if="applyInfo.status === '2'" class="recomm-button" @tap="handleConfirm">重新提交</button>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue'
import { getUserRegisterEnterpriseApply } from '@/api/enterprise.js'
import { timesTampChange } from '@/utils/date'
import { onLoad } from '@dcloudio/uni-app'
import { userStore } from '@/store/user'

const user = userStore()
const applyInfo = ref({})
const show = ref(false)

// 查看用户是否有在申请中的数据
const getApplyInfo = async () => {
	// 已经有数据说明已经申请过了
	let result = {}
	if (hasData && uni.getStorageSync('entRegisterData')) {
		result = JSON.parse(uni.getStorageSync('entRegisterData'))
	} else {
		const { data } = await getUserRegisterEnterpriseApply()
		result = data || {}
		uni.setStorageSync('applyInfo', JSON.stringify(result))
	}
	
  applyInfo.value = {
		phone: result.phone,
    createTime: timesTampChange(result.createTime), // 创建时间
    updateTime: timesTampChange(result.updateTime), // 更新时间
    status: result.status, // 审核状态（0审核中 1审核通过 2审核不通过）） // 审核状态
    reason: result.reason, // 审核原因
    remark: result.remark // 备注
  }
  console.log(result, 'review----查看是否有申请中的数据', applyInfo.value)
	show.value = true
}

let hasData = false
onLoad((options) => {
	hasData = options?.hasData ? true : false
	getApplyInfo()
})


// 回到首页时需将当前个人登录状态及缓存中的数据清除
const handleToHome = async () => {
	await user.handleUserLogout()
	uni.reLaunch({
		url: '/pages/index/my'
	})
}

const handleConfirm = () => {
	if (uni.getStorageSync('token') && uni.getStorageSync('isPersonalToken')) {
		uni.navigateTo({ url: '/pages/register/index' })
		return
	}
	uni.reLaunch({
		url: `/pages/register/phoneValidate?phone=${applyInfo.value?.phone}`
	})
}
</script>

<style scoped lang="scss">

</style>
