<template>
	<view class="allpage">
		<view class="zhanline"></view>
		<view class="alllist">
			<!-- l列表 -->
			<project-list type='skdwzj'  :datalist="list" :wtdt='wtdt' @getDetail="getDetail"></project-list>
			
		</view>
		<skdwzi-pop :iteminfo="dwzjinfo" :isSh="isSh" :status="status" @getldDelFn="getldDelFn" @proSure="proSure" @getClose="getClose" :addzjdwflag='addzjdwflag'></skdwzi-pop>
		<!-- 新增 -->
		<block v-if="checkPermi(['projectV2:dzje:add'])&&isSh==2">
			<view style="height: 100rpx;"></view>
			<view class="cluebtn btn2"   @click="getAdddwzi">添加到位资金</view?>
		</block>
		
	</view>
</template>

<script>
	import projectList from "@/components/projectlist/list.vue"
	import {getdzjeList,getputdzjeFn,getdeldzjeFn,getadddzjeFn} from "@/api/work/addsk.js"
	import skdwziPop from "@/components/popup/skdwzjpop.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,
				status:'update',
				deptId:this.$store.state.user.deptId,
				id:"",
				dwzjinfo:{},
				addzjdwflag:false,
				isSh:''
			}
		},
		components:{
			projectList,skdwziPop
		},
		onUnload(){
			
		},
		onLoad(e) {
			if(e.data){
				var newobj=JSON.parse(decodeURIComponent(e.data));
				this.id=newobj.id;
				this.isSh=newobj.isSh||'1';
				this.xmmc=newobj.xmmc||''
				this.getDataFn();
			}
			
		},
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			getClose(){
				this.type=0;
			},
			getDetail(data){
				//判断权限
				if(checkPermi(['projectV2:dzje:edit','projectV2:dzje:remove'])){
					this.status='update'
					this.addzjdwflag=true;
					this.dwzjinfo=data;
				}
			},
			getClose(){
				this.addzjdwflag=false;
				this.dwzjinfo={};
			},
			getAdddwzi(){
				this.status='add'
				this.dwzjinfo={
					"dwmc":'',//单位名称
					"zzje":'',//注资金额
					"dwrq":'',//到位日期
				};
				this.addzjdwflag=true
			},
			proSure(data){
				var that=this;
				var params=JSON.parse(JSON.stringify(data));
				// params.skId=this.datainfo.skId;
				// params.xmmc=this.datainfo.xmmc;
				// params.id=this.dwzjinfo.id
				// 修改
				if(this.status=='add'){
					params.skId=this.id;
					params.xmmc=this.xmmc;
					getadddzjeFn(params).then(res=>{
						if(res.code==200){
							that.$toast("添加到位资金成功")
							setTimeout(function(){
								uni.$emit('refreshdata','dwzj');
								that.dwzjinfo={};
								that.pageNum=1;
								that.reachflag=true;
								that.list=[];
								that.getDataFn();
								that.addzjdwflag=false;
							},1500)
						}else{
							this.$toast(res.msg)
						}
					})
				}else{
					getputdzjeFn(params).then(res=>{
						if(res.code==200){
							that.$toast("到位资金修改成功")
							setTimeout(function(){
								uni.$emit('refreshdata','dwzj');
								that.pageNum=1;
								that.reachflag=true;
								that.list=[];
								that.getDataFn();
								that.addzjdwflag=false;
							},1500)
						}else{
							this.$toast(res.msg)
						}
					})	
				}
				
				// 新增
			},
			getldDelFn(){
				var params={};
				var that=this;
				// params.id=this.dwzjinfo.id;
				// params.skId=this.id;
				// var s=[]
				// s[0]=this.id
				getdeldzjeFn(this.dwzjinfo.id).then(res=>{
					if(res.code==200){
						that.$toast('到位资金删除成功')
						setTimeout(function(){
							uni.$emit('refreshdata','dwzj');
							that.pageNum=1;
							that.reachflag=true;
							that.list=[];
							that.getDataFn()
							that.addzjdwflag=false;
						},1500)
					}else{
						this.$toast(res.msg)
					}
				})
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
					skId:this.id,
				}
				getdzjeList(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>