支持移除猪栏
This commit is contained in:
@@ -7,7 +7,9 @@
|
||||
<span>批次编号: {{ batch.batch_number }}</span>
|
||||
<span>状态: {{ batch.status }}</span>
|
||||
<span>初始数量: {{ batch.initial_count }}</span>
|
||||
<span v-if="batch.currentTotalQuantity !== undefined && batch.currentTotalQuantity !== null">当前总数: {{ batch.currentTotalQuantity }}</span>
|
||||
<span v-if="batch.currentTotalQuantity !== undefined && batch.currentTotalQuantity !== null">当前总数: {{
|
||||
batch.currentTotalQuantity
|
||||
}}</span>
|
||||
<span v-if="batch.origin_type">批次来源: {{ batch.origin_type }}</span>
|
||||
</div>
|
||||
<div class="batch-info-line">
|
||||
@@ -27,7 +29,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="batch-actions">
|
||||
<el-button size="small" type="primary" @click.stop="showAddPenDialog(batch)" :disabled="!batch.is_active">增加猪栏</el-button>
|
||||
<el-button size="small" type="primary" @click.stop="showAddPenDialog(batch)" :disabled="!batch.is_active">
|
||||
增加猪栏
|
||||
</el-button>
|
||||
<el-button size="small" @click.stop="emitEditBatch(batch)">编辑</el-button>
|
||||
<el-button size="small" type="danger" @click.stop="emitDeleteBatch(batch)">删除</el-button>
|
||||
</div>
|
||||
@@ -35,12 +39,12 @@
|
||||
<div v-if="batch.isExpanded" class="batch-content">
|
||||
<div v-if="batch.pens && batch.pens.length > 0" class="pig-pen-list">
|
||||
<PigBatchPenCard
|
||||
v-for="pen in batch.pens"
|
||||
:key="pen.id"
|
||||
:pen="pen"
|
||||
:isBatchActive="batch.is_active"
|
||||
@allocate-pigs="showAllocatePigsDialog($event, batch)"
|
||||
@remove="emitRemovePen"
|
||||
v-for="pen in batch.pens"
|
||||
:key="pen.id"
|
||||
:pen="pen"
|
||||
:isBatchActive="batch.is_active"
|
||||
@allocate-pigs="showAllocatePigsDialog($event, batch)"
|
||||
@remove="emitRemovePen"
|
||||
/>
|
||||
</div>
|
||||
<div v-else class="no-pens-message">
|
||||
@@ -53,10 +57,10 @@
|
||||
<el-dialog title="选择猪栏" v-model="addPenDialogVisible" width="30%">
|
||||
<el-select v-model="selectedPenId" placeholder="请选择猪栏" style="width: 100%;">
|
||||
<el-option
|
||||
v-for="pen in availablePens"
|
||||
:key="pen.id"
|
||||
:label="pen.label"
|
||||
:value="pen.id">
|
||||
v-for="pen in availablePens"
|
||||
:key="pen.id"
|
||||
:label="pen.label"
|
||||
:value="pen.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<template #footer>
|
||||
@@ -69,11 +73,11 @@
|
||||
|
||||
<!-- 分配猪只对话框 -->
|
||||
<AllocatePigsDialog
|
||||
v-if="allocatePigsDialogVisible"
|
||||
:visible.sync="allocatePigsDialogVisible"
|
||||
:unassigned-pig-count="currentBatch ? currentBatch.unassigned_pig_count : 0"
|
||||
:pen-id="selectedPenForAllocation ? selectedPenForAllocation.id : 0"
|
||||
@confirm="handleAllocatePigs"
|
||||
v-if="allocatePigsDialogVisible"
|
||||
:visible.sync="allocatePigsDialogVisible"
|
||||
:unassigned-pig-count="currentBatch ? currentBatch.unassigned_pig_count : 0"
|
||||
:pen-id="selectedPenForAllocation ? selectedPenForAllocation.id : 0"
|
||||
@confirm="handleAllocatePigs"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -81,8 +85,8 @@
|
||||
<script>
|
||||
import PigBatchPenCard from './PigBatchPenCard.vue';
|
||||
import AllocatePigsDialog from './AllocatePigsDialog.vue';
|
||||
import { getAllPens, getAllPigHouses, movePigsIntoPen } from '../api/pigBatch';
|
||||
import { formatRFC3339 } from '../utils/format'; // 导入格式化函数
|
||||
import {getAllPens, getAllPigHouses, movePigsIntoPen} from '../api/pigBatch';
|
||||
import {formatRFC3339} from '../utils/format'; // 导入格式化函数
|
||||
|
||||
export default {
|
||||
name: 'PigBatchList',
|
||||
@@ -119,7 +123,7 @@ export default {
|
||||
getAllPigHouses()
|
||||
]);
|
||||
|
||||
const pens = pensResponse.data;
|
||||
const pens = pensResponse.data;
|
||||
const houses = housesResponse.data;
|
||||
|
||||
// Create a map for quick lookup of house names by ID
|
||||
@@ -156,9 +160,9 @@ export default {
|
||||
this.selectedPenForAllocation = pen;
|
||||
this.allocatePigsDialogVisible = true;
|
||||
},
|
||||
async handleAllocatePigs({ penId, quantity }) {
|
||||
async handleAllocatePigs({penId, quantity}) {
|
||||
try {
|
||||
await movePigsIntoPen(this.currentBatch.id, { toPenID: penId, quantity });
|
||||
await movePigsIntoPen(this.currentBatch.id, {toPenID: penId, quantity});
|
||||
this.$message.success('猪只分配成功');
|
||||
this.allocatePigsDialogVisible = false;
|
||||
this.$emit('reload-data'); // 通知父组件重新加载数据
|
||||
@@ -252,20 +256,6 @@ export default {
|
||||
}
|
||||
|
||||
.batch-info-line .red-text {
|
||||
color: red !important; // src/api/pigBatch.js 中错误的部分
|
||||
|
||||
/**
|
||||
* 从猪批次移除空栏
|
||||
* @param {number} batchID - 猪批次ID
|
||||
* @param {number} penID - 待移除的猪栏ID
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export const removePenFromBatch = (batchID, penID) = > {
|
||||
// BUG: URL中的参数顺序 ${penID}/${batchID} 与函数签名 (batchID, penID) 不一致
|
||||
|
||||
return http.
|
||||
|
||||
delete(` /api/ v1 /pig-batches/ remove-pen / ${penID} / ${batchID} `);
|
||||
};
|
||||
color: red !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user