<template>
	<view class="page">
		<view class="fui-cell-group">
			<view class="fui-cell">
				<view class="fui-cell-label">订单金额</view>
				<view class="fui-cell-text textl"></view>
				<view class="text-danger">¥<text>
						{{ listDetail.price}}元</text>
				</view>
			</view>
			<view class="fui-cell" v-if="listDetail.bean*0.15>0">
				<view class="fui-cell-label">金豆抵扣</view>
				<view class="fui-cell-text textl"></view>
				<view class="text-danger"><text>{{ (listDetail.bean*0.15).toFixed(2) }}元</text>
				</view>
			</view>
			<view class="fui-cell" v-if="listDetail.reduction>0">
				<view class="fui-cell-label">随机立减</view>
				<view class="fui-cell-text textl"></view>
				<view class="text-danger"><text>{{ listDetail.reduction/100 }}元</text>
				</view>
			</view>
			<view class="fui-cell">
				<view class="fui-cell-label">实付金额</view>
				<view class="fui-cell-text textl"></view>
				<view class="text-danger" style="font-weight:bold;">
					¥<text>{{ (listDetail.price-(listDetail.bean*0.15)-(listDetail.reduction/100)).toFixed(2) }}元</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		pay,
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				listDetail: '',
			}
		},
		onLoad(option) {
			this.listDetail = JSON.parse(option.val)
			this.gopay()
		},
		methods: {
			gopay() {
				pay(this.listDetail).then(res => {
					console.log(res.data);
					if (!res.code) {
						let pay = JSON.parse(res.data.jsapiPayInfo)
						if (!res.code) {
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: pay.timeStamp,
								nonceStr: pay.nonceStr,
								package: pay.package,
								signType: pay.signType,
								paySign: pay.paySign,
								success: function(res) {
									console.log('success:' + JSON.stringify(res));
								},
								fail: function(err) {
									console.log('fail:' + JSON.stringify(err));
									uni.navigateBack({
										delta:1
									})
								}
							});
						}
					} else {
						this.$u.toast(res.message)
					}
				})
			}
		}
	}
</script>
<style>
	@import "./index.css";
</style>