<template>
	<view class="content">
		<view class="top-fixed">
			 <u-tabs
			  :scrollable="false"
			  :list="tabs"  
			  lineColor="#FF5C03"
			 @change="statusChange">
			 </u-tabs>
		</view>
		<mescroll-body top="88rpx" bottom="0" ref="mescrollRef" @init="mescrollInit"    :down="downOption" :up="upOption" @down="downCallback" @up="upCallback">
		<view class="order-list">
			<view class="order-item"  v-for="(item) in dataList" @click="navTo('./inquiryOrderDetails?orderId='+item.orderId)">
				<view class="order-top"  >
					<view class="left"  >
						<view class="title" >
							{{item.tempName}}   
						</view>
					</view>
					<view class="status red" v-if="item.writeStatus==0">
						未完成
					</view>
					<view class="status green" v-if="item.writeStatus==1">
						已完成
					</view>
				</view>
				<view class="order-cont">
					<view class="order-time-box">
						<view class="order-time">
							<view class="time">{{item.planTime}}   </view>
							<view class="count"> {{item.num}}/{{item.totalNum}}期</view>
						</view>
						<view class="right">
							<view class="btn red" v-if="item.writeStatus==0" @click.stop="doFoloow(item)">去填写</view>
							<view class="btn green" v-if="item.writeStatus==1" @click.stop="showDetails(item)">查看</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {getFollowList} from '@/api/follow.js'
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				tabs:[
					{
						id:-1,
						name:'全部'
					},
					{
						id:0,
						name:'未完成'
					},
					{
						id:1,
						name:'已完成'
					}
					 
				],
				writeStatus:-1,
				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://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
						tip: '暂无数据'
					}
				},
				dataList: []
			}
		},
		onLoad() {
			var that=this;
			uni.$on('refreshFollowList', () => {
				that.mescroll.resetUpScroll()
			})
		},
		onShow() {
		},
		methods: {
			doFoloow(item){
				uni.navigateTo({
					url: "./doFollow?followId="+item.followId
				})
			},
			showDetails(item){
				uni.navigateTo({
					url: "./followDetails?followId="+item.followId
				})
			},
			statusChange(item){
				this.writeStatus=item.id
				console.log(item)
				this.mescroll.resetUpScroll()
			},
			navTo(url){
				uni.navigateTo({
					url: url
				})
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调*/
			upCallback(page) {   
				//联网加载数据
				var that = this;
				var data = {
					pageNum: page.num,
					pageSize: page.size
				};
				if(this.writeStatus!=-1){
					data.writeStatus=this.writeStatus
				}
				getFollowList(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();
					}
				});
			},
			
		}
	}
</script>

<style lang="scss">
	page{
		
		height: 100%;
		background: #f6f6f6;
	}
</style>
<style scoped lang="scss">
	.content{
		height: 100%;
		.top-fixed{
			width: 100%;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 10;
			height: 88upx;
			background-color: #fff;
		}
		.order-list{
			width: 100%;
			padding: 15rpx;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			justify-content: flex-start;
			.order-item{
				margin-bottom: 20rpx;
				width: 100%;
				padding: 20rpx;
				box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
				background-color: #fff;
				border-radius: 15rpx;
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				justify-content: flex-start;
				.order-top{
					display: flex;
					align-items: center;
					justify-content: space-between;
					width: 100%;
					padding-bottom: 15rpx;
					border-bottom: 1px solid #efefef;
					.left{
						display: flex;
						align-items: center;
						justify-content: flex-start;
						.title{
							font-size: 32upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #111111;
						}
						 
					}
					.status{
						font-size: 28upx;
						font-family: PingFang SC;
					}
					.red{
						
						color: #db5053;
					}
					.green{
						color: #FF5C03;
					}
					 
				}
				.order-cont{
					width: 100%;
					margin-top: 20rpx;
					.order-time-box{
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						.order-time{
							display: flex;
							align-items: center;
							justify-content: flex-start;
							.time{
								font-size: 28upx;
								font-family: PingFang SC;
								color: #9a9a9c;
							}
							.count{
								margin-left: 10rpx;
								font-size: 28upx;
								font-family: PingFang SC;
								color: #111;
							}
						}
						.right{
							.btn{
								padding: 10rpx 30rpx;
								font-size: 28rpx;
								border-radius: 30rpx;
							}
							.red{
								background-color: #FF5C03;
								color: #fff;
							}
							.green{
								border: 1rpx solid #FF5C03;
								color: #FF5C03;
							}
						}
					}
				}
				
			}
		} 
		
	}
	 
</style>
