<template>
	<view class="jobDetails">
		<view class="jobInfo">
			<view class="f_b">
				<view class="jobName">{{ detail.name }}</view>
				<view class="jobSalary">{{detail.salaryMin}}-{{detail.salaryMax}}元</view>
			</view>
			<view class="companyName">{{detail.industryName}}</view>
			<view class="requirement f_s">
				<view class="f_s">
					<u-icon name="clock"/>
					{{detail.experience}}
				</view>
				<view class="f_s">
					<u-icon name="bookmark"/>
					{{detail.qualification}}
				</view>
				<view class="f_s">
					<u-icon name="bag"/>
					{{ detail.recruitType }}
				</view>
			</view>
		</view>
		<view class="jobDesc">
			<view class="moduleTitle">职位描述</view>
			<view style="white-space: pre-line;line-height: 2;font-weight: 300;">{{detail.details}}</view>
		</view>
		<view class="companyInfo" @click="toCompanyDetails(detail.org)">
			<view class="moduleTitle">公司信息</view>
			<view class="f_b" style="margin-top: 30rpx;">
				<view class="f_s">
					<u--image
						:src="detail.org.logo"
						width="60rpx"
						height="60rpx"
						radius="4"
					/>
					<text style="padding: 0 10px;color: #666;">{{detail.orgName}}</text>
				</view>
				<u-icon
				  size="20"
				  name="arrow-right"
				/>
			</view>
			<!-- <view class="f_s" style="font-weight: 300;color: #666;margin-top: 20rpx;">
				<u-icon
					size="30"
					color="#999"
					
					name="map-fill"
				/>
				{{detail.org.province}} {{detail.org.city}} {{detail.org.region}} {{detail.address}}
			</view> -->
		</view>
		<view class="footer f_b">
			<u-icon
				size="30"
				name="star-fill"
				color="#f40"
				v-if="collect"
				@click="shoucang"
			/>
			<u-icon
				size="30"
				name="star"
				@click="shoucang"
				v-else
			/>
			<view style="width: 20px;"></view>
			<u-button type="primary" text="已投递" v-if="signUp" disabled></u-button>
			<u-button type="primary" text="投递简历" v-else @click="deliver"></u-button>
		</view>
		<LoginOpen v-if="loginShow" @close="loginSuccess"/>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				recruitId: '',
				detail: {},
				userInfo: [],
				token: '',
				signUp: false, // 是否已报名
				collect: false, // 是否已收藏
				loginShow: false, // 登录弹窗
			}
		},
		onLoad(o) {
			console.log(o)
			this.recruitId = o.id
			this.token = uni.getStorageSync('jy-recruit-token') || ''
			this.$http.get('/public/recruit/details', {
				id: o.id,
			}).then(res => {
				this.detail = res.data
				this.getSignRecord()
			})
			this.getLoginInfo()
		},
		methods: {
			toCompanyDetails(org) {
				uni.setStorageSync('ogrDetails',org)
				uni.navigateTo({
					url: '/pages/home/companyDetails'
				})
			},
			getLoginInfo() {
				if (uni.getStorageSync('jy-recruit-token')) {
					this.$http.get('/person/person/details', {}).then(res => {
						this.userInfo = res.data
						this.$http.get('/objective/l', {personId: res.data.id}).then(res => {
							this.userInfo.tabList = res.data.list || []
						})
					})
				}
			},
			shoucang() {
				if (this.token) {
					this.$http.post('/collect/c', {
						recruitId: this.recruitId,
					}).then(res => {
						this.collect = !this.collect
						uni.showToast({
							title: this.collect ? `收藏成功` : '取消成功',
							icon: 'none',
						})
					})
				} else { // 未登录 触发登录
					this.loginShow = true
				}
			},
			// 检查是否已报名
			getSignRecord() {
				if (this.token) {
					this.$http.post('/signRecord/have', {
						recruitId: this.recruitId,
					}).then(res => {
						this.signUp = res.data == '1' ? true : false
					})
					this.$http.post('/collect/have', {
						recruitId: this.recruitId,
					}).then(res => {
						this.collect = res.data == '1' ? true : false
					})
				}
			},
			// 投递简历
			deliver() {
				if (this.token) {
					if (this.userInfo.name && this.userInfo.tabList.length > 0) {
						this.$http.post('/signRecord/c', {
							recruitId: this.recruitId,
						}).then(res => {
							this.signUp = true
							uni.showToast({
								title: `报名成功`,
								icon: 'none',
							})
						})
					} else {
						uni.showToast({
							title: '请先完善简历',
							icon: 'none'
						})
						uni.navigateTo({
							url: `/pages/user/resume/index`
						})
					}
				} else { // 未登录 触发登录
					this.loginShow = true
				}
			},
			loginSuccess(e) {
				this.loginShow = false
				if (e) {
					this.token = e
					this.getSignRecord()
					this.getLoginInfo()
				}
			}
		}
	}
</script>
<style lang="scss">
.jobDetails{
	padding-bottom: 300rpx;
	overflow: auto;
	box-sizing: border-box;
	.moduleTitle{
		font-size: 36rpx;
		color: #333;
	}
	.jobInfo{
		margin: 30rpx 0;
		background: #fff;
		padding: 30rpx;
		.jobName{
			font-size: 40rpx;
		}
		.jobSalary{
			font-size: 40rpx;
			color: #E26767;
		}
		.companyName{
			padding: 20rpx 0;
			font-weight: 300;
		}
		.requirement{
			.u-icon{
				margin-right: 6rpx;
			}
			.f_s + .f_s{
				margin-left: 20rpx;
			}
			font-weight: 300;
		}
	}
	.jobDesc{
		background: #fff;
		padding: 10rpx 0 60rpx;
		margin: 30rpx 0;
		color: #666;
		font-size: 28rpx;
		line-height: 2;
		>view{
			padding:10rpx 30rpx;
		}
	}
	.companyInfo{
		background: #fff;
		padding: 30rpx;
	}
	.footer{
		padding: 20rpx 30px calc(env(safe-area-inset-bottom) + 20rpx);
		background: #fff;
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
		border: none;
		box-sizing: border-box;
	}
}
</style>
