<template>
	<view>
		
		<view class="bg-white homepage">
			<view>
				<!-- <view class="padding"></view> -->
				<image mode="widthFix" :src="$getImageUrl('static/images/applet/homebg.jpg')"></image>
				<view class="padding"></view>
				
				<view class="padding-tb padding-lr-xl flex justify-between homebox">
					<image mode="widthFix" :src="$getImageUrl('static/images/applet/homebtn1.jpg')" @tap="goUser"></image>
					
					<image mode="widthFix" :src="$getImageUrl('static/images/applet/homebtn2.jpg')" @tap="checkWorker"></image>
				</view>
			</view>
			
			
			<!-- <image mode="widthFix" src="../../static/images/home2.png" @tap="goUser"></image>
			<view class="padding"></view>
			<image mode="widthFix" src="../../static/images/home3.png" @tap="checkWorker"></image> -->
			
			
			<!-- <image class="homebg" mode="widthFix" src="../../static/images/home4.png"></image> -->
		</view>
	
		<view class="cu-modal" :class="modalName=='workerModal'?'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-tb-sm">
					
					<view class="cu-list menu">
						<block v-if="workerall!=null">
							<view class="cu-item arrow" v-for="(item,index) in workerall" :key="index" @tap="goWorker" :data-index="index">
								<view class="content text-left">
									<text class="cuIcon-settings text-grey"></text>
									<text>{{item.ftitle}}</text>
								</view>
								<view class="action">
									<text class="text-grey">
										<text class="margin-left text-red" v-if="item.status==1">待审核</text>
										<text class="margin-left text-red" v-if="item.status==4">升级审核</text>
									</text>
								</view>
							</view>
						</block>
						<view class="cu-item arrow" @click="goLogin">
							<view class="content text-left">
								<text class="cuIcon-settings text-grey"></text>
								<text>注册劳务公司</text>
							</view>
						</view>
					</view>
					
				</view>
			</view>
		</view>
		
		<view class="cu-modal" :class="modalName=='apptreatyModal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">服务协议和隐私政策</view>
				</view>
				<view class="padding-tb-sm">
					<scroll-view class="xy-content text-left" scroll-y>
						<text>请你务必审慎阅读、充分理解“用户服务协议”和“隐私政策”各条款，包括但不限于：为了向你提供即时招聘讯息、内容分享等服务，我们需要收集你的设备信息、操作日志等个人信息。</text> <br/>
						<view>你可阅读
							<text class="text-blue" @tap="goPage('/pages/tool/sinpage?field=service')">《用户服务协议》</text>
							和<text class="text-blue" @tap="goPage('/pages/tool/sinpage?field=privacy')">《隐私政策》</text>
							了解详细信息，如你同意，请点击“我同意”开始接受我们等服务。
						</view>
					</scroll-view>
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn line-blue text-blue" @tap="outApptreaty">不同意</button>
						<button class="cu-btn bg-blue margin-left" @tap="setApptreaty">我同意</button>
					</view>
				</view>
			</view>
		</view>

		
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				identityinfo: false,
				userinfo: false,
				workerinfo: null,
				workerall: null,
				
				modalName: null,
				apptreaty: ""
			}
		},
		onLoad: function(option) {
			_this = this;
			_this.identityinfo = uni.getStorageSync('identityinfo') || false;
			_this.userinfo = uni.getStorageSync('userinfo') || false;
			_this.workerinfo = uni.getStorageSync('workerinfo') || null;
			if (_this.identityinfo==true && _this.workerinfo!=null){
				uni.reLaunch({
					url: "/pages/worker/worker"
				});
				return;
			}
			if (_this.identityinfo==true){
				uni.reLaunch({
					url: "/pages/index/index"
				});
				return;
			}
			_this.$req.ajax({
				path: "index/gethomedata",
				data: {
					userid: _this.userinfo==false ? 0 : _this.userinfo.id
				}
			}).then((data) => {
				_this.apptreaty = data.apptreaty;
				_this.workerall = data.workerall;
				
				// #ifdef APP-PLUS
				_this.modalName = uni.getStorageSync('apptreatyModal') || "apptreatyModal";
				// #endif  
			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false
				});
			});
			
		},
		onShareAppMessage: function(res) {
			return {
				title: "晋江人力",
				path: "/pages/index/home"
		    }
		},
		methods: {
			setApptreaty: function() {
				uni.setStorageSync('apptreatyModal', "hideapptreatyModal");
				_this.modalName = null;
			},
			outApptreaty: function() {
				plus.runtime.quit();  
			},
			goPage: function(pageurl) {
				uni.navigateTo({
					url: pageurl,
					fail: function() {
						uni.switchTab({
							url: pageurl
						});
					}
				});
			},
			
			
			checkWorker: function() {
				if (_this.workerall=='null'){
					uni.navigateTo({
						url: "/pages/login/worker"
					});
					return false;
				}
				_this.modalName = "workerModal";
			},
			hideModal: function(e) {
				_this.modalName = null;
			},
			goWorker: function(e) {
				var index = e.currentTarget.dataset.index;
				if (_this.workerall[index].status==1){
					// uni.showModal({
					// 	title: '信息提示',
					// 	content: "信息审核中，请耐心等待。",
					// 	showCancel: false
					// });
					// return;
				}
				uni.setStorageSync('identityinfo', true);
				uni.setStorageSync('workerinfo', _this.workerall[index]);
				uni.reLaunch({
					url: "/pages/worker/worker"
				});
			},
			
			
			goLogin: function() {
				uni.setStorageSync('identityinfo', true);
				uni.navigateTo({
					url: "/pages/login/worker"
				});
			},
			
			goUser: function() {
				_this.userinfo = _this.checkLogin("/pages/index/index");
				uni.setStorageSync('identityinfo', true);
				uni.setStorageSync('workerinfo', null);
				uni.reLaunch({
					url: "/pages/index/index"
				});
			}
		}
	}
</script>

<style>
	.homepage{ height: calc(100vh); background-repeat: no-repeat; background-size: 100%; background-position: bottom center;  }
	.homepage image{ width: 100%; }
	.homepage image.homebg{ width: 750rpx; position: fixed; bottom: 0rpx; }
	
	.homebox{  }
	.homebox image{ width: 280rpx; }
	
	.xy-content{padding:10rpx 30rpx; background:#F6F6F6; line-height:50rpx; font-size:28rpx; text-align: justify; box-sizing:border-box;}
</style>
