<template>
	<view class="container" :style="{height:computeHeight}">
		<up-navbar class="u-navbar-box" title="首页" placeholder bgColor="transparent" leftIcon=''
			:title-style="{fontWeight:'bold'}">
		</up-navbar>
		<!-- header -->
		<view class="flex-row justify-between"
			style="width: 676rpx; height: 342rpx;padding-left: 48rpx;padding-right: 26rpx;">
			<view class="flex-column font-xxl" style="margin-top: 46rpx;">
				<text class="text-black3 font-weight-bolder">特困户系统</text>
				<view class="index-tag flex-row align-center justify-center">
					<text class="font text-white font-weight-bolder" style="margin-right: 12rpx;">便民服务</text>
				</view>
			</view>
			<view style="width: 284rpx;height: 342rpx;">
				<image style="width: 100%;height: 100%;" src="@/static/images/index-computer.png" mode="aspectFill">
				</image>
			</view>
		</view>
		<!--入口  -->
		<view class="px-32" style="margin-top: -60rpx;" @click="handleEnterClick">
			<view class="position-relative flex-row align-center justify-between"
				style="width: 100%;height: 148rpx;border-radius: 20rpx;background-color: rgba(228, 240, 255, 0.8);">
				<image style="width: 100%;height: 100%;" src="@/static/images/index-center-bg.png" mode="aspectFill">
				</image>
				<view class="position-absolute top-0 left-0 flex-row align-center justify-between"
					style="height: 100%;width: 100%;">
					<view class="flex-row align-center" style="margin-left: 28rpx;">
						<image style="width: 66rpx;height: 66rpx;" src="@/static/images/index-enter-logo.png"
							mode="aspectFill"></image>
						<view class="flex-column ml-24">
							<text class="font-md" style="color: #4A90C6;">{{computeHandleDesc}}</text>
							<view class="bg-white flex-row align-center justify-center"
								style="width: 208rpx;height: 40rpx;border-radius: 20rpx;margin-top: 18rpx;">
								<text style="color: #4A90C6;font-size: 22rpx;">一键快速处理</text>
							</view>
						</view>
					</view>
					<image src="/static/images/index-enter-arrow.png"
						style="width: 32rpx;height: 32rpx;margin-right: 52rpx;" mode="aspectFill"></image>
				</view>
			</view>
		</view>

		<!--入口  -->
		<view v-if="vuex_user.roles.includes('company')" class="px-32" style="margin-top: 40rpx;" @click="goApply">
			<view class="position-relative flex-row align-center justify-between"
				style="width: 100%;height: 148rpx;border-radius: 20rpx;background-color: rgba(228, 240, 255, 0.8);">
				<image style="width: 100%;height: 100%;" src="@/static/images/index-center-bg.png" mode="aspectFill">
				</image>
				<view class="position-absolute top-0 left-0 flex-row align-center justify-between"
					style="height: 100%;width: 100%;">
					<view class="flex-row align-center" style="margin-left: 28rpx;">
						<image style="width: 66rpx;height: 66rpx;" src="@/static/images/index-enter-logo.png"
							mode="aspectFill"></image>
						<view class="flex-column ml-24">
							<text class="font-md" style="color: #4A90C6;">护理申请</text>
							<view class="bg-white flex-row align-center justify-center"
								style="width: 208rpx;height: 40rpx;border-radius: 20rpx;margin-top: 18rpx;">
								<text style="color: #4A90C6;font-size: 22rpx;">一键快速处理</text>
							</view>
						</view>
					</view>
					<image src="/static/images/index-enter-arrow.png"
						style="width: 32rpx;height: 32rpx;margin-right: 52rpx;" mode="aspectFill"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserInfoUrl,
		getMsgCountUrl
	} from '@/common/config/api.js'

	import {
		getDict
	} from '@/common/status/index.js'
	import {
		getCareInfo
	} from '@/common/config/application-api.js'
	export default {
		data() {
			return {

			}
		},
		onLoad() {
			// 获取用户信息
			this.getUserInfo();
		},
		onShow() {
			this.getMsgCount();
		},
		computed: {
			computeHeight() {
				return uni.$u.sys().windowHeight + 'px'
			},
			computeHandleDesc() {
				if (!this.vuex_user.roles) {
					return '请先登录'
				}
				// 民政所
				if (this.vuex_user.roles.includes('village')) {
					return '护理初审'
				}
				if (this.vuex_user.roles.includes('area')) {
					return '护理审核'
				}
				// 护理公司
				if (this.vuex_user.roles.includes('company')) {
					return '护理指派'
				}
				if (this.vuex_user.roles.includes('nurse')) {
					return '护理打卡'
				}
			}
		},
		methods: {
			goApply() {
				return uni.navigateTo({
					url: '/pages/subpack/pages/apply/apply'
				})
			},
			getUserInfo() {
				getUserInfoUrl()
					.then(res => {
						console.log('用户信息', res);
						let user = {
							id: res.user.userId,
							avatar: res.user.avatar,
							nickName: res.user.nickName,
							phonenumber: res.user.phonenumber,
							roles: res.roles
						}
						this.$u.vuex('vuex_user', user);
					})
					.catch(err => {
						console.log('err', err);
					})
			},
			// 获取未读消息数量
			getMsgCount() {
				console.log(this.vuex_user.id);
				getMsgCountUrl({
						params: {
							pageNum: 1,
							pageSize: 1,
							userId: this.vuex_user.id,
							status: 0
						},
						custom: {
							catch: true
						}
					})
					.then(res => {
						console.log('未读消息数', res);
						if (res.code === 200) {
							const count = String(res.total);
							if (count > 0) {
								uni.setTabBarBadge({
									index: 1,
									text: count > 99 ? '99+' : count
								})
							} else {
								uni.removeTabBarBadge({
									index: 1
								})
							}
						} else {
							uni.removeTabBarBadge({
								index: 1
							})
						}

					})
					.catch(err => {
						console.log(err);
					})
			},
			// 点击预约
			handleEnterClick() {
				// 街道
				if (this.vuex_user.roles.includes('village')) {
					return uni.navigateTo({
						url: '/pages/subpack/pages/application/list'
					})
				}
				// 民政局
				if (this.vuex_user.roles.includes('area')) {
					return uni.navigateTo({
						url: '/pages/subpack/pages/application/list'
					})
				}

				// 护理公司
				if (this.vuex_user.roles.includes('company')) {
					return uni.navigateTo({
						url: '/pages/subpack/pages/application/list'
					})
				}

				// 护理人员
				if (this.vuex_user.roles.includes('nurse')) {
					return uni.navigateTo({
						url: '/pages/subpack/pages/application/list'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.u-navbar-box {
		background: radial-gradient(circle at left, #FFE5E4 0%, #EEF2F5 40%, #DBEEFB 100%);
	}


	.container {
		// background-image: url('@/static/images/index-bg.png');
		// background-size: cover;
		// background-position: center;

		.index-tag {
			width: 164rpx;
			height: 58rpx;
			margin-top: 38rpx;
			background-image: url('@/static/images/index-tag-bg.png');
			background-size: cover;
			background-position: center;
		}
	}
</style>