绿满眶商城微信小程序-uniapp
peng
2025-06-27 b6b1a34a610795ed5ea8dd8658955ea4c9a0d401
pages/commodity-square/commoditySquare.vue
@@ -1,24 +1,26 @@
<template>
   <view class="container">
      <top-bar selectedTitleIndex="shop" textColor="black" @changeTab="topBarChange" class="topBar"></top-bar>
      <input type="text" v-show="false" v-model="flushDom" />
      <view class="search">
      <view class="search" :style="{marginTop: buttonHeight+'px',}">
         <u-search class="nav-search" @blur='searchGoods' placeholder="搜索商品" :show-action="false"></u-search>
      </view>
      <view class="commoditySquare">
      <scroll-view class="scrollContainer"  :scroll-y="true" @scrolltolower="loadMoreData" >
         <view class="commoditySquare">
         <view class="left" style="width: 310rpx;">
            <view class="commoditySquareItem" v-for="(item,index) in goodsList1"
               @click="goToGoodsInfo('goodsList1',item.id)">
               <video :src="item.goodsVideo" v-if="item.goodsVideo " v-show="item.show" :initial-time="0"
               <!-- <video :src="item.goodsVideo" v-if="item.goodsVideo " v-show="item.show" :initial-time="0"
                  :controls="false" object-fit="contain" :show-play-btn="false" :show-center-play-btn="false"
                  @loadedmetadata="getvideoInfo($event,'goodsList1',index)" :ref="'video'+item.id"
                  :style="{width:item.width,height:item.height}"></video>
               <image :src="item.thumbnail" v-if="item.goodsVideo ==null  || item.goodsVideo == ''"
                  :style="{width:item.width,height:item.height}"></video> -->
               <image :src="item.thumbnail"
                  mode="aspectFill" class="goodsImg">
               </image>
               <view class="goodsInfo">
                  <view class="">{{item.goodsName}}</view>
                  <view class="goodsName">{{item.goodsName}}</view>
                  <view class="priceInfo">
                     <view class="">¥{{item.price}}</view>
                     <view class="goodsPrice">¥{{item.price}}</view>
                     <view class="">已售: {{item.buyCount}}</view>
                  </view>
               </view>
@@ -27,44 +29,44 @@
         <view class="right" style="width: 310rpx;">
            <view class="commoditySquareItem" v-for="(item,index) in goodsList2"
               @click="goToGoodsInfo('goodsList2',item.id)">
               <video :src="item.goodsVideo" v-if="item.goodsVideo " v-show="item.show" :initial-time="0"
<!--                <video :src="item.goodsVideo" v-if="item.goodsVideo " v-show="item.show" :initial-time="0"
                  :controls="false" object-fit="contain" :show-play-btn="false" :show-center-play-btn="false"
                  @loadedmetadata="getvideoInfo($event,'goodsList2',index)" :ref="'video'+item.id"
                  :style="{width:item.width,height:item.height}"></video>
               <image :src="item.thumbnail" v-if="item.goodsVideo ==null || item.goodsVideo == ''"
                  :style="{width:item.width,height:item.height}"></video> -->
               <image :src="item.thumbnail"
                  mode="aspectFill" class="goodsImg">
               </image>
               <view class="goodsInfo">
                  <view class="">{{item.goodsName}}</view>
                  <view class="goodsName">{{item.goodsName}}</view>
                  <view class="priceInfo">
                     <view class="">¥{{item.price}}</view>
                     <view class="goodsPrice">¥{{item.price}}</view>
                     <view class="">已售: {{item.buyCount}}</view>
                  </view>
               </view>
            </view>
         </view>
         <view class="openShowLeft" @click="showDrawer('showLeft')" v-if="!showLeft">
            <uni-icons type="right" size="30"></uni-icons>
         </view>
         <uni-drawer ref="showLeft" mode="left" width="120" height="94vh" @change="change($event,'showLeft')"
            :cus-style="true" class="navigationLeft">
            <scroll-view class="typeNavigation" :scroll-y="true" show-scrollbar="false">
      </view>
      <view style="display: flex;align-items: center;justify-content: center;margin-top: 20rpx;" v-if="canLoadMore">
         没有更多数据了.................</view>
      </scroll-view>
         <uni-drawer ref="showLeft" mode="left" width="120" height="80vh" :drawerTop="buttonHeight" @change="change($event,'showLeft')"
            :cus-style="true" class="navigationLeft" :mask="false">
            <scroll-view class="typeNavigation" :scroll-y="true" :show-scrollbar="false" >
               <view class="typeNavigationItem" :class="{typeNavigationItemCheck:currentCategort ==item.id}"
                  @click="chooseCategory(item.id)" v-for="item in categoryList" :key="item.id">
                  {{item.name}}
               </view>
            </scroll-view>
         </uni-drawer>
      </view>
      <view style="display: flex;align-items: center;justify-content: center;margin-top: 20rpx;" v-if="canLoadMore">
         没有更多数据了.................</view>
      <custom-tabbar bgColor="#ffffff" selected="shop"></custom-tabbar>
   </view>
