<template>
	<view class="back">
		<view class="topbox">
			<view class="" style="position: absolute;top: -30rpx;right: 0;">
				<view class="state u-flex u-row-between" @click="stateshow = !stateshow">
					<text>{{state}}</text>
					<image src="static/images/pull_down.png" style="width: 24rpx;height: 24rpx;" mode=""></image>
				</view>
				<view class="state" v-if="stateshow">
					<view @click="statechange(item,idx)" :class="state_id==idx?'stateac':'unstate'"
						style="margin-bottom: 20rpx;font-size: 24rpx;" v-for="(item,idx) in array">{{item.name}}</view>
				</view>
			</view>
			<view class="u-row-center"
				style="display: flex;flex-direction: column;align-items: center;margin-top: 56rpx;">
				<view class="paysum">{{i18n.Actual}}</view>
				<view class="numbe" style="margin-top: 40rpx;">
					<text>￥</text>
					<text style="font-size: 60rpx;font-weight: 500;">{{sum}}</text>
				</view>
				<!-- 				<view class="">
					<text>支付剩余时间 13:50</text>
				</view> -->
			</view>
			<!-- 余额支付 -->
			<view class="payitem" style="margin-top: 100rpx;display: flex;" @click="change(0)">
				<image src="static/images/yuer.png" mode="" style="width: 40rpx;height: 40rpx;"></image>
				<view class="u-flex u-row-between " style="margin-left: 20rpx;flex: 1;">
					<view class="">
						<view class="">{{i18n.Balancepayment}}</view>
						<view class="" style="margin-top: 10rpx;color: rgba(248, 50, 36, 1);">
							{{i18n.Currentbalance}}：{{balance}}
						</view>
					</view>
					<image v-if="mode==0" src="static/images/active.png" mode="" style="width: 36rpx;height: 36rpx;">
					</image>
					<image v-else src="static/images/unactive.png" mode="" style="width: 36rpx;height: 36rpx;"></image>
				</view>
			</view>
			<!-- 微信支付 -->
			<view v-if="state_id==0" class="payitem" style="margin-top: 20rpx;display: flex;" @click="change(1)">
				<image src="static/images/wx.png" mode="" style="width: 40rpx;height: 40rpx;"></image>
				<view class="u-flex u-row-between " style="margin-left: 20rpx;flex: 1;">
					<view class="">
						<view class="">{{i18n.WechatPay}}</view>
						<view class="" style="margin-top: 10rpx;color: rgba(121, 121, 121, 1)">
							{{i18n.applicable}}
						</view>
					</view>
					<image v-if='mode==1' src="static/images/active.png" mode="" style="width: 36rpx;height: 36rpx;">
					</image>
					<image v-else src="static/images/unactive.png" mode="" style="width: 36rpx;height: 36rpx;"></image>
				</view>
			</view>
			<!-- 客服支付 -->
			<view class="payitem" style="margin-top: 20rpx;display: flex;" @click="change(2)">
				<image src="static/images/kefu2.png" mode="" style="width: 40rpx;height: 40rpx;"></image>
				<view class="u-flex u-row-between " style="margin-left: 20rpx;flex: 1;">
					<view class="">
						<view class="">{{i18n.Customerservicepayment}}</view>
						<view class="" style="margin-top: 10rpx;color: rgba(121, 121, 121, 1)">
							{{i18n.Contactpayment}}
						</view>
					</view>
					<image v-if='mode==2' src="static/images/active.png" mode="" style="width: 36rpx;height: 36rpx;">
					</image>
					<image v-else src="static/images/unactive.png" mode="" style="width: 36rpx;height: 36rpx;"></image>
				</view>
			</view>
		</view>
		<!-- 付款须知 -->
		<view class="">
			<view class="payment" style="margin-top: 24rpx;">{{i18n.Paymentinstructions}}</view>
			<view class="content" style="margin-top: 18rpx;">1.联系客服付款需走线下支付通道，付款成</view>
		</view>
		<view class="confirm" @click="confirm">
			{{i18n.Confirmpayment}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mode: 0,
				stateshow: false,
				state: '人民币',
				state_id: 0,
				array: [{
					name: '人民币'
				}, {
					name: '欧元'
				}, {
					name: '美元'
				}],
				sum: '',
				pay_type: 'balance',
				orderid: '',
				balance:'',
			};
		},
		onLoad(options) {
			this.sum = options.sum
			this.orderid = options.orderid
			this.userinfo()
		},
		computed: {
			i18n() {
				return this.$t('index')
			}
		},
		methods: {
			userinfo() {
				uni.$u.http.get('/api/member/info', {}).then((res) => {
					this.balance = res.balance
				}).catch(() => {

				})
			},
			change(idx) {
				this.mode = idx
			},
			statechange(item, idx) {
				this.state = item.name
				this.state_id = idx
				if (idx == 0) {
					this.pay_type = 'balance'  
				}
				if (idx == 1) {
					this.pay_type = 'wechat'
				}
				if (idx == 2) {
					this.pay_type = 'customer'
				}
				this.stateshow = !this.stateshow
			},
			confirm() {
				uni.$u.http.post('/api/order/payment', {
					order_id: this.orderid,
					pay_type: this.pay_type
				}).then((res) => {
					uni.navigateTo({
						url: 'confirm'
					})
				}).catch(() => {})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.payment {
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #222222;
		line-height: 34rpx;
		text-align: left;
		font-style: normal;
	}

	.content {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 20rpx;
		color: #777777;
		line-height: 28rpx;
		text-align: left;
		font-style: normal;
	}

	.stateac {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #FF1515;
		line-height: 34rpx;
		text-align: left;
		font-style: normal;
	}

	.unstate {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #222222;
		line-height: 34rpx;
		text-align: left;
		font-style: normal;
	}

	.confirm {
		position: fixed;
		bottom: 66rpx;
		width: 702rpx;
		height: 84rpx;
		background: #F83224;
		border-radius: 44rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 84rpx;
		text-align: center;
		font-style: normal;
	}

	.payitem {
		width: 702rpx;
		height: 140rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		padding: 34rpx 24rpx;
		box-sizing: border-box;
	}

	.back {
		padding: 20rpx 24rpx;
		box-sizing: border-box;

		.topbox {
			position: relative;

			.state {
				width: 128rpx;
				// height: 56rpx;
				background: #FFFFFF;
				border-radius: 6rpx;
				padding: 12rpx;
				box-sizing: border-box;
			}

			.paysum {
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #222222;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
			}

			.numbe {
				font-family: HarmonyOS_Sans_Medium;
				font-size: 28rpx;
				color: #000000;
				line-height: 38rpx;
				text-align: left;
				font-style: normal;
				margin-top: 20rpx;
			}
		}
	}
</style>