<template>
	<view>

		<view class="padding-top padding-lr">
			<view class="flex justify-between padding-lr-sm align-center infobox">
				<view class="cu-avatar lg round" v-if="workerinfo!=false"
					:style="'background-image:url('+workerinfo.tilpic+');'"></view>
				<view class="workerinfo padding-left-sm">
					<view class="text-df padding-bottom-xs">{{workerinfo.title}}</view>
					<view class="text-gray text-sm flex" v-if="workerinfo.status==1">
						<view class="cu-capsule round margin-right-sm">
							<view class="cu-tag sm bg-red">
								<text class="cuIcon-safe"></text>
							</view>
							<view class="cu-tag sm line-red">待审核</view>
						</view>
					</view>
					<view class="text-gray text-sm flex" v-else>
						<view class="cu-capsule round margin-right-sm">
							<view class="cu-tag sm bg-blue">
								<text class="cuIcon-safe"></text>
							</view>
							<view class="cu-tag sm line-blue">已认证</view>
						</view>
					</view>
				</view>
				<view class="btnbox action text-right text-lg">
					<image :src="$getImageUrl('static/images/applet/worker_icon1.png')" class="iconimage"
						@tap="getShopCode" v-if="appplatform!='ios'"></image>
					<image :src="$getImageUrl('static/images/applet/worker_icon2.png')" class="iconimage"
						data-pageurl="/pages/worker/winfo" @click="goPage"></image>

					<!-- <text class="cuIcon cuIcon-share padding-xs round" @tap="getShopCode"></text>
					<text class="cuIcon cuIcon-settings padding-xs round margin-left-lg" data-pageurl="/pages/worker/winfo" @click="goPage"></text> -->
				</view>
			</view>

			<view class="text-center padding-top grid col-3 margin-bottom-sm">
				<view class="padding-tb-sm">
					<view class="text-xxl">{{countobj[1]}}</view>
					<view class="text-gray text-sm">昨日浏览</view>
				</view>
				<view class="padding-tb-sm">
					<view class="text-xxl">{{countobj[2]}}</view>
					<view class="text-gray text-sm">今日浏览</view>
				</view>
				<view class="padding-tb-sm">
					<view class="text-xxl">{{countobj[3]}}</view>
					<view class="text-gray text-sm">累计访客</view>
				</view>
			</view>
		</view>

		<!-- 轮播图 -->
		<swiper class="screen-swiper square-dot padding-lr margin-bottom" :indicator-dots="true" :circular="true"
			:autoplay="true" @change="cardSwiper" interval="5000" duration="500" indicator-color="#8799a3"
			indicator-active-color="#0081ff">
			<block v-for="(item,index) in slide" :key="index">
				<swiper-item class="radius" @tap="pageUrl(item.stype, item.tilurl)">
					<image :src="item.tilpic" mode="scaleToFill"></image>
				</swiper-item>
			</block>
		</swiper>

		<!-- 导航 -->
		<view class="text-center solid-bottom padding-lr margin-bottom">
			<view class="cu-list grid col-1 no-border shadow shadow-lg radius echo-grid"
				style="padding: 0rpx !important;" v-if="workerinfo.wtype==1">
				<view class="cu-item" data-pageurl="/pages/worker/wcomform" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/worker_comjobs.png')" mode="scaleToFill"></image>
					<text>发布招聘</text>
				</view>
				<!-- <view class="cu-item" data-pageurl="/pages/mall/mall" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/worker_mall.png')" mode="scaleToFill"></image>
					<text>积分商城</text>
				</view> -->
			</view>

			<view class="cu-list grid col-3 no-border shadow shadow-lg radius echo-grid"
				style="padding: 0rpx !important;" v-else>
				<view class="cu-item" data-pageurl="/pages/worker/wcomform" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/worker_comjobs.png')" mode="scaleToFill"></image>
					<text>发布招聘</text>
				</view>
				<view class="cu-item" data-pageurl="/pages/demand/demandform" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/worker_demand.png')" mode="scaleToFill"></image>
					<text>发布派遣</text>
				</view>
				<view class="cu-item" data-pageurl="/pages/supply/supplyform" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/worker_supply.png')" mode="scaleToFill"></image>
					<text>发布供人</text>
				</view>
				<!-- <view class="cu-item" data-pageurl="/pages/mall/mall" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/worker_mall.png')" mode="scaleToFill"></image>
					<text>积分商城</text>
				</view> -->
			</view>
		</view>


		<view class="padding-lr-lg padding-tb-xs">
			<text class="text-gray">其他功能</text>
		</view>

		<view class="padding-lr margin-tb-sm">
			<view class="cu-list grid col-3 no-border shadow shadow-lg radius echo-grid workernav-grid">
				<view class="cu-item" data-pageurl="/pages/worker/wcomlist" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav1.png')" mode="scaleToFill"></image>
					<text>我的招聘</text>
				</view>

				<view class="cu-item" data-pageurl="/pages/worker/invite" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav8.png')" mode="scaleToFill"></image>
					<text>我的邀请</text>
				</view>

				<view v-if="workerinfo.wtype==2" class="cu-item" data-pageurl="/pages/demand/wdemandlist" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav3.png')" mode="scaleToFill"></image>
					<text>派遣订单</text>
				</view>

				<view class="cu-item" data-pageurl="/pages/supply/wsupplylist" @tap="goPage" v-if="workerinfo.wtype==2">
					<image :src="$getImageUrl('static/images/applet/workernav2.png')" mode="scaleToFill"></image>
					<text>我的供人</text>
				</view>

				<view class="cu-item" data-pageurl="/pages/worker/wcomlog" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav6.png')" mode="scaleToFill"></image>
					<text>招聘报名记录</text>
				</view>

				<view class="cu-item" data-pageurl="/pages/worker/wreportlist" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav3.png')" mode="scaleToFill"></image>
					<text>悬赏记录</text>
				</view>

				<view class="cu-item" data-pageurl="/pages/demand/snatch" @tap="goPage" v-if="workerinfo.wtype==2">
					<image :src="$getImageUrl('static/images/applet/workernav4.png')" mode="scaleToFill"></image>
					<text>我接的派遣</text>
				</view>

				<!-- <view class="cu-item" data-pageurl="/pages/my/myintegral" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav5.png')" mode="scaleToFill"></image>
					<text>我的积分</text>
				</view> -->



				<!-- <view v-if="workerinfo.wtype==1" class="cu-item" data-pageurl="/pages/worker/wupdate" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav10.png')" mode="scaleToFill"></image>
					<text>升级到派遣</text>
				</view> -->
				<!--
				<view class="cu-item" data-pageurl="/pages/form/form?formid=3" @click="goHome">
					<image :src="$getImageUrl('static/images/applet/workernav7.png')" mode="scaleToFill"></image>
					<text>切换身份</text>
				</view>
				
				<view class="cu-item" data-pageurl="/pages/form/form?formid=3" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav7.png')" mode="scaleToFill"></image>
					<text>申请加盟</text>
				</view>
				
				<view class="cu-item" data-pageurl="/pages/form/form?formid=5" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav8.png')" mode="scaleToFill"></image>
					<text>工厂招聘</text>
				</view>
				-->
				<view class="cu-item" data-pageurl="/pages/worker/wshare" @tap="goPage" v-if="appplatform!='ios'">
					<image :src="$getImageUrl('static/images/applet/workernav9.png')" mode="scaleToFill"></image>
					<text>获客海报</text>
				</view>

				<!-- <view class="cu-item" data-pageurl="/pages/article/article" @tap="goPage">
					<image :src="$getImageUrl('static/images/applet/workernav11.png')" mode="scaleToFill"></image>
					<text>资讯中心</text>
				</view> -->

				<!-- <view class="cu-item" data-pageurl="/pages/worker/mpaccount" @tap="goPage" v-if="appplatform!='ios' && workerinfo.wtype==2">
					<image :src="$getImageUrl('static/images/applet/workernav12.png')" mode="scaleToFill"></image>
					<text>嵌入公众号</text>
				</view> -->


			</view>
		</view>


		<!-- <view class="padding-sm"></view> -->
		<view class="padding-lg"></view>
		<view class="cu-bar tabbar bg-white foot">
			<view class="action text-blue" @tap="goNavPage('/pages/worker/worker')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/windexSelected.png"></image>
				</view>
				首页
			</view>
			<view class="action text-gray" @tap="goNavPage('/pages/demand/demand')" v-if="workerinfo.wtype==2">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/wdemand.png"></image>
				</view>
				抢单大厅
			</view>
			<!-- #ifndef MP-WEIXIN -->
			<view class="action text-gray videoimg" @tap="goNavPage('/pages/video/video')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/video.png"></image>
				</view>
				录视频
			</view>
			<!-- #endif -->
			<view class="action text-gray" @tap="goNavPage('/pages/resume/resume')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/resume.png"></image>
				</view>
				简历
			</view>
			<view class="action text-gray" @tap="goNavPage('/pages/supply/supply')" v-if="workerinfo.wtype==2">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/wsupply.png"></image>
				</view>
				共享用工
			</view>
			<!--
			<view class="action text-gray" @tap="goNavPage('/pages/worker/workerlist')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/wworker.png"></image>
				</view>
				企业1
			</view>
			-->
		</view>

		<button class="cu-btn bg-blue lg shadow echo-gohome" @tap="goHome"> 切换身份 </button>

		<wxContact></wxContact>
		<view class="padding-xl"></view>

		<view class="cu-modal" :class="modal.name=='regworker'?'show':''" @tap="hideModal">
			<view class="cu-dialog picmodal" @tap.stop="">
				<view class="bg-img">
					<image mode="widthFix" style="display: block;" :src="picregworker" v-if="picregworker"></image>
					<view class="cu-bar justify-end text-white picmodalclose">
						<view class="action" @tap="hideModal">
							<text class="cuIcon-close "></text>
						</view>
					</view>
				</view>
				<view class="cu-bar bg-white radius">
					<view class="action margin-0 flex-sub solid-left" @tap="getWorkerIntegral">立即领取</view>
				</view>
			</view>
		</view>

		<!-- <view class="cu-modal" :class="modal.name=='regworker'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">奖励积分</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl text-lg">
					<view class="solid-bottom text-xsl padding-bottom">
						<text class=" cuIcon-selection text-red"></text>
					</view>
					<view class="text-xl">
						恭喜您，注册的劳务公司账号审核通过，获得 {{intregworker}} 积分，请点击领取...
					</view>
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn" @tap="hideModal">取消</button>
						<button class="cu-btn bg-blue margin-left" @tap="getWorkerIntegral">立即领取</button>
					</view>
				</view>
			</view>
		</view> -->

		<view class="cu-modal" :class="modal.name=='shopcode'?'show':''" @tap="hideModal">
			<view class="cu-dialog picmodal" @tap.stop="">
				<view class="bg-img">
					<image mode="widthFix" :src="modal.shopcode" v-if="modal.shopcode"></image>
					<view class="cu-bar justify-end text-white picmodalclose">
						<view class="action" @tap="hideModal">
							<text class="cuIcon-close "></text>
						</view>
					</view>
				</view>
				<view class="cu-bar bg-white margin-top-xs">
					<view class="action margin-0 flex-sub solid-left" @tap="saveImage">保存到相册</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				appplatform: "",
				isRotate: false,
				userinfo: false,
				workerinfo: {},
				picregworker: "",
				intregworker: 0,

				slide: {},
				cardCur: 0,
				countobj: {
					tentry: 0,
					entry: 0
				},

				modal: {
					name: "",
					shopcode: ""
				}
			}
		},
		onLoad: function() {
			_this = this;
			//#ifdef APP-PLUS
			_this.appplatform = uni.getSystemInfoSync().platform;
			//#endif
			_this.userinfo = uni.getStorageSync('userinfo') || false;
			_this.workerinfo = uni.getStorageSync('workerinfo') || false;
			if (_this.workerinfo === false) {
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			_this.$req.ajax({
				path: "worker/pageworker",
				data: {
					userid: _this.userinfo.id,
					workerid: _this.workerinfo.id
				}
			}).then((data) => {
				_this.countobj = data.countobj;
				_this.slide = data.slide;
				_this.picregworker = data.picregworker;
				_this.intregworker = data.intregworker;
				if (_this.intregworker > 0) {
					_this.modal.name = "regworker";
				}
				_this.workerinfo = data.workerinfo;
				uni.setStorageSync('workerinfo', _this.workerinfo);

			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false
				});
			});
		},
		methods: {

			getWorkerIntegral: function() {
				if (_this.isRotate) {
					return false;
				}
				_this.isRotate = true;
				_this.$req.ajax({
					title: "积分发放中...",
					path: "worker/getworkerintegral",
					data: {
						userid: _this.userinfo.id,
						workerid: _this.workerinfo.id
					}
				}).then((data) => {
					uni.showToast({
						title: '积分领取成功',
						duration: 2000
					});
					_this.intregworker = 0;
					_this.modal.name = "";
					_this.isRotate = false;
				}).catch((err) => {
					uni.showModal({
						title: '温馨提示',
						content: err,
						showCancel: false
					});
					_this.isRotate = false;
				});
			},

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

			getShopCode: function() {
				_this.$req.ajax({
					title: "微店二维码生成中...",
					path: "worker/getshopcode",
					data: {
						workerid: _this.workerinfo.id,
						parentid: _this.userinfo == false ? 0 : _this.userinfo.id
					}
				}).then((data) => {
					_this.modal.shopcode = data.shopcode;
					_this.modal.name = "shopcode";
				}).catch((err) => {
					uni.showModal({
						title: '温馨提示',
						content: err,
						showCancel: false
					});
				});
			},
			hideModal: function() {
				_this.modal.name = "";
			},

			goHome: function() {
				uni.setStorageSync('identityinfo', false);
				uni.setStorageSync('workerinfo', null);
				uni.reLaunch({
					url: "/pages/index/home"
				});
			},

			workerOut: function() {
				uni.setStorageSync('workerinfo', null);
				uni.reLaunch({
					url: "/pages/index/home"
				});
			},

			goNavPage: function(pageurl) {
				_this.userinfo = _this.checkLogin("/pages/my/my");
				if (_this.userinfo === false) {
					return false;
				}
				uni.redirectTo({
					url: pageurl
				});
			},

			goPage: function(e) {
				var pageurl = e.currentTarget.dataset.pageurl;
				uni.navigateTo({
					url: pageurl,
					fail: function() {
						uni.switchTab({
							url: pageurl
						});
					}
				});
			},

			cardSwiper: function(e) {
				_this.cardCur = e.detail.current
			},
			pageUrl: function(type, tilurl) {
				if (type == 1) {
					uni.navigateTo({
						url: tilurl,
						fail: function() {
							uni.switchTab({
								url: tilurl
							});
						}
					});
				} else {
					uni.navigateTo({
						url: '/pages/tool/webview?pagesrc=' + encodeURIComponent(tilurl)
					});
				}
			},
		}
	}
