转群功能完善
This commit is contained in:
parent
acb021d78d
commit
53b3efb432
@ -60,3 +60,12 @@ export function approveScTransGroup(data) {
|
|||||||
data
|
data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取所有牧场列表
|
||||||
|
export function listRanch() {
|
||||||
|
return request({
|
||||||
|
url: '/ranch/ranch/list',
|
||||||
|
method: 'get',
|
||||||
|
params: { pageNum: 1, pageSize: 9999 }
|
||||||
|
});
|
||||||
|
}
|
@ -102,15 +102,27 @@
|
|||||||
:value="sheep.manageTags" />
|
:value="sheep.manageTags" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="转出羊舍" prop="foldFrom">
|
<!-- 在el-form中新增牧场选择项 -->
|
||||||
<el-select v-model="form.foldFrom" placeholder="请选择转出羊舍" clearable @change="handleSheepFilter"
|
<el-form-item label="牧场" prop="ranchId">
|
||||||
:disabled="!isAdd">
|
<el-select v-model="form.ranchId" placeholder="请选择牧场" clearable @change="handleRanchChange">
|
||||||
<el-option v-for="fold in sheepfoldOptions" :key="fold.id" :label="fold.sheepfoldName" :value="fold.id" />
|
<el-option v-for="ranch in ranchOptions" :key="ranch.id" :label="ranch.ranchName" :value="ranch.id" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
<!-- 调整转出羊舍的options为当前牧场的羊舍 -->
|
||||||
|
<el-form-item label="转出羊舍" prop="foldFrom">
|
||||||
|
<el-select v-model="form.foldFrom" placeholder="请选择转出羊舍" clearable :disabled="!form.ranchId"
|
||||||
|
@change="handleSheepFilter">
|
||||||
|
<el-option v-for="fold in currentRanchSheepfolds" :key="fold.id" :label="fold.sheepfoldName"
|
||||||
|
:value="fold.id" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<!-- 调整转入羊舍的options为当前牧场的羊舍 -->
|
||||||
<el-form-item label="转入羊舍" prop="foldTo">
|
<el-form-item label="转入羊舍" prop="foldTo">
|
||||||
<el-select v-model="form.foldTo" placeholder="请选择转入羊舍" clearable :disabled="!isAdd">
|
<el-select v-model="form.foldTo" placeholder="请选择转入羊舍" clearable :disabled="!form.ranchId">
|
||||||
<el-option v-for="fold in sheepfoldOptions" :key="fold.id" :label="fold.sheepfoldName" :value="fold.id" />
|
<el-option v-for="fold in currentRanchSheepfolds" :key="fold.id" :label="fold.sheepfoldName"
|
||||||
|
:value="fold.id" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item v-if="isAdd" label="羊只类型" prop="sheepTypeId">
|
<el-form-item v-if="isAdd" label="羊只类型" prop="sheepTypeId">
|
||||||
@ -175,7 +187,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="Trans_group">
|
<script setup name="Trans_group">
|
||||||
import { listTrans_group, getTrans_group, delTrans_group, addTrans_group, updateTrans_group, approveScTransGroup } from '@/api/produce/manage_sheep/trans_group'
|
import { listTrans_group, getTrans_group, delTrans_group, addTrans_group, updateTrans_group, approveScTransGroup, listRanch } from '@/api/produce/manage_sheep/trans_group'
|
||||||
import { listSheepfold_management as listSheepfold } from '@/api/fileManagement/sheepfold_management'
|
import { listSheepfold_management as listSheepfold } from '@/api/fileManagement/sheepfold_management'
|
||||||
import { checkSheepByManageTags, getSheepBySheepfoldId } from '@/api/produce/other/fixHoof'
|
import { checkSheepByManageTags, getSheepBySheepfoldId } from '@/api/produce/other/fixHoof'
|
||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
@ -203,6 +215,8 @@ const sheepfoldNameMap = ref({});
|
|||||||
const varietyOptions = ref([]);
|
const varietyOptions = ref([]);
|
||||||
const sheepTypeOptions = ref([]);
|
const sheepTypeOptions = ref([]);
|
||||||
const isAdd = ref(false);
|
const isAdd = ref(false);
|
||||||
|
const ranchOptions = ref([]);
|
||||||
|
const currentRanchSheepfolds = ref([]);
|
||||||
|
|
||||||
const data = reactive({
|
const data = reactive({
|
||||||
form: {
|
form: {
|
||||||
@ -214,6 +228,7 @@ const data = reactive({
|
|||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
sheepId: null,
|
sheepId: null,
|
||||||
manageTags: null,
|
manageTags: null,
|
||||||
|
ranchId: null,
|
||||||
foldTo: null,
|
foldTo: null,
|
||||||
foldFrom: null,
|
foldFrom: null,
|
||||||
varietyId: null,
|
varietyId: null,
|
||||||
@ -222,6 +237,7 @@ const data = reactive({
|
|||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
manageTags: [{ required: true, message: '请输入耳号', trigger: 'blur' }],
|
manageTags: [{ required: true, message: '请输入耳号', trigger: 'blur' }],
|
||||||
|
ranchId: [{ required: true, message: '请选择牧场', trigger: 'change' }],
|
||||||
foldTo: [{ required: true, message: '请选择转入羊舍', trigger: 'change' }],
|
foldTo: [{ required: true, message: '请选择转入羊舍', trigger: 'change' }],
|
||||||
varietyId: [{ required: true, message: '请选择品种', trigger: 'change' }],
|
varietyId: [{ required: true, message: '请选择品种', trigger: 'change' }],
|
||||||
reason: [{ required: true, message: '请选择转群原因', trigger: 'change' }],
|
reason: [{ required: true, message: '请选择转群原因', trigger: 'change' }],
|
||||||
@ -250,6 +266,7 @@ function reset() {
|
|||||||
form.value = {
|
form.value = {
|
||||||
id: null,
|
id: null,
|
||||||
sheepId: null,
|
sheepId: null,
|
||||||
|
ranchId: null,
|
||||||
foldFrom: null,
|
foldFrom: null,
|
||||||
foldTo: null,
|
foldTo: null,
|
||||||
varietyId: null,
|
varietyId: null,
|
||||||
@ -268,10 +285,17 @@ function reset() {
|
|||||||
|
|
||||||
//新增时判断筛选条件
|
//新增时判断筛选条件
|
||||||
async function handleSheepFilter() {
|
async function handleSheepFilter() {
|
||||||
const { foldFrom, sheepTypeId } = form.value;
|
const { foldFrom, sheepTypeId, ranchId } = form.value;
|
||||||
let isOnlySheepfold = false;
|
let isOnlySheepfold = false;
|
||||||
let isOnlyTypeOrCombined = false;
|
let isOnlyTypeOrCombined = false;
|
||||||
|
|
||||||
|
if (!ranchId) {
|
||||||
|
form.value.manageTags = [];
|
||||||
|
sheepOptions.value = [];
|
||||||
|
proxy.$message.warning("请先选择牧场");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (foldFrom && !sheepTypeId) {
|
if (foldFrom && !sheepTypeId) {
|
||||||
isOnlySheepfold = true;
|
isOnlySheepfold = true;
|
||||||
} else if (!foldFrom && sheepTypeId) {
|
} else if (!foldFrom && sheepTypeId) {
|
||||||
@ -285,21 +309,22 @@ async function handleSheepFilter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isOnlySheepfold) {
|
if (isOnlySheepfold) {
|
||||||
await loadSheepBySheepfoldOnly(foldFrom);
|
await loadSheepBySheepfoldOnly(foldFrom, ranchId);
|
||||||
}
|
} else if (isOnlyTypeOrCombined) {
|
||||||
else if (isOnlyTypeOrCombined) {
|
|
||||||
form.value.manageTags = [];
|
form.value.manageTags = [];
|
||||||
let loadedSheep = [];
|
let loadedSheep = [];
|
||||||
|
|
||||||
if (foldFrom && sheepTypeId) {
|
if (foldFrom && sheepTypeId) {
|
||||||
loadedSheep = await loadSheepBySheepfoldAndType(foldFrom, sheepTypeId);
|
loadedSheep = await loadSheepBySheepfoldAndType(foldFrom, sheepTypeId, ranchId);
|
||||||
} else if (sheepTypeId) {
|
} else if (sheepTypeId) {
|
||||||
loadedSheep = await loadSheepByTypeOnly(sheepTypeId);
|
loadedSheep = await loadSheepByTypeOnly(sheepTypeId, ranchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadedSheep.length > 0) {
|
if (loadedSheep.length > 0) {
|
||||||
form.value.manageTags = loadedSheep.map((sheep) => sheep.manageTags);
|
form.value.manageTags = loadedSheep.map((sheep) => sheep.manageTags);
|
||||||
await loadSheepInfo();
|
await loadSheepInfo();
|
||||||
|
} else {
|
||||||
|
proxy.$message.info("未查询到符合条件的耳号");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -325,24 +350,77 @@ function getSheepTypeList() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//加载所有牧场列表
|
||||||
|
function loadRanchList() {
|
||||||
|
listRanch().then(res => {
|
||||||
|
ranchOptions.value = res.rows.map(ranch => ({
|
||||||
|
id: ranch.id,
|
||||||
|
ranchName: ranch.ranch
|
||||||
|
}));
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('加载牧场列表失败', error);
|
||||||
|
proxy.$modal.msgError('获取牧场数据失败');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//切换牧场时触发
|
||||||
|
function handleRanchChange(ranchId) {
|
||||||
|
form.value.foldFrom = null;
|
||||||
|
form.value.foldTo = null;
|
||||||
|
|
||||||
|
if (!ranchId) {
|
||||||
|
currentRanchSheepfolds.value = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
request({
|
||||||
|
url: '/sheepfold_management/sheepfold_management/list',
|
||||||
|
method: 'get',
|
||||||
|
params: { ranchId, pageNum: 1, pageSize: 9999 }
|
||||||
|
}).then(res => {
|
||||||
|
currentRanchSheepfolds.value = res.rows || [];
|
||||||
|
if (currentRanchSheepfolds.value.length === 0) {
|
||||||
|
proxy.$modal.msgWarning(`所选牧场(ID:${ranchId})暂无羊舍数据`);
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('加载牧场羊舍失败', error);
|
||||||
|
proxy.$modal.msgError('获取羊舍数据失败');
|
||||||
|
currentRanchSheepfolds.value = [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//只通过羊舍
|
//只通过羊舍
|
||||||
async function loadSheepBySheepfoldOnly(sheepfoldId) {
|
async function loadSheepBySheepfoldOnly(sheepfoldId, ranchId) {
|
||||||
|
if (!sheepfoldId || isNaN(Number(sheepfoldId))) {
|
||||||
|
proxy.$message.error('请选择有效的羊舍');
|
||||||
|
sheepOptions.value = [];
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (!ranchId) {
|
||||||
|
proxy.$message.error('牧场信息异常,请重新选择');
|
||||||
|
sheepOptions.value = [];
|
||||||
|
return [];
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const res = await getSheepBySheepfoldId(String(sheepfoldId));
|
const res = await getSheepBySheepfoldId(Number(sheepfoldId));
|
||||||
const newSheepList = (res.data || []).map((sheep) => ({
|
const newSheepList = (res.data || []).map((sheep) => ({
|
||||||
id: sheep.id,
|
id: sheep.id,
|
||||||
manageTags: sheep.manageTags,
|
manageTags: sheep.manageTags || '未知耳号',
|
||||||
sheepfoldId: sheepfoldId,
|
sheepfoldId: Number(sheepfoldId),
|
||||||
}));
|
})).filter(item => item.manageTags);
|
||||||
|
|
||||||
const existingTags = new Set(sheepOptions.value.map((item) => item.manageTags));
|
if (newSheepList.length === 0) {
|
||||||
const mergedSheep = newSheepList.filter((item) => !existingTags.has(item.manageTags));
|
proxy.$message.info('当前羊舍下暂无羊只数据');
|
||||||
|
sheepOptions.value = [];
|
||||||
sheepOptions.value.push(...mergedSheep);
|
return [];
|
||||||
return mergedSheep;
|
}
|
||||||
|
sheepOptions.value = newSheepList;
|
||||||
|
return newSheepList;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('根据羊舍加载耳号失败', error);
|
console.error('根据羊舍加载耳号失败:', error);
|
||||||
proxy.$modal.msgError('加载羊舍耳号失败,请重试');
|
const errorMsg = error.response?.data?.msg || '加载羊舍耳号失败,请重试';
|
||||||
|
proxy.$modal.msgError(errorMsg);
|
||||||
|
sheepOptions.value = [];
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -507,16 +585,10 @@ async function handleUpdate(row) {
|
|||||||
isEdit: true
|
isEdit: true
|
||||||
};
|
};
|
||||||
|
|
||||||
// 5. 验证匹配情况(调试用)
|
|
||||||
// const foldFromItem = sheepfoldOptions.value.find(item => item.id === formData.foldFrom);
|
|
||||||
// const foldToItem = sheepfoldOptions.value.find(item => item.id === formData.foldTo);
|
|
||||||
// const sheepTypeItem = sheepTypeOptions.value.find(item => item.id === formData.sheepTypeId);
|
|
||||||
// console.log("转出羊舍匹配结果:", foldFromItem ? foldFromItem.sheepfoldName : "未找到");
|
|
||||||
// console.log("转入羊舍匹配结果:", foldToItem ? foldToItem.sheepfoldName : "未找到");
|
|
||||||
// console.log("羊只类型匹配结果:", sheepTypeItem ? sheepTypeItem.name : "未找到");
|
|
||||||
|
|
||||||
form.value = formData;
|
form.value = formData;
|
||||||
|
form.value.ranchId = row.ranchId;
|
||||||
|
handleRanchChange(row.ranchId);
|
||||||
|
isAdd.value = false;
|
||||||
if (manageTags.length > 0) {
|
if (manageTags.length > 0) {
|
||||||
await loadSheepInfo();
|
await loadSheepInfo();
|
||||||
}
|
}
|
||||||
@ -622,6 +694,7 @@ function handleApproveReject() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//加载羊舍数据
|
||||||
function loadSheepfold() {
|
function loadSheepfold() {
|
||||||
listSheepfold({ pageNum: 1, pageSize: 9999 }).then((res) => {
|
listSheepfold({ pageNum: 1, pageSize: 9999 }).then((res) => {
|
||||||
sheepfoldOptions.value = res.rows;
|
sheepfoldOptions.value = res.rows;
|
||||||
@ -632,6 +705,7 @@ function loadSheepfold() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取品种数据
|
||||||
function getVarietyOptions() {
|
function getVarietyOptions() {
|
||||||
request({
|
request({
|
||||||
url: '/base/variety/list',
|
url: '/base/variety/list',
|
||||||
@ -644,6 +718,7 @@ function getVarietyOptions() {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadSheepfold();
|
loadSheepfold();
|
||||||
|
loadRanchList();
|
||||||
getVarietyOptions();
|
getVarietyOptions();
|
||||||
getSheepTypeList();
|
getSheepTypeList();
|
||||||
getList();
|
getList();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user