<template>
    <AppLayout :title="title" :show-bg-image="false" >
		<view class="page-container" >
			<scroll-view :scroll-y="true" class="nearby-scroll" @scrolltolower="scrollBottom" lower-threshold="50">
				<view class="main-list" :style="getBackgroundStyle('k.png')">
					<view class="task-box">
						<text class="task-label">任务：</text>
						<text class="task-name">{{props.taskName}}</text>
					</view>
				</view>
			
				<view class="main-list" :style="getBackgroundStyle('k.png')">
					<view class="list-top">
						<view class="list-title">
							<text>目标人员列表</text>
							<view class="title-line" style="left: 70rpx;"></view>
						</view>
						<view class="title-total">
							目标人数<text class="total-num">{{totalNum}}</text>人
						</view>
					</view>
					<view class="list-box" v-if="dataList.length>0">
						<view class="con-box" v-for="(item,index) in dataList" :key="index">
							<view class="form-title">
								<view class="form-name">
									{{item.name}}
								</view>
							</view>
							<view class="form-item" v-if="item.idCard">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/person.png'" mode=""></image>
									<view class="item-label">
										身份证号：
									</view>
								</view>
								<view class="item-right">
									{{item.idCard}}
								</view>
							</view>
							<view class="form-item" v-if="item.phone">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/tele.png'" mode=""></image>
									<view class="item-label">
										联系电话：
									</view>
								</view>
								<view class="item-right">
									{{item.phone}}
								</view>
							</view>
							<view class="form-item" v-if="item.address">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/base.png'" mode=""></image>
									<view class="item-label">
										住址：
									</view>
								</view>
								<view class="item-right">
									{{item.address}}
								</view>
							</view>
							<view class="form-item" v-if="item.skills">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/num.png'" mode=""></image>
									<view class="item-label">
										技能特长：
									</view>
								</view>
								<view class="item-right">
									{{item.skills}}
								</view>
							</view>
							<view class="form-item" v-if="item.tags.length>0">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/date.png'" mode=""></image>
									<view class="item-label">
										人员标签：
									</view>
								</view>
								<view class="item-right">
									<view class="" v-for="(val,num) in item.tags" :key="num">
										{{val}}
									</view>
								</view>
							</view>
							<view class="form-item" v-if="item.datasource">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/next.png'" mode=""></image>
									<view class="item-label">
										数据来源：
									</view>
								</view>
								<view class="item-right">
									{{item.datasource=== '1' ? '自动识别' : '手动添加'}}
								</view>
							</view>
							<view class="form-item" v-if="item.assistStatus">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/help.png'" mode=""></image>
									<view class="item-label">
										帮扶状态：
									</view>
								</view>
								<view class="item-right">
									{{item.assistStatus}}
								</view>
							</view>
							<view class="form-item" v-if="item.employmentStatus">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/num.png'" mode=""></image>
									<view class="item-label">
										就业状态：
									</view>
								</view>
								<view class="item-right">
									{{item.employmentStatus}}
								</view>
							</view>
							<view class="form-item" v-if="item.unemploymentDate">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/date.png'" mode=""></image>
									<view class="item-label">
										失业时间：
									</view>
								</view>
								<view class="item-right">
									{{item.unemploymentDate}}
								</view>
							</view>
							<view class="form-item" v-if="item.unemploymentRegisterDate">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/date.png'" mode=""></image>
									<view class="item-label">
										失业登记时间：
									</view>
								</view>
								<view class="item-right">
									{{item.unemploymentRegisterDate}}
								</view>
							</view>
							<view class="form-item" v-if="item.graduateDate">
								<view class="item-left">
									<image class="item-img" :src="baseUrl+'/dispatch/next.png'" mode=""></image>
									<view class="item-label">
										毕业时间：
									</view>
								</view>
								<view class="item-right">
									{{item.graduateDate}}
								</view>
							</view>
						</view>
					</view>
				    <empty v-else pdTop="200"></empty>
				</view>
			</scroll-view>
			<view class="button-group">
				<view class="btns">
					<button class="btn reset-btn" @click="handleCancel">关闭</button>
				</view>
			  
			</view>
		</view>
    </AppLayout>
