<template>
	<view class="policy main-bg">
		<view v-if="show">
			<image class="header-img" src="../../../static/img.png"></image>
			<view class="list main-bg" v-if="list.length > 0">
				<view class="item" v-for="item in list" @click="goto(item)">
					<image class="item-img" src="/static/new.png"></image>
					<view class="item-right">
						<view class="item-right-name font-twenty font-color3">{{ item.noticeTitle ? item.noticeTitle : '' }}</view>
						<view class="item-right-time font-twenty-four font-color4">{{ item.createTime ? item.createTime : '' }}</view>
					</view>
				</view>
			</view>
			<view v-else>
				<u-empty text="暂无数据" mode="list"></u-empty>
			</view>
		</view>
		<view v-else>
			<view class="list-people main-bg" v-if="list.length > 0">
				<view class="item-people" v-for="item in list" @click="goto(item)">
					<image class="people-img" :src="image(item.picUrl)"></image>
					<view> {{ item.noticeTitle }}</view>
				</view>
			</view>
			<view v-else>
				<u-empty text="暂无数据" mode="list"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import http from '@/common/http.js'
	import server from "@/api/index";
	export default {
		data() {
			return {
				list:[],
				show: false,
				type: null
			}
		},
		onLoad(e) {
			this.type = e.type;
			if(e.type === '004' || e.type === '005'){
				this.show = false;
			}else{
				this.show = true;
			}
			uni.startPullDownRefresh();
		},
		onPullDownRefresh() {
			this.getListFn();
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			image(e) {
				return http.webUrl + e
			},
			getListFn(){
				server.getInfo({ noticeType: this.type }).then(res => {
					this.list = [];
					if(res){
						this.list = res
					}
				})
			},
			goto(item){
				uni.navigateTo({
				    url: '/pages/soldier/home/detail?id=' + item.noticeId
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.policy{
		width: 100%;
		min-height: 100vh;
		height: auto;
		.header-img{
			width: 100%;
			height: 392rpx;
		}
		.list{
			width: 100%;
			padding: 0rpx 30rpx;
			.item{
				height: 240rpx;
				background: #FFFFFF;
				padding: 30rpx;
				margin-top: 30rpx;
				display: flex;
				.item-img{
					width: 180rpx;
					height: 180rpx;
				}
				.item-right{
					width: calc(100% - 180rpx);
					padding-left: 30rpx;
					padding-top: 10rpx;
					.item-right-name{
						font-weight: 550;
						letter-spacing: 2rpx;
						line-height: 40rpx;
						height: 80rpx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
					}
					.item-right-time{
						padding-top: 20rpx;
					}
				}
			}
		}
		.list-people{
			width: 100%;
			padding: 30rpx 30rpx;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
			.item-people{
				width: calc(50% - 15rpx);
				height: 370rpx;
				margin-bottom: 20rpx;
				overflow: hidden;
				.people-img{
					width: 100%;
					height: 320rpx;
					border-radius: 16rpx;
				}
				.people-name{
					width: 100%;
					height: 50rpx;
					line-height: 50rpx;
					text-align: center;
					overflow: hidden;
				}
			}
		}
	}
</style>
