<template>
	<view>
		<headers :showBack="true">
			<view class="headerName">
				消息中心
			</view>
		</headers>
		<view class="centerContent">
			<view class="uni-form-item">
				<input class="uni-input" name="searchName" v-model="searchName" @input="searchFile"
					placeholder="请输入搜索内容" />
				<!-- <uni-icons class="search-icon" type="search" @click="loadData"></uni-icons> -->
				<button  class="mini-btn" type="primary" size="mini"  @click="loadData">搜索</button>
			</view>
			<view v-if="centerContentList.length > 0" class="centerContentBox">
				<view v-for="(item,index) in centerContentList" :key="index" class="centerContent_item">
					<view class="itemImgBox">
						<image v-if="item.imageUrl" @click="previewImg(item.imageUrl)" :src="item.imageUrl" class="itemImg"></image>
					</view>
					<view class="itemBox">
						<view class="title">标题：{{ item.title }}</view>
						<view class="content">内容：{{ item.msg }}</view>""
						<view class="time">发送时间：{{item.sendTime}}</view>
					</view>
				</view>
			</view>
			<view class="placeholderBox" v-else>
				<image src="/static/noData.png" class="noDataImg"></image>
				<view class="text">
					暂无数据
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import headers from '../../components/headers/headers.vue'
	export default {
		components: {
			headers
		},
		data() {
			return {
				searchName: '',
				centerContentList: ''
			}
		},
		mounted() {
			console.log(JSON.parse(uni.getStorageSync('userInfo')).userId)
			this.loadData()
		},
		methods: {
			previewImg(imgUrl){
				console.log(imgUrl)
			        //urls为数组，数据里有多少图片链接则显示多少张，若只想预览一张的话，直接传只有一个图片地址的数组即可
				let imgurl=imgUrl
				let imgArr=[]
				imgArr[0] = imgurl
				uni.previewImage({
					current:0,
					urls: imgArr
				})
			},
			searchFile(e) {
				this.searchName = e.detail.value
			},
			loadData() {
				var json = {
					accountId: JSON.parse(uni.getStorageSync('userInfo')).userId,
					pageNo: 1,
					title: this.searchName,
					pageSize: 100
				}
				var that = this
				this.sendRequest({
					url: "xmgl/notice/list",
					data: json,
					method: "POST",
					success(res) {
						that.centerContentList = res.result.records
						console.log('res.result.records',res.result.records)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.centerContentBox{
		border-top: 1px solid rgba(221, 221, 221, 0.8);
	}
	.centerContent_item{
		border-bottom: 1px solid rgba(221, 221, 221, 0.8);
		display: flex;
		align-items: center;
		min-height: 100px;
		padding: 20rpx 40rpx;
		font-size: 15px;
		box-sizing: border-box;
		.itemBox{
			.content{
				margin-top: 3px;
			}
			.time{
				margin-top: 3px;
			}
		}
	}
	.itemImgBox{
		margin-right: 10px;
		.itemImg{
			width: 60px;
			height: 60px;
		}
	}
	.uni-form-item {
		position: relative;

		.search-icon {
			position: absolute;
			top: 50%;
			right: 50rpx;
			transform: translateY(-50%);
		}
	}

	.uni-input {
		border-radius: 15px;
		margin: 10px 10px;
		background-color: #f2f2f2;
		height: 30px;
		line-height: 30px;
		padding: 0 20px;
		font-size: 14px;
		width: 65%;
	}
	.mini-btn{
		position: absolute;
		    right: 6px;
		    top: 0px;
		    border-radius: 15px;
		    height: 30px;
		    line-height: 30px;
	}
</style>
