<template name="cm-price">
	<!-- 商品详情价格判断 -->
	<view class="wrap-main">
		<template v-if="!hasLogin">
			<view class="p-login grade tui-skeleton-fillet">
				<text class="p-no">￥</text>
				<uni-stars :stars="parseInt(product.price1Grade)" :font-size='36' :width-info="180"></uni-stars>
				<view v-if="product.actStatus==1" class="floor-item-act">
					<view v-if="product.promotions.type == 1 && product.promotions.mode==1"  class="floor-tags" @click.stop="clickPopupShow()">
						{{product.promotions.name}}<text v-if="hasLogin">:￥{{ product.price | NumFormat }}</text>
					</view>
					<view v-else class="floor-tags" @click.stop="clickPopupShow()">{{product.promotions.name}}</view>	
				</view>
				<view v-if="product.actStatus ==0  &&  product.ladderPriceFlag === 1" class="floor-item-act">
					<view class="floor-tags" @click.stop="clickPopupShow()">阶梯价格</view>	
				</view>
				<view class="floor-item-btn">
					<view class="btn" @click.stop="loginClick">登录查看价格</view>
				</view>
			</view>
		</template>
		<template v-else>
			<!-- 协销  -->
			<template  v-if="userIdentity == 1">
				<view class="wrap-main-item">
					<view class="p-price tui-skeleton-fillet" :class="product.promotions.type == 1 && product.promotions.mode == 1 ? 'none' : ''">
						<text class="txt sm">￥</text>
						<text class="txt big">{{product.retailPrice | NumFormat}}</text>
					</view>
					<view v-if="product.actStatus==1" class="floor-item-act">
						<view v-if="product.promotions.type == 1 && product.promotions.mode == 1"  class="floor-tags" @click.stop="clickPopupShow(1)">
							{{product.promotions.name}}<text v-if="hasLogin">:￥{{ product.price | NumFormat }}</text>
						</view>
						<view v-else class="floor-tags" @click.stop="clickPopupShow()">{{product.promotions.name}}</view>	
					</view>
					<view  v-if="product.actStatus == 0  &&  product.ladderPriceFlag == 1" class="floor-item-act">
						<view class="floor-tags" @click.stop="clickPopupShow()">阶梯价格</view>	
					</view>
				</view>		
			</template>	
			<!-- 会员机构  -->
			<template v-if="userIdentity == 2">
				<view v-if="product.price1TextFlag == '1'" class="wrap-main-pricenone">
					<view class="wrap-main-text">￥未公开价格</view>
				</view>
				<view v-else class="wrap-main-item">
					<view class="p-price tui-skeleton-fillet" :class="product.promotions.type == 1 && product.promotions.mode==1 ? 'none' : ''">
						<text class="txt sm">￥</text>
						<text class="txt big">{{product.retailPrice | NumFormat}}</text>
					</view>
					<view v-if="product.actStatus==1" class="floor-item-act">
						<view v-if="product.promotions.type == 1 && product.promotions.mode == 1"  class="floor-tags" @click.stop="clickPopupShow(1)">
							{{product.promotions.name}}<text v-if="hasLogin">:￥{{ product.price | NumFormat }}</text>
						</view>
						<view v-else class="floor-tags" @click.stop="clickPopupShow()">{{product.promotions.name}}</view>	
					</view>
					<view  v-if="product.actStatus ==0  &&  product.ladderPriceFlag == 1" class="floor-item-act">
						<view class="floor-tags" @click.stop="clickPopupShow()">阶梯价格</view>	
					</view>
				</view>
			</template>
			<!-- 普通机构  -->
			<template v-if="userIdentity == 4">
				<template v-if="product.price1TextFlag == '1'">
					<text class="wrap-main-text">￥未公开价格</text>
				</template>
				<template v-if="product.price1TextFlag == '2'">
					<text class="wrap-main-text">￥价格仅会员可见</text>
					<view class="floor-item-btn">
						<view class="btn" @click.stop="goUpgradeApply">升级会员查看价格</view>
					</view>
				</template>
				<template v-if="product.price1TextFlag == '0'">
					<view class="wrap-main-item">
						<view class="p-price tui-skeleton-fillet" :class="product.promotions.type == 1 && product.promotions.mode == 1 ? 'none' : ''">
							<text class="txt sm">￥</text>
							<text class="txt big">{{product.retailPrice | NumFormat}}</text>
						</view>
						<view v-if="product.actStatus==1" class="floor-item-act">
							<view v-if="product.promotions.type == 1 && product.promotions.mode == 1"  class="floor-tags" @click.stop="clickPopupShow(1)">
								{{product.promotions.name}}<text v-if="hasLogin">:￥{{ product.price | NumFormat }}</text>
							</view>
							<view v-else class="floor-tags" @click.stop="clickPopupShow()">{{product.promotions.name}}</view>	
						</view>
						<view  v-if="product.actStatus ==0  &&  product.ladderPriceFlag == 1" class="floor-item-act">
							<view class="floor-tags" @click.stop="clickPopupShow()">阶梯价格</view>	
						</view>
					</view>
				</template>		
			</template>
			<!--促销活动弹窗提示-->
			<tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup()">
				<view class="tui-popup-box clearfix">
					<template v-if="product.actStatus == 0  &&  product.ladderPriceFlag == 1">
						<view class="tui-scrollview-box">
							<view class="ladder-main">
								<view class="ladder-item">
									<view class="ladder-item-td">起订量</view>
									<view class="ladder-item-td">价格</view>
								</view>
								<view class="ladder-item" v-for="(ladd, index) in product.ladderPriceList" :key="index">
									<view class="ladder-item-td">{{ ladd.buyNumRangeShow }}</view>
									<view class="ladder-item-td">{{ ladd.buyPrice | NumFormat }}</view>
								</view>
							</view>
						</view>	
					</template>	
					<template v-else>
						<view class="tui-scrollview-box">
							<view class="box-text">
								<text>促销时间：</text>
								<text class="txt" v-if="promotions.status == 1">不限时</text>
								<text class="txt" v-else>{{ promotions.beginTime }} ～ {{ promotions.endTime }}</text>
							</view>
							<view class="box-title" v-show="promotions.mode ==2">
								<text>购买凑单商品，满</text>
								<text class="txt">¥{{promotions.touchPrice}}</text>减
								<text class="txt">¥{{promotions.reducedPrice}}</text>
							</view>
							<view class="box-title" v-show="promotions.mode==3">
								<text>购买购买凑单商品，满</text>
								<text class="txt">¥{{promotions.touchPrice}}</text>赠送商品
							</view>
							<view class="box-product" v-show="promotions.mode==3">
								<view class="title">赠送商品:</view>
								<view class="box-product-main"  v-for="(item, index) in promotions.giftList" :key="index">
									<view class="image"><image :src="item.image" mode="widthFix"></image></view>
									<view class="info">
										<view class="name">{{ item.name }}</view>
										<view class="num">X{{ item.number }}</view>
									</view>
								</view>
							</view>
						</view>
					</template>
					<view class="tui-right-flex tui-popup-btn" :style="{ paddingBottom :isIphoneX ? '68rpx' : '0rpx' }">
						<view class="tui-flex-1">
							<view class="tui-button" v-if="product.promotions.type == 2" @click="hidePopup()">更多凑单商品</view>
							<view class="tui-button" v-else @click="hidePopup()">了解</view>
						</view>
					</view>
				</view>	
			</tui-bottom-popup>
		</template>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	export default{
		name:'cm-price',
		props:{
			product:{
				type:Object,
			},
			userIdentity: {
				type: Number,
				default: 2
			},
			ladderPriceList:{
				type: Array,
			},
			promotions:{
				type:Object,
			}
		},
		data() {
			return{
				popupShow:false,
				promotionsType:0,
				isIphoneX:this.$store.state.isIphoneX,
			}
		},
		filters: {
			NumFormat:function(text) {//处理金额
				return Number(text).toFixed(2);
			},
		},
		created() {
			
		},
		computed: {
			...mapState(['hasLogin','isWxAuthorize'])
		},
		methods:{
			clickPopupShow(type){
				this.popupShow = true
				this.promotionsType = type
			},
			hidePopup(){
				this.popupShow = false
			},
			goUpgradeApply(){
				this.$api.navigateTo('/pages/login/apply')
			},
			loginClick(){
				this.$api.navigateTo('/pages/login/login')
			},
			toFixed:function(text) {//处理金额
				if(text == null || text === undefined){
					return Number(0).toFixed(2);
				}else{
					return Number(text).toFixed(2);
				}
			},
		},
		
	}
