<template>
	<view  class="content">
		<mescroll-body  ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			 <view class="goods-list">
			 	<view class="item" v-for="(item,index) in dataList" :key="index" >
			 		<image @click="showDetail(item)" class="goods-img" :src="item.image" mode="aspectFit"></image>
			 		<view   class="info-box">
			 			<view>
			 				<view class="title-box">
			 					<view class="title ellipsis">{{ item.productName }}</view>
			 				</view>
			 			</view>
			 			<view class="prce-num">
			 				<view class="price">
			 					<text class="unit">¥</text>
			 					<text class="num">{{item.price.toFixed(2)}} </text>
			 				</view>
							<view class="operat-box">
								<image src="/static/images/del1.png" mode="" @click="del(item)"></image>
								 
							</view>
			 			</view>
			 		</view>
					
			 	</view>
			 </view>
		</mescroll-body>
	</view>
</template>

<script>
	import {delProductFoots,getProductFoots} from '@/api/user'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				mescroll:null,
				// 上拉加载的配置
				upOption: {
					onScroll:true,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						icon:'/static/images/no_data.png',
						tip: '暂无数据'
					}
				},
				// 列表数据
				dataList: [],
			};
		},
		onLoad(option) {
			var that=this;
		},
		methods: {
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					page: page.num,
					pageSize: page.size
				};
				getProductFoots(data).then(res => {
					if(res.code==200){
						//设置列表数据
						if (page.num == 1) {
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						that.mescroll.endBySize(res.data.list.length, res.data.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			del(item){
			
				uni.showModal({
					title:"提示",
					content:"确认删除吗?",
					showCancel:true,
					cancelText:'取消',
					confirmText:'确定',
					success:res=>{
						if(res.confirm){
							// 用户点击确定
							var data={id:item.id}
							delProductFoots(data).then(
								res => {
									if(res.code==200){
										 uni.showToast({
										 	icon:'success',
										 	title: "操作成功",
										 });
										 this.mescroll.resetUpScroll()
									}else{
										uni.showToast({
											icon:'none',
											title: "请求失败",
										});
									}
								},
								rej => {}
							);
														
						}else{
							// 否则点击了取消  
						}
					}
				})
			},
			showDetail(item) {
				console.log(item)
				uni.navigateTo({
					url: '/pages/shopping/productDetails?productId=' + item.productId
				})
			},
			 
			
		}
	}
</script>

<style lang="scss">
	.content{
	 	height: 100%;
	 	.goods-list{
			padding: 20upx;
	 		.item{
	 			box-sizing: border-box;
	 			height: 221upx;
	 			background: #FFFFFF;
	 			border-radius: 16upx;
	 			margin-bottom: 20upx;
	 			padding: 30upx;
	 			display: flex;
	 			align-items: center;
	 			&:last-child{
	 				margin-bottom: 0;
	 			}
	 			.goods-img{
	 				width: 160upx;
	 				height: 160upx;
	 				background: #FFFFFF;
	 				margin-right: 30upx;
	 				flex-shrink: 0;
	 			}
	 			.info-box{
	 				height: 160upx;
	 				display: flex;
	 				flex-direction: column;
	 				justify-content: space-between;
	 				width: calc(100% - 160upx);
	 				.title-box{
	 					width: 100%;
	 					display: flex;
	 					align-items: center;
	 					 
	 					.title{
	 						flex: 1;
	 						font-size: 28upx;
	 						font-family: PingFang SC;
	 						font-weight: 500;
	 						color: #111111;
	 						line-height: 1;
	 					}
	 				}
	 				.prce-num{
	 					display: flex;
	 					align-items: center;
	 					justify-content: space-between;
	 					margin-top: 30upx;
	 					.price{
	 						display: flex;
	 						align-items: flex-end;
	 						.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;
	 						}
	 					}
						.operat-box{
							margin-right: 30rpx;
							display: flex;
							align-items: center;
							image{
								width: 30upx;
								height: 30upx;
							 
							}
						}
	 					 
	 				}
	 			}
	 		}
	 	}
	}
	
</style>
