<template>
	<!-- 数据不存在时的友好提示 -->
	<view v-if="!item || !item.id" class="boss-item deleted-item">
		<view class="deleted-content">
			<view class="deleted-icon">⚠️</view>
			<view class="deleted-text">
				<view class="deleted-title">数据已被删除</view>
				<view class="deleted-desc">该用户信息可能已被删除或不存在</view>
			</view>
		</view>
	</view>
	
	<!-- 正常数据显示 -->
	<view v-else class="boss-item"
	@click="$emit('click')">
		<view class="head">
			<view class="headImage">
				<image :src="item.hanHaiMember && item.hanHaiMember.headImage" mode=""></image>
			</view>
			<view class="info">
				<view class="name">
					<!-- 李老板 -->
					{{ item.employAuthenticationPerson && item.employAuthenticationPerson.name }}
					<view v-if="item.typeId_dictText">
						<!-- 装配电工 -->
						{{ item.typeId_dictText }}
					</view>
					<view v-if="item.natureId_dictText">
						<!-- 装配电工 -->
						{{ item.natureId_dictText }}
					</view>
				</view>
				<view class="tips">
					<!-- 男 · 汉族 · 本科 · 应届生 -->
					{{ sex || item.sex }} · {{ item.nation }} · {{ item.qualification }}
				</view>
			</view>
			<view class="right">
				<view class="price"
				v-if="item.salaryLow >= 1000">
					<text>
						{{ (item.salaryLow / 1000).toFixed(0) }}
					</text>
					<text
					v-if="item.salaryUp">
						-{{ (item.salaryUp / 1000).toFixed(0) }}
					</text>
					K
				</view>
				<view class="price" v-else>
					<text>{{ item.salaryLow }}</text>
					<text
					v-if="item.salaryUp">-{{ item.salaryUp }}</text>
				</view>
			</view>
		</view>
		<view class="bottom">
			<view class="time">
				<!-- 09月23日  16：20 -->
				{{ $dayjs(createTime || item.createTime).format('YYYY-MM-DD') }}
			</view>
			<view class="phone"
			@click.stop="callPhone">
				<image src="/static/image/home/phone.png" mode=""></image>
				联系他
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props : {
			item : {
				default : {}
			},
			createTime : {
				default : '',
			},
			image : {
				default : ''
			},
			sex : {
				default : ''
			},
		},
		data() {
			return {
				
			}
		},
		computed : {
			headImage(){
				return this.image || (this.item && this.item.headImage) || '/static/image/center/headImage.png'
			},
			phone(){
				return this.item && this.item.hanHaiMember && this.item.hanHaiMember.phone
			},
			// 检查数据是否有效
			isDataValid(){
				return this.item && this.item.id
			}
		},
		methods: {
			callPhone(){
				
				// 检查数据是否有效和电话号码是否存在
				if (!this.isDataValid || !this.phone) {
					uni.showToast({
						title: '联系方式不可用',
						icon: 'none'
					});
					return;
				}
				
				this.$store.commit('checkViewCount', {
                    data : this.item,
                    phone : this.phone,
                    type : 'phone',
                })
				
				// uni.makePhoneCall({
				// 	phoneNumber: this.phone,
				// 	success() {
				// 		console.log('安卓拨打成功');
				// 	},
				// 	fail() {
				// 		console.log('安卓拨打失败');
				// 	}
				// })
			},
		}
	}
</script>

<style scoped lang="scss">
.boss-item{
	background-color: #fff;
	border-radius: 20rpx;
	
	&.deleted-item {
		background-color: #f5f5f5;
		border: 2rpx dashed #ccc;
		padding: 40rpx 20rpx;
		
		.deleted-content {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			text-align: center;
			
			.deleted-icon {
				font-size: 60rpx;
				margin-bottom: 20rpx;
			}
			
			.deleted-text {
				.deleted-title {
					font-size: 32rpx;
					color: #666;
					font-weight: bold;
					margin-bottom: 10rpx;
				}
				
				.deleted-desc {
					font-size: 24rpx;
					color: #999;
				}
			}
		}
	}
	.head {
		display: flex;
		align-items: center;
		position: relative;
		padding: 20rpx;
		
	
		image {
			width: 100%;
			height: 100%;
		}
	
		.headImage {
			width: 80rpx;
			height: 80rpx;
			background-size: 100% 100%;
			overflow: hidden;
			border-radius: 50%;
			margin-right: 40rpx;
		}
	
		.info {
			font-size: 28rpx;
	
			.name {
				font-size: 32rpx;
				display: flex;
				padding-bottom: 10rpx;
				
				view {
					display: flex;
					font-size: 24rpx;
					align-items: center;
					margin-left: 20rpx;
					background: rgba($uni-color, 0.2);
					color: $uni-color;
					padding: 10rpx;
					border-radius: 10rpx;
				}
			}
	
			.tips {
				font-size: 24rpx;
			}
		}
		.right{
			margin-left: auto;
			font-size: 24rpx;
			.price{
				color: $uni-color;
			}
		}
	}
	.bottom{
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
		font-size: 24rpx;
		padding: 20rpx;
		padding-top: 0;
		.time{
			color: #999999;
		}
		.phone{
			background-color: rgba($uni-color, 0.2);
			color: $uni-color;
			padding: 8rpx 16rpx;
			border-radius: 10rpx;
			image{
				width: 20rpx;
				height: 20rpx;
			}
		}
	}
}
</style>
