<template>
	<view class="warp">
		<view class="content1">
			<u-search placeholder="输入合同编号" :show-action="false" v-model="inputKeyword"></u-search>
		</view>
		<view class="content2" v-if="!inputKeyword&&newSelectList.length!=0">
			<view class="title" v-if="">最新选择</view>
			<view class="item-contnet">
				<view class="item-list" v-for="(item,index) in newSelectList" :key="index" @click="confirm(item)">
					{{item.contractNo}}
				</view>
			</view>
		</view>
		<view class="content2" v-if="!inputKeyword&&moreList.length!=0 ">
			<view class="title" v-if="">更多合同</view>
			<view class="item-contnet">
				<view class="item-list" v-for="(item,index) in moreList" :key="index" @click="confirm(item)">
					{{item.contractNo}}
				</view>
			</view>
		</view>
		<view class="content3" v-if="inputKeyword">
			<view class="search-item-list" v-for="(item,index) in filterNewList" :key="index" @click="confirm(item)">
				{{item.contractNo}}
			</view>
		</view>
	</view>
</template>

<script>
	 import helper from '@/common/helper.js'; 
	export default {
		data() {
			return {
				inputKeyword: '',
				newList: [],
				newSelectList:[],
				filterNewList: [],
				moreList:[],
				compId: ''
			}
		},
		onShow() {},
		onLoad(options) {debugger
			this.compId = options.compId
			console.log(helper.selectContractNo); 
			this.getContractNoList()
		},
		watch: {
			inputKeyword(val) {
				this.filterNewList = this.newList.filter(function(item) {
					if (item.contractNo.indexOf(val) > -1&&item.flag==7) {
						return item
					}
				})
			}
		},
		methods: {
			confirm(item){
				let _list = uni.setStorageSync('erpContractNoList');
				if(_list.length<=20){
					_list.unshift()
				}else{
					_list.unshift().pop()
				}
				uni.setStorageSync('erpContractNoList', _list);
				uni.navigateBack({})
			},
			makeMoreList(){
				let _data = this.newList
				for(let i=0;i<_data;i++){
					if(_data[i].status=='执行中'&&_data[i].flag==6){
						this.moreList.push(_data[i])
					}
				}
			},
			getContractNoList() {
				this.$api.doRequest('get', '/warehouseBaseInfo/selectContractNoList', {
					compId: this.compId,
					flag: 5,
				}).then(res => {
					if (res.data.code == 200) {
						console.log(res)
						this.newList = res.data.data
						this.makeMoreList()
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content1 {
		background: white;
		padding: 20rpx;
		border-radius: 0 0 20rpx 20rpx;
	}

	.content2 {
		background: white;
		margin-top: 20rpx;
		padding: 20rpx;
		border-radius: 20rpx 20rpx 0 0;

		.title {
			font-size: 28rpx;
			font-weight: 400;
			color: #AFB3BF;
		}

		.item-contnet {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
		}

		.item-list {
			width: 45%;
			background: #F5F6F9;
			margin: 20rpx 0;
			padding: 10rpx 15rpx;
			border-radius: 30rpx;
			text-align: center;
		}
	}

	.content3 {
		height: calc(100vh - 192rpx);
		background: white;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.search-item-list {
		margin: 20rpx;
		border-bottom: 1px solid #EEEEEE;
		padding-bottom: 20rpx;
	}
</style>
