<template>
    <view class="photo">
		<view class="status_bar"></view>
        <view class="back">
            <u-icon name="close" color="#999999" :size="30" @click="goBack"></u-icon>
        </view>
        <swiper class="swiper" circular autoplay @change="changeSwiper">
            <swiper-item v-for="(simg,sindex) in list.photo" :key="sindex">
                <image :src="simg.url" mode="aspectFill" @tap="viewImage" :data-url="simg.url"></image>
            </swiper-item>
        </swiper>
        <view class="bottom">
            <view class="item">
                <text>图片</text>
                <view v-for="(item,index) in list.photo" :key="index" :style="{'background-color':index == swiper_id ? '#fff' : '#ede8e8'}"></view>
            </view>
            <view class="username">{{ list.member_nickname }}</view>
            <view class="title">{{ list.article_title }}</view>
            <view class="info">{{ list.article_content }}</view>
			<view class="box">
				<view class="label" v-for="(label,id) in list.label" :key="id">{{ label.name }}</view>
			</view>
        </view>
		<!-- 用户操作 -->
        <userinfo class="userinfo" :list="list" :cart="cart_type" :comment="is_comment" @openCart="openCart"></userinfo>
		<!-- 评论 -->
		<u-popup v-model="is_comment" class="pl" mode="bottom" border-radius="10" height="700rpx">
			<view class="top">
				<text>评论</text>
				<u-icon name="arrow-down" color="#333" size="28" @click="close"></u-icon>
			</view>
			<scroll-view class="scroll-box" scroll-y="true" >
				<view></view>
			</scroll-view>
			<view class="editing">
				<input type="text" value="" />
				<text>发送</text>
			</view>
		</u-popup>
		<!-- 购物车 -->
		<u-popup v-if="cart_len > 1" class="cart" v-model="cart_type" mode="bottom" length="782" border-radius="20">
			<view class="top">
				<text>全部商品</text>
		        <u-icon name="close" color="#999999" :size="30" @click="cart_type = false"></u-icon>
			</view>
		    <scroll-view :scroll-y="true" class="scroll-box">
		        <view v-for="(item,index) in list.goods" :key="index" class="item" @click="gotoInfo(item.goods_id)">
					<image :src="item.goods_image" mode="aspectFill"></image>
					<view>
						<text class="title">{{ item.goods_advword }}</text>
						<text class="name">{{ item.goods_name }}</text>
						<text class="price">{{ item.goods_promotion_price }}</text>
					</view>
				</view>
		    </scroll-view>
		</u-popup>
		<!-- 单个 -->
		<view class="good-one" v-else v-show="cart_type">
			<view class="box" v-for="(item,index) in list.goods" :key="index" @click="gotoInfo(item.goods_id)">
				<image :src="item.goods_image" mode=""></image>
				<view>
					<view class="title u-line-1">{{ item.goods_advword }}</view>
					<view class="content u-line-2">{{ item.goods_name }}</view>
					<view class="price">￥{{ item.goods_promotion_price }}</view>
				</view>
			</view>
		</view>
        <!-- <shoplist :list="list.goods" v-show="list.goods.length > 1 && cart_type" @hideCart="hideCart"></shoplist> -->
    </view>
