<template>
	<view class="container shop clearfix" :style="{paddingTop:CustomBar+'px'}">
		<!-- 主页内容 -->
		<view class="container-shop tui-skeleton">
			<!-- 轮播 -->
			<view class="shop-search">
				<text class="iconfont icon-sousuo"></text>
				<input class="input" type="text" value="" placeholder="搜索本店铺商品"/>
			</view>
			<view class="product-supplier" @click="goSupplier">
				<view class="logo"><img src="https://img.caimei365.com/group1/M00/03/4B/Cmis210DQ_qAIoyoAAKD15t_iQc959.png" alt=""></view>
				<view class="main">
					<view class="name">北京恩盛众成国际贸易有限公司</view>
					<view class="massgs">
						<view class="label">满意度:</view>
						<view class="p-stars">
							<uni-stars :stars="6" :iconClass="iconClass" :iconColor="iconColor" :fontSize="36" :widthInfo="176"></uni-stars>
						</view>
						<view class="acount">
							<text>50</text>件商品
						</view>
					</view>
				</view>
				<view class="right"><text class="iconfont icon-xiayibu"></text></view>
			</view>
			<banner :list="bannerImageList"></banner>
		</view>	
		<view class="container-section tui-skeleton">
			<view class="title">主推商品</view>
			<view class="section-product clearfix">
				<view class="floor-item" v-for="(item, index) in organizeProducts" :key="index" @click.stop="navToDetailPage(item.productID)">
					<image class="tui-skeleton-fillet" :src="item.mainImage" mode="aspectFill"></image>
					<view class="floor-item-content">
						<view class="title tui-skeleton-rect">
							<text class="mclap">{{item.name}}</text>
						</view>
						<view class="floor-item-act">
							<template v-if="item.actStatus==1">
								<view class="floor-tags" v-if="PromotionsFormat(item.promotions)">
									{{item.promotions.name}}<text v-if="hasLogin && item.price1TextFlag != '1'">:￥{{item.price | NumFormat}}</text>
								</view>
								<view class="floor-tags" v-else>{{item.promotions.name}}</view>	
							</template>
							<template v-if="item.actStatus ==0  &&  item.ladderPriceFlag==1">
								<view class="floor-tags">阶梯价格</view>	
							</template>	
						</view>
						<view class="" v-if="hasLogin">
							<view v-if="userIdentity == 4">
								<view class="title-none" v-show="item.price1TextFlag == '1'">
									<text class="p big">￥未公开价格</text>
								</view>
								<view class="title-none" v-show="item.price1TextFlag == '2'">
									<text class="p big">￥价格仅会员可见</text>
								</view>
								<view class="price tui-skeleton-rect" v-show="item.price1TextFlag == '0'" :class="PromotionsFormat(item.promotions) ? 'none' : ''">
									<text class="p sm">￥</text>
									<text class="p big">{{ (PromotionsFormat(item.promotions) ? item.originalPrice : item.price ) | NumFormat}}</text>
								</view>
							</view>
							<view v-else>
								<view class="title-none" v-if="item.price1TextFlag == '1'">
									<text class="p big">未公开价格</text>
								</view>
								<view class="price tui-skeleton-rect" v-else :class="PromotionsFormat(item.promotions) ? 'none' : ''">
									<text class="p sm">￥</text>
									<text class="p big">{{ (PromotionsFormat(item.promotions) ? item.originalPrice : item.price ) | NumFormat}}</text>
								</view>
							</view>
						</view>
						<view v-else class="no-price">
							<view class="p-stars">
								<text class="p-no">￥</text>
								<uni-stars :stars="parseInt(item.price1Grade)" :fontSize="36" :widthInfo="180"></uni-stars>
							</view>
						</view>	
					</view>
				</view>
			</view>
		</view>
		<!-- 侧边 -->
		<scroll-top v-if="isScrollTop"></scroll-top>
	</view>
</template>

