2025-07-31 23:15:10 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="app-container">
|
2026-01-19 20:40:15 +08:00
|
|
|
|
<el-form :inline="true" :model="queryParams" ref="queryRef" class="filter-form">
|
|
|
|
|
|
<el-form-item label="耳号" prop="allEarNumbers">
|
|
|
|
|
|
<el-select
|
|
|
|
|
|
v-model="queryParams.allEarNumbers"
|
|
|
|
|
|
multiple
|
|
|
|
|
|
filterable
|
|
|
|
|
|
remote
|
|
|
|
|
|
reserve-keyword
|
|
|
|
|
|
placeholder="输入耳号搜索"
|
|
|
|
|
|
:remote-method="searchEarNumber"
|
|
|
|
|
|
:loading="earNumberLoading"
|
|
|
|
|
|
allow-create
|
|
|
|
|
|
default-first-option
|
|
|
|
|
|
style="width: 300px"
|
|
|
|
|
|
@change="handleEarNumberChange"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in earNumberOptions"
|
|
|
|
|
|
:key="item"
|
|
|
|
|
|
:label="item"
|
|
|
|
|
|
:value="item"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
@click="clearEarNumbers"
|
|
|
|
|
|
v-if="queryParams.allEarNumbers && queryParams.allEarNumbers.length > 0"
|
|
|
|
|
|
style="margin-left: 10px"
|
|
|
|
|
|
>
|
|
|
|
|
|
清空
|
|
|
|
|
|
</el-button>
|
2025-07-31 23:15:10 +08:00
|
|
|
|
</el-form-item>
|
2026-01-19 20:40:15 +08:00
|
|
|
|
|
2025-07-31 23:15:10 +08:00
|
|
|
|
<el-form-item label="筛选天数">
|
2025-08-13 18:59:24 +08:00
|
|
|
|
<el-input-number v-model="queryParams.screenDays" :min="1" placeholder="请输入天数" />
|
2025-07-31 23:15:10 +08:00
|
|
|
|
</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>
|
|
|
|
|
|
|
2026-01-19 20:40:15 +08:00
|
|
|
|
<div v-if="queryParams.allEarNumbers && queryParams.allEarNumbers.length > 0" class="selected-ear-numbers">
|
|
|
|
|
|
<span style="margin-right: 10px; color: #606266;">已选择耳号:</span>
|
|
|
|
|
|
<el-tag
|
|
|
|
|
|
v-for="earNumber in queryParams.allEarNumbers"
|
|
|
|
|
|
:key="earNumber"
|
|
|
|
|
|
closable
|
|
|
|
|
|
@close="removeEarNumber(earNumber)"
|
|
|
|
|
|
style="margin-right: 8px;"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ earNumber }}
|
|
|
|
|
|
</el-tag>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-07-31 23:15:10 +08:00
|
|
|
|
<div class="button-group">
|
2025-08-13 18:59:24 +08:00
|
|
|
|
<el-popover placement="bottom" width="400" trigger="click">
|
|
|
|
|
|
<el-checkbox-group v-model="selectedFields" class="checkbox-columns">
|
2025-08-29 17:26:39 +08:00
|
|
|
|
<el-checkbox v-for="col in allColumns" :key="col.prop" :value="col.prop">{{ col.label }}</el-checkbox>
|
2025-08-13 18:59:24 +08:00
|
|
|
|
</el-checkbox-group>
|
|
|
|
|
|
<template #reference>
|
2025-12-05 17:51:26 +08:00
|
|
|
|
<el-button type="info" icon="Menu">展示列</el-button>
|
2025-08-13 18:59:24 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-popover>
|
2025-12-05 17:51:26 +08:00
|
|
|
|
<el-button type="success" icon="Download" @click="handleExport">导出</el-button>
|
2025-07-31 23:15:10 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-08-13 18:59:24 +08:00
|
|
|
|
<el-table :data="list" border style="width: 100%" v-loading="loading" :row-key="row => row.sheepId">
|
2025-07-31 23:15:10 +08:00
|
|
|
|
<el-table-column
|
|
|
|
|
|
v-for="col in visibleColumns"
|
|
|
|
|
|
:key="col.prop"
|
|
|
|
|
|
:label="col.label"
|
|
|
|
|
|
:prop="col.prop"
|
|
|
|
|
|
:min-width="col.minWidth || 120"
|
2025-12-05 17:51:26 +08:00
|
|
|
|
:sortable="col.sortable || false"
|
2025-08-13 18:59:24 +08:00
|
|
|
|
:formatter="col.formatter || undefined"
|
2025-07-31 23:15:10 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</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"
|
2025-12-05 17:51:26 +08:00
|
|
|
|
:page-sizes="[20, 50, 100, 200, 500, 1000, 2000]"
|
2025-07-31 23:15:10 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2026-01-19 20:40:15 +08:00
|
|
|
|
// 修改处:导入 searchEarNumbers
|
|
|
|
|
|
import { listSheepMilkAnalysis, searchEarNumbers } from "@/api/dairyProducts/sheepMilkAnalysis/sheepMilkAnalysis.js";
|
2025-08-13 18:59:24 +08:00
|
|
|
|
import { format } from 'date-fns';
|
2025-08-29 17:26:39 +08:00
|
|
|
|
import * as XLSX from 'xlsx'; // 导入xlsx库
|
2025-07-31 23:15:10 +08:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: "SheepMilkAnalysis",
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
total: 0,
|
|
|
|
|
|
list: [],
|
2026-01-19 20:40:15 +08:00
|
|
|
|
// 修改处:新增耳号搜索相关状态
|
|
|
|
|
|
earNumberOptions: [],
|
|
|
|
|
|
earNumberLoading: false,
|
|
|
|
|
|
|
2025-07-31 23:15:10 +08:00
|
|
|
|
queryParams: {
|
|
|
|
|
|
pageNum: 1,
|
2026-01-19 20:40:15 +08:00
|
|
|
|
pageSize: 20,
|
|
|
|
|
|
allEarNumbers: [], // 修改:改为数组
|
|
|
|
|
|
screenDays: 100
|
2025-07-31 23:15:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
selectedFields: [],
|
|
|
|
|
|
allColumns: [
|
|
|
|
|
|
{ label: "耳号", prop: "manageEarTag" },
|
|
|
|
|
|
{ label: "品种", prop: "variety" },
|
2025-08-13 18:59:24 +08:00
|
|
|
|
{ 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') : '' },
|
2025-12-05 17:51:26 +08:00
|
|
|
|
{ label: "筛选天数", prop: "screenDays", sortable: true },
|
|
|
|
|
|
{ label: "挤奶天数", prop: "milkingDays", sortable: true },
|
|
|
|
|
|
{ label: "校正后最大胎次", prop: "maxParity", sortable: true },
|
|
|
|
|
|
{ label: "系统奶量之合计", prop: "sumSystemMilk", sortable: true },
|
|
|
|
|
|
{ label: "校正奶量之合计", prop: "sumCorrectedMilk", sortable: true },
|
|
|
|
|
|
{ label: "校正日平均奶量", prop: "avgCorrectedDaily", sortable: true },
|
|
|
|
|
|
{ label: "胎次1的总奶量", prop: "sumParity1Milk", sortable: true },
|
|
|
|
|
|
{ label: "胎次2的总奶量", prop: "sumParity2Milk", sortable: true },
|
|
|
|
|
|
{ label: "胎次3的总奶量", prop: "sumParity3Milk", sortable: true },
|
|
|
|
|
|
{ label: "胎次4的总奶量", prop: "sumParity4Milk", sortable: true },
|
|
|
|
|
|
{ label: "胎次1日平均", prop: "avgParity1Daily", sortable: true },
|
|
|
|
|
|
{ label: "胎次2日平均", prop: "avgParity2Daily", sortable: true },
|
|
|
|
|
|
{ label: "胎次3日平均", prop: "avgParity3Daily", sortable: true },
|
|
|
|
|
|
{ label: "胎次4日平均", prop: "avgParity4Daily", sortable: true },
|
|
|
|
|
|
{ label: "泌乳天数", prop: "lactationDays", sortable: true },
|
|
|
|
|
|
{ label: "过去7日均奶量", prop: "avgLast7Milk", sortable: true },
|
|
|
|
|
|
{ label: "校正过去7日均", prop: "avgLast7Corrected", sortable: true },
|
|
|
|
|
|
{ label: "过去14日均奶量", prop: "avgLast14Milk", sortable: true },
|
|
|
|
|
|
{ label: "过去30日均奶量", prop: "avgLast30Milk", sortable: true },
|
2025-08-13 18:59:24 +08:00
|
|
|
|
{ label: "羊只类别", prop: "sheepCategory" },
|
|
|
|
|
|
{ label: "生日", prop: "birthday", formatter: row => row.birthday ? format(new Date(row.birthday),'yyyy-MM-dd') : '' },
|
2025-12-05 17:51:26 +08:00
|
|
|
|
{ label: "当前胎次", prop: "parity", sortable: true },
|
|
|
|
|
|
{ label: "月龄", prop: "monthAge", sortable: true },
|
|
|
|
|
|
{ label: "当前体重", prop: "currentWeight", sortable: true },
|
2025-07-31 23:15:10 +08:00
|
|
|
|
{ label: "繁育状态", prop: "breedStatus" },
|
2025-08-13 18:59:24 +08:00
|
|
|
|
{ label: "父号", prop: "fatherManageTags" },
|
|
|
|
|
|
{ label: "母号", prop: "motherManageTags" },
|
|
|
|
|
|
{ label: "牧场", prop: "ranchName" },
|
|
|
|
|
|
{ label: "家系", prop: "family" },
|
2025-12-05 17:51:26 +08:00
|
|
|
|
{ label: "母亲挤奶天数", prop: "motherMilkingDays", sortable: true },
|
|
|
|
|
|
{ label: "母亲校正奶量之合计", prop: "motherSumCorrected", sortable: true },
|
|
|
|
|
|
{ label: "母亲校正后最大胎次", prop: "motherMaxParity", sortable: true },
|
|
|
|
|
|
{ label: "母亲校正日平均奶量", prop: "motherAvgCorrectedDaily", sortable: true }
|
2025-07-31 23:15:10 +08:00
|
|
|
|
]
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
|
|
|
|
|
created() {
|
|
|
|
|
|
this.selectedFields = this.allColumns.map(c => c.prop);
|
|
|
|
|
|
this.getList();
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
visibleColumns() {
|
2025-12-05 17:51:26 +08:00
|
|
|
|
// 保持原有顺序
|
2025-07-31 23:15:10 +08:00
|
|
|
|
return this.allColumns.filter(col => this.selectedFields.includes(col.prop));
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2026-01-19 20:40:15 +08:00
|
|
|
|
// 修改处:新增耳号搜索与处理方法
|
|
|
|
|
|
/** 远程搜索耳号 */
|
|
|
|
|
|
searchEarNumber(query) {
|
|
|
|
|
|
if (query !== '') {
|
|
|
|
|
|
this.earNumberLoading = true
|
|
|
|
|
|
searchEarNumbers(query).then(response => {
|
|
|
|
|
|
this.earNumberOptions = response.data || []
|
|
|
|
|
|
this.earNumberLoading = false
|
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
this.earNumberOptions = []
|
|
|
|
|
|
this.earNumberLoading = false
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.earNumberOptions = []
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/** 耳号变更处理 */
|
|
|
|
|
|
handleEarNumberChange(value) {
|
|
|
|
|
|
// 可选:添加日志或额外逻辑
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/** 清空所有耳号 */
|
|
|
|
|
|
clearEarNumbers() {
|
|
|
|
|
|
this.queryParams.allEarNumbers = []
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/** 移除单个耳号 */
|
|
|
|
|
|
removeEarNumber(earNumber) {
|
|
|
|
|
|
const index = this.queryParams.allEarNumbers.indexOf(earNumber)
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
|
this.queryParams.allEarNumbers.splice(index, 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2025-07-31 23:15:10 +08:00
|
|
|
|
getList() {
|
|
|
|
|
|
this.loading = true;
|
|
|
|
|
|
listSheepMilkAnalysis(this.queryParams).then(response => {
|
2025-08-13 18:59:24 +08:00
|
|
|
|
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);
|
2025-07-31 23:15:10 +08:00
|
|
|
|
this.loading = false;
|
2025-08-13 18:59:24 +08:00
|
|
|
|
}).catch(()=>{ this.loading = false; });
|
2025-07-31 23:15:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
handleQuery() {
|
|
|
|
|
|
this.queryParams.pageNum = 1;
|
|
|
|
|
|
this.getList();
|
|
|
|
|
|
},
|
|
|
|
|
|
resetQuery() {
|
|
|
|
|
|
this.queryParams = {
|
|
|
|
|
|
pageNum: 1,
|
2025-12-05 17:51:26 +08:00
|
|
|
|
pageSize: 20,
|
2026-01-19 20:40:15 +08:00
|
|
|
|
allEarNumbers: [], // 修改:重置为空数组
|
2025-08-13 18:59:24 +08:00
|
|
|
|
screenDays: 100
|
2025-07-31 23:15:10 +08:00
|
|
|
|
};
|
2026-01-19 20:40:15 +08:00
|
|
|
|
this.earNumberOptions = []; // 修改:清空选项
|
2025-07-31 23:15:10 +08:00
|
|
|
|
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();
|
|
|
|
|
|
},
|
2025-08-29 17:26:39 +08:00
|
|
|
|
// 前端导出方法
|
2025-07-31 23:15:10 +08:00
|
|
|
|
handleExport() {
|
2025-08-29 17:26:39 +08:00
|
|
|
|
// 准备导出数据
|
|
|
|
|
|
const exportData = this.list.map(item => {
|
|
|
|
|
|
const row = {};
|
|
|
|
|
|
this.visibleColumns.forEach(col => {
|
|
|
|
|
|
let value = item[col.prop];
|
|
|
|
|
|
// 处理日期格式化
|
|
|
|
|
|
if (col.formatter && typeof col.formatter === 'function') {
|
|
|
|
|
|
value = col.formatter(item);
|
|
|
|
|
|
} else if (value instanceof Date) {
|
|
|
|
|
|
value = format(new Date(value), 'yyyy-MM-dd');
|
|
|
|
|
|
}
|
|
|
|
|
|
row[col.label] = value;
|
|
|
|
|
|
});
|
|
|
|
|
|
return row;
|
2025-07-31 23:15:10 +08:00
|
|
|
|
});
|
2025-08-29 17:26:39 +08:00
|
|
|
|
|
|
|
|
|
|
// 创建工作簿和工作表
|
|
|
|
|
|
const worksheet = XLSX.utils.json_to_sheet(exportData);
|
|
|
|
|
|
const workbook = XLSX.utils.book_new();
|
|
|
|
|
|
XLSX.utils.book_append_sheet(workbook, worksheet, "羊奶产量分析");
|
|
|
|
|
|
|
|
|
|
|
|
// 生成Excel文件并下载
|
|
|
|
|
|
XLSX.writeFile(workbook, "羊奶产量分析数据.xlsx");
|
|
|
|
|
|
|
|
|
|
|
|
this.$message.success('导出成功');
|
2025-07-31 23:15:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
</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;
|
|
|
|
|
|
}
|
2026-01-19 20:40:15 +08:00
|
|
|
|
/* 修改处:新增样式 */
|
|
|
|
|
|
.selected-ear-numbers {
|
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
background-color: #f5f7fa;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
}
|
2025-08-29 17:26:39 +08:00
|
|
|
|
</style>
|