<template>
	<!-- 安全教育培训加入人员 -->
	<view class="fullHeight bgWhite">
		<headers :showBack="true">
			<view class="headerName">
				选择人员
			</view>
		</headers>
		<view class="searchBox">
			<input type="text" v-model="workerName" confirm-type="search" class="input" placeholder="按工人姓名查找" @confirm="personList=[];loadData()" />
		</view>
		<scroll-view scroll-y="true" class="pageContent">
			<view class="personContent">
				<view class="personItem" v-for="item in personList" :key="item.id">
					<image v-if="item.fieldAcquisitionUrl" :src="url_config+'image/'+item.fieldAcquisitionUrl" class="profile_photo"></image>
					<image v-else src="/static/profile_photo.png" class="profile_photo"></image>
					<view class="personInfo">
						<view class="name">
							{{item.workerName}}
						</view>
						<view class="teamName">
							{{item.teamName}}
						</view>
						<view class="small">
							{{item.sex==2?'女':'男'}} {{item.age}}
						</view>
					</view>
					<text v-if="item.status" class="statusBtn">已加入</text>
					<text v-else class="addBtn" @click="addPersonFn(item)">加入</text>
				</view>
				<view class="placeholderBox" v-show="personList.length==0">
					<image src="/static/noData.png" class="noDataImg"></image>
					<view class="text">
						暂无数据
					</view>
				</view>
			</view>
		</scroll-view>
		
	</view>
</template>

<script>
	import headers from "../../../components/headers/headers.vue"
	export default {
		components:{headers},
		data() {
			return {
				personList:[],
				selectArr:[],
				projectDetail:{},
				workerName:'',
				pageTitle:'',
				selectPerson:[]
			};
		},
		mounted(){
			this.projectDetail=JSON.parse(uni.getStorageSync('projectDetail'))
			if(uni.getStorageSync('person')){
				this.selectPerson = JSON.parse(uni.getStorageSync('person'))
			}
			this.loadData()
		},
		methods:{
			addPersonFn(item){
				
				this.selectPerson.push({workerId:item.id,sex: item.sex,teamName: item.teamName,workerName: item.workerName,fieldAcquisitionUrl: item.fieldAcquisitionUrl})
				console.log('addPersonFn',this.selectPerson)
				this.showStatus()
				uni.setStorageSync('person',JSON.stringify(this.selectPerson))
			},
			showStatus(){
				var  Things=this.selectPerson
				for (var i = 0; i < Things.length; i++) {
					for (var j = 0; j < this.personList.length; j++) {
						if(this.personList[j].id==Things[i].workerId){
							var json = this.personList[j]
							json.status = 1
							this.$set(this.personList,j,json)
						}
					}
				}
			},
			loadData(){
				var that = this
				this.sendRequest({
					url: "xmgl/workerInfo/selectWorkerInfoList",
					// url: "xmgl/workerInfo/getLaborManagementInfoList",
					data: {projectSn: this.projectDetail.projectSn,workerName:this.workerName},
					method: "POST",
					success(res){
						that.personList = res.result.records
						that.showStatus()
						
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pageContent{
		height: calc(100% - 125px);
	}
	.personContent{
		padding: 15px;
	}
.personItem{
	display: flex;
	align-items: center;
	box-shadow: 0px 4px 13px 0px rgba(212, 220, 236, 0.53);
	position: relative;
	margin-bottom: 5px;
	padding: 15px;
	border-radius: 8px;
	// padding: 0 15px;
	font-size: 15px;
	.teamName{
		font-size: 13px;
	}
	.small{
		font-size: 12px;
		opacity: 0.8;
	}
	
}
.submitBtn{
		position: fixed;
		bottom: 15px;
		left: 15px;
		width: calc(100% - 30px);
	}
.profile_photo{
	width: 50px;
	height: 60px;
	margin-right: 10px;
}
.addBtn{
	font-size: 14px;
	border-radius: 4px;
	border: 1px solid $uni-color-primary;
	color: $uni-color-primary;
	padding: 1px 6px;
	position: absolute;
	top: calc(50% - 12px);
	right: 15px;
}
.statusBtn{
	font-size: 14px;
	color: $uni-color-success;
	padding: 1px 6px;
	position: absolute;
	top: calc(50% - 12px);
	right: 15px;
}
.searchBox{
	// background-color: #2b8df3;
	// padding: 0 15px 5px;
	// position: fixed;
	// left: 0;
	// width: calc(100% - 30px);
	// top: 0;
	margin: 10px 15px;
	.input{
		border-radius: 18px;
		height: 35px;
		text-align: center;
		background-color: #f7f7f7;
	}
}
</style>