</template>
<script>
   import TopBar from "@/components/TopBar.vue";
   import {
      getCategoryList,
      getGoodsList
@@ -73,8 +75,10 @@
      getSTSToken
   } from '@/api/common.js'
   export default {
      components: {TopBar},
      data() {
         return {
            buttonHeight:0,
            //记录两列高度
            listHeight1: 0,
            listHeight2: 0,
@@ -96,6 +100,7 @@
               pageSize: 12,
               pageNumber: 1,
               categoryId: null,
               canFilter:true
            },
            //商品双列显示
            goodsList1: [],
@@ -103,6 +108,17 @@
         }
      },
      methods: {
         topBarChange(titleObj) {
            if (titleObj.index === 'home') {
               uni.switchTab({
                  url: titleObj.pagePath
               });
            } else {
               uni.redirectTo({
                  url: titleObj.pagePath
               });
            }
         },
         async searchGoods(keyWard) {
            this.getGoodsParam.keyword = keyWard
            this.getGoodsParam.pageNumber = 1
@@ -158,6 +174,16 @@
               url: `/pages/product/goods?id=${item.id}&goodsId=${item.goodsId}`
            });
         },
         //触底获取数据
         async loadMoreData() {
            if (this.getGoodsParam.pageNumber < this.maxPages) {
               this.getGoodsParam.pageNumber++;
               await this.getgoodsData()
            } else {
               this.canLoadMore = true;
            }
         },
         //获取分类导航栏
         async loadCategoryList() {
            let list = await getCategoryList(0);
@@ -165,19 +191,19 @@
         },
         async getgoodsData() {
            const goodsList = await getGoodsList(this.getGoodsParam);
            const sts = await getSTSToken();
            const stsUrl = sts.data.data.endpoint
            // 处理数据
            goodsList.data.result.records.forEach(item => {
               if (item.thumbnail !== '' && item.thumbnail !== null && item.thumbnail.indexOf('http') ===
                  -1) {
                  item.thumbnail = stsUrl + '/' + item.thumbnail
               }
               if (item.goodsVideo !== '' && item.goodsVideo !== null && item.goodsVideo.indexOf(
                     'http') === -1) {
                  item.goodsVideo = stsUrl + '/' + item.goodsVideo
               }
            })
            // const sts = await getSTSToken();
            // const stsUrl = sts.data.data.endpoint
            // // 处理数据
            // goodsList.data.result.records.forEach(item => {
            //    if (item.thumbnail !== '' && item.thumbnail !== null && item.thumbnail.indexOf('http') ===
            //       -1) {
            //       item.thumbnail = stsUrl + '/' + item.thumbnail
            //    }
            //    if (item.goodsVideo !== '' && item.goodsVideo !== null && item.goodsVideo.indexOf(
            //          'http') === -1) {
            //       item.goodsVideo = stsUrl + '/' + item.goodsVideo
            //    }
            // })
            //计算两个数组的长度 用于解决瀑布流两边高度不一致问题
            //平分给两个数组
            const goodsSize = goodsList.data.result.records.length;
@@ -226,20 +252,15 @@
         this.showDrawer('showLeft')
      },
      async onLoad() {
         // 获取状态栏高度
         const systemInfo = uni.getSystemInfoSync();
         this.buttonHeight = systemInfo.statusBarHeight +40;
         console.log('-------------------------------->',this.buttonHeight)
         await this.loadCategoryList();
         this.getGoodsParam.pageNumber = 1
         this.getGoodsParam.categoryId = ""
         this.getGoodsParam.keyword = ""
         await this.getgoodsData()
      },
      async onReachBottom() {
         if (this.getGoodsParam.pageNumber < this.maxPages) {
            this.getGoodsParam.pageNumber++;
            await this.getgoodsData()
         } else {
            this.canLoadMore = true;
         }
      }
   }
