<template>
	<view class="content">
		<view class="container">
			<view class="header-">
				<view class="" @click="goback">
					<u-icon name="arrow-left" color="#fff" size="20"></u-icon>
				</view>
				<view class="">

				</view>
				<view class=""></view>
			</view>
			<view class="input-bs">
				<view class="input-k">
					<u-icon name="search" size="20"></u-icon>
					<input type="text" @input="searchBank" v-model="inputText" placeholder="请输入" />
				</view>
				<view class="lv-color" @click="cancel()">取消</view>
			</view>
			<view class="box-" v-for="(item,index) in bankList" :key="index" @click="selectBank(item,index)">

				<view class="">
					{{item.bankBranchName}}
				</view>
				<view class="qu" v-if="boxindex != index"></view>
				<view class="xqu" v-if="boxindex == index">
					<u-icon name="checkmark" color="#fff" size="14"></u-icon>
				</view>
			</view>
			<view class="bottom-an" @click="chooseOk()">
				<view class="anniu">
					确定
				</view>
			</view>

		</view>

	</view>
</template>

<script>
	import request from '../../utils/request.js'
	import headers from '../../components/header/headers.vue'

	export default {
		data() {
			return {
				page: 1,
				totalPage: 0,
				boxindex: null,
				bankList: [],
				titles: "默认",
				msg: "1",
				dataList: [],
				show: false,
				status: 'loading',
				inputText: "",
				selectData: {},
				bankCode: null,
				code: null
			}
		},
		onLoad(option) {
			console.log(option);
			this.code = option.code
			this.bankCode = option.bankCode
		},
		onShow() {
			this.boxindex = null
			this.selectData = {}
			this.getBankBranch()
		},
		components: {
			headers
		},
		methods: {
			async getBankBranch() {
				let res = await request({
					url: 'app/drop/getBankBranch?bankCode=' + this.bankCode + "&code=" + this.code,
					method: 'get'
				})
				if (res.code == 0) {
					this.dataList = res.data
					this.bankList = res.data
				}
			},
			chooseOk() {
				console.log(this.boxindex);
				if (this.boxindex == null) {
					uni.showToast({
						title: "请选择支行",
						icon: 'error'
					})
					return
				}
				uni.$emit("chooseBranchZcy", this.selectData)
				uni.navigateBack()
			},
			selectBank(data, idx) {
				this.boxindex = idx
				this.selectData = data
			},
			cancel() {
				this.bankList = this.dataList
				this.inputText = ""

			},
			searchBank() {
				this.bankList = this.dataList.filter(it =>
					it.bankBranchName.indexOf(this.inputText) >= 0
				)
			},
			goback() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #fff;
		height: 100vh;
	}

	.container {
		width: 100%;
		background: #fff;
		box-sizing: border-box;
		padding-top: 88px;
	}

	.header- {
		width: 100%;
		height: 88px;
		background: #E4612E;
		position: fixed;
		top: 0px;
		display: flex;
		box-sizing: border-box;
		padding: 15px;

		padding-top: 50px;
		justify-content: space-between;
		color: white;

	}

	.input-bs {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-around;
		margin: 10px auto;

	}

	.lv-color {
		font-size: 14px;
		color: #E4612E;
	}

	.input-k {
		width: 85%;
		height: 30px;

		border-radius: 5px;
		box-sizing: border-box;
		padding: 0px 15px;
		display: flex;
		align-items: center;
		border: 1px solid #d9d9d9;

		input {
			width: 100%;
		}
	}

	.box- {
		width: 100%;
		box-sizing: border-box;
		padding: 15px;
		display: flex;
		justify-content: space-between;
	}

	.qu {
		width: 15px;
		height: 15px;
		border: 1px solid #d9d9d9;
		border-radius: 50%;
	}

	.xqu {
		width: 15px;
		height: 15px;
		border: 1px solid #E4612E;
		border-radius: 50%;
		background: #E4612E;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
	}

	.bottom-an {
		width: 100%;
		height: 50px;
		background: #fff;
		position: fixed;
		bottom: 0px;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.anniu {
		width: 95%;
		height: 35px;
		background: #E4612E;
		border-radius: 4px;
		display: flex;
		align-items: center;
		justify-content: center;
		color: white;

	}
</style>
