<template>
	<view>
		<uni-card v-for="(val, index) in items" :key="index" :is-shadow="true" @tap.stop="handleDetail(val)" :border='false' shadow="0px 0px 3px 1px rgba(0,0,0,0.1)">
			<!-- 基本信息 -->
			<view class="d-flex align-center">
				<view class="user-avatar">
					<image class="user-avatar-img" :src="getUserAvatar(val.avatar, val.sex)" mode="scaleToFill"></image>
					<image class="user-avatar-sex" :src="val?.sex ? val?.sex === '1' ? '/static/img/man.png' : '/static/img/female.png' : ''" alt="" mode="scaleToFill" />
				</view>
				<view style="flex: 1; margin-left: 10px;">
					<view class="font-size-18">{{ val.name }}</view>
					<view class="ss-m-t-10">
						<span 
							class="color-666"
							v-for="(key, index) in desc" 
							:key="index"
						>
							{{ val[key] }}
							<span v-if="index !== desc.length - 1 && val[key]" class="ss-m-x-10">|</span>
						</span>
					</view>
				</view>
			</view>
			
			<!-- 感兴趣职位 -->
			<view v-if="val.position?.positionNames && showLastWorkExp" class="ss-m-t-15 color-666">
				感兴趣职位：{{ val.position?.positionNames || '暂无' }}
			</view>

			<!-- 最近一份工作经验 -->
			<view v-if="val?.lastWorkExp && showLastWorkExp" class="ss-m-t-15 color-666">
				<view>
					<uni-icons type="smallcircle" class="ss-m-r-10" color="#666"></uni-icons>
					{{ formatName(val.lastWorkExp.enterpriseName) || '未填写企业名称' }}
				</view>
				<view class="ss-m-l-45">
					<span>{{ formatName(val.lastWorkExp.positionName) || '未填写职位名称' }}</span>
					<span v-if="val.lastWorkExp.startTime" class="ss-m-l-20">
						{{ val.lastWorkExp.startTime ? timesTampChange(val.lastWorkExp.startTime, 'Y-M') : '暂无' }}
						- 
						{{ val.lastWorkExp.endTime ? timesTampChange(val.lastWorkExp.endTime, 'Y-M') : val.lastWorkExp.startTime ? '至今' : '' }}
					</span>
				</view>
			</view>

			<!-- 工作经历 -->
			<view v-if="val?.workList && val.workList.length > 0 && !showLastWorkExp" class="ss-m-t-15 color-666">
				<view v-for="k in val.workList" :key="k.id" class="ss-m-b-30">
					<view>
						<uni-icons type="smallcircle" class="ss-m-r-10" color="#666"></uni-icons>
						{{ formatName(k.enterpriseName) || '未填写企业名称' }}
					</view>
					<view class="ss-m-l-45">
						<span>{{ formatName(k.positionName) || '未填写职位名称' }}</span>
						<span class="ss-m-l-20">
							<span>{{ k.startTimeStr }}</span>
							<span v-if="k.endTimeStr"> - {{ k.endTimeStr }}</span>
							<!-- <span v-if="k.year"> ({{ k.year }})</span> -->
						</span>
					</view>
				</view>
			</view>
		</uni-card>
	</view>
</template>

<script setup>
import { getUserAvatar } from '@/utils/avatar.js'
import { timesTampChange } from '@/utils/date'
import { formatName } from '@/utils/getText'

defineProps({
	items: Array,
	showLastWorkExp: {
		type: Boolean,
		default: true
	}
})

const desc = ['jobStatusName', 'eduName', 'expName']

const handleDetail = ({ userId }) => {
	if (!userId) {
		uni.showToast({
			title: '资源获取失败，请稍后重试',
			icon: 'none',
			duration: 2000
		})
		return
	}
	uni.navigateTo({
		url: `/pagesB/personnelDetails/index?id=${userId}&type=1`
	})
}
</script>

<style scoped lang="scss">
.user-avatar {
	position: relative;
	&-img {
		width: 60px;
		height: 60px;
		border-radius: 50%;
	}
	&-sex {
		position: absolute;
		right: 0;
		bottom: 2px;
		width: 20px;
		height: 20px;
		background-color: #fff;
		border-radius: 50%;
	}
}
</style>
