<template>
	<view class="uni-container uni-container-bg">
		<view class="top">
			<view>
				<view class="search-time">
					<text class="time-item">事件时间:</text>
					<uni-datetime-picker class="time-item-check" type="date" v-model="startSingle"
						@maskClick="startMaskClick" />
				</view>
				<view class="search-time">
					<text class="time-item">结束时间:</text>
					<uni-datetime-picker class="time-item-check" type="date" v-model="endSingle"
						@maskClick="endMaskClick" />
				</view>
			</view>
			<view class="search-icon">
				<u-icon name="search" color="#4CB2B6" size="40" @click="handleQuery"></u-icon>
			</view>
		</view>
		<view class="main">
			<view v-for="(item, index) in list" :key="index">
				<uni-card  v-if="list.length>0">
					<view class="main-item">
						<rich-text :nodes="`事件内容: ${item.eventContent}`" class="font-16 uni-ellipsis-set"></rich-text>
					</view>
					<view class="main-item">
						<text style="width: 140rpx;">事件日期：</text>
						<text class="conts">{{ item.eventTime}}</text>
					</view>
					<view class="">
						<view class="an-niu" @click.native="delClick(item.id)" link style="margin-left:3px">
							<text class="deletes">删除事件</text>
						</view>
						<view class="an-niu" @click.native="detailClick(item.id)" link style="margin-left:3px;">
							<text class="bianji details">查看详情</text>
						</view>
						<view class="an-niu" @click.native="editClick(item.id)" link style="margin-left:3px;">
							<text class="bianji">编辑事件</text>
						</view>
					</view>

				</uni-card>
				<view v-else style="text-align:center">
					暂无数据
				</view>
			</view>
		</view>
	
		<view>
			<image :src="Group" @click="addClick" class="tiantupian"></image>
		</view>
	</view>
</template>

<script>
	import config from '@/config'
	import {
		getStationEvent,
		delMicrostation
	} from '@/api/fire_station/index';
	const baseUrlImg = config.baseUrlImg
	export default {
		data() {
			return {
				Group: `${baseUrlImg}/checkActive/Group.png`,
				endSingle: '', //结束时间
				startSingle: '', //开始时间
				list: [],
				queryParams: {
					pageNo: 1,
					pageSize: 5,
					eventTime: [],
					eventContent: null,
					microstationid:''
				},
				eventTimeString: '',
				// 总条数
				total: 0,
				runId:""
			}
		},
		onShow() {
			this.list = []
			this.getData()
		},
		onLoad: function(option) {
			this.runId=option.runId
			this.queryParams.microstationid=option.runId
			},
		methods: {
			getData() {
				if (this.queryParams.pageNo != 1) {
					this.queryParams.eventTime.push(this.startSingle, this.endSingle)
				}
				getStationEvent(this.queryParams).then(response => {
					console.log(response, 'responseresponse');
					this.list = [...this.list, ...response.data.list]
					this.total = response.data.total;
					this.queryParams.eventTime = []
				})
			},
			delClick(val) {
				let that = this
				uni.showModal({
					title: '确认删除',
					content: `是否确认删除？`,
					success: function(res) {
						console.log(res, 'res');
						if (res.confirm) {
							delMicrostation({
								id: val
							}).then(delres => {
								that.$modal.msg('删除成功')
								that.queryParams.pageNo = 1;
								that.list=[]
								that.getData()
								that.$forceUpdate()
							})
							// delRole(ids);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			/** 搜索按钮操作 */
			handleQuery() {
				const end = new Date(this.endSingle).getTime()
				const start = new Date(this.startSingle).getTime()
				if (!this.endSingle && !this.startSingle) {
					this.queryParams.pageNo = 1;
					this.list = []
					this.getData();
				} else if (this.endSingle && this.startSingle && start <= end) {
					// } else{
					this.queryParams.pageNo = 1;
					this.queryParams.eventTime.push(this.startSingle, this.endSingle)
					this.list = []
					this.getData();
				} else if (start > end) {
					this.$modal.msgError('结束时间不能小于事件时间')
				} else {
					this.$modal.msgError('请选择事件时间和结束时间')
				}

			},
			startMaskClick(e) {
				console.log('maskClick事件:', e);
			},
			endMaskClick(e) {
				console.log('maskClick事件:', e);
			},
			addClick() {
				uni.navigateTo({
					url: `/pagesA/fire/add_fireRun/add_fireEvent/add_fireEvent?runId=${this.runId}`
				});

			},
			detailClick(val){
				uni.navigateTo({
					url: `/pagesA/fire/add_fireRun/add_fireEvent/add_fireEvent?id=${val}&runId=${this.runId}&isview=isview`
				});
			},
			editClick(val) {
				uni.navigateTo({
					url: `/pagesA/fire/add_fireRun/add_fireEvent/add_fireEvent?id=${val}&runId=${this.runId}`
				});
			}
		},
		// 触底的事件
		onReachBottom() {
			// 判断是否还有下一页数据
			if (this.queryParams.pageNo * this.queryParams.pageSize >= this.total)
				return uni.showToast({
					title: `数据加载完毕`
				});
			// 判断是否正在请求其它数据，如果是，则不发起额外的请求
			if (this.loading) return;
			this.queryParams.pageNo += 1;
			this.getData();
		},
	}
</script>

<style lang="scss" scoped>
	body {
		background-color: #f5f7f9;
	}

	page {
		background-color: #f5f7f9 !important;
	}

	.uni-container {
		height: 100vh;
	}

	.top {
		display: flex;
		align-items: center;
		width: 90%;
		margin-left: 5%;
		justify-content: space-between;

		.search-time {
			display: flex;
			align-items: center;
			margin-top: 40rpx;
			margin-bottom: 20rpx;

			.time-item {
				margin-right: 20rpx;
			}

			.time-item-check {}
		}

		.search-icon {}
	}

	.tiantupian {
		width: 110rpx;
		height: 110rpx;
		position: fixed;
		right: 15px;
		bottom: 40rpx;
	}

	/deep/.uni-card {
		box-shadow: 0px 0px 3px 0px rgba(86, 165, 168, 0.63) !important;
		border-radius: 30rpx;
	}

	.main {
		margin-left: 5%;
		margin-top: 30rpx;
		width: 90%;

		.main-item {
			display: flex;
			// justify-content: start;
			// justify-content: space-between;
			margin-bottom: 15rpx;
			color: #728f90;
		}
	}

	.an-niu {
		float: right;
		font-size: 10px;
		text-align: center;
		display: flex;
		color: #fff;

		.deletes,
		.bianji {
			width: 72px;
			height: 60rpx;
			border-radius: 30px;
			background-color: red;
			margin-right: 20rpx;
			margin-bottom: 20rpx;
			text-align: center;
			line-height: 60rpx;
		}

		.bianji {
			background-color: #4CB2B6
		}
		.details{
			background-color: #F7C41E
		}
	}

	/deep/.u-button--primary {
		border: 1px solid #fff;
		background-color: #fff !important;
	}
</style>
