新增组合筛选查询功能
This commit is contained in:
@@ -32,6 +32,15 @@
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<!-- 新增:自定义筛选按钮 -->
|
||||
<CustomFilter ref="customFilterRef" @filter="handleCustomFilter" />
|
||||
<span v-if="isCustomFilterActive" style="color: #67c23a; margin-left: 5px;">
|
||||
<i class="el-icon-success"></i> 筛选条件已激活
|
||||
</span>
|
||||
</el-col>
|
||||
|
||||
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
@@ -54,6 +63,24 @@
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<!-- 新增:显示已应用的筛选条件 -->
|
||||
<div v-if="appliedFilters.length > 0" class="applied-filters mb8">
|
||||
<div class="filter-title">已应用筛选条件:</div>
|
||||
<el-tag
|
||||
v-for="(filter, index) in appliedFilters"
|
||||
:key="index"
|
||||
closable
|
||||
@close="removeAppliedFilter(index)"
|
||||
type="primary"
|
||||
style="margin-right: 8px; margin-bottom: 8px;"
|
||||
>
|
||||
{{ filter.text }}
|
||||
</el-tag>
|
||||
<el-button link type="primary" @click="clearAllFilters" style="margin-left: 10px;">
|
||||
清除所有
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div style="margin-bottom: 10px;">
|
||||
<el-button type="info" plain icon="Setting" @click="openColumnDialog">显示列</el-button>
|
||||
</div>
|
||||
@@ -346,6 +373,40 @@
|
||||
<span style="font-weight: bold; color: #333;">当前体重</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
|
||||
<el-table-column
|
||||
v-if="columns['weaningDayAge'].visible"
|
||||
label="断奶日龄"
|
||||
align="center"
|
||||
prop="weaningDayAge"
|
||||
width="120"
|
||||
sortable
|
||||
>
|
||||
<template #header>
|
||||
<span style="font-weight: bold; color: #333;">断奶日龄</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
v-if="columns['weaningDailyGain'].visible"
|
||||
label="断奶日增重"
|
||||
align="center"
|
||||
prop="weaningDailyGain"
|
||||
width="120"
|
||||
sortable
|
||||
>
|
||||
<template #header>
|
||||
<span style="font-weight: bold; color: #333;">断奶日增重</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- <el-table-column
|
||||
v-if="columns['breedStatusId'].visible"
|
||||
label="繁育状态id"
|
||||
@@ -935,7 +996,9 @@
|
||||
<el-checkbox label="weaningDate">断奶日期</el-checkbox>
|
||||
<el-checkbox label="statusId">羊只状态</el-checkbox>
|
||||
<el-checkbox label="weaningWeight">断奶体重</el-checkbox>
|
||||
<el-checkbox label="currentWeight">当前体重</el-checkbox>
|
||||
<el-checkbox label="currentWeight">当前体重</el-checkbox>\
|
||||
<el-checkbox label="weaningDayAge">断奶日龄</el-checkbox>
|
||||
<el-checkbox label="weaningDailyGain">断奶日增重</el-checkbox>
|
||||
<!-- <el-checkbox label="breedStatusId">繁育状态id</el-checkbox> -->
|
||||
<el-checkbox label="breed">繁殖状态</el-checkbox>
|
||||
<!-- <el-checkbox label="bsFatherId">父号id</el-checkbox> -->
|
||||
@@ -993,12 +1056,20 @@
|
||||
|
||||
<script setup name="Sheep_file">
|
||||
import { listSheep_file, getSheep_file } from "@/api/fileManagement/sheep_file"
|
||||
// 新增:引入自定义筛选组件
|
||||
import CustomFilter from '@/components/CustomFilter/index.vue'
|
||||
|
||||
// 新增:响应式数据
|
||||
const customFilterRef = ref()
|
||||
const appliedFilters = ref([])
|
||||
|
||||
|
||||
// 1. 添加新的响应式变量来存储自定义筛选条件
|
||||
const customFilterParams = ref({})
|
||||
const isCustomFilterActive = ref(false)
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
const { sheep_gender } = proxy.useDict('sheep_gender')
|
||||
console.log('性别字典数据:', sheep_gender) // 添加这行来调试
|
||||
const { breed_type } = proxy.useDict('breed_type')
|
||||
const { controlled } = proxy.useDict('controlled')
|
||||
const { source } = proxy.useDict('source')
|
||||
@@ -1014,7 +1085,7 @@ const total = ref(0)
|
||||
const title = ref("")
|
||||
const columnDialogVisible = ref(false)
|
||||
const selectedColumns = ref([
|
||||
'id', 'bsManageTags', 'ranchId', 'drRanch', 'sheepfoldId', 'sheepfoldName', 'electronicTags', 'varietyId', 'variety', 'family', 'name', 'gender', 'birthday', 'dayAge', 'monthAge', 'parity', 'birthWeight', 'weaningDate', 'statusId', 'weaningWeight', 'currentWeight', 'breedStatusId', 'breed', 'bsFatherId', 'fatherManageTags', 'bsMotherId', 'motherManageTags', 'receptorId', 'receptorManageTags', 'fatherFatherId', 'grandfatherManageTags', 'fatherMotherId', 'grandmotherManageTags', 'fatherId', 'maternalGrandfatherManageTags', 'motherId', 'maternalGrandmotherManageTags', 'matingDate', 'matingTypeId', 'pregDate', 'lambingDate', 'lambingDay', 'matingDay', 'gestationDay', 'expectedDate', 'postLambingDay', 'lactationDay', 'anestrousDay', 'matingCounts', 'matingTotal', 'miscarriageCounts', 'comment', 'controlled', 'body', 'breast', 'source', 'sourceDate', 'sourceRanchId', 'sourceRanch', 'updateBy', 'updateTime', 'createBy', 'createTime'
|
||||
'id', 'bsManageTags', 'ranchId', 'drRanch', 'sheepfoldId', 'sheepfoldName', 'electronicTags', 'varietyId', 'variety', 'family', 'name', 'gender', 'birthday', 'dayAge', 'monthAge', 'parity', 'birthWeight', 'weaningDate', 'statusId', 'weaningWeight', 'currentWeight','weaningDayAge', 'weaningDailyGain','breedStatusId', 'breed', 'bsFatherId', 'fatherManageTags', 'bsMotherId', 'motherManageTags', 'receptorId', 'receptorManageTags', 'fatherFatherId', 'grandfatherManageTags', 'fatherMotherId', 'grandmotherManageTags', 'fatherId', 'maternalGrandfatherManageTags', 'motherId', 'maternalGrandmotherManageTags', 'matingDate', 'matingTypeId', 'pregDate', 'lambingDate', 'lambingDay', 'matingDay', 'gestationDay', 'expectedDate', 'postLambingDay', 'lactationDay', 'anestrousDay', 'matingCounts', 'matingTotal', 'miscarriageCounts', 'comment', 'controlled', 'body', 'breast', 'source', 'sourceDate', 'sourceRanchId', 'sourceRanch', 'updateBy', 'updateTime', 'createBy', 'createTime'
|
||||
])
|
||||
const isAllSelected = ref(false)
|
||||
const columns = reactive({
|
||||
@@ -1039,6 +1110,8 @@ const columns = reactive({
|
||||
statusId: { visible: true },
|
||||
weaningWeight: { visible: true },
|
||||
currentWeight: { visible: true },
|
||||
weaningDayAge: { visible: true },
|
||||
weaningDailyGain: { visible: true },
|
||||
breedStatusId: { visible: true },
|
||||
breed: { visible: true },
|
||||
bsFatherId: { visible: true },
|
||||
@@ -1107,13 +1180,24 @@ const data = reactive({
|
||||
|
||||
const { queryParams, form, rules } = toRefs(data)
|
||||
|
||||
/** 查询羊只档案列表 */
|
||||
function getList() {
|
||||
// 5. 修改 getList 函数,支持传入自定义参数
|
||||
function getList(queryParamOverride = null) {
|
||||
loading.value = true
|
||||
listSheep_file(queryParams.value).then(response => {
|
||||
|
||||
// 准备查询参数
|
||||
const finalQueryParams = queryParamOverride || { ...queryParams.value }
|
||||
|
||||
// 如果有自定义筛选条件,合并到查询参数中
|
||||
if (isCustomFilterActive.value && Object.keys(customFilterParams.value).length > 0) {
|
||||
Object.assign(finalQueryParams, customFilterParams.value)
|
||||
}
|
||||
|
||||
listSheep_file(finalQueryParams).then(response => {
|
||||
sheep_fileList.value = response.rows
|
||||
total.value = response.total
|
||||
loading.value = false
|
||||
}).catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1141,6 +1225,8 @@ function reset() {
|
||||
statusId: null,
|
||||
weaningWeight: null,
|
||||
currentWeight: null,
|
||||
weaningDayAge: null,
|
||||
weaningDailyGain:null,
|
||||
breedStatusId: null,
|
||||
breed: null,
|
||||
bsFatherId: null,
|
||||
@@ -1191,13 +1277,38 @@ function reset() {
|
||||
/** 搜索建议功能 */
|
||||
function handleQuery() {
|
||||
queryParams.value.pageNum = 1
|
||||
getList()
|
||||
|
||||
// 准备查询参数
|
||||
const finalQueryParams = { ...queryParams.value }
|
||||
|
||||
// 如果有自定义筛选条件,合并到查询参数中
|
||||
if (isCustomFilterActive.value && Object.keys(customFilterParams.value).length > 0) {
|
||||
Object.assign(finalQueryParams, customFilterParams.value)
|
||||
}
|
||||
|
||||
// 执行查询
|
||||
loading.value = true
|
||||
listSheep_file(finalQueryParams).then(response => {
|
||||
sheep_fileList.value = response.rows
|
||||
total.value = response.total
|
||||
loading.value = false
|
||||
}).catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
// 4. 修改 resetQuery 函数,重置所有筛选条件
|
||||
function resetQuery() {
|
||||
proxy.resetForm("queryRef")
|
||||
handleQuery()
|
||||
|
||||
// 清空自定义筛选条件
|
||||
customFilterParams.value = {}
|
||||
appliedFilters.value = []
|
||||
isCustomFilterActive.value = false
|
||||
|
||||
// 执行查询
|
||||
queryParams.value.pageNum = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
// 多选框选中数据
|
||||
@@ -1218,11 +1329,16 @@ function handleDelete(row) {
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
/** 导出按钮操作 */
|
||||
// 8. 修改 handleExport 函数,导出时也包含自定义筛选条件
|
||||
function handleExport() {
|
||||
proxy.download('sheep_file/sheep_file/export', {
|
||||
...queryParams.value
|
||||
}, `sheep_file_${new Date().getTime()}.xlsx`)
|
||||
const exportParams = { ...queryParams.value }
|
||||
|
||||
// 如果有自定义筛选条件,合并到导出参数中
|
||||
if (isCustomFilterActive.value && Object.keys(customFilterParams.value).length > 0) {
|
||||
Object.assign(exportParams, customFilterParams.value)
|
||||
}
|
||||
|
||||
proxy.download('sheep_file/sheep_file/export', exportParams, `sheep_file_${new Date().getTime()}.xlsx`)
|
||||
}
|
||||
|
||||
// 打开列设置对话框
|
||||
@@ -1266,12 +1382,175 @@ function confirmColumnSettings() {
|
||||
// 重置列设置
|
||||
function resetColumnSettings() {
|
||||
selectedColumns.value = [
|
||||
'id', 'bsManageTags', 'ranchId', 'drRanch', 'sheepfoldId', 'sheepfoldName', 'electronicTags', 'varietyId', 'variety', 'family', 'name', 'gender', 'birthday', 'dayAge', 'monthAge', 'parity', 'birthWeight', 'weaningDate', 'statusId', 'weaningWeight', 'currentWeight', 'breedStatusId', 'breed', 'bsFatherId', 'fatherManageTags', 'bsMotherId', 'motherManageTags', 'receptorId', 'receptorManageTags', 'fatherFatherId', 'grandfatherManageTags', 'fatherMotherId', 'grandmotherManageTags', 'fatherId', 'maternalGrandfatherManageTags', 'motherId', 'maternalGrandmotherManageTags', 'matingDate', 'matingTypeId', 'pregDate', 'lambingDate', 'lambingDay', 'matingDay', 'gestationDay', 'expectedDate', 'postLambingDay', 'lactationDay', 'anestrousDay', 'matingCounts', 'matingTotal', 'miscarriageCounts', 'comment', 'controlled', 'body', 'breast', 'source', 'sourceDate', 'sourceRanchId', 'sourceRanch', 'updateBy', 'updateTime', 'createBy', 'createTime'
|
||||
'id', 'bsManageTags', 'ranchId', 'drRanch', 'sheepfoldId', 'sheepfoldName', 'electronicTags', 'varietyId', 'variety', 'family', 'name', 'gender', 'birthday', 'dayAge', 'monthAge', 'parity', 'birthWeight', 'weaningDate', 'statusId', 'weaningWeight', 'currentWeight','weaningDayAge', 'weaningDailyGain','breedStatusId', 'breed', 'bsFatherId', 'fatherManageTags', 'bsMotherId', 'motherManageTags', 'receptorId', 'receptorManageTags', 'fatherFatherId', 'grandfatherManageTags', 'fatherMotherId', 'grandmotherManageTags', 'fatherId', 'maternalGrandfatherManageTags', 'motherId', 'maternalGrandmotherManageTags', 'matingDate', 'matingTypeId', 'pregDate', 'lambingDate', 'lambingDay', 'matingDay', 'gestationDay', 'expectedDate', 'postLambingDay', 'lactationDay', 'anestrousDay', 'matingCounts', 'matingTotal', 'miscarriageCounts', 'comment', 'controlled', 'body', 'breast', 'source', 'sourceDate', 'sourceRanchId', 'sourceRanch', 'updateBy', 'updateTime', 'createBy', 'createTime'
|
||||
]
|
||||
updateColumnVisibility()
|
||||
localStorage.setItem('selectedColumns', JSON.stringify(selectedColumns.value))
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理自定义筛选
|
||||
*/
|
||||
/**
|
||||
* 处理自定义筛选
|
||||
*/
|
||||
//
|
||||
function handleCustomFilter(filterParams) {
|
||||
console.log('接收到筛选参数:', filterParams)
|
||||
|
||||
// 构建应用筛选条件的显示文本
|
||||
appliedFilters.value = Object.keys(filterParams).map(field => {
|
||||
const fieldConfig = availableFields.find(f => f.value === field)
|
||||
const value = filterParams[field]
|
||||
let text = ''
|
||||
|
||||
if (!fieldConfig) {
|
||||
text = `${field}: ${value}`
|
||||
} else if (value === 'IS_NULL') {
|
||||
text = `${fieldConfig.label}: 为空`
|
||||
} else if (value === 'NOT_NULL') {
|
||||
text = `${fieldConfig.label}: 不为空`
|
||||
} else if (value.startsWith('GT:')) {
|
||||
text = `${fieldConfig.label} > ${value.substring(3)}`
|
||||
} else if (value.startsWith('LT:')) {
|
||||
text = `${fieldConfig.label} < ${value.substring(3)}`
|
||||
} else if (value.startsWith('GE:')) {
|
||||
text = `${fieldConfig.label} ≥ ${value.substring(3)}`
|
||||
} else if (value.startsWith('LE:')) {
|
||||
text = `${fieldConfig.label} ≤ ${value.substring(3)}`
|
||||
} else if (value.includes(',')) {
|
||||
const values = value.split(',')
|
||||
if (['gender', 'status_id', 'mating_type_id'].includes(field)) {
|
||||
const dictLabels = values.map(v => getDictLabel(field, v)).join(', ')
|
||||
text = `${fieldConfig.label} 在 [${dictLabels}] 中`
|
||||
} else {
|
||||
text = `${fieldConfig.label} 在 [${value}] 中`
|
||||
}
|
||||
} else {
|
||||
if (['gender', 'status_id', 'mating_type_id'].includes(field)) {
|
||||
const dictLabel = getDictLabel(field, value)
|
||||
text = `${fieldConfig.label}: ${dictLabel}`
|
||||
} else {
|
||||
text = `${fieldConfig.label}: ${value}`
|
||||
}
|
||||
}
|
||||
|
||||
return { field, value, text }
|
||||
})
|
||||
|
||||
// 保存自定义筛选参数,不立即查询
|
||||
customFilterParams.value = filterParams
|
||||
isCustomFilterActive.value = Object.keys(filterParams).length > 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典标签
|
||||
*/
|
||||
function getDictLabel(field, value) {
|
||||
let dictOptions = []
|
||||
|
||||
// 根据字段名映射到对应的字典
|
||||
if (field === 'gender') {
|
||||
dictOptions = sheep_gender.value || []
|
||||
} else if (field === 'status_id') {
|
||||
dictOptions = sheep_status.value || []
|
||||
} else if (field === 'mating_type_id') {
|
||||
dictOptions = breed_type.value || []
|
||||
} else if (field === 'controlled') {
|
||||
dictOptions = controlled.value || []
|
||||
} else if (field === 'source') {
|
||||
dictOptions = source.value || []
|
||||
}
|
||||
|
||||
if (!dictOptions || !Array.isArray(dictOptions) || dictOptions.length === 0) {
|
||||
return String(value)
|
||||
}
|
||||
|
||||
// 将原始值转换为字符串进行比较
|
||||
const valueStr = String(value)
|
||||
const item = dictOptions.find(item => String(item.value) === valueStr)
|
||||
|
||||
return item ? item.label : String(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除单个筛选条件
|
||||
*/
|
||||
// 6. 修改 removeAppliedFilter 函数
|
||||
function removeAppliedFilter(index) {
|
||||
const filter = appliedFilters.value[index]
|
||||
|
||||
// 从自定义筛选参数中移除该字段
|
||||
if (customFilterParams.value[filter.field]) {
|
||||
delete customFilterParams.value[filter.field]
|
||||
}
|
||||
|
||||
appliedFilters.value.splice(index, 1)
|
||||
|
||||
// 如果没有筛选条件了,更新状态
|
||||
if (appliedFilters.value.length === 0) {
|
||||
isCustomFilterActive.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有筛选条件
|
||||
*/
|
||||
// 7. 修改 clearAllFilters 函数
|
||||
function clearAllFilters() {
|
||||
customFilterParams.value = {}
|
||||
appliedFilters.value = []
|
||||
isCustomFilterActive.value = false
|
||||
|
||||
// 不立即查询,等待用户点击搜索按钮
|
||||
}
|
||||
|
||||
// 定义字段配置(用于显示)
|
||||
const availableFields = [
|
||||
{ label: '耳号', value: 'bs_manage_tags' },
|
||||
{ label: '电子耳号', value: 'electronic_tags'},
|
||||
{ label: '牧场名称', value: 'dr_ranch' },
|
||||
{ label: '羊舍名称', value: 'sheepfold_name'},
|
||||
{ label: '品种', value: 'variety'},
|
||||
{ label: '家系', value: 'family' },
|
||||
{ label: '羊只类型', value: 'name'},
|
||||
{ label: '性别', value: 'gender'},
|
||||
{ label: '出生日期', value: 'birthday'},
|
||||
{ label: '日龄', value: 'day_age'},
|
||||
{ label: '月龄', value: 'month_age'},
|
||||
{ label: '胎次', value: 'parity'},
|
||||
{ label: '出生体重', value: 'birth_weight' },
|
||||
{ label: '断奶日期', value: 'weaning_date' },
|
||||
{ label: '羊只状态', value: 'status_id' },
|
||||
{ label: '断奶体重', value: 'weaning_weight' },
|
||||
{ label: '当前体重', value: 'current_weight' },
|
||||
{ label: '断奶日龄', value: 'weaning_day_age' },
|
||||
{ label: '断奶日增重', value: 'weaning_daily_gain' },
|
||||
{ label: '繁殖状态', value: 'breed' },
|
||||
{ label: '父亲耳号', value: 'father_manage_tags' },
|
||||
{ label: '母亲耳号', value: 'mother_manage_tags'},
|
||||
{ label: '受体耳号', value: 'receptor_manage_tags' },
|
||||
{ label: '配种类型', value: 'mating_type_id' },
|
||||
{ label: '孕检日期', value: 'preg_date'},
|
||||
{ label: '产羔日期', value: 'lambing_date'},
|
||||
{ label: '产羔时怀孕天数', value: 'lambing_day'},
|
||||
{ label: '配后天数', value: 'mating_day' },
|
||||
{ label: '怀孕天数', value: 'gestation_day'},
|
||||
{ label: '预产日期', value: 'expected_date'},
|
||||
{ label: '产后天数', value: 'post_lambing_day'},
|
||||
{ label: '泌乳天数', value: 'lactation_day'},
|
||||
{ label: '空怀天数', value: 'anestrous_day' },
|
||||
{ label: '配种次数', value: 'mating_counts' },
|
||||
{ label: '累计配种次数', value: 'mating_total'},
|
||||
{ label: '累计流产次数', value: 'miscarriage_counts' },
|
||||
{ label: '体况评分', value: 'body' },
|
||||
{ label: '乳房评分', value: 'breast'},
|
||||
{ label: '入群日期', value: 'source_date' },
|
||||
{ label: '修改日期', value: 'update_time'},
|
||||
{ label: '创建日期', value: 'create_time'},
|
||||
]
|
||||
|
||||
|
||||
getList()
|
||||
</script>
|
||||
|
||||
@@ -1283,4 +1562,26 @@ getList()
|
||||
margin: 5px;
|
||||
width: calc(30% - 20px);
|
||||
}
|
||||
|
||||
|
||||
.applied-filters {
|
||||
padding: 12px 16px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.filter-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
.filter-active-tip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-left: 8px;
|
||||
font-size: 12px;
|
||||
color: #67c23a;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user