<template>
	<view class="content">
		<view class="title">
			<view class="item" :class="active_item == 0?'active':''" @click="click_btn(0)">全部</view>
			<view class="item" :class="active_item == 1?'active':''" @click="click_btn(1)">待审核</view>
			<view class="item" :class="active_item == 2?'active':''" @click="click_btn(2)">已通过</view>
			<view class="item" :class="active_item == 3?'active':''" @click="click_btn(3)">被驳回</view>
		</view>
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index" v-if="active_item == 0" :style="item.state == 3?'border-top-color: red;':''">
				<view class="top">
					<view class="user">
						<view class="img" v-if="item.staff_avatar">
							<image :src="item.staff_avatar" mode="aspectFill"></image>
						</view>
						<view class="info">
							<view class="text">{{item.section}}{{item.staff}}</view>
							<view class="text">编号：#{{item.id}} {{item.created_at}}</view>
						</view>
					</view>
					<view class="state" v-if="item.state == 1">{{item.status}}</view>
					<view class="state" v-if="item.state == 2">{{item.status}}</view>
					<view class="state" v-if="item.state == 3" style="color: red;">{{item.status}}</view>
				</view>
				<view class="inner">
					<view class="class_name">{{item.classify}} : </view>
					<view class="name">{{item.title}}</view>
					<view class="tip">{{item.introduce}}</view>
				</view>
				<view class="bottom">
					<view class="btn" style="background-color: #FDDD9B; margin-right: 10px;" v-if="item.state == 1" @click="del_btn(item.id,item.title)">撤回</view>
					<view class="btn" @click="go_chakan(item.id,item.title)">查看</view>
				</view>
			</view>
			<view class="item" v-for="(item,index) in list" :key="index" v-if="active_item == 1 && item.state == 1">
				<view class="top">
					<view class="user">
						<!-- <view class="img">
							<image :src="item.staff_avatar" mode="aspectFill"></image>
						</view> -->
						<view class="info">
							<view class="text">{{item.section}}{{item.staff}}</view>
							<view class="text">编号：#{{item.id}} {{item.created_at}}</view>
						</view>
					</view>
					<view class="state" v-if="item.state == 1">{{item.status}}</view>
				</view>
				<view class="inner">
					<view class="class_name">{{item.classify}} : </view>
					<view class="name">{{item.title}}</view>
					<view class="tip">{{item.introduce}}</view>
				</view>
				<view class="bottom">
					<view class="btn" style="background-color: #FDDD9B; margin-right: 10px;" v-if="item.state == 1" @click="del_btn(item.id,item.title)">撤回</view>
					<view class="btn" @click="go_chakan(item.id,item.title)">查看</view>
				</view>
			</view>
			<view class="item" v-for="(item,index) in list" :key="index" v-if="active_item == 2 && item.state == 2">
				<view class="top">
					<view class="user">
						<!-- <view class="img">
							<image :src="item.staff_avatar" mode="aspectFill"></image>
						</view> -->
						<view class="info">
							<view class="text">{{item.section}}{{item.staff}}</view>
							<view class="text">编号：#{{item.id}} {{item.created_at}}</view>
						</view>
					</view>
					
					<view class="state" v-if="item.state == 2">{{item.status}}</view>
				</view>
				<view class="inner">
					<view class="class_name">{{item.classify}} : </view>
					<view class="name">{{item.title}}</view>
					<view class="tip">{{item.introduce}}</view>
				</view>
				<view class="bottom">
					<view class="btn" @click="go_chakan(item.id,item.title)">查看</view>
				</view>
			</view>
			<view class="item" v-for="(item,index) in list" :key="index" v-if="active_item == 3 && item.state == 3" style="border-top-color: red;">
				<view class="top">
					<view class="user">
						<!-- <view class="img">
							<image :src="item.staff_avatar" mode="aspectFill"></image>
						</view> -->
						<view class="info">
							<view class="text">{{item.section}}{{item.staff}}</view>
							<view class="text">编号：#{{item.id}} {{item.created_at}}</view>
						</view>
					</view>
					
					<view class="state" v-if="item.state == 3" style="color: red;">{{item.status}}</view>
				</view>
				<view class="inner">
					<view class="class_name">{{item.classify}} : </view>
					<view class="name">{{item.title}}</view>
					<view class="tip">{{item.introduce}}</view>
				</view>
				<view class="bottom">
					<view class="btn" @click="go_chakan(item.id,item.title)">查看</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				active_item:0,
				list:[],
				
				
				page:1,
				page_size:10,
				state:0
			};
		},
		onLoad() {
			this.get_worksheet_apply_listmei()
		},
		onReachBottom(){
			console.log("++")
			this.page++
			this.get_worksheet_apply_listmei()
		},
		methods:{
			// 切换列表
			click_btn(item){
				this.active_item = item
				this.state = item
				this.page = 1
				this.list = []
				// 刷新数据
				this.get_worksheet_apply_listmei()
			},
			go_chakan(id,title){
				console.log(id,title)
				
				uni.navigateTo({
					url:"chakan/chakan?id=" + id + "&title=" + title
				})
			},
			get_worksheet_apply_listmei(){
				uni.showLoading()
				
				this.$api.worksheet_apply_listmei({
					page:this.page,
					size:this.page_size,
					state:this.state,
				}).then((res)=>{
					// console.log(res.data.data)
					if(this.page == 1 && res.data.data == 0){
						this.list = []
					}else{
						this.list = this.list.concat(res.data.data)
					}
					
					uni.hideLoading()
				})
			},
			
			// 撤回
			del_btn(id,title){
				console.log(id,title)
				
				uni.showModal({
				    title: '撤回提醒',
				    content: '是否撤回' + title + '?',
				    success: (res) => {
				        if (res.confirm) {
				            // console.log('用户点击确定');
							this.$api.worksheet_orderdel({
								id:id
							}).then((res)=>{
								// console.log(res)
								
								this.get_worksheet_apply_listmei()
							})
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
				
			}
		}
	}
</script>

<style lang="scss">
	.content{
		width: 749rpx;
	}
	
	.title{
		height: 43px;
		display: flex;
	
		border-bottom: 1px solid #E4E4E4;
		.item{
			width: 249rpx;
			line-height: 43px;
			text-align: center;
			font-size: 16px;
			color: #BDC3C7;
		}
		.active{
			border-bottom: 2px solid #16A085;
			color: #16A085;
		}
	}
	
	.list{
		box-sizing: border-box;
		padding: 24rpx;
		.item{
			width: 700rpx;
			border-radius: 6px;
			border: 1px solid #EDEFF9;
			border-top: 2px solid #00D983;
			
			box-sizing: border-box;
			padding: 10px 25rpx;
			
			margin-bottom: 15px;
			.top{
				display: flex;
				justify-content: space-between;
				.user{
					display: flex;
					.img{
						width: 60px;
						height: 60px;
						border-radius: 50%;
						overflow: hidden;
						image{
							width: 60px;
							height: 60px;
						}
					}
					.info{
						margin-left: 10rpx;
						height: 60px;
						.text{
							line-height: 25px;
							font-size: 12px;
						}
					}
				}
				.state{
					width: 150rpx;
					text-align: right;
					line-height: 25px;
					font-size: 12px;
					color: #2ECC71;
				}
				
			}
			.inner{
				margin: 10px auto;
				width: 650rpx;
				border: 1px solid #EDEFF9;
				border-radius: 6px;
				box-sizing: border-box;
				padding: 10px;
				font-size: 12px;
				.class_name{
					line-height: 20px;
					color: #3498DB;
				}
				.name{
					line-height: 20px;
				}
				.tip{
					line-height: 20px;
					text-indent: 2em;
				}
			}
			.bottom{
				text-align: right;
				.btn{
					display: inline-block;
					width: 80px;
					text-align: center;
					line-height: 30px;
					font-size: 12px;
					color: #FFFFFF;
					background-color: #3498DB;
				}
			}
		}
	}
</style>
