<template>
	<view>
		<view class="">
			<picker mode="date" fields="month" v-model="pickerCurrentTime" @change="bindDateChange">
				<uni-easyinput prefixIcon="search" :value="pickerCurrentTime"  :clearable ="false"></uni-easyinput>
			</picker>
		</view>
		<view>
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" top="80" @down="downCallback" @up="upCallback">
				<uni-list border-full v-for="(item,index) in goods" :key="index" >
					<uni-list-item clickable :title="item.tittle" :note="item.notecont" :rightText="item.monthdays" @click="lookflowcont(item)" />
				</uni-list>
			</mescroll-uni>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				pickerCurrentTime:"",
				headerVerify:{
					userkey:"",
					token:"",
					userCont:"",
					userInfo:""
				},
				upOption:{
					// page: {
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: '~ 搜索无数据 ~', // 提示
						btnText: '去看看'
					}
				},
				goods: [], //列表数据
			};
		},
		onLoad() {
			let _this = this
			//判断Token是否有效
			let systemCache = _this.$commonMethod.getSystemCacheDate('myCache')
			if(!systemCache){
				_this.$commonMethod.JumpUrl('/pages/login/login')
			}else{
				let currentTime = new Date().getTime() - systemCache.tokenTime
				if (currentTime >= 10800000){
					_this.$commonMethod.verifyPowerIsTrue('myCache')
				}
			}
			_this.headerVerify.userkey = systemCache.userKey
			_this.headerVerify.token = systemCache.token
			_this.headerVerify.userInfo = systemCache.userInfo
			_this.headerVerify.userCont = systemCache.userCont
			console.log(_this.headerVerify)
		},
		onReady(){
			// this.upCallback()
		},
		methods:{
			//获取年月
			getCurrentMonth () {
				const date = new Date()
				let year = date.getFullYear()
				let month = date.getMonth()
				this.yserDate = year
				this.monthDate = month
				month = month > 9 ? month : '0' + month
				return `${year}-${month}`
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				console.log(page,"page---------------->")
				let _this = this
				let sunTargetDate ={
					page:page.num,
					pagesize:10,
					state:0,
					title:"",
					department:"",
					time:_this.pickerCurrentTime,
					isset:0,
					class:0
				}
				//获取审批列表
				uni.request({
					url:_this.$commonMethod.localhostUrl+'/api/eval/seeflowlog',
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
						// 'User-Agent':250,
						'user-key': _this.headerVerify.userkey,
						'user-token':_this.headerVerify.token
					},
					method:'POST',//请求方式，必须为大写
					data:sunTargetDate,
					success: (res) => {
						console.log(res)
						let callBackDate = res.data
						if(callBackDate.code == 0){
							console.log("列表值---------------->",callBackDate.data)
							_this.mescroll.endBySize(callBackDate.data.count, callBackDate.data.total); //必传参数(当前页的数据个数, 总数据量)
							if(page.num == 1) _this.goods = [];
							let listAry = new Array
							callBackDate.data.list.forEach(itme=>{
								let notecont = ""
								switch(itme.cycle){
									case 1:
										notecont = itme.year+"年"
										break;
									case 4:
										notecont = itme.year+"年"+itme.month+"月"
										break;
									case 5:
										notecont = itme.year+"年"+itme.quarter+"季度"
										break;
									case 6:
										notecont = itme.year+"年"
										break;
									default:
										notecont = itme.year+"年"+itme.month+"月"
								}
								let listCont = {
									title:itme.tittle,
									monthdays:itme.monthdays,
									notecont:notecont,
									class:itme.class
								}
								listAry.push(listCont)
							})
							
							for(let i=0;i< callBackDate.data.list.length;i++){
								// callBackDate.data.list[i]
								switch(callBackDate.data.list[i].cycle){
									case 1:
										callBackDate.data.list[i].notecont = callBackDate.data.list[i].year+"年"
										break;
									case 4:
										callBackDate.data.list[i].notecont = callBackDate.data.list[i].year+"年"+callBackDate.data.list[i].month+"月"
										break;
									case 5:
										callBackDate.data.list[i].notecont = callBackDate.data.list[i].year+"年"+callBackDate.data.list[i].quarter+"季度"
										break;
									case 6:
										callBackDate.data.list[i].notecont = callBackDate.data.list[i].year+"年"
										break;
									default:
										callBackDate.data.list[i].notecont = callBackDate.data.list[i].year+"年"+callBackDate.data.list[i].month+"月"
								}
								// console.log("列表值-------->",i,callBackDate.data.list[i])
							}
							
							
							_this.goods=_this.goods.concat(callBackDate.data.list)
							console.log("列表值",_this.goods)
						}else{
							_this.mescroll.endBySize(0, 0);
							// _this.$refs.uToast.show({
							// 	message: callBackDate.msg,
							// 	duration: 1000 * 2,
							// 	position:'bottom',
							// })
						}
					},
					fail:function(e){
						_this.mescroll.endBySize(0, 0);
						_this.$refs.uToast.show({
							message: e,
							duration: 1000 * 2,
							position:'bottom',
						})
					}
				});
			},
			//点击空布局按钮的回调
			emptyClick(){
				uni.showToast({
					title:'点击了按钮,具体逻辑自行实现'
				})
			},
			//按时间擦找
			bindDateChange(e){
				this.pickerCurrentTime = e.detail.value
				this.goods = []// 先置空列表,显示加载进度
				this.mescroll.resetUpScroll() // 再刷新列表数据
			},
			//查看审批详情
			lookflowcont(data){
				console.log("查看审批详情",data)
				let _this = this
				if(data.class == 1){
					//定性
					_this.$commonMethod.JumpUrl('/pages/user/lookmydingxin?data='+JSON.stringify(data))
				}else{
					//定量
					_this.$commonMethod.JumpUrl('/pages/user/lookmydingliang?data='+JSON.stringify(data))
				}
			}
		},
		
	}
</script>

<style lang="scss">

</style>
