支持移除猪栏
This commit is contained in:
@@ -252,6 +252,20 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.batch-info-line .red-text {
|
.batch-info-line .red-text {
|
||||||
color: red !important;
|
color: red !important; // src/api/pigBatch.js 中错误的部分
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从猪批次移除空栏
|
||||||
|
* @param {number} batchID - 猪批次ID
|
||||||
|
* @param {number} penID - 待移除的猪栏ID
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export const removePenFromBatch = (batchID, penID) = > {
|
||||||
|
// BUG: URL中的参数顺序 ${penID}/${batchID} 与函数签名 (batchID, penID) 不一致
|
||||||
|
|
||||||
|
return http.
|
||||||
|
|
||||||
|
delete(` /api/ v1 /pig-batches/ remove-pen / ${penID} / ${batchID} `);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -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