<template>
	<view class="pay">
		<!-- 支付金额 -->
		<view class="header">
			<view class="header-title">实付金额</view>
			<view class="header-price"><text>￥</text>{{total}}</view>
			<view class="header-no">订单号:{{orderNo}}</view>
		</view>
		<!-- 选择支付方式 -->
		<view class="choose">
			<radio-group @change="payMethod = $event.detail.value">
				<label class="choose-item">
					<view class="choose-text nowrap">
						<image src="@/static/icons/pay_alipay.png" mode="aspectFill"></image>
						火力值支付
					</view>
					<radio class="choose-radio" value="coin" checked></radio>
				</label>
				<label class="choose-item nowrap">
					<view class="choose-text">
						<image src="@/static/icons/pay_code.png" mode="aspectFill"></image>
						付款码支付
					</view>
					<radio class="choose-radio" value="code"></radio>
				</label>
				<label class="choose-item nowrap">
					<view class="choose-text">
						<image src="@/static/icons/pay_wechat.png" mode="aspectFill"></image>
						微信支付
					</view>
					<radio class="choose-radio" value="wx"></radio>
				</label>
			</radio-group>
		</view>
		<!-- 确认支付 -->
		<view class="payBtn">
			<button size="default" @click="onPay">支付</button>
		</view>
	</view>
</template>

<script>
	import { info } from '@/apis/interfaces/order.js'
	import { coinPay, diffCoinPay } from '@/apis/interfaces/pay.js'
	export default {
		data() {
			return {
				orderId	  : '',
				diffId	  : '',
				payMethod : 'coin',
				payType   : 'price',
				total  	  : '0.00',
				orderNo	  : ''
			};
		},
		created() {
			uni.showLoading({
				title: '获取订单信息...',
				mask : true
			})
			info(this.$Route.query.orderId).then(res => {
				let { total, order_no, business_order_id, diff_prices, diff } = res
				this.orderId 	= business_order_id
				this.diffId		= diff.business_order_diff_price_id
				this.payType 	= this.$Route.query.paytype
				this.total 		= this.payType === 'diff' ? diff_prices: total
				this.orderNo 	= order_no
				uni.hideLoading()
			}).catch(err => {
				uni.showToast({
					title: err.message,
					icon : 'none'
				})
			})
		},
		methods: {
			// 支付方式
			onPay(){
				switch(this.payMethod){
					case 'coin':
						if(this.payType == 'price') this.onCoinPay()
						if(this.payType == 'diff') this.onDiffCoinPay()
						break;
					case 'code':
						uni.showToast({
							title: '付款码支付暂未开放，请敬期待',
							icon : 'none'
						})
						break;
					case 'wx':
						uni.showToast({
							title: '微信支付暂未开放，请敬期待',
							icon : 'none'
						})
						break;
				}
			},
			// 火力值支付
			onCoinPay(){
				wx.showLoading({
					title: '支付中...',
					mask : true
				})
				console.log(this.orderId)
				coinPay(this.orderId).then(res => {
					wx.showModal({
						title		: '提示',
						content 	: '待缴费成功，请提醒用户尽快签约并完善资料',
						showCancel	: false,
						confirmColor: '#446EFE',
						success		: () => {
							this.onRrmoveItem()
						}
					})
				}).catch(err => {
					console.log(err)
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			},
			// 活力值补差价支付
			onDiffCoinPay(){
				diffCoinPay(this.diffId).then(res => {
					wx.showModal({
						title		: '提示',
						content 	: '补缴差价成功',
						showCancel	: false,
						confirmColor: '#446EFE',
						success		: () => {
							this.onRrmoveItem()
						}
					})
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			},
			// 更新订单列表
			onRrmoveItem(){
				this.$store.commit('setOrderId', this.orderId)
				this.$Router.back()
			}
		}
	}
</script>

<style lang="scss">
	.pay{
		background: #f8f8f8;
		height: 100vh;
		width: 100vw;
		padding: 30rpx 30rpx 60rpx;
		box-sizing: border-box;
		.header{
			padding: 80rpx 0 100rpx;
			text-align: center;
			.header-title{
				font-size: 32rpx;
				padding-bottom: 10rpx;
			}
			.header-price{
				font-size: 68rpx;
				font-family: Arial, Helvetica, sans-serif;
				font-weight: bold;
				text{
					font-size: 60%;
				}
			}
			.header-no{
				padding-top: 20rpx;
				font-size: 28rpx;
				color: gray;
			}
		}
		// 选择支付方式
		.choose{
			background-color: white;
			border-radius: 20rpx;
			padding: 10rpx 30rpx;
			.choose-item{
				display: block;
				padding: 20rpx 0;
				display: flex;
				justify-content: space-between;
				align-items: center;
				&:last-child{
					border-bottom: none;
				}
				.choose-text{
					line-height: 80rpx;
					font-size: 32rpx;
					padding-left: 80rpx;
					position: relative;
					image{
						position: absolute;
						left: 0;
						top: 15rpx;
						width: 50rpx;
						height: 50rpx;
						border-radius: 10rpx;
					}
				}
				.choose-radio{
					transform:scale(0.8)
				}
			}
		}
		// 按钮
		.payBtn{
			padding: 50rpx 0;
			button[size="default"]{
				height: 100rpx;
				line-height: 100rpx;
				padding: 0;
				border-radius: 20rpx;
				background-color: $main-color;
				color: white;
				font-size: 32rpx;
				font-weight: bold;
				&::after{
					display: none;
				}
			}
		}
	}
</style>
