推荐商品分页

h5
wangdong 8 months ago
parent 11dd757c18
commit 6c86022f90
  1. 8
      api/goods/index.js
  2. 52
      pages/cart/index.vue
  3. 35
      pages/index/index.vue
  4. 60
      pages/user/index.vue

@ -8,7 +8,8 @@ const api = {
basic: 'goods/basic', basic: 'goods/basic',
specData: 'goods/specData', specData: 'goods/specData',
skuInfo: 'goods/skuInfo', skuInfo: 'goods/skuInfo',
recommended: 'goods/recommended', recommended: 'goods/recommended',
recommendedNew: 'goods/recommendedNew',
poster: 'goods/poster', poster: 'goods/poster',
serveList:'goods.service/list', serveList:'goods.service/list',
presale:'goods/presale' presale:'goods/presale'
@ -79,6 +80,11 @@ export const specData = (goodsId) => {
// 获取推荐的商品列表 // 获取推荐的商品列表
export const recommended = () => { export const recommended = () => {
return request.get(api.recommended) return request.get(api.recommended)
}
// 获取推荐的商品列表(新)
export const recommendedNew = (params) => {
return request.get(api.recommendedNew, { ...params })
} }
// 获取商品的指定SKU信息 // 获取商品的指定SKU信息

@ -174,6 +174,7 @@
</view> </view>
</template> --> </template> -->
<!-- </u-waterfall> --> <!-- </u-waterfall> -->
<view v-if="goodsRecommend.length" class="finished">{{ recommendLoadTitle }}</view>
<u-empty text="暂无数据显示哦~" v-if="goodsRecommend.length==0" mode="list" style="width: 100%"></u-empty> <u-empty text="暂无数据显示哦~" v-if="goodsRecommend.length==0" mode="list" style="width: 100%"></u-empty>
</view> </view>
@ -244,7 +245,10 @@
// ID // ID
checkedIds: [], checkedIds: [],
// //
totalPrice: '0.00' totalPrice: '0.00',
recommendPage: 1,
recommendFinish: false,
recommendLoadTitle: ''
} }
}, },
computed: { computed: {
@ -273,9 +277,6 @@
setCartTabBadge() setCartTabBadge()
} }
}, },
onReady() {
this.getSuggest();
},
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
@ -284,24 +285,40 @@
this.checkedIds = uni.getStorageSync(CartIdsIndex) this.checkedIds = uni.getStorageSync(CartIdsIndex)
// //
checkLogin() ? this.getCartList() : this.isLoading = false checkLogin() ? this.getCartList() : this.isLoading = false
this.recommendPage = 1;
this.recommendFinish = false;
this.recommendLoadTitle = '';
this.goodsRecommend = [];
this.getSuggest()
},
onReachBottom() {
if (!this.recommendFinish) {
this.getSuggest()
}
}, },
methods: { methods: {
getSuggest() { getSuggest() {
// //
Api.recommended().then(res => { Api.recommendedNew({ page: this.recommendPage++ }).then(res => {
let arr = res.data.goodsList console.log(res);
let arr = res.data.goodsList.data
if (arr && arr.length > 0) { if (arr && arr.length > 0) {
arr.map(a => { for (let i = 0; i < arr.length; i++) {
a.goods_price_min = Number(a.goods_price_min) arr[i].goods_price_min = Number(arr[i].goods_price_min);
a.goods_price_max = Number(a.goods_price_max) arr[i].goods_price_max = Number(arr[i].goods_price_max)
a.line_price_min = Number(a.line_price_min) arr[i].line_price_min = Number(arr[i].line_price_min);
a.line_price_max = Number(a.line_price_max) arr[i].line_price_max = Number(arr[i].line_price_max)
}) }
}
if (arr.length < res.data.goodsList.per_page) {
this.recommendFinish = true;
} }
this.goodsRecommend = arr this.recommendLoadTitle = this.recommendFinish ? "已全部加载完" : "上拉加载更多";
this.goodsRecommend = [...this.goodsRecommend, ...arr]
}) })
}, },
// () // ()
onCalcTotalPrice() { onCalcTotalPrice() {
@ -610,6 +627,13 @@
} }
} }
} }
.finished {
font-size: 28rpx;
line-height: 100rpx;
text-align: center;
color: #bbb;
width: 100%;
}
} }
// //

