<template>
	<view class="allTaskList" ref="allTaskList">
		<custom-tabs type="allTaskListViewRef" :value="pageData.current" fixed="true" :activeTextStyle="{color:'rgba(190, 163, 117, 1)'}" :activeLineStyle="{'background-color':'rgba(190, 163, 117, 1)',height:'6rpx'}" @change="changeIndex">
			<!-- 全部 -->
			<custom-tab-pane label="全部" name="allTaskListViewRef_1" class="allTaskList_tab">
				<TotalTask :taskList="pageData.taskList"></TotalTask>
				<view v-if="pageData.taskList.length!=0">
					<uni-load-more :status="loadingData.status" :contentText="loadingData.contentText"></uni-load-more>
				</view>
			</custom-tab-pane>
			<!-- 待整改 -->
			<custom-tab-pane label="待整改" name="allTaskListViewRef_2" class="allTaskList_tab">
				<DaiZgTask :taskList="pageData.taskList"></DaiZgTask>
				<view v-if="pageData.taskList.length!=0">
					<uni-load-more :status="loadingData.status" :contentText="loadingData.contentText"></uni-load-more>
				</view>
			</custom-tab-pane>
			<!-- 审核中 -->
			<custom-tab-pane label="审核中" name="allTaskListViewRef_3" class="allTaskList_tab">
				<ShenheTask :taskList="pageData.taskList"></ShenheTask>
				<view v-if="pageData.taskList.length!=0">
					<uni-load-more :status="loadingData.status" :contentText="loadingData.contentText"></uni-load-more>
				</view>
			</custom-tab-pane>
			<!-- 完成 -->
			<custom-tab-pane label="完成" name="allTaskListViewRef_4" class="allTaskList_tab">
				<WanchenTask :taskList="pageData.taskList"></WanchenTask>
				<view v-if="pageData.taskList.length!=0">
					<uni-load-more :status="loadingData.status" :contentText="loadingData.contentText"></uni-load-more>
				</view>
			</custom-tab-pane>
		</custom-tabs>
	</view>
</template>

<script setup>
import http from '@/utils/request';
import {djtabbar} from '@/pages/index/tabShow.js'
import {ref,reactive,getCurrentInstance, computed, nextTick,watch} from "vue";
import {onLoad,onShow,onUnload,onPageScroll,onReachBottom,onPullDownRefresh,onReady} from "@dcloudio/uni-app";
import TotalTask from './totalTask.vue'
import DaiZgTask from './daiZgTask.vue'
import ShenheTask from './shenheTask.vue'
import WanchenTask from './wanchenTask.vue'

const allTaskListViewRef_1 = ref(null)

const loadingData = reactive({
	// 加载true，到底false
	reload: false,
	status: 'more',
	contentText: {
		contentdown: '上拉加载更多',
		contentrefresh: '加载中',
		contentnomore: '已经全部加载完毕'
	}
})

const pageData=reactive({
	current:-1,
	taskList:[]
})

const formData=reactive({
	pageSize: 10,
	pageNum: 1,
	status:''
})

// 切换tab
const changeIndex=(e)=>{
	pageData.current=e.value
	if(e.value==0){
		delete formData.status
	}
	if(e.value==1){
		formData.status='0'
	}
	if(e.value==2){
		formData.status='1'
	}
	if(e.value==3){
		formData.status='2'
	}
	pageData.taskList=[]
	getZgTask()
}

// 获取整改任务
const getZgTask=()=>{
	http.get("app-api/rectify/findZgTaskList",formData).then(res=>{
		pageData.taskList=pageData.taskList.concat(res.data)
		if(formData.hasOwnProperty(status)==false){
			pageData.taskList.forEach(item=>{
				if(item.status=='0'){
					item.statusIcon='/static/gai_icon.png'
				}else if(item.status=='1'){
					item.statusIcon='/static/shen_icon.png'
				}else{
					item.statusIcon='/static/wan_icon.png'
				}
			})
		}
		if (formData.pageSize > res.data.length) {
			loadingData.reload = false
			loadingData.status = 'noMore'
			uni.stopPullDownRefresh();
		} else {
			loadingData.status = 'more'
			loadingData.reload = true
		}
	})
	getZgNumber()
	uni.stopPullDownRefresh();
}

// 获取待整改任务数量
const getZgNumber=()=>{
	// api/app-api/rectify/getZgNumber
	http.get("app-api/rectify/getZgNumber").then(res=>{
		if(res==0){
			uni.removeTabBarBadge({
				index:3
			})
		}else{
			uni.setTabBarBadge({
				index:3,
				text:res.toString()
			})
		}
	})
}

onShow(()=>{
	djtabbar()
	pageData.current=0
	delete formData.status
	pageData.taskList=[]
	getZgTask()
})

// 下拉刷新
onPullDownRefresh(()=>{
	console.log("下拉刷新");
	formData.pageNum = 1;
	loadingData.reload = true
	pageData.taskList = []
	getZgTask();
})

// 上拉加载
onReachBottom(()=>{
	console.log("上拉加载");
	if (loadingData.reload) {
		formData.pageNum++;
		loadingData.status = 'loading'
		getZgTask();
	}
})
</script>

<style lang="scss" scoped>
@import 'index.scss';
</style>
