<template>
	<view>
		<!-- 头部 -->
		<headContent borderBottom>
			<template #left>
				<reverse-back />
			</template>
		</headContent>
		<view class="content">
			<view class="pages-title">
				地址管理
			</view>
			<view class="currency-type">
				<view class="currency-lable">
					<template v-if="currencyInfo">
						<image class="lable-title" :src="currencyInfo.logo" mode="aspectFit"></image>
						<text class="lable-tag">{{ currencyInfo.name }}</text>
					</template>

				</view>
				<view class="select-currency" @click.stop="selectCurrency">
					<text class="select-text">请选择币种</text>
					<text class="select-icon iconfont">&#xe88e;</text>
				</view>
			</view>
			<view class="add-box">
				<view class="add-type">
					<text @click.stop="type = 'TRC20'"
						:class="['link-btn' , type === 'TRC20' ? 'active-link-btn' : '']">TRC20</text>
					<text @click.stop="type = 'ERC20'"
						:class="['link-btn' , type === 'ERC20' ? 'active-link-btn' : '']">ERC20</text>
				</view>
				<view class="address-text">
					<text class="address-lable">地址</text>
					<view class="address-info">
						<textarea class="address-input" v-model="address" maxlength="100" auto-height
							placeholder-class="placeholder-class" placeholder="请输入地址" />
						<text class="address-moer">粘贴</text>
						<text class="address-link"></text>
						<text class="address-icon iconfont">&#xe606;</text>
					</view>
				</view>
				<view class="address-text">
					<text class="address-lable">钱包备注</text>
					<view class="address-info"><textarea class="address-input" v-model="notes" maxlength="20"
							auto-height placeholder-class="placeholder-class" placeholder="请输入备注" />
					</view>
				</view>
			</view>


			<view class="add-address">
				<view class="add-btn" @click.stop="submitAddress()">
					添加
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		Api_addAddress
	} from "@/api/index.js"
	export default {
		name: 'addAddress',
		data() {
			return {
				currencyInfo: null,
				type: 'ERC20',
				address: '',
				notes: ''
			};
		},
		onLoad() {
			const eventChannel = this.getOpenerEventChannel();

			// 监听setCurrency事件，获取上一页面通过eventChannel传送到当前页面的数据
			eventChannel.on('setCurrency', data => {
				this.currencyInfo = data
			})
		},

		onShow() {},
		mounted() {

		},
		methods: {
			// 选择币种
			selectCurrency() {
				uni.navigateTo({
					url: `/pages/content/select-currency?type=addAddress`
				})
			},
			submitAddress() {

				if (this.currencyInfo && this.address && this.notes) {
					const obj = {
						currency_id: this.currencyInfo.id,
						type: this.type,
						wallet_address: this.address,
						notes: this.notes
					}
					Api_addAddress(obj).then(res => {
						uni.redirectTo({
							url: '/pages/content/address'
						});
					}).catch(err => {

					})
				}





			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		padding: 0 $pages-padding;

		.pages-title {
			height: 120rpx;
			font-size: 60rpx;
			font-weight: bold;
			line-height: 130rpx;
		}

		// <view class="currency-type">
		// 				<view class="currency-lable">
		// 					<image class="lable-title" src="../../static/logo.png" mode="aspectFit"></image>
		// 					<text class="lable-tag">USDT</text>
		// 				</view>
		// 				<view class="select-currency">
		// 					<text class="select-text">请选择币种</text>
		// 					<text class="select-icon iconfont">&#xe88e;</text>
		// 				</view>
		// 			</view>
		.currency-type {
			width: 100%;
			min-height: 100rpx;
			display: flex;
			align-items: stretch;
			justify-content: space-between;
			padding: 20rpx 20rpx 20rpx 30rpx;
			background-color: #f6f6f6;
			margin-bottom: 20rpx;
			border-radius: 10rpx;

			.currency-lable {
				display: flex;
				align-items: center;

				.lable-title {
					width: 50rpx;
					height: 50rpx;
					border-radius: 50%;
				}

				.lable-tag {
					font-size: 30rpx;
					font-weight: 700;
					padding-left: 20rpx;
				}
			}

			.select-currency {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				color: #010101;

				.select-icon {
					font-size: 24rpx;
					color: #010101;
				}
			}
		}


		.add-box {
			width: 100%;
			padding: 30rpx 20rpx;
			border-radius: 10rpx;
			background-color: #f6f6f6;

			.add-type {
				width: 100%;

				.link-btn {
					display: inline-block;
					width: 140rpx;
					height: 72rpx;
					background: #f6f5f3;
					border-radius: 8px;
					text-align: center;
					line-height: 70rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: #666666;
					border-radius: 8rpx;
					border: 1rpx solid #f6f5f3;

					&:nth-child(n + 2) {
						margin-left: 20rpx;
					}
				}

				.active-link-btn {
					background: #ffffff;
					border-color: #05c175;
					color: #FFBA6A;
				}
			}

			.address-text {
				width: 100%;
				padding-top: 40rpx;

				.address-lable {
					font-size: 30rpx;
				}

				.address-info {
					width: 100%;
					height: 80rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					overflow: hidden;
					border-bottom: 1rpx solid $border-color4;

					.address-input {
						height: 100%;
						font-size: 26rpx;
						padding-right: 20rpx;
					}

					.address-moer {
						flex-shrink: 0;
						font-size: 26rpx;
						color: #FFBA6A;
					}

					.address-link {
						width: 1rpx;
						height: 70%;
						background-color: $border-color4;
						margin: 0 16rpx;
					}

					.address-icon {
						flex-shrink: 0;
						font-size: 40rpx;
						color: #000;
						margin-right: 10rpx;
					}

					.placeholder-class {
						// color: #f6f5f3;
					}
				}
			}

			// <view class="address-text">
			// 	<text class="address-lable">钱包备注</text>
			// 	<view class="address-info">
			// 		<input class="address-input" focus placeholder="自动获得焦点" />
			// 	</view>
			// </view>
		}

		.add-address {
			width: 100%;
			height: 160rpx;
			padding: 40rpx 10rpx;

			.add-btn {
				width: 100%;
				height: 100%;
				text-align: center;
				line-height: 80rpx;
				background-color: $Theme-Color;
				font-size: 32rpx;
				color: #fff;
				border-radius: 10rpx;
			}
		}
	}
</style>