<template>
  <view class="box-container">
    <view 
      v-for="(item, index) in data" 
      :key="index" 
      class="box-item"
      :style="{ 
        'grid-column': `span ${item.span || 1}`,
        'background-color': item.bgColor || '#fff'
      }"
    >
      <!-- 第一个内容区域 -->
      <view class="box-content top">
        <slot name="top" :item="item" :index="index">
          <text class="content-text">{{ item.top || '顶部内容' }}</text>
        </slot>
      </view>
      
      <!-- 第二个内容区域 -->
      <view class="box-content middle">
        <slot name="middle" :item="item" :index="index">
          <text class="content-text">{{ item.middle || '中间内容' }}</text>
        </slot>
      </view>
      
      <!-- 第三个内容区域 -->
      <view class="box-content bottom">
        <slot name="bottom" :item="item" :index="index">
          <text class="content-text">{{ item.bottom || '底部内容' }}</text>
        </slot>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'BoxGrid',
  props: {
    // 数据数组
    data: {
      type: Array,
      default: () => []
    },
    // 每行显示的列数
    columns: {
      type: Number,
      default: 3
    },
    // 间距
    gap: {
      type: String,
      default: '20rpx'
    },
    // 圆角大小
    borderRadius: {
      type: String,
      default: '16rpx'
    },
    // 内边距
    padding: {
      type: String,
      default: '24rpx'
    }
  },
  computed: {
    // 动态计算grid布局
    gridStyle() {
      return {
        'grid-template-columns': `repeat(${this.columns}, 1fr)`,
        'gap': this.gap
      }
    }
  }
}
</script>

<style scoped>
.box-container {
  display: grid;
  width: 100%;
}

.box-item {
  border-radius: v-bind(borderRadius);
  padding: v-bind(padding);
  box-shadow: 0 4rpx 12rpx 0 rgba(0, 0, 0, 0.08);
  border: 1rpx solid #f0f0f0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 200rpx;
}

.box-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.box-content.top {
  font-size: 28rpx;
  font-weight: 600;
  color: #333;
}

.box-content.middle {
  font-size: 32rpx;
  font-weight: bold;
  color: #1890ff;
}

.box-content.bottom {
  font-size: 24rpx;
  color: #666;
}

.content-text {
  text-align: center;
  word-break: break-all;
}
</style>