Files
pig-farm-controller-fe/src/components/PigPenInfoCard.vue
2025-10-23 18:23:31 +08:00

128 lines
3.1 KiB
Vue

<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">存栏: <span :class="{'over-capacity': pen.current_pig_count > pen.capacity}">{{ pen.current_pig_count || 0 }}</span></div>
</div>
<div class="actions-section">
<el-button size="small" @click="emitEdit">编辑</el-button>
<el-button size="small" type="danger" @click="emitDelete">删除</el-button>
</div>
</div>
</template>
<script>
import { computed } from 'vue';
export default {
name: 'PigPenInfoCard',
props: {
pen: {
type: Object,
required: true
}
},
emits: ['edit', 'delete'],
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 emitEdit = () => {
emit('edit', props.pen);
};
const emitDelete = () => {
emit('delete', props.pen);
};
return {
statusType,
emitEdit,
emitDelete
};
}
}
</script>
<style scoped>
.pig-pen-info-card {
border: 2px solid #ccc;
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;
}
.over-capacity {
color: red;
}
</style>