<template>
	<view style="padding-bottom: 100px;">
		<view class="dtop">
			<view class="title">{{ item.title || '' }}</view>
			<view class="price" v-if="item.type == 0">{{ item.salary == '面议' ? item.salary : item.salary + '/月' }}</view>
			<view class="price" v-if="item.type == 1">{{ item.salary }}¥</view>
			<view class="desc" v-if="item.title">
				<text v-if="item.type == 0">{{ item.experience == '不限' ? '经验不限' : item.experience + '经验' }}</text>
				<text>{{ item.positionName || '' }}</text>
				<text>{{ item.type == 0 ? '全职' : '完工结算' }}</text>
				<view class="audit">
					<text class="icon">&#xe64f;</text>
					<text>已审核</text>
				</view>
			</view>
		</view>
		<view class="mbos">
			<view class="ms" style="margin-top: 0px">
				<view v-if="item.type == 1">
					<view class="mtitle">兼职时间</view>
					<view class="desc mb15">{{ item.startDate }}至{{ item.endDate }}，共计：{{ item.days }}天</view>
					<view class="mtitle">兼职地点</view>
					<view class="desc mb15">{{ item.address || '工作地点不限' }}</view>
					<view class="mtitle">结算方式</view>
					<view class="desc mb15">在规定时间内完工结算（平台打款）</view>
				</view>
				<view class="mtitle">{{ item.type == 0 ? '职位描述' : '兼职描述' }}</view>
				<u-parse :content="item.contents" class="item"></u-parse>
				<map :latitude="item.latitude" :longitude="item.longitude" :markers="covers" v-if="item.latitude && item.type == 1"></map>
			</view>
			<!--企业信息-->
			<view v-if="item.type == 0">
				<view class="ms" @click="go('/pages/job/enterprise/detail?id=' + enterprise.id)">
					<view class="icon gs">&#xe646;</view>
					<view class="con">
						<view class="mti omit">{{ enterprise.name }}</view>
						<view class="address omit">{{ enterprise.address }}</view>
					</view>
					<text class="icon more">&#xe62b;</text>
				</view>
				<map :latitude="item.latitude" :longitude="item.longitude" :markers="covers"></map>
			</view>
		</view>
		<view class="bz pl5">
			<text class="icon">&#xe634;</text>
			<text>如有疑问或者需要帮助请联系我们客服</text>
			<button class="contact" open-type="contact">
				<text class="icon">&#xe632;</text>
				<text>点我沟通</text>
			</button>
		</view>
		<view class="mfooter">
			<view class="cn">
				<button class="tob share" open-type="share">
					<text class="icon">&#xe637;</text>
					<view class="mtt">分享</view>
				</button>
				<view class="tob" @click="add()" :class="{ active: flag }">
					<text class="icon">&#xe626;</text>
					<view class="mtt">收藏</view>
				</view>
				<button class="btn" @click="send()">
					<text class="icon">&#xe652;</text>
					<text>{{ item.type == 0 ? '投递简历' : '立即报名' }}</text>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			item: {},
			enterprise: {},
			covers: [],
			flag: false
		};
	},
	onLoad(e) {
		this.http.request({
			url: '/app/position/detail/' + e.id,
			success: (res) => {
				this.item = res.data.data.position;
				this.enterprise = res.data.data.enterprise;
				this.covers.push({ latitude: this.item.latitude, longitude: this.item.longitude });
				this.item.days = this.util.days(this.item.startDate, this.item.endDate);
			}
		});
	},
	methods: {
		go(url) {
			uni.navigateTo({ url: url });
		},
		//收藏职位
		add() {
			this.http.request({
				url: '/app/favorite/add/' + this.item.id,
				success: (res) => {
					uni.showToast({ title: '收藏成功' });
					this.flag = true;
				}
			});
		},
		//投递简历
		send() {
			this.http.request({
				url: '/app/deliver/send/' + this.item.id,
				success: (res) => {
					//实名认证跳转
					if (res.data.code == 7878) {
						uni.showModal({
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: (res) => {
								uni.navigateTo({ url: '/pages/user/auth' });
							}
						});
						return;
					}
					//完善简历跳转
					if (res.data.code == 7979) {
						uni.showModal({
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: (res) => {
								uni.navigateTo({ url: '/pages/user/resume/index' });
							}
						});
						return;
					}
					let tmplIds = [];
					if (this.item.type == 0) {
						tmplIds = ['ll-qdaEgbDN4rEod0nJpsjUuSqHT9e12EniZfRPiNqM'];
					}
					if (this.item.type == 1) {
						tmplIds = ['yhFtY-hzXerPnIxXcYcRCAjQUf8CdLoYEQQi5nBgim0', '87jYTnpeZJnvdQ6gHcscZ96eQYlSXpfGeFU3g9deTeA'];
					}
					//通知模板订阅消息
					uni.requestSubscribeMessage({
						tmplIds: tmplIds,
						complete: (c) => {
							uni.showModal({ content: this.item.type == 0 ? '投递成功，等待企业回应' : '报名成功，等待雇主审核', showCancel: false });
						}
					});
				}
			});
		},
		//分享
		onShareAppMessage: function (res) {
			return {
				title: this.item.title,
				path: '/pages/job/detail?id=' + this.item.id,
				success: (res) => {},
				fail: (res) => {}
			};
		}
	}
};
</script>

<style lang="scss">
.mfooter {
	background-color: white;
	bottom: 0px;
	border-top: 1px solid $line;
	.cn {
		padding: 10px 10px 15px 10px;
		overflow: hidden;
		.tob {
			margin-right: 15px;
			float: left;
			color: $font-c;
			&.active {
				color: $main-color;
			}
			.icon {
				font-size: 28px;
			}
			.mtt {
				font-size: 14px;
			}
		}
		.share {
			background-color: white;
			line-height: 22px;
			padding-top: 3px;
		}
		.btn {
			float: right;
			margin-top: 5px;
		}
	}
}
</style>
