<!-- 选择合同 -->
<template>
	<view class="container-wrap">
		<uni-nav-bar title="选择合同" :status-bar="true" background-color="#3F92F9" color="#FFF">
			<view slot="left">
				<u-icon name="account-fill" color="#FFF" size="35"></u-icon>
				<span style="padding: 0 5rpx;color: #FFFFFF;">{{ userInfo.name }}</span>
			</view>
			<view slot="right" @tap="$utils.back()">
				<span style="color: #FFFFFF;">返回</span>
			</view>
		</uni-nav-bar>
		<view class="container">
			<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="loadMore()">
				<view class="list">
					<view class="item" v-for="(item, index) in data" :key="index" @tap="chooseContract(item)">
						<view class="row">
							<view class="col">
								<view class="label">供应商：</view>
								<view class="value">{{ item.supplierName }}</view>
							</view>
						</view>
						<view class="row">
							<view class="col">
								<view class="label">合同编号：</view>
								<view class="value">{{ item.purchaseBillNo }}</view>
							</view>
							<view class="col" style="flex: 0;width: 200rpx;">
								<view class="label" style="width: 100rpx;">批次：</view>
								<view class="value">{{ item.batchNo.split('-')[item.batchNo.split('-').length - 1] }}</view>
							</view>
						</view>
						<view class="row">
							<view class="col">
								<view class="label">发货时间：</view>
								<view class="value">{{ item.shipTime }}</view>
							</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="loadStatus" @loadmore="loadMore" />
			</scroll-view>
		</view>
	</view>
</template>

<script>
	// #ifdef APP-PLUS
	// #endif
	export default {
		data() {
			return {
				materialCode: '',
				isReading: false,
				data: []
			};
		},
		methods: {
			/* 选择合同 */
			chooseContract(item) {
				uni.$emit('chooseContract', {
					purchaseBillNo: item.purchaseBillNo,
					batchNo: item.batchNo
				})
				this.$utils.back()
			},
			getList() {
				console.log(this.materialCode)
				this.$http.GetContractBatchPageList({
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
					materialCode: this.materialCode
				}).then(res => {
					console.log(res)
					if (res.code === 0) {
						this.data.push(...res.result.list)
						if(res.result.isLastPage) {
							this.loadStatus = 'nomore'
						}else {
							this.loadStatus = 'loadmore'
						}
					}
				})
			}
		},
		onLoad(option) {
			this.materialCode = option.materialCode
			this.getList()
		},
		onUnload() {}
	}
</script>

<style lang="scss" scoped>
	.container-wrap {
		overflow: hidden;

		.container {
			padding: 10rpx;
			height: calc(100vh - var(--status-bar-height) - 44px);
			overflow: auto;

			.info {
				padding: 10rpx 20rpx;
				font-size: 32rpx;
			}

			.list {
				.item {
					padding: 20rpx;
					margin-bottom: 10rpx;
					background-color: #FFFFFF;
					border: 1rpx solid rgba(215, 215, 215, 1);
					border-radius: 10rpx;

					.row {
						&.border {
							border-bottom: 1px solid rgba(215, 215, 215, 1);
						}
					}
				}
			}
		}
	}
</style>
