Przeglądaj źródła

团购代码修改

LiuShu_0203 3 tygodni temu
rodzic
commit
c563c798ad

+ 17 - 0
pages/groupbuying/groupbuying.js

@@ -126,6 +126,23 @@ Page({
     });
 
     const collectList = data.records || [];
+
+     // 循环去查 groupbuy 表
+    for (let item of collectList) {
+      try {
+        const res = await models.wx_groupbuy_groupbuy.list({
+          filter: { where: { groupbuy_id: item._id } },
+          envType: "prod",
+        });
+        // 把查到的记录存入 specList,保证是数组
+        item.specList = res.data.records || [];
+      } catch (err) {
+        console.error(`获取 groupbuy 失败,商品ID: ${item._id}`, err);
+        item.specList = [];
+      }
+    }
+    console.log(collectList, '+++++++++++++++++++++++++++++');
+
     this.setData({
       goods: isLoadMore ? this.data.goods.concat(collectList) : collectList, // ✅ 用 goods 拼接
       pageNumber: pageNumber + 1,

+ 2 - 2
pages/groupbuying/groupbuying.wxml

@@ -23,10 +23,10 @@
             <view class="goods-info">
               <view class="goods-title">{{item.name}}</view>
               <view class="goods-price">
-                <text>¥{{item.price}}</text>
+                <text>¥{{item.specList[0].price ? item.specList[0].price : '暂无'}}</text>
                 <text class="goods-status">已拼 {{item.count}}件</text>
               </view>
-              <view class="original-price">¥{{item.old_price}}</view>
+              <view class="original-price">¥{{item.specList[0].old_price ? item.specList[0].old_price : '暂无'}}</view>
               <view class="gw_boxs">
               <!-- <view class="gw_imgboxs">
                 <image style="width: 55rpx;height: 55rpx;padding-top: 6rpx;" src="../../image/imgs/gwc.png" />

+ 10 - 1
subpackages/productdetails/productdetails.js

@@ -14,6 +14,7 @@ Page({
     console.log('进了');
     const itemData = decodeURIComponent(options.data);
     const item = JSON.parse(itemData);
+    console.log(item, 'itemitemitemitemitemitemitem');
     this.setData({
       item: item,
       from
@@ -122,7 +123,15 @@ Page({
       imageUrl: item.detail_images?.[0] || ''
     };
   },
-  
+
+  // 点击切换规格
+  selectSpec(e) {
+    const specIndex = e.currentTarget.dataset.specindex;
+
+    this.setData({
+      gaoliao: specIndex
+    })
+  }
 
   // handleSpecSelect(e) {
   //   const spec = e.currentTarget.dataset.spec;

+ 14 - 6
subpackages/productdetails/productdetails.wxml

@@ -3,7 +3,7 @@
     <!-- 商品图片 -->
     <view class="empty-space">
       <swiper style="width: 100%; height: 100%;" autoplay="true" interval="3000" circular>
-        <block wx:for="{{item.detail_images}}" wx:key="index">
+        <block wx:for="{{item.specList[gaoliao].detail_images}}" wx:key="index">
           <swiper-item>
             <image style="width: 100%; height: 100%;" src="{{item}}" mode="aspectFill"
             bindtap="previewImage" data-index="{{index}}" />
@@ -16,8 +16,8 @@
     <!-- 商品价格和浏览量 -->
     <view class="price-and-views">
       <view>
-        <text class="price">¥{{item.price}}</text>
-        <text class="original-price">¥{{item.old_price}}</text>
+        <text class="price">¥{{item.specList[gaoliao].price ? item.specList[gaoliao].price : '暂无'}}</text>
+        <text class="original-price">¥{{item.specList[gaoliao].old_price ? item.specList[gaoliao].old_price : '暂无'}}</text>
       </view>
       <view style="display: flex; align-content: center;">
         <image style="width: 30rpx; height: 30rpx;" src="{{showimg}}" />
@@ -31,8 +31,15 @@
     <!-- 选择规格 -->
     <view class="specifications">
       <text style="font-size: 38rpx;">选择规格</text>
-      <view class="specifications_boxs">
-        <button wx:for="{{item.specs}}" wx:key="index" class="spec-btn {{gaoliao === index ? 'active' : ''}}">{{item}}</button>
+      <view wx:if="{{item.specList.length > 0}}" class="specifications_boxs">
+        <button wx:for="{{item.specList}}" wx:key="index" class="spec-btn {{gaoliao === index ? 'active' : ''}}"
+        bindtap="selectSpec"
+        data-specindex="{{index}}">
+          {{item.spec}}
+        </button>
+      </view>
+      <view wx:else class="specifications_boxs">
+        <text style="width: 100%; text-align: center; padding: 30rpx 0; color: #ccc;">暂无规格</text>
       </view>
     </view>
     
@@ -50,7 +57,8 @@
     <view class="product-details">
       <text style="font-size: 38rpx;">产品详情</text>
       <view class="details-list">
-        <text wx:for="{{item.details}}" wx:key="index">• {{item}}</text>
+        <!-- <text wx:for="{{item.details}}" wx:key="index">• {{item}}</text> -->
+        <text>{{item.specList[gaoliao].details}}</text>
       </view>
     </view>