<template>
	<view class="center">
		<view class="top"><image src="" mode=""></image></view>
		<view class="name-box">
			<view class="price-box">
				兑换价：
				<text class="price">9800</text>
				<text class="unit">拼团积分</text>
				<text class="yuan">￥229</text>
			</view>
			<view class="name clamp">拼购IPFS服务器 紫盘 4TB 移动监控服务器</view>
		</view>
		<view class="tip-box">
			<view class="tip-titele">兑换须知</view>
			<view class="tip-main">兑换说明详细介绍兑换说明详细介绍兑换兑换说明详细介绍兑换说明详细介绍兑换说明详细介绍</view>
		</view>
		<view class="detail">
			<view class="detail-title">
				商品详情
			</view>
			<view class="systom">
				
			</view>
		</view>
		<view class="btn" @click="buy()">
			立即兑换
		</view>
	</view>
</template>
<script>
import { miningDateils, buyMining } from '@/api/market.js';
import uniNumberBox from '@/components/uni-number-box.vue';
export default {
	components: {
		uniNumberBox
	},
	data() {
		return {
			id: '',
			type: '',
			num: 1,
			step: 0,
			password: '',

			price: '',
			list: {},
			checked: false,
			current: 0
		};
	},
	onLoad(option) {
		this.id = option.id;
		this.type = option.type;
	},

	computed: {
		money() {
			return this.num * this.price * this.step;
		}
	},
	onShow() {},
	methods: {
		async loadData() {
			let obj = this;
			miningDateils({}, obj.id).then(({ data }) => {
				obj.list = data;
				// obj.money = obj.list.cost_money;
				obj.price = obj.list.cost_money;
				obj.step = obj.list.step;
				console.log(obj.list);
			});
		},
		//阅读并同意
		Getcheckbox() {
			let obj = this;
			obj.checked = !obj.checked;
		},
		ToIndex() {
			uni.navigateTo({
				url: '/pages/finance/xieyi'
			});
		},
		pay() {
			let obj = this;
			if (obj.password == '') {
				obj.$api.msg('请输入交易密码！');
				return;
			}
			if (obj.checked == false) {
				obj.$api.msg('请阅读并同意协议！');
				return;
			}
			buyMining(
				{
					num: obj.num * obj.step,
					trade_psw: obj.password
				},
				obj.id
			)
				.then(data => {
					obj.$api.msg(data.msg);
					obj.password = '';
					obj.num = 1;
				})
				.catch(e => {
					obj.password = '';
					obj.num = 1;
					if (e.msg == '交易密码错误') {
						return;
					}
					console.log(e);
					var reg = new RegExp('购买矿机所需的');
					if (e.msg.match(reg) == -1) {
					} else {
						setTimeout(function() {
							uni.navigateTo({
								url: '/pages/finance/recharge'
							});
						}, 1000);
					}
				});
		},
		numberChange(data) {
			let obj = this;
			obj.num = data.number;
		},
		buy() {
			// let list = JSON.stringify(this.list)
			uni.navigateTo({
				url: '/pages/market/pay?&id=' + this.id + '&type=' + this.type
			});
			// console.log(this.list,'--------------***********')
			// console.log('buy click')
		},
		changeCurrent(index) {
			this.current = index;
		},
		back() {
			uni.navigateBack({
				url: '/pages/calculation/buyCalculation'
			});
		}
	}
};
</script>

<style lang="scss" scoped>
page,
.center {
	background: #f8f6f6;
	height: 100%;
}
.top {
	background: #45969B;
	width: 750rpx;
	height: 710rpx;
}
.name-box {
	padding: 30rpx 26rpx;
	line-height: 1;
	background-color: #FFFFFF;
	.price-box {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		.price {
			font-size: 48rpx;
			color: #E83F30;
		}
		.unit {
			display: inline-block;
			padding-left: 10rpx;
			color: #E83F30;
		}
		.yuan {
			
			padding-left: 10rpx;
			font-size: 30rpx;
			font-weight: 500;
			text-decoration: line-through;
			color: #999999;
		}
	}
	.name {
		font-size: 34rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #1D2023;
		margin-top: 30rpx;
	}
}
.tip-box {
	margin-top: 20rpx;
	padding: 34rpx 90rpx 50rpx 30rpx;
	display: flex;
	align-items: flex-start;
	background-color: #FFFFFF;
	.tip-titele {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #3B3B3B;
	}
	.tip-main {
		margin-left: 30rpx;
		width: 467rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #8A8A8A;
	}
}
.detail {
	.detail-title{
		width: 750rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: 28rpx;
		font-family: PingFangSC;
		font-weight: bold;
		color: #1D2023;
	}
}
.btn {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	width: 750rpx;
	height: 98rpx;
	background: linear-gradient(0deg, #2E58FF, #32C6FF);
	text-align: center;
	line-height: 98rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #FFFFFF;
}
</style>
