<template>
	<view class="content">
		<view class="vheight"></view>
		<view class="top flex">
			<image @click="back()" class="top-icon1" src="../../static/img/cb2.png" mode=""></image>
			<image @click="navTo('/pages/user/cbRecord')" class="top-icon2" src="../../static/img/cb1.png" mode=""></image>
		</view>
		<view class="title">充幣</view>
		<view class="type flex" @click="navTo('/pages/transaction/cblist')">
			<view class="type-left">幣種</view>
			<view class="type-right">
				<view class="type-name">{{ info.title }}</view>
				<image class="type-icon" src="../../static/icon/user-back.png" mode=""></image>
			</view>
		</view>
		<view class="main">
			<view class="main-title">充幣網絡</view>
			<view class="main-list">{{ info.czline }}</view>
			<view class="main-title" style="margin-top: 20rpx;">充幣地址</view>
			<view class="erweima">
				<tki-qrcode
					:cid="cid"
					ref="qrcode"
					:val="info.czaddress"
					:size="size"
					:unit="unit"
					:background="background"
					:foreground="foreground"
					:pdground="pdground"
					:iconSize="iconSize"
					:lv="lv"
					:onval="onval"
					:loadMake="loadMake"
					:usingComponents="usingComponents"
					@result="qrR"
				/>
			</view>
			<view class="address">{{ info.czaddress }}</view>
			<view class="btn" @click="copy(info.czaddress)">複製地址</view>
		</view>
		<view class="info">
			<view class="info-item red">最小充值金額：{{ info.czminnum }}{{ info.title }}，小於最小金額的充值將不會上賬且無法退回</view>
			<view class="info-item">請選擇正確的充值通道網絡，否則資產將不可找回</view>
			<view class="info-item">最小充值金額：{{ info.czminnum }}{{ info.title }}，小於最小金額的充值將不會上賬且無法退回</view>
			<view class="info-item">您的充值地址不會經常改變，可以重複充值；如有更改，我們會盡量通過網站公告或郵件通知您</view>
			<view class="info-item">請務必確認電腦及瀏覽器安全，防止信息被篡改或洩露</view>
		</view>
		<view class="sr">
			<view class="sr-title">轉賬金額</view>
			<view class="sr-input"><input placeholder="請輸入轉賬金額" type="number" v-model="num" /></view>
			<view class="sr-title" style="margin-top: 20rpx;">上傳轉賬憑證</view>
			<view class="sr-image">
				<image :src="image" mode="" class="upload-img" @click.stop="imgsub" v-if="image"></image>
				<image src="../../static/img/add.png" class="upload-img" mode="" v-if="!image" @click.stop="imgsub"></image>
			</view>
			<view class="sr-btn" @click="submit()">提交</view>
		</view>
	</view>
</template>

<script>
import { czpage, upload, paycoin } from '@/api/wallet.js';
import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue';
import uniCopy from '@/js_sdk/xb-copy/uni-copy.js';
export default {
	data() {
		return {
			id: '',
			info: '',
			cid: 'cid',
			size: 100,
			unit: '150',
			background: '#FFFFFF',
			foreground: '#000000',
			pdground: '#000000',
			icon: '',
			iconSize: 40,
			lv: 3,
			onval: true,
			loadMake: true,
			usingComponents: true,
			num: '',
			image: '',
			image1: ''
		};
	},
	onLoad(opt) {
		this.id = opt.type;
		this.loadData();
	},
	onShow() {},
	onReachBottom() {},
	onReady() {},
	methods: {
		loadData() {
			czpage({ id: this.id }).then(e => {
				this.info = e.data;
			});
		},
		qrR(res) {
			console.log(res, '123456');
		},
		back() {
			uni.navigateBack();
		},
		navTo(url) {
			uni.navigateTo({
				url
			});
		},
		imgsub() {
			console.log(111);
			upload({
				filename: ''
			}).then(data => {
				console.log('data', data);
				this.image = data[0].src;
				this.image1 = data[0].img;
			});
		},
		copy(item) {
			let obj = this;
			let content = item; //需要复制的内容
			content = typeof content === 'string' ? content : content.toString(); // 复制内容，必须字符串，数字需要转换为字符串
			const result = uniCopy(content);
			if (result === false) {
				uni.showToast({
					title: '不支持'
				});
			} else {
				uni.showToast({
					title: '複製成功',
					icon: 'none'
				});
			}
		},
		submit() {
			console.log(222);
			if (this.num < 0) {
				return this.$api.msg('充值金額不能為0');
			}
			if (!this.image1) {
				return this.$api.msg('請上傳轉款憑證');
			}
			paycoin({ cid: this.id, zznum: this.num, payimg: this.image1, coinname: this.info.title }).then(e => {
				this.num = '';
				this.image = '';
				return this.$api.msg('提交申請成功，請耐心等待審核');
			});
		}
	}
};
</script>

