<template>
	<view class="allpage">
		<view class="zhanline"></view>
		<view class="alllist">
			<!-- l列表 -->
			<project-list type='ldwritten' :datalist="list" :wtdt='wtdt' @getDetail="getDetail"></project-list>
			
		</view>
		<!-- 弹窗 -->
		<pop-up :type="type" fromstr='zdldps' :status="status" @getClose='getClose' :iteminfo="iteminfo"  @getLinSubmit='getLinSubmit' @getldDelFn="getldDelFn"></pop-up>
	</view>
</template>

<script>
	import projectList from "@/components/projectlist/zdlist.vue"
	import {getlistzdldpsFn,getldpsFn,getputzdldpsFn,getdelzdldpsFn} from "@/api/zdwork/clue.js"
	import popUp from "@/components/popup/popup.vue"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	export default{
		data(){
			return{
				pageSize: 10,
				pageNum: 1,
				reachflag:true,
				itemslist:[],
				wtdt:'',
				tabidx:0,
				date:'',
				list:[],
				year:'',
				name:'',
				census:'',
				type:0,
				iteminfo:{},
				status:'add',
				deptId:this.$store.state.user.deptId,
				datainfo:{
					xmId:'',
					// xmbh:'',
					xmmc:'',
				}
			}
		},
		components:{
			projectList,popUp
		},
		onUnload(){
			
		},
		onLoad(e) {
			var newobj=JSON.parse(decodeURIComponent(e.data))
			this.datainfo=newobj;
			this.getDataFn();
		},
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			getClose(){
				this.type=0;
			},
			getDetail(data){
				//判断权限
				if(checkPermi(['fgw:ldps:edit'])||checkPermi(['fgw:ldps:remove'])){
					this.iteminfo=data;
					this.type=7;
					this.status='update'
				}
			},
			getLinSubmit(data){
				var that=this;
				
				var params={};
				var str=''
				if(data.type==0){//暂存
					params.zcpsnr=data.psnr;
					params.type=1;
					str='批示暂存成功'
				}else{
					params.psnr=data.psnr;
					params.type=2;
					str='批示提交成功'
				}
				params.xmId=this.datainfo.xmId;
				// params.xmbh=this.datainfo.xmbh;
				// params.xmmc=this.datainfo.xmmc;
				//修改
				params.id=this.iteminfo.id
				getputzdldpsFn(params).then(res=>{
					if(res.code==200){
						that.$toast(str)
						setTimeout(function(){
							that.pageNum=1;
							that.reachflag=true;
							that.list=[];
							that.getDataFn();
							// 刷新列表数据
							if(data.type!=0){
								uni.$emit('refreshdatalistzd','ldps');
							}
							that.type=0;
						},1500)
					}else{
						this.$toast(res.msg)
					}
				})	
			},
			getldDelFn(){
				var params={};
				var that=this;
				params.id=this.iteminfo.id;
				params.xmId=this.datainfo.xmId
				getdelzdldpsFn(params).then(res=>{
					if(res.code==200){
						that.$toast('批示撤回成功')
						setTimeout(function(){
							uni.$emit('refreshdatalistzd','ldps');;
							that.pageNum=1;
							that.reachflag=true;
							that.list=[];
							that.getDataFn()
							that.type=0;
						},1500)
					}else{
						this.$toast(res.msg)
					}
				})
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
					xmId:this.datainfo.xmId,
					// xmbh:this.datainfo.xmbh
				}
				getlistzdldpsFn(params).then(res=>{
					if(res.code==200){
						if (res.rows.length < this.pageSize) {
							this.reachflag = false
							this.wtdt = '到底了~';
						} else {
							var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
							if (num < res.total) {
								this.reachflag = true
								this.wtdt = '上拉加载更多'
							} else {
								this.reachflag = false
								this.wtdt = '到底了~';
							}
						}
						if (this.pageNum == 1) {
							this.list = res.rows;
						} else {
							this.list = this.list.concat(res.rows)
						}
					}else{
						this.$toast(res.msg)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.allpage{min-height: 100vh;background: #ffffff;box-sizing: border-box;}
.listtopa{border: 6rpx solid #FD5001;border-radius: 36rpx;height:72rpx;box-sizing: border-box;padding:0 140rpx 0 32rpx ;position: relative;
 input{}
 image{width: 30rpx;height: 30rpx;margin-right: 24rpx;}
 .btn{background: #FA5F03;border-radius: 36rpx;width: 140rpx;position: absolute;right: -2rpx;top: -2rpx;bottom:-2rpx;}
 }
 .listtopb{
	 .tit{flex: 1;height: 130rpx;display: flex;flex-direction: column;justify-content: center;position: relative;
	 view{text-align: center;}
	 .tits{color: #666666;}
	 .txt{color: #aaaaaa;}
	 &.act{
		 &::after{content: '';width: 100rpx;height: 6rpx;background:#FE5706 ;position: absolute;left: 50%;margin-left: -50rpx;bottom: 0;}
		.tits{color: #343434;}
		.txt{color: #FE5706;} 
	 }
	 }
 }
 .alllist{padding-top:10rpx ;}
  // 操作按钮
  .cluebtn{
  	display: flex;align-items: center;justify-content: center;font-weight: bold;font-size: 32rpx;color: #ffff;height: 100rpx;position: fixed;left: 0;right: 0;bottom: 0;z-index: 3;
  	&.btn1{background-color: #1FB9F7;flex: 1;}
  	&.btn2{background-color:#FF6400;flex: 1;}
  }
</style>