@ -253,7 +253,7 @@
</view> </view>
<view class="goodsInfo"> <view class="goodsInfo">
<view class="title"> <view class="title">
<text v-if="item.selling_point" class="ziying">{{item.selling_point}}</text> <!-- <text v-if="item.selling_point" class="ziying">{{item.selling_point}}</text> -->
<text class="name">{{item.goods_name}}</text> <text class="name">{{item.goods_name}}</text>
</view> </view>
</view> </view>
@ -345,6 +345,7 @@
</view> </view>
</template> --> </template> -->
<!-- </u-waterfall> --> <!-- </u-waterfall> -->
<view v-if="goodsRecommend.length" class="finished">{{ recommendLoadTitle }}</view>
<u-empty text="暂无数据显示哦~" v-if="goodsRecommend.length==0" mode="list" style="width: 100%"></u-empty> <u-empty text="暂无数据显示哦~" v-if="goodsRecommend.length==0" mode="list" style="width: 100%"></u-empty>
</view> </view>
</view> </view>
@ -628,6 +629,9 @@
storagePageIndex: '', storagePageIndex: '',
tabActiveColor: '', tabActiveColor: '',
navBgColor: '', navBgColor: '',
recommendPage: 1,
recommendFinish: false,
recommendLoadTitle: ''
} }
}, },
computed: { computed: {
@ -646,6 +650,11 @@
}, },
}, },
}, },
onReachBottom() {
if (!this.recommendFinish) {
this.getSuggest()
}
},
methods: { methods: {
/** /**
* 获取小程序配置 * 获取小程序配置
@ -926,8 +935,9 @@
}, },
getSuggest() { getSuggest() {
// //
Api.recommended().then(res => { Api.recommendedNew({ page: this.recommendPage++ }).then(res => {
let arr = res.data.goodsList console.log(res);
let arr = res.data.goodsList.data
if (arr && arr.length > 0) { if (arr && arr.length > 0) {
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
arr[i].goods_price_min = Number(arr[i].goods_price_min); arr[i].goods_price_min = Number(arr[i].goods_price_min);
@ -936,7 +946,11 @@
arr[i].line_price_max = Number(arr[i].line_price_max) arr[i].line_price_max = Number(arr[i].line_price_max)
} }
} }
this.goodsRecommend = arr if (arr.length < res.data.goodsList.per_page) {
this.recommendFinish = true;
}
this.recommendLoadTitle = this.recommendFinish ? "已全部加载完" : "上拉加载更多";
this.goodsRecommend = [...this.goodsRecommend, ...arr]
}) })
}, },
@ -1168,7 +1182,6 @@
onLoad() { onLoad() {
this.getTypeList() this.getTypeList()
this.getSeckill() this.getSeckill()
this.getSuggest() //
this.getCityInfo() this.getCityInfo()
this.getCoupons(); this.getCoupons();
this.getServeList(); this.getServeList();
@ -1182,6 +1195,11 @@
} }
this.getWxAppStyle(); this.getWxAppStyle();
this.isLogin = uni.getStorageSync("AccessToken") ? true : false this.isLogin = uni.getStorageSync("AccessToken") ? true : false
this.recommendPage = 1;
this.recommendFinish = false;
this.recommendLoadTitle = '';
this.goodsRecommend = [];
this.getSuggest()
}, },
onPageScroll(e) { onPageScroll(e) {
if (e.scrollTop <= 200) { // true if (e.scrollTop <= 200) { // true
@ -2066,6 +2084,13 @@
} }
} }
} }
.finished {
font-size: 28rpx;
line-height: 100rpx;
text-align: center;
color: #bbb;
width: 100%;
}
} }
} }

@ -523,9 +523,9 @@
:src="$picUrl+'/static/user/right.png'"></image> :src="$picUrl+'/static/user/right.png'"></image>
</view> </view>
<view class="goodsRecommend" v-if="isLogin == false || userInfo.user_type != 40"> <view class="goodsRecommend" v-if="isLogin == false || userInfo.user_type != 40">
<!-- <u-waterfall v-model="suggestGoodsList" ref="uWaterfall1"> --> <!-- <u-waterfall v-model="goodsRecommend" ref="uWaterfall1"> -->
<!-- <template v-slot:left="{leftList}"> --> <!-- <template v-slot:left="{leftList}"> -->
<view class="goodsItem" v-for="(item,index) in suggestGoodsList" @click="goodsDetail(item)" <view class="goodsItem" v-for="(item,index) in goodsRecommend" @click="goodsDetail(item)"
:key="index"> :key="index">
<view class="pic"> <view class="pic">
<image :src="item.goods_image" mode="aspectFill"></image> <image :src="item.goods_image" mode="aspectFill"></image>
@ -616,6 +616,7 @@
</view> </view>
</template> --> </template> -->
<!-- </u-waterfall> --> <!-- </u-waterfall> -->
<view v-if="goodsRecommend.length" class="finished">{{ recommendLoadTitle }}</view>
</view> </view>
</view> </view>
@ -688,7 +689,10 @@
memberCode: false, memberCode: false,
isLogin: false, isLogin: false,
userInfo: {}, userInfo: {},
suggestGoodsList: [], goodsRecommend: [],
recommendPage: 1,
recommendFinish: false,
recommendLoadTitle: ''
} }
}, },
onShow(options) { onShow(options) {
@ -706,7 +710,16 @@
recovery_order: {} recovery_order: {}
} }
} }
this.getSuggest(); this.recommendPage = 1;
this.recommendFinish = false;
this.recommendLoadTitle = '';
this.goodsRecommend = [];
this.getSuggest()
},
onReachBottom() {
if (!this.recommendFinish) {
this.getSuggest()
}
}, },
onPageScroll(e) { onPageScroll(e) {
if (e.scrollTop <= 200) { // true if (e.scrollTop <= 200) { // true
@ -854,20 +867,24 @@
}, },
getSuggest() { getSuggest() {
// //
const that = this Api.recommendedNew({ page: this.recommendPage++ }).then(res => {
Api.recommended() console.log(res);
.then(res => { let arr = res.data.goodsList.data
let arr = res.data.goodsList if (arr && arr.length > 0) {
if (arr && arr.length > 0) { for (let i = 0; i < arr.length; i++) {
arr.map(a => { arr[i].goods_price_min = Number(arr[i].goods_price_min);
a.goods_price_min = Number(a.goods_price_min) arr[i].goods_price_max = Number(arr[i].goods_price_max)
a.goods_price_max = Number(a.goods_price_max) arr[i].line_price_min = Number(arr[i].line_price_min);
a.line_price_min = Number(a.line_price_min) arr[i].line_price_max = Number(arr[i].line_price_max)
a.line_price_max = Number(a.line_price_max)
})
} }
that.suggestGoodsList = arr }
}) if (arr.length < res.data.goodsList.per_page) {
this.recommendFinish = true;
}
this.recommendLoadTitle = this.recommendFinish ? "已全部加载完" : "上拉加载更多";
this.goodsRecommend = [...this.goodsRecommend, ...arr]
})
}, },
// //
onRefreshPage() { onRefreshPage() {
@ -1388,6 +1405,15 @@
} }
} }
} }
.finished {
font-size: 28rpx;
line-height: 100rpx;
text-align: center;
color: #bbb;
width: 100%;
}
} }
.section_1 { .section_1 {

Loading…
Cancel
Save