<template>
	<view class="container">
		<view class="imageBox">
			<image :src="'https://www.bscnice.com'+info.image" ></image>
		</view>
		<view class="name">{{info.name}}</view>
		<view class="info flex">
			<view class="price">{{ $t("details.价格") }}：<text class="tip">{{info.price * 1}}NUSD</text></view>
			<view class="price">{{ $t("details.总收益") }}：<text class="tip">{{info.send_all * 1}}NUSD</text></view>
		</view>
		<view class="partition"></view>
		<view class="detailes" @click="navTo('/pages/index/detailsTpl')">
			<view class="flex detaTpl">
				<view class="flex_item tpl">
					<view class="tip"></view>
					<view class="nameTip">{{ $t("details.当前运作矿机") }}</view>
				</view>
				<view class="tpls">{{ $t("details.今日挖矿收益") }}</view>
			</view>
			<view class="flex detaTip">
				<view class="text">{{info.name}}</view>
				<view class="num">{{info.day_send * 1}}NUSD</view>
			</view>
			<view class="go"><u-icon name="arrow-right" size="14" color="#fff"></u-icon></view>
		</view>
		<view class="goBuy" :class="{ submitNo: !payOn }" @click="payOn ? buyOrder() : ''">{{ $t("details.立即购买") }}</view>
	</view>
</template>
<script>
	import { detail,order } from '@/api/index.js';
	import {mapState,mapActions,mapMutations} from "vuex";
	export default {
		data () {
			return {
				id:"",
				info:'',
				payOn:true
			}
		},
		onLoad (option) {
			this.id = option.id
			uni.setNavigationBarTitle({
				title: this.$t('details.矿机详情'),
			});
			this.loadDate()
		},
		onShow () {
			
		},
		computed: {
			...mapState({
				langList: "langList",
				lang: "lang",
			}),
		},
		methods: {
			buyOrder(){
				let obj = this
				obj.payOn = false
				ethereum.request({
					method: 'eth_requestAccounts'
				}).then((account) => {
					const PKR_ORDER = 'PKR_ORDER' + (new Date()).getTime();
					ethereum.request({
						"method": "personal_sign",
						"params": [
							PKR_ORDER,
							account[0]
						]
					}).then((res) => {
						obj.buyIndex(res,PKR_ORDER);
					});
				});
			},
			buyIndex(sign,msg){
				let obj = this
				order({
					sign,
					msg,
					id:obj.id,
				}).then(function(res){
					if(res.code == 0){
						obj.payOn = true
						uni.showToast({
							title: res.msg,
							icon: "error",
							duration:3000
						});
					}else{
						obj.payOn = true
						uni.showToast({
							title:obj.$t('details.开通完成'),
							icon: "success",
						});
						// setTimeout(function () {
						// 	obj.$router.go(0)
						// }, 1000);
					}
				}).catch(e => {
					obj.payOn = true
					console.log(e,11111);
				});
			},
			loadDate(){
				let obj = this
				detail(obj.id).then(function(res){
					if(res.code == 1){
						obj.info = res.data.info
					}else{
						uni.showToast({
							title: res.msg,
							duration: 1500,
							mask: false,
							icon: 'none',
						})
					}
				})
			},
			navTo(url){
				uni.navigateTo({
					url:url
				})
			},
		},
	}
</script>

<style lang="scss">
	page {
		width: 100%;
	}
	.container {
		width: 100%;
		padding: 30rpx 30rpx;
		color: #fff;
		padding-bottom: 150rpx;
	}
	.imageBox{
		width: 100%;
		height: 690rpx;
		background: url('../../static/img/img27.png') no-repeat;
		background-size: 100% 100%;
		text-align: center;
		padding-top: 70rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.name{
		font-weight: bold;
		font-size: 36rpx;
		color: #FFFFFF;
		padding: 40rpx 0rpx;
	}
	.info{
		margin-bottom: 45rpx;
		.price{
			font-weight: bold;
			font-size: 28rpx;
			.tip{
				font-weight: bold;
				font-size: 37rpx;
				color: #E83F30;
				background: linear-gradient(258deg, #FFF0CF 0%, #CBA16B 30.0048828125%, #FCE9CF 67.67578125%, #C29963 100%);
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
			}
		}
	}
	.partition{
		height: 15rpx;
		background: #F8F6F6;
		opacity: 0.11;
		position: absolute;
		width: 100%;
		left: 0;
	}
	.detailes{
		margin-top: 100rpx;
		background: url('../../static/img/img26.png') no-repeat;
		width: 100%;
		height: 158rpx;
		background-size: 100% 100%;
		padding: 37rpx 26rpx;
		padding-right: 70rpx;
		position: relative;
		.detaTpl{
			.tpl{
				.tip{
					width: 8rpx;
					height: 30rpx;
					background: linear-gradient(80deg, #FFF0CF, #CBA16B, #FCE9CF, #C29963);
					border-radius: 4rpx;
				}
				.nameTip{
					font-weight: 500;
					font-size: 23rpx;
					color: #999999;
					padding-left: 15rpx;
				}
			}
			.tpls{
				font-weight: 500;
				font-size: 24rpx;
				color: #999999;
			}
		}
		.detaTip{
			padding-top: 10rpx;
			.text{
				font-weight: bold;
				font-size: 32rpx;
				color: #999999;
				line-height: 55rpx;
				background: linear-gradient(258deg, #FFF0CF 0%, #CBA16B 30.0048828125%, #FCE9CF 67.67578125%, #C29963 100%);
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
			}
			.num{
				font-weight: bold;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
		.go{
			position: absolute;
			top: 43%;
			right: 20rpx;
		}
	}
	.goBuy{
		position: fixed;
		bottom: 0;
		width: 100%;
		left: 0;
		font-weight: 500;
		font-size: 36rpx;
		color: #31190B;
		background: linear-gradient(258deg, #FFF0CF, #CBA16B, #FCE9CF, #C29963);
		height: 98rpx;
		line-height: 98rpx;
		text-align: center;
		padding-bottom: env(safe-area-inset-bottom);
	}
	.submitNo {
		background: #999999 !important;
		color: #fff !important;
	}
</style>