<template>
	<uni-popup ref="popupRef" type="bottom">

		<view class="popup-box">
			<view class="popup-title">
				<text class="title-side"></text>
				<text class="title-name">选择币种</text>
				<text class="title-side iconfont">&#xe621;</text>
			</view>
			<view class="currency-content">
				<view :class="['currency-item' , activeCurrencyVal === undefined ? 'active-currency-item' : '']"
					@click.stop="activeCurrency()">
					<text class="currency-icon all-currency"></text>
					<!-- <image class="currency-icon" :src="item.icon" mode="aspectFit"></image> -->
					<text class="currency-text">全部币种</text>
					<text v-show="activeCurrencyVal === undefined" class="active-currency iconfont">&#xe627;</text>
				</view>
				<block v-for="item in currencyList">
					<view :class="['currency-item' , activeCurrencyVal === item.name ? 'active-currency-item' : '']"
						@click.stop="activeCurrency(item.name)">
						<image class="currency-icon" :src="item.icon" mode="aspectFit"></image>
						<text class="currency-text">{{ item.name }}</text>
						<text v-show="activeCurrencyVal === item.name" class="active-currency iconfont">&#xe627;</text>
					</view>
				</block>
			</view>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		props: {
			currencyVal: {
				type: [String],
				default: undefined
			}
		},
		data() {
			return {
				activeCurrencyVal: undefined,
				currencyList: [{
						icon: require('@/static/images/bi/bi_01.png'),
						name: 'BTC'
					},
					{
						icon: require('@/static/images/bi/bi_02.png'),
						name: 'ETH'
					},
					{
						icon: require('@/static/images/bi/bi_03.png'),
						name: 'LTC'
					},
					{
						icon: require('@/static/images/bi/bi_03.png'),
						name: 'USDT'
					}
				]
			};
		},
		watch: {
			currencyVal: {
				handler(newVal) {
					this.activeCurrencyVal = newVal || undefined
				},
				immediate: true,
				deep: true
			}

		},
		mounted() {
			// this.$refs.popupRef.open()
		},
		methods: {
			open() {
				this.$nextTick(() => {
					this.$refs.popupRef.open();
				})
			},
			activeCurrency(name = undefined) {
				this.activeCurrencyVal = name;
				this.$refs.popupRef.close();
				this.$emit("update:currencyVal", this.activeCurrencyVal);
			}

		}
	}
</script>

<style lang="scss" scoped>
	.popup-box {
		width: 100%;
		background-color: #Fff;
		border-radius: 50rpx 50rpx 0px 0px;

		.popup-title {
			width: 100%;
			height: 113rpx;
			border-radius: 50rpx 50rpx 0px 0px;
			background-color: #F7F7F7 !important;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 40rpx;
			font-weight: 700;

			.title-side {
				flex-shrink: 0;
				font-size: 28rpx;
				width: 40rpx;
				height: 100%;
				line-height: 113rpx;
				color: #666;
				font-weight: 400;
			}
		}

		.currency-content {
			width: 100%;

			.currency-item {
				padding: 0 $pages-padding;
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 80rpx;
				border-bottom: 1rpx solid $border-color;

				.all-currency {
					background-color: #ccc;
					border-radius: 50%;
				}

				.currency-icon {
					width: 36rpx;
					height: 36rpx;
					border-radius: 50%;

				}

				.currency-text {
					flex: 1;
					padding: 0 20rpx;
					font-size: 26rpx;
				}

				.active-currency {
					font-size: 34rpx;
					color: $Theme-Color;
				}
			}

			.active-currency-item {
				color: $Theme-Color;
			}
		}
	}
</style>