<template>
	<view class="choiceness">
		<uni-segmented-control :current="statusCurrent" :values="statusList" :style-type="styleType"
							:active-color="activeColor" @clickItem="onClickStatus" />
							<uni-segmented-control :current="typeCurrent" :values="typeList" :style-type="styleType"
												:active-color="activeColor" @clickItem="onClickType" />
			<view class="choiceness-list">
				<image v-for="(item,index) in creatorImgList" :key='index' class="img-box"
					:style="'width:'+imgWidth+';height:'+imgHeight" :src="item.imgUrl" @click="targetDetail(item)"
					mode=""></image>
					<view class="ivOver" v-if="flag">-----已经到底啦-----</view>
			</view>
	</view>
</template>

<script>
	import {
		listType,listTiktokImgIn
	} from '@/api/index.js'
	export default {
		data() {
			return {
				statusCurrent: 0,
				activeColor: '#007aff',
				styleType: 'text',
				statusList: ['待审核','审核拒绝','已上架','已下架'],
				typeList:[],
				typeIdList:[],
				typeCurrent: 0,
				typeId: 1,
				status: 0,
				pageNum: 1,
				pageSize: 10,
				creatorImgList: [],
				userInfo: {},
				imgWidth: 0, // 图片宽
				imgHeight: 0, // 图片高
				flag: false
			} 
		},
		onLoad() {
			this.listTiktokImgIn();
		},
		created(){
			const userInfoSync = uni.getStorageSync("userInfo");
			this.userInfo = userInfoSync;
			this.queryListType();
			this.imgWidth = 750/3-20 + 'rpx'
			this.imgHeight = 750/3-20 + 'rpx'
		},
		// 下拉刷新
		onPullDownRefresh(){
			this.pageNum = 1
			this.creatorImgList = []
			this.listTiktokImgIn();
			this.flag = false;
			uni.stopPullDownRefresh();
		},
		// 上划加载更多
		onReachBottom() {
			console.log(2222)
			if (this.creatorImgList.length > this.pageSize*this.pageNum-1) {
				this.flag = false;
				this.pageNum += 1
				this.listTiktokImgIn()
			}else{
				this.flag = true;
			}
		},
		methods: {
			// 前往详情页
			targetDetail(item) {
				//console.log('跳转', item)
				if (item.id) {
					uni.setStorage({
						key: 'detailId',
						data: item.id,
						success() {
							console.log(111111)
							uni.navigateTo({
								url: '/pages/index/material/imgDetail',
								success:function(){
									console.log('跳转成功!')
								},
								fail:function(){
									console.log('跳转失败!')
								}
							})
						}
					})
				}
			},
			
			onClickStatus(e1){
				let that = this;
				that.flag = false;
				that.creatorImgList = [];
				that.status = e1.currentIndex;
				//console.log('status',that.status)
				uni.showLoading({
				  title: "加载中",
				  mask: true,
				  success() {
				   // 查询指定艺术家图片集合
				   const param = {
				     creatorId: that.userInfo.id,
				     typeId: that.typeId,
				     pageSize: that.pageSize,
				     pageNum: that.pageNum,
					 status: that.status
				   };
				   listTiktokImgIn(param).then(res => {
					   console.log('that.typeId',that.typeId);
					   console.log('that.status',that.status);
					   if(res.data.code === 200){
						   that.creatorImgList.push(...res.data.rows)
						   //console.log('调用成功1!', that.creatorImgList);
					   }else {
							uni.showModal({
							content: "艺术家图片列表数据加载失败！",
							showCancel: false,
						});
						}
				   });
				  },
				  complete() {
				    uni.hideLoading();
				  },
				});
			},
			onClickType(e2){
				let that = this;
				that.flag = false;
				that.creatorImgList = [];
				that.typeId = that.typeIdList[e2.currentIndex];
				//console.log('typeId',that.typeId)
				uni.showLoading({
				  title: "加载中",
				  mask: true,
				  success() {
				   // 查询指定艺术家图片集合
				   const param = {
				     creatorId: that.userInfo.id,
				     typeId: that.typeId,
				     pageSize: that.pageSize,
				     pageNum: that.pageNum,
					 status: that.status
				   };
				   listTiktokImgIn(param).then(res => {
					   console.log('that.typeId',that.typeId);
					   console.log('that.status',that.status);
					   if(res.data.code === 200){
						   that.creatorImgList.push(...res.data.rows)
						   console.log(that.creatorImgList)
						   //console.log('调用成功2!', that.creatorImgList);
						   if(that.typeId === 1){
						   	that.imgWidth = 750/3-20 + 'rpx'
						   	that.imgHeight = 750/3-20 + 'rpx'
						   }else if(that.typeId === 2){
						   	that.imgWidth = 750/3-30 + 'rpx'
						   	that.imgHeight = 750/3+60 + 'rpx'
						   }else if(that.typeId === 3){
						   	that.imgWidth = 750/3-30 + 'rpx'
						   	that.imgHeight = 750/3+60 + 'rpx'
						   }else if(that.typeId === 4){
						   	that.imgWidth = 750/3+100 + 'rpx'
						   	that.imgHeight = 750/3 + 'rpx'
						   }else if(that.typeId === 5){
						   	that.imgWidth = 750/3-20 + 'rpx'
						   	that.imgHeight = 750/3-20 + 'rpx'
						   }else if(that.typeId === 6){
						   	that.imgWidth = 750/3-20 + 'rpx'
						   	that.imgHeight = 750/3-20 + 'rpx'
						   }
					   }else {
							uni.showModal({
							content: "艺术家图片列表数据加载失败！",
							showCancel: false,
						});
						}
				   });
				  },
				  complete() {
				    uni.hideLoading();
					
				  },
				});
			},
			
			// 获取图片分类列表
			async queryListType() {
			  const res = await listType();
			  if (res.data.code === 200) {
				  for (let s of res.data.data) {
				  	this.typeList.push(s.typeName);
					this.typeIdList.push(s.id);
				  }
			    //console.log('typeList', this.typeList)
				console.log('typeIdList', this.typeIdList)
			  } else {
			    uni.showModal({
			      content: "图片分类列表加载失败！",
			      showCancel: false,
			    });
			  }
			},
			
			//查询指定艺术家图片集合
			async listTiktokImgIn() {
				const userInfo = uni.getStorageSync('userInfo')
				if (!userInfo) {
					console.log('havent userInfo')
					
				} else {
					console.log('have userInfo')
				}
				const res = await listTiktokImgIn({
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					typeId: this.typeId,
					status: this.status,
					creatorId: userInfo.id
				})
				if (res.data.code === 200) {
					this.creatorImgList.push(...res.data.rows)
					console.log('creatorImgList',this.creatorImgList);
				} else {
					uni.showModal({
						content: '艺术家图片列表加载失败！',
						showCancel: false
					});
				}
			}
		}
	}
</script>

<style lang="scss">
	.choiceness {
		padding-top: 20rpx;
		//width: 750rpx;
		
		.choiceness-list {
			display: flex;
			flex-wrap: wrap;
			justify-content:   flex-start; 
			flex-direction: row;
			width: 750rpx;
			//border: 1rpx solid blue;
		
		
			.img-box {
				margin-top: 10rpx;
				margin-left: 16rpx;
			    //margin-right: 10rpx;
				//margin:8rpx;
				border-radius: 10rpx;
				//border: 1rpx solid red;
			}
		}
	}
	
	.ivOver{
		width: 100%;
		height:50rpx;
		line-height: 50rpx;
		text-align: center;
		background: #fff;
		font-size: 20rpx;
	}
</style>
