<template>
	<view>
		<view v-if="orgName" class="org-title">
			{{orgName}}
		</view>
		<swiper 
			v-if="banner.length > 0"
			class="swiper" 
			:indicator-dots="true" 
			indicator-color="#FF7576" 
			:autoplay="true" 
			:interval="3000" 
			:duration="200"
		>
			<swiper-item v-for="(item,index) in banner" :key="index">
				<image class="slide-image" mode="scaleToFill" :src="item.path"></image>
			</swiper-item>
		</swiper>
		<view class="container">
			<view class="book-box">
				<view class="left-box"  @click="goAdd">
					<view class="left-title">
						<img src="../../images/on-line-ico.png" alt="">
						<text class="name">线上预约</text>
					</view>
					<view class="left-title2">高效率响应</view>	
				</view>
				<view class="right-box" @click="callPhone">
					<view class="left-title">
						<img src="../../images/phone-book-ico.png" alt="">
						<text class="name">电话预约</text>
					</view>
					<view class="left-title2">一键快捷操作</view>	
				</view>
				
			</view>
		<!-- 	<image class="book-btn" @click="goAdd" src="../../images/book.png"></image>
			
			<view class="book-phone" @click="callPhone">
				<image src="../../images/dianhua@2x.png"></image>
				直接电话下单
			</view> -->
			
			<view> 
			    <view class="worker-title">
					护工推荐
					<span class="pull-right worker-title-more" @click="goWorker()">查看更多<image src="../../images/youjiantou-hui@2x.png"></image></span>
				</view>
			    <view class="worker-box" v-for="(item,index) in list" :key="index">
			      <view class="worker-box-info">
			        <view class="worker-box-avator">
			          <image :src="item.img" mode="aspectFit"></image>
			        </view>
			        <view class="worker-box-body">
			          <view class="worker-box-title">
			            <text>{{item.name}}</text>
			          </view>
			          <view class="worker-box-desc">
			            <text v-if="item.gender == 1">男</text>
						<text v-if="item.gender == 2">女</text>
			            | {{item.age}}岁 | {{item.worker}}年护理经验
			          </view>
			          <view class="worker-box-desc">
						  <rich-text :nodes="item.content"></rich-text>
					  </view>
			        </view>
			      </view>
			    </view>
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp();
	export default {
		data() {
			return {
				list: [],
				banner: [],
				phone: '',
				orgName: '',
			}
		},
		onLoad() {
			var orgId = this.getUrlCode('orgId');
			if(orgId){
				uni.setStorageSync(app.globalData.storagePre+'orgId',orgId);
				app.globalData.userinfo.orgId = orgId;
			}else{
				orgId = uni.getStorageSync(app.globalData.storagePre+'orgId');
				if(orgId){
					app.globalData.userinfo.orgId = orgId;
				}else{
					uni.showToast({
						title: '参数错误，未获取到orgId',
						icon: 'none',
						duration: 2000
					})
				}
			}
		},
		onShow() {
			var that = this;
			app.ajaxReadyCallback = res => {  //各个接口统一回调方法
				var apiname = res.data.apiname;
				console.log(res);
				if(apiname == 'banner'){
					that.banner = res.data.data;
				}else if(apiname == 'config'){
					that.phone = res.data.data.val;
				}else if(apiname == 'worker'){
					that.list = res.data.data;
				}else if(apiname == 'org'){
					that.orgName = res.data.data.name;
				}
			}
			
			if(app.globalData.userinfo.orgId){
				this.getOrg();
				this.getConfig();
				this.getBanner();
				this.getWorkerHot();
			}
		},
		onPullDownRefresh() {
			
		},
		onReachBottom() { //上拉加载
		   
		},
		methods: {
			callPhone(){
				if(this.phone){
					uni.makePhoneCall({
					    phoneNumber: this.phone //仅为示例
					});
				}else{
					uni.showToast({
						title: '未设置联系电话',
						icon: 'none',
						duration: 2000
					})
				}
			},
			goAdd(){
				uni.navigateTo({
				    url: '/pages/index/add'
				});
			},
			goWorker(){
				uni.navigateTo({
				    url: '/pages/index/worker'
				});
			},
			getOrg(){
				app.ajax({
					url: app.globalData.serverUrl + 'common/getOrg',
					type: 'POST',
					apiname: 'org',
				});
			},
			getConfig(){
				app.ajax({
					url: app.globalData.serverUrl + 'common/getConfig',
					type: 'POST',
					apiname: 'config',
					data: {
						name: 'org_phone'
					}
				});
			},
			getBanner(){
				app.ajax({
					url: app.globalData.serverUrl + 'common/banner',
					type: 'POST',
					apiname: 'banner',
				});
			},
			getWorkerHot(){
				app.ajax({
					url: app.globalData.serverUrl + 'worker/hot',
					type: 'POST',
					apiname: 'worker',
				});
			},
			getUrlCode (name) {
				return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		// background-color: #FFFFFF;
	}
	.org-title{
		position: fixed;
		z-index: 1000;
		left: 0;
		top: 0;
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		padding: 20rpx;
		font-size: 34rpx;
		font-weight: 500;
		color: #FFFFFF;
	}
	.swiper{
		width: 100%;
		height: 579rpx;
	}
	.slide-image{
	    width: 750rpx;
	    height: 579rpx;
	}
	
	.book-btn{
	    width: 100%;
	    height: 180rpx;
	    margin-bottom: 20rpx;
	}
	.book-phone{
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		border-radius: 45rpx;
		color: #FF7576;
		font-size: 34rpx;
		border: 1rpx solid #FF7576;
		text-align: center;
		font-weight: bold;
	}
	.book-phone image{
		width: 30rpx;
		height: 30rpx;
		margin-right: 20rpx;
	}
	
	.worker-title{
		width: 100%;
	    // height: 90rpx;
	    line-height: 90rpx;
	    color: #333333;
	    font-size: 32rpx;
	    font-weight: bold;
	}
	.worker-title-more{
		color: #999999;
		font-size: 28rpx;
		 font-weight: 400;
	}
	.worker-title-more image{
		width: 26rpx;
		height: 26rpx;
	}
	.book-box{
		width: 100%;
		height: 228rpx;
		// position: absolute;
		// top:490rpx;
		// left:0;
		// right:0;
		// bottom:0;
	}
	.book-box .left-box{
		width: 334rpx;
		height: 228rpx;
		background-image: url(../../images/on-line-bg.png);
		background-size: 100% 100%;
		background-repeat: no-repeat;
		padding-top: 57rpx;
		display: inline-block;
		float: left;
	}
	.book-box .left-box .left-title{
		width: 100%;
		height: 60rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.book-box .left-box .left-title img{
		width: 44rpx;
		height: 44rpx;
	}
	.book-box .left-box .left-title .name{	
		margin-left: 24rpx;
		color: #fff;				
		font-size: 38rpx;
		font-weight: bold;
	 }
	 .book-box .left-box .left-title2{
		width: 224rpx;
		height: 35rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		padding-left: 110rpx;
	 }
	 
	 .book-box .right-box{
	 	width: 334rpx;
	 	height: 228rpx;
	 	background-image: url(../../images/phone-book-bg.png);
	 	background-size: 100% 100%;
	 	background-repeat: no-repeat;
	 	padding-top: 57rpx;
		margin-left: 22rpx;
		display: inline-block;
		float: right;
	 }
	 
	 .book-box .right-box .left-title{
	 	width: 100%;
	 	height: 60rpx;
	 	display: flex;
	 	justify-content: center;
	 	align-items: center;
	 }
	 .book-box .right-box .left-title img{
	 	width: 44rpx;
	 	height: 44rpx;
	 }
	 .book-box .right-box .left-title .name{	
	 	margin-left: 24rpx;
	 	color: #fff;				
	 	font-size: 38rpx;
	 	font-weight: bold;
	  }
	  .book-box .right-box .left-title2{
	 	width: 224rpx;
	 	height: 35rpx;
	 	font-size: 26rpx;
	 	font-family: PingFang SC;
	 	font-weight: 500;
	 	color: #FFFFFF;
	 	padding-left: 110rpx;
	  }
	  
	  .container{
		  position: absolute;
		  top:460rpx;
	  }
</style>
