Compare commits

...

3 Commits

Author SHA1 Message Date
e1fb3055bb 优化展示 2025-10-23 18:23:31 +08:00
6d452394aa 修bug 2025-10-23 18:18:07 +08:00
62801326cb 群内调栏 2025-10-23 18:05:41 +08:00
5 changed files with 214 additions and 6 deletions

View File

@@ -32,6 +32,15 @@
<el-button size="small" type="primary" @click.stop="showAddPenDialog(batch)" :disabled="!batch.is_active">
增加猪栏
</el-button>
<el-button
size="small"
type="success"
@click.stop="emitTransferPigs(batch)"
:disabled="!batch.is_active || !batch.pens || batch.pens.length < 2"
title="将猪从一个猪栏转移到同一批次的另一个猪栏"
>
群内调栏
</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>
@@ -43,6 +52,7 @@
:key="pen.id"
:pen="pen"
:isBatchActive="batch.is_active"
:batchUnassignedPigCount="batch.unassigned_pig_count"
@allocate-pigs="showAllocatePigsDialog($event, batch)"
@remove="emitRemovePen"
/>
@@ -73,8 +83,7 @@
<!-- 分配猪只对话框 -->
<AllocatePigsDialog
v-if="allocatePigsDialogVisible"
:visible.sync="allocatePigsDialogVisible"
v-model:visible="allocatePigsDialogVisible"
:unassigned-pig-count="currentBatch ? currentBatch.unassigned_pig_count : 0"
:pen-id="selectedPenForAllocation ? selectedPenForAllocation.id : 0"
@confirm="handleAllocatePigs"
@@ -100,7 +109,7 @@ export default {
required: true
}
},
emits: ['edit-batch', 'delete-batch', 'add-pen', 'remove-pen', 'assign-pen-to-batch', 'reload-data'],
emits: ['edit-batch', 'delete-batch', 'add-pen', 'remove-pen', 'assign-pen-to-batch', 'reload-data', 'transfer-pigs'],
data() {
return {
addPenDialogVisible: false,
@@ -181,6 +190,9 @@ export default {
emitDeleteBatch(batch) {
this.$emit('delete-batch', batch);
},
emitTransferPigs(batch) {
this.$emit('transfer-pigs', batch);
},
// 猪栏操作
emitRemovePen(pen) {
this.$emit('remove-pen', pen);

View File

@@ -7,10 +7,10 @@
<div class="info-item">猪舍: {{ pen.house_name || '未知' }}</div>
<div class="info-item border-left">容量: {{ pen.capacity }}</div>
<div class="info-item">批次: {{ pen.batch_number || '未分配' }}</div>
<div class="info-item border-left">存栏: {{ pen.current_pig_count || 0 }}</div>
<div class="info-item border-left">存栏: <span :class="{'over-capacity': pen.current_pig_count > pen.capacity}">{{ pen.current_pig_count || 0 }}</span></div>
</div>
<div class="actions-section">
<el-button size="small" @click="emitAllocatePigs" :disabled="!isBatchActive">分配猪只</el-button>
<el-button size="small" @click="emitAllocatePigs" :disabled="!isBatchActive || batchUnassignedPigCount <= 0">分配猪只</el-button>
<el-button size="small" type="danger" @click="emitRemove" :disabled="!isBatchActive || pen.current_pig_count > 0">移除</el-button>
</div>
</div>
@@ -29,6 +29,10 @@ export default {
isBatchActive: {
type: Boolean,
default: true // 默认活跃,以防万一没有传递
},
batchUnassignedPigCount: {
type: Number,
default: 0
}
},
emits: ['remove', 'allocate-pigs'],
@@ -124,4 +128,8 @@ export default {
width: 100%;
margin: 0;
}
.over-capacity {
color: red;
}
</style>

View File

@@ -7,7 +7,7 @@
<div class="info-item">猪舍: {{ pen.house_name || '未知' }}</div>
<div class="info-item border-left">容量: {{ pen.capacity }}</div>
<div class="info-item">批次: {{ pen.batch_number || '未分配' }}</div>
<div class="info-item border-left">存栏: {{ pen.current_pig_count || 0 }}</div>
<div class="info-item border-left">存栏: <span :class="{'over-capacity': pen.current_pig_count > pen.capacity}">{{ pen.current_pig_count || 0 }}</span></div>
</div>
<div class="actions-section">
<el-button size="small" @click="emitEdit">编辑</el-button>
@@ -120,4 +120,8 @@ export default {
width: 100%;
margin: 0;
}
.over-capacity {
color: red;
}
</style>

View File

@@ -0,0 +1,161 @@
<template>
<el-dialog
title="群内调栏"
:model-value="visible"
@update:model-value="$emit('update:visible', $event)"
width="500px"
:before-close="handleClose"
>
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
<el-form-item label="调出猪栏" prop="fromPenID">
<el-select v-model="form.fromPenID" placeholder="请选择调出猪栏" style="width: 100%;" @change="handleFromPenChange">
<el-option
v-for="pen in sourcePens"
:key="pen.id"
:label="`${pen.pen_number} (存栏: ${pen.current_pig_count})`"
:value="pen.id"
:disabled="pen.current_pig_count === 0"
/>
</el-select>
</el-form-item>
<el-form-item label="调入猪栏" prop="toPenID">
<el-select v-model="form.toPenID" placeholder="请选择调入猪栏" style="width: 100%;" :disabled="!form.fromPenID">
<el-option
v-for="pen in destinationPens"
:key="pen.id"
:label="`${pen.pen_number} (存栏: ${pen.current_pig_count})`"
:value="pen.id"
/>
</el-select>
</el-form-item>
<el-form-item label="调栏数量" prop="quantity">
<el-input-number
v-model="form.quantity"
:min="1"
:max="maxQuantity"
:disabled="!form.fromPenID"
placeholder="请输入数量"
style="width: 100%;"
/>
</el-form-item>
<el-form-item label="备注" prop="remarks">
<el-input v-model="form.remarks" type="textarea" placeholder="请输入备注" />
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="handleClose"> </el-button>
<el-button type="primary" @click="handleSubmit" :loading="loading"> </el-button>
</span>
</template>
</el-dialog>
</template>
<script>
import { transferPigsWithinBatch } from '@/api/pigBatch.js';
export default {
name: 'TransferPigsModal',
props: {
visible: {
type: Boolean,
default: false,
},
batch: {
type: Object,
required: true,
},
},
emits: ['update:visible', 'success'],
data() {
return {
loading: false,
form: {
fromPenID: null,
toPenID: null,
quantity: 1,
remarks: '',
},
rules: {
fromPenID: [{ required: true, message: '请选择调出猪栏', trigger: 'change' }],
toPenID: [{ required: true, message: '请选择调入猪栏', trigger: 'change' }],
quantity: [{ required: true, message: '请输入调栏数量', trigger: 'blur' }],
},
};
},
computed: {
sourcePens() {
return this.batch.pens || [];
},
destinationPens() {
if (!this.form.fromPenID) return [];
return this.batch.pens.filter(pen => pen.id !== this.form.fromPenID);
},
maxQuantity() {
if (!this.form.fromPenID) return 1;
const selectedPen = this.sourcePens.find(p => p.id === this.form.fromPenID);
return selectedPen ? selectedPen.current_pig_count : 1;
},
},
watch: {
visible(newVal) {
if (newVal) {
this.resetForm();
}
},
},
methods: {
handleFromPenChange(penId) {
this.form.toPenID = null;
this.form.quantity = 1;
const selectedPen = this.sourcePens.find(p => p.id === penId);
if (selectedPen && selectedPen.current_pig_count === 0) {
this.$message.warning('该猪栏没有猪,无法调出。');
this.form.fromPenID = null;
}
},
handleSubmit() {
this.$refs.formRef.validate(async (valid) => {
if (valid) {
if (this.form.quantity > this.maxQuantity) {
this.$message.error('调栏数量不能超过当前存栏量');
return;
}
this.loading = true;
try {
await transferPigsWithinBatch(this.batch.id, this.form);
this.$message.success('调栏成功');
this.$emit('success');
this.handleClose();
} catch (error) {
this.$message.error('调栏失败: ' + (error.response?.data?.message || error.message));
console.error('Failed to transfer pigs:', error);
} finally {
this.loading = false;
}
}
});
},
handleClose() {
this.$emit('update:visible', false);
},
resetForm() {
if (this.$refs.formRef) {
this.$refs.formRef.resetFields();
}
this.form = {
fromPenID: null,
toPenID: null,
quantity: 1,
remarks: '',
};
},
},
};
</script>
<style scoped>
.dialog-footer {
text-align: right;
}
</style>

View File

@@ -42,6 +42,7 @@
@modify-pig-count-pen="handleModifyPigCountPen"
@remove-pen="handleRemovePen"
@assign-pen-to-batch="handleAssignPenToBatch"
@transfer-pigs="handleTransferPigs"
@reload-data="loadData"
/>
<el-empty v-else description="暂无数据" />
@@ -66,6 +67,14 @@
@success="handlePenSuccess"
@cancel="penDialogVisible = false"
/>
<!-- 群内调栏对话框 -->
<TransferPigsModal
v-if="transferDialogVisible"
v-model:visible="transferDialogVisible"
:batch="currentBatchForTransfer"
@success="handleTransferSuccess"
/>
</div>
</template>
@@ -76,6 +85,7 @@ import { getPigHouses } from '@/api/pigHouse.js';
import PigBatchList from '@/components/PigBatchList.vue';
import PigBatchForm from '@/components/PigBatchForm.vue';
import PenForm from '@/components/PenForm.vue';
import TransferPigsModal from '@/components/TransferPigsModal.vue';
import { Refresh } from '@element-plus/icons-vue';
export default {
@@ -84,6 +94,7 @@ export default {
PigBatchList,
PigBatchForm,
PenForm,
TransferPigsModal,
Refresh
},
data() {
@@ -99,6 +110,9 @@ export default {
penDialogVisible: false,
isEditPen: false,
currentPen: {},
// 调栏模态框状态
transferDialogVisible: false,
currentBatchForTransfer: {},
// 辅助映射
houseMap: new Map(), // 用于猪栏显示猪舍名称
};
@@ -264,6 +278,15 @@ export default {
this.$message.error('分配猪栏失败: ' + (error.response?.data?.message || error.message || '未知错误'));
console.error('Failed to assign pen to batch:', error);
}
},
// --- 调栏操作 ---
handleTransferPigs(batch) {
this.currentBatchForTransfer = batch;
this.transferDialogVisible = true;
},
handleTransferSuccess() {
this.transferDialogVisible = false;
this.loadData(); // 重新加载数据以反映变化
}
}
}