<template>
	<view class="probox">
		<view class="zhanline" v-if="shenhelist.length"></view>
		<!-- 步骤条 -->
		<view class="step" v-if="shenhelist.length">
			<view class="steplist flex" v-for="(ite,idx) in shenhelist" :key="idx">
				<view class="stepl">
					<!-- 待审核 -->
					<image :src="statimga" v-if="ite.shjg==1"></image>
					<!-- 已通过 -->
					<image :src="statimgc" v-else-if="ite.shjg==2"></image>
					<!-- 未通过 -->
					<image :src="statimgb" v-else></image>
				</view>
				<view class="stepr">
					<view class="mb6 flexc">
						<view class="f17 c34 f500 flex1">{{ite.shrxm}}</view>
						<!-- 领导进来才有批示 -->
						<!-- <block v-if="checkPermi(['system:ldps:update'])">
							<view class="flex0 titp" @click="getPiFn('update',ite)" v-if="ite.zsyzLdpsList[0].psnr">
								<image :src="xpsimg"></image>
								<view>修改批示</view>
							</view>
						</block>
						<block v-if="checkPermi(['system:ldps:add'])">
							<view class="flex0 titp" @click="getPiFn('add',ite)" v-if="!ite.zsyzLdpsList[0].psnr">
								<image :src="psimg"></image>
								<view>批示</view>
							</view>
						</block> -->
						<!-- <block v-if="roles=='leader'">
							
							
						</block> -->
						
					</view>
					<view class="flex mb6"><view class="flex0 f15 ca">是否通过：</view>
						<view class="f15 c34 f500" >{{ite.xmjd}}
							<block v-if="ite.shjg==1">待审核</block>
							<block v-if="ite.shjg==2">已通过</block>
							<block v-if="ite.shjg==3">未通过</block>
						</view>
					</view>
					<view class="flex mb6"><view class="flex0 f15 ca">审核时间：</view>
						<view class="f15 c34 f500" >{{ite.shsj}}</view>
					</view>
					<view class="flex mb6" v-if="ite.shyj"><view class="flex0 f15 ca">反馈意见：</view><view class="f15 c34 f500">{{ite.shyj}}</view></view>
					<!-- <block v-if="ite.zsyzLdpsList.length">
						<view class="flex mb6"  v-for="(pite,pidx) in ite.zsyzLdpsList" :key="'info-'+pidx"><view class="flex0 f15 ca">领导批示：</view><view class="f15 c34 f500" >{{pite.psnr}}</view></view>
					</block> -->
				</view>
			</view>
		</view>
		<block v-else>
			<no-data ></no-data>
		</block>
		<!-- 弹窗 -->
		<pop-up :status="status"  :iteminfo='iteminfo'  :type="type" @getClose='getClose' @getLinSubmit="getLinSubmit" @getldDelFn="getldDelFn"></pop-up>
	</view>
</template>

<script>
	import popUp from "@/components/popup/popup.vue"
	import { getshyjList,getldpsFn,getldpsputFn,getldpsdelFn} from '@/api/work/clue.js'
	import noData from "@/components/nodata/nodata.vue"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	export default{
		data(){
			return{
				psimg:require("@/static/images/mine/psicon.png"),
				xpsimg:require("@/static/images/mine/xpicon.png"),
				statimga:require("@/static/images/mine/ywicon.png"),//审核
				statimgb:require("@/static/images/mine/cicon.png"),//未通过
				statimgc:require("@/static/images/mine/jicon.png"),//通过
				type:0,
				status:'add',
				id:'',//线索id
				xmId:'',//项目id,
				roles:this.$store.state.user.roles[0],
				shenhelist:[],
				iteminfo:{},
				xmbh:"",
				xmmc:'',
				sourceId:'',
				deptId:this.$store.state.user.deptId,
				pageSize: 10,
				pageNum: 1,
				reachflag:true,
				
			}
		},
		components:{
			popUp,noData
		},
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		onLoad(e) {
			// this.id=e.id;
			this.xmId=e.id;
			this.getDataFn()
		},
		methods:{
			checkPermi, checkRole,
			getDataFn(){
				var params={
					xmId:this.xmId,
					deptId:this.deptId,
					pageSize:this.pageSize,
					pageNum: this.pageNum,
				}
				getshyjList(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.shenhelist = res.rows;
						} else {
							this.shenhelist = this.shenhelist.concat(res.rows)
						}
					}else{
						this.$toast(res.msg)
					}
					// if(res.code==200){
					// 	this.shenhelist=res.rows;
					// }else{
					// 	this.$toast(res.msg)
					// }
				})
			},
			getClose(){
				this.type=0;
			},
			getldDelFn(){
				var params={};
				var that=this;
				params.id=this.iteminfo.ids;
				getldpsdelFn(params).then(res=>{
					if(res.code==200){
						that.$toast('批示撤回成功')
						setTimeout(function(){
							that.getDataFn()
							that.type=0;
						},1500)
					}else{
						this.$toast(res.msg)
					}
				})
			},
			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='批示提交成功'
				}
				if(this.status=='add'){
					params.xmId=this.xmId;
					params.sourceId=this.sourceId;
					params.xmbh=this.xmbh;
					params.xmmc=this.xmmc;
					getldpsFn(params).then(res=>{
						if(res.code==200){
							that.$toast(str)
							setTimeout(function(){
								that.getDataFn()
								that.type=0;
							},1500)
						}else{
							this.$toast(res.msg)
						}
					})
				}else{
					//修改
					params.id=this.iteminfo.ids
					getldpsputFn(params).then(res=>{
						if(res.code==200){
							that.$toast(str)
							setTimeout(function(){
								that.getDataFn()
								that.type=0;
							},1500)
						}else{
							this.$toast(res.msg)
						}
					})
				}
				
			},
			getPiFn(e,ite){
				this.sourceId=ite.id;
				this.xmbh=ite.xmbh;
				this.xmmc=ite.xmmc;
				if(ite.zsyzLdpsList.length){
					this.iteminfo=ite.zsyzLdpsList[0]
				}else{
					this.iteminfo={};
				}
				if(this.iteminfo.ids){
					this.status='update';
				}else{
					this.status='add';
				}
				this.type=3
			}
		}
	}
</script>

<style lang="scss" scoped>
.probox{background-color: #ffffff;min-height: 100vh;}
.step{padding: 56rpx 44rpx 40rpx 44rpx;
	.steplist{position: relative;padding-bottom: 24rpx;
		&::before{width: 2rpx;height: 100%;background: #E5E5E5;content: '';position: absolute;left: 18rpx;top: 18rpx;}
		&:last-of-type::before{display: none;}
		.stepl{ flex:0 0 auto;margin-right: 26rpx;width: 34rpx;height: 34rpx;border-radius: 50%;background-color: #ffffff;z-index: 1;
			image{width: 36rpx;height: 36rpx;border-radius: 50%;}
		}
		.stepr{flex: 1;
			.titp{display: flex;align-items: center;height: 48rpx;min-width: 120rpx;justify-content: center;
				image{width: 32rpx;height: 32rpx;}
				view{font-size: 30rpx;color: #1FB9F7 ;margin-left: 12rpx;}
			}
		}
	}
	
	
}
</style>