<template>
	<view class="content">
		<view class="acountbox">
			<view v-for="(item,index) in form.contractDrafts" :key="index" v-if="!openhe">
				<view class="listitem">
					<text class="lys">承兑人</text>
					<view class="chosbox">
						<uni-data-select v-model="item.acceptor" :localdata="range1" @change="changeacPerson"
							:showas="false" :plname="'搜索承兑人名称'" @search="searchAcceptor" :checklistIn="index"
							@checkin="checkacptIndex"></uni-data-select>
					</view>
				</view>
			</view>
		</view>
		<view v-for="(item,index) in range2" class="text-box" scroll-y="true">
			<text class="text-data">{{index+1}}:</text>
			<text>{{item.acceptorName}}</text>
			<!-- <text @click='deletData(index)'>删除</text> -->
			<view class="item" @click='deletData(index)'>
				<icon :type="'clear'" size="16"></icon>
			</view>
		</view>

		<view class="logininbtn" @click="makeNewAcept">
			<text>确认</text>
		</view>
	</view>
</template>

<script>
	let that
	export default {
		data() {
			return {
				number: '',
				supplierId: '', //供应商id
				id: '',
				range1: [], //下拉框数据
				range2: [], //展示数据
				acceptor: '', //承兑人
				seacept: '',
				acceptorName: '',
				name:'',
				acceptorIds:[],
				form: {
					name: '',
					supplierId: '',
					contractDrafts: [{
						acceptorName: '',
						acceptor: '',

					}, ],
				},
			}
		},
		onLoad(o) {
			that = this
			if (o.id) {
				this.number = o.id
			}
		},
		onShow() {
			this.getAcceptors()
		},
		methods: {
			//模糊查询
			searchAcceptor(e) {
				if(e!=''){
					let value = e
					uni.showLoading()
					uni.$u.http.get(`/api/Acceptor/search?name=${value}`,
					).then((res) => {
						uni.hideLoading()
						this.range1 = res.result
						console.log(this.range1);
							this.range1.forEach((item, index) => {
								this.range1[index].value = index
								this.range1[index].text = item.name
							})
					})
				}else{
					this.getAcceptors()
				}
			},
			changeacPerson(e) {
				// this.acceptor = e
				let r = {
					acceptorName: this.range1[e].name,
					id: this.range1[e].id
				}
				this.range2.push(r)
				console.log(this.range2);
			},
			getAcceptors() {
				uni.showLoading()
				uni.$u.http.get('/api/Acceptor/search?pageSize=-1&status=5',
				).then((res) => {
					uni.hideLoading()
					this.range1 = res.result
					console.log(this.range1);
						this.range1.forEach((item, index) => {
							this.range1[index].value = index
							this.range1[index].text = item.name
						})
					
				})
			},

			checkacptIndex(index) {
				console.log(index);
				this.acptIndex = index
			},
			//删除数据
			deletData(i){
				this.range2.splice(i,1)
			},
			//确定提交
			makeNewAcept() {
				if (this.range2.length == 0) {
					that.$toast("请输入承兑人名称")
					return
				}
				this.range2.forEach(item=>{
				this.acceptorIds.push(item.id)	
				})
				uni.showLoading()
				uni.$u.http.post('/api/SupplierAcceptor', {
					supplierId:this.number,
					acceptorIds:this.acceptorIds
				}, {
					custom: {
						auth: true
					}
				}).then((res) => {
					uni.hideLoading()
					that.$toast("提交成功")
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 500)
				}).catch((err) => {
					uni.hideLoading()
					that.$toast(err.msg)
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	/* uni.scss */
	@import 'uview-ui/theme.scss';

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

	}

	.loginbg {
		background-image: url("https://t39.9026.com/web/uploads/thumbs/mall10000/20220629/e01b927c95ee1f05364f5e456f281388.png");
		height: 559rpx;
		width: 750rpx;
		background-size: 100% 100%;

		// display: flex;
		// align-items: center;
		// justify-content: center;
	}

	.logo {
		margin: 0 auto;
		height: 200rpx;
		width: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.logobox {
		margin: 0 auto;
		margin-top: 212rpx;
		width: 269rpx;
		height: 191rpx;
		// background-color: #F1F1F1;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.checkbox {}

	.business {
		width: 305rpx;
		height: 90rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		text-align: center;
		// background-color: #D8AB5A;
		border-raotherdius: 20rpx;
		color: #FFFFFF;
		margin-top: 57rpx;
	}

	.bnesper {
		background-size: 100%;
		background-image: url("@/static/img/loginbtn4.png");
		padding-top: 10rpx;
		color: #FFF1D8;
		line-height: 90rpx;
	}

	.applyper {
		background-image: url("@/static/img/loginbt1.png");
		background-size: 100%;
		padding-top: 10rpx;
		color: #FFF1D8;
	}

	.actapp {
		background-image: url("@/static/img/loginbtn3.png");
		background-size: 100%;
		color: #D05C39;
	}

	.actbnes {
		background-image: url("@/static/img/loginbt2.png");
		background-size: 100%;
		color: #D05C39;
	}

	.acountbox {
		.inacount {
			display: flex;
			padding: 35rpx 20rpx;
			box-sizing: border-box;
			width: 690rpx;
			margin-top: 40rpx;
			background-color: #F6F6F6;
			border-radius: 20rpx;
			font-size: 30rpx;
			color: #1F242A;

			input {
				width: 360rpx;
			}
		}

		.acoutitle {
			font-weight: 600;
		}

		.checkword {
			padding-left: 20rpx;
			color: #1F242A;
			font-size: 30rpx;
		}
	}

	.otherbt {
		width: 606rpx;
		display: flex;
		justify-content: space-between;
		font-size: 24rpx;
		padding-top: 30rpx;
	}

	.regbt {
		color: $uni-all-theme;
	}

	.logininbtn {
		margin-top: 80rpx;
		width: 690rpx;
		border-radius: 20rpx;
		background: linear-gradient(to right, #FFE1AD, #D8AB5A);
		box-shadow: 0 10rpx 20rpx 1rpx rgba(179, 116, 5, 0.2);
		height: 100rpx;
		text-align: center;
		color: #fff;
		line-height: 100rpx;
	}

	::v-deep .text-box {
		text-align: left !important;
		width: 87%;
		border-bottom: 1px solid #ccc;
		text-align: left !important;
		font-size: 18px;
		margin: 20px 0px 0px;
	}
	.text-box{
		position: relative;
	}
	.item{
		position: absolute;
		right: 8px;
		top: 0px;
		
	}
	.text-data{
		display: inline-block;
		margin-right: 10px;
	}
</style>
