<template>
	<view class="">
		<!-- 头部 -->
		<headContent>&#xe642;
			<template #left>
				<reverse-back />
			</template>
			<template #content>
				<view class="haed-title">
					选择币种
				</view>
			</template>
			<template #right>
				<view @click.stop="lookRecord()" class="head-record iconfont">&#xe642;</view>
			</template>
		</headContent>

		<view class="currency-box">
			<block v-for="(item , index) in currencyList" :key="`currency_${index}`">
				<view class="currency-item" @click.stop="topUp(item)">
					<image class="currency-icon" :src="item.logo" mode="aspectFit"></image>
					<text class="currency-name">{{ item.name }}</text>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	import reverseBack from "@/components/headModules/reverse-back.vue"
	import {
		Api_getQuotationNew,
		Api_getBiTypeList,
		Api_getFlashRecord,
		Api_getSubmit
	} from "@/api/index.js"
	export default {
		name: 'selectCurrency',
		components: {
			reverseBack
		},
		data() {
			return {
				pageType: '',
				currencyList: []
			};
		},
		onLoad(opt) {
			this.pageType = opt?.type;
			this.getBiTypeList();
		},

		methods: {
			getBiTypeList() {
				uni.showLoading()
				Api_getQuotationNew().then(res => {
					this.currencyList = res || [];
				}).catch(err => {}).finally(() => {
					uni.hideLoading();
				})
			},
			// pages/content/top-up
			topUp(item) {
				let path = ''
				switch (this.pageType) {
					case 'addAddress':
						path = 'pages/content/add-address';
						break;
					case 'address':
						path = 'pages/content/address';
						break;
					case 'recharge':
						path = 'pages/content/top-up';
						break;






				}




				// let path = `/pages/content/top-up?key=${`bi_${time}`}`
				// 'pages/content/top-up'
				const pages = getCurrentPages()
				if (pages.length >= 2 && pages[pages.length - 2].route === path) {
					let prevPage = pages[pages.length - 2];
					// pages
					prevPage.$vm.currencyInfo = item;
					uni.navigateBack({
						delta: 1
					});
				} else {
					const time = new Date().getTime();
					let key = {};
					key[`bi_${time}`] = item
					this.$setStorageSync('select', key)
					path = `/${path}?key=${`bi_${time}`}`
					uni.navigateTo({
						url: path
					});
				}


				// uni.navigateTo({
				// 	url: path
				// });
			},
			// 查看充值记录
			lookRecord() {
				uni.navigateTo({
					url: '/pages/content/charge-record'
				})
			}

		}
	}
</script>
<style>
	page {
		background-color: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.head-record {
		font-size: 60rpx;
	}

	.currency-box {
		width: 100%;
		padding: 40rpx $pages-padding 0;

		.currency-item {
			width: 100%;
			display: flex;
			align-items: center;
			padding: 30rpx 0;

			.currency-icon {
				width: 46rpx;
				height: 46rpx;
				flex-shrink: 0;
			}

			.currency-name {
				font-size: 28rpx;
				padding-left: 7px;
				font-weight: 700;
			}
		}

		// <view class="currency-box">
		// 	<block v-for="(item , index) in currencyList" :key="`currency_${index}`">
		// 		<view class="currency-item">
		// 			<image class="currency-icon" :src="item.icon" mode="aspectFit"></image>
		// 			<text class="currency-name">{{ item.name }}</text>
		// 		</view>
		// 	</block>
		// </view>
	}
</style>