<template>
	<view class="fullHeight">
		<view class="header_fixed">
			<headers :showBack="true" :themeType="'white'" class="fixedHeaderBox">
				<view class="headerName">
					查队伍
				</view>
			</headers>
			<!-- :style="{ 'padding-top': (statusBarHeight + 52) * 1.5+ 'rpx' }" -->
			<view class="searchBox">
				<view class="type flex">
					<picker @change="(e)=>bindPickerChange(e)" :value="issueGradeIndex" class="picker"
						:range="cooperatorList" range-key="enterpriseName">
						<view class="uni-input uni-select cl" v-if="enterpriseId=='' && enterpriseName != '全部'">
							请选择 <image class="icon-down" src="/static/icon-down-black.png"></image>
						</view>
						<view class="uni-input uni-select" v-else>
							{{enterpriseName}}
							<image class="icon-down" src="/static/icon-down-black.png"></image>
						</view>
					</picker>
				</view>
				<input type="text" v-model="teamName" confirm-type="search" class="input"
					placeholder-style="color:rgba(72, 141, 236, 0.5)" placeholder="按岗位(工种)名称查找"
					@confirm="list=[];loadData()" />
			</view>
		</view>
		<view class="listBox" :style="{ 'padding-top': (statusBarHeight+52+40) * 2 + 'rpx' }">
			<view class="listItem" v-for="item in list" :key="item.id" @click="goAdd(item)">
				<view class="title">
					<!-- {{item.teamName}}-{{item.enterpriseName}} -->
					{{item.name}}
				</view>
				<view class="bottom">
					<image src="/static/icon-person.png" class="icon-person"></image>
					<text class="time">
						<!-- {{item.totalPersonNum}} -->
						{{item.totalPerson}}人
					</text>
				</view>
				<image src="/static/icon-right.png" class="icon-right"></image>
			</view>
			<view class="placeholderBox" v-show="list.length==0">
				<image src="/static/noData.png" class="noDataImg"></image>
				<view class="text">
					暂无数据
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				projectDetail: {},
				list: [],
				statusBarHeight: 0,
				teamName: '',
				cooperatorList: [],
				issueGradeIndex: 0,
				enterpriseId: "",
				enterpriseName: "",
			};
		},
		mounted() {
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight
			this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'))
			this.loadData()
			this.getCooperatorList();
		},

		methods: {
			bindPickerChange(e, type) {
				console.log(e)
				this.issueGradeIndex = e.detail.value;
				this.enterpriseId = this.cooperatorList[e.detail.value].id;
				this.enterpriseName = this.cooperatorList[e.detail.value].enterpriseName;
				this.loadData()
			},
			//获取列表数据
			getCooperatorList() {
				this.sendRequest({
					url: 'xmgl/projectEnterprise/list',
					method: "post",
					data: {
						projectSn: this.projectDetail.projectSn,
						page: 1,
						pageSize: -1,
					},
					success: res => {
						if (res.code == 200) {
							this.cooperatorList = [{
								id: "",
								enterpriseName: "全部"
							}, ...res.result.records];
							this.enterpriseName = "全部"
						}
					}
				})
			},
			loadData() {
				var that = this
				// xmgl/workerInfo/selectAllProjectTeamList
				this.sendRequest({
					url: 'xmgl/workerInfo/selectWorkerTeamAndDepartmentStatistics',
					data: {
						enterpriseId: this.enterpriseId,
						name: this.teamName,
						projectSn: this.projectDetail.projectSn
					},
					method: "POST",
					success(res) {
						that.list = res.result.list
					}
				})
			},
			goAdd(item) {
				console.log(item)
				uni.navigateTo({
					url: './personList?id=' + item.departmentId + '&teamId=' + item.teamId
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.header_fixed {
		position: fixed;
		left: 0;
		// width: calc(100% - 60rpx);
		width: 100%;
		top: 0;
		z-index: 1;
	}
	.searchBox {
		background-color: #2b8df3;
		padding: 0 30rpx 10rpx;
		display: flex;
		justify-content: space-between;
		.type  {
			width: 27%;
			background-color: white;
			font-size: 28rpx;
			border-radius: 36rpx;
			text-align: center;
			padding: 0 20rpx;
			.uni-select {
				height: 70rpx;
			}
		}

		.input {
			width: 70%;
			font-size: 28rpx;
			border-radius: 36rpx;
			height: 70rpx;
			text-align: center;
			background-color: white;
		}
	}

	.listBox {
		margin: 30rpx;
	}

	.listItem {
		box-shadow: 0px 4px 26rpx 0px rgba(212, 220, 236, 0.53);
		position: relative;
		margin-bottom: 10rpx;
		padding: 30rpx;
		border-radius: 16rpx;

		.title {
			font-size: 30rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
		}

		.bottom {
			color: rgba(55, 45, 102, 0.5);
			font-size: 24rpx;
			display: flex;
			align-items: center;
		}

		.time {
			margin-left: 6px;
		}
	}

	.icon-right {
		position: absolute;
		width: 16rpx;
		height: 28rpx;
		right: 30rpx;
		top: calc(50% - 7px);
	}

	.icon-person {
		width: 28rpx;
		height: 28rpx;
	}
</style>