<template>
	<view class="content">
		<view class="top1 flex">
			<image @click="back()" class="top-icon1" src="../../static/img/cb2.png" mode=""></image>
			<image @click="navTo('/pages/user/myrg')" class="top-icon2" src="../../static/img/cb1.png" mode=""></image>
		</view>
		<view class="main" v-if="info">
			<view class="main-top flex">
				<view class="main-icon"><image :src="info.imgs" mode=""></image></view>
				<view class="main-top-info">
					<view class="main-title clamp">{{ info.name }}</view>
					<view class="main-btype">{{ $t('rg.rgbz') }}：{{ info.coinname.toLocaleUpperCase() }}</view>
					<view class="main-time">{{ $t('rg.kssj') }}：{{ info.starttime }}</view>
					<view class="main-time">{{ $t('rg.jssj') }}：{{ info.finishtime }}</view>
				</view>
			</view>
			<view class="xian"><u-line-progress active-color="#2979ff" :percent="((info.num * 1 - info.sellnum * 1) / (info.num * 1)) * 100"></u-line-progress></view>
			<view class="main-bottom flex">
				<view class="main-bottom-item first">
					<view class="main-bottom-item-font">{{ $t('rg.fxzl') }}</view>
					<view class="main-bottom-item-num">{{ info.num }}</view>
				</view>
				<view class="main-bottom-item">
					<view class="main-bottom-item-font">{{ $t('rg.rgdj') }}</view>
					<view class="main-bottom-item-num">{{ info.price }} {{ info.buycoin.toLocaleUpperCase() }}</view>
				</view>
				<view class="main-bottom-item">
					<view class="main-bottom-item-font">{{ $t('rg.scsj') }}</view>
					<view class="main-bottom-item-num">{{ info.lockday }}{{ $t('rg.t') }}</view>
				</view>
			</view>
			<view class="main-bottom flex">
				<view class="main-bottom-item first">
					<view class="main-bottom-item-font">{{ $t('rg.cysl') }}</view>
					<view class="main-bottom-item-num">{{ info.sellnum }}</view>
				</view>
				<view class="main-bottom-item">
					<view class="main-bottom-item-font">{{ $t('rg.rgsx') }}</view>
					<view class="main-bottom-item-num">{{ info.allmax }}</view>
				</view>
				<view class="main-bottom-item">
					<view class="main-bottom-item-font">{{ $t('rg.dczd') }}</view>
					<view class="main-bottom-item-num">{{ info.min }}</view>
				</view>
			</view>
			<view class="sr-input flex">
				<input :placeholder="$t('rg.qsr')" type="number" v-model="num" />
				<view class="main-type">{{ info.coinname.toLocaleUpperCase() }}</view>
			</view>
			<view class="sr-input flex">
				<view class="main-type">{{ $t('rg.xyzf') }}：{{ num != '' ? info.price * 1 * num : '0.00' }}</view>
				<view class="main-type">{{ info.buycoin.toLocaleUpperCase() }}</view>
			</view>
			<view class="font">{{ $t('rg.ky') }}{{ info.buycoin.toLocaleUpperCase() }}: {{ money }}</view>
			<view class="sr-btn" @click="submit()">{{ $t('rg.ljcy') }}</view>
			<view class="info">
				<view class="info-item">
					{{ $t('rg.xmsm') }}：
					<view v-html="info.content"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { details, upbuynum } from '@/api/wallet.js';
export default {
	data() {
		return {
			id: '',
			info: '',
			money: '',
			num: ''
		};
	},
	onLoad(opt) {
		this.id = opt.id;
		this.loadData();
	},
	onShow() {},
	methods: {
		back() {
			uni.navigateBack();
		},
		navTo(url) {
			uni.navigateTo({
				url
			});
		},
		loadData() {
			details({ id: this.id }).then(({ data }) => {
				this.info = data.info;
				this.money = data.money;
			});
		},
		submit() {
			if (this.num * 1 <= 0) {
				return this.$api.msg(this.$t('rg.rgsl'));
			}
			if (this.num * 1 > this.money * 1) {
				return this.$api.msg(this.$t('rg.yebz'));
			}
			upbuynum({ pid: this.id, num: this.num }).then(e => {
				this.loadData();
				this.num = '';
				return this.$api.msg(this.$t('rg.rgcg'));
			});
		}
	}
};
</script>

<style lang="scss">
page,
.content {
	min-height: 100%;
	height: auto;
	background: #f5f5f5;
}
.top1 {
	padding: 20rpx 40rpx;
	.top-icon1 {
		width: 52rpx;
		height: 36rpx;
	}
	.top-icon2 {
		width: 48rpx;
		height: 48rpx;
	}
}
.main {
	background: #fff;
	margin-top: 20rpx;
	padding: 16rpx 20rpx 24rpx;
	.main-top {
		justify-content: flex-start;
		align-items: center;
		.main-icon {
			width: 250rpx;
			height: 250rpx;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.main-top-info {
			margin-left: 10rpx;
			.main-title {
				font-size: 32rpx;
				font-weight: bold;
				color: #707a8a;
			}
			.main-btype {
				margin-top: 6rpx;
				font-size: 28rpx;
				color: #707a8a;
			}
			.main-time {
				margin-top: 6rpx;
				font-size: 28rpx;
				color: #707a8a;
			}
		}
	}
	.xian {
		margin-top: 20rpx;
	}
	.main-bottom {
		padding: 28rpx 16rpx;
		.first {
			align-items: flex-start !important;
		}
		.main-bottom-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			.main-bottom-item-font {
				font-size: 28rpx;
				color: #707a8a;
			}
			.main-bottom-item-num {
				margin-top: 10rpx;
				font-size: 28rpx;
				color: #707a8a;
			}
		}
	}
	.sr-input {
		margin-top: 20rpx;
		display: flex;
		align-items: center;
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		background: #f5f5f5;
		border-radius: 20rpx;
		padding: 0rpx 30rpx;
		input {
			width: 292rpx;
			font-size: 28rpx;
			background: #f5f5f5;
		}
		.main-type {
			font-size: 28rpx;
			color: #707a8a;
			margin-right: 20rpx;
		}
	}
	.font {
		margin-top: 20rpx;
		padding-left: 30rpx;
		font-size: 28rpx;
		color: #707a8a;
	}
	.sr-btn {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 10rpx;
		margin: 40rpx auto 0;
		background: linear-gradient(to left, #eeb80d, #ffe35b);
		font-size: 28rpx;
		color: #000;
	}
	.info {
		margin: 40rpx auto 0;
		width: 690rpx;
		background: #ffffff;
		border-radius: 20rpx;
		padding: 30rpx 20rpx;
		.info-item {
			font-size: 28rpx;
			color: #000;
			margin-bottom: 20rpx;
		}
	}
}
</style>