</script>

<style lang="scss">	
	.tui-flex-1 {
		flex: 1;
	}
	.tui-popup-box {
		position: relative;
		box-sizing: border-box;
		min-height: 220rpx;
		padding:24rpx 24rpx 0 24rpx;
	}
	.tui-scrollview-box{
		width: 100%;
		height: auto;
		float: left;
		box-sizing: border-box;
		.ladder-main{
			width: 100%;
			height: 320rpx;
			border: 1px solid rgba(225,86,22,0.3);
			border-radius: 10rpx;
			.ladder-item{
				width: 100%;
				height: 80rpx;
				float: left;
				border-bottom: 1px solid rgba(225,86,22,0.3);
				&:nth-child(1){
					.ladder-item-td{
						color: #333333;
					}
				}
				&:last-child{
					border-bottom: none;
				}
				.ladder-item-td{
					width:50%;
					text-align: center;
					line-height: 80rpx;
					font-size: $font-size-24;
					color: $color-system;
					box-sizing: border-box;
					float: left;
					&:nth-child(1){
						border-right: 1px solid rgba(225,86,22,0.3);
					}
				}
			}
		}
		.box-title{
			font-size: $font-size-26;
			color: $text-color;
			text-align: left;
			line-height: 56rpx;
			.txt{
				color: $color-system;
				margin: 0 8rpx;
			}
		}
		.box-text{
			font-size: $font-size-26;
			color: $text-color;
			text-align: left;
			line-height: 56rpx;
			.txt{
				color: $color-system;
			}
		}
		.box-product{
			width: 100%;
			height: auto;
			margin-top: 20rpx;
			.title{
				font-size: $font-size-24;
				color: $text-color;
				text-align: left;
				line-height: 54rpx;
			}
			.box-product-main{
				width: 100%;
				height: 136rpx;
				.image{
					width: 134rpx;
					height: 134rpx;
					border: 1px solid #EBEBEB;
					float: left;
					image{
						width: 100%;
						height: 100%;
						display: block;
					}
				}
				.info{
					width: 540rpx;
					height: 134rpx;
					float: left;
					margin-left: 16rpx;
					position: relative;
					.name{
						width: 100%;
						float: left;
						line-height: 40rpx;
						font-size: $font-size-28;
						color: $text-color;
						-o-text-overflow: ellipsis;
						text-overflow: ellipsis;
						display: -webkit-box;
						word-break: break-all;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}
					.num{
						width: 100%;
						height: 44rpx;
						font-size: $font-size-24;
						color: $text-color;
						text-align: left;
						line-height: 44rpx;
						position: absolute;
						bottom: 0;
						left: 0;
					}
				}
			}
		}
	}
	
	.tui-popup-btn {
		width: 100%;
		height: auto;
		float: left;
		margin-top: 24rpx;
		.tui-button{
			width: 100%;
			height: 88rpx;
			background: $btn-confirm;
			line-height: 88rpx;
			text-align: center;
			color: #FFFFFF;
			font-size: $font-size-28;
			border-radius: 14rpx;
		}
	}
</style>





















