<template>
	<view class="page">
		<navbar leftClick @leftClick="$utils.navigateBack" />

		<view class="head">
			<view class="headImage">
				<image :src="hanHaiMember.headImage" mode=""></image>
				<view class="">
					{{ detail.title }}
				</view>
			</view>
			<view class="info">
				<view class="name">
					{{ authenticationPerson.name }}
				</view>
				<view class="tips">
					性别：{{ detail.sex }}
				</view>
				<view class="tips">
					年龄：{{ detail.age }}岁
				</view>
				<view class="tips">
					学历：{{ detail.qualification }}
				</view>
			</view>
			<view class="right">
				<view class="phone"
				@click.stop="callPhone">
					<image src="/static/image/home/phone.png" mode=""></image>
					联系他
				</view>
			</view>

		</view>

		<view style="background-color: #f3f3f3;height: 30rpx;"></view>
		
		<view class="box">

			<view class="userinfo">

				<view class="line"
				style="justify-content: flex-end;">
					<view v-if="collectionFlag == false" @click="addResumeCollection"
					style="display: flex;align-items: center;">
						<uv-icon size="30rpx" color="666" name="star"></uv-icon>
						收藏
					</view>
					
					<view v-else @click="addResumeCollection"
					style="display: flex;align-items: center;color: #f40;">
						<uv-icon size="30rpx" color="#f40" name="star-fill"></uv-icon>
						已收藏
					</view>
				</view>

				<view class="line">
					<view class="left">
						联系电话
					</view>
					<view class="right phone-container">
						<text>{{ displayPhone }}</text>
						<view v-if="!showPhone" class="view-phone-btn" @click="clickShowPhone">
							查看
						</view>
					</view>
				</view>

				<view class="line">
					<view class="left">
						期望工作地
					</view>
					<view class="right">
						{{ detail.expectAddressName || detail.expectAddress }}
					</view>
				</view>

				<view class="line">
					<view class="left">
						民族
					</view>
					<view class="right">
						{{ detail.nation }}
					</view>
				</view>

				<view class="line">
					<view class="left">
						工龄
					</view>
					<view class="right">
						{{ detail.workTime ? `${detail.workTime}年` : '应届生' }}
					</view>
				</view>

				<view class="line">
					<view class="left">
						IP归属地
					</view>
					<view class="right">
						{{ detail.ipAddress || '' }}
					</view>
				</view>

			</view>

			<view class="info">
				<view class="title2">
					<text>个人介绍</text>

				</view>

				<!-- <view 
				class="text" 
				v-html="text">
				</view> -->
				<view class="text">
					<uv-parse :content="detail.brief"></uv-parse>
				</view>
				<view class="tag-list">
					<view :key="i" v-for="(t, i) in detail.tag && detail.tag.split('、')">
						{{ t }}
					</view>
				</view>
			</view>

		</view>
		
		<view class="uni-color-btn"
		@click="$refs.contractManagePopup.open(hanHaiMember.id)">
			发送合同
		</view>
		
		<contractManagePopup ref="contractManagePopup"/>
	</view>
</template>

<script>
	import userHead from '../components/user/userHead.vue'
	import contractManagePopup from '@/components/list/contract/contractManagePopup.vue'
	export default {
		components: {
			userHead,
			contractManagePopup,
		},
		data() {
			return {
				text: '',
				id: 0,
				detail: {},
				hanHaiMember: {},
				authenticationPerson: {},
				collectionFlag: false,
				showPhone : false,
			}
		},
		computed : {
			phone(){
				return this.hanHaiMember && this.hanHaiMember.phone
			},
			// 显示的手机号，根据showPhone状态决定是否脱敏
			displayPhone(){
				const phone = this.phone
				if (!phone) return ''
				if (this.showPhone) {
					return phone
				} else {
					// 手机号脱敏处理，保留前3位和后4位，中间用****代替
					return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
				}
			},
			// 检查数据是否有效
			isDataValid(){
				return this.id
			}
		},
		onLoad({
			id
		}) {
			this.id = id
		},
		onShow() {
			this.getData()
		},
		methods: {
			getData() {
				let data = {
					jobId: this.id
				}
				if (uni.getStorageSync('token')) {
					data.token = uni.getStorageSync('token')
				}
				this.$api('bossQueryResumeById', data, res => {
					if (res.code == 200) {
						this.detail = res.result.resume
						this.collectionFlag = res.result.collectionFlag
						this.hanHaiMember = res.result.hanHaiMember
						this.authenticationPerson = res.result.authenticationPerson
					}
				})
			},
			addResumeCollection(){
				let data = {
					resumeId : this.id
				}
				if(uni.getStorageSync('token')){
					data.token = uni.getStorageSync('token')
				}
				this.$api('addResumeCollection', data, res => {
					this.getData();
					if(res.code == 200){
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				})
			},
            clickShowPhone(){
                this.$store.commit('checkViewCount', {
                    data : this.detail,
                    success : () => {
                        this.showPhone = true
                    }
                })
            },
			callPhone(){
				
				// 检查数据是否有效和电话号码是否存在
				if (!this.isDataValid || !this.phone) {
					uni.showToast({
						title: '联系方式不可用',
						icon: 'none'
					});
					return;
				}
				
				this.$store.commit('checkViewCount', {
                    data : this.detail,
                    phone : this.phone,
                    type : 'phone',
                })
				
				
				// uni.makePhoneCall({
				// 	phoneNumber: this.hanHaiMember && this.hanHaiMember.phone,
				// 	success() {
				// 		console.log('安卓拨打成功');
				// 	},
				// 	fail() {
				// 		console.log('安卓拨打失败');
				// 	}
				// })
			},
		}
	}
</script>

<style scoped lang="scss">
	.page {
		background-color: #fff;
		min-height: 100vh;

		.head {
			display: flex;
			align-items: center;
			position: relative;
			padding: 20rpx;

			image {
				width: 140rpx;
				height: 140rpx;
				border-radius: 50%;
			}

			.headImage {
				width: 160rpx;
				margin-right: 40rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				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;
					margin-top: 10rpx;
				}
			}

			.info {
				font-size: 28rpx;

				.name {
					font-size: 32rpx;
					display: flex;
					padding-bottom: 10rpx;

					view {
						display: flex;
						font-size: 20rpx;
						align-items: center;
						padding-left: 20rpx;
					}
				}

				.tips {
					font-size: 26rpx;
				}
			}

			.right {
				margin-left: auto;

				.phone {
					background-color: rgba($uni-color, 0.2);
					color: $uni-color;
					padding: 8rpx 16rpx;
					border-radius: 10rpx;

					image {
						width: 24rpx;
						height: 24rpx;
					}
				}
			}
		}

		.box {
			padding: 30rpx;

			.userinfo {
				font-size: 28rpx;
				color: #666666;
				line-height: 44rpx;
				margin-bottom: 40rpx;

				.line {
					margin-bottom: 20rpx;
					display: flex;

					.left {
						width: 220rpx;
						flex-shrink: 0;
					}
					
					.phone-container {
						display: flex;
						align-items: center;
						gap: 20rpx;
						
						.view-phone-btn {
							background-color: rgba($uni-color, 0.1);
							color: $uni-color;
							padding: 8rpx 16rpx;
							border-radius: 8rpx;
							font-size: 24rpx;
							border: 1px solid rgba($uni-color, 0.3);
						}
					}
				}
			}

			.info {
				.text {
					font-size: 24rpx;
					color: #666666;
					line-height: 44rpx;
				}
			}
		}
		.uni-color-btn{
			// position: fixed;
			// right: 40rpx;
			// bottom: 30vh;
		}
	}
</style>