<template>
	<view>
		<view class="tab">
			<u-tabs :list="tab" @click="click" :lineHeight="5"></u-tabs>
			<view class="length">{{ dataCount }}件商品</view>
		</view>
		<view class="goodsManageList">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="top">
					<view class="title omit">{{ item.goodsName }}</view>
					<view class="state" v-if="item.goodsStatus == 1">
						<text class="icon" style="color: #13ce66">&#xe830;</text>
						<text>在售</text>
					</view>
					<view class="state" v-else>
						<text class="icon" style="color: #f44336">&#xe622;</text>
						<text>下架</text>
					</view>
					<view class="clear"></view>
				</view>
				<view class="con">
					<view class="flex fs">
						<view class="f">
							<view class="tag">类型</view>
							<view class="v omit">{{ item.goodsType }}</view>
						</view>
						<view class="f">
							<view class="tag">单位</view>
							<view class="v omit">{{ item.goodsUnits || '吨' }}</view>
						</view>
						<view class="f">
							<view class="tag">价格</view>
							<view class="v omit">￥{{ item.price }}</view>
						</view>
						<view class="f">
							<view class="tag">库存</view>
							<view class="v omit">{{ item.stock }}</view>
						</view>
					</view>
					<view class="tradeAreaName">{{ item.tradeAreaName }}</view>
					<view class="date">发布于：{{ item.createTime }}</view>
				</view>
				<view class="op">
					<view class="flex">
						<view class="f rline" style="color: #0081ff" @click.stop="edit(item.id)">
							<text class="icon">&#xe668;</text>
							<text>编辑</text>
						</view>
						<view class="f" style="color: #f44336" @click.stop="del(item.id)">
							<text class="icon">&#xe852;</text>
							<text>删除</text>
						</view>
					</view>
				</view>
				<view class="clear"></view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && list.length == 0"></u-empty>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			tab: [
				{ name: '全部', goodsStatus: '' },
				{ name: '在售', goodsStatus: 1 },
				{ name: '下架', goodsStatus: 0 }
			],
			param: { pageNo: 1, pageSize: 10, isOrders: 0 },
			list: [],
			loadMore: true,
			dataCount: 0
		};
	},
	onLoad() {
		this.getData();
		uni.$on('goodsHandle', res => {
			this.refresh();
		});
	},
	methods: {
		getData() {
			this.http.request({
				url: '/level-one-server/app/TbGoodsTransit/getTransitList',
				loading: 'false',
				data: this.param,
				success: res => {
					this.dataCount = res.data.dataCount;
					this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
					this.list.push(...res.data.data);
				}
			});
		},
		//点击tab切换
		click(e) {
			this.param.goodsStatus = e.goodsStatus;
			this.refresh();
		},
		del(id) {
			uni.showModal({
				title: '提示',
				content: '确定删除?',
				success: res => {
					if (res.confirm) {
						this.http.request({
							url: '/level-one-server/app/TbGoodsTransit/deleteById?id=' + id,
							success: res => {
								uni.showToast({ title: '删除成功' });
								this.refresh();
							}
						});
					}
				}
			});
		},
		edit(id) {
			uni.navigateTo({ url: '/pages/market/one/merchant/goods/add?id=' + id });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNo = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNo++;
			this.getData();
		}
	},
	onNavigationBarButtonTap() {
		uni.navigateTo({ url: '/pages/market/one/merchant/goods/add' });
	}
};
</script>

<style lang="scss">
page {
	background-color: $pg;
}
</style>
