<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 : 'https://sys.znkjfw.com/imgs/crmimages/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="http://sys.znkjfw.com/imgs/crmimages/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="http://sys.znkjfw.com/imgs/crmimages/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="http://sys.znkjfw.com/imgs/crmimages/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="http://sys.znkjfw.com/imgs/crmimages/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 :customStyle="customStyle" @click=" gopage2('/pages/customer/index') ">
						<uv-icon name="http://sys.znkjfw.com/imgs/crmimages/1.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 orderTabs" :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 :customStyle="customStyle" @click="navigateToMiniProgram()">
						<uv-icon name="http://sys.znkjfw.com/imgs/crmimages/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,
		onShow
	} 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: 'http://sys.znkjfw.com/imgs/crmimages/index002.png',
			path: '/pages/components/pages/customer/open'
		},
		{
			title: '线索',
			index: 2,
			image: 'http://sys.znkjfw.com/imgs/crmimages/2.png',
			path: '/pages/components/pages/clues/index'
		},
		{
			title: '合同',
			index: 3,
			image: 'http://sys.znkjfw.com/imgs/crmimages/index006.png',
			path: '/pages/components/pages/contract/index'
		},
		{
			title: '产品',
			index: 4,
			image: 'http://sys.znkjfw.com/imgs/crmimages/8.png',
			path: '/pages/components/pages/product/index'
		},
	]

	const orderTabs2 = [
		// {
		// 	title: '公告',
		// 	index: 1,
		// 	image: 'http://sys.znkjfw.com/imgs/crmimages/11.png',
		// 	path: '/pages/components/pages/mine/list'
		// },
		{
			title: '跟进记录',
			index: 1,
			image: 'http://sys.znkjfw.com/imgs/crmimages/index004.png',
			path: '/pages/components/pages/record/index'
		},
	]

	const orderTabs3 = [{
			title: '业绩完成度',
			index: 1,
			image: 'http://sys.znkjfw.com/imgs/crmimages/24.png',
			path: '/pages/components/pages/analysis/achievement'
		},
		{
			title: '销售简报',
			index: 2,
			image: 'http://sys.znkjfw.com/imgs/crmimages/10.png',
			path: '/pages/components/pages/analysis/sales'
		},
		{
			title: '排行榜',
			index: 3,
			image: 'http://sys.znkjfw.com/imgs/crmimages/9.png',
			path: '/pages/components/pages/analysis/rank'
		},
		{
			title: '业绩结算',
			index: 4,
			image: 'https://api.znkjfw.com/admin-api/infra/file/4/get/invoice_png_179_1741244639133.png',
			path: '/pages/components/pages/performanceSet/list'
		}
	]

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

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


	onShow(() => {
		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>