<template>
    <div class="padding-sm">
        <el-form :model="queryParams" ref="queryForm" :inline="true">
			<el-form-item label="报警名称：" prop="alarmContent">
				<el-input clearable v-model="queryParams.alarmContent" placeholder="请输入关键词" 
					@keyup.enter="handleQuery"/>
			</el-form-item>
			<el-form-item label="报警时间：">
				<el-date-picker
					v-model="queryParams.startTime"
					type="date"
					format="YYYY-MM-DD"
					value-format="YYYY-MM-DD">
				</el-date-picker>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" class="margin-left-xs" @click="handleQuery">查询</el-button>
				 <el-button icon="Refresh" @click="resetQuery">重置</el-button>
			</el-form-item>
        </el-form>
        <el-card shadow="never" :body-style="{padding: '0px'}">
            <el-table v-loading="loading" :data="alarmLogList" stripe @sort-change="handleSortChange"
				:header-cell-style="{ color: 'var(--white)',background: '#30B08E' }">
                <el-table-column label="序号" align="center" type="index" width="100"/>
                <el-table-column label="报警名称" align="center" prop="alarmContent" />
                <el-table-column label="报警值" sortable align="center" prop="alarmValue">
					<template #default="scope">
						<span class="text-red text-bold">{{ scope.row.alarmValue }}</span>
					</template>
				</el-table-column>
				<el-table-column label="开始时间" align="center" prop="startTime" sortable="custom"
                    :sort-orders="['descending', 'ascending']"/>
				<el-table-column label="结束时间" align="center" prop="endTime" sortable="custom"
                    :sort-orders="['descending', 'ascending']"/>
				<el-table-column label="路径" align="center" prop="sensorFullPath"/>
            </el-table>
        </el-card>
        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script setup name="alarmLog">
import { listAlarmLog, getAlarmLog, addAlarmLog, updateAlarmLog, delAlarmLog, downloadAlarmLog } from "@/api/Incinerator/alarmLogApi";
const { proxy } = getCurrentInstance();
const total = ref(0);
const loading = ref(false);
const alarmLogList = ref([]);
const data = reactive({
    queryParams: {
        pageNum: 1,
        pageSize: 10,
		alarmContent: null,
		orderByColumn: "startTime",
		isAsc: "descending",
		startTime: '2024-04-17'
    }
});
const { queryParams } = toRefs(data);
/** 排序触发事件 */
function handleSortChange(column, prop, order) {
    queryParams.value.orderByColumn = column.prop;
    queryParams.value.isAsc = column.order;
    getList();
}
/** 查询证书列表 */
function getList() {
    loading.value = true;
    listAlarmLog(queryParams.value).then(response => {
        alarmLogList.value = response.rows;
        total.value = response.total;
        loading.value = false;
    });
}
/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryForm");
    handleQuery();
}
function initialData() {
	queryParams.value.startTime = proxy.parseTime(new Date(),`{y}-{m}-{d}`);
	let _list = proxy.$store.state.data.analogList.filter(item => item.sn == proxy.$store.state.data.curAnalogSn);
	queryParams.value.incineratorSn = _list.length?_list[0].incineratorSn:null;
	getList();
}
initialData();
watch(proxy.$store.state.data.curAnalogSn, (newValue) => {
	initialData();
});
</script>

