<template>
	<view>
		<view class="box">
			<view class="top">
				<text class="title">申报记录</text>
			</view>
		</view>
		<u-search v-if="recordItemList.length>0" placeholder="申报人" shape="square" v-model="p.declarePeople" @search="getDeclareList()" @change="getDeclareList"
			:height="80" style="margin: 30rpx;">
		</u-search>
		<view class="card-box">
			<u-radio-group v-model="p.declareNo" placement="column"  @change="onSelect">
				<view class="card" v-for="(recordItem,index) in recordItemList" :key="index">
					<view class="c">
						<view class="item car-num-item">
							<text class="car-num">企业：{{recordItem.customerName}}</text>
						</view>
						<view class="item car-num-item">
							<text class="p1">申报人:</text>
							<text class="p2">{{recordItem.declarePeople}}</text>
						</view>
						<view class="item car-num-item">
							<text class="p1">产品学名:</text>
							<text class="p2">{{recordItem.goodsName}}</text>
						</view>
						<view class="item car-num-item">
							<text class="p1">越南车牌:</text>
							<text class="p2">{{recordItem.carNo}}</text>
						</view>
						<view class="item car-num-item">
							<text class="p1">申报时间:</text>
							<text class="p2">{{recordItem.createTime}}</text>
						</view>

					</view>
					<view class="b">
						<u-radio :key="index" :name="recordItem.declareNo" label="选择">
						</u-radio>
					</view>
				</view>

			</u-radio-group>
		</view>
		<!-- 没有数据时显示noData -->
		<noData v-if="recordItemList.length==0"></noData>
		<view style="text-align: center;margin: 20rpx 0 50rpx 0;color: #007AFF;" @click="toDeclare">前往添加</view>
		<u-loadmore v-if="recordItemList.length>0" style="margin: 30rpx;" :status="status" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				p:{
					pageNo: 1,
					pageSize: 10,
					dataCount: 0,
					declareNo: '1',
				},
				status: 'loadmore',
				recordItemList: [],
			}
		},
		onLoad(options) {
			let declareNo=options.declareNo;
			if(declareNo){
				this.p.declareNo=declareNo;
			}
		},
		methods: {
			toDeclare(){
				this.$common.to('/pages/declare/add');
			},
			onSelect() {
				let select = this.p.declareNo;
				let declare = this.recordItemList.filter(obj => obj.declareNo == select).pop();
				uni.navigateBack({
					delta: 1,
					success: function(resp) {
						uni.$emit('getSelectDeclare', declare) //触发事件
					}
				})
			},
			getDeclareList() {
				if(!this.p.declareNo){
					this.p.declareNo='-1'
				}
				this.$api.getDeclareList(this.p).then(resp => {
					this.status = 'loadmore';
					let recordList = resp.data;
					this.p.dataCount = resp.dataCount;
					this.p.pageNo = resp.pageNo;
					this.recordItemList = recordList;
					if (this.dataCount < this.pageSize * this.pageNo) this.status = 'nomore';
				})
			},
			//------------------------------------------
			//上拉加载更多，分页模拟数据
			onReachBottom() {
				this.status = 'loading';
				if (this.p.dataCount > this.p.pageSize * this.p.pageNo) {
					this.p.pageSize = parseInt(this.p.pageSize) + 3;
					this.getDeclareList();
				} else {
					this.status = 'nomore';
				}
			}
		},
		onShow() {
			this.getDeclareList();
		},
	}
</script>

<style lang="scss">
	.card-box {
		display: flex;
		width: 100%;
		flex-direction: column;

		.card {
			background-color: #fff;
			border-radius: 20rpx;
			margin: 20rpx 20rpx 0 20rpx;
			padding: 30rpx;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;

			.t {
				width: 100%;
				display: flex;
				align-items: center;
				padding-bottom: 30rpx;
				border-bottom: 1rpx solid #f5f5f5;

				.icon {
					width: 40rpx;
					height: 40rpx;
				}

				.title {
					font-size: 30rpx;
					font-weight: bold;
					margin-left: 20rpx;
				}
			}

			.c {
				padding: 15rpx 0 0 0;
				display: flex;
				flex-wrap: wrap;

				//border-bottom: 1rpx solid #f5f5f5;
				.item {
					width: 50%;
					padding: 20rpx 0;
					display: flex;

					.car-num {
						background-color: #edf6ff;
						color: #0080ff;
						font-size: 30rpx;
						padding: 15rpx 0;
						text-align: center;
						width: 100%;
						border-radius: 10rpx;
						font-weight: bold;
					}

					.p1 {
						font-size: 28rpx;
						color: #999;
						flex: 5;
					}

					.p2 {
						font-size: 28rpx;
						color: #191919;
						font-weight: bold;
						margin-left: 20rpx;
						flex: 7;
					}
				}

				.car-num-item {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}

			.b {
				margin-top: 20rpx;
				display: flex;
				width: 100%;
				align-items: center;
				justify-content: space-between;
			}
		}
	}

	.t-btn {
		width: 400rpx;
		margin: 0 auto 80rpx auto;
		height: 88rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx;
		color: #191919;
		font-size: 28rpx;
		background-color: #fff;
		border: 1px solid #eee;
	}

	@import '@/common/common.scss'
</style>
