<template>
	<view>
		<uni-nav-bar  left-icon="left" :statusBar="true"  title="My Coupons" color="#fff" backgroundColor="#000000" rightIcon="info" @clickLeft="back" @clickRight="goPage" :border="false"/>
		<view class="body">
			<view class="coupons_item" v-for="(item,index) in list " :key="item.bonus_id">
				<view class="coupons_item_left">
					<view class="item_left_prcie">${{item.type_money}}</view>
					<text class="item_left_span">Min.spend</text>
					<view>${{item.min_goods_amount}}</view>
				</view>
				<view class="coupons_item_right">
					<view class="coupons_right_info">
						<view class="coupons_right_info_title">{{item.type_name}}</view>
						<text>The tide zone is available</text>
						<view class="coupons_right_info_time">{{item.use_start_date}} - {{item.use_end_date}}</view>
					</view>
					<button @click="goPage(1)">Use Now</button>
				</view>
			</view>
			<view class="empty_item1" v-if="!list">
				<view class="empty_item_img">
					<image src = "../../static/img/$.png" mode=""></image>
				</view>
				<view>sorry,no coupons~</view>
				<view>
					<button @click="goPages()">Get coupons</button>
					<!-- <button @click="goPage(1)">Go to the home page</button> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {defaultRequest2} from '../../api/index.js'
	export default {
		data() {
			return {
				list:[]
			}
		},
		onLaunch() {
			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);
		},
		methods:{
			getList(){
				let data={_action:'getuserbonus'}
				defaultRequest2(data).then(res=>{
					console.info(res)
					if(res.error==0){
						this.list=res.data
					}
				})
			},
			back(){
				uni.navigateBack()
			},
			goPages() {
				uni.navigateTo({
					url:"/pages/index/pickUpCentre"
				})
			},
			goPage(e){
				if(e==1){
					uni.switchTab({
						url:'../index/index'
					})
				}
				else{
					uni.navigateTo({
						url:"/pages/index/pickUpCentre"
					})
				}
				
			}
		},
		onShow() {
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.uni-navbar{
		font-size: 32rpx;
		font-weight: bold;
	}
	.body{
		// border-top: 14.67rpx #F7F7F7 solid;
		padding:0 26rpx;
		padding-top: 31.33rpx;
	}
	.empty_item1{
			
			height: 500rpx;
			padding: 20rpx 100rpx;
			margin:50rpx auto;
			color:#000;
			font-size: 24rpx;
			text-align: center;
			.empty_item_img{
				height: 180rpx;
				width: 180rpx;
				margin: 0 auto;
				margin-bottom: 30rpx;
				image{
					height: 100%;
					width: 100%;
					
				}
			}
			button {
				font-size: 24.33rpx;
				font-weight: 500;
				background-color: black;
				color: white;
				width: 240rpx;
				height: 65.67rpx;
				border-radius: 20rpx !important;
				line-height: 65.67rpx;
				border-radius: 0;
				margin-top: 33.33rpx;
			}
			.uni-button{
				border-radius: 20rpx !important;
			}
		}
</style>