<template>
  <view
    class="up-grid"
    :class="[bottomLine ? '' : 'up-grid-bottom', border ? '' : 'up-grid__unlined', 'up-grid-' + (cell < 2 ? 3 : cell)]"
    :hover-class="hover ? 'up-item-hover' : ''"
    :hover-stay-time="150"
    :style="{ backgroundColor: backgroundColor }"
    @tap="handleClick"
  >
    <view class="up-grid-bg">
      <slot></slot>
    </view>
  </view>
</template>

<script>
export default {
  name: 'tuiGridItem',
  emits: ['click'],
  props: {
    cell: {
      type: [Number, String],
      default: 3
    },
    backgroundColor: {
      type: String,
      default: '#fff'
    },
    //是否有点击效果
    hover: {
      type: Boolean,
      default: true
    },
    //是否需要底部线条
    bottomLine: {
      type: Boolean,
      default: true
    },
    //是否需要纵向边框线条
    border: {
      type: Boolean,
      default: true
    },
    index: {
      type: Number,
      default: 0
    }
  },
  methods: {
    handleClick() {
      this.$emit('click', {
        index: this.index
      });
    }
  }
};
</script>

<style scoped>
.up-grid {
  position: relative;
  padding: 40rpx 20rpx;
  box-sizing: border-box;
  background: #fff;
  float: left;
}
/* #ifdef MP-BAIDU */
.up-grid:active {
  background-color: #f7f7f9;
}
/* #endif */

.up-grid-2 {
  width: 50%;
}

.up-grid-3 {
  width: 33.333333333%;
}

.up-grid-4 {
  width: 25%;
  padding: 30rpx 20rpx !important;
}

.up-grid-5 {
  width: 20%;
  padding: 20rpx !important;
}

.up-grid-2:nth-of-type(2n)::before {
  width: 0;
  border-right: 0;
}

.up-grid-3:nth-of-type(3n)::before {
  width: 0;
  border-right: 0;
}

.up-grid-4:nth-of-type(4n)::before {
  width: 0;
  border-right: 0;
}

.up-grid-5:nth-of-type(5n)::before {
  width: 0;
  border-right: 0;
}

.up-grid::before {
  content: ' ';
  position: absolute;
  right: 0;
  top: 0;
  width: 1px;
  bottom: 0;
  border-right: 1px solid #eaeef1;
  -webkit-transform-origin: 100% 0;
  transform-origin: 100% 0;
  -webkit-transform: scaleX(0.5);
  transform: scaleX(0.5);
}

.up-grid__unlined::before {
  width: 0 !important;
  border-right: 0 !important;
}

.up-grid::after {
  content: ' ';
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  height: 1px;
  border-bottom: 1px solid #eaeef1;
  -webkit-transform-origin: 0 100%;
  transform-origin: 0 100%;
  -webkit-transform: scaleY(0.5);
  transform: scaleY(0.5);
}

.up-grid-bottom::after {
  height: 0 !important;
  border-bottom: 0 !important;
}

.up-grid-bg {
  position: relative;
  padding: 0;
  width: 100%;
  box-sizing: border-box;
}

.up-item-hover {
  background-color: #f7f7f9 !important;
}
</style>