</template>

<script setup>
import { inject, ref, reactive, onMounted } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
const { $api, navTo, navBack } = inject('globalFunction');
import config from "@/config.js"

const props = defineProps({
  currentItem:{
    type: String,
    required: true,
	default: ''
  },
  taskName:{
    type: String,
    required: true,
	default: ''
  },
})
const title = ref('');
const pageNum = ref(1)
const pageSize = ref(2)
const currentItem=ref({})
const totalNum=ref(0)
const dataList=ref([])
const personDatabaseStatusOptions=ref([])
const employmentStatusOptions=ref([])
const baseUrl = config.imgBaseUrl
const getBackgroundStyle = (imageName) => ({
    backgroundImage: `url(${baseUrl}/dispatch/${imageName})`,
    backgroundSize: 'cover',      // 覆盖整个容器
    backgroundPosition: 'center', // 居中
    backgroundRepeat: 'no-repeat'
});
const emit = defineEmits(['update:showView'])
function getDictionary(){
	$api.myRequest('/system/public/dict/data/type/person_database_status').then((resData) => {
		if(resData && resData.code == 200){
			resData.data.forEach(item=>{
				const obj = {
				    value: item.dictValue,
				    text: item.dictLabel
				}
				personDatabaseStatusOptions.value.push(obj)
			})
		}
	});
	$api.myRequest('/system/public/dict/data/type/assist_employment_status').then((resData) => {
		if(resData && resData.code == 200){
			resData.data.forEach(item=>{
				const obj = {
				    value: item.dictValue,
				    text: item.dictLabel
				}
				employmentStatusOptions.value.push(obj)
			})
		}
	});
}
function getabelByValue(value,arr) {
	if (!Array.isArray(arr.value)) {
	    return ''
	}
	const item = arr.value.find(item => item.value === String(value))
	return item ? item.text : '暂无'
}
const handleCancel = () => {
	emit('update:showView', 'main')
}
function getDataList(){
	console.log("props.currentItem",props.currentItem)
	let header={
		'Authorization':uni.getStorageSync('Padmin-Token'),
		'Content-Type': "application/x-www-form-urlencoded"
	}
	let params={
		allocationId: props.currentItem,
		pageNum: pageNum.value,
		pageSize: pageSize.value
	}
	$api.myRequest('/dispatch/assist/person/database/pageGoalPersonList',params,'get',9100,header).then((resData) => {
		resData.rows.forEach(item=>{
			item.tags=item.tagName.split(',')
			item.assistStatus=getabelByValue(item.assistStatus,personDatabaseStatusOptions)
			item.employmentStatus=getabelByValue(item.employmentStatus,employmentStatusOptions)
		})
		totalNum.value=resData.total
		dataList.value=dataList.value.concat(resData.rows)
		
	});
}
function scrollBottom(){
	if(pageNum.value<totalNum.value/pageSize.value){
		pageNum.value++
		getDataList()
	}
}
onMounted(() => {
	runAsyncTasks()
});
const runAsyncTasks = async () => {
  await getDictionary()
  await getDataList()
}

</script>

<style lang="stylus" scoped>
image
  height: 100%
  width: 100%
.page-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--window-top)); /* 如果 AppLayout 有 header，需减去 */
  /* 或者简单用：height: 100vh; */
  padding-bottom: 140rpx
}
.nearby-scroll
    // 使用flex布局让scroll-view自适应高度，占据剩余空间
  flex: 1
  // overflow: hidden;
.task-box
  display: flex
  align-items: center
.task-label
  font-size: 30rpx
  color: #6E7E9B
.task-name
  font-weight: bold
  font-size: 30rpx
  color: #3D61AC
