<template>
  <view class="group-list">
    <uv-navbar title="拼团" autoBack bgColor="#fa6138" placeholder leftIconColor="#ffffff" titleStyle="color: #ffffff"></uv-navbar>
    <view class="today">
      <view class="today-item">
        <view class="today-left"> 今日必拼 </view>
      </view>
    </view>
    <swiper
      class="commodity"
      v-if="groupList && groupList.length > 0"
      :indicator-dots="false"
      :autoplay="false"
      @change="imgActiveFun"
    >
      <!-- <view class="commodity-item"> -->
      <swiper-item
        v-for="(item, index) in groupList"
        :key="index"
        @click="
          goProductDetails('/pages/groupBuying/details?id=' + item.id)
        "
      >
        <view class="commodity-item">
          <!-- ?x-oss-process=style/w_350 -->
          <image
            :src="`${item.coverImage}`"
            mode=""
          ></image>
          <view class="number">
            <text>{{ item.groupPeopleNum }}人团 </text>
            <view class="u-FF0000" style="font-weight: Bold">
              <rich-text
                :nodes="$mUtil.priceBigSmall(item.minPrice)"
              ></rich-text>
            </view>
          </view>
          <view class="completed" v-if="item.resultSaleNum / 10000 > 1">
            已有<text>{{ (item.resultSaleNum / 10000).toFixed(1) }}万</text>
            人拼
          </view>
          <view class="completed" v-else>
            已有<text>{{ item.resultSaleNum }}</text> 人拼
          </view>
        </view>
      </swiper-item>
      <!-- </view> -->
    </swiper>
    <!-- </view> -->
    <nodata v-else :config="{ top: 1, content: '暂无商品~' }"></nodata>
    <view class="option" v-if="groupList && groupList.length > 0">
      <view
        class="option-item"
        :class="{ active: activeBannerIndex == index }"
        v-for="(item, index) in groupList"
        :key="index"
      >
      </view>
    </view>
    <view class="content">
      <view class="content-top">
        <view class="content-left"> 精选商品 </view>
        <view class="line"> </view>
        <view class="content-right"> 热销优品快来拼购 </view>
      </view>
      <view class="middle" v-if="RowsList && RowsList.length > 0">
        <view
          class="middle-item"
          v-for="(item, index) in RowsList"
          :key="index"
          @click="
            goProductDetails('/pages/groupBuying/details?id=' + item.id)
          "
        >
          <view class="image">
            <image
              :src="`${item.coverImage}`"
              mode=""
            ></image>
          </view>
          <view class="middle-right">
            <view class="title u-text2">
              {{ item.title }}
            </view>
            <view class="large-box">
              <view class="box">
                <view class="number">
                  <view class="large">
                    <rich-text
                      :nodes="$mUtil.priceBigSmall(item.minPrice)"
                    ></rich-text>
                  </view>
                  <view class="small">
                    <rich-text
                      :nodes="$mUtil.priceBigSmall(item.minSalePrice)"
                    ></rich-text>
                  </view>
                </view>
                <view class="three-people">
                  {{ item.groupPeopleNum }}人拼，已拼<text>{{
                    item.resultSaleNum
                  }}</text
                  >件
                </view>
              </view>
              <view class="go-group-work"> 去拼团 </view>
            </view>
          </view>
        </view>
        <loadMore v-if="RowsList.length > 0" :status="LoadStatus"></loadMore>
      </view>
      <noData v-else :config="{ top: 1, content: '暂无商品~' }"></noData>
    </view>
  </view>
</template>


<script setup>
import { ref, reactive, onMounted } from "vue";
import {
  onLoad,
  onShow,
  onPullDownRefresh,
  onReachBottom,
} from "@dcloudio/uni-app";
import {
  activitygoodswillYouSpellPage_Api,
  activitygoodswillYouSpell_Api,
} from "@/api/groupbuy";

import { usePageData } from "@/hooks/usePageData.ts";

const { RowsList, LoadStatus, initData } = usePageData(
  activitygoodswillYouSpellPage_Api
);
const groupList = ref([]);
const activeBannerIndex = ref(0);

// 方法定义
const goProductDetails = (url) => {
  uni.navigateTo({
    url: url,
  });
};

const imgActiveFun = (e) => {
  activeBannerIndex.value = e.detail.current;
};

const getGroup = () => {
  // return;
  activitygoodswillYouSpell_Api({
    limit: 12,
    page: 1,
  }).then((res) => {
    if (res && res.code == 200) {
      groupList.value = res.data || [];
    }
  });
};