</script>
@@ -248,16 +269,27 @@
   .container {
      width: 750rpx;
      padding-bottom: 64rpx;
      height: 100vh;
      overflow: hidden;
   }
   .commoditySquare {
      width: 750rpx;
      position: relative;
      box-sizing: border-box;
      display: flex;
      justify-content: space-around;
      height: 100%;
   }
   .scrollContainer{
      overflow: hidden;
      height: 1224rpx;
      -webkit-overflow-scrolling: touch;
   }
   .scrollContainer::-webkit-scrollbar {
     display: none; /* Chrome/Safari等 */
     width: 0 !important; /* 兼容iOS */
     height: 0 !important;
   }
   .left {
      box-sizing: border-box;
   }
@@ -289,7 +321,7 @@
   .openShowLeft {
      position: fixed;
      top: 120rpx;
      top: 200rpx;
      left: 0;
      align-items: center;
      justify-content: flex-start;
@@ -309,29 +341,29 @@
   }
   .scroll-view {
      /* #ifndef APP-NVUE */
      width: 100%;
      height: 100%;
      /* #endif */
      flex: 1
   }
   // .scroll-view {
   //    /* #ifndef APP-NVUE */
   //    width: 100%;
   //    height: 100%;
   //    /* #endif */
   //    flex: 1
   // }
   .priceInfo {
      margin-top: 10rpx;
      display: flex;
      justify-content: space-around;
   }
   // .priceInfo {
   //    margin-top: 10rpx;
   //    display: flex;
   //    justify-content: space-around;
   // }
   // 处理抽屉内容滚动
   .scroll-view-box {
      flex: 1;
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
   }
   // .scroll-view-box {
   //    flex: 1;
   //    position: absolute;
   //    top: 0;
   //    right: 0;
   //    bottom: 0;
   //    left: 0;
   // }
   .typeNavigation {
@@ -346,13 +378,12 @@
      font-size: 28rpx;
      color: black;
      margin-top: 10rpx;
      border-radius: 12rpx;
      border: 1rpx solid gray;
   }
   .typeNavigationItemCheck {
      background-color: #42b993;
      color: #fff;
      color: #ef321e;
      font-size: 32rpx;
      font-weight: bold;
      border: 0;
   }
@@ -370,4 +401,37 @@
      // width: 500rpx;
      // z-index: 9999;
   }
</style>
   .goodsInfo{
      margin-top: 10rpx;
      box-sizing: border-box;
      width: 100%;
      display: flex;
      flex-direction: column;
   }
   .goodsName{
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
      height: 32rpx;
      overflow: hidden;
      text-overflow: ellipsis;
      text-align: center;
      vertical-align: middle;
   }
   .priceInfo{
      margin-top: 10rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;
   }
   .goodsPrice{
      color: red;
      font-weight: bold;
   }
   .topBar {
      position: fixed;
      top: 20rpx;
      left: 20rpx;
      z-index: 1000
   }
</style>