<template>
	<view v-if="istrue" class="flex_items flex_center over pos" style="height: 100vh;">
		<view v-if="state==1" class="flex_column flex_items">
			<image :src="isimg" style="width: 120rpx;height: 120rpx;" mode=""></image>
			<view class="bold f32 mt20">支付成功</view>
			<view class="mt20 f26">返回美团可查看订单详情</view>
		</view>
		<view v-else class="flex_column flex_items">
			<image :src="isimg2" style="width: 120rpx;height: 120rpx;" mode=""></image>
			<view class="bold f32 mt20">支付失败</view>
			<view class="mt20 f26">错误，请重新支付</view>
		</view>
		<view style="position: fixed;left: 0;bottom: 35rpx;width: 100%;" class="flex_column flex_items">
			<view v-if="state!=1" @click="gobuy" class="ptb15 f30 bold f-center"
				style="background: #fde64f;width: calc(100% - 120rpx);color: #333;border-radius: 30rpx;">重新支付</view>
			<view @click="goh" class="ptb15 f30 bold f-center mt20"
				:style="{'background':state=='1'?'#fde64f':'#333','width': 'calc(100% - 120rpx)','color':state==1?'#333':'#fff','border-radius': '30rpx'}">
				返回美团</view>
		</view>
		<Ywatermark :info="'蓝色兄弟'"></Ywatermark>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isimg: require('@/static/cg.png'),
				isimg2: require('@/static/sb.png'),
				orderno: "",
				state: 1,
				istrue: false,
				types: "1",
				user: ""
			}
		},
		onLoad() {
			let params = this.getRequestParams();
			let mobile = params['order_no'];
			this.orderno = mobile
			this.getinfo(mobile)
		},
		methods: {
			getinfo(mobile) {
				uni.showLoading({
					title: "加载中...",
					icon: "none"
				})
				this.api.getinfoorder({
					order_no: mobile,
				}).then((res) => {
					console.log(res)
					if (res.data.code == 200) {
						uni.hideLoading()
						this.state = res.data.data.order.state
						// this.state = 2
						this.user = res.data.data.user.user_number
						this.types = res.data.data.order.type
						this.istrue = true
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				})
			},
			getRequestParams() {
				let url = location.href;
				let requestParams = {};
				if (url.indexOf("?") !== -1) {
					let str = url.substr(url.indexOf("?") + 1); //截取?后面的内容作为字符串
					// console.log(str, '?后面的内容');
					let strs = str.split("&"); //将字符串内容以&分隔为一个数组
					// console.log(strs, '以&切割的数组');
					for (let i = 0; i < strs.length; i++) {
						requestParams[strs[i].split("=")[0]] = decodeURI(
							strs[i].split("=")[1]
						);
						// 将数组元素中'='左边的内容作为对象的属性名，'='右边的内容作为对象对应属性的属性值
					}
				}
				return requestParams;
			},
			gobuy() {
				uni.reLaunch({
					url: '/pages/mt/pay?order_no=' + this.orderno
				})
			},
			goh() {
				this.api.gomt({
					user_number: this.user,
					type: this.types,
					dinner_type: ""
				}).then((res) => {
					console.log(res)
					if (res.data.code == 200) {
						uni.hideLoading()
						var href = res.data.url
						window.open(href, '_self')
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style>
</style>