<template>
	<view>
		<uni-nav-bar color="#fff" height="60" left-icon="back" @clickLeft="back()" @clickRight="rightClick()"
			 right-text="新增商品" :border="false" backgroundColor="#0081ff" title="商品管理" />
		</u-navbar>
		
		<u-list class="list" width="100%" @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in goods" :key="index">
				<view class="item-box">
					<view class="goods-item">
						<u-row>
							<u-col span="5" @click="toDetails(item.id)">
								<u--image :showLoading="true" src="" width="270rpx" height="220rpx"></u--image>
							</u-col>
							<u-col span="7">
								<view class="t1 txt" @click="toDetails(item.id)">
									<text>{{item.goodsName}}</text>
								</view>
								<view class="txt">
									<text v-if="item.grossWeight">{{item.grossWeight}}吨</text>
								</view>
								<view class="txt" v-if="item.tradeAreaName">
									<u-tag style="width: 250rpx" :text="item.tradeAreaName" plain size="mini"></u-tag>
								</view>
								<view class="t4">
									<view class="price">￥{{item.price}}</view>
									<view class="edit" @click="editGoods(item.id)">
										<u-icon color="#fff" name="edit-pen-fill" size="30"></u-icon>
									</view>
									<view class="delete" @click="deleteGoods(item.id)">
										<u-icon color="#fff" name="warning-fill" size="30"></u-icon>
									</view>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</u-list-item>
		</u-list>
		
		
		<view class="tab">
			<!-- <view class="tabBtn" @click="BtnClick(1)">
				<u-icon label="商品列表" size="30" color="#ef732a" labelColor="#ef732a" name="shopping"></u-icon>
			</view> -->
			<view class="tabBtn" @click="BtnClick()">
				<u-icon label="订单列表" size="30" color="#1E90FF" labelColor="#1E90FF" name="order"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadmoreStatus: 'loadmore',
				form: {},
				goods: [],
				orders: [],
				item: {},
				

			}
		},
		onLoad() {
			this.getTransitList()
		},
		methods: {
			// 商品列表
			getTransitList() {
				this.form = {
					isOrders: 0,//是否已被下单[0=未被下单,1=已被下单]
					//enterpriseConfirm: ,//商铺确认情况[0=待确认,1=已确认,2=拒绝]
					goodsStatus: 1,//商品状态(0=下架,1=在售)
				}
				this.http.request({
					url: '/level-one-server/app/TbGoodsTransit/getTransitList',
					data: this.form,
					//method: 'POST',
					success: resp => {
						console.log('resp',resp)
						this.goods = resp.data.data;
						this.goods.forEach((item, index) => {
							if (index === this.goods.length - 1) {
								this.loadmoreStatus = 'nomore'
							} else {
								this.loadmoreStatus = 'loadmore'
							}
						})
					}
				});
			},
			// 删除商品
			deleteGoods(id) {
				console.log('id',id)
				this.http.request({
					url: '/level-one-server/app/TbGoodsTransit/deleteById',
					data: {id : id},
					method: 'POST',
					success: resp => {
						console.log('删除商品',resp)
					}
				});
			},
			// 编辑商品
			editGoods(id) {
				this.$common.to('/pages/goodsManage/oneMarket/editGoods?id='+id)
			},
			scrolltolower() {
				this.getTransitList()
			},
			BtnClick(type) {
				uni.navigateTo({
					url: '/pages/goodsManage/oneMarket/goodsOrders'
				})
			},
			back() {
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
			rightClick() {
				this.$common.to('/pages/goodsManage/oneMarket/addGoods')
			},

			
		}/* ,
		onNavigationBarButtonTap(e) { //导航栏新增商品按钮
			this.$common.to('/pages/goodsManage/oneMarket/addGoods')
		} */
	}
</script>

<style lang="scss">

	.list {
		height: auto;
		border-radius: 10rpx;
		margin: 15rpx;
	}

	.goods-item {
		margin-bottom: 8rpx;
	}

	.item-box {
		height: 230rpx;
		width: 90%;
		padding: 20rpx;
		background-color: #fff;
		border: 1rpx #FFF solid;
		margin: 10rpx 0rpx;
		border-radius: 10rpx;
	}

	.txt {
		/* height: 50rpx; */
		margin-bottom: 20rpx;
	}

	.t1 {
		font-size: 32rpx;
		font-weight: bold;
		word-wrap: break-word;
		position: relative;
		top: 1rpx;
		right: 5rpx;
	}

	.t4 {
		display: flex;
		position: relative;
		bottom: 1rpx;
		right: 5rpx;
	}
	
	.price {
		color: #ef732a;
		width: 400rpx;
		font-weight: bold;
	}

	.edit {
		background-color: #0081ff;
		width: 60rpx;
		height: 60rpx;
		border-radius: 30rpx;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.delete {
		background-color: indianred;
		width: 60rpx;
		height: 60rpx;
		border-radius: 30rpx;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.tab {
		position: fixed;
		bottom: 1rpx;
		width: 100%;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-top: #ffffff 1rpx solid;
		background-color: #ffffff;
	}
	

	.tabBtn {
		width: 35%;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 0 30rpx;
	}
</style>
