Compare commits
3 Commits
2191bf2bdf
...
e341e53fe2
| Author | SHA1 | Date | |
|---|---|---|---|
| e341e53fe2 | |||
| 03eed8202b | |||
| 624592a63d |
@@ -244,11 +244,11 @@ export const assignPensToBatch = (id, pensData) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从猪批次移除空栏
|
* 从猪批次移除空栏
|
||||||
* @param {number} batchID - 猪批次ID
|
|
||||||
* @param {number} penID - 待移除的猪栏ID
|
* @param {number} penID - 待移除的猪栏ID
|
||||||
|
* @param {number} batchID - 猪批次ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const removePenFromBatch = (batchID, penID) => {
|
export const removePenFromBatch = (penID, batchID) => {
|
||||||
return http.delete(`/api/v1/pig-batches/remove-pen/${penID}/${batchID}`);
|
return http.delete(`/api/v1/pig-batches/remove-pen/${penID}/${batchID}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
<span>批次编号: {{ batch.batch_number }}</span>
|
<span>批次编号: {{ batch.batch_number }}</span>
|
||||||
<span>状态: {{ batch.status }}</span>
|
<span>状态: {{ batch.status }}</span>
|
||||||
<span>初始数量: {{ batch.initial_count }}</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>
|
<span v-if="batch.origin_type">批次来源: {{ batch.origin_type }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="batch-info-line">
|
<div class="batch-info-line">
|
||||||
@@ -27,7 +29,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="batch-actions">
|
<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" @click.stop="emitEditBatch(batch)">编辑</el-button>
|
||||||
<el-button size="small" type="danger" @click.stop="emitDeleteBatch(batch)">删除</el-button>
|
<el-button size="small" type="danger" @click.stop="emitDeleteBatch(batch)">删除</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -35,12 +39,12 @@
|
|||||||
<div v-if="batch.isExpanded" class="batch-content">
|
<div v-if="batch.isExpanded" class="batch-content">
|
||||||
<div v-if="batch.pens && batch.pens.length > 0" class="pig-pen-list">
|
<div v-if="batch.pens && batch.pens.length > 0" class="pig-pen-list">
|
||||||
<PigBatchPenCard
|
<PigBatchPenCard
|
||||||
v-for="pen in batch.pens"
|
v-for="pen in batch.pens"
|
||||||
:key="pen.id"
|
:key="pen.id"
|
||||||
:pen="pen"
|
:pen="pen"
|
||||||
:isBatchActive="batch.is_active"
|
:isBatchActive="batch.is_active"
|
||||||
@allocate-pigs="showAllocatePigsDialog($event, batch)"
|
@allocate-pigs="showAllocatePigsDialog($event, batch)"
|
||||||
@remove="emitRemovePen"
|
@remove="emitRemovePen"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="no-pens-message">
|
<div v-else class="no-pens-message">
|
||||||
@@ -53,10 +57,10 @@
|
|||||||
<el-dialog title="选择猪栏" v-model="addPenDialogVisible" width="30%">
|
<el-dialog title="选择猪栏" v-model="addPenDialogVisible" width="30%">
|
||||||
<el-select v-model="selectedPenId" placeholder="请选择猪栏" style="width: 100%;">
|
<el-select v-model="selectedPenId" placeholder="请选择猪栏" style="width: 100%;">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="pen in availablePens"
|
v-for="pen in availablePens"
|
||||||
:key="pen.id"
|
:key="pen.id"
|
||||||
:label="pen.label"
|
:label="pen.label"
|
||||||
:value="pen.id">
|
:value="pen.id">
|
||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@@ -69,11 +73,11 @@
|
|||||||
|
|
||||||
<!-- 分配猪只对话框 -->
|
<!-- 分配猪只对话框 -->
|
||||||
<AllocatePigsDialog
|
<AllocatePigsDialog
|
||||||
v-if="allocatePigsDialogVisible"
|
v-if="allocatePigsDialogVisible"
|
||||||
:visible.sync="allocatePigsDialogVisible"
|
:visible.sync="allocatePigsDialogVisible"
|
||||||
:unassigned-pig-count="currentBatch ? currentBatch.unassigned_pig_count : 0"
|
:unassigned-pig-count="currentBatch ? currentBatch.unassigned_pig_count : 0"
|
||||||
:pen-id="selectedPenForAllocation ? selectedPenForAllocation.id : 0"
|
:pen-id="selectedPenForAllocation ? selectedPenForAllocation.id : 0"
|
||||||
@confirm="handleAllocatePigs"
|
@confirm="handleAllocatePigs"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -81,8 +85,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import PigBatchPenCard from './PigBatchPenCard.vue';
|
import PigBatchPenCard from './PigBatchPenCard.vue';
|
||||||
import AllocatePigsDialog from './AllocatePigsDialog.vue';
|
import AllocatePigsDialog from './AllocatePigsDialog.vue';
|
||||||
import { getAllPens, getAllPigHouses, movePigsIntoPen } from '../api/pigBatch';
|
import {getAllPens, getAllPigHouses, movePigsIntoPen} from '../api/pigBatch';
|
||||||
import { formatRFC3339 } from '../utils/format'; // 导入格式化函数
|
import {formatRFC3339} from '../utils/format'; // 导入格式化函数
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PigBatchList',
|
name: 'PigBatchList',
|
||||||
@@ -119,7 +123,7 @@ export default {
|
|||||||
getAllPigHouses()
|
getAllPigHouses()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const pens = pensResponse.data;
|
const pens = pensResponse.data;
|
||||||
const houses = housesResponse.data;
|
const houses = housesResponse.data;
|
||||||
|
|
||||||
// Create a map for quick lookup of house names by ID
|
// Create a map for quick lookup of house names by ID
|
||||||
@@ -156,9 +160,9 @@ export default {
|
|||||||
this.selectedPenForAllocation = pen;
|
this.selectedPenForAllocation = pen;
|
||||||
this.allocatePigsDialogVisible = true;
|
this.allocatePigsDialogVisible = true;
|
||||||
},
|
},
|
||||||
async handleAllocatePigs({ penId, quantity }) {
|
async handleAllocatePigs({penId, quantity}) {
|
||||||
try {
|
try {
|
||||||
await movePigsIntoPen(this.currentBatch.id, { toPenID: penId, quantity });
|
await movePigsIntoPen(this.currentBatch.id, {toPenID: penId, quantity});
|
||||||
this.$message.success('猪只分配成功');
|
this.$message.success('猪只分配成功');
|
||||||
this.allocatePigsDialogVisible = false;
|
this.allocatePigsDialogVisible = false;
|
||||||
this.$emit('reload-data'); // 通知父组件重新加载数据
|
this.$emit('reload-data'); // 通知父组件重新加载数据
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="actions-section">
|
<div class="actions-section">
|
||||||
<el-button size="small" @click="emitAllocatePigs" :disabled="!isBatchActive">分配猪只</el-button>
|
<el-button size="small" @click="emitAllocatePigs" :disabled="!isBatchActive">分配猪只</el-button>
|
||||||
<el-button size="small" type="danger" @click="emitRemove" :disabled="!isBatchActive">移除</el-button>
|
<el-button size="small" type="danger" @click="emitRemove" :disabled="!isBatchActive || pen.current_pig_count > 0">移除</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -70,8 +70,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getPigBatches, deletePigBatch, assignPensToBatch } from '@/api/pigBatch.js';
|
import { getPigBatches, deletePigBatch, assignPensToBatch, removePenFromBatch } from '@/api/pigBatch.js';
|
||||||
import { getPens, deletePen } from '@/api/pen.js';
|
import { getPens } from '@/api/pen.js';
|
||||||
import { getPigHouses } from '@/api/pigHouse.js';
|
import { getPigHouses } from '@/api/pigHouse.js';
|
||||||
import PigBatchList from '@/components/PigBatchList.vue';
|
import PigBatchList from '@/components/PigBatchList.vue';
|
||||||
import PigBatchForm from '@/components/PigBatchForm.vue';
|
import PigBatchForm from '@/components/PigBatchForm.vue';
|
||||||
@@ -215,22 +215,18 @@ export default {
|
|||||||
},
|
},
|
||||||
async handleRemovePen(pen) {
|
async handleRemovePen(pen) {
|
||||||
try {
|
try {
|
||||||
await this.$confirm(`确认删除猪栏 "${pen.pen_number}" 吗?`, '提示', {
|
await this.$confirm(`确认将猪栏 "${pen.pen_number}" 从猪群中移除吗?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
});
|
});
|
||||||
await deletePen(pen.id);
|
await removePenFromBatch(pen.id, pen.pig_batch_id);
|
||||||
this.$message.success('删除成功');
|
this.$message.success('猪栏已成功从猪群中移除');
|
||||||
// 本地更新数据
|
await this.loadData(); // Refresh data to show updated state
|
||||||
const batch = this.pigBatchesData.find(b => b.id === pen.pig_batch_id);
|
|
||||||
if (batch) {
|
|
||||||
batch.pens = batch.pens.filter(p => p.id !== pen.id);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err !== 'cancel') {
|
if (err !== 'cancel') {
|
||||||
this.$message.error('删除失败: ' + (err.message || '未知错误'));
|
this.$message.error('移除失败: ' + (err.message || '未知错误'));
|
||||||
console.error('Failed to delete pen:', err);
|
console.error('Failed to remove pen from batch:', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user