<template>
	<view>
		<view class="goodsList animated fadeInDown">
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
				<view class="title">{{ item.shopName }}</view>
				<view class="state" @click.stop="del(item)"><text class="icon del">&#xe852;</text></view>
				<image src="../../../../static/news.jpg" mode="aspectFill" class="pic"></image>
				<view class="con">
					<view class="productName omit">{{ item.goodsName }}</view>
					<view class="desc omit">
						<text>{{ item.netWeight }}</text>
						<text>{{ item.tradeAreaName }}</text>
					</view>
					<view class="price">¥ {{ item.totalPrice }}</view>
				</view>
				<view class="clear"></view>
				<view class="op">
					<view class="date">{{ item.createTime }}</view>
					<view class="an btn" @click.stop="buy(item)">立即购买</view>
				</view>
			</view>
			<u-empty v-if="list.length == 0"></u-empty>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: []
		};
	},
	onLoad() {
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/level-one-server/app/TbGoodsCart/getList',
				data: this.param,
				success: res => {
					this.list = res.data.data || [];
				}
			});
		},
		detail(item) {
			uni.navigateTo({ url: '/pages/market/one/detail?id=' + item.publishGoodsId });
		},
		// 立即购买
		buy(item) {
			this.http.request({
				url: '/level-one-server/app/TbGoodsTransit/purchaseLevelOntGoodsTransit',
				data: { goodsTransitId: item.publishGoodsId, goodsCartId: item.id },
				method: 'POST',
				contentType: 'application/json;charset=utf-8',
				success: res => {
					uni.redirectTo({ url: '/pages/market/one/leader/success' });
				}
			});
		},
		del(item) {
			let ids = item.id || this.list.map(i => i.id);
			uni.showModal({
				title: '提示',
				content: item.id ? '确定删除该购物车？' : '清空所有购物车',
				success: res => {
					if (res.confirm) {
						this.http.request({
							url: '/level-one-server/app/TbGoodsCart/cleanCart/' + ids,
							success: res => {
								uni.showToast({ title: '删除成功' });
								this.getData();
							}
						});
					}
				}
			});
		}
	},
	onNavigationBarButtonTap() {
		this.del({});
	}
};
</script>

<style lang="scss">
page {
	background-color: $pg;
}
.date {
}
.an {
	padding: 6px 15px;
	font-size: 14px;
	margin-top: 0px !important;
	font-weight: normal !important;
}
</style>
