群内调栏
This commit is contained in:
@@ -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>
|
||||
@@ -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);
|
||||
|
||||
161
src/components/TransferPigsModal.vue
Normal file
161
src/components/TransferPigsModal.vue
Normal 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>
|
||||
@@ -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(); // 重新加载数据以反映变化
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user