<template>
  <view class="group-work u-skeleton-fillet">
    <view
      class="head-item"
      @click="goDetail('/pages/groupBuying/list')"
      :style="{ backgroundImage: `url(${bgImage || ''})` }"
    >
      <view class="top-left">
        <view class="top-left-title">拼团购</view>
        <view class="top-left-tip">精选好物推荐</view>
      </view>
      <view class="top-right" style="color: #75c27a">
        <text>查看更多</text>
        <!-- <text class="iconfont u-font24">&#xe6c7;</text> -->
        <uv-icon name="arrow-right" size="24rpx" color="#75c27a"></uv-icon>
      </view>
    </view>
    <view
      class="group-work-main"
      v-if="(groupList && groupList.length > 0) || skeletonShow"
    >
      <view
        class="middle_item"
        v-for="item in skeletonShow ? 1 : groupList"
        :key="item.id"
      >
        <view
          class="middle"
          @click="goProductDetails('/pages/groupBuying/details?id=' + item.id)"
        >
          <view class="middle-left">
            <!-- ?x-oss-process=style/w_350 -->
            <image
              v-if="item && item.coverImage"
              :src="`${item.coverImage}`"
              mode="aspectFill"
            >
            </image>
          </view>
          <view class="middle-right">
            <view class="middle-title u-text2">{{ item.title }}</view>
            <view class="division">
              <view class="middle-num">
                <view class="contain">
                  <view class="large">
                    <rich-text
                      :nodes="$mUtil.priceBigSmall(item.minPrice)"
                    ></rich-text>
                  </view>
                  <view class="small">¥ {{ item.minSalePrice }}</view>
                </view>
                <view class="three"
                  >{{ item.groupPeopleNum }}人团，已拼
                  <text style="color: red"> {{ item.resultSaleNum }}</text>
                  件</view
                >
              </view>
              <view class="button">去拼团</view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <noData v-else :config="{ top: 1, content: '暂无商品~' }"></noData>
  </view>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { activitygoodswillYouSpellPage_Api, activitygoodswillYouSpell_Api } from "@/api/groupbuy";

const props = defineProps({
  skeletonShow: {
    type: Boolean,
    default: false,
  },
  bgImage: {
    type: String,
    default: "",
  },
});

const emit = defineEmits(["goDetail", "goProductDetails"]);
const groupList = ref([]);
const goDetail = (url) => {
  emit("goDetail", url);
};

const goProductDetails = (url) => {
  emit("goProductDetails", url);
};

/**团购 */
const getgroupList = () => {
  activitygoodswillYouSpell_Api({
    limit: 10,
    page: 1,
  }).then((res) => {
    if (res && res.code == 200) {
      groupList.value = res.data || [];
    }
  });
};

onMounted(() => {
  getgroupList();
});

defineExpose({
  init: getgroupList,
});
</script>

<style scoped lang="scss">
.group-work {
  margin: 30rpx 0;
  background: #d4f2e8;
  padding-bottom: 30rpx;
  border-radius: 10rpx;
  box-sizing: border-box;
  overflow: hidden;

  .group-work-main {
    padding: 30rpx;
    margin: 20rpx 30rpx 0 30rpx;
    box-sizing: border-box;
    background-color: #ffffff;
    border-radius: 10rpx;
  }
}

.head-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 27rpx 30rpx;
  box-sizing: border-box;
  overflow: hidden;
  background-size: 100% 100%;
  background-repeat: no-repeat;

  .top-left {
    .top-left-title {
      font-size: 36rpx;
      font-family: PingFang SC, PingFang SC-Bold;
      font-weight: 700;
    }
    .top-left-tip {
      font-size: 24rpx;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: 400;
      margin-top: 5rpx;
    }
  }

  .top-right {
    width: 165rpx;
    height: 67rpx;
    line-height: 67rpx;
    background: #ffffff;
    border-radius: 34rpx;
    box-sizing: border-box;
    font-size: 24rpx;
    font-family: PingFang SC, PingFang SC-Regular;
    font-weight: 400;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.middle_item {
  padding: 0 30rpx;
}

.middle_item:last-child {
  border: none;
}

.middle {
  display: flex;
  border-bottom: 1rpx solid #f7f7f7;
  padding-bottom: 40rpx;
  padding-top: 42rpx;

  .middle-left {
    margin-right: 20rpx;

    image {
      width: 226rpx;
      height: 226rpx;
      border-radius: 10rpx;
    }
  }

  .middle-right {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-top: 10rpx;
    padding-bottom: 10rpx;

    .middle-title {
      font-size: 28rpx;
      margin-top: 10rpx;
      color: #181818;
      font-weight: 400;
      line-height: 36rpx;
    }

    .division {
      display: flex;
      width: 100%;
      padding-bottom: 10rpx;
      justify-content: space-between;
    }

    .middle-num {
      flex: 1;

      .contain {
        display: flex;
        align-items: flex-end;
      }

      .three {
        font-size: 24rpx;
        font-weight: Regular;
        color: #333333;
        line-height: 24rpx;
        margin-top: 8rpx;
      }

      .large {
        color: #ff0000;
        font-size: 36rpx;
        font-weight: Bold;
        line-height: 24rpx;
      }

      .small {
        margin-left: 16rpx;
        font-size: 22rpx;
        font-weight: 500;
        color: #cccccc;
        line-height: 24rpx;
        text-decoration: line-through;
      }
    }

    .button {
      width: 130rpx;
      height: 60rpx;
      text-align: center;
      line-height: 60rpx;
      color: #ffffff;
      font-size: 28rpx;
      background: #fa6138;
      border-radius: 32rpx;
    }
  }
}
</style>
