<template>
	<view class="container">
		<u-navbar leftIconColor="#fff" titleStyle="color:#fff;fontSize:36rpx;" :autoBack="true" bgColor="#2C6FF3"
			:placeholder="true" title="商品建模"></u-navbar>
		<view class="content">
			<view class="search">
				<u-search animation placeholder="商品搜索" :clearabled="false" v-model="keyword" :showAction="false"
					@search="search"></u-search>
				<view class="scan-icon" @click="scan">
					<u-icon name="scan" size="22" color="#909399"></u-icon>
				</view>
			</view>
			<view class="tab-list">
				<u-tabs :list="tabList" :scrollable="false" :current="pos" @click="tabClick" lineColor="#2C6FF3">
				</u-tabs>
			</view>
			<view class="list">
				<u-list @scrolltolower="scrolltolower" :height="fullHeight" v-if="commList.length>0">
					<u-list-item class="list-item" v-for="(item, index) in commList" :key="item.id"
						@click.native="goDetail(item)">
						<view class="comm-item">
							<view class="image">
								<u--image width="130rpx" height="130rpx" :src="item.cover" mode="widthFix"
									:lazy-load="true"></u--image>
							</view>
							<view class="item-content">
								<view>
									{{item.goodsName}}
								</view>
								<view>
									{{item.brandName}}
								</view>
								<view>
									{{item.createTime}}
								</view>
								<view class="failedMsg" v-if="item.status==-1">
									驳回原因：{{item.failedMsg}}
								</view>
							</view>
							<view class="tag">
								<u-tag text="已通过" plain size="mini" type="success" v-if="item.status==1"></u-tag>
								<u-tag text="已驳回" plain size="mini" type="error" v-if="item.status==-1"></u-tag>
								<u-tag text="审核中" plain size="mini" type="warning" v-if="item.status==0"></u-tag>
							</view>
						</view>

					</u-list-item>
					<u-loadmore :status="status" v-if="commList.length>=1" />
				</u-list>
				<view class="empty" v-else>
					<u-empty></u-empty>
				</view>
			</view>
		</view>
		<view class="btn safe-bottom">
			<xbutton size="large" @click="$tab.navigateTo('/pages/commodity/addCom')">新品建模</xbutton>
		</view>

	</view>
</template>

<script>
	import {
		goodsPage
	} from "@/api/commodity/goodsMode.js"
	export default {
		data() {
			return {
				keyword: '',
				tabList: [{
						name: '已通过',
						id: 1
					},
					{
						name: '审核中',
						id: 0
					},
					{
						name: '已驳回',
						id: -1
					}
				],

				page: 1,
				size: 10,
				keywords: '',

				pos: 1,
				current: 0,
				status: 'loadmore',
				commList: [],
				fullHeight: 0
			}
		},
		onLoad() {
			let _this = this;
			const query = uni.createSelectorQuery().in(this);
			query.select(".list").boundingClientRect((data) => {
				uni.getSystemInfo({
					success(res) {
						_this.fullHeight = res.windowHeight-218 + 'px';
					},
				});
			}).exec();
			this.getList()
		},
		methods: {
			tabClick(e) {
				console.log(e)
				this.pos = e.index;
				this.current = e.id;
				this.reset();
				this.getList();
			},

			reset() {
				this.status == 'loadmore'
				this.page = 1;
				this.size = 10;
				this.commList = [];
			},

			getList() {
				goodsPage({
					page: {
						current: this.page,
						size: this.size
					},
					keywords: this.keyword,
					status: this.current
				}).then(res => {
					let data = res.data.records;
					if (data.length < 10) {
						this.status = "nomore"
					} else {
						this.status = "loadmore"
					}
					this.commList = this.commList.concat(data)
				})
			},

			scrolltolower() {
				if (this.status == 'nomore') return
				this.page++
				this.getList()
			},

			search(val) {
				this.reset()
				this.getList()
			},

			scan() {
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			},

			// 详情
			goDetail(e) {
				this.$tab.navigateTo('/pages/commodity/addCom?id=' + e.id)
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		height: 100% !important;
	}

	.container {
		height: 100% !important;

		.content {
			// padding-bottom: 88rpx;

			.search {
				padding: 24rpx 24rpx;
				background-color: #fff;
				position: relative;

				.scan-icon {
					position: absolute;
					right: 36rpx;
					top: 50%;
					transform: translateY(-50%);
					z-index: 2;
				}
			}

			.tab-list {
				width: 100%;
				padding: 0 24rpx;
				background-color: #fff;
				margin-bottosearchm: 12rpx;
			}

			.empty {
				margin: 40% auto 0;
			}

			.list {
				width: 100%;
				padding: 0 24rpx;
				margin-top: 16rpx;

				.comm-item {
					display: flex;
					flex-direction: row;
					justify-content: flex-start;
					align-items: center;
					background-color: #fff;
					margin-bottom: 12rpx;
					border-radius: 12rpx;
					box-sizing: border-box;
					padding: 12rpx;
					position: relative;

					.image {
						width: 130rpx;
						height: 130rpx;
					}

					.item-content {
						padding-left: 24rpx;
						color: #999;

						>view:nth-child(1) {
							font-size: 28rpx;
							font-weight: bold;
							color: #333;

						}

						>view:nth-child(2) {
							font-size: 24rpx;
							padding: 12rpx 0;
						}

						>view:nth-child(3) {
							font-size: 24rpx;
						}
						
						.failedMsg{
							color: red;
							font-size: 24rpx;
							line-height: 30rpx;
							margin-top: 10rpx;
						}
					}

					.tag {
						position: absolute;
						right: 12rpx;
						top: 12rpx;
					}
				}
			}
		}

		.btn {
			width: 100%;
			position: fixed;
			left: 0;
			bottom: 24rpx;
			padding: 0 24rpx;
		}
	}
</style>
