193 lines
7.1 KiB
Vue
193 lines
7.1 KiB
Vue
<template>
|
||
<div class="app-container">
|
||
<!-- 查询条件 -->
|
||
<el-form :inline="true" :model="queryParams" class="filter-form">
|
||
<el-form-item label="耳号">
|
||
<el-input v-model="queryParams.manageEarTag" placeholder="请输入耳号" />
|
||
</el-form-item>
|
||
<el-form-item label="筛选天数">
|
||
<el-input-number v-model="queryParams.screenDays" :min="1" placeholder="请输入天数" />
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||
<el-button @click="resetQuery">重置</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<!-- 操作按钮行 -->
|
||
<div class="button-group">
|
||
<el-button type="success" @click="handleExport">导出</el-button>
|
||
|
||
<el-popover placement="bottom" width="400" trigger="click">
|
||
<el-checkbox-group v-model="selectedFields" class="checkbox-columns">
|
||
<el-checkbox v-for="col in allColumns" :key="col.prop" :label="col.prop">{{ col.label }}</el-checkbox>
|
||
</el-checkbox-group>
|
||
<template #reference>
|
||
<el-button type="info">展示列</el-button>
|
||
</template>
|
||
</el-popover>
|
||
</div>
|
||
|
||
<!-- 数据表格 -->
|
||
<el-table :data="list" border style="width: 100%" v-loading="loading" :row-key="row => row.sheepId">
|
||
<el-table-column
|
||
v-for="col in visibleColumns"
|
||
:key="col.prop"
|
||
:label="col.label"
|
||
:prop="col.prop"
|
||
:min-width="col.minWidth || 120"
|
||
:formatter="col.formatter || undefined"
|
||
/>
|
||
</el-table>
|
||
|
||
<!-- 分页 -->
|
||
<el-pagination
|
||
v-show="total > 0"
|
||
:total="total"
|
||
:current-page="queryParams.pageNum"
|
||
:page-size="queryParams.pageSize"
|
||
@current-change="handlePageChange"
|
||
@size-change="handleSizeChange"
|
||
layout="total, sizes, prev, pager, next, jumper"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import { listSheepMilkAnalysis, exportSheepMilkAnalysis } from "@/api/dairyProducts/sheepMilkAnalysis/sheepMilkAnalysis.js";
|
||
import { format } from 'date-fns';
|
||
|
||
export default {
|
||
name: "SheepMilkAnalysis",
|
||
data() {
|
||
return {
|
||
loading: false,
|
||
total: 0,
|
||
list: [],
|
||
queryParams: {
|
||
pageNum: 1,
|
||
pageSize: 10,
|
||
manageEarTag: null,
|
||
screenDays: 100 // 默认筛选天数
|
||
},
|
||
selectedFields: [],
|
||
allColumns: [
|
||
{ label: "耳号", prop: "manageEarTag" },
|
||
{ label: "品种", prop: "variety" },
|
||
{ label: "挤奶开始时间", prop: "milkingStartTime", formatter: row => row.milkingStartTime ? format(new Date(row.milkingStartTime),'yyyy-MM-dd') : '' },
|
||
{ label: "干奶时间", prop: "dryEndTime", formatter: row => row.dryEndTime ? format(new Date(row.dryEndTime),'yyyy-MM-dd') : '' },
|
||
{ label: "筛选天数", prop: "screenDays" },
|
||
{ label: "挤奶天数", prop: "milkingDays" },
|
||
{ label: "校正后最大胎次", prop: "maxParity" },
|
||
{ label: "系统奶量之合计", prop: "sumSystemMilk" },
|
||
{ label: "校正奶量之合计", prop: "sumCorrectedMilk" },
|
||
{ label: "校正日平均奶量", prop: "avgCorrectedDaily" },
|
||
{ label: "胎次1的总奶量", prop: "sumParity1Milk" },
|
||
{ label: "胎次2的总奶量", prop: "sumParity2Milk" },
|
||
{ label: "胎次3的总奶量", prop: "sumParity3Milk" },
|
||
{ label: "胎次4的总奶量", prop: "sumParity4Milk" },
|
||
{ label: "胎次1日平均", prop: "avgParity1Daily" },
|
||
{ label: "胎次2日平均", prop: "avgParity2Daily" },
|
||
{ label: "胎次3日平均", prop: "avgParity3Daily" },
|
||
{ label: "胎次4日平均", prop: "avgParity4Daily" },
|
||
{ label: "泌乳天数", prop: "lactationDays" },
|
||
{ label: "过去7日均奶量", prop: "avgLast7Milk" },
|
||
{ label: "校正过去7日均", prop: "avgLast7Corrected" },
|
||
{ label: "过去14日均奶量", prop: "avgLast14Milk" },
|
||
{ label: "过去30日均奶量", prop: "avgLast30Milk" },
|
||
{ label: "羊只类别", prop: "sheepCategory" },
|
||
{ label: "生日", prop: "birthday", formatter: row => row.birthday ? format(new Date(row.birthday),'yyyy-MM-dd') : '' },
|
||
{ label: "当前胎次", prop: "parity" },
|
||
{ label: "月龄", prop: "monthAge" },
|
||
{ label: "当前体重", prop: "currentWeight" },
|
||
{ label: "繁育状态", prop: "breedStatus" },
|
||
{ label: "父号", prop: "fatherManageTags" },
|
||
{ label: "母号", prop: "motherManageTags" },
|
||
{ label: "牧场", prop: "ranchName" },
|
||
{ label: "家系", prop: "family" },
|
||
{ label: "母亲挤奶天数", prop: "motherMilkingDays" },
|
||
{ label: "母亲校正奶量之合计", prop: "motherSumCorrected" },
|
||
{ label: "母亲校正后最大胎次", prop: "motherMaxParity" },
|
||
{ label: "母亲校正日平均奶量", prop: "motherAvgCorrectedDaily" }
|
||
]
|
||
};
|
||
},
|
||
created() {
|
||
this.selectedFields = this.allColumns.map(c => c.prop);
|
||
this.getList();
|
||
},
|
||
computed: {
|
||
visibleColumns() {
|
||
return this.allColumns.filter(col => this.selectedFields.includes(col.prop));
|
||
}
|
||
},
|
||
methods: {
|
||
getList() {
|
||
this.loading = true;
|
||
listSheepMilkAnalysis(this.queryParams).then(response => {
|
||
// 兼容可能的 axios wrapper:有的返回 { data: { rows, total } }, 有的直接返回 { rows, total }
|
||
const res = response && response.data ? response.data : response;
|
||
this.list = res.rows || res;
|
||
this.total = res.total || (Array.isArray(this.list) ? this.list.length : 0);
|
||
this.loading = false;
|
||
}).catch(()=>{ this.loading = false; });
|
||
},
|
||
handleQuery() {
|
||
this.queryParams.pageNum = 1;
|
||
this.getList();
|
||
},
|
||
resetQuery() {
|
||
this.queryParams = {
|
||
pageNum: 1,
|
||
pageSize: 10,
|
||
manageEarTag: null,
|
||
screenDays: 100
|
||
};
|
||
this.selectedFields = this.allColumns.map(c => c.prop);
|
||
this.getList();
|
||
},
|
||
handlePageChange(pageNum) {
|
||
this.queryParams.pageNum = pageNum;
|
||
this.getList();
|
||
},
|
||
handleSizeChange(pageSize) {
|
||
this.queryParams.pageSize = pageSize;
|
||
this.getList();
|
||
},
|
||
handleExport() {
|
||
exportSheepMilkAnalysis(this.queryParams).then(response => {
|
||
const data = response && response.data ? response.data : response;
|
||
const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||
const url = window.URL.createObjectURL(blob);
|
||
const link = document.createElement('a');
|
||
link.href = url;
|
||
link.setAttribute('download', '羊奶分析数据.xlsx');
|
||
document.body.appendChild(link);
|
||
link.click();
|
||
document.body.removeChild(link);
|
||
window.URL.revokeObjectURL(url);
|
||
}).catch(err => {
|
||
this.$message.error('导出失败,请检查后端是否正确返回文件流');
|
||
});
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
.filter-form .el-form-item {
|
||
margin-right: 15px;
|
||
}
|
||
.button-group {
|
||
margin-bottom: 10px;
|
||
}
|
||
.checkbox-columns {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 10px;
|
||
max-height: 300px;
|
||
overflow-y: auto;
|
||
}
|
||
</style>
|