<template>
	<view class="listbox">
		<view class="fixedt">
			<!-- tab -->
			<view class="tablists flexc">
				<block v-for="(ite,idx) in tabList" >
					<view  v-if="!ite.limit||ite.limit&&checkPermi([ite.limit])" @click="getTabFn(ite.val)" :class="{act:tabval==ite.val}" :key="idx">{{ite.tit}}</view>
				</block>
			</view>
			<!-- 选择器 -->
			<view class="flexc checkbox">
				<picker mode="date"   @change='bindDateChangea'>
					<view class="chekt">
						<view>{{sbsj|| "申报时间"}}</view>
						<image :src="upimg"></image>
					</view>
				</picker>
				<picker range-key='label' :value="shidx" :range="shlist"  @change='bindDateChangeb'>
					<view class="chekt">
						<view>{{shzt || "审核状态"}}</view>
						<image :src="upimg"></image>
					</view>
				</picker>
				<picker range-key='label' :value="sdyhidx" :range="sdyhlist"  @change='bindDateChangec'>
					<view class="chekt">
						<view>{{sdyh || "申贷银行"}}</view>
						<image :src="upimg"></image>
					</view>
				</picker>
				<picker range-key='label' :value="dblxidx" :range="dblxlist"  @change='bindDateChanged'>
					<view class="chekt">
						<view>{{dblx || "担保类型"}}</view>
						<image :src="upimg"></image>
					</view>
				</picker>
				<view class="reset" @click="getResetFn">
					<image :src="resetimg"></image>
				</view>
			</view>
		</view>
		<!-- 列表 -->
		<view class="plr18">
			<bus-list :datalist="list" :wtdt="wtdt" :sdyhlist="sdyhlist" :dblxlist="dblxlist" :shjdlist="shjdlist" :type="type" @getDetail="getDetail"></bus-list>
		</view>
		
	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import busList from "@/work/components/business/list.vue"
	import {getApplicationList} from "@/api/mine/work.js"
	import {getDictionaryFn} from "@/api/mine/register.js"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	export default{
		components:{busList},
		data(){
			return{
				upimg:require('@/work/static/images/sup.png'),
				resetimg:require('@/work/static/images/reset.png'),
				list:[],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				// limit:''
				type:'work',
				tabval:'0',
				tabList:[
					{tit:'全部',val:'0',},{tit:'申报审核',val:'2',},{tit:'担保初审',val:'3',},{tit:'初审风险合规',val:'4',},
					{tit:'尽职调查',val:'5',},{tit:'评审会',val:'6',},{tit:'签署合同',val:'7',},
				],
				sbsj:'',
				shidx:[0],
				shzt:'',
				shztid:'',
				sdyhidx:[0],
				sdyh:'',
				sdyhid:'',
				dblxidx:[0],
				dblx:'',
				dblxid:'',
				sdyhlist:[],//申贷银行
				shlist:[],//审核状态
				dblxlist:[],//担保类型
				shjdlist:[],//审核进度
				from:'',//从哪来的
				userId:this.$store.state.user.userId,
			}
		},
		onUnload() {
			uni.$off('refreshywlist')
			uni.$off('refreshdatalist')
		},
		onLoad(e) {
			if(e.type){
				this.tabval=e.type;
			}
			if(e.from){
				this.from=e.from;
			}
			uni.$on('refreshywlist',(e) => {
				this.getrefreshData()
			})
			uni.$on('refreshdatalist',(e) => {
				this.getrefreshData()
			})
			this.init()
			this.getDataFn()
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			init(){
				// 申贷银行
				getDictionaryFn('shendai_bank').then(res=>{
					if(res.code==200){
						this.sdyhlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
				//审核状态
				getDictionaryFn('sh_status').then(res=>{
					if(res.code==200){
						this.shlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
				//担保类型
				getDictionaryFn('guarantee_type').then(res=>{
					if(res.code==200){
						this.dblxlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
				//审核进度
				getDictionaryFn('audit_schedule').then(res=>{
					if(res.code==200){
						this.shjdlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
			},
			getDetail(e){
				this.$tab.navigateTo("/work/pages/business/details?id="+e)
			},
			getTabFn(val){
				this.tabval=val;
				this.getrefreshData()
			},
			bindDateChangea(e){
				var val=e.detail.value;
				this.sbsj=val;
				this.getrefreshData()
			},
			bindDateChangeb(e){
				var val=e.detail.value;
				this.shzt=this.shlist[val].label;
				this.shztid=this.shlist[val].value;
				this.getrefreshData()
			},
			bindDateChangec(e){
				var val=e.detail.value;
				this.sdyh=this.sdyhlist[val].label;
				this.sdyhid=this.sdyhlist[val].value;
				this.getrefreshData()
			},
			bindDateChanged(e){
				var val=e.detail.value;
				this.dblx=this.dblxlist[val].label;
				this.dblxid=this.dblxlist[val].value;
				this.getrefreshData()
			},
			getResetFn(){
				// 重置
				this.sbsj='';
				this.shzt='';
				this.sdyh='';
				this.dblx='';
				
				this.shidx=[0];
				this.sdyhidx=[0];
				this.dblxidx=[0];
				this.getrefreshData()
			},
			getrefreshData(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getDataFn(){
				// var str='2,3,4'
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
				}
				params.loanApplicationType=2
				// if(this.from&&this.from=='my'){
				// 	params.userId=this.userId
				// }
				if(!checkPermi(['system:system:user'])){
					params.userId=this.userId
				}
				// else{
				// 	params.loanApplicationType=2
				// }
				if(this.tabval!=0){
					params.loanSchedule=this.tabval
				}
				if(this.sbsj){
					params.applicationTime=this.sbsj
				}
				if(this.shzt){
					params.auditType=this.shztid
				}
				if(this.sdyh){
					params.applicationBank=this.sdyhid
				}
				if(this.dblx){
					params.guaranteeType=this.dblxid
				}
				getApplicationList(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>
.fixedt{position: fixed;left: 0;right: 0;top: 0;z-index: 2;}
.fixedt /deep/ uni-picker{flex: 1;}
.tablists{background: $com-cd3;overflow: auto;flex-wrap: nowrap;padding:4rpx 16rpx 16rpx;
	view{font-weight: bold;font-size: 26rpx;color: #FFFFFF;position: relative;flex: 1 0 auto;padding: 0rpx 20rpx;margin-right: 6rpx;box-sizing: border-box;text-align: center;
		height: 80rpx;display: flex;align-items: center;
		&:last-child{margin-right: 0;}
		&.act{font-size: 30rpx;
			&::after{content: '';width: 30rpx;height: 10rpx;background: #FFFFFF;border-radius: 4rpx;left: 50%;margin-left: -15rpx;bottom: 0rpx;position: absolute;}
		}
	}
}
.checkbox{padding: 4rpx 0 0 20rpx ;background-color: #efefef;
	.chekt{display: flex;align-items: center;margin-right: 12rpx;height:88rpx;
		view{text-align: center;
			font-weight: bold;font-size: 26rpx;color: #374B61;width: 136rpx;word-break: break-all;text-overflow: ellipsis;overflow: hidden;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;white-space: normal;}
		image{width: 16rpx;height: 12rpx;flex: 0 0 auto;margin-left: 4rpx;}
	}
}
.reset{width:56rpx; height: 88rpx;display: flex;align-items: center;justify-content: center;
	image{width: 26rpx;height: 30rpx;}
}
.listbox{padding-top: 192rpx;padding-bottom: 24rpx;}
</style>