bug修复以及数据分离操作

This commit is contained in:
zyh
2026-02-09 20:22:46 +08:00
parent ab3efaa405
commit 5555d6a747
11 changed files with 975 additions and 448 deletions

View File

@@ -41,7 +41,7 @@
</el-button>
</div>
</el-form-item>
<el-form-item label="羊舍" prop="sheepfold">
<!-- <el-form-item label="羊舍" prop="sheepfold">
<el-select v-model="queryParams.sheepfold" placeholder="请选择羊舍" style="min-width:150px" clearable>
<el-option v-for="item in sheepfoldOptions" :key="item.id" :label="item.sheepfoldName" :value="item.id" />
</el-select>
@@ -50,6 +50,11 @@
<el-select v-model="queryParams.varietyId" placeholder="请选择品种" style="min-width:150px" clearable>
<el-option v-for="item in varietyOptions" :key="item.id" :label="item.variety" :value="item.id" />
</el-select>
</el-form-item> -->
<el-form-item label="技术员" prop="technician">
<el-select v-model="queryParams.technician" placeholder="请选择技术员" clearable filterable style="max-width: 160px">
<el-option v-for="item in technicalOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="是否在群" prop="isDelete">
<el-select v-model="queryParams.isDelete" placeholder="全部" clearable style="min-width:120px">
@@ -89,15 +94,14 @@
<el-table v-loading="loading" :data="castrateList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="耳号" align="center" prop="manageTags" />
<el-table-column label="品种" align="center" prop="varietyName" />
<el-table-column label="事件类型" align="center" prop="eventType" width="120" />
<el-table-column label="事件日期" align="center" prop="eventDate" width="130">
<el-table-column label="去势日期" align="center" prop="eventDate" width="130">
<template #default="scope">
<span>{{ parseTime(scope.row.eventDate, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="羊舍" align="center" prop="sheepfoldName" />
<el-table-column label="品种" align="center" prop="varietyName" />
<el-table-column label="备注" align="center" prop="comment" />
<el-table-column label="技术员" align="center" prop="technician" />
<el-table-column label="创建人" align="center" prop="createBy" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
@@ -105,6 +109,7 @@
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="comment" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<!-- 按需添加 是否需要修改功能 -->
@@ -115,7 +120,6 @@
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize" @pagination="getList" :page-sizes="[20, 50, 100, 200, 500, 1000, 2000]" />
@@ -123,27 +127,35 @@
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
<el-form ref="castrateRef" :model="form" :rules="rules" label-width="80px">
<el-form-item label="管理耳号" prop="manageTags">
<div style="display: flex; align-items: center; gap: 8px;">
<el-select v-model="form.manageTags" placeholder="请输入或选择耳号" multiple filterable allow-create
style="width: 100%; flex:1;" @change="loadSheepInfo" @blur="loadSheepInfo">
<el-option v-for="sheep in sheepOptions" :key="sheep.id" :label="sheep.manageTags"
:value="sheep.manageTags" />
</el-select>
<span v-if="form.manageTags?.length > 0" class="tag-count">
已选 {{ form.manageTags.length }}
</span>
</div>
<el-input v-model="form.manageTags" placeholder="请输入管理耳号" @blur="onManageTagsBlur" clearable />
</el-form-item>
<!-- 新增弹窗已选耳号展示区 -->
<div v-if="batchTags.length" class="selected-ear-numbers">
<el-tag v-for="(tag, idx) in batchTags" :key="tag" closable @close="removeBatchTag(idx)" style="margin:4px"
type="success">
{{ tag }}
</el-tag>
<el-button type="primary" link @click="clearBatchTags">
一键清空 ({{ batchTags.length }})
</el-button>
</div>
<el-form-item label="事件日期" prop="eventDate">
<el-date-picker v-model="form.eventDate" value-format="YYYY-MM-DD" type="date" placeholder="请选择事件日期" />
</el-form-item>
<el-form-item label="羊舍" prop="sheepfold">
<el-select v-model="form.sheepfold" placeholder="请选择羊舍" clearable @change="loadSheepBySheepfold">
<el-option v-for="fold in sheepfoldOptions" :key="fold.id" :label="fold.sheepfoldName" :value="fold.id" />
<el-select v-model="form.sheepfold" placeholder="请选择或输入羊舍" clearable filterable
:filter-method="filterSheepfold" @change="loadSheepBySheepfold">
<el-option v-for="fold in filteredSheepfoldOptions" :key="fold.id" :label="fold.sheepfoldName"
:value="fold.id" />
</el-select>
</el-form-item>
<el-form-item label="技术员" prop="technician">
<el-input v-model="form.technician" placeholder="请输入技术员" />
<el-select v-model="form.technician" placeholder="请选择技术员" clearable filterable style="width: 100%">
<el-option v-for="item in technicalOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="事件日期" prop="eventDate">
<el-date-picker v-model="form.eventDate" value-format="YYYY-MM-DD" type="date" placeholder="请选择事件日期" />
<el-form-item label="备注" prop="comment">
<el-input v-model="form.comment" type="textarea" :rows="3" placeholder="请输入备注" />
</el-form-item>
</el-form>
<template #footer>
@@ -161,6 +173,7 @@ import { listCastrate, getCastrate, delCastrate, addCastrate, searchEarNumbers }
import { checkSheepByManageTags, getVarietyOptions, getSheepBySheepfoldId } from '@/api/produce/other/fixHoof'
import { listSheepfold_management as listSheepfold } from '@/api/fileManagement/sheepfold_management'
import { Plus, Delete, ArrowUp, ArrowDown } from '@element-plus/icons-vue'
import { getUserByPost } from '@/api/common/user'
import { nextTick } from 'vue'
import dayjs from 'dayjs'
const { proxy } = getCurrentInstance()
@@ -175,9 +188,13 @@ const multiple = ref(true)
const total = ref(0)
const title = ref('')
const daterangeCreateTime = ref([])
const sheepOptions = ref([])
const filteredSheepfoldOptions = ref([])
const varietyOptions = ref([])
const daterangeEventDate = ref([])
const batchTags = ref([]) // 本次要新增的多条耳号
const batchSheep = ref([]) // 对应的羊只对象
// 技术员下拉选项
const technicalOptions = ref([])
const pasteText = ref('')
const isExpanded = ref(false)
const defaultShowCount = 2
@@ -194,6 +211,7 @@ const data = reactive({
technician: null,
tagDetails: {},
eventDate: null,
comment: null,
},
queryParams: {
pageNum: 1,
@@ -225,84 +243,81 @@ const data = reactive({
const { queryParams, form, rules } = toRefs(data)
const earOptions = ref([])
const earLoading = ref(false)
//通过羊舍获取羊只
// 羊舍变化处理:自动加载该羊舍下所有公羊(清空已有)
function loadSheepBySheepfold() {
const sheepfoldId = form.value.sheepfold;
const sheepfoldId = form.value.sheepfold
if (!sheepfoldId) {
sheepOptions.value = [];
return;
// 清空羊舍时,不清空耳号
return
}
// 清空已有耳号
batchTags.value = []
batchSheep.value = []
form.value.manageTags = ''
getSheepBySheepfoldId(sheepfoldId)
.then(res => {
let sheepList = res.data || [];
sheepList = sheepList.filter(sheep => sheep.gender === 2);
let sheepList = res.data || []
sheepList = sheepList.filter(sheep => sheep.gender === 2)
if (sheepList.length === 0) {
proxy.$modal.msgInfo('该羊舍下暂无性别为公的羊只');
sheepOptions.value = [];
return;
proxy.$modal.msgInfo('该羊舍下暂无公羊')
return
}
sheepOptions.value = sheepList.map(sheep => ({
id: sheep.id,
manageTags: sheep.manageTags,
gender: sheep.gender
}));
// 填充该羊舍所有公羊
for (const sheep of sheepList) {
batchTags.value.push(sheep.manageTags)
batchSheep.value.push(sheep)
}
form.value.manageTags = batchTags.value.join(' ')
proxy.$modal.msgSuccess(`已加载 ${batchTags.value.length} 只公羊`)
})
.catch(error => {
console.error('加载羊舍耳号失败', error);
proxy.$modal.msgError('加载耳号失败,请重试');
sheepOptions.value = [];
});
console.error('加载羊舍耳号失败', error)
proxy.$modal.msgError('加载耳号失败,请重试')
})
}
// 输入耳号后校验并获取品种/羊舍等信息
async function loadSheepInfo() {
const tags = form.value.manageTags;
if (!tags || tags.length === 0) return;
// 输入耳号后校验并追加(不清空已有)
async function onManageTagsBlur() {
const raw = form.value.manageTags?.trim()
if (!raw) return
const tagDetails = {};
const validResults = [];
// 按分隔符拆分
const separators = /[\p{White_Space},]+/u
const newTags = [...new Set(raw.split(separators).filter(v => v))]
for (const tag of tags) {
try {
const { data: sheepData } = await checkSheepByManageTags(tag.trim());
// 过滤掉已存在的
const existTags = new Set(batchTags.value)
const tagsToAdd = newTags.filter(tag => !existTags.has(tag))
if (!sheepData) {
validResults.push(false);
proxy.$modal.msgError(`耳号 ${tag} 不存在`);
} else if (sheepData.gender !== 2) {
validResults.push(false);
proxy.$modal.msgError(`耳号 ${tag} 对应的羊只性别不是公,无法添加`);
} else {
validResults.push(true);
tagDetails[tag] = {
sheepId: sheepData.id,
gender: sheepData.gender,
sheepfoldId: sheepData.sheepfoldId,
varietyId: sheepData.varietyId,
comment: sheepData.comment || ''
};
if (validResults.length === 1) {
form.value.sheepfold = sheepData.sheepfoldId;
}
}
} catch (error) {
console.error(`耳号 ${tag} 校验失败`, error);
validResults.push(false);
proxy.$modal.msgError(`耳号 ${tag} 校验异常,请重试`);
if (tagsToAdd.length === 0) {
// 全部已存在,回写现有
form.value.manageTags = batchTags.value.join(' ')
return
}
// 校验并追加新耳号
for (const tag of tagsToAdd) {
const sheep = await checkSheepByManageTags(tag).then(r => r.data).catch(() => null)
if (!sheep) {
proxy.$modal.msgWarning(`耳号 ${tag} 不存在,已跳过`)
continue
}
if (Number(sheep.gender)) {
proxy.$modal.msgWarning(`耳号 ${tag} 不是公羊,已跳过`)
continue
}
batchTags.value.push(tag)
batchSheep.value.push(sheep)
}
form.value.manageTags = tags.filter((_, index) => validResults[index]);
form.value.tagDetails = tagDetails;
if (validResults.includes(false)) {
proxy.$message.warning('部分耳号不符合条件(不存在或非公羊),已自动过滤');
}
// 回写所有耳号
form.value.manageTags = batchTags.value.join(' ')
}
/** 查询列表 */
function getList() {
loading.value = true;
@@ -319,7 +334,9 @@ function getList() {
q.params.beginEventDate = daterangeEventDate.value[0];
q.params.endEventDate = daterangeEventDate.value[1];
}
if (q.technician) {
q.params.technician = q.technician;
}
listCastrate(q).then(res => {
castrateList.value = res.rows;
console.log("后端返回的列表数据:", res.rows);
@@ -342,13 +359,16 @@ function cancel() {
function reset() {
form.value = {
id: null,
manageTags: [],
manageTags: null,
sheepfold: null,
technician: null,
eventDate: null
};
sheepOptions.value = [];
proxy.resetForm('castrateRef');
eventDate: null,
comment: null
}
batchTags.value = []
batchSheep.value = []
filteredSheepfoldOptions.value = sheepfoldOptions.value
proxy.resetForm('castrateRef')
}
//搜索
@@ -362,6 +382,7 @@ function resetQuery() {
daterangeCreateTime.value = []
daterangeEventDate.value = []
queryParams.value.manageTagsList = []
queryParams.value.technician = null
queryParams.value.isDelete = null
proxy.resetForm('queryRef')
handleQuery()
@@ -428,49 +449,52 @@ async function validateAllTags() {
//提交
function submitForm() {
proxy.$refs.castrateRef.validate(valid => {
if (!valid) return;
if (batchTags.value.length === 0) {
proxy.$modal.msgError('请输入至少一个有效耳号')
return
}
if (!form.value.technician) {
proxy.$modal.msgError('请输入技术员')
return
}
if (!form.value.eventDate) {
proxy.$modal.msgError('请选择事件日期')
return
}
const allTags = form.value.manageTags;
const tagDetails = form.value.tagDetails || {};
if (!allTags || allTags.length === 0) {
proxy.$modal.msgError('请选择有效的公羊耳号');
return;
}
const invalidTags = allTags.filter(tag => {
const details = tagDetails[tag];
return !details || details.gender !== 2;
});
if (invalidTags.length > 0) {
proxy.$modal.msgError(`耳号 ${invalidTags.join(',')} 性别不符合要求,无法提交`);
return;
}
const requests = allTags.map(tag => {
const details = tagDetails[tag];
return addCastrate({
// 批量新增
Promise.all(
batchTags.value.map((tag, idx) =>
addCastrate({
sheepId: batchSheep.value[idx].id,
manageTags: tag,
sheepId: details.sheepId,
sheepfold: details.sheepfoldId || form.value.sheepfold,
sheepfold: batchSheep.value[idx].sheepfoldId,
varietyId: batchSheep.value[idx].varietyId,
technician: form.value.technician,
varietyId: details.varietyId,
comment: details.comment,
eventDate: form.value.eventDate
});
});
Promise.all(requests)
.then(() => {
proxy.$modal.msgSuccess('新增成功');
open.value = false;
getList();
eventDate: form.value.eventDate,
comment: form.value.comment || ''
})
.catch(error => {
proxy.$modal.msgError(`新增失败:${error.message}`);
});
});
)
).then(() => {
proxy.$modal.msgSuccess(`成功新增 ${batchTags.value.length} 条去势记录`)
open.value = false
getList()
}).catch(() => { })
}
/* 删除单个批量耳号 */
function removeBatchTag(idx) {
batchTags.value.splice(idx, 1)
batchSheep.value.splice(idx, 1)
form.value.manageTags = batchTags.value.join(' ')
// 不再自动更新羊舍
}
/* 一键清空批量耳号 */
function clearBatchTags() {
batchTags.value = []
batchSheep.value = []
form.value.manageTags = ''
}
//删除
@@ -488,14 +512,41 @@ function handleDelete(row) {
function handleExport() {
proxy.download('/produce/other/castrate/export', { ...queryParams.value }, `castrate_${new Date().getTime()}.xlsx`)
}
// 获取技术员列表岗位编码techs
const fetchTechnicalList = () => {
getUserByPost({ postCode: "techs" })
.then(res => {
if (res.code === 200 && Array.isArray(res.data)) {
technicalOptions.value = res.data.map(item => ({
value: item.nickName,
label: item.nickName
}))
} else {
technicalOptions.value = []
}
})
.catch(() => {
technicalOptions.value = []
})
}
//加载羊舍数据
const sheepfoldOptions = ref([])
function getSheepfoldOptions() {
listSheepfold({ pageNum: 1, pageSize: 9999 }).then(res => {
sheepfoldOptions.value = res.rows
filteredSheepfoldOptions.value = res.rows
})
}
// 羊舍模糊过滤
function filterSheepfold(query) {
if (!query) {
filteredSheepfoldOptions.value = sheepfoldOptions.value
return
}
filteredSheepfoldOptions.value = sheepfoldOptions.value.filter(fold =>
fold.sheepfoldName.includes(query)
)
}
function searchEarNumber(query) {
if (!query) { earOptions.value = []; return }
earLoading.value = true
@@ -546,6 +597,7 @@ function handleEarChange(val) {
onMounted(() => {
getSheepfoldOptions()
getVarietyOptions()
fetchTechnicalList()
getList()
})
</script>