<template>
	<view class="content">
		<view class="box">
			<view class="hflex acenter jbetween">
				<view class="top">{{pageData.title}}</view>
				<view class="text_blue">{{pageData.salary_start}}
				{{(pageData.salary_start + '').indexOf('k') != -1 || (pageData.salary_start + '').indexOf('K') != -1 ? '' : 'k'}}-{{pageData.salary_end}}
				{{(pageData.salary_end + '').indexOf('k') != -1 || (pageData.salary_end + '').indexOf('K') != -1 ? '' : 'k'}}</view>
			</view>
			<view class="hflex acenter fwrap">
				<view class="box_item" v-if="pageData.number_person">招{{pageData.number_person}}人</view>
				<!-- <view class="box_item" v-if="pageData.experience">{{pageData.experience}}</view> -->
				<view class="box_item" v-if="pageData.schooling">{{pageData.schooling}}</view>
				<view class="box_item" v-if="pageData.age">{{pageData.age}}</view>
				<view class="box_item" v-if="pageData.sex">{{pageData.sex}}性</view>
			</view>
		</view>
		<view class="box">
			<view class="hflex acenter">
				<image :src="pageData.contact_headimg" class="headimg"></image>
				<view class="text1">{{pageData.contact_person}}</view>
			</view>
			<view class="hflex acenter padT-26">
				<u-icon name="phone-fill" color="#666666" size="14" class="padR-24"></u-icon>
				<view class="text_style1">{{pageData.contact_phone}}<span style="color: #506dff;" @click="tall(pageData.contact_phone)"><span style="padding: 0 5rpx;">|</span>拨打</span></view>
			</view>
			<view class="hflex acenter padT-26">
				<image src="/static/images/index/demand/email.png" class="icon"></image>
				<view class="text_style1">{{pageData.contact_email}}<span style="color: #506dff;" @click="copy(pageData.contact_email)"><span style="padding: 0 5rpx;">|</span>复制</span></view>
			</view>
		</view>
		<view class="box">
			<view class="box_title">职位描述</view>
			<view class="desc">
				<view class="hflex pad_tb10">
					<view class="label">地区范围</view>
					<view class="text_style1">{{pageData.province}}{{pageData.city}}{{pageData.area}}{{pageData.address}}</view>
				</view>
				<view class="hflex acenter pad_tb10">
					<view class="label">用工时间</view>
					<view class="text_style1">{{pageData.working_time}}</view>
				</view>
				<view class="hflex acenter pad_tb10">
					<view class="label">用工性质</view>
					<view class="text_style1">{{pageData.work_nature}}</view>
				</view>
			</view>
		</view>
		<view class="box" v-if="pageData.necessary_skills">
			<view class="box_title">必备技能</view>
			<view class="">
				<view class="text2">{{pageData.necessary_skills}}</view>
				<!-- <block v-for="(item,index) in pageData.necessary_skills" :key="index">
					<view class="text2">{{index+1}}.{{item.name}}</view>
				</block> -->
			</view>
		</view>
		<view class="box" v-if="pageData.experience">
			<view class="box_title">经验</view>
			<view class="">
				<view class="text2">{{pageData.experience}}</view>
				<!-- <block v-for="(item,index) in pageData.necessary_skills" :key="index">
					<view class="text2">{{index+1}}.{{item.name}}</view>
				</block> -->
			</view>
		</view>
		<view class="box" v-if="pageData.certificate">
			<view class="box_title" style="padding-top: 20rpx;">证书</view>
			<view class="hflex acenter">
				<view class="text2">{{pageData.certificate}}</view>
				<!-- <block v-for="(item,index) in pageData.certificate" :key="index">
					<view class="text2">{{item.name}}</view>
				</block> -->
			</view>
		</view>
		<view class="box" v-if="pageData.welfare_benefits">
			<view class="box_title">福利待遇</view>
			<view class="text2">{{pageData.welfare_benefits}}</view>
		</view>
		<view class="box" v-if="pageData.remark" style="margin-bottom: 186rpx;">
			<view class="box_title">备注</view>
			<view class="text2">{{pageData.remark}}</view>
		</view>
		<view class="bottom hflex acenter jbetween">
			<view class="hflex acenter">
				<view class="vflex acenter" style="margin-right: 20rpx;" @click="collect">
					<u-icon name="star" color="#444444" size="20" v-if="pageData.is_collection == 0"></u-icon>
					<u-icon name="star-fill" color="#506DFF" size="20" v-else></u-icon>
					<view class="text_style1">收藏</view>	
				</view>	
				<view class="vflex acenter" @click="share('Poster1')">
					<image src="https://ship.shipcc.cn/common/share.png" mode="" class="bottom_img"></image>	
					<view class="text_style1">分享</view>	
				</view>	
			</view>
			<view class="hflex acenter">
				<view class="left_btn hflex acenter jcenter" :class="pageData.huanxinID ? '' : 'left_btn1'" @click="like">
					<u-icon name="heart" color="#506DFF" size="20" v-if="pageData.is_like == 0"></u-icon>
					<u-icon name="heart-fill" color="#506DFF" size="20" v-else></u-icon>
					<view class="btn_text">感兴趣</view>
				</view>
				<view class="right_btn hflex acenter jcenter" @click="into_chatroom" v-if="pageData.huanxinID">
					<image src="https://ship.shipcc.cn/common/chat.png" class="btn_icon"></image>
					<view class="btn_text2">立即沟通</view>
				</view>
			</view>
		</view>
		<view class="share_content" :class="share_show?'':'share_content1'">
			<!-- <view style="width: 100%;height: 168rpx;"></view> -->
			<view class="share_box vflex">
				<view class="hflex acenter">
					<image class="Poster1 pos_img" data-etype="image" :data-enode="posImg" :src="posImg"></image>
					<view class="vflex">
						<view class="Poster1 pos_title" :data-enode="pageData.title">{{pageData.title}}</view>
						<view class="Poster1 pos_subtitle" :data-enode="pageData.salary_start + (pageData.salary_start + '').indexOf('k') && (pageData.salary_start + '').indexOf('K') != -1 ? '' : 'k'+'-'+pageData.salary_end + (pageData.salary_end + '').indexOf('k') && (pageData.salary_end + '').indexOf('K') != -1 ? '' : 'k'">{{pageData.salary_start}}
						{{(pageData.salary_start + '').indexOf('k') && (pageData.salary_start + '').indexOf('K') != -1 ? '' : 'k'}}-{{pageData.salary_end}}
						{{(pageData.salary_end + '').indexOf('k') && (pageData.salary_end + '').indexOf('K') != -1 ? '' : 'k'}}</view>
					</view>
				</view>
				<view class="Poster1 pos_title2" data-enode="职位描述">职位描述</view>
				<view class="hflex acenter">
					<view class="label Poster1" data-enode="地区范围">地区范围</view>
					<view class="Poster1 text" :data-enode="pageData.province + pageData.city + pageData.area + pageData.address">{{pageData.province}}{{pageData.city}}{{pageData.area}}{{pageData.address}}</view>
				</view>
				<view class="hflex acenter">
					<view class="label Poster1" data-enode="用工时间">用工时间</view>
					<view class="Poster1 text" :data-enode="pageData.working_time">{{pageData.working_time}}</view>
				</view>
				<view class="hflex acenter">
					<view class="label Poster1" data-enode="用工性质">用工性质</view>
					<view class="Poster1 text" :data-enode="pageData.work_nature">{{pageData.work_nature}}</view>
				</view>
				<view class="hflex acenter share_text jcenter Poster1" style=" margin: 0 190rpx 12rpx;" data-enode="长按或扫码查看">扫码查看职位详情</view>
				<view style="width: 100%;" class="vflex acenter jcenter">
					<image class="Poster1" style="width: 25rpx;height: 20rpx;" :data-enode="style.img1" data-etype="image" :src="style.img1"></image>
					<image class="Poster1" style="width: 100%;height: 2rpx;margin: 30rpx 0;" :data-enode="style.img2" data-etype="image" :src="style.img2"></image>
				</view>
				<view class="hflex acenter jbetween">
					<view class="vflex">
						<view class="share_name Poster1" style="margin: 54rpx 0 20rpx;" data-enode="船百知">船百知</view>
						<view class="share_text Poster1" style="margin: 0 0 36rpx;" data-enode="船百知伴你一起杨帆启航,驶向成功彼岸">船百知伴你一起杨帆启航,驶向成功彼岸</view>
					</view>
					<image class="Poster1" data-etype="image" :data-enode="style.code" :src="style.code" style="width: 136rpx;height: 136rpx;"></image>
					<!-- <image class="Poster1" data-etype="image" :data-enode="pageData.contact_headimg" :src="pageData.contact_headimg" style="width: 136rpx;height: 136rpx;"></image> -->
				</view>
			</view>
			<evils-el-poster width="325" height="467" @on-error="onError" :list="list" backgroundColor="rgb(255, 255, 255)" @on-success="onSuccess" ref="Eposter"></evils-el-poster>
			<view class="share_bottom">
				<view class="hflex acenter jcenter">
					<button class="vflex acenter jcenter bottom_item" open-type="share">
						<image src="https://ship.shipcc.cn/common/wx.png" class="item_icon"></image>
						<view class="item_text">微信好友</view>
					</button>
					<!-- <button class="vflex acenter jcenter bottom_item" open-type="share">
						<image src="https://ship.shipcc.cn/common/moments.png" class="item_icon"></image>
						<view class="item_text">朋友圈</view>
					</button> -->
					<view class="vflex acenter jcenter bottom_item" @click="saveImg">
						<image src="https://ship.shipcc.cn/common/download.png" class="item_icon"></image>
						<view class="item_text">保存图片</view>
					</view>
				</view>
				<view class="share_cancel" @click="close">取消</view>
			</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				pageData: {},
				id: '',
				share_show: false,
				posImg: 'https://ship.shipcc.cn/common/company2.png',
				list: {},
				style: {
					img1: 'https://ship.shipcc.cn/common/down2.png',
					img2: 'https://ship.shipcc.cn/common/line.png',
					code: 'https://ship.shipcc.cn/common/code.jpg'
				},
			}
		},
		onLoad(options) {
			that = this
			that.id = options.id
			that.getData()
			let view = uni.createSelectorQuery().in(this).select(".Poster1");
			
			view.fields({
			  size: true,
			  rect: true,
			  scrollOffset: true
			}, data => {
			}).exec();
		},
		onShareAppMessage(res) {
			console.log(res);
		    if (res.from === 'button') {// 来自页面内分享按钮
		        console.log(res.target)
		    }
		    return {
		        title: '船百知', //分享的名称
		    }
		},
		onShareTimeline(res) {
			console.log(res);
		    return {
		        title: '船百知',
		        type: 0,
		        summary: "",
		    }
		},
		methods: {
			getData() {
				$api.req({
					url: '/data/api.auth.DemandLabor/demanddetail',
					method: 'POST',
					data: {
						type: 1,
						id: that.id
					}
				}, function(res) {
					if(res.code == 1) {
						console.log(res);
						that.pageData = res.data
					}
				})
			},
			// 复制
			copy(value) {
				uni.setClipboardData({
					data: value,
					success: function () {
						$api.info('复制成功')
					}
				});
			},
			tall(value) {
				uni.makePhoneCall({
					phoneNumber: value
				});
			},
			collect() {
				$api.req({
					url: '/data/api.auth.DemandLabor/cocanclecollection',
					method: 'POST',
					data: {
						type: 1,
						id: that.id,
						category: that.pageData.is_collection + 1
					}
				}, function(res) {
					if(res.code == 1) {
						$api.info(res.info)
						if(that.pageData.is_collection) {
							that.pageData.is_collection = 0
						}  else {
							that.pageData.is_collection = 1
						}
					}
				})
			},
			like() {
				$api.req({
					url: '/data/api.auth.DemandLabor/cocanclelike',
					method: 'POST',
					data: {
						type: 1,
						id: that.id,
						category: that.pageData.is_like + 1
					}
				}, function(res) {
					if(res.code == 1) {
						$api.info(res.info)
						if(that.pageData.is_like) {
							that.pageData.is_like = 0
						}  else {
							that.pageData.is_like = 1
						}
					}
				})
			},
			into_chatroom() {
				var my = uni.getStorageSync("myUsername");
				var nameList = {
				  myName: my,
				  your: that.pageData.huanxinID,
				};
				uni.navigateTo({
				  url: "/pages/chatroom/chatroom?username=" + JSON.stringify(nameList),
				});
			},
			share(elClass) {
				
				that.share_show = true
				that.$refs.Eposter.createForElRect(elClass,false)
			},
			close() {
				that.share_show = false
			},
			onSuccess(e) {
				console.log('返回的地址',e);
				that.tempImage = e
			},
			onError(err) {
				console.log('发生错误');
				console.log(err);
			},
			saveImg() {
				console.log('准备保存的图片',that.tempImage);
				uni.authorize({
				    scope: 'scope.writePhotosAlbum',
				    success() {
				        uni.saveImageToPhotosAlbum({
				        	filePath: that.tempImage,
				        	success: function () {
				        		console.log('save success');
								$api.info('保存成功')
								that.close()
				        	}
				        });
				    }
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		.box {
			width: 690rpx;
			margin: 0 30rpx;
			box-sizing: border-box;
			padding: 20rpx 0;
			border-bottom: 1rpx solid #F4F4F4;
			.top {
				font-size: 40rpx;
				font-weight: 500;
				color: #222222;
				line-height: 56rpx;
				padding: 24rpx 0 20rpx;
			}
			.text_blue {
				font-size: 32rpx;
				font-weight: 400;
				color: #506DFF;
				line-height: 40rpx;
			}
			.box_item {
				width: auto;
				height: 40rpx;
				background: #F0F2F6;
				border-radius: 4rpx;
				margin: 0 20rpx 20rpx 0;
				padding: 0 16rpx;
				font-size: 22rpx;
				font-weight: 400;
				color: #444444;
				line-height: 40rpx;
			}
			.headimg {
				width: 72rpx;
				height: 72rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}
			.text1 {
				font-size: 30rpx;
				font-weight: 500;
				color: #222222;
				line-height: 42rpx;
			}
			.padT-26 {
				padding-top: 26rpx;
			}
			.padR-24 {
				padding-right: 24rpx;
			}
			.label {
				width: 20%;
				font-size: 24rpx;
				font-weight: 400;
				color: #444444;
			}
			.icon {
				width: 28rpx;
				height: 28rpx;
			}
			.text_style1 {
				width: 80%;
				font-size: 24rpx;
				padding-left: 5rpx;
				font-weight: 400;
				color: #666666;
			}
			.box_title {
				font-size: 32rpx;
				font-weight: 500;
				color: #222222;
			}
			.desc {
				margin: 16rpx 0 0;
				background: #F7F7F7;
				border-radius: 8px;
				box-sizing: border-box;
				padding: 24rpx 20rpx;
				.pad_tb10 {
					padding: 10rpx 0;
				}
			}
			.text2 {
				font-size: 24rpx;
				font-weight: 400;
				color: #333333;
				line-height: 34rpx;
				padding: 16rpx 0 0;
			}
		}
		.bottom {
			width: 100%;
			z-index: 9;
			position: fixed;
			bottom: 0;
			height: 166rpx;
			background: #FFFFFF;
			box-sizing: border-box;
			box-shadow: 0px -1px 0px 0px #F4F4F4;
			padding: 8rpx 30rpx 74rpx;
			.text_style1 {
				font-size: 20rpx;
				font-weight: 400;
				color: #444444;
			}
			.left_btn {
				width: 230rpx;
				height: 80rpx;
				background: #F1F6FF;
				border-radius: 42rpx;
			}
			.left_btn1 {
				width: 500rpx;
			}
			.btn_text {
				font-size: 32rpx;
				font-weight: 500;
				color: #506DFF;
				line-height: 44rpx;
				padding-left: 10rpx;
			}
			.right_btn {
				width: 230rpx;
				height: 80rpx;
				background: #506DFF;
				border-radius: 42rpx;
				margin-left: 20rpx;
				.btn_icon {
					width: 40rpx;
					height: 40rpx;
				}
				.btn_text2 {
					font-size: 32rpx;
					font-weight: 500;
					color: #FFFFFF;
					line-height: 44rpx;
					padding-left: 10rpx;
				}
			}
			.bottom_img {
				width: 40rpx;
				height: 40rpx;
			}
			
		}
		.share_content {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			width: 100vw;
			height: 100vh;
			background: rgba(0,0,0,0.5);
			backdrop-filter: blur(5px);
			padding: 0 0 0;
			.pos_img {
				width: 112rpx;
				height: 112rpx;
				margin: 0 12rpx 0 0;
			}
			.pos_title {
				font-size: 32rpx;
				font-weight: 500;
				color: #222222;
				line-height: 44rpx;
				margin: 0 0 0 0;
			}
			.pos_subtitle {
				font-size: 32rpx;
				font-weight: 400;
				color: #506DFF;
				line-height: 40rpx;
				margin: 24rpx 0 0;
			}
			.pos_title2 {
				font-size: 28rpx;
				font-weight: 500;
				color: #222222;
				line-height: 40rpx;
				margin: 36rpx 0 28rpx;
			}
			.label {
				width: 120rpx;
				font-size: 24rpx;
				font-weight: 400;
				color: #444444;
				line-height: 34rpx;
				margin: 0 0 20rpx;
			}
			.text {
				font-size: 24rpx;
				font-weight: 400;
				color: #444444;
				line-height: 34rpx;
				margin: 0 0 20rpx;
			}
			.share_box {
				margin: 130rpx auto 0;
				width: 650rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				box-sizing: border-box;
				padding: 48rpx 40rpx 0;
				.share_name {
					width: 100%;
					font-size: 32rpx;
					font-weight: 500;
					color: #222222;
					line-height: 44rpx;
				}
				.share_label {
					width: 100%;
					font-size: 28rpx;
					font-weight: 400;
					color: #222222;
					line-height: 40rpx;
				}
				.share_text {
					width: 100%;
					font-size: 24rpx;
					font-weight: 400;
					color: #999999;
					line-height: 34rpx;
					text-overflow: ellipsis;
					overflow: hidden;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					box-orient: vertical;
					line-clamp: 5;
					-webkit-line-clamp: 5;
				}
				.box_bottom {
					width: 100%;
					padding: 34rpx 0 16rpx;
					border-top: 1rpx dashed #C3C3C3;
					
					.bottom_left1 {
						font-size: 32rpx;
						font-weight: 500;
						color: #222222;
						line-height: 44rpx;
						padding-bottom: 20rpx;
						
					}
					.bottom_left2 {
						font-size: 22rpx;
						font-weight: 400;
						color: #999999;
						line-height: 32rpx;
					}
					.bottom_right {
						width: 136rpx;
						height: 136rpx;
					}
				}
			}
			.canvas {
				position: absolute;
				top: 188rpx;
				left: 50rpx;
				width: 650rpx;
				min-height: 494rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
			}
			.share_bottom {
				position: fixed;
				bottom: 0;
				width: 100%;
				height: 388rpx;
				background: #F5F7FF;
				border-radius: 40rpx 40rpx 0px 0px;
				.bottom_item {
					width: 33%;
					margin: 50rpx 0 90rpx;
					border: none !important;
					background-color: #F5F7FF !important;
					
					
					.item_icon {
						width: 76rpx;
						height: 76rpx;
					}
					.item_text {
						font-size: 26rpx;
						font-weight: 400;
						color: #333333;
						line-height: 36rpx;
						margin-top: 12rpx;
					}
				}
				button::after {
					border: none !important;
				}
				.share_cancel {
					width: 100%;
					text-align: center;
					font-size: 32rpx;
					font-weight: 400;
					color: #333333;
					line-height: 44rpx;
				}
			}
		}
		.share_content1 {
			z-index: -99 !important;
		}
	}
</style>