<template>
	<view>
		<view class="success">
			<image src="../../static/img/success.png" mode="" v-if="type==0"></image>
			<image src="../../static/img/fail.png" mode="" v-else></image>
			<text class="success_title">{{type==0?'Payment is successful':'Payment failed'}}</text>
			<view >
				This order will be rewarded with 
				<text class="success_span">{{will_get_integral || 0}} points</text>
				after receipt.
			</view>
			<view class="success_button">
				<button class="details" @click="goPage">Order details</button>
				<button class="shop" @click="goCategory">Continue shopping</button>
			</view>
		</view>
		<view class="recommend">
			<view class="recommend_title" >RECOMMEND</view>
			<view class="recommend_content">
				<view class="recommend_content_item" v-for="(item,index) in catList " :key="index">
					<view class="recommend_content_item_image">
						<image :src="item.thumb" mode=""></image>
					</view>
					<view class="recommend_content_item_image_name">{{item.short_name}}</view>
					<view class="recommend_content_item_pric">US${{item.is_promote==0? item.shop_price :item.promote_price}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {defaultRequest4} from '../../api/index.js'
	export default {
		data() {
			return {
				// 是否支付成功 0成功 1失败
				type:0,
				id:'',
				will_get_integral:0,
				// 获取该分类的其他商品的请求参数
				catQuery:{
					_action:'getgoods',
					page_index:1,
					page_size:10
				},
				catList:[],
				isReachBottom:true,
			}
		},
		methods:{
			// 获取的其他商品
			getCatList(type){
				defaultRequest4(this.catQuery).then(res=>{
					console.info(res)
					if(res.error==0){
						if(res.data){
							if(type==0){
								this.catList=res.data
							}else{
								this.catList=this.catList.concat(res.data)
							}
						}else{
							this.isReachBottom=false
							uni.showToast({
								title: 'No more data yet',
								icon:'none',
								duration: 2000
							})
							this.catQuery.page_index--
						}
					}
					uni.hideNavigationBarLoading();
				})
			},
			goPage(){
				let details_index
				if(this.type==0){
					details_index=0
				}else{
					details_index=3
				}
				uni.redirectTo({
					url: './details?details_index='+details_index+'&'+'id='+this.id
				});
			},
			goCategory(){
				uni.switchTab({
					url:'../category/index'
				})
			}
		},
		onLoad(e) {
			let that = this;
			let s = 0;
			let time = setInterval(() => {
				uni.getNetworkType({
					success: (res) => {
						console.log(res.networkType, s);
						if (res.networkType == 'none') {
							uni.showToast({
								icon: 'none',
								title: 'Please connect to the network',
								duration: 3000,
							})
						} else if (res.networkType !== 'none') {
							that.typee = 2;
							clearInterval(time);
							
						}
					}
				})
				s++;
			}, 1000);
			this.id=e.order_id
			this.will_get_integral=e.will_get_integral || 0
			this.type=e.type
			this.getCatList(0)
		},
		// 上拉加载
		onReachBottom(){
			if(!this.isReachBottom)return
			this.catQuery.page_index++
			this.getCatList(1)
		},
		onPullDownRefresh(){
			 uni.stopPullDownRefresh()
		}
	}
</script>

<style>
	page{
		border-top: 14.67rpx #F7F7F7 solid;
	}
</style>
<style lang="scss" scoped>
	
	.success{
		display: flex;
		align-items: center;
		justify-content: center;
		padding-top: 72rpx;
		font-size: 24rpx;
		color: #555555;
		font-weight: 400;
		flex-direction: column;
		border-bottom: 14.67rpx #F7F7F7 solid;
		padding-bottom: 81.33rpx;
		image{
			width: 160rpx;
			height: 160rpx;
			margin-bottom: 46.67rpx;
		}
		.success_title{
			font-size: 32rpx;
			color: black;
			font-weight: 500;
			margin-bottom: 13.33rpx;
		}
		.success_span{
			color: #B22234;
			display: inline-block;
			margin: 0 5rpx;
		}
		.success_button{
			display: flex;
			margin-top: 70.67rpx;
			align-items: center;
			justify-content: center;
			
			button{
				height: 63.33rpx;
				font-size: 24rpx;
				margin: 0;
				font-weight: 500;
			}
			.details{
				background-color: white;
				border: 1px solid #CBCBCB;
				color: black;
			}
			.shop{
				color: white;
				background-color: black;
				margin-left: 48rpx;
			}
		}
	}
	
</style>