支持分配猪只

This commit is contained in:
2025-10-23 15:29:29 +08:00
parent d7d68684e4
commit 2191bf2bdf
4 changed files with 120 additions and 13 deletions

View File

@@ -39,7 +39,7 @@
:key="pen.id"
:pen="pen"
:isBatchActive="batch.is_active"
@modify-pig-count="emitModifyPigCountPen"
@allocate-pigs="showAllocatePigsDialog($event, batch)"
@remove="emitRemovePen"
/>
</div>
@@ -66,18 +66,29 @@
</span>
</template>
</el-dialog>
<!-- 分配猪只对话框 -->
<AllocatePigsDialog
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>
<script>
import PigBatchPenCard from './PigBatchPenCard.vue';
import { getAllPens, getAllPigHouses } from '../api/pigBatch';
import AllocatePigsDialog from './AllocatePigsDialog.vue';
import { getAllPens, getAllPigHouses, movePigsIntoPen } from '../api/pigBatch';
import { formatRFC3339 } from '../utils/format'; // 导入格式化函数
export default {
name: 'PigBatchList',
components: {
PigBatchPenCard
PigBatchPenCard,
AllocatePigsDialog
},
props: {
pigBatches: {
@@ -85,13 +96,15 @@ export default {
required: true
}
},
emits: ['edit-batch', 'delete-batch', 'add-pen', 'modify-pig-count-pen', 'remove-pen', 'assign-pen-to-batch'],
emits: ['edit-batch', 'delete-batch', 'add-pen', 'remove-pen', 'assign-pen-to-batch', 'reload-data'],
data() {
return {
addPenDialogVisible: false,
availablePens: [],
selectedPenId: null,
currentBatch: null // To store the batch for which we are adding a pen
currentBatch: null, // To store the batch for which we are adding a pen
allocatePigsDialogVisible: false,
selectedPenForAllocation: null
};
},
methods: {
@@ -138,6 +151,22 @@ export default {
this.$message.warning("请选择一个猪栏");
}
},
showAllocatePigsDialog(pen, batch) {
this.currentBatch = batch;
this.selectedPenForAllocation = pen;
this.allocatePigsDialogVisible = true;
},
async handleAllocatePigs({ penId, quantity }) {
try {
await movePigsIntoPen(this.currentBatch.id, { toPenID: penId, quantity });
this.$message.success('猪只分配成功');
this.allocatePigsDialogVisible = false;
this.$emit('reload-data'); // 通知父组件重新加载数据
} catch (error) {
console.error('Error allocating pigs:', error);
this.$message.error('分配猪只失败');
}
},
// 猪群操作
emitEditBatch(batch) {
this.$emit('edit-batch', batch);
@@ -146,9 +175,6 @@ export default {
this.$emit('delete-batch', batch);
},
// 猪栏操作
emitModifyPigCountPen(pen) {
this.$emit('modify-pig-count-pen', pen);
},
emitRemovePen(pen) {
this.$emit('remove-pen', pen);
}