<template>
	<view class="select sys-background-fff page-env-20">
		<view class="title p-30 row-justify-sb">
			<view class="icon"></view>
			<text class="size-30 sys-weight-600">{{title}}</text>
			<view class="icon">
				<uni-icons :animation="animationData" class="dropdown-icon" type="closeempty" size="16"
					color="#666"></uni-icons>
			</view>
		</view>
		<view class="select">
			<scroll-view scroll-y="true" class="scroll-Y select">
				<view id="demo1" class="scroll-view-item" :class="item.id === current?'':'active'"
					v-for="(item,index) in localData" @click="onSelect(index)">
					<text class="size-28">{{item[itemText]}}</text>
				</view>
			</scroll-view>
		</view>
		<EnButton :is_fixed="true" text="确认" @onSubmit="setAffirm(true)"></EnButton>
	</view>
</template>

<script>
	import EnButton from "@/components/en-utils/en-button/en-button.vue";

	export default {
		name: 'peak_chart',
		props: {
			title: {
				type: String,
				default: '选择'
			},
			localData: {
				default: []
			},
			itemKey: {
				type: String,
				default: 'id'
			},
			itemText: {
				type: String,
				default: 'name'
			},
			value: {
				default: ''
			}
		},
		components: {
			EnButton
		},
		data() {
			return {
				current: -1,
				newValue: 0
			};
		},
		watch: {
			'value': function() {
				if (this.current !== this.value) {
					this.current = this.value
				}
			}
		},
		methods: {
			setAffirm(type) {
				this.$emit('input', this.newValue)
				this.$emit('setAffirm', type)
			},
			onSelect(index) {
				this.current = index
				this.newValue = this.localData[index][this.itemKey]
				this.$emit('input', this.newValue)
			}
		}
	}
</script>

<style lang="scss">
	.select {
		height: 800rpx;
		border-radius: 20rpx 20rpx 0 0;
	}

	.icon {
		width: 40rpx;
		text-align: right;
	}

	.scroll-view-item {
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		background: rgba(15, 177, 96, 0.1);
		border-radius: 10rpx;
		color: #0FB160;
		border: 1rpx solid #0FB160;
		margin: 16rpx 30rpx;
	}

	.active {
		border: none;
		color: #333333;
		background: #F7F9FE;
	}
</style>