<template>
	<view>
		<headers :showBack="false">
			<view class="headerName">
				消息中心
			</view>
		</headers>
		<view class="tab flex2">
			<view class="tabType" @click="changeTab(0)" :class="checkedTab==0?'checkedTab':'noCheckTab'">全部</view>
			<view class="tabType" @click="changeTab(2)" :class="checkedTab==2?'checkedTab':'noCheckTab'">质量</view>
			<view class="tabType" @click="changeTab(3)" :class="checkedTab==3?'checkedTab':'noCheckTab'">安全</view>
			<view class="tabType" @click="changeTab(4)" :class="checkedTab==4?'checkedTab':'noCheckTab'">AI</view>
		</view>
		<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"
					@click="goList(item)">
					<view class="itemImgBox">
						<image v-if="item.imageUrl" @click.stop="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>
		<footers :activeTab="'mssage'" v-if="accountType == 5 || accountType == 6 || accountType == 10"></footers>
	</view>
</template>

<script>
	import headers from '../../components/headers/headers.vue'
	import footers from '../../components/footers/footers.vue'
	export default {
		components: {
			headers
		},
		data() {
			return {
				checkedTab: 0,
				accountType: 1,
				searchName: '',
				centerContentList: ''
			}
		},
		mounted() {
			console.log(JSON.parse(uni.getStorageSync('userInfo')).userId)
			this.loadData()
		},
		onLoad() {
			var userInfo = JSON.parse(uni.getStorageSync('userInfo'))
			this.accountType = userInfo.accountType
		},
		methods: {
			//去指定页
			goList(obj) {
				let payLoadParams = eval("(" + obj.payload + ")")
				console.log(payLoadParams)
				if (obj.type == 10) { // 安全
					this.sendRequest({
						url: "xmgl/xzSecurityQualityInspectionRecord/selectQualityInspectionRecordById",
						data: {
							id: payLoadParams.data.id
						},
						method: "POST",
						success(res) {
							if (!res.result || res.result.status == 6) {
								uni.showToast({
									title: '检查单已撤回',
									icon: "none"
								})
								return;
							}
							uni.navigateTo({
								url: '/pages/projectEnd/safeSame/details?id=' + payLoadParams.data.id + '&type=' +
									payLoadParams.data.status
							})
						}
					})
				} else if (obj.type == 11) { // 质量
					this.sendRequest({
						url: "xmgl/qualityInspectionRecord/selectQualityInspectionRecordById",
						data: {
							id: payLoadParams.data.id
						},
						method: "POST",
						success(res) {
							console.log(res)
							if (!res.result || res.result.status == 6) {
								uni.showToast({
									title: '检查单已撤回',
									icon: "none"
								})
								return;
							}
							uni.navigateTo({
								url: '/pages/projectEnd/qualityManage/details?id=' + payLoadParams.data.id + '&type=' +
									payLoadParams.data.status
							})
						}
					})
				} else if (obj.type == 8) { // AI
					uni.navigateTo({
						url: "/pages/alarmPage/disposition/disposition?item=" + encodeURIComponent(JSON.stringify(
							payLoadParams.data))
					});
				}
				// if (obj.type == 11) {
				// 	uni.navigateTo({
				// 		url: '/pages/projectEnd/qualityManage/list?type=1'
				// 	})
				// } else if (obj.type == 10) {
				// 	uni.navigateTo({
				// 		url: '/pages/projectEnd/safeSame/list?type=1'
				// 	})
				// } else if (obj.type == 8) {
				// 	uni.navigateTo({
				// 		url: '/pages/alarmPage/indexTwo'
				// 	})

				// }
			},
			//切换tab
			changeTab(type) {
				this.checkedTab = type;
				this.loadData()
			},
			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
				}
				if (this.checkedTab == 2) {
					json.type = 11
				} else if (this.checkedTab == 3) {
					json.type = 10
				} else if (this.checkedTab == 4) {
					json.type = 8
				}
				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>
	.flex2 {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.tab {
		width: 100%;
		height: 45px;
		text-align: center;
		box-shadow: 0 0 10px rgba(194, 194, 194, 0.5);

		.tabType {
			width: 33%;
			line-height: 43px;
			border-bottom: 1px solid rgba(194, 194, 194, 0.2);
		}

		.checkedTab {
			color: #4181FE;
			border-bottom: 2px solid #4181FE;
		}

		.noCheckTab {
			padding-bottom: 2px;
		}
	}

	.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>