<template>
	<view class="bg-page">
		<u-sticky>
		<view class="secreen-section" style="background-color: #fff;">
			<u-dropdown class="dropdown-box" ref="uDropdown">
				<u-dropdown-item v-model="lvvalue" title="预警等级" 
				:options="lvList" @change="change1"></u-dropdown-item>
				<u-dropdown-item v-model="typevalue" title="设备类型"
				:options="typeList" @change="change2"></u-dropdown-item>
				<u-dropdown-item v-model="statusvalue" title="状态"
				:options="statusList" @change="change3"></u-dropdown-item>
			</u-dropdown>
		</view>
		</u-sticky>

		<view class="content-box" style="padding-bottom: 60rpx;">
			<view class="tb_swipe_list" 
				 v-for="(item, index) in loglist" 
				 :show="item.show" :index="index":key="item.id" 
				>
				<view class="tb_body" @click="showInfo(index)">
					
					<view class="row_box">
						<view class="text">基地：{{ item.base_name }}</view>
					</view>
					<view class="row_box">
						<view class="text">监控点：{{ item.point_name }}</view>
					</view>
					<!-- <view class="row_box">
						<view class="text">设备类型：{{ item.device_type }}</view>
					</view> -->
					<view class="row_box">
						<view class="text">等级：{{ item.lv }}</view>
					</view>
					<view class="row_box">
						<view class="text">状态：{{ item.status }}</view>
					</view>
					<view class="row_box">
						<view class="text">时间：{{ item.created_at|timeFormat}}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" margin-top="60"/>
		</view>
	</view>
</template>

<script>
	import {showLoading,toast,formatDate} from '@/com/utils.js'
	export default {
		data() {
			return {
				per_page:15,
				page:1,
				loglist:[],
				loading:'loadmore',
				lvList:[
					{
						label: '全部',
						value: 0,
					},
					{
						label: 'Ⅰ级预警',
						value: 1,
					},
					{
						label: 'Ⅱ级预警',
						value: 2,
					},
					{
						label: 'Ⅲ级预警',
						value: 3,
					},
					{
						label: 'Ⅳ级预警',
						value: 4,
					},
				],
				lvvalue:'',
				typeList:[
					{
						label: '全部',
						value: '',
					},
					{
						label: '监控设备',
						value: 1,
					},
					{
						label: '土壤设备',
						value: 2,
					},
					{
						label: '水质设备',
						value: 3,
					},
					{
						label: '气象设备',
						value: 4,
					}
				],
				typevalue:'',
				statusList:[
					{
						label: '全部',
						value: -1,
					},
					{
						label: '未处理',
						value: 0,
					},
					{
						label: '已处理',
						value: 1,
					},
					{
						label: '已忽略',
						value: 2,
					},
				],
				statusvalue:-1,
			};
		},
		filters:{
			timeFormat(val){
				return formatDate(val*1000, 'yyyy-MM-dd hh:mm');
			},
			typename(val){
				let keys = {
					delete:'删除',
					create:'创建',
					update:'修改'
				}
				let name = keys[val]?keys[val]:'其它'
				return name;
			},
			
		},
		onLoad() {
			this.queryloglist();
			
		},
		methods: {
			showInfo(){
				
			},
			change1(val){
				console.log(val);
				this.queryloglist(true);
			},
			change2(val){
				console.log(val);
				this.queryloglist(true);
			},
			change3(val){
				console.log(val);
				this.queryloglist(true);
			},
			queryloglist(refresh){
				if(refresh){
					this.loading = 'loadmore';
					this.loglist = [];
					this.page = 1;
				}
				if(this.loading=='nomore'){//超出最大页
					return false;
				}
				let params = {
					per_page:this.per_page,
					page: this.page ++,
					_t: new Date().getTime()
				}
				if(this.lvvalue){
					params['lv'] = this.lvvalue;
				}
				if(this.typevalue){
					params['device'] = this.typevalue;
				}
				if(this.statusvalue>-1){
					params['status'] = this.statusvalue;
				}
				this.loading = 'loading';
				this.$http.get('/api/device-warning-logs',{params:params}).then(({data})=>{
					
					console.log(data)
					this.loading = 'loadmore';
					if(data.code==200){
						let _list = data.data|| [];
						let {current_page,per_page,last_page} = data.meta;
						
						this.loglist = this.loglist.concat(_list);
						console.log(this.loglist);
						if(current_page >= last_page){
							this.loading ='nomore';
						}
						
					}
				}).catch(()=>{
					this.loading = 'loadmore';
				})
			},
		},
		//触底加载
		onReachBottom() {
			if(this.loading=='loadmore'){
				this.queryloglist();
			}
		},
	}
</script>

<style lang="scss" scoped>
.content-box{
	padding: 30rpx 30rpx 60rpx 30rpx;
}
.row_box{
	.text{
		word-break: break-all;
	}
}

</style>
