Compare commits

..

3 Commits

Author SHA1 Message Date
e341e53fe2 修bug 2025-10-23 16:07:21 +08:00
03eed8202b 支持移除猪栏 2025-10-23 15:47:13 +08:00
624592a63d 支持移除猪栏 2025-10-23 15:45:14 +08:00
4 changed files with 37 additions and 37 deletions

View File

@@ -244,11 +244,11 @@ export const assignPensToBatch = (id, pensData) => {
/**
* 从猪批次移除空栏
* @param {number} batchID - 猪批次ID
* @param {number} penID - 待移除的猪栏ID
* @param {number} batchID - 猪批次ID
* @returns {Promise<*>}
*/
export const removePenFromBatch = (batchID, penID) => {
export const removePenFromBatch = (penID, batchID) => {
return http.delete(`/api/v1/pig-batches/remove-pen/${penID}/${batchID}`);
};

View File

@@ -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>

View File

@@ -11,7 +11,7 @@
</div>
<div class="actions-section">
<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>
</template>

View File

@@ -70,8 +70,8 @@
</template>
<script>
import { getPigBatches, deletePigBatch, assignPensToBatch } from '@/api/pigBatch.js';
import { getPens, deletePen } from '@/api/pen.js';
import { getPigBatches, deletePigBatch, assignPensToBatch, removePenFromBatch } from '@/api/pigBatch.js';
import { getPens } from '@/api/pen.js';
import { getPigHouses } from '@/api/pigHouse.js';
import PigBatchList from '@/components/PigBatchList.vue';
import PigBatchForm from '@/components/PigBatchForm.vue';
@@ -215,22 +215,18 @@ export default {
},
async handleRemovePen(pen) {
try {
await this.$confirm(`确认删除猪栏 "${pen.pen_number}" 吗?`, '提示', {
await this.$confirm(`确认猪栏 "${pen.pen_number}" 从猪群中移除吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
});
await deletePen(pen.id);
this.$message.success('删除成功');
// 本地更新数据
const batch = this.pigBatchesData.find(b => b.id === pen.pig_batch_id);
if (batch) {
batch.pens = batch.pens.filter(p => p.id !== pen.id);
}
await removePenFromBatch(pen.id, pen.pig_batch_id);
this.$message.success('猪栏已成功从猪群中移除');
await this.loadData(); // Refresh data to show updated state
} catch (err) {
if (err !== 'cancel') {
this.$message.error('除失败: ' + (err.message || '未知错误'));
console.error('Failed to delete pen:', err);
this.$message.error('除失败: ' + (err.message || '未知错误'));
console.error('Failed to remove pen from batch:', err);
}
}
},