<script>
	import { mapState,mapMutations} from 'vuex';
	import banner from '@/components/cm-module/supplier/banner.vue'
	import uniStars from '@/components/uni-stars/uni-stars.vue'
	import authorize from '@/common/config/authorize.js'
	
	export default {
		components:{
			banner,
			uniStars
		},
		data() {
			return {
				userID:0,
				iconClass:'icon-aixin',
				iconColor:'#ff9100',
				isScrollTop:false,
				bannerImageList:[
					{image:'https://m.360buyimg.com/mobilecms/s700x280_jfs/t1/114550/12/7437/102254/5ec3971fE78db18f4/438d4775f9d653ee.jpg!q70.jpg.dpg'},
					{image:'https://m.360buyimg.com/mobilecms/s700x280_jfs/t1/126187/19/17323/149042/5fa13ef1E6bc65f5b/8fbecafdbf0e4736.jpg!q70.jpg.dpg'},
					{image:'https://m.360buyimg.com/mobilecms/s700x280_jfs/t1/126522/38/16493/151268/5f9940bfE9bf4ce43/b9a09e36102a9667.jpg!q70.jpg.dpg'}
				],
				organizeProducts:[]
			}
		},
		onLoad() {
			
		},
		filters: {
			NumFormat:function(text) {//处理金额
				return Number(text).toFixed(2);
			},
		},
		computed: {
			...mapState(['hasLogin','userInfo','isActivity'])
		},
		methods: {
			...mapMutations(['login','logout']),
			getOrganizeProducts(){//获取模块三商品
				this.ProductService.queryProductPreferred({userId:this.userID,preferredFlag:100,pageNum:1,pageSize:4}).then(res =>{
					this.organizeProducts = res.data.results
					this.getProductPrice()
				}).catch(error =>{
					this.$util.msg(error.msg,2000)
				})
			},
			getProductPrice(){//获取商品或者活动价格
				let productIdArr = [];
				let productIds ='';
				this.organizeProducts.map(item=>{// 0公开价格 1不公开价格 2仅对会员机构公开
					productIdArr.push(item.productID)
				})
				productIds = productIdArr.join(",");
				this.ProductService.querySearchProductPrice({userId: this.userID,productIds:productIds}).then(response =>{
					this.organizeProducts = this.ReturnNewProducts(this.organizeProducts,response.data);
					this.skeletonShow = false;
				}).catch(error =>{
					this.$util.msg(error.msg,2000)
				})
			},
			ReturnNewProducts(Array,list){
				let NewArray = []
				Array.map(item=>{
					for (let i = 0; i < list.length; i++) {
						if( item.productID == list[i].productId ){
							NewArray.push(Object.assign(item,list[i])) 
						}
					}
				});
				return NewArray
			},
		},
		onPageScroll(e){//实时获取到滚动的值
			if(e.scrollTop>400){
				this.isScrollTop = true
			}else{
				this.isScrollTop = false
			}	
		},
		onPullDownRefresh() {//下拉刷新
			this.getHomeInformation()
			uni.stopPullDownRefresh()
		},
		onShow(){
			this.getOrganizeProducts()
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #F7F7F7;
	}
	.shop{
		width: 100%;
		height: auto;
	}
	.container-shop{
		width: 100%;
		height: auto;
		padding:24rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
	}
	.shop-search{
		width: 100%;
		height: 66rpx;
		border-radius: 33rpx;
		background-color: #F7F7F7;
		box-sizing: border-box;
		padding: 0 20rpx;
		.icon-sousuo{
			width: 60rpx;
			height: 66rpx;
			display: block;
			float: left;
			color: #707070;
			line-height: 66rpx;
			text-align: center;
			font-size: 36rpx;
		}
		.input{
			width: 600rpx;
			height: 66rpx;
			box-sizing: border-box;
			padding: 0 20rpx;
			color: #666666;
			overflow: hidden;
			font-size: $font-size-24;
		}
	}
	.product-supplier{
		width: 100%;
		height: 140rpx;
		padding: 30rpx 0 10rpx 0;
		box-sizing: border-box;
		background-color: #FFFFFF;
		position: relative;
		box-sizing: border-box;
		.logo{
			width: 128rpx;
			height: 92rpx;
			float: left;
			border: 1px solid #efefef;
			border-radius: 6rpx;
			image{
				width: 100%;
				height: 100%;
				display: block;
				border-radius: 6rpx;
			}
		}
		.main{
			width: 470rpx;
			height: 92rpx;
			float: left;
			margin-left: 20rpx;
			.name{
				width: 100%;
				line-height: 46rpx;
				float: left;
				font-size: $font-size-28;
				color: $text-color;
				float: right;
				overflow: hidden;
				text-overflow:ellipsis;
				white-space: nowrap;
				text-align: left;
			}
			.massgs{
				width: 100%;
				line-height: 46rpx;
				float: left;
				font-size: $font-size-24;
				color: #999999;
				.label{
					float: left;
				}
				.p-stars{
					float: left;
					margin-left: 20rpx;
				}
				.acount{
					float: right;
					text{
						color: $color-system;
					}
				}
			}
		}
		.icon-xiayibu{
			line-height: 154rpx;
			display: inline-block;
			position: absolute;
			width: 48rpx;
			top: 0;
			right: 0;
			color: #b2b2b2;
		}
	}
	.container-section{
		width: 100%;
		height: auto;
		background-color: #F7F7F7;
		box-sizing: border-box;
		padding: 0 24rpx;
		.title{
			width: 100%;
			height: 88rpx;
			line-height: 88rpx;
			font-size: $font-size-30;
			font-weight: bold;
		}
		.section-product{
			width: 100%;
			height: auto;
			.floor-item{
				width: 341rpx;
				height: auto;
				margin-right: 20rpx;
				font-size: $font-size-24;
				color: $text-color;
				background: #FFFFFF;
				line-height: 36rpx;
				border-radius: 2rpx;
				margin-bottom: 20rpx;
				float: left;
				box-sizing: border-box;
				padding-bottom: 16rpx;
				&:nth-child(2n){
					margin-right: 0;
				}
				image{
					width: 341rpx;
					height: 341rpx;
					border-radius: 20rpx 20rpx 0 0;
					display: block;
					margin-bottom: 20rpx;
				}
				.floor-item-content{
					width: 311rpx;
					padding: 0 15rpx;
				}
				.floor-item-act{
					display: block;
					width: 100%;
					height: 68rpx;
					text-align: center;
					box-sizing: border-box;
					padding: 16rpx 0;
					margin-top: 8rpx;
					.floor-tags{
						float: left;
						height: 36rpx;
						border-radius: 4rpx;
						background-color: rgba(225, 86, 22, 0.1);
						line-height: 36rpx;
						color: $color-system;
						text-align: center;
						display: inline-block;
						padding:0 16rpx;
						font-size: $font-size-20;
					}
				}
				.title-none{
					font-size: $font-size-26;
					color: #FF2A2A;
					line-height: 44rpx;
					.btn{
						display: inline-block;
						float: right;
						width: 112rpx;
						height: 44rpx;
						background: $btn-confirm;
						line-height: 44rpx;
						font-size: $font-size-24;
						color: #FFFFFF;
						text-align: center;
						border-radius: 22rpx;
						margin-top: 17rpx;
					}
				}
				.title{
					width: 100%;
					height: 72rpx;
					display: flex;
					flex-direction: column;
					.mclap{
						width: 100%;
						line-height: 36rpx;
						text-overflow:ellipsis;
						display: -webkit-box;
						word-break: break-all;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
						font-size: 26rpx;
					}
				}
				.no-price{
					height: 54rpx;
					line-height: 54rpx;
					display: flex;
					box-sizing: border-box;
					.p-no{
						font-size: $font-size-30;
						color: $text-color;
						display: block;
						float: left;
					}
					.p-stars{
						width: 230rpx;
						float: left;
					}
				}
				.price{
					color: #FF2A2A;
					line-height: 44rpx;
					&.none{
						text-decoration: line-through;
						color: #999999;
					}
					.sm{
						font-size: $font-size-24;
					}
					.big{
						font-size: $font-size-28;
					}
				}
			}
		}
	}
</style>
