调整卡片

This commit is contained in:
2025-10-23 13:46:54 +08:00
parent 1a55330734
commit 263af9fa3a
4 changed files with 160 additions and 29 deletions

View File

@@ -15,12 +15,12 @@
</div> </div>
<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">
<PigPenInfoCard <PigBatchPenCard
v-for="pen in batch.pens" v-for="pen in batch.pens"
:key="pen.id" :key="pen.id"
:pen="pen" :pen="pen"
@edit="emitEditPen" @modify-pig-count="emitModifyPigCountPen"
@delete="emitDeletePen" @remove="emitRemovePen"
/> />
</div> </div>
<div v-else class="no-pens-message"> <div v-else class="no-pens-message">
@@ -50,13 +50,13 @@
</template> </template>
<script> <script>
import PigPenInfoCard from './PigPenInfoCard.vue'; import PigBatchPenCard from './PigBatchPenCard.vue';
import { getAllPens, getAllPigHouses } from '../api/pigBatch'; // Import new API functions import { getAllPens, getAllPigHouses } from '../api/pigBatch'; // Import new API functions
export default { export default {
name: 'PigBatchList', name: 'PigBatchList',
components: { components: {
PigPenInfoCard PigBatchPenCard
}, },
props: { props: {
pigBatches: { pigBatches: {
@@ -64,7 +64,7 @@ export default {
required: true required: true
} }
}, },
emits: ['edit-batch', 'delete-batch', 'add-pen', 'edit-pen', 'delete-pen', 'assign-pen-to-batch'], emits: ['edit-batch', 'delete-batch', 'add-pen', 'modify-pig-count-pen', 'remove-pen', 'assign-pen-to-batch'],
data() { data() {
return { return {
addPenDialogVisible: false, addPenDialogVisible: false,
@@ -124,11 +124,11 @@ export default {
this.$emit('delete-batch', batch); this.$emit('delete-batch', batch);
}, },
// 猪栏操作 // 猪栏操作
emitEditPen(pen) { emitModifyPigCountPen(pen) {
this.$emit('edit-pen', pen); this.$emit('modify-pig-count-pen', pen);
}, },
emitDeletePen(pen) { emitRemovePen(pen) {
this.$emit('delete-pen', pen); this.$emit('remove-pen', pen);
} }
} }
} }

View File

@@ -0,0 +1,123 @@
<template>
<div class="pig-pen-info-card">
<div class="info-section">
<div class="title">
猪栏: {{ pen.pen_number }} <el-tag size="small" :type="statusType">{{ pen.status || '未知' }}</el-tag>
</div>
<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>
<div class="actions-section">
<el-button size="small" @click="emitModifyPigCount">修改猪只数量</el-button>
<el-button size="small" type="danger" @click="emitRemove">移除</el-button>
</div>
</div>
</template>
<script>
import { computed } from 'vue';
export default {
name: 'PigBatchPenCard',
props: {
pen: {
type: Object,
required: true
}
},
emits: ['remove', 'modify-pig-count'],
setup(props, { emit }) {
const statusType = computed(() => {
switch (props.pen.status) {
case '使用中':
return 'success';
case '病猪栏':
case '维修中':
return 'danger';
case '清洗消毒':
return 'warning';
case '空闲':
default:
return 'info';
}
});
const emitModifyPigCount = () => {
emit('modify-pig-count', props.pen);
};
const emitRemove = () => {
emit('remove', props.pen);
};
return {
statusType,
emitModifyPigCount,
emitRemove
};
}
}
</script>
<style scoped>
.pig-pen-info-card {
border: 1px solid #eee;
border-radius: 8px;
padding: 16px;
display: flex;
flex-direction: column;
justify-content: space-between;
width: 220px; /* 适当加宽以容纳更多信息 */
height: auto; /* 让高度自适应内容 */
min-height: 240px; /* 设置最小高度 */
background-color: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
transition: box-shadow 0.3s;
}
.pig-pen-info-card:hover {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.info-section {
display: grid; /* 使用grid布局创建两列 */
grid-template-columns: 1fr 1fr; /* 两列等宽 */
gap: 8px 10px; /* 行间距 8px, 列间距 10px */
margin-bottom: 10px;
flex-grow: 1; /* 允许信息部分填充可用空间 */
}
.info-section .title {
font-weight: bold;
font-size: 1.1em;
color: #303133;
grid-column: 1 / -1; /* 标题横跨两列 */
margin-bottom: 5px; /* 标题下方增加一点间距 */
display: flex; /* Add flexbox for alignment */
align-items: center; /* Vertically align items */
gap: 8px; /* Space between title text and tag */
}
.info-section .info-item {
font-size: 0.9em;
color: #606266;
}
.info-item.border-left {
border-left: 1px solid #eee; /* 添加左边框作为分隔线 */
padding-left: 10px; /* 增加左内边距,使内容不紧贴边框 */
}
.actions-section {
display: flex;
flex-direction: column;
gap: 8px;
}
.actions-section .el-button {
width: 100%;
margin: 0;
}
</style>

View File

@@ -1,12 +1,13 @@
<template> <template>
<div class="pig-pen-info-card"> <div class="pig-pen-info-card">
<div class="info-section"> <div class="info-section">
<div class="title">猪栏: {{ pen.pen_number }}</div> <div class="title">
<div class="info-item">状态: <el-tag size="small" :type="statusType">{{ pen.status || '未知' }}</el-tag></div> 猪栏: {{ pen.pen_number }} <el-tag size="small" :type="statusType">{{ pen.status || '未知' }}</el-tag>
<div class="info-item">容量: {{ pen.capacity }}</div> </div>
<div class="info-item">存栏: {{ pen.current_pig_count || 0 }}</div>
<div class="info-item">批次: {{ pen.batch_number || '未分配' }}</div>
<div class="info-item">猪舍: {{ pen.house_name || '未知' }}</div> <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> </div>
<div class="actions-section"> <div class="actions-section">
<el-button size="small" @click="emitEdit">编辑</el-button> <el-button size="small" @click="emitEdit">编辑</el-button>
@@ -68,8 +69,9 @@ export default {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
width: 200px; /* 适当加宽以容纳更多信息 */ width: 220px; /* 适当加宽以容纳更多信息 */
height: 260px; /* 调整高度适应更多信息 */ height: auto; /* 高度适应内容 */
min-height: 240px; /* 设置最小高度 */
background-color: #fff; background-color: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
transition: box-shadow 0.3s; transition: box-shadow 0.3s;
@@ -80,16 +82,22 @@ export default {
} }
.info-section { .info-section {
display: flex; display: grid; /* 使用grid布局创建两列 */
flex-direction: column; grid-template-columns: 1fr 1fr; /* 两列等宽 */
gap: 10px; /* 调整信息项间距 */ gap: 8px 10px; /* 行间距 8px, 列间距 10px */
margin-bottom: 10px; margin-bottom: 10px;
flex-grow: 1; /* 允许信息部分填充可用空间 */
} }
.info-section .title { .info-section .title {
font-weight: bold; font-weight: bold;
font-size: 1.1em; font-size: 1.1em;
color: #303133; color: #303133;
grid-column: 1 / -1; /* 标题横跨两列 */
margin-bottom: 5px; /* 标题下方增加一点间距 */
display: flex; /* Add flexbox for alignment */
align-items: center; /* Vertically align items */
gap: 8px; /* Space between title text and tag */
} }
.info-section .info-item { .info-section .info-item {
@@ -97,6 +105,11 @@ export default {
color: #606266; color: #606266;
} }
.info-item.border-left {
border-left: 1px solid #eee; /* 添加左边框作为分隔线 */
padding-left: 10px; /* 增加左内边距,使内容不紧贴边框 */
}
.actions-section { .actions-section {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@@ -39,8 +39,8 @@
@edit-batch="handleEditBatch" @edit-batch="handleEditBatch"
@delete-batch="handleDeleteBatch" @delete-batch="handleDeleteBatch"
@add-pen="handleAddPen" @add-pen="handleAddPen"
@edit-pen="handleEditPen" @modify-pig-count-pen="handleModifyPigCountPen"
@delete-pen="handleDeletePen" @remove-pen="handleRemovePen"
@assign-pen-to-batch="handleAssignPenToBatch" @assign-pen-to-batch="handleAssignPenToBatch"
/> />
<el-empty v-else description="暂无数据" /> <el-empty v-else description="暂无数据" />
@@ -201,17 +201,12 @@ export default {
} }
}, },
// --- 猪栏操作 (在猪群管理中) --- // --- 猪栏操作 (在猪群管理中) ---
handleAddPen(batch) { handleModifyPigCountPen(pen) {
this.currentPen = { pig_batch_id: batch.id }; // 预设猪栏所属批次
this.isEditPen = false;
this.penDialogVisible = true;
},
handleEditPen(pen) {
this.currentPen = { ...pen }; this.currentPen = { ...pen };
this.isEditPen = true; this.isEditPen = true;
this.penDialogVisible = true; this.penDialogVisible = true;
}, },
async handleDeletePen(pen) { async handleRemovePen(pen) {
try { try {
await this.$confirm(`确认删除猪栏 "${pen.pen_number}" 吗?`, '提示', { await this.$confirm(`确认删除猪栏 "${pen.pen_number}" 吗?`, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',