<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="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-item" >
								<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.postType}}
								</view>
							</view>
							<view class="form-item">
								<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.salary}}
								</view>
							</view>
							<view class="form-item" >
								<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.regionName}}
								</view>
							</view>
							<view class="form-item" >
								<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.welfare}}
								</view>
							</view>
							<view class="form-item">
								<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">
									{{getabelByValue(item.education,educationOptions)}}
								</view>
							</view>
							<view class="form-item" >
								<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">
									{{getabelByValue(item.jobType,jobTypeOptions)}}
								</view>
							</view>
							<view class="form-item" >
								<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">
									{{getabelByValue(item.type,gangweiTypeOptions)}}
								</view>
							</view>
							<view class="form-btns">
								<button class="mini-btn form-box-btn detail-btn"  size="mini" @click="goDetail('edit',item)">编辑</button>
								<button class="mini-btn form-box-btn follow-btn"  size="mini" @click="del(item)">删除</button>
							</view>
						</view>
					</view>
				    <empty v-else pdTop="200"></empty>
				</view>
			</scroll-view>
			<view class="float-btn" @click="goDetail('add')">
				<uni-icons type="plusempty" color="#fff" size="30"></uni-icons>
			</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 title = ref('');
const id=ref('')
const pageNum = ref(1)
const pageSize = ref(2)
const totalNum=ref(0)
const dataList=ref([])
const educationOptions=ref([])
const jobTypeOptions=ref([])
const gangweiTypeOptions=ref([])
const goalPersonId=ref([])
const baseUrl = config.imgBaseUrl
const getBackgroundStyle = (imageName) => ({
    backgroundImage: `url(${baseUrl}/dispatch/${imageName})`,
    backgroundSize: 'cover',      // 覆盖整个容器
    backgroundPosition: 'center', // 居中
    backgroundRepeat: 'no-repeat'
});
function getDictionary(){
	$api.myRequest('/system/public/dict/data/type/education').then((resData) => {
		if(resData && resData.code == 200){
			resData.data.forEach(item=>{
				const obj = {
				    value: item.dictValue,
				    text: item.dictLabel
				}
				educationOptions.value.push(obj)
			})
		}
	});
	$api.myRequest('/system/public/dict/data/type/job_type').then((resData) => {
		if(resData && resData.code == 200){
			resData.data.forEach(item=>{
				const obj = {
				    value: item.dictValue,
				    text: item.dictLabel
				}
				jobTypeOptions.value.push(obj)
			})
		}
	});
	$api.myRequest('/system/public/dict/data/type/gangwei_type').then((resData) => {
		if(resData && resData.code == 200){
			resData.data.forEach(item=>{
				const obj = {
				    value: item.dictValue,
				    text: item.dictLabel
				}
				gangweiTypeOptions.value.push(obj)
			})
		}
	});
}
function getabelByValue(value,arr) {
	if (!Array.isArray(arr)) {
	    return ''
	}
	const item = arr.find(item => item.value === String(value))
	return item ? item.text : '暂无'
}
function getDataList(){
	let header={
		'Authorization':uni.getStorageSync('Padmin-Token'),
		'Content-Type': "application/x-www-form-urlencoded"
	}
	let params={
		personId: id.value,
		pageNum: pageNum.value,
		pageSize: pageSize.value
	}
	$api.myRequest('/dispatch/job/willingness/list',params,'get',9100,header).then((resData) => {
		totalNum.value=resData.total
		dataList.value=dataList.value.concat(resData.rows)
		
	});
}
function scrollBottom(){
	if(pageNum.value<totalNum.value/pageSize.value){
		pageNum.value++
		getDataList()
	}
}
function goDetail(val,item){
	if(val=='add'){
		navTo('/packageB/priority/jobWillEdit?goalPersonId=' + goalPersonId.value);
	}
	
}
function del(item){}
onLoad((options) => {
	id.value=options.id
	goalPersonId.value=options.goalPersonId
	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;
}
.float-btn{
	position: fixed;
	bottom: 100rpx;
	right: 50rpx;
	background: #368BFF;
	width: 100rpx;
	height: 100rpx;
	border-radius: 50%;
	line-height: 100rpx;
	text-align: center;
	color: #fff;
}
</style>
