浏览代码

用户体系优化

zhengjinyi 5 年之前
父节点
当前提交
fe7e0be678
共有 1 个文件被更改,包括 369 次插入0 次删除
  1. 369 0
      components/module/listTemplate/productList.vue

+ 369 - 0
components/module/listTemplate/productList.vue

@@ -0,0 +1,369 @@
+<template>
+	<view class="container commodity-list-wrapper" :style="{'overflow':(showSkeleton? 'hidden' : 'auto'),'height': (showSkeleton? windowHeight + 'px' : 'auto')}">
+		<list-skeleton v-if="showSkeleton" :listType='0'></list-skeleton>
+		<view class="product-container" v-if="!isShowEmpty">
+			<scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="scrolltolower" scroll-y v-if="productList.length > 0">
+				<view v-for="(item,index) in productList" :key="index" :id="item.id" class="all-type-list-content commodity-list" @click.stop="navToDetailPage(item.productID)">
+					<image mode='widthFix' :src="item.mainImage"  class="list-img" alt="list-img"></image>
+					<view class="list-details-info">
+						<text class="list-details-title">{{item.name}}</text>
+						<text class="list-details-specs">规格:{{item.unit}}</text>
+						<text class="list-details-miniQuantity">起订量:{{item.minBuyNumber}}</text>
+						<view class="list-details-price">
+							<view class="list-none" v-if="item.price1TextFlag == 1">
+								<view class="price-small">该商品尚未公开价格</view>
+								<view class="price-small">购买请致电:0755-22907771</view>
+							</view>
+							<view class="list-shop" v-else>
+								<view class="list-price" >
+									<text class="price-view activity" v-if="item.isShowActFlg">活动价</text>
+									<text class="price-view ladder" v-if="item.ladderPriceFlag == 1">阶梯价</text>
+									<text class="price-larger">¥{{item.retailPrice.toFixed(2)}}</text>
+								</view>
+								<button class="add-cart-btn" @click.stop="operationHanld(item)">选择数量</button>
+							</view>
+						</view>
+						<view class="list-details-price">
+							<text v-if="item.repurchasePriceState">
+								<text class="price-none">¥{{item.discountPrice}}</text>
+								<text class="iconfont"></text>
+							</text>
+						</view>
+					</view>
+				</view>
+				<button class="show-more-btn" v-if="showRegularBtn" @click="getListFromServer(true)">查看更多</button>
+				<view v-if="showLoading && productList.length > 4 && !showRegularBtn">
+					<view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
+					<view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
+				</view>
+			</scroll-view>
+		</view>
+		<view class="empty-container" v-else>
+			<image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
+			<text class="error-text">您还没有购买过任何商品哟~</text>
+			<button class="submit-btn toIndexPage" @click="toIndexPage">去逛逛</button>
+		</view>
+		<view class="cart-icon" v-if="!isShowEmpty" @click="toCartPage">
+			<text v-if="cartNum > 0" class="uni-badge uni-badge-error uni-small uni-badge--small icon-num">
+				{{cartNum >= 100 ? '99+' : cartNum}}
+			</text>
+			<image src='../../../static/icon-cart-active@3x.png' mode="widthFix"></image>
+		</view>
+		<!-- 透明模态层 -->
+		<modal-layer v-if='isModallayer'></modal-layer>
+	</view>
+</template>
+
+<script>
+	import listSkeleton from '@/components/module/listTemplate/listSkeleton'
+	import modalLayer from "@/components/modal-layer"
+	import uniStars from '@/components/uni-stars/uni-stars.vue'
+	import { queryAgaingoodslist } from "@/api/product.js"
+	import { mapState,mapMutations } from 'vuex';
+	export default{
+		name:'productList',
+		components:{
+			listSkeleton,
+			modalLayer,
+			uniStars
+		},
+		props: {
+			emptyText: {
+				type: String
+			},
+		},
+		data(){
+			return{
+				isModallayer:false,
+				windowHeight: '',
+				showSkeleton: true,
+				isShowEmpty: false,
+				userID: '',
+				scrollHeight: '',
+				productList: [],
+				showLoading: false,
+				loadingNow: true,
+				loadingText: '上拉加载更多',
+				pageSize: 10,
+				pageNum: 1,
+				hasNextPage: false,
+				pullFlag: true,
+				fromRegularPurchasePage: false,
+				cartNum: 0,
+				showRegularBtn: false,
+				isPrecedence:false
+			}
+		},
+		created() {
+			this.setScrollHeight();		
+			this.$api.getStorage().then((resolve) =>{
+				this.userID = resolve.userID
+				this.getProductAgainInfo()
+			})
+		},
+		computed: {
+			...mapState(['hasLogin','userInfo'])
+		},
+		methods:{
+			scrolltolower() {
+				if(this.hasNextPage && this.pullFlag) {
+					this.getProductAgainInfo(true);
+				}
+			},
+			setScrollHeight() {
+				const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
+				this.windowHeight = windowHeight - 1;
+				this.scrollHeight = windowHeight - 1;
+			},
+			getProductAgainInfo(loadMore) {
+				this.showLoading = true;
+				this.loadingNow = true;
+				this.loadingText = '加载中';
+				this.isShowEmpty = false;				
+				if(loadMore) {this.pageNum += 1;}
+				let params = {userId:10081,pageNum:this.pageNum,pageSize:this.pageSize}
+				queryAgaingoodslist(params).then(response =>{
+					this.isShowWrapper = true
+					const responseData = response.data;
+					if(responseData.results && responseData.results.length > 0){
+						this.hasNextPage = responseData.hasNextPage;
+						this.isShowEmpty = false;
+						if(loadMore) {
+							this.productList = [...this.productList,...responseData.results];
+						} else {
+							this.productList = [...responseData.results];
+							this.showSkeleton = false;
+						}
+						let isActFlg,newArry=[];
+						this.productList.map((item, index)=> {
+							if(item.actFlag == 1){
+								isActFlg = true
+							}else if(item.actFlag == 1 && item.ladderPriceFlag == 1){
+								isActFlg = true
+							}else{
+								isActFlg = false
+							}
+							newArry.push(Object.assign({},item,{isShowActFlg:isActFlg}))
+						})
+						this.productList = newArry
+						console.log(this.productList)
+						// 防上拉暴滑
+						this.pullFlag = false;
+						setTimeout(()=>{
+							this.pullFlag = true;
+						},500)
+						// 底部提示文案
+						if(this.hasNextPage) {
+							this.loadingText = '上拉加载更多';
+						} else {
+							this.showLoading = true;
+							this.loadingNow = false;
+						}
+					} else {
+						if(!loadMore) {
+							this.isShowEmpty = true;
+						}
+					}
+				}).catch(response =>{
+					this.$util.msg(response.msg,3000);
+				})
+			},
+			operationHanld(prop){
+				this.$emit('operationConfim',prop)
+			},
+			navToDetailPage(id) {
+				this.isModallayer = true;
+				this.$api.navigateTo(`/pages/goods/product?id=${id}`);
+				this.isModallayer = false;
+			},
+			toCartPage() {
+				uni.switchTab({
+					url: '/pages/tabBar/cart/cart'
+				})
+			},
+			toIndexPage() {
+				uni.switchTab({
+					url: '/pages/tabBar/home/home' 
+				})
+			}
+		}
+	}
+</script>
+
+<style lang="scss">
+	.commodity-list-wrapper {
+		scroll-view {
+			height: 100%;
+			border-top: 2rpx solid rgba(0,0,0,0.07);
+		}
+		.empty-container-image {
+			margin-top: -300rpx;
+		}
+		.toIndexPage {
+			bottom: 390rpx;
+		}
+		.show-more-btn {
+			width: 276rpx;
+			height: 52rpx;
+			line-height: 52rpx;
+			border: 2rpx solid #D8D8D8;
+			background: #F7F7F7;
+			font-size: 26rpx;
+			margin: 26rpx 0;
+			position: absolute;
+			left: 50%;
+			margin-left: -138rpx;
+		}
+	}
+	.all-type-list-content {
+		height: 216rpx;
+		padding: 24rpx;
+		background: #fff;
+		margin-bottom: 2rpx;
+		display: flex;
+		flex-direction: row;
+		box-sizing: content-box;
+		.list-img {
+			width: 210rpx;
+			height: 218rpx !important;
+			margin-right: 26rpx;
+			border-radius: 10rpx;
+			border: 2rpx solid #f3f3f3;
+		}
+	}
+	.list-details-info {
+		width: 466rpx;
+		display: flex;
+		flex-direction: column;
+		font-size: 26rpx;
+		position: relative;
+		.list-details-title {
+			line-height: 38rpx;
+			text-overflow: ellipsis;
+			overflow: hidden;
+			display: -webkit-box;
+			-webkit-line-clamp: 2;
+			line-clamp: 2;
+			-webkit-box-orient: vertical;
+		}
+		.list-details-specs {
+			margin-top: 8rpx;
+			color: #999999;
+		}
+		.list-details-miniQuantity {
+			margin-top: 7rpx;
+		}
+	}
+	.list-details-price {
+		width: 100%;
+		display: flex;
+		flex-direction: row;
+		justify-content: space-between;
+		position: absolute;
+		bottom: 0;
+		right: 0;
+		.price-none{
+			text-decoration: line-through;
+			color: #999999;
+			display: inline-block;
+		}
+		.price-icon {
+			width: 22rpx;
+			height: 28rpx;
+			vertical-align: middle;
+			margin-right: 10rpx;
+		}
+		.price-icon + text {
+			font-size: 25rpx;
+			vertical-align: middle;
+		}
+		.list-login-now {
+			width: 375rpx;
+			color: #F8C499;
+			position: absolute;
+			bottom: 0;
+			.p-no{
+				float: left;
+				font-size: $font-size-24;
+				color: $color-system;
+				margin-right: 10rpx;
+			}
+		}
+		.login-now {
+			padding: 10rpx 10rpx 10rpx 0;
+		}
+		.list-none{
+			.price-small{
+				font-size:$font-size-24;
+				line-height: 36rpx;
+				color: #FF2A2A;
+			}
+		}
+		.list-shop{
+			width: 100%;
+			height: auto;
+			display: flex;
+			.list-price {
+				flex: 7;
+				color: #FF2A2A;
+				float: left;
+				line-height:64rpx ;
+				align-items: center;
+				justify-content: center;
+				.price-larger {
+					font-size: $font-size-32;
+					display: inline-block;
+				}
+				.price-view{
+					display: inline-block;
+					width: 78rpx;
+					border-radius: 18rpx;
+					font-size: $font-size-20;
+					text-align: center;
+					color: #FFFFFF;
+					height: 36rpx;
+					line-height: 36rpx;
+					&.ladder{
+						background: linear-gradient(135deg,rgba(255,0,0,1) 0%,rgba(242,143,49,1) 100%);
+					}
+					&.activity{
+						background: linear-gradient(135deg,rgba(128,0,255,1) 0%,rgba(242,49,153,1) 100%);
+					}
+				}
+			}
+			.add-cart-btn {
+				width: 156rpx;
+				height: 64rpx;
+				line-height: 64rpx;
+				border-radius: 32rpx;
+				color: #fff;
+				font-size: 26rpx;
+				margin-right: 0;
+				background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
+			}
+		}
+	}
+	.cart-icon {
+		width: 92rpx;
+		height: 92rpx;
+		border-radius: 50%;
+		background: rgba(255, 147, 0, 0.5);
+		position: fixed;
+		right: 24rpx;
+		bottom: 30%;
+		display: flex;
+		align-items: center;
+		justify-content: center;
+		cursor: pointer;
+		image {
+			width: 58rpx;
+			height: 58rpx;
+		}
+		text {
+			font-size: 28rpx;
+			position: absolute;
+			top: -10rpx;
+			right: 0;
+		}
+	}
+</style>