<template>
	<view>
		<view class="swiper-container">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" style="height: 370rpx;">
				<swiper-item class="w-100 h-100" v-for="item in state.banner" :key="item.id">
					<image class="w-100 h-100" :src="item.image" mode=""></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="container">
			<view class="container-list">
				<view class="mb28 col3 font32">合伙人工作台</view>
				<!--  申请加入     -->
				<view class="container-list-but font28" v-if="userInfo.userHh!==1">
					<view class="flex flex-between">
						<view>
							<view class="font24 add-but col-white" @click="handleJoin(1)">申请加入 ></view>
						</view>
					</view>
				</view>
				<!-- 申请加入后       -->
				<view class="flex flex-between font24 flex-wrap" v-if="userInfo.userHh==1">
					<view class="icon-list" @click="handleGoto(1,item)" v-for="item in iconState.list1" :key="item.id">
						<up-image class="mb20" :show-loading="true" :src="item.image" width="68rpx"
							height="68rpx"></up-image>
						<view>{{item.name}}</view>
					</view>
					<view class="icon-list"></view>
				</view>
			</view>
			<view class="container-list">
				<view class="mb28 col3 font32">伴宠师工作台</view>
				<!--  申请之前       -->
				<view class="container-list-but" style="background: #FFECE5" v-if="userInfo.userBcs!==1">
					<view class="flex flex-between">
						<view>
							<view class="font24 add-but col-white" style="background: #FF8343" @click="handleJoin(2)">
								申请加入 ></view>
						</view>
					</view>
				</view>
				<!--  申请之后      -->
				<view class="flex-rowl flex-wrap" v-if="userInfo.userBcs===1">
					<view class="icon-list" v-for="item in iconState.list2" :key="item.id" @click="handleClick(item)">
						<up-image class="mb20" :show-loading="true" :src="item.image" width="68rpx"
							height="68rpx"></up-image>
						<view>{{ item.name }}</view>
					</view>
				</view>
			</view>
		</view>
		<ModalCom :open="isoOpen" @close="modalClose" />
	</view>

</template>

<script setup>
	import ModalCom from "./components/modal.vue"
	import {
		onShow
	} from "@dcloudio/uni-app"
	import {
		banner,
		joinHh,
		joiBcs,
		indexConfig,
		indexConfigIco,
		getbaseInfo
	} from "../../api/home.js"
	import {
		computed,
		onMounted,
		reactive,
		ref
	} from "vue";
	import tab from "../../plugins/tab";
	import {
		getLoginStatus
	} from "../../utils/useMixin";
	import {
		useStore
	} from "vuex"

	const store = useStore();
	const state = reactive({
		banner: []
	})
	onMounted(() => {
		getBanner()
		getpz()
		console.log("userInfo", userInfo)
	})
	const userInfo = computed(() => {
		return store.getters.userInfo
	})
	onShow(() => {

	})
	// 获取轮播图
	const getBanner = async () => {
		const res = await banner()
		if (res.code === 200) {
			state.banner = [...res.data]
		}
	}
	// 申请加入合伙人
	const num = ref(0)
	const isoOpen = ref(false)
	const handleJoin = (type) => {
		num.value = Number(type)
		const info = uni.getStorageSync("baseInfo")
		if (!info) {
			uni.navigateTo({
				url: "/pages/login/index"
			})
			return
		}
		const baseInfo = JSON.parse(info)
		if (type === 1) {
			joinHh({
				appUserId: baseInfo.userId
			}).then(res => {
				isoOpen.value = true
				changeBaseInfo(baseInfo.userId)
			}).catch(() => {})
		} else {
			joiBcs({
				appUserId: baseInfo.userId
			}).then(res => {
				isoOpen.value = true
				changeBaseInfo(baseInfo.userId)
			})
		}
	}
	// 更新基本信息
	const changeBaseInfo = (userId) => {
		getbaseInfo(userId).then(res => {

		})
	}

	const modalClose = () => {
		isoOpen.value = false
		if (num.value === 1) {
			show.value = false
		} else {
			show.value = false
		}

	}

	// 获取工作台图标
	const iconState = reactive({
		list1: [],
		list2: [],
	})
	const getpz = () => {
		indexConfig().then(res => {
			// 合伙人工作台菜单
			iconState.list1 = res?.rows?.slice(0, 4) || [];
			// 伴宠师工作台
			iconState.list2 = res?.rows?.slice(4) || [];
		})
	}

	const show = ref(true)
	const hhShow = ref(true)
	const handleGoto = (val, item) => {
		switch (item.id) {
			case 1:
				tab.navigateTo('/otherPages/binding/list/index')
				break;
			case 2:
				tab.navigateTo('/otherPages/workbenchManage/myUser/index')
				break;
			case 3:
				tab.navigateTo('/otherPages/workbenchManage/myLevel/index')
				break;
			case 4:
				// tab.navigateTo('/otherPages/binding/wallet/index')
				tab.navigateTo('/otherPages/workbenchManage/myWallet/index')
				break;
		}
	}
	// 加入合伙人
	const handleAdd = (type) => {
		if (!getLoginStatus()) return
		switch (type) {
			case 1:
				break
			case 2:
				tab.navigateTo("/otherPages/workbenchManage/feedingStaff/index")
				break
		}
	}

	const handleClick = (item) => {
		switch (item.code) {
			case "1":
				uni.navigateTo({
					url: "/otherPages/authentication/serve/index"
				})
				break;
			case "2":
				uni.navigateTo({
					url: "/otherPages/authentication/serve/record"
				})
				break;
			case "3":
				uni.navigateTo({
					url: "/otherPages/authentication/connectAddress/index"
				})
				break;
			case "4":
				break;
			case "5":
				uni.navigateTo({
					url: "/otherPages/orderTakingManage/evaluate/index"
				})
				break;
		}
	}

	const handleOpen = () => {
		show.value = false
	}
	const handleBc = () => {
		uni.navigateTo({
			url: "/otherPages/authentication/list/index"
		})
	}
</script>

<style scoped lang="scss">
	@import "index";
</style>