<template>
	<view class="content">

		<view class="content-bg flex-y-center" v-for="(item,index) of list" :key='index' @click="choice" :data-index='index'>
			<view class="main-icon" v-if="is_check!=2">
				<i class="iconfont iconxuanzhong" v-if="item.checked"></i>
				<i class="iconfont iconweixuanzhong" v-else style="color:#bfbfbf"></i>
			</view>
			<view class="">
				<view class="">
					{{item.name}}
				</view>
				<view class="content-bg-time">
					{{item.update_time}}
				</view>
			</view>
		</view>
		
		<view style="height: 100px;"></view> 
		
		<view class="bottom-bars ">
			<button @click="save" v-if="is_check!=2" class="flex-center ft28" style="margin-bottom: 20rpx;">选择记录</button>
			<button @click="nav" class="flex-center ft28">添加{{$test.$test}}池</button>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				$test: this.$test.$test,
				list: [],
				page: 1,
				type: 1,
				is_check:1,
			}
		},

		onLoad(e) {
			this.type = e.type;
			this.is_check=e.is_check||1;
		},

		onShow(e) {
			this.page = 1;
			this.list = [];
			this.http();
		},

		onReachBottom(e) {
			this.http();
		},
		methods: {

			choice(e) {
				if(this.is_check==2){
					let index = e.currentTarget.dataset.index;
					let id=	this.list[index].id;
					uni.navigateTo({
						url:"add-way?id="+id
					})
					return
				}
				
				let index = e.currentTarget.dataset.index;
				if (this.type == 2) {
					for(let i of this.list){
						i.checked=false
					}
					this.list[index].checked =true;
				} else {
					this.list[index].checked = !this.list[index].checked;
				}
				
			},


			nav(e) {
				uni.navigateTo({
					url: "./add-way"
				})
			},

			save() {
				let hasGoodStudentType = this.list.some((v, i) => v.checked )
				if(!hasGoodStudentType){
					uni.showToast({
						title: "请选择记录",
						icon: 'none'
					})
					return
				}
				uni.setStorageSync("list_way", this.list);
				uni.navigateBack();
				return;
				var pages = getCurrentPages();
				var currPage = pages[pages.length - 1]; //当前页面
				var prevPage = pages[pages.length - 2]; //上一个页面
				//可以打印prevPage看看
				console.log(prevPage)
				//h5的写法
				// #ifdef H5
				prevPage.powerpool_id = way_id;
				// #endif 
				// #ifdef MP-WEIXIN
				//小程序的写法 具体要怎么写可以打印一下prevPage看一下
				prevPage.$vm.powerpool_id = way_id;;
				// #endif
			},
			
			http() {
				this.request({
					url: "powerpool/poollists",
					data: {
						page: this.page,
						token: uni.getStorageSync("token"),
					},
				}).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>
	.content {
		padding: 20rpx 0;
	}

	.content-bg {
		background: #FAFAFA;
		width: 670rpx;
		margin: 0 auto;
		margin-bottom: 20rpx;
		padding: 20rpx;
		border-radius: 8rpx;
	}

	.content-bg-time {
		font-size: 26rpx;
		color: 999;
	}

	.main-icon {
		margin-right: 33rpx;
	}

	.main-icon .iconfont {
		font-size: 38rpx;
	}

	.iconxuanzhong {
		color: #007AFF;
	}
</style>
