<template>
	<view class="hzIndex">
		<hzHeader title="疫情防控"></hzHeader>
		<!-- <view class="tab-banner">
			<image class="image" src="/static/imgs//yqfk-bg.png" ></image>
			<image class="image2" src="/static/imgs//yqfk-header.png" ></image>
		</view> -->
		<view class="hzContent" style="padding-top: 200upx;">
		<!-- <view style="height: 300upx;"></view> -->
		<view style="padding: 20upx;">
			<view class="box  box-wrap" style="width: 100%;padding: 20upx 20upx;border-radius: 10upx;background-color: white;">
				<view :style="permissions.length==5?'width: 25%;':'width: 25%;'" style=" margin-bottom: 30upx;" @click="navTo(item.pageUrl,item.code,item.children)" class="box box-column box-align-center" v-for="(item, index) in permissions" :key="index" v-if="item.isOpen == 0">
					<image class="box" style="width: 90upx; height: 90upx;" :src="item.iconUrl"></image>
					<view style="font-size: 26upx;color: grey;">{{item.name}}</view>
				</view>
				<!-- <view style="width: 25%;" @click="navTo('/pages/epidemic/vaccine-static')" class="box box-column box-align-center" >
					<image class="box" style="width: 80upx; height: 80upx;" src="/static/images/epidemic/cxsp.png"></image>
					<view style="font-size: 24upx;color: grey;">疫苗接种</view>
				</view> -->
				<!-- <view style="width: 25%;" @click="navTo('/pages/epidemic/travel-report-exam')" class="box box-column box-align-center" >
					<image class="box" style="width: 80upx; height: 80upx;" src="/static/images/epidemic/cxsp.png"></image>
					<view style="font-size: 24upx;color: grey;">出行审批</view>
				</view>
				<view style="width: 25%;" @click="navTo('/pages/epidemic/epidemic-supplies')" class="box box-column box-align-center" >
					<image class="box" style="width: 80upx; height: 80upx;" src="/static/images/epidemic//wzsq.png"></image>
					<view style="font-size: 24upx;color: grey;">物资申请</view>
				</view>
				<view style="width: 25%;" @click="navTo('/pages/epidemic/epidemic-supplies-exam')" class="box box-column box-align-center" >
					<image class="box" style="width: 80upx; height: 80upx;" src="/static/images/epidemic/cxsp.png"></image>
					<view style="font-size: 24upx;color: grey;">物资审批</view>
				</view> -->
			</view>
		</view>
		<view style="font-size: 30upx;padding: 0upx 20upx;font-weight: 600;">
			防疫政策
		</view>
		<view style="padding: 20upx;">
			<view v-if="travelPolicy.length>0" style="background-color: white;border-radius: 10upx;">
				<view  v-for="(item, index) in travelPolicy" :key="index"
					class="list-cell "
					@tap="detail(item)"
					:style="index==0?'border-bottom:1px solid #e7e7e7;border-radius:10upx 10upx 0upx 0px;':index==travelPolicy.length-1?'border-radius:0upx 0upx 10upx 10upx;':'border-bottom:1px solid #e7e7e7;'"
				>	
					<view class="box box-between" >
						<view>
							<view class="cell-title-box" >
								<view class="cell-title" :class="[item.img == 0 ? 'pdr0' : '']">{{ item.title }}</view>
							</view>
							<view class="sub-title">
								<text class="tag" >{{formatDate(item.create_time)}}</text>
							</view>
						</view>
						<view class="box box-align-center">
							<image style="width: 20upx;height: 30upx;" src="/static/imgs/select.png"></image>
						</view>
					</view>
					
				</view>
				
				
			</view>
			<view v-else style="padding:20upx;text-align: center;color: #666;font-size: 30upx;background-color: white;border-radius: 10upx;">
				暂无数据
			</view>
		</view>
		</view>
	</view>
</template>

<script>
	import {getUserPermission3,travelPolicyList} from '@/common/api.js';
	import {callbackRequest,formatDate,getStorage,callbackRequestNoLoading  } from '@/common/util.js';
	export default {
		data() {
			return {
				formatDate:formatDate,
				permissions:[],
				travelPolicy:[]
				
			}
		},
		onLoad(option) {
			let code = option.code||"";
			this.permissions = JSON.parse(option.permissions) ||[];
			// this.getUserPermissions(code);
			this.travelPolicyList();
		},
		methods: {
			getUserPermissions(code) {
				let that = this;
				// if (!that.userId) {
				// 	return;
				// }
				let userId= getStorage('userInfo').userId;
				callbackRequestNoLoading({ method: getUserPermission3, data: { userId: userId,parentCode:code } }).then(res => {
					if (res.data.returnCode == 1) {
						that.permissions = res.data.returnData;
					} else {
						console.log('获取权限失败');
					}
				});
			},
			travelPolicyList() {
				let that = this;
				// if (!that.userId) {
				// 	return;
				// }
				callbackRequestNoLoading({ method: travelPolicyList, data: {} }).then(res => {
					if (res.data.returnCode == 1) {
						that.travelPolicy = res.data.returnData;
					} else {
						console.log('获取权限失败');
					}
				});
			},
			detail(item){
				let url = "/pages/epidemic/travel-policy?id="+item.id
				uni.navigateTo({
					url
				});
			},
			navTo(url,code,child) {
				if(!url){
					alertTip('敬请期待');
				}
				// console.log(url)
				// console.log(child)
				for(let i = 0;i<child.length;i++){
					if(child[i].type==1){
						if(url.indexOf('?')!=-1){
							url = url+'&'+child[i].pageUrl;
						}else{
							url = url+'?'+child[i].pageUrl;
						}
					}
				}
				if (url && url.startsWith('/')) {
					if (url.indexOf('?') != -1) {
						url = url + '&code=' + code;
					} else {
						url = url + '?code=' + code;
					}
					if (child.length > 0) {
						url = url + '&permissions=' + JSON.stringify(child);
					}
					// console.log(url)
					uni.navigateTo({
						url
					});
				}
				
			},
		}
	}
</script>

<style lang="scss">
	uni-page-body {
		background-color:#F5F5F5!important;
		min-height: 100% !important;
		height: auto !important;
	}
.box {
	display: flex;
	display: -webkit-flex;
}

.box-row-reverse {
	flex-direction: row;
}

.box-column {
	flex-direction: column;
}

.box-left {
	justify-content: flex-start;
}

.box-right {
	justify-content: flex-end;
}

.box-center {
	justify-content: center;
}

.box-between {
	justify-content: space-between;
}
.box-around {
	justify-content: space-around;
}
.box-align-center {
	align-items: center;
}

.box-wrap {
	flex-wrap: wrap;
}	
	
.tab-banner{
	width: 100%;
	position: relative;
	
	.image{
		width: 100%;
		height: 200upx;
		position: absolute;
		top: 0upx;
	}
	.image2{
		position: absolute;
		top: 40upx;
		width: 100%;
		padding: 0px 20upx;
		height: 240upx;
	}
}

.list-cell {
		padding: 20upx 20upx;
		box-sizing: border-box;
		background: #fff;
		margin-bottom: 10upx;
	}
.cell-title {
	font-size: 28upx;
	/* line-height: 56upx; */
	word-break: break-all;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
}
.sub-title {
		padding-top: 10upx;
		font-size: 28upx;
		color: #bcbcbc;
	}
</style>
