<template>
	<view class="fullHeight bgWhite">
		<headers :showBack="true">
			<view class="headerName">
				选择人员
			</view>
		</headers>
		<scroll-view scroll-y="true" class="pageContent ">
			<view class="personContent">
				<checkbox-group @change="checkboxChange">
					<label class="personItem" v-for="item in personList" :key="item.value">
						<view>
							<checkbox :value="item.id+''" :checked="item.checked" />
						</view>
						<view class="workerName">{{item.workerName}}</view>
					</label>
				</checkbox-group>
				
			</view>
		</scroll-view>
		<button type="primary" @click="saveFn" class="submitBtn big">保存</button>
	</view>
</template>

<script>
	import headers from "../../../components/headers/headers.vue"
	export default {
		components:{headers},
		data() {
			return {
				personList:[],
				selectArr:[],
				projectDetail:{},
				workerName:''
			};
		},
		mounted(){
			this.projectDetail=JSON.parse(uni.getStorageSync('projectDetail'))
			this.loadData()
		},
		methods:{
			checkboxChange: function (e) {
				console.log(this.selectArr)
				console.log(e.detail.value)
				var items = this.personList,
					values = e.detail.value;
				
				for (var i = 0, lenI = items.length; i < lenI; ++i) {
					const item = items[i]
					if(values.includes(item.id)){
						this.$set(item,'checked',true)
					}else{
						this.$set(item,'checked',false)
					}
				}
				this.selectArr=values
			},
			loadData(){
				var that = this
				this.sendRequest({
					url: "xmgl/workerInfo/getLaborManagementInfoList",
					data: {projectSn: this.projectDetail.projectSn,workerName:this.workerName},
					method: "POST",
					success(res){
						that.personList = res.result
						if(uni.getStorageSync('person')){
							var person = uni.getStorageSync('person')
							if(person.indexOf(',')!=-1){
								that.selectArr=person.split(',')
							}else{
								that.selectArr=[person]
							}
							var items = that.personList
							for (var i = 0, lenI = items.length; i < lenI; ++i) {
								const item = items[i]
								if(person.includes(item.id)){
									that.$set(item,'checked',true)
								}else{
									that.$set(item,'checked',false)
								}
							}
						}
					}
				})
			},
			saveFn(){
				uni.setStorageSync('person',this.selectArr.join(','))
				uni.navigateBack({
					
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pageContent{
		height: calc(100% - 125px);
	}
	.personContent{
		padding: 15px;
	}
.personItem{
	display: flex;
	align-items: center;
	// padding: 0 15px;
	.workerName{
		margin-left: 10px;
	}
	
}
.submitBtn{
		position: fixed;
		bottom: 15px;
		left: 15px;
		width: calc(100% - 30px);
	}
</style>
