alarm-history.vue 3.61 KB
<template>
	<view class="alert-page">
		<!-- 告警头部 -->
		<view class="filter-button" @click="openSearchDialog">
			<text>{{ $t('common.screen') }}</text>
			<image src="/static/shaixuan.png" />
		</view>
		<!-- 告警分页 -->
		<mescroll-uni height="700rpx;" ref="mescrollRef" @init="mescrollInit" :up="upOption" :down="downOption"
			@down="downCallback" @up="upCallback">
			<alarm-item :list="list" @openAlertDetail="openAlertDetail"></alarm-item>
			<mescroll-empty v-if="!list.length" />
		</mescroll-uni>
		<view style="height: 20rpx"></view>
		<!-- 告警筛选 -->
		<alarm-popup ref="alarmPopupRef" :show="show" @close="close" @queryCondition="getQueryCondition"></alarm-popup>
	</view>
</template>
<script>
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	import api from '@/api/index.js'
	import alarmItem from '@/pages/alarm/components/alarm-item.vue'
	import alarmPopup from '@/pages/alarm/components/alarm-popup.vue'
	import {
		useNavigateTo
	} from '@/plugins/utils.js'

	export default {
		mixins: [MescrollMixin],
		components: {
			alarmItem,
			alarmPopup
		},
		props: {
			deviceId: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				show: false,
				list: [],
				total: 0,
				downOption: {
					auto: true //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption: {
					auto: false // 不自动加载
				},
				page: {
					num: 0,
					size: 10
				},
				conditions: {},
			};
		},
		methods: {
			disabledScroll() {
				return;
			},
			getQueryCondition(value) {
				this.conditions = value
				this.conditions.deviceId = this.deviceId
				this.loadData(1, this.conditions);
				this.close()
			},
			resetQuery() {
				this.page.num = 1;
				this.$nextTick(() => {
					this.$refs.alarmPopupRef.resetQuery()
				})
				this.conditions = {}
			},
			downCallback() {
				this.list = [];
				this.page.num = 1;
				this.resetQuery();
				this.loadData(this.page.num, {
					deviceId: this.deviceId
				});
			},
			upCallback() {
				const deviceId = {
					deviceId: this.deviceId
				}
				const condition = Object.values(this.conditions)
				if (condition.length === 0) {
					this.page.num += 1;
					this.loadData(this.page.num, {
						...deviceId
					});
				} else if (condition.filter(Boolean).length > 0) {
					this.page.num += 1;
					this.loadData(this.page.num, {
						...this.conditions,
						...deviceId
					});
				} else {
					this.page.num += 1;
					this.loadData(this.page.num, {
						...deviceId
					});
				}
			},
			async loadData(page, param) {
				let that = this;
				let params = {
					page,
					pageSize: 10,
					...param
				};
				const res = await api.alarmApi.getAlarmApi({
					params,
					custom: {
						load: false
					}
				})
				if (!res) return
				uni.stopPullDownRefresh();
				that.mescroll.endByPage(res.items.length, res.total); //必传参数(当前页的数据个数, 总页数)
				that.alarmTotal = res.total;
				if (page == 1) {
					that.list = res.items;
				} else {
					that.list = that.list.concat(res.items);
				}
			},
			openSearchDialog() {
				this.show = true;
				this.resetQuery();
			},
			close() {
				this.show = false;
			},
			openAlertDetail(e) {
				useNavigateTo('/alarm-subpackage/alarm-detail/alarm-detail?data=', e)
			}
		}
	};
</script>

<style lang="scss" scoped>
	.filter-button {
		margin: 0 20rpx;
		font-size: 12px;
		width: 160rpx;
		height: 64rpx;
		border-radius: 32rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #f0f1f2;
		color: #666;

		image {
			width: 28rpx;
			height: 28rpx;
			margin-left: 4rpx;
		}
	}
</style>