<template>
	<view class="work-item"
	:class="{ 'expired': isExpired }"
	@click="handledClick">
		<view class="top">
			<view class="title">
				{{ item.title }}
			</view>
			<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 class="expired-status" v-if="isExpired">
			<text class="expired-text">招聘已截止</text>
		</view>
		
		<view class="tag-list">
			<view 
			v-for="(t, i) in lableText"
			:key="i">
				{{ t }}
			</view>
		</view>
		<view class="bottom">
			<view class="address">
				<!-- <text>2.5km | 楚河汉区</text> -->
				{{ item.workAddress }}
			</view>
			<view class="time">
				<!-- 09月23日  16：20 -->
				{{ $dayjs(item.createTime).format('YYYY-MM-DD') }}
			</view>
			<view class="phone"
			:class="{ 'disabled': isExpired }"
			@click.stop="callPhone">
				<image src="/static/image/home/phone.png" mode=""></image>
				联系老板
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props : {
			item : {
				default : {}
			}
		},
		computed : {
			lableText(){
				let arr = 
				this.item.tab ?
				this.item.tab.split('、')
				: []
				
				if(this.item.workAge){
					arr.unshift(this.item.workAge)
				}
				if(this.item.qulification){
					arr.unshift(this.item.qulification)
				}
				
				return arr
			},
			// 检查是否过期
			isExpired(){
				if(!this.item.deadline) return false
				
				const now = this.$dayjs()
				const deadline = this.$dayjs(this.item.deadline)
				
				return now.isAfter(deadline)
			}
		},
		data() {
			return {
				
			}
		},
		methods: {
			callPhone(){
				// 如果过期，禁止拨打电话
				if(this.isExpired) {
					uni.showToast({
						title: '招聘已截止',
						icon: 'none'
					})
					return
				}
				
				uni.makePhoneCall({
					phoneNumber: this.item.phone,
					success() {
						console.log('安卓拨打成功');
					},
					fail() {
						console.log('安卓拨打失败');
					}
				})
			},
			handledClick(){
				// 如果过期，禁止点击
				if(this.isExpired) {
					uni.showToast({
						title: '招聘已截止，无法查看详情',
						icon: 'none'
					})
					return
				}
				
				this.$emit('click')
			},
		}
	}
</script>

<style scoped lang="scss">
.work-item{
	background-color: #fff;
	padding: 20rpx;
	border-radius: 20rpx;
	position: relative;
	
	// 过期状态样式
	&.expired {
		opacity: 0.6;
		background-color: #f5f5f5;
		
		.title {
			color: #999;
		}
		
		.price {
			color: #999 !important;
		}
	}
	
	.top{
		display: flex;
		justify-content: space-between;
		font-weight: 900;
		.title{
		}
		.price{
			color: $uni-color;
		}
	}
	
	// 过期状态标识
	.expired-status {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		z-index: 10;
		
		.expired-text {
			background-color: rgba(0, 0, 0, 0.8);
			color: #fff;
			padding: 16rpx 32rpx;
			border-radius: 20rpx;
			font-size: 28rpx;
			font-weight: 600;
		}
	}
	
	.bottom{
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 24rpx;
		gap: 16rpx;
		.time{
			color: #999999;
			flex-shrink: 0;
		}
		.phone{
			background-color: rgba($uni-color, 0.2);
			color: $uni-color;
			padding: 8rpx 16rpx;
			border-radius: 10rpx;
			flex-shrink: 0;
			image{
				width: 20rpx;
				height: 20rpx;
			}
			
			// 禁用状态样式
			&.disabled {
				background-color: #f0f0f0;
				color: #999;
				opacity: 0.6;
			}
		}
	}
}
</style>