// 页面生命周期函数
onLoad((options) => {
  initData();
});

onShow(() => {
  getGroup();
});

// 下拉刷新
onPullDownRefresh(() => {
  getGroup();
  initData();
});
</script>

<style lang="scss" scoped>
.middle {
  margin: 0 20rpx 0 0;

  .middle-item {
    display: flex;
    padding: 20rpx 0rpx 25rpx 16rpx;

    .image {
      image {
        width: 187rpx;
        height: 187rpx;
        border-radius: 18rpx;
      }
    }

    .middle-right {
      margin-left: 30rpx;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      width: 100%;

      .title {
        font-size: 28rpx;
        font-weight: 400;
        color: #181818;
      }

      .large-box {
        display: flex;
        align-items: flex-end;
        justify-content: space-between;

        .box {
          .number {
            display: flex;
            align-items: flex-end;
            margin-top: 25rpx;

            .large {
              font-size: 36rpx;
              color: #ff0000;
              font-weight: bold;

              text {
                font-size: 36rpx;
                color: 700;
              }
            }

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

          .three-people {
            font-size: 24rpx;
            color: #333333;
            font-weight: 400;

            text {
              color: #fe9000;
            }
          }
        }

        .go-group-work {
          color: #ffffff;
          font-size: 28rpx;
          font-weight: 500;
          padding: 12rpx 27rpx;
          background-color: #fa6138;
          border-radius: 32rpx;
        }
      }
    }
  }
}

.content {
  padding: 0 30rpx;
  background-color: #ffffff;
  overflow: hidden;

  .content-top {
    display: flex;
    align-items: center;
    margin-top: 36rpx;
    margin-bottom: 22rpx;

    .content-left {
      font-size: 36rpx;
      color: #1a1a1a;
      font-weight: 700;
    }

    .line {
      width: 1rpx;
      height: 33rpx;
      margin: 0 15rpx;
      background-color: #707070;
    }

    .content-right {
      font-size: 24rpx;
      color: #666666;
      font-weight: 400;
    }
  }
}

.option {
  margin: 30rpx 0;
  display: flex;
  justify-content: center;

  .option-item {
    background-color: #d9d9d9;
    margin: 0 8rpx;
    width: 14rpx;
    height: 14rpx;
    border-radius: 7rpx;
  }

  .active {
    background-color: #fa6138;
    width: 35rpx;
    height: 14rpx;
    border-radius: 7rpx;
  }
}

.commodity {
  margin-top: -195rpx;

  margin-left: 30rpx;
  margin-right: 30rpx;
  height: 367rpx;

  ::v-deep .uni-swiper-slide-frame {
    width: 42% !important;
  }

  .commodity-item {
    // margin-right: 30rpx;
    border-radius: 16rpx;
    background-color: #ffffff;
    padding: 18rpx;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;

    image {
      width: 232rpx;
      height: 232rpx;
      border-radius: 16rpx;
    }

    .completed {
      font-size: 22rpx;
      margin-top: 2rpx;
      font-weight: 400;
      color: #333333;

      text {
        color: #ff0000;
      }
    }

    .number {
      margin-top: 20rpx;
      font-size: 22rpx;
      color: #333333;
      font-weight: 500;
      display: flex;
      align-items: center;

      .zero {
        margin-left: 20rpx;
        font-size: 22rpx;
        color: #ff0000;
        font-weight: 500;
      }

      .one {
        color: #ff0000;
        font-size: 34rpx;
        font-weight: 700;
      }

      .two {
        color: #ff0000;
        font-size: 18rpx;
        font-weight: 700;
      }
    }
  }
}

.today {
  background-color: #fa6138;
  overflow: hidden;
  height: 300rpx;

  .today-item {
    display: flex;
    align-items: center;
    margin: 30rpx;

    .today-left {
      font-size: 36rpx;
      color: #ffffff;
      font-weight: 700;
    }

    .line {
      width: 1rpx;
      height: 33rpx;
      background-color: #ffffff;
      margin: 0 15rpx;
    }

    .surplus {
      font-size: 24rpx;
      color: #ffffff;
      font-weight: 400;
      margin-right: 14rpx;
    }

    .time {
      font-size: 24rpx;
      font-weight: 500;
      color: #ffffff;

      text {
        color: #ff0000;
        padding: 0 4rpx;
        background-color: #dccda4;
        border-radius: 4rpx;
        margin: 0 4rpx;
      }
    }
  }
}

.group-list {
  background-color: #f6f6f6;
}
</style>