<route lang="json">
{ "style": { "navigationBarTitleText": "", "navigationBarBackgroundColor": "#fff" } }
</route>
<script setup lang="ts">
import { phone, right } from '../../../core/libs/svgs'
import { pageReferrerDetail, getDistributePage, referrerCount } from '../../../core/libs/requests'
import { handleCall } from '../../../core/utils/common'
import { onLoad } from '@dcloudio/uni-app'
import PageHelperEvo from '@/components/page-helper-evo.vue'
import { ComponentExposed } from 'vue-component-type-helpers'

const PageHelperEvoRef = ref<ComponentExposed<typeof PageHelperEvo>>()
const referrerId = ref<number | string>('')
const { data: count, run: setCount } = useRequest(() => referrerCount({ referrerId:referrerId.value }))
const queryReward = computed(() => ({ status: tabsReward.value[tab.value]?.value }))
const queryRecommend = computed(() => (referrerId.value?{ auditStatus: tabsRecommend.value[tab.value]?.value, referrerId:referrerId.value }:{auditStatus: tabsRecommend.value[tab.value]?.value}))

const type = ref("recommend")
const tab = ref(0)
const tabsReward = ref([
  {
    label: '已完成',
    value: "1",
  },
  {
    label: '待入账',
    value: "2"
  },
  {
    label: '已取消',
    value: "3",
  },
])

const tabsRecommend  = ref([
  {
    label: '已认证',
    value: "0",
  },
  {
    label: '审核中',
    value: "1"
  },
  {
    label: '未通过',
    value: "2",
  },
])

const handleClick = () => {
  uni.navigateTo({ url: '/pages-sub/mine/orders/detail/index' })
}

const toSecond = (record) =>{
	referrerId.value = record.userId
	PageHelperEvoRef.value?.reload()
	uni.setNavigationBarTitle({
		title:record.name + "的推荐"
	})
}

const handleChange = async (value) => {
 console.log(value)
}

onLoad(async (options)=>{
	console.log(decodeURIComponent(options.str))
	let ob = JSON.parse(decodeURIComponent(options.str))
	referrerId.value = ob.userId
	let res = await setCount();
	tabsRecommend.value[0].label = tabsRecommend.value[0].label + "(" +res.onePassCount+ ")"
	tabsRecommend.value[1].label = tabsRecommend.value[1].label + "(" +res.oneWaitCount+ ")"
	tabsRecommend.value[2].label = tabsRecommend.value[2].label + "(" +res.oneRejectCount+ ")"
	uni.setNavigationBarTitle({
		title:ob.name + "的推荐"
	})
})

</script>
<template>
	<view class="flex flex-col">
		<PageHelperEvo ref="pageHelperRef" class="flex-grow flex" :request="pageReferrerDetail" :query="type === queryRecommend">
			<template #top>
			  <wd-tabs v-model="tab" @change="handleChange">
			    <block v-for="({ label }, i) in tabsRecommend" :key="i">
			      <wd-tab :title="`${label}`" class="relative"></wd-tab>
			    </block>
			  </wd-tabs>
			</template>
			<template #default="{ source }">
				<view class="bg-white rounded-[20rpx] mx-[24rpx] mt-[30rpx] px-[20rpx] py-[30rpx]">
					<view class="py-[30rpx]" v-for="(it, i) in source.list" :key="i">
						<view class="flex items-center pb-[20rpx]" style="border-bottom: 2rpx solid #FAFAFA;">
							<view class="rounded-full w-[88rpx] h-[88rpx] overflow-hidden mr-[20rpx]">
								<image :src="it.avatar" mode="widthFix"></image>
							</view>
							<view class="flex-grow text-[32rpx]">{{ it.name }}</view>
						</view>
						<view class="text-[24rpx] text-[#EF4343] pl-[108rpx] pt-[20rpx] pr-[20rpx]" v-if="it.auditStatus == 2">原因：{{ it.reason }}</view>
					</view>
				</view>
			</template>
		</PageHelperEvo>
	</view>
</template>
