<template>
	<view>
		<view class="company_body">
			<view v-if="type.data==''||!type" class="header_seach_seach">
				<uni-easyinput
				@confirm="seachFn"
					style="height: 100%; flex: 1; margin: 0 auto; background-color: #FFFFFF; border-radius:12rpx ;"
					prefixIcon="search" v-model="getData.params.name" placeholder="公司名称" @iconClick="onClick">
				</uni-easyinput>
			</view>
		</view>
		<view class="company_list">
			<view v-if="!type" @tap="seleFn()"  style="margin-top: 0;" class="company_list_item">
				<image src="../../static/selegs.png" style="width: 73rpx; height: 73rpx;"></image>
				<view class="company_list_item_text">所有企业</view>
				<view style="flex-grow: 1; text-align: end;text-align: -webkit-right;">
						<view  class="checkboxs">
							<view v-if="selecompany==''" class="checkboxss"></view>
						</view>
				</view> 
			</view>
			<view @tap="seleFn(item)" v-for="(item,index) in diverList " class="company_list_item">
				<image v-if="!type" src="../../static/selegs.png" style="width: 73rpx; height: 73rpx;"></image>
				<view v-if="type" :style="{ background:item.parentMark==0?'#2866FF':'#FD9500'}" class="companytip">{{item.parentMark==0?'总公司':'子公司'}}</view>
				<view class="company_list_item_text">{{item.name}}</view>
				<view style="flex-grow: 1; text-align: end;text-align: -webkit-right;">
						<view  class="checkboxs">
							<view v-if="item.name==selecompany.name" class="checkboxss"></view>
						</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import driverManagement from '@/api/driverManagement'
	export default {
		data() {
			return {
				selecompany:'',
				timer:null,
				diverList:[],
				getData: {
					pageSize: 15,
					currentPage: 1,
					params: {
						name:""
					},
					sorted: {
						createTime: "desc"
					},
					columns: []
				},
				value: 0,
				range: [{
					"value": 0,
					"text": ""
				}],
				type:'',
			}
		},
		onLoad(e) {
			if(e.jsData){
				if(JSON.parse(e.jsData)=='') return
				if(JSON.parse(e.jsData).type=='send'||JSON.parse(e.jsData).type=='receive'){
					this.type = JSON.parse(e.jsData)
					return
				}
				this.selecompany = {}
				this.selecompany.name = JSON.parse(e.jsData)
			}
		},
		onShow() {
			if( this.type!==''&&this.type.data!==''){
				this.fylist(this.type.id)
			}else{
				console.log(this.type.data,'-------------------------------------------------')
				this.getDriversList()
			}
		},
		onReachBottom() {
			this.getData.currentPage+=1
			console.log('触底了')
			this.getDriversList()
		},
		methods: {
			fylist(e){
				driverManagement.fylist(e).then(res=>{
					if(res.code!==20000)return
					this.diverList = res.data
				})
			},
			seleFn(e){
				clearTimeout(this.timer) 
				if(!e){
					this.selecompany = ''
					uni.$emit('company')
					this.timer = setTimeout(()=>{
						uni.navigateBack()
					},1000)
					return
				}
				
				this.selecompany = e
				this.selecompany.type = this.type.type
				uni.$emit('company',this.selecompany)
				this.timer = setTimeout(()=>{
					uni.navigateBack()
				},1000)
			},
			seachFn(){
				this.selecompany = {}
				this.getData.currentPage = 1
				this.getDriversList()
			},
			getDriversList() {
				console.log('正常')
				driverManagement.getByPage(this.getData).then(res=>{
					if(res.code!==20000)return
					if(this.getData.currentPage!==1){
						this.diverList = this.diverList.concat(res.data.list);
						return
					}
					this.diverList = res.data.list
				})
			},
			change(e) {
				console.log('e:', e);
			}
		}
	}
</script>

<style>
	.companytip{
		width: 88rpx;
		height: 38rpx;
		border-radius: 4rpx;
		color: #FFFFFF;
        font-size: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.checkboxss{
		width: 80%;
		height: 80%;
		background-color: #2866FF;
		border-radius: 50px;
	}
	.checkboxs{
		width: 20rpx;
		height: 20rpx;
		border-radius: 50px;
		border: 1px solid #BBBBBB;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.checkbox__inner {
		border-radius: 50px !important;
	}

	.uni-data-checklist {
		flex: 0 !important;
	}

	.uni-data-checklist .checklist-group .checklist-box {
		margin: 0 !important;
	}

	.uni-data-checklist {
		width: max-content;
	}

	.company_list_item_text {
		font-size: 28rpx;
		color: #000000;
		margin-left: 23rpx;
	}

	.company_list_item {
		min-height: 92rpx;
		background: #FFFFFF;
		box-shadow: 0px 3px 9px 0px rgba(88, 88, 88, 0.2);
		border-radius: 8rpx;
		font-size: 28rpx;
		display: flex;
		align-items: center;
		padding: 9rpx 21rpx;
		margin-top: 19rpx;
	}

	.company_list {
		width: 100vw;
		padding: 0 31rpx;
		box-sizing: border-box;
		margin-top: 40rpx;
	}

	.company_body {
		background-color: #2866FF;
		padding: 25rpx 0;
	}

	.uni-easyinput__content {
		height: 80rpx;
	}

	.uni-easyinput {
		height: 80rpx;
	}

	.header_seach_seach {
		display: flex;
		height: 80rpx;
		background-color: #2866FF;
		padding: 0 31rpx;
	}
</style>