From 796977e24baa7c1d3a333e2c1c8e06ca73fd9a56 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期三, 19 十一月 2025 18:08:35 +0800
Subject: [PATCH] 优惠劵
---
pages/commodity-square/commoditySquare.vue | 152 +++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 124 insertions(+), 28 deletions(-)
diff --git a/pages/commodity-square/commoditySquare.vue b/pages/commodity-square/commoditySquare.vue
index 791daf2..a8dec07 100644
--- a/pages/commodity-square/commoditySquare.vue
+++ b/pages/commodity-square/commoditySquare.vue
@@ -9,7 +9,8 @@
<view class="banner" style="margin-top: 14rpx;" v-if="bannerList.length>0">
<swiper :indicator-dots="false" :autoplay="true" :interval="3000" :duration="1000" :circular="true"
style="width: 100%;height: 160rpx;">
- <swiper-item v-for="item in bannerList" :key="item.id" @click="navigateGoodsInfo(item.skuId,item.goodsId)">
+ <swiper-item v-for="item in bannerList" :key="item.id"
+ @click="navigateGoodsInfo(item.skuId,item.goodsId)">
<view style="width: 100%; display: flex; align-items: center;justify-content: center;">
<image :src="item.showBannerUrl" mode="aspectFill"
style="width: 690rpx;height: 150rpx;border-radius: 24rpx;overflow: hidden;"></image>
@@ -47,13 +48,13 @@
<view class="goodsName">
<text>{{item.goodsName}}</text>
</view>
- <view class="goodsContent">
+ <view class="goodsContent" style="font-size: 24rpx;">
{{item.sellingPoint}}
</view>
- <view
- style="display: flex; justify-content: space-between;align-items:center; 100%;width: 100%;">
- <view class="goodsPrice">锟{item.price}}</view>
- <view class="addCard" style="display: flex; align-items: center;">
+ <view
+ style="display: flex; justify-content: space-between;align-items:center;height: 100%;width: 100%;">
+ <view class="goodsPrice" style="padding: 20rpx 0;">锟{item.price}}</view>
+ <view class="addCard" style="display: flex; align-items: center;" v-if="item.goodsType !=='VIRTUAL_GOODS'&& item.customizeFlag!=='CUSTOMIZE'">
<view style="padding: 20rpx 0 20rpx 20rpx;" v-show="item.cardNum && item.cardNum>0"
@click.stop="miousCardNum($event,item.id)">
<uni-icons type="minus" size="30" color="#96a6bc"></uni-icons>
@@ -76,18 +77,30 @@
<view class="settlement">鍘昏喘鐗╄溅缁撶畻</view>
</view> -->
</view>
- <view class="squareFotter" style="width: 750rpx; display: flex;align-items: center;
+ <view @click="gotoCardList()" class="squareFotter" style="width: 750rpx; display: flex;align-items: center;
justify-content: space-between;padding: 0 32rpx;box-sizing: border-box;">
- <view class="icon">
- <text class="iconfont"></text>
+ <view style="display: flex;align-items: center;justify-content: center;">
+ <view class="icon" style="position: relative;">
+ <text class="iconfont"></text>
+ <view style=" height: 36rpx;width:36rpx;display: flex;
+ align-items: center;
+ justify-content: center;
+ background-color: #f9583b;border-radius: 100%; position: absolute;
+ top: -25rpx; right: -20rpx;color: #fff;font-size: 24rpx;">
+ {{priceInfo.num > 99?'路路路':priceInfo.num}}
+ </view>
+ </view>
+ <view style="margin-left: 10rpx;color: #e06c75;font-size: 48rpx;font-weight: bold;">
+ 锟{priceInfo.price}}</view>
</view>
- <view class="settlement" @click="gotoCardList()">鍘荤粨绠�</view>
+ <view class="settlement">鍘荤粨绠�</view>
</view>
</view>
</template>
<script>
import TopBar from "@/components/TopBar.vue";
+ import { getSessionId, userAction } from "@/api/userAction.js";
import {
getCategoryList,
getGoodsList,
@@ -110,7 +123,11 @@
},
data() {
return {
- bannerList:[],
+ priceInfo: {
+ price: 0,
+ num: 0
+ },
+ bannerList: [],
canGoToCarList: false,
nums: 10,
searchInfo: '',
@@ -139,11 +156,21 @@
order: 'asc',
sort: 'goodsSort'
},
+ pageSessionNo:"",
+ sendOnShow:false,
+ actionParam:{
+ sessionId:'',
+ actionType:"PAGE",
+ joinType:"SELF",
+ pageCode:"SHOPPING_SQUARE",
+ pageParams:"{}",
+ pageStatus:"JOIN",
+ pageType:"LIST"
+ }
}
},
methods: {
- navigateGoodsInfo(skuId,goodsId){
- console.log(skuId,goodsId)
+ navigateGoodsInfo(skuId, goodsId) {
uni.navigateTo({
url: `/pages/product/goods?id=${skuId}&goodsId=${goodsId}`
});
@@ -153,8 +180,26 @@
url: '/pages/cusbar/cart/cartList'
})
},
- addCardNum(e, id) {
- this.goodsList.forEach(item => {
+ async addCardNum(e, id) {
+ // this.goodsList.forEach(item => {
+ // if (item.id === id) {
+ // if (item.cardNum) {
+ // item.cardNum++;
+ // } else {
+ // item.cardNum = 1;
+ // }
+ // this.flushDom = new Date().getMilliseconds();
+ // const data = {
+ // skuId: item.id,
+ // num: item.cardNum
+ // }
+ // await addCard(data)
+ // await this.getCartList();
+ // return;
+ // }
+ // })
+ for (let i = 0; i < this.goodsList.length; i++) {
+ const item = this.goodsList[i];
if (item.id === id) {
if (item.cardNum) {
item.cardNum++;
@@ -162,27 +207,27 @@
item.cardNum = 1;
}
this.flushDom = new Date().getMilliseconds();
- console.log("閫変腑鐨勫晢鍝佷负------------------->", JSON.stringify(item))
const data = {
skuId: item.id,
num: item.cardNum
}
- addCard(data)
+ await addCard(data)
+ await this.getCartList();
return;
}
- })
-
+ }
},
- miousCardNum(e, id) {
+ async miousCardNum(e, id) {
for (let i = 0; i < this.goodsList.length; i++) {
const item = this.goodsList[i];
if (item.id === id) {
if (item.cardNum && item.cardNum > 1) {
item.cardNum--;
} else {
- deleteSkuItem([id]);
+ await deleteSkuItem([id]);
item.cardNum = 0;
this.flushDom = new Date().getMilliseconds();
+ await this.getCartList();
break; // 閫�鍑烘暣涓惊鐜�
}
this.flushDom = new Date().getMilliseconds();
@@ -190,7 +235,8 @@
skuId: item.id,
num: item.cardNum
};
- addCard(data);
+ await addCard(data);
+ await this.getCartList();
break; // 閫�鍑烘暣涓惊鐜�
}
}
@@ -275,19 +321,19 @@
this.listHeight1 -= videoHeight;
}
}
- console.log(this[arrName][index].width, this[arrName][index].height)
+ // console.log(this[arrName][index].width, this[arrName][index].height)
this.flushDom = new Date();
},
goToGoodsInfo(id) {
const item = this.goodsList.find(item => id === item.id);
- console.log(item)
+ // console.log(item)
uni.navigateTo({
url: `/pages/product/goods?id=${item.id}&goodsId=${item.goodsId}`
});
},
//瑙﹀簳鑾峰彇鏁版嵁
async loadMoreData() {
- console.log("瑙﹀簳鍔犺浇------------銆�", this.maxPages)
+ // console.log("瑙﹀簳鍔犺浇------------銆�", this.maxPages)
if (this.getGoodsParam.pageNumber < this.maxPages) {
this.getGoodsParam.pageNumber++;
await this.getgoodsData()
@@ -308,10 +354,34 @@
async getBannerList() {
const bannerList = await getBannerList();
this.bannerList = bannerList.data.data
- console.log(this.bannerList)
+ // console.log(this.bannerList)
+ },
+ async getCartList() {
+ const cardInfos = await getCarts();
+ const cardList = cardInfos.data.result.cartList.flatMap(item => {
+ return item.skuList.map(sku => {
+ return (sku.goodsSku.id, {
+ skuId: sku.goodsSku.id,
+ num: sku.num,
+ price: sku.priceDetailDTO.flowPrice
+ })
+ })
+
+ })
+
+ this.priceInfo = cardList.reduce((newVal, current) => {
+ return {
+ num: newVal.num + current.num,
+ price: newVal.price + current.price
+ }
+ }, {
+ num: 0,
+ price: 0
+ })
},
async getgoodsData() {
const cardInfos = await getCarts();
+ // console.log('--------------------->', cardInfos)
// 澶勭悊璐墿杞︿俊鎭�
let cardMap = new Map();
this.canGoToCarList = cardInfos.data.result.cartList.length > 0
@@ -335,7 +405,7 @@
})
this.goodsList = [...this.goodsList, ...goodsList.data.result.records];
this.maxPages = goodsList.data.result.pages
- console.log('this.goodsList----------------------->', JSON.stringify(goodsList.data.result))
+ // console.log('this.goodsList----------------------->', JSON.stringify(goodsList.data.result))
},
async chooseCategory(id) {
@@ -355,8 +425,33 @@
console.log(this.maxPages)
}
},
+ onUnload() {
+ let param = Object.assign({}, this.actionParam);
+ if (this.sendOnShow)return
+ param.pageStatus = "LEAVE"
+ userAction(param)
+ },
+ onHide() {
+ this.startHidenTime = Date.now()
+ let param = Object.assign({}, this.actionParam);
+ this.sendOnShow = true;
+ param.pageStatus = "LEAVE"
+ userAction(param)
+ },
+ onShow() {
+ getSessionId().then(res=>{
+ this.pageSessionNo = res.data.data
+ this.actionParam.sessionId = this.pageSessionNo
+ if(this.pageSessionNo){
+ let param = Object.assign({}, this.actionParam);
+ userAction(param)
+ }
+ })
+ },
+ async onLoad(options) {
+ this.actionParam.pageParams = JSON.stringify(options)
- async onLoad() {
+ await this.getCartList();
// 鑾峰彇鐘舵�佹爮楂樺害
const systemInfo = uni.getSystemInfoSync();
@@ -459,6 +554,7 @@
overflow: hidden;
text-overflow: ellipsis;
vertical-align: middle;
+ color: #e7c463;
}
.goodsPrice {
--
Gitblit v1.8.0