<template>
	<!-- 全局下拉框组件 -->
	<view>
		<picker class="picker" @change="bindPickerChange" :range="list" range-key="text">
			<view class="picker-wrapper">
				<view class="">{{text}}</view>
				<uni-icons type="bottom" :size="12" color="#DDDDDD"></uni-icons>
			</view>
		</picker>
	</view>
</template>

<script>
	/**
	 * 全局单列下拉框组件
	 * @description 全局下拉组件选择样式行为统一封装
	 */
	export default {
		name: "ui-picker",
		data() {
			return {
				text: '',
			};
		},
		props: {
			// 文件地址
			value: {
				type: String,
				default: ''
			},
			list: {
				type: Array,
				default: () => {
					return []
				}
			},
		},
		watch: {
			value(val) {
				let res = this.list.find(item => item.value == val);
				return res?.text ?? ''
			}
		},
		mounted() {
			let res = this.list.find(item => item.value == this.value);
			this.text = res?.text ?? ''
		},
		methods: {
			// 选择项目
			bindPickerChange(e) {
				let index = e.detail.value;
				this.text = this.list[index].text;
				this.$emit('onChagne', this.list[index])
			}
		}
	}
</script>

<style lang="scss">
	.picker {
		width: 240rpx;
		height: 60rpx;
		margin-left: 18rpx;
		font-size: 24rpx;
		border: #DDDDDD 1rpx solid;
		border-radius: 8rpx;
	}

	.picker-wrapper {
		display: flex;
		align-items: center;
		justify-content: space-between;

		height: 60rpx;
		padding: 0 24rpx;

		color: #999999;
		line-height: 1;

	}
</style>
