<template>
	<view>
		<view class="container">
			<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.headImage" mode="aspectFit"></image>
			        </view>
			        <view class="worker-box-body">
			          <view class="worker-box-title">
			            <text>{{item.realName}}</text>
			          </view>
			          <view class="worker-box-desc">
			            <text v-if="item.gender == 1">男</text>
						<text v-if="item.gender == 2">女</text>
			            | {{item.age}}岁 | {{item.work}}年护理经验
			          </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: [],
				page: 1,
				size: 10,
				flag: 0
			}
		},
		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: '参数错误',
						icon: 'none',
						duration: 2000
					})
				}
			}
		},
		onShow() {
			var that = this;
			app.ajaxReadyCallback = res => {  //各个接口统一回调方法
				var apiname = res.data.apiname;
				console.log(res);
				if(apiname == 'worker'){
					that.list = res.data.data;
					if (that.list.length < that.size) {
						that.flag = 1;
					} else {
						that.page++;
					}
				}
			}
			
			if(app.globalData.userinfo.orgId){
				this.flag = 0;
				this.page = 1;
				this.getWorkerList();
			}
		},
		onPullDownRefresh() {
			this.flag = 0;
			this.page = 1;
			this.getWorkerList();
		},
		onReachBottom() { //上拉加载
		    this.getWorkerList();
		},
		methods: {
			getWorkerList(){
				if(this.flag == 1){
					return;
				}
				app.ajax({
					url: app.globalData.serverUrl + 'worker/lists',
					type: 'POST',
					apiname: 'worker',
					data: {
						page: this.page,
						size: this.size
					}
				});
			},
			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{
	    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;
	}
	
</style>
