<template>
    <div class="padding-sm">
        <el-form :model="queryParams" ref="queryForm" :inline="true">
			<el-form-item label="查询时间：" style="margin-bottom: 10px;">
				<el-date-picker
					v-model="queryParams.searhDate"
					type="date"
					format="YYYY-MM-DD"
					value-format="YYYY-MM-DD">
				</el-date-picker>
			</el-form-item>
			<el-form-item style="margin-bottom: 10px;">
				<el-button type="primary" class="margin-left-xs" @click="handleQuery">查询</el-button>
			</el-form-item>
        </el-form>
        <el-card shadow="never" :body-style="{padding: '0px'}">
            <el-table v-loading="loading" :data="usageLogList" 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="incineratorSn">
					<template #default="scope">
						<span>{{ getIncineratoName(scope.row.incineratorSn) }}</span>
					</template>
				</el-table-column>
				<el-table-column label="开始时间" align="center" prop="usageStartTime" 
					sortable="custom" :sort-orders="['descending', 'ascending']"/>
				<el-table-column label="结束时间" align="center" prop="usageEndTime" 
					sortable="custom" :sort-orders="['descending', 'ascending']"/>
				<el-table-column label="废品类型" align="center" prop="usageProject"/>
            </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="usageLog">
import { listHistoryLog, downloadHistoryLog } from "@/api/Incinerator/historyLogApi";
const { proxy } = getCurrentInstance();
const total = ref(0);
const loading = ref(false);
const usageLogList = ref([]);
const  getIncineratoName = function(val){
	let _list = proxy.$store.state.data.analogList.filter(item => item.incineratorSn == val);
	return _list.length?_list[0].incineratorName:"";
}
const data = reactive({
    queryParams: {
        pageNum: 1,
        pageSize: 10,
		orderByColumn: "usageStartTime",
		isAsc: "descending",
        incineratorId: null,
		searhDate: null
    }
});
const { queryParams } = toRefs(data);

/** 查询证书列表 */
function getList() {
    loading.value = true;
	queryParams.value.usageStartTime = null;
	queryParams.value.usageEndTime = null;
	if(queryParams.value.searhDate != null){
		queryParams.value.usageStartTime = queryParams.value.searhDate + " 00:00:00";
		queryParams.value.usageEndTime = queryParams.value.searhDate + " 23:59:59";
	}
    listHistoryLog(queryParams.value).then(response => {
        usageLogList.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() {
	let _list = proxy.$store.state.data.analogList.filter(item => item.sn == proxy.$store.state.data.curAnalogSn);
	queryParams.value.incineratorId = _list.length?_list[0].id:null;
	getList();
}
initialData();
watch(proxy.$store.state.data.curAnalogSn, (newValue) => {
	initialData();
});
// queryParams.value.searhDate = [proxy.parseTime(new Date(new Date().getTime()-6*24*3600*1000),`{y}-{m}-{d}`), proxy.parseTime(new Date(),`{y}-{m}-{d}`)]
</script>

