<template>
	<view class="container">
		
		<view class="main">
			<view class="flex-y-center main-home"  @click="choice" :data-url='item.url' :data-id='item.id' 
			:data-index="index" v-for="(item,index) in list" :key="item.id">
			
				<view class="main-icon">
					<i class="iconfont iconxuanzhong" v-if="item.checked"></i>
					<i class="iconfont iconweixuanzhong" v-else style="color:#bfbfbf"></i>
				</view>
				
				<view :data-index='index' class="item flex-row">
					<image src="../../static/images/icon_game.png" mode="aspectFit" class="type-img" v-if="item.type == 7"></image>
					<image src="../../static/images/icon_6.png" mode="aspectFit" class="type-img" v-if="item.type == 4"></image>
					<image src="../../static/images/icon_5.png" mode="aspectFit" class="type-img" v-if="item.type == 3"></image>
					<image src="../../static/images/icon_2.png" mode="aspectFit" class="type-img" v-if="item.type == 2"></image>
					<image src="../../static/images/icon_4.png" mode="aspectFit" class="type-img" v-if="item.type == 1"></image>
					<image src="../../static/images/icon_7.png" mode="aspectFit" class="type-img" v-if="item.type == 6"></image>
					<view class="info">
						<view class="title text-1" v-if="item.description">{{item.description}}</view>
						<view class="desc flex-row-between">
							<view class="time content">{{item.url}}</view>
						</view>
	
					</view>
				</view>	
			</view>
		</view>
		<view class="hg90">
			
		</view>
		
		<view class="bottom-bars flex-center">
			<button @click="save" class="flex-center ft28">立即提交</button>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				page: 1,
				checked:-1,
				
			}
		},
		onLoad(e) {		
			this.type=e.type;
			uni.setNavigationBarTitle({
				title:`${this.$test.$test}列表`
			})
			this.page = 1;
			this.list = [];
			this.funeng_list();
		},
		onShow() {
 
		},
		onReachBottom(e) {
			this.funeng_list()
		},
		methods: {
			
			choice(e) {
				 let index= e.currentTarget.dataset.index;
				// var url= e.currentTarget.dataset.url;
				this.list[index].checked=!this.list[index].checked;
				// var pages = getCurrentPages();
				
				// 	var currPage = pages[pages.length - 1]; //当前页面
				// 	var prevPage = pages[pages.length - 2]; //上一个页面
				//     //可以打印prevPage看看
				// 	console.log(prevPage)
				//     //h5的写法
				// 	// #ifdef H5
				// 		prevPage.save_url=url;
				// 		prevPage.id=id;
				// 	// #endif 
				// 	// #ifdef MP-WEIXIN
				//     //小程序的写法 具体要怎么写可以打印一下prevPage看一下
				//     prevPage.$vm.save_url=url;
				// 	prevPage.$vm.id=id;
				// 	 // #endif
				// 	uni.navigateBack();	
			},
			
			save(e){
				let arr = this.list,way_id = [];
				for (let i of this.list) {
					 if(i.checked){
						 way_id.push({id:i.id})
					 }
				}
				this.request({
					url:"funeng/addExchangePool",
					data:{
						arr:way_id,
						type:this.type,				
						token: uni.getStorageSync("token"),
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code === '200') {
						uni.showToast({
							title: "添加成功",
							icon: 'none'
						})      
					    setTimeout(()=>{
				         	uni.navigateBack()	
						},2000)
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				});
			},
			 
			viewRecords(e) {
				var index = e.currentTarget.dataset.index,
					card_num = this.list[index].card_num,
					type = this.list[index].type;
				uni.navigateTo({
					url: "../viewRecords/viewRecords?card_num=" + card_num + '&type=' + type
				})
			},

			funeng_list() {
				this.request({
					url: "user/funeng_list",
					data: {
						page: this.page,
						token: uni.getStorageSync("token"),
						type:this.type,
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code === '200') {
						for(var i of res.data){
							i.checked=false;
						}
						this.list = this.list.concat(res.data);
						this.page = this.page + 1;	
					}
				})
			},	
		}
	}  
</script>

<style>
	
	page {
		background: #F9F9F9;
	}
	
	.content {
		word-wrap: break-word;
		word-break: break-all;
	}
	.iconxuanzhong {
		color: #007AFF;
	}

	.header {
		width: 100%;
		height: 198rpx;
		position: relative;
	}

	.header .bg-img {
		display: block;
		position: absolute;
		left: 0;
		top: 0;
		z-index: -1;
		width: 100%;
		height: 198rpx;

	}

	.header .info {
		width: 100%;
		height: 100%;
		display: flex;
		flex-flow: row nowrap;
		justify-content: center;
		align-items: center;
	}

	.header .info .num {
		font-size: 70rpx;
		font-weight: 700;
		font-family: DIN Alternate, DIN Alternate-Bold;
		color: #fff;
		line-height: 1;
	}

	.header .info .desc {
		font-size: 32rpx;
		line-height: 1;
		color: #fff;
		margin-top: 39rpx;
	}

	.main {
		background-color: #F9F9F9;
		border-radius: 20rpx 20rpx 0 0;
		margin-top: 20rpx;
		padding: 20rpx 40rpx 0;
	}

	.main .page-title {
		padding: 28rpx 0 40rpx;
	}

	.main .page-title .title {
		font-size: 36rpx;
		color: #262626;
		line-height: 50rpx;
		font-weight: 600;
	}

	.main .item {
		background-color: #fff;
		border-radius: 8rpx;
		padding: 20rpx 32rpx 20rpx 34rpx;
		width: 606rpx;
	}

	.main-home {
		margin-bottom: 40rpx;
	}

	.main .item .type-img {
		display: block;
		flex: none;
		width: 40rpx;
		height: 40rpx;
		margin-right: 26rpx;
	}

	.main .item .info {
		flex: auto;
	}

	.main .item .info .title {
		/* width: 538rpx; */
		font-size: 30rpx;
		font-weight: 500;
		color: #323232;
		line-height: 42rpx;
		margin-bottom: 16rpx;
	}

	.main .item .info .desc {
		/* margin-top: 16rpx; */
	}

	.main .item .info .num {
		font-size: 28rpx;
		font-weight: 400;
		color: #3387FF;
		line-height: 40rpx;
	}

	.main .item .info .time {
		font-size: 28rpx;
		font-weight: 400;
		color: #999;
		line-height: 40rpx;
	}

	.main-icon {
		margin-right: 33rpx;
	}
	.main-icon .iconfont{
		font-size: 38rpx;
	}
	
	.hg90{
		height: 90rpx;
	}
	
	.bottom-bars {
		width: 100%;
		/* padding: 30rpx 0; */
		position: fixed;
		bottom: 0rpx;
	}
	
	.bottom-bars button {
		text-align: center;
		width: 690rpx;
		height: 90rpx;
		background: linear-gradient(132deg, rgb(64, 158, 255) 0%, rgb(64, 158, 255) 100%);
		box-shadow: 0px 2rpx 12rpx rgb(64, 158, 255);
		opacity: 1;
		color: #fff;
	}
	
</style>