</template>
<style lang="scss" scoped>
.photo{
    width: 100%;
    height: 100%;
    background-color: #ececec;
    .back{
        padding-top: 28rpx;
        padding-right: 31rpx;
        text-align: right;
    }
    .swiper{
        width: 750rpx;
        height: 702rpx;
        margin-top: 102rpx;
        image{
            width: 100%;
            height: 100%;
        }
    }
    .bottom{
		width: 100%;
		margin-top: 150rpx;
        padding: 20rpx 30rpx;
        background-color: #fff;
        .item{
            display: flex;
            align-items: center;
            padding: 8rpx 16rpx;
            font-size: 24rpx;
            color: #fff;
            border-radius: 10rpx;
            background-color: #999;
            >view{
                width: 12rpx;
                height: 12rpx;
                border-radius: 50%;
                margin-left: 10rpx;
            }
        }
        .username{
			margin: 20rpx 0;
            font-size: 36rpx;
            color: #333;

        }
        .title{
            font-size: 26rpx;
            color: #333;
        }
        .info{
			margin: 20rpx 0;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
			overflow: hidden;
            font-size: 28rpx;
        }
		.box {
			display: flex;
			flex-wrap: wrap;
			.label {
				padding: 6rpx 10rpx;
				margin: 0 10rpx 10rpx 0;
				font-size: 24rpx;
				color: #fff;
				border-radius: 6rpx;
				background-color: #000000;
				opacity: 0.5;
			}
		}
    }
    .userinfo{
        position: absolute;
        right: 30rpx;
        top: 50%;
        transform: translateY(-285rpx);
    }
	.pl {
		.top {
			position: fixed;
			top: 0;
			width: 100%;
			height: 88rpx;
			padding: 0 20rpx;
			line-height: 88rpx;
			background-color: #ECECEC;
			& > text {
				margin-right: 280rpx;
				color: #333;
				font-size: 30rpx;
				font-weight: 500;
			}
		}
		.scroll-box {
			margin: 88rpx 0 100rpx 0;
			height: 100%;
		}
		.editing {
			position: fixed;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			height: 90rpx;
			padding: 0 30rpx;
			background-color: #ECECEC;
			& > input {
				width: 80%;
				height: 60rpx;
				padding: 0 20rpx;
				border-radius: 30rpx;
				background-color: #fff;
			}
		}
	}
	.cart {
		.top{
			z-index: 1000;
			position: fixed;
			top: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			height: 88rpx;
			padding: 0 30rpx;
			border-bottom: 1rpx solid #ececec;
			background-color: #fff;
			>text{
				font-size: 30rpx;
				color: #333;
			}
		}
		.scroll-box {
			margin-top: 88rpx;
			.item {
				display: flex;
				padding: 20rpx;
				border-bottom: 1px solid #ECECEC;
				& > image {
					flex-shrink: 0;
					width: 160rpx;
					height: 160rpx;
					margin-right: 14rpx;
					border-radius: 10rpx;
				}
				& > view {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					color: #333;
					font-size: 28rpx;
					.title {
					}
					.name {
						width: 500rpx;
						height: 80rpx;
						font-size: 24rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
					}
					.price {
						color: #FF3131;
					}
				}
			}
		}
	}
    .good-one{
        z-index: 999;
        position: absolute;
        right: 139rpx;
        top: 54%;
        transform: translateY(100rpx);
		.box {
			display: flex;
			align-items: center;
			width: 440rpx;
			height: 200rpx;
			padding: 20rpx;
			font-size: 28rpx;
			color: #fff;
			border-radius: 10rpx;
			background-color: rgba(0,0,0,0.5);
			& > image {
				flex-shrink: 0;
				width: 160rpx;
				height: 100%;
				margin-right: 10rpx;
				border-radius: 10rpx;
			}
			& > view {
				width: 200rpx;
			}
			.title {}
			.content {
				height: 60rpx;
				margin: 10rpx 0;
				font-size: 24rpx;
			}
			.price {
				color: #FF3131;
			}
		}
    }
}
</style>
<script>
import userinfo from "../components/userinfo/index" // 点赞组件
import contentBox from "../components/shpoone/index" // 评论
// import shoplist from "../components/shoplist/index" // 商品列表

export default {
    name:"photo",
    components:{
        userinfo
    },
    data(){
        return {
            list:{},
			swiper_id: "",
			cart_type: false,
			is_comment: false,
			cartList: [],
			cart_len: 0,
        }
    },
	onLoad(o){
	    this.id = o.id;
	    this.articleInfo(this.id);
	},
    methods:{
		// 发现详情
        articleInfo(article_id){
            this.$u.api.articleInfo({article_id}).then((res)=>{
                this.list = res.data.info;
				this.cart_len = res.data.info.goods.length;
            })
        },
		// 改变swiper
		changeSwiper(e) {
			// console.log(e.detail.current);
			this.swiper_id = e.detail.current; // 储存swiper id
		},
		// 更改购物车状态
		openCart(data) {
			console.log(data);
			this.cart_type = data.cart;
			this.is_comment = data.comment;
		},
		hideCart(data) {
			// console.log(data);
			this.cart_type = data.cart;
		},
		close() {
			this.is_comment = false;
		},
		// 预览图片
		viewImage(e) {
			let arr = [];
			this.list.photo.forEach(item => {
				arr.push(item.url);
			})
			uni.previewImage({
				urls: arr,
				current: e.currentTarget.dataset.url,
			})
		},
		// 跳转到商品
		gotoInfo(id) {
			console.log(id);
			uni.navigateTo({
				url: "/pageB/sdetails/index?id=" + id + "&type=" + 1,
			})
		},
		goBack() {
			uni.navigateBack({
				delta: 1
			})
		}
    },
}
</script>