<template>
	<view class="container">
		<view class="tabBox">
			<view class="tabItem" v-for="(item, index) in industryData" :key="index" :class="industryID == item.id ? 'active' : ''" @tap="onChangeState(item)">{{item.name}}</view>
		</view>
		<view class="hazardPublicityBox">
			<view class="hazardPublicityInfo" @tap="onHazardPublicityTo()">
				<view class="hazardPublicityTitle">
					<text>点击查看线索公示</text>
					<text>>></text>
				</view>
			</view>
		</view>
		<view class="contentBox">
			<z-paging ref="paging" v-model="noticeListData" @query="onGetNoticeNewsInfo" refresher-update-time-key="noticeList" :auto="false">
				<view class="listInfoBox">
					<view class="listInfo" v-for="(item, index) in noticeListData" :key="index" @tap="onNoticeViewTo(item.id)">
						<view class="listTitle">{{item.title}}</view>
						<view class="listContent" v-if="item.content">
							<image class="listContentImg" src="/static/img/common/noticeIcon.png"></image>
							<view class="listContentText">{{item.content}}</view>
						</view>
					</view>
				</view>
			</z-paging>
		</view>
	</view>
</template>

<script>
	var that
	export default {
		data() {
			return {
				tabIndex: '',
				industryData: [],
				industryID: '',
				industryName: '',
				noticeListData: [],
				isReLoad: false,
			}
		},
		onLoad() {
			that = this;
			that.onGetIndustryData(function(){
				that.$nextTick(function() {
					that.$refs.paging.reload()
				})
			})
		},
		methods: {
			onGetIndustryData(fun) {
				that.$admin.reqDirect({
					method: 'GET',
					url: '/api/v1/Snapshot/industry'
				}).then(res => {
					if (res && res.length > 0) {
						res.forEach((item, index) => {
							if (index == 0){
								that.industryID = item.id;
								that.industryName = item.name;
							}
						})
						that.industryData = res;
					}
					typeof fun === 'function' && fun();
				}, err => {
					that.$util.msg(err);
				})
			},
			onGetNoticeNewsInfo(pageNo, pageSize) {
				that.$admin.reqDirect({
					method: 'GET',
					url: '/api/v1/Snapshot/bulletions?IndustryId=' + that.industryID + '&QueryIndex=' + (pageNo - 1) + '&QueryCount=' + pageSize
				}).then(res => {
					if (res && res.length > 0) {
						res.forEach((item, index) => {
							item.creationTime = that.$util.formatTime(new Date(item.creationTime))
						})
						that.$refs.paging.complete(res);
					} else if (res && res.length == 0) {
						that.$refs.paging.complete([]);
					} else {
						that.$util.msg('网络出错！');
						that.$refs.paging.complete(false);
					}
					typeof fun === 'function' && fun();
				}, err => {
					if (!that.isReLoad) {
						that.isReLoad = true;
						that.onGetNoticeNewsInfo(pageNo, pageSize);
					} else {
						that.$util.msg(err);
						that.$refs.paging.complete(false);
					}
				})
			},
			// 切换状态
			onChangeState(obj) {
				if (that.industryID != obj.id){
					that.industryID = obj.id;
					that.industryName = obj.name;
					that.$refs.paging.reload();
				}
			},
			onNoticeViewTo(id) {
				uni.navigateTo({
					url: '/pagesBase/Notice/View?id=' + encodeURIComponent(id)
				})
			},
			onHazardPublicityTo(){
				uni.navigateTo({
					url: '/pagesBase/Notice/HazardPublicity?industryID=' + encodeURIComponent(that.industryID) + '&industryName=' + encodeURIComponent(that.industryName)
				})
			}
		}
	}
</script>

<style>
	.container {
		background-color: #f3f3f3;
	}
	
	.tabBox {
		background-color: #3e6ffd;
		padding: 0 20rpx;
		line-height: 48rpx;
		overflow-x: auto;
		white-space: nowrap;
	}
	
	.tabItem {
		padding: 20rpx 30rpx;
		margin: 16rpx 0;
		display: inline-block;
		width: auto;
		text-align: center;
		color: #fff;
		background-color: #6d91ff;
		font-size: 28rpx;
		position: relative;
		border-radius: 20rpx;
	}
	
	.tabItem + .tabItem{
		margin-left: 30rpx;
	}
	
	.active {
		color: #3e6ffd;
		background-color: #fff;
		font-weight: bold;
		box-shadow: 4rpx 5rpx 12rpx 0rpx #243979;
	}
	
	.hazardPublicityBox{
		color: #3e6ffd;
		margin: 30rpx 20rpx 0;
	}
	
	.hazardPublicityInfo{
		padding: 30rpx;
		border-radius: 10rpx;
		background-color: #fff;
	} 
	
	.hazardPublicityTitle{
		color: #04a8f0;
		width: 100%;
		line-height: 46rpx;
		font-size: 28rpx;
		font-weight: bold;
		border-bottom: 2rpx #f1f1f1 solid;
		padding-bottom: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.contentBox {
		position: relative;
		height: calc(100vh - 250rpx);
	}

	.listInfo {
		margin: 30rpx 20rpx;
		padding: 30rpx;
		border-radius: 10rpx;
		background-color: #fff;
	}

	.listTitle {
		color: #000405;
		width: 100%;
		line-height: 46rpx;
		font-size: 32rpx;
		font-weight: bold;
		border-bottom: 2rpx #f1f1f1 solid;
		padding-bottom: 20rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	
	.listContent{
		position: relative;
		padding-top: 20rpx;
		font-size: 28rpx;
	} 
	
	.listContentImg{
		width: 40rpx;
		height: 40rpx;
		position: absolute;
		top: 24rpx;
		left: 0rpx;
	} 
	
	.listContentText{
		padding-left: 50rpx;
		color: #333;
		line-height: 46rpx;
		white-space: pre-line;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		/*行向垂直排列*/
		-webkit-line-clamp: 2;
	}
</style>