.main-list
  background-color: #ffffff
  padding: 20rpx 20rpx 28rpx 20rpx
  margin: 30rpx 30rpx
  box-shadow: 0px 3px 20px 0px rgba(0,105,234,0.1)
  border-radius: 12px
.list-top
  display: flex
  align-items: center
  justify-content: space-between
.list-title
  font-weight: bold
  font-size: 36rpx
  color: #404040
  position: relative

.title-line
  position: absolute
  bottom: -10rpx
  left: 70rpx
  width: 70rpx
  height: 8rpx
  background: linear-gradient(90deg, #FFAD58 0%, #FF7A5B 100%)
  border-radius: 4rpx
.title-total
  font-size: 24rpx
  color: #999999
.total-num
  color: #3088FF
  margin-left: 4rpx
  margin-right: 4rpx
  font-weight: bold
  font-size: 26rpx

.list-box
  margin-top: 40rpx

:deep(.uni-forms-item__label)
  width: 194rpx !important
  font-size: 28rpx;
  color: #404040;
  
.search-container
  padding: 20rpx 0rpx 0rpx 0rpx
.title-total
  font-size: 24rpx
  color: #999999
.total-num
  color: #3088FF
  margin-left: 4rpx
  margin-right: 4rpx
  font-weight: bold
  font-size: 26rpx
.search-item
  display: flex
  align-items: center
  margin-bottom: 30rpx

.label
  width: 160rpx
  font-size: 28rpx
  color: #404040
  flex-shrink: 0

.input,
.picker
  background: #FFFFFF
  flex: 1
  min-width: 0
.search-box-btn
  border-radius: 32rpx !important
  background: #3088FF !important
  margin-right: 16rpx
.reset-box-btn
  border-radius: 32rpx !important
  background: #02B44D
  color: #fff
.con-box
  background: #fff
  padding: 20rpx
  box-shadow: 0px 0px 6rpx 0px rgba(0,71,200,0.16)
  border-radius: 24rpx
  border: 1rpx solid #EDF5FF
  margin-top: 30rpx
.form-title
  display: flex
  align-items: center

.form-name
  font-weight: bold
  font-size: 30rpx
  color: #595959
  margin-right:16rpx
.form-type
  border-radius: 8rpx;
  border: 2rpx solid #FF7D26;
  font-size: 24rpx
  color: #F1690E
  padding: 4rpx 10rpx
.form-item
  display: flex
  align-items: center
  justify-content: space-between
  margin-top: 30rpx
.item-left
  display: flex
  align-items: center
.item-img
  width: 26rpx
  height: 26rpx
  margin-right: 10rpx
.item-label
  font-size: 26rpx
  color: #B3B3B3
  width: 190rpx
.item-right
  font-size: 26rpx
  color: #737373
  // overflow: hidden
  // text-overflow: ellipsis
  // white-space: nowrap
  word-wrap: break-word
  overflow-wrap: break-word
  white-space: normal
.form-btns
  margin-top:30rpx
.form-box-btn
  border-radius: 50rpx !important
  margin-right: 24rpx
  padding: 0rpx 40rpx
.detail-btn
  background: #EDF5FF
  border: 1px solid #3088FF
  font-size: 28rpx
  color: #3088FF
.follow-btn
  background: #EEF9F3
  border: 1px solid #00933E
  font-size: 28rpx
  color: #00933E
.recommend-btn
  background: linear-gradient(92deg, #0DCCFF 0%, #4760FF 100%)
  font-size: 28rpx
  color: #FFFFFF
.button-group 
	position: fixed
	bottom: 0
	left: 0
	width: 100%
	height: 120rpx
	background: #fff
.btns
  height: 120rpx
  width: 100%
  line-height: 120px
  display: flex
  align-items: center
  justify-content: space-between
  box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1)

.btn {
  width: 45%;
  height: 80rpx;
  font-size: 30rpx;
  border-radius: 8rpx;
}

.reset-btn {
  background-color: #D8E9FF;
  color: #1176FF;
}

.submit-btn {
  background-color: #368BFF;
  color: white;
}
</style>
