<template>
	 <a-drawer
		v-model:visible="visible"
		class="task_page"
		style="color: #000"
		title="Task List"
		placement="right"
		@after-visible-change="afterVisibleChange"
	>
		<template #extra>
			<div class="button_second" @click="openTaskDetailPage">Detailed Task</div>
		</template>
		<div class="task_content">
			<div class="task_content_item" v-for="item in taskList">
				<img v-if="item.state !== 'success'" src="@/assets/images/homePage/loading.gif" alt="">
				<img v-else :src="item.inputParam.images" alt="">
				<div class="task_content_item_text">
					<div class="task_content_item_text_left modal_title_text">
						<div class="task_content_item_text_left_titile">{{ item.title }}</div>
						<div class="task_content_item_text_left_into modal_title_text_intro">{{ item.createDate }}</div>
					</div>
					<div class="task_content_item_text_right modal_title_text">
						<div class="task_content_item_text_left_titile">{{ item.status }}</div>
					</div>
				</div>
			</div>
			<div class="task_content_more" v-show="taskListMore.length == 0" @click="setTaskListMore">
				点击查看更多
			</div>
			<div class="task_content_select" v-show="taskListMore.length > 0">
				<a-select :visibleChange="visibleChange()" v-model:value="currentState.value" size="large" optionFilterProp="label" :options="state" placeholder="Please select" :getPopupContainer="getPopupContainer" allowClear show-search></a-select>
			</div>
			<div class="task_content_item" v-for="item in taskListMore" v-show="taskListMore.length > 0">
				<img v-if="item.state === '执行中' || item.state === '失败'" src="@/assets/images/homePage/loading.gif" alt="">
				<img v-else :src="item.url" alt="">
				<div class="task_content_item_text">
					<div class="task_content_item_text_left modal_title_text">
						<div class="task_content_item_text_left_titile">{{ item.title }}</div>
						<div class="task_content_item_text_left_into modal_title_text_intro">{{ item.time }}</div>
					</div>
					<div class="task_content_item_text_right modal_title_text">
						<div class="task_content_item_text_left_titile">{{ item.state }}</div>
					</div>
				</div>
			</div>
			<div v-show="total > taskListMore?.length && total != 0 && taskListMore.length > 0" class="task_content_more" v-observe>
				<img src="@/assets/images/homePage/loading.gif" alt="">
			</div>
		</div>
		<TaskDetailPage ref="TaskDetailPage"></TaskDetailPage>
	</a-drawer>
</template>
<script lang="ts">
import { message, Upload } from "ant-design-vue";
import { defineComponent, computed, h, ref, nextTick, inject } from "vue";
import { Https } from "@/tool/https";
import { useStore } from "vuex";
// import { forEach } from "jszip";
import TaskDetailPage from "@/component/HomePage/TaskDetailPage.vue";
export default defineComponent({
	components: {
		TaskDetailPage,	
	},
    props: ["msg",'sketchCatecoryList'],
    setup() {
        // console.log(prop.msg);
        const store = useStore();
       	let visible = ref<boolean>(false);
		let taskList = ref([
		
		])
		let taskListMore:any = ref([])
		let state:any = ref([
			{
				label:'Income',
				value:'income',
			},
			{
				label:'Expend',
				value:'expend',
			}
		])
		let currentState = ref({
			value:'income',
		})
        return {
			store,
			visible,
			taskList,
			taskListMore,
			state,
			currentState,
        };
    },
    data(prop) {
        return {
			currentPage: 1,
            pageSize: 10,
            total: 99,
		}
    },
	
    mounted() {
    },
	directives:{
		observe:{
			mounted (el,binding) {
				// console.log(binding.instance);
				const ob = new IntersectionObserver(callback,{
					root:null,
					threshold:[0.1]
				})
				ob.observe(el)
				// this.currentPage = 1
				// this.pageSize = 12
				let this_:any = binding.instance
				function callback(entries:any, observer:any) {
					entries.forEach((entry:any) => {
						if (entry.isIntersecting) {
							this_.getTaskList()
						} else {
						}
					});
				}
			},
		},
	},
	watch:{
		// newWindowState:{
		// 	handler(newVal,oldVal){
		// 		console.log(newVal);
		// 		if(newVal){
		// 			this.newWindow?.close();
		// 		}
		// 	}
		// },
		
	},
    methods: {
		getPopupContainer(){
			let dom = document.querySelector('.task_page .task_content_select')
			return dom
		},
        init(){
			this.visible = true
			Https.axiosGet(Https.httpUrls.getTasksList).then((rv)=>{

				this.taskList = this.sort(rv)
			})
		},
		sort(arr:any){
			arr.sort((a:any, b:any) => {
				var a_num = Date.parse(a.createDate);
				var b_num = b.style.zIndex;
				return a_num - b_num;
			});
			return arr
		},
		afterVisibleChange(bool:any){
			if(!bool){
				this.taskListMore = []
			}
			console.log(bool);
		},
		setTaskListMore(){
			// this.taskListMore = this.taskList
			
			this.taskListMore.push(...this.taskList,...this.taskList)
		},
		openTaskDetailPage(){
			let taskDetailPage:any = this.$refs.TaskDetailPage
			this.visible = false
			taskDetailPage.init()
		},
		visibleChange(){
			this.pageSize = 10
			this.currentPage = 1
			this.total = 0
		},
		getTaskList(){
			let data = {
				size:this.pageSize,
                page: this.currentPage,
				aaa:this.currentState,
			}
			console.log(123123);
			this.currentPage += 1
			Https.axiosGet()
		}
    },
});
</script>
<style lang="less">
.task_page {
	.ant-drawer-body{
		background: #f6f5fa;
	}
	.task_content{
		.task_content_item{
			background: #fff;
			margin: 2rem 0;
			padding: 1rem 2rem 1rem 1rem; 
			display: flex;
			justify-content: space-between;
			align-items: center;
			align-items: flex-start;
			position: relative;
			height: 12rem;
			border-radius: 1rem;
			overflow: hidden;
			img{
				width: 10rem;
				max-height: 100%;
				object-fit: contain;
				margin-right: 2rem;
			}
			.task_content_item_text{

				// display: flex;
				display: flex;
				justify-content: space-between;
				flex: 1;
				height: 100%;
				align-items: center;
				overflow: hidden;
				position: relative;
				.task_content_item_text_left,.task_content_item_text_right{
					margin-bottom: 0;
				}
				.task_content_item_text_left{
					flex: 1;
					overflow: hidden;
					margin-right: 2rem;
					div{
						overflow: hidden;
						white-space: nowrap; /* 禁止换行 */
						text-overflow: ellipsis; /* 显示省略号 */
					}
				}
				.task_content_item_text_right{
					width: 10rem;
					.task_content_item_text_left_titile,.task_content_item_text_left_into{
						text-align: right;
					}
					.text_click{
					}
					.task_content_item_text_left_into{
						cursor: pointer;
						transition: .3s all;
						opacity: 0;
						position: absolute;
						right: 0;
					}
				}
			}
		}
		.task_content_item:hover .task_content_item_text_left_into{
			opacity: 1 !important;
		}
		.task_content_more{
			background: #fff;
			width: 100%;
			line-height: 5rem;
			text-align: center;
			cursor: pointer;
			img{
				width: 100%;
				height: 5rem;
				object-fit: contain;
			}
		}
		.task_content_select{
			>div{
				width: 100%;
			}
		}
	}
}
	

</style>
<style lang="less">
.task_page,.layout_modal{
}
</style>