<template>
   <view>
		<view class="like-title" v-show="list &&list.length > 0">
			<image src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/like.png" mode=""></image>
			<text class="text">猜你喜欢</text>
		</view>
		<view class="like-list">
			<view class="item" v-for="(item,index) in list" :key="index" @click="showProduct(item)">
				<view class="img-box">
					<image :src="item.image" mode=""></image>
				</view>
				<view class="info-box">
					<view class="title ellipsis2">{{ item.productName }}</view>
					<view class="price-box">
						<view class="now">
							<text class="unit">¥</text>
							<text class="num"  v-if="userinfoa.isShow==1&&isuser==false">{{item.price.toFixed(2)}}</text>
							<text class="num" v-else>{{item.otPrice.toFixed(2)}}</text>
						</view>
						<view class="old" v-if="userinfoa.isShow==1&&isuser==false">¥{{item.otPrice.toFixed(2)}}</view>
					</view>
				</view>
			</view>
		</view>
		<Loading :loaded="loaded" :loading="loading"></Loading>
   </view>
</template>

<script>
  import {getGoodsProducts} from '@/api/product'
  import {getUserInfo} from '@/api/user'
  import Loading from "@/components/Loading";
  export default {
	components: {Loading },
    name: "likeProduct",
	data() {
		return {
			page:{
				page: 1,
				pageSize: 10,
				appId:wx.getAccountInfoSync().miniProgram.appId,
			},
			total:0,
			list:[],
			loaded: false,
			loading: false,
			userinfoa:[],
			isuser:false,
		};
	},
	created() {
	},
	mounted() {
		this.getGoodsProducts();
		if(uni.getStorageSync('AppToken')){
			this.getUserInfos()
		}else{
			this.isuser=true
		}
	},
	watch: {
		UserInfo() {
		    return uni.getStorageSync('AppToken')
		}
	},
	methods: {
		getUserInfos(){
			getUserInfo().then(res => {
					if(res.code==200){
						if(res.user!=null){
							// if(res.user.isPromoter==null||res.user.isPromoter==0){
							// 	this.tuiModalControl=true
							// }
							this.userinfoa=res.user
							console.log(this.userinfoa.isShow,78787)
						}
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
					}
				},
				rej => {}
			);
		},
		getGoodsProducts(){
			console.log(1)
			var that=this;
			if (that.loaded == true || that.loading == true) return;
			that.loading = true;
			uni.showLoading({
				title:"加载中..."
			})
			getGoodsProducts(that.page).then(
				res => {
					if(res.code==200){
						that.total=res.data.total;
						that.list.push.apply(that.list, res.data.list);
						that.loading = false;
						that.loaded = that.list.length<that.total?false:true;
						that.page.page = that.page.page + 1;
						uni.hideLoading()
					}
				},
				err => {
					uni.hideLoading()
					uni.showToast({
						title: err.msg ,
						icon: 'none',
						duration: 2000
					});
				}
			);
		},
		showProduct(item){
			uni.navigateTo({
				url: '/pages/shopping/productDetails?productId='+item.productId
			})
		},
	}
 
  };
</script>
<style lang="scss">
	.like-title{
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 30upx 0;
		image{
			width: 37upx;
			height: 37upx;
			margin-right: 20upx;
		}
		.text{
			font-size: 36upx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #111111;
			line-height: 1;
		}
	}
	.like-list{
		display: flex;
		flex-wrap: wrap;
		.item{
			margin-right: 20rpx;
			margin-bottom: 20rpx;
			width: 345rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 10rpx 4rpx rgba(199, 199, 199, 0.22);
			border-radius: 20rpx;
			overflow: hidden;
			&:nth-child(2n) {
				margin-right: 0;
			}
			.img-box{
				width: 100%;
				height: 334upx;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.info-box{
				box-sizing: border-box;
				height: 182upx;
				padding: 20upx 20upx 30upx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.title{
					font-size: 26upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
					line-height: 40upx;
				}
				.price-box{
					display: flex;
					align-items: flex-end;
					.now{
						display: flex;
						align-items: flex-end;
						margin-right: 20upx;
						.unit{
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #FF6633;
							line-height: 1.2;
							margin-right: 4upx;
						}
						.num{
							font-size: 36upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #FF6633;
							line-height: 1;
						}
					}
					.old{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						text-decoration: line-through;
						color: #BBBBBB;
						line-height: 1.1;
					}
				}
			}
		}
	}
</style>
