<template>
	<view>
		<view class="task-list">
			<view class="item" v-for="(item,index) in tabs" :key="index" >
				<view class="left">
					<image :src="item.icon" mode=""></image>
					<view class="title-l">{{item.name}}</view>
				</view>
				<view class="right" @click="showDetail(item.url)">
					<view class="num" v-if="item.num!==0">{{item.num}}</view>
					<image src="@/static/image/icon_more.png" mode=""></image>
				</view>
			</view>
		</view>
		<Server/>
	</view>
</template>

<script>
	import {getDictByKey} from '@/api/common.js'
	import {getQuestionsList} from '@/api/index.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import Server from '@/components/Server.vue'
	export default {
		mixins: [MescrollMixin], 
		components: {
			Server
		},
		data() {
			return {
				tabs:[
					{name:'在线讲座',num:12,icon:'/static/image/icon_task_zxjz.png',url:'/pages_task/onlineLecture'},
					{name:'空中课堂',num:3,icon:'/static/image/icon_task_kzkt.png',url:'/pages_task/airClassroom'},
					{name:'用药调研',num:8,icon:'/static/image/icon_task_yydy.png',url:'/pages_task/medicationSurvey'},
					{name:'问卷调查',num:0,icon:'/static/image/icon_task_wjdc.png',url:'/pages_task/airClassroom'},
					{name:'科普创作',num:0,icon:'/static/image/icon_task_kpcz.png',url:'/pages_task/science'},
				],
				typeOptions:[],
				questionsType:0,
				keyword: '',
				mescroll:null,
				downOption: {   //下拉刷新
				 	use:true,
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					onScroll:false,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					textNoMore:"已经到底了",
					empty: {
						icon:'https://user.test.ylrztop.com/images/empty_icon.png',
						tip: '暂无数据'
					}
				},
				dataList: []
			};
		},
		onShow() {
			this.getDictByKey("sys_questions_type");
		},
		methods:{
			getDictByKey(key){
				var data={key:key}
				getDictByKey(data).then(
					res => {
						if(res.code==200){
							if(key=="sys_questions_type"){
								this.typeOptions=res.data;
							}
						 
						}
					},
					err => {
					}
				);
				
			},
			doSearch(){
				this.mescroll.resetUpScroll()
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					keyword:this.keyword,
					questionsType:this.questionsType,
					pageNum: page.num,
					pageSize: page.size
				};
				getQuestionsList(data).then(res => {
					if(res.code==200){
						//设置列表数据
						if (page.num == 1) {
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						that.mescroll.endBySize(res.data.list.length, res.data.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			// 关键词选择
			choseType(item) {
				this.questionsType = item.dictValue;
				this.mescroll.resetUpScroll()
			},
			// 查看详情
			showDetail(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss">
	.task-list{
		padding: 24rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: flex-start;
		width: 100%;
		  box-sizing: border-box; 
		.item{
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background: #FFFFFF;
			box-shadow: 0rpx 8rpx 16rpx 0rpx rgba(199,226,254,0.22);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			padding:28rpx 32rpx;
			box-sizing: border-box; // 核心：padding不撑宽item
			margin-bottom: 24rpx;
			.left{
				display: flex;
				align-items: center;
				justify-content: center;
				image{
					width: 72rpx;
					height: 72rpx;
					margin-right: 28rpx;
				}
				.title-l{
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
				}
			}
			.right{
				display: flex;
				align-items: center;
				.num{
					text-align: center;
					width: 50rpx;
					height: 36rpx;
					line-height: 36rpx;
					background: rgba(56,139,255,0.16);
					border-radius: 34rpx 34rpx 34rpx 34rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #388BFF;
				}
				image{
					width: 32rpx;
					height: 32rpx;
					margin-left: 12rpx;
				}
			}
		}
	}
</style>
