新增羊只,转场,转群,改耳号,改品种,改备注,体尺测量,体况评分,乳况评分,修蹄,去势初版
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
<div class="app-container">
|
||||
<!-- 搜索区域 -->
|
||||
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
|
||||
<el-form-item label="耳号" prop="manageTags">
|
||||
<el-input v-model="queryParams.manageTags" placeholder="请输入耳号" clearable @keyup.enter="handleQuery" />
|
||||
<el-form-item label="管理耳号" prop="manageTags">
|
||||
<el-input v-model="queryParams.manageTags" placeholder="请输入管理耳号" clearable @keyup.enter="handleQuery" style="width: 150px;"/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="羊舍" prop="sheepfold">
|
||||
@@ -60,6 +60,7 @@
|
||||
<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">
|
||||
<template #default="scope">
|
||||
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
||||
@@ -82,9 +83,9 @@
|
||||
<!-- 新增/修改弹窗 -->
|
||||
<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">
|
||||
<el-select v-model="form.manageTags" placeholder="请输入或选择耳号" multiple filterable collapse-tags allow-create
|
||||
style="width: 100%" @change="loadSheepInfo">
|
||||
<el-form-item label="管理耳号" prop="manageTags">
|
||||
<el-select v-model="form.manageTags" placeholder="请输入或选择耳号" multiple filterable allow-create
|
||||
style="width: 100%" @change="loadSheepInfo" @blur="loadSheepInfo">
|
||||
<el-option v-for="sheep in sheepOptions" :key="sheep.id" :label="sheep.manageTags"
|
||||
:value="sheep.manageTags" />
|
||||
</el-select>
|
||||
@@ -134,7 +135,7 @@ const data = reactive({
|
||||
manageTags: [],
|
||||
sheepfold: null,
|
||||
technician: null,
|
||||
tagDetails: {}
|
||||
tagDetails: {}
|
||||
},
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
@@ -151,18 +152,19 @@ const data = reactive({
|
||||
// { required: true, message: '羊只id不能为空', trigger: 'blur' }
|
||||
// ],
|
||||
manageTags: [
|
||||
{ required: true, message: '耳号不能为空', trigger: 'blur' }
|
||||
{ required: true, message: '请输入管理耳号', trigger: 'blur' }
|
||||
],
|
||||
sheepfold: [
|
||||
{ required: true, message: '羊舍不能为空', trigger: 'change' }
|
||||
{ required: true, message: '请选择羊舍', trigger: 'change' }
|
||||
],
|
||||
technician: [
|
||||
{ required: true, message: '技术员不能为空', trigger: 'blur' }
|
||||
{ required: true, message: '请输入技术员', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
const { queryParams, form, rules } = toRefs(data)
|
||||
//通过羊舍获取羊只
|
||||
function loadSheepBySheepfold() {
|
||||
const sheepfoldId = form.value.sheepfold;
|
||||
if (!sheepfoldId) {
|
||||
@@ -170,23 +172,26 @@ function loadSheepBySheepfold() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 加载选择的羊舍的耳号
|
||||
getSheepBySheepfoldId(sheepfoldId)
|
||||
.then(res => {
|
||||
const sheepList = res.data || [];
|
||||
let sheepList = res.data || [];
|
||||
sheepList = sheepList.filter(sheep => sheep.gender === 2);
|
||||
|
||||
if (sheepList.length === 0) {
|
||||
proxy.$modal.msgInfo('该羊舍暂无可用耳号');
|
||||
proxy.$modal.msgInfo('该羊舍下暂无性别为公的羊只');
|
||||
sheepOptions.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
sheepOptions.value = sheepList.map(sheep => ({
|
||||
id: sheep.id,
|
||||
manageTags: sheep.manageTags,
|
||||
sheepfoldId: sheepfoldId
|
||||
gender: sheep.gender
|
||||
}));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('加载羊舍耳号失败', error);
|
||||
proxy.$modal.msgError(`加载耳号失败: ${error.message}`);
|
||||
proxy.$modal.msgError('加载耳号失败,请重试');
|
||||
sheepOptions.value = [];
|
||||
});
|
||||
}
|
||||
@@ -196,44 +201,45 @@ async function loadSheepInfo() {
|
||||
const tags = form.value.manageTags;
|
||||
if (!tags || tags.length === 0) return;
|
||||
|
||||
const tagDetails = {}; // 存储每个耳号的信息
|
||||
const tagDetails = {};
|
||||
const validResults = [];
|
||||
|
||||
for (const tag of tags) {
|
||||
try {
|
||||
const { data: sheepData } = await checkSheepByManageTags(tag.trim());
|
||||
|
||||
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] = {
|
||||
comment: sheepData.comment || '', // 备注信息
|
||||
varietyId: sheepData.varietyId,
|
||||
sheepId: sheepData.id,
|
||||
gender: sheepData.gender,
|
||||
sheepfoldId: sheepData.sheepfoldId,
|
||||
sheepId: sheepData.id
|
||||
varietyId: sheepData.varietyId,
|
||||
comment: sheepData.comment || ''
|
||||
};
|
||||
// 自动填充第一个耳号的羊舍(不影响备注,仅优化用户体验)
|
||||
if (validResults.length === 1) {
|
||||
form.value.sheepfold = sheepData.sheepfoldId;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取耳号信息失败:', error);
|
||||
proxy.$modal.msgError(`耳号 ${tag} 验证失败`);
|
||||
console.error(`耳号 ${tag} 校验失败`, error);
|
||||
validResults.push(false);
|
||||
proxy.$modal.msgError(`耳号 ${tag} 校验异常,请重试`);
|
||||
}
|
||||
}
|
||||
|
||||
// 过滤不合法耳号
|
||||
if (validResults.includes(false)) {
|
||||
form.value.manageTags = tags.filter((_, index) => validResults[index]);
|
||||
proxy.$message.warning('部分耳号不合法,已过滤');
|
||||
}
|
||||
|
||||
// 保存所有耳号的信息(关键:用于后续提交时匹配备注)
|
||||
form.value.manageTags = tags.filter((_, index) => validResults[index]);
|
||||
form.value.tagDetails = tagDetails;
|
||||
|
||||
if (validResults.includes(false)) {
|
||||
proxy.$message.warning('部分耳号不符合条件(不存在或非公羊),已自动过滤');
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询列表 */
|
||||
@@ -254,13 +260,19 @@ function getList() {
|
||||
total.value = res.total;
|
||||
loading.value = false;
|
||||
});
|
||||
|
||||
getVarietyOptions({ pageNum: 1, pageSize: 9999 }).then(res => {
|
||||
varietyOptions.value = res.rows || []
|
||||
})
|
||||
}
|
||||
|
||||
//取消
|
||||
function cancel() {
|
||||
open.value = false
|
||||
reset()
|
||||
}
|
||||
|
||||
//重置
|
||||
function reset() {
|
||||
form.value = {
|
||||
id: null,
|
||||
@@ -272,11 +284,13 @@ function reset() {
|
||||
proxy.resetForm('castrateRef');
|
||||
}
|
||||
|
||||
//搜索
|
||||
function handleQuery() {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
}
|
||||
|
||||
//重置
|
||||
function resetQuery() {
|
||||
daterangeCreateTime.value = []
|
||||
proxy.resetForm('queryRef')
|
||||
@@ -289,12 +303,14 @@ function handleSelectionChange(selection) {
|
||||
multiple.value = !selection.length
|
||||
}
|
||||
|
||||
//新增
|
||||
function handleAdd() {
|
||||
reset()
|
||||
open.value = true
|
||||
title.value = '添加去势'
|
||||
}
|
||||
|
||||
//修改
|
||||
function handleUpdate(row) {
|
||||
reset();
|
||||
const _id = row.id || ids.value;
|
||||
@@ -320,7 +336,7 @@ function handleUpdate(row) {
|
||||
});
|
||||
}
|
||||
|
||||
// 新增:校验所有回显的耳号是否存在
|
||||
// 校验所有回显的耳号是否存在
|
||||
async function validateAllTags() {
|
||||
const tags = form.value.manageTags || [];
|
||||
if (tags.length === 0) return;
|
||||
@@ -339,47 +355,53 @@ async function validateAllTags() {
|
||||
}
|
||||
}
|
||||
|
||||
//提交
|
||||
function submitForm() {
|
||||
proxy.$refs.castrateRef.validate(valid => {
|
||||
if (!valid) return;
|
||||
|
||||
const allTags = form.value.manageTags;
|
||||
const tagDetails = form.value.tagDetails || {};
|
||||
|
||||
if (!allTags || allTags.length === 0) {
|
||||
proxy.$modal.msgError('请选择耳号');
|
||||
proxy.$modal.msgError('请选择有效的公羊耳号');
|
||||
return;
|
||||
}
|
||||
|
||||
// 循环处理每个耳号,逐个提交
|
||||
const requests = allTags.map(async (tag) => {
|
||||
const details = tagDetails[tag] || {};
|
||||
const formData = {
|
||||
...form.value,
|
||||
manageTags: tag,
|
||||
comment: details.comment || '', // 关键:每个耳号的备注
|
||||
sheepId: details.sheepId,
|
||||
varietyId: details.varietyId,
|
||||
sheepfold: details.sheepfoldId || form.value.sheepfold
|
||||
};
|
||||
const invalidTags = allTags.filter(tag => {
|
||||
const details = tagDetails[tag];
|
||||
return !details || details.gender !== 2;
|
||||
});
|
||||
if (invalidTags.length > 0) {
|
||||
proxy.$modal.msgError(`耳号 ${invalidTags.join(',')} 性别不符合要求,无法提交`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 提交单个去势记录(与后端接口匹配)
|
||||
return addCastrate(formData);
|
||||
const requests = allTags.map(tag => {
|
||||
const details = tagDetails[tag];
|
||||
return addCastrate({
|
||||
manageTags: tag,
|
||||
sheepId: details.sheepId,
|
||||
sheepfold: details.sheepfoldId || form.value.sheepfold,
|
||||
technician: form.value.technician,
|
||||
varietyId: details.varietyId,
|
||||
comment: details.comment
|
||||
});
|
||||
});
|
||||
|
||||
// 并行处理所有请求
|
||||
Promise.all(requests)
|
||||
.then(() => {
|
||||
proxy.$modal.msgSuccess('操作成功');
|
||||
proxy.$modal.msgSuccess('新增成功');
|
||||
open.value = false;
|
||||
getList();
|
||||
})
|
||||
.catch(error => {
|
||||
proxy.$modal.msgError(`处理失败:${error.message}`);
|
||||
proxy.$modal.msgError(`新增失败:${error.message}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//删除
|
||||
function handleDelete(row) {
|
||||
const _ids = row.id || ids.value
|
||||
proxy.$modal.confirm(`是否确认删除去势编号为"${_ids}"的数据项?`).then(() => {
|
||||
@@ -390,10 +412,12 @@ function handleDelete(row) {
|
||||
})
|
||||
}
|
||||
|
||||
//导出
|
||||
function handleExport() {
|
||||
proxy.download('/produce/other/castrate/export', { ...queryParams.value }, `castrate_${new Date().getTime()}.xlsx`)
|
||||
}
|
||||
|
||||
//加载羊舍数据
|
||||
const sheepfoldOptions = ref([])
|
||||
function getSheepfoldOptions() {
|
||||
listSheepfold({ pageNum: 1, pageSize: 9999 }).then(res => {
|
||||
|
||||
Reference in New Issue
Block a user