<template>
	<view v-if="pageloading">

		<view class="padding-lr padding-tb margin-bottom-sm bg-white">
				<view class="bg-white padding-top-sm text-xl text-black text-bold">
					<text v-if="supply.mnumber>0"> 男{{supply.mnumber}}人，</text><text v-if="supply.wnumber>0"> 女{{supply.wnumber}}人</text>【{{supply.agegroup}}】
				</view>
				<view class="bg-white padding-top-sm text-gray flex justify-between">
					 <view><text style="min-width: calc(6em);">可到岗日期：</text>{{supply.candate}}</view>
					 <view>{{supply.updatetime_text}}</view>
				</view>
				<view class="bg-white padding-top-sm text-gray flex justify-start">
					 <text style="min-width: calc(6em);">人员所在地：</text><text>{{supply.province}} {{supply.city}} {{supply.district}}</text>
				</view>
				<view class="bg-white padding-top-sm text-gray flex justify-start">
					 <text style="min-width: calc(6em);">期望工作地：</text><text>{{supply.descity}}</text>
				</view>
				<view class="bg-white padding-top-sm text-gray text-right text-sm">
					{{supply.worker.title}}
				</view>
		</view>

		<view class="cu-bar bg-white solids-bottom">
			<view class="action">
				<text class="cuIcon-titles text-red"></text> 情况说明
			</view>
		</view>
		<view class="echo-article-details bg-white margin-bottom-sm">
			<text>{{supply.remark}}</text>
		</view>

		<view class="cu-bar bg-white solids-bottom margin-top-sm">
			<view class="action">
				<text class="cuIcon-titles text-red"></text> 店铺推荐
			</view>
			<view class="action" @tap="goPage('/pages/worker/shop?workerid='+supply.workerid)">
				<text class="text-df">进店看看 </text>
				<view class="cuIcon-right"></view>
			</view>
		</view>

		<block v-for="(item,index) in supplylist" :key="index">
			<view class="cu-card dynamic no-card solid-bottom echo-supply-item">
				<view class="cu-item shadow padding-top-sm padding-bottom" @tap="goDetail(item.id)">
					<view class="padding-lr padding-bottom-sm flex justify-between align-center">
						<view class="basis-xl text-bold text-lg text-cut"><text v-if="item.mnumber>0"> 男{{item.mnumber}}人，</text><text v-if="item.wnumber>0"> 女{{item.wnumber}}人</text>【{{item.agegroup}}】</view>
						<view class="basis-xs text-cut text-right text-gray text-sm">{{item.updatetime_text}}</view>
					</view>
					<view class="padding-lr padding-bottom-sm text-cut text-gray text-sm">
						{{item.province}} {{item.city}} <text class="cuIcon-move margin-lr-xs text-gray"></text> {{item.descity}}
					</view>
					<view class="padding-lr text-sm text-gray"> 可到岗日期：{{item.candate}} </view>
					<view class="text-gray padding-lr text-sm padding-top-sm flex align-center justify-between" @tap="goShop(item.workerid)">
						<view class="text-cut basis-xl flex align-center">
							<image class="iconyrz" :src="$getImageUrl('static/images/applet/iconyrz.png')" mode="scaleToFill"></image>
							<view class="margin-left-sm">{{item.worker.title}}</view>
						</view>
						<view class="text-gray text-right basis-xs">
							<text class="cuIcon-shop margin-right-xs text-lg"></text>
							进店
						</view>
					</view>
				</view>
			</view>
		</block>

		<view class="padding"></view>
		<view class="padding"></view>
		<view class="cu-bar bg-white tabbar border shop foot">
			<view class="action" @tap="goPage('/pages/worker/shop?workerid='+supply.workerid)">
				<view class="cuIcon-shop"></view>
				进店
			</view>

			<button class="action" open-type="share" v-if="appplatform!='ios'">
				<view class="cuIcon-weixin text-green">
					<view class="cu-tag badge" style="font-size: 16rpx;">邀好友</view>
				</view>
				分享
			</button>

			<view class="bg-red submit echo-foot-button" :data-telephone="supply.telephone" @tap="makeTelephone"> <text>电话咨询</text> </view>
		</view>

		<wxContact></wxContact>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				appplatform: "",
				pageloading: false,
				userinfo: false,
				workerinfo: false,
				param: {},
				supply: {},
				iscantele: false,
				supplylist: {},

				modal: {
					isshow: "",
					supplypic: ""
				}
			}
		},
		onLoad: function(option) {
			_this = this;
			//#ifdef APP-PLUS
			_this.appplatform = uni.getSystemInfoSync().platform;
			//#endif
			var supplyid = option.supplyid || 0;
			var parentid = option.parentid || 0;
			if (option.scene) {
				const scene = decodeURIComponent(option.scene);
				if (scene != "undefined") {
					supplyid = scene.split("&")[0];
					parentid = scene.split('&')[1];
				}
			}
			uni.setStorageSync('parentid', parentid);
			_this.userinfo = _this.checkLogin("/pages/my/my");
			_this.workerinfo = uni.getStorageSync('workerinfo') || false;
			if (_this.userinfo === false || _this.workerinfo === false) {
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			_this.$req.ajax({
				path: "supply/getsupply",
				title: "加载中...",
				data: {
					supplyid: supplyid,
					userid: _this.userinfo == null ? 0 : _this.userinfo.id
				}
			}).then((data) => {
				_this.param = data.param;
				_this.supply = data.supply;
				_this.iscantele = data.iscantele;
				_this.supplylist = data.supplylist;
				_this.pageloading = true;
			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false
				});
			});
		},
		onShareAppMessage: function(res) {
			return {
				title: ( _this.supply.mnumber>0?("男"+ _this.supply.mnumber +"人，"):"")+(_this.supply.wnumber>0?("女"+ _this.supply.wnumber +"人"):"")+"【"+_this.supply.agegroup+"】",
				path: "/pages/supply/detail?supplyid=" + _this.supply.id + "&parentid=" + _this.userinfo == null ? 0 : _this.userinfo.id
			}
		},
		methods: {
			getSupplyCode: function() {
				_this.userinfo = _this.checkLogin("/pages/supply/detail?supplyid=" + _this.supply.id);
				if (_this.userinfo === false) {
					return false;
				}
				_this.$req.ajax({
					title: "招聘简章生成中...",
					path: "supply/getsupplycode",
					data: {
						supplyid: _this.supply.id,
						userid: _this.userinfo.id
					}
				}).then((data) => {
					_this.modal.supplypic = data.supplypic;
					_this.modal.isshow = "show";
				}).catch((err) => {
					uni.showModal({
						title: '温馨提示',
						content: err,
						showCancel: false
					});
				});
			},

			saveImage: function() {
				uni.downloadFile({
					url: _this.modal.supplypic, //仅为示例，并非真实的资源
					success: (res) => {
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function() {
									uni.showModal({
										title: '信息提示',
										content: "已保存到手机相册，注意查收。",
										showCancel: false
									});
								}
							});
						}
					}
				});
			},

			hideModal: function() {
				_this.modal.isshow = "";
			},

			setSupplyLog: function() {
				_this.$req.ajax({
					title: "报名中",
					path: "supply/setsupplylog",
					data: {
						supplyid: _this.supply.id,
						gworkerid: _this.workerinfo.id
					}
				}).then((data) => {
					uni.showModal({
						title: '温馨提示',
						content: "恭喜您，报名成功，请尽快提供就业人员。",
						showCancel: false
					});
				}).catch((err) => {
					uni.showModal({
						title: '温馨提示',
						content: err,
						showCancel: false
					});
				});
			},

			goPage: function(pageurl) {
				uni.navigateTo({
					url: pageurl,
					fail: function() {
						uni.switchTab({
							url: pageurl
						});
					}
				});
			},
			goDetail: function(supplyid) {
				uni.navigateTo({
					url: '/pages/supply/detail?supplyid=' + supplyid
				});
			},
			goShop: function(workerid) {
				uni.navigateTo({
					url: '/pages/worker/shop?workerid=' + workerid
				});
			},
			navigate: function(href, e) {
				// #ifdef H5
				location.href = href;
				// #endif
				// #ifndef H5
				uni.navigateTo({
					url: '/pages/tool/webview?pagesrc=' + encodeURIComponent(href)
				});
				// #endif
			},
			// 咨询电话
			makeTelephone: function(e) {
				var telephone = e.currentTarget.dataset.telephone;
				if (_this.iscantele){
					uni.makePhoneCall({
						phoneNumber: telephone
					});
					return;
				}
				uni.showModal({
					title: '信息提示',
					content: '拨打咨询电话会扣除'+_this.param.telsupply+'积分，确定要拨打咨询电话吗？',
					success: function(res) {
						if (res.confirm) {
							_this.$req.ajax({
								path: "supply/telesupply",
								data: {
									supplyid: _this.supply.id,
									userid: _this.userinfo.id
								}
							}).then((data) => {
								_this.iscantele = true;
								uni.makePhoneCall({
									phoneNumber: telephone
								});
							}).catch((err) => {
								uni.showModal({
									title: '信息提示',
									content: err,
									showCancel: false
								});
							});
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.flex-1 {
		flex: 1;
	}

	.flex-6 {
		flex: 6;
	}

	.picmodal {
		width: 640rpx;
		background-color: transparent;
	}

	.picmodal image {
		width: 100%;
	}

	.picmodal .bg-img {
		position: relative;
	}

	.picmodalclose {
		position: absolute;
		top: 0rpx;
		right: 0rpx;
	}
</style>