<style lang="scss">
page,
.content {
	min-height: 100%;
	height: auto;
	background: #f5f5f5;
}
.vheigh {
	height: var(--status-bar-height);
}
.top {
	padding: 20rpx 40rpx;
	.top-icon1 {
		width: 52rpx;
		height: 36rpx;
	}
	.top-icon2 {
		width: 48rpx;
		height: 48rpx;
	}
}
.title {
	padding: 20rpx 20rpx 0;
	font-size: 52rpx;
	font-weight: 500;
}
.type {
	margin: 20rpx auto 0;
	width: 690rpx;
	background: #ffffff;
	border-radius: 20rpx;
	padding: 30rpx 20rpx;
	.type-left {
		font-size: 32rpx;
		color: #000;
	}
	.type-right {
		display: flex;
		align-items: center;
		.type-name {
			font-size: 36rpx;
			font-weight: bold;
			color: #fcd535;
			margin-right: 10rpx;
		}
		.type-icon {
			width: 24rpx;
			height: 24rpx;
		}
	}
}
.main {
	margin: 20rpx auto 0;
	width: 690rpx;
	background: #ffffff;
	border-radius: 20rpx;
	padding: 30rpx 20rpx;
	.main-title {
		font-size: 32rpx;
		color: #000;
	}
	.main-list {
		margin-top: 20rpx;
		width: 200rpx;
		height: 70rpx;
		line-height: 70rpx;
		text-align: center;
		border: 2px solid #fcd535;
		border-radius: 10rpx;
		font-size: 28rpx;
		color: #fcd535;
	}
	.erweima {
		margin-top: 40rpx;
		width: 100%;
		display: flex;
		justify-content: center;
	}
	.address {
		margin-top: 20rpx;
		width: 100%;
		text-align: center;
		font-size: 24rpx;
		color: #000;
	}
	.btn {
		width: 200rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		border-radius: 10rpx;
		border: 2px solid #fcd535;
		font-size: 28rpx;
		color: #fcd535;
		margin: 20rpx auto 0;
	}
}
.info {
	margin: 20rpx auto 0;
	width: 690rpx;
	background: #ffffff;
	border-radius: 20rpx;
	padding: 30rpx 20rpx;
	.info-item {
		font-size: 24rpx;
		color: #000;
		margin-bottom: 20rpx;
	}
	.red {
		color: red;
	}
}
.sr {
	margin: 20rpx auto 0;
	width: 690rpx;
	background: #ffffff;
	border-radius: 20rpx;
	padding: 30rpx 20rpx;
	.sr-title {
		font-size: 32rpx;
		color: #000;
	}
	.sr-input {
		display: flex;
		align-items: center;
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		background: #f5f5f5;
		border-radius: 20rpx;
		padding: 0rpx 30rpx;
		input {
			font-size: 28rpx;
			padding-left: 30rpx;
			background: #f5f5f5;
		}
	}
	.sr-image {
		display: flex;
		justify-content: center;
		margin: 20rpx;
		image {
			width: 200rpx;
			height: 200rpx;
		}
	}
	.sr-btn {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 10rpx;
		margin: 20rpx auto 0;
		background: linear-gradient(to left, #eeb80d, #ffe35b);
		font-size: 28rpx;
		color: #000;
	}
}
</style>
