<template>
	<view class="main-content">
		<headers :showBack="true" :themeType="true">
			<view class="headerName">
				选择人员
			</view>
		</headers>
		<view class="index-boxs" v-if="personList.length">
			<view class="index-box" v-for="(item,index) in personList" :key="index">
				<image :src="url_config+'image/'+item.fieldAcquisitionUrl"></image>
				<view class="person-info">
					<text>{{item.workerName}}</text>
					<text>{{item.workerType}}</text>
					<text>{{item.sex == 1?'男':'女'}}&nbsp;&nbsp;{{item.age}}</text>
				</view>
			</view>
		</view>
		<view class="placeholderBox" v-else>
			<image src="/static/exam/noCourseData.png" class="noDataImg" style="width: 180rpx; height: 160rpx;"></image>
			<!-- <view class="text">
				暂无数据
			</view> -->
		</view>
		<view class="editBtn">
			<view class="btn-select" @click="toSelectPerson">选择人员</view>
			<view class="btn-resubmit" @click="addForm">新增保存</view>
		</view>
		<levitatedsphere :x="100" :y="80"></levitatedsphere>
	</view>
</template>

<script>
	import levitatedsphere from "@/components/levitatedsphere/levitatedsphere.vue"
	export default {
		data() {
			return {
				title: 'Hello',
				activeIndex: 0,
				personList: [],
				userInfo: {},
				pageData: {}
			}
		},
		onLoad(options) {
			this.pageData = JSON.parse(options.pageData)
			this.userInfo = JSON.parse(uni.getStorageSync("userInfo"))
			uni.removeStorageSync("personInfo")
		},
		onShow() {
			if(uni.getStorageSync("personInfo")){
				this.personList = JSON.parse(uni.getStorageSync("personInfo"))
			}
		},
		methods: {
			addForm(){
				if(!this.personList.length){
					uni.showToast({
						title: '请选择人员',
						icon: 'none'
					})
					return
				}
				let requestData = {
					...this.pageData,
					examTrainRecordList: this.personList,
					projectSn: this.userInfo.sn
				}
				this.sendRequest({
					url: "exam/train/add",
					data: requestData,
					header: {},
					method: 'post',
					success(res) {
						if(res.code == 200){
							uni.showToast({
								title: "添加成功"
							})
							setTimeout(function(){
								uni.redirectTo({
									url: './list'
								})
							},500)
						}
					}
				})
			},
			toSelectPerson(){
				uni.navigateTo({
					url: './searchTeam/teamList'
				})
			},
			getDataList() {
				var that = this
				let requestData = {
					workerId: this.userInfo.id
				}
				this.sendRequest({
					url: "xmgl/workerExam/trainList",
					data: requestData,
					header: {},
					method: 'post',
					success(res) {
						console.log('视频分组列表', res)
						that.personList = res.result;
					}
				})
			},
			returnBack() {
				uni.redirectTo({
					url: `/pages/personLocation/index/index`
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.main-content {
		display: flex;
		flex-direction: column;
		.index-boxs {
			height: calc(100vh - 200rpx);
			overflow-y: scroll;
			padding: 58rpx 35rpx;
			padding-bottom: 10rpx;
			.index-box {
				width: 100%;
				background-color: white;
				box-shadow: 4rpx 4rpx 8rpx 2rpx rgba(81, 129, 246, 0.12);
				border-radius: 10rpx;
				padding: 30rpx;
				margin-bottom: 30rpx;
				display: flex;

				>image {
					width: 110rpx;
					height: 130rpx;
				}

				.person-info {
					font-family: Source Han Sans CN, Source Han Sans CN;
					font-weight: 400;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					margin: 8rpx 20rpx 0rpx 20rpx;

					text:nth-child(1) {
						color: #303030;
						font-size: 30rpx;
					}

					text:nth-child(2) {
						color: #292929;
						font-size: 26rpx;
					}

					text:nth-child(3) {
						color: #5B5B5B;
						font-size: 22rpx;
					}
				}
			}
		}
	}

	.editBtn {
		position: fixed;
		bottom: 20rpx;
		left: 0px;
		width: 100%;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		z-index: 99;
		.btn-select {
			width: 50%;
			line-height: 40px;
			background-color: #F1F1F1;
			color: #2D2D60;
			text-align: center;
			border-radius: 10rpx;
		}
		.btn-resubmit{
			width: 50%;
			line-height: 40px;
			background-color: #5382F6;
			color: #fff;
			text-align: center;
			border-radius: 10rpx;
		}
	}
</style>