<template>
  <div class="goods_info">
    <div v-for="(item, index) in showList" :key="item.id || index" class="row">
      <el-image :src="item.productImg" class="cover" lazy />
      <div class="info">
        <div class="name">
          <span :class="[item.isVip == 1 ? 'colorStyle' : '']">
            {{ item.productName }}
          </span>
          <span v-if="item.refundNum" class="refund">(退 - {{ item.refundNum }})</span>
          <span v-else-if="item.returnNum" class="refund">(退 - {{ item.returnNum }})</span>
        </div>
        <div class="sku">{{ item.skuName }}</div>
      </div>
    </div>

    <div v-if="needShowMore" class="show-more" @click="showAll = !showAll">
      {{ showAll ? "收起" : "查看全部" }}
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, ref } from "vue";

// 接收商品列表
const props = defineProps<{
  goods: any[];
}>();

// 组件内部独立状态，自己控制，不影响外部
const showAll = ref(false);

// 计算需要展示的列表
const showList = computed(() => {
  const list = props.goods || [];
  return showAll.value ? list : list.slice(0, 2);
});

// 是否需要显示查看更多
const needShowMore = computed(() => {
  return (props.goods || []).length > 2;
});
</script>

<style scoped lang="scss">
.goods_info {
  .row {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    &:not(:first-child) {
      margin-top: 10px;
    }

    .cover {
      width: 40px;
      height: 40px;
      object-fit: cover;
    }

    .info {
      flex: 1;
      display: flex;
      flex-direction: column;
      margin-top: 2px;
      text-align: center;

      .name {
        font-size: 12px;
      }

      .sku {
        color: #999;
        font-size: 12px;
      }
    }
  }
}

.show-more {
  color: #1989fa;
  font-size: 12px;
  margin-top: 6px;
  cursor: pointer;
  text-align: center;
}

.colorStyle {
  color: #ffc315;
}

.refund {
  color: #ff9731;
  font-weight: bold;
}
</style>
