<template>
	<layout>
		<uv-navbar :fixed="false" :title="title" left-arrow @leftClick="$onClickLeft" />
		<view class="container">
			<view class="my-background">
				<view class="flex justify-between align-center login-info">
					<view class="flex">
						<image :src="member.avatar ? member.avatar : '/static/images/mine/default.png'"
							class="rounded-circle avatar-img"></image>
						<view class="flex flex-column text-white justify-center align-cente ml-2">
							<text class="nick-text">{{member.nickname}}</text>
							<text class="id-text">{{roleName}}</text>
						</view>
					</view>
					<!-- 	<view class="mt-2 mr-4" @tap="gopage('/pages/components/pages/mine/index')">
						<image src="/static/images/mine/set.png" class="setting-icon-img"></image>
					</view> -->
				</view>
				<view style="padding: 0 30rpx;">
					<view class="user-box">
						<!-- 
							<view class="user-grid" @click="gopage('/pages/components/pages/mine/list')">
								<view class="value font-size-extra-lg font-weight-bold text-color-base position-relative">
									<uv-badge type="error" max="99" :value="noticeCount" :absolute="true" :offset="[-5,-5]"></uv-badge>
									<image src="/static/images/12.png" class="icon-img"></image>
								</view>
								<view class="font-size-sm text-color-assist">通知</view>
							</view> 
						-->
						<view class="user-grid" @click="gopage('/pages/components/pages/msg/wait')">
							<view class="value font-size-extra-lg font-weight-bold text-color-base position-relative">
								<uv-badge type="error" max="99" :value="waitCount" :absolute="true" :offset="[-10,-10]"></uv-badge>
								<image src="/static/images/13.png" class="icon-img"></image>
							</view>
							<view class="font-size-sm text-color-assist">待办</view>
						</view>
						<view class="user-grid" @click="gopage('/pages/components/pages/msg/exam')">
							<view class="value font-size-extra-lg font-weight-bold text-color-base position-relative">
								<uv-badge type="error" max="99" :value="checkCount" :absolute="true" :offset="[-10,-10]"></uv-badge>
								<image src="/static/images/14.png" class="icon-img"></image>
							</view>
							<view class="font-size-sm text-color-assist">审批</view>
						</view>
					</view>
				</view>
			</view>

			<view class="customer-management">
				<view class="title">
					客户管理
				</view>
				<uv-grid :col="4" :border="false" @click="onGrid">
					<uv-grid-item v-for="(item, index) in orderTabs" :key="index" :customStyle="customStyle"
						@click="item.name == '客户' ? gopage2(item.path) : gopage(item.path)">
						<uv-icon :name="item.image" :size="30"></uv-icon>
						<text class="p-1 font-size-sm text-color-assist">{{ item.title }}</text>
					</uv-grid-item>
				</uv-grid>
			</view>

			<view class="customer-management">
				<view class="title">
					办公
				</view>
				<uv-grid :col="4" :border="false" @click="onGrid">
					<uv-grid-item :customStyle="customStyle" @click="navigateToMiniProgram()">
						<uv-icon name="/static/images/OA.png" :size="30"></uv-icon>
						<text class="p-1 font-size-sm text-color-assist">中鼐智能</text>
					</uv-grid-item>
					<uv-grid-item v-for="(item, index) in orderTabs2" :key="index" :customStyle="customStyle"
						@click="gopage(item.path)">
						<uv-icon :name="item.image" :size="30"></uv-icon>
						<text class="p-1 font-size-sm text-color-assist">{{ item.title }}</text>
					</uv-grid-item>
				</uv-grid>
			</view>

			<view class="customer-management">
				<view class="title">
					数据分析
				</view>
				<uv-grid :col="4" :border="false" @click="onGrid">
					<uv-grid-item v-for="(item, index) in orderTabs3" :key="index" :customStyle="customStyle"
						@click="gopage(item.path)">
						<uv-icon :name="item.image" :size="30"></uv-icon>
						<text class="p-1 font-size-sm">{{ item.title }}</text>
					</uv-grid-item>
				</uv-grid>
			</view>
		</view>
	</layout>
</template>