</script>

<style>
	.workernav-grid image {
		width: 70rpx;
		height: 70rpx;
		margin-bottom: 10rpx;
	}

	.infobox {}

	.infobox .cu-avatar {
		width: 100rpx;
	}

	.infobox .workerinfo {
		width: 380rpx;
	}

	.infobox .btnbox {
		width: 190rpx;
	}

	.codebox {
		/* width: 690rpx;
		margin: 0rpx auto 0rpx auto;
		border-radius: 8rpx;
		overflow: hidden; */
	}


	.iconimage {
		width: 34rpx;
		height: 34rpx;
		margin-left: 30rpx;
	}

	.echo-grid image {
		width: 48rpx;
		height: 48rpx;
		margin-bottom: 10rpx;
	}

	.wnavbox {}

	.wnavbox .wcomitem {
		width: 340rpx !important;
		margin-bottom: 15rpx;
	}

	.wnavbox .wcomitem image {
		display: block;
		width: 70rpx;
		height: 70rpx;
	}

	.wnavbox .wcomitem .wcomtil {
		width: 210rpx;
		line-height: 90rpx;
		padding-left: 20rpx;
		color: #0081FF;
		font-size: 30rpx;
	}

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

	.picmodal image {
		width: 100%;
	}

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

	.picmodalclose {
		position: absolute;
		top: 0rpx;
		right: 0rpx;
	}


	.screen-swiper {
		min-height: 160rpx;
		height: 160rpx;
	}
</style>
