<template name="cm-price">
	<!-- 商品详情价格判断 -->
	<view class="wrap-main">
		<!-- 协销  -->
		<view class="wrap-main-item">
			<view class="p-price tui-skeleton-fillet">
				<text class="txt sm">￥</text>
				<text class="txt big">{{ showIndexOfMoney }} </text>
				<text class="txt sm">{{ smallMoney }} </text>
			</view>
			<view class="floor-item-act" v-if="product.activeStatus == 1">
				<text class="tag tag-01" v-if="product.includedTax == '0'">自营</text>
				<text class="tag tag-01" v-if="product.includedTax == '1'">促销</text>
				<view class="tag tag-02" @click.stop="clickPopupShow()">活动价</view>
			</view>
		</view>
		<!--促销活动弹窗提示-->
		<tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup()">
			<view class="tui-popup-box clearfix">
				<template v-if="product.activeStatus == 1">
					<view class="tui-scrollview-box">
						<view class="ladder-main clearfix">
							<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.ladderList"
								:key="index"
							>
								<view class="ladder-item-td">{{ ladd.buyNum }}</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="product.promotion.status == 1">不限时</text>
							<text class="txt" v-else
								>{{ product.promotion.beginTime }}～{{ product.promotion.endTime }}</text
							>
						</view>
						<view class="box-title" v-show="product.promotion.mode == 2">
							<text>购买{{ product.promotion.name }}商品，满</text>
							<text class="txt"
								>¥{{
									product.promotion == null
										? '0.00'
										: product.promotion.touchPrice | NumFormat
								}}</text
							>减
							<text class="txt"
								>¥{{
									product.promotion == null
										? '0.00'
										: product.promotion.reducedPrice | NumFormat
								}}</text
							>
						</view>
						<view class="box-title" v-show="product.promotion.mode == 3">
							<text>购买{{ product.promotion.name }}商品，满</text>
							<text class="txt"
								>¥{{
									product.promotion == null
										? '0.00'
										: product.promotion.touchPrice | NumFormat
								}}</text
							>赠送商品
						</view>
						<view class="box-product" v-show="product.promotion.mode == 3">
							<view
								class="box-product-main"
								v-for="(item, index) in product.promotion.productGifts"
								:key="index"
							>
								<view class="image"
									><image :src="item.mainImage" mode="widthFix"></image
								></view>
								<view class="info">
									<view class="name">{{ item.productName }}</view>
									<view class="num">X{{ item.productCount }}</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.promotion.type == 2"
							@click="goGoodActiveFn(product.promotion.id)"
							>更多凑单商品</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'
import uniGrader from '@/components/uni-grade/uni-grade.vue'
export default {
	name: 'cm-price',
	components: {
		uniGrader
	},
	props: {
		product: {
			type: Object
		},
		userIdentity: {
			type: Number,
			default: 2
		},
		ladderList: {
			type: Array
		},
		promotion: {
			type: Object
		}
	},
	data() {
		return {
			productInfo:{},
			popupShow: false,
			promotionType: 0,
			isIphoneX: this.$store.state.isIphoneX,
			ableUserMoney:'',
			showIndexOfMoney:'',
			smallMoney:''
		}
	},
	filters: {
		NumFormat: function(text) {
			//处理金额
			return Number(text).toFixed(2)
		}
	},
	created() {
		
		this.InfoData(this.product)			
	},
	computed: {
		...mapState(['hasLogin', 'isWxAuthorize'])
	},
	methods: {
		InfoData(data){
			this.productInfo = data
			if(this.productInfo.price == 0){
				this.showIndexOfMoney ='0';
				this.smallMoney=".00"
			}else{
				this.ableUserMoney = this.$api.FormatMoney(this.productInfo.price) ;
				let i =  this.ableUserMoney.toString().lastIndexOf('.');
				if(i==-1){
					this.showIndexOfMoney=this.$api.FormatMoney(this.ableUserMoney)
					this.smallMoney=".00"
				}else{
					this.smallMoney = this.ableUserMoney.toString().substring(i,i+3);
					this.showIndexOfMoney= this.$api.FormatMoney(this.ableUserMoney.toString().substring(0,i))
					if(this.smallMoney.length == 2) { //补0,实际上用不着
						this.smallMoney = this.smallMoney + '0';
					}
				}
			}
			console.log('this.showIndexOfMoney',this.showIndexOfMoney)
			console.log('this.smallMoney',this.smallMoney)
		},
		clickPopupShow(type) {
			this.popupShow = true
			this.promotionType = type
		},
		hidePopup() {
			this.popupShow = false
		},
		promotionFormat(promo) {
			//促销活动类型数据处理
			if (promo != null) {
				if (promo.type == 1 && promo.mode == 1) {
					return true
				} else {
					return false
				}
			}
			return false
		},
		goUpgradeApply() {
			this.$api.navigateTo('/pages/login/apply')
		},
		loginClick() {
			this.$api.navigateTo('/pages/login/login')
		},
		goGoodActiveFn(id) {
			this.$parent.popupShow = false
			this.$api.navigateTo('/pages/goods/goods-active?id=' + id)
		}
	}
}
</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%;
		min-height: 240rpx;
		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: #ff2a2a;
		}
	}
	.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;
			float: left;
			margin: 10rpx 0;
			.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: 44rpx;
	}
}

// .wrap-main{
// 	.floor-item-act{
// 		&::after{
// 			content: "";
// 			display: block;
// 			clear: both;
// 		}
// 		.tag{
// 			margin-right: 10rpx;
// 			float: left;
// 		}
// 	}
// }
</style>