<script setup>
	import {
		ref,
		computed
	} from 'vue'
	import {
		useMainStore
	} from '@/store/store'
	import {
		storeToRefs
	} from 'pinia'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		userGetUserInfo
	} from '@/api/user'
	const main = useMainStore()
	const {
		member,
		isLogin,
		indexCount
	} = storeToRefs(main)

	const title = ref('个人中心')
	const services = ref([])
	const orderTabs = [{
			title: '公海客户',
			index: 1,
			image: '/static/images/index002.png',
			path: '/pages/components/pages/customer/open'
		},
		{
			title: '线索',
			index: 1,
			image: '/static/images/2.png',
			path: '/pages/components/pages/clues/index'
		},
		{
			title: '客户',
			index: 2,
			image: '/static/images/1.png',
			path: '/pages/customer/index'
		},
		{
			title: '合同',
			index: 3,
			image: '/static/images/index006.png',
			path: '/pages/components/pages/contract/index'
		},
		{
			title: '产品',
			index: 4,
			image: '/static/images/8.png',
			path: '/pages/components/pages/product/index'
		},
	]

	const orderTabs2 = [
		// {
		// 	title: '公告',
		// 	index: 1,
		// 	image: '/static/images/11.png',
		// 	path: '/pages/components/pages/mine/list'
		// },
		{
			title: '跟进记录',
			index: 1,
			image: '/static/images/index004.png',
			path: '/pages/components/pages/record/index'
		},
	]

	const orderTabs3 = [{
			title: '业绩完成度',
			index: 1,
			image: '/static/images/24.png',
			path: '/pages/components/pages/analysis/achievement'
		},
		{
			title: '销售简报',
			index: 1,
			image: '/static/images/10.png',
			path: '/pages/components/pages/analysis/sales'
		},
		{
			title: '排行榜',
			index: 1,
			image: '/static/images/9.png',
			path: '/pages/components/pages/analysis/rank'
		},
	]

	const customStyle = computed(() => {
		return {
			paddingBottom: '40rpx',
		}
	})

	const roleName = ref('--')
	const waitCount = ref(0)
	const checkCount = ref(0)
	const noticeCount = ref(0)


	onLoad(() => {
		noticeCount.value = indexCount.value.brieCountVO?.count13 || 0
		waitCount.value = (indexCount.value.followBusinessCount + indexCount.value.followCluesCount + indexCount.value
			.followCustomerCount) || 0
		checkCount.value = (indexCount.value.contractCheckCount + indexCount.value.invoiceCheckCount + indexCount.value
			.receivablesCheckCount) || 0
		getUserInfo();
	})

	const toDetail = (page, index) => {
		uni.navigateTo({
			url: page + '?current=' + index
		})
	}
	const getUserInfo = async () => {
		let data = await userGetUserInfo()
		if (data) {
			main.SET_MEMBER(data)
			if (data.roles.length > 0) {
				roleName.value = data.roles[0].name
			}
		}
	}
	const gopage = (url) => {
		if (url == '') {
			uni.showToast({
				icon: 'error',
				title: '开发中，未开放'
			})
			return
		}
		uni.navigateTo({
			url
		})
	}

	const gopage2 = (url) => {
		if (url == '') {
			uni.showToast({
				icon: 'error',
				title: '开发中，未开放'
			})
			return
		}
		uni.switchTab({
			url
		})
	}

	//跳转中鼐
	const navigateToMiniProgram = () => {
		uni.navigateToMiniProgram({
			appId: 'wx2919e237e6018bea',
			path: 'pages/index',
			extraData: {

			},
			success(res) {
				// 打开成功
			}
		})

	}
</script>

<style lang="scss" scoped>
	page {
		height: auto;
		min-height: 100%;
	}

	.container {
		background: linear-gradient(-180deg, #b3e8fb 0, #ffffff 100%, #ffffff 100%) !important
	}

	.my-background {
		margin-bottom: 20rpx;

		.login-info {
			padding: 50rpx 30rpx 40rpx 30rpx;
		}

		.setting-icon-img {
			width: 50rpx;
			height: 50rpx;
		}

		.avatar-img {
			width: 100rpx;
			height: 100rpx;
		}

		.nick-text {
			font-size: 31rpx;
			color: #333;
			font-weight: bold;
		}

		.id-text {
			margin-top: 8rpx;
			font-size: 22rpx;
			color: #333;
		}

	}

	.user-box {
		position: relative;
		border-radius: 8rpx;
		margin-bottom: 10rpx;
		background-color: #fff;
		display: flex;
		align-items: center;

		.user-grid {
			width: 25%;
			padding: 30rpx 0;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			.value {
				margin-bottom: 0rpx;
			}

			.icon-img {
				width: 60rpx;
				height: 60rpx;
			}
		}
	}

	.customer-management {
		border-radius: 8rpx;
		margin: 0 30rpx 20rpx 30rpx;
		background-color: #fff;

		.title {
			padding: 22rpx 0 26rpx 30rpx;
			font-size: 28rpx;
			font-weight: bold;
		}
	}
</style>