(function() {
	Vue.component('doctor-list', {
		template: '<div class="ui-col-1 ml15 bgc-fff c-border p20">\
						<div class="c-f16 c-323232 mb20">医生列表</div>\
						<div class="ui-grid c-border p10 pb0 mt10" v-for="(doc, index) in doctorList">\
							<div class="ui-col-0 mr10">\
								<img v-bind:src="doc.photoUri" width="70" height="70" class="c-images-cycle">\
							</div>\
							<div class="ui-col-1 div-doctor-info">\
								<p>\
									<span class="c-f16 c-323232 c-bold mr10">{{doc.doctorName}}</span>\
									<span class="c-f14 c-323232 mr10">{{doc.lczcName}}</span>\
									<span class="c-f14 c-909090">{{doc.standardDeptName}}</span>\
								</p>\
								<p class="c-f14 c-909090">{{currentHosName}}</p>\
								<p class="c-f14 text-ellipsis">\
									<span class="c-909090">擅长：</span>\
									<span class="c-909090" v-bind:title="doc.skill">{{doc.skill}}</span>\
								</p>\
							</div>\
							<div class="ui-col-1 div-doctor-section" v-for="(arrange, aindex) in arrangeList" v-if="index==aindex">\
								<div class="div-left-btn c-hide" @click="preClick"></div>\
								<ul class="doctor-ul">\
									<li v-for="(arrg, arrIndex) in arrange">\
										<div class="div-doctor-item" :class="getColorClass(arrg.numberStatus,arrg.arrangeStatus)">\
											<div class="mt5">{{arrg.registerDate}}</div>\
											<div class="mt5">{{arrg.timeName}}</div>\
											<div class="div-doctor-type bgc-0ad8c8" v-if="arrg.numberStatus==1">预约</div>\
											<div class="div-doctor-type bgc-d1d1d1" v-if="arrg.numberStatus==2">已满</div>\
											<div class="div-doctor-type bgc-f0a65f" v-if="arrg.arrangeStatus==2">放号提醒</div>\
											<div class="div-doctor-type bgc-ff8787" v-if="arrg.arrangeStatus==4">停诊</div>\
										</div>\
									</li>\
								</ul>\
								<div class="div-right-active-btn" @click="nextClick" v-if="arrangeList[aindex].length>4"></div>\
							</div>\
						</div>\
						<div id="page" class="page_div fr"></div>\
					</div>',
		props: ["info"],
		data: function() {
			return {
				isInit: true,
				currentHospitalId: "",
				currentHosName: "",
				pageIndex: 1,
				pageSize: 10,
				totalPage: 0,
				hosDeptId: "",
				doctorList: [],
				arrangeList:[]
			}
		},
		mounted: function() {
			var vm = this;
			setTimeout(function() {
				vm.currentHospitalId = JSON.parse(vm.info).hospitalId;
				vm.currentHosName = JSON.parse(vm.info).hosName;
				vm.getDoctorList();
			}, 50);
		},
		methods: {
			getColorClass:function(numberStatus,arrangeStatus){
				var classZ="";
				if(numberStatus==1){
					classZ = "border-0ad8c8 c-0ad8c8";
				}else if(numberStatus==2){
					classZ = "border-d1d1d1 c-d1d1d1";
				}else if(arrangeStatus==2){
					classZ = "border-ff8787 c-ff8787";
				}else if(arrangeStatus==4){
					classZ = "border-f0a65f c-f0a65f";
				}
				return classZ;
			},
			//获取医生列表
			getDoctorList: function() {
				var vm = this;
				var params = {
					pageIndex: vm.pageIndex,
					pageSize: vm.pageSize,
					hospitalId: vm.currentHospitalId,
					hosDeptId: vm.hosDeptId
				}
				appointmentAPI.querySimpleDoctorList(params).then(function(res) {
					if(res.successFlg && res.obj.Code == "10000") {
						vm.doctorList = res.obj.Result;
						//获取医生排班数据
						vm.getArrangeWater(vm.doctorList);
						if(vm.isInit) {
							vm.totalPage = Math.ceil(res.obj.Total / vm.pageSize);
							//分页初始化
							$("#page").paging({
								pageNo: 1,
								totalPage: vm.totalPage,
								totalSize: res.obj.Total,
								callback: function(num) {
									vm.pageIndex = num; //回调的页数
									getDoctorList(vm);
								}
							})
							vm.isInit = false;
						}
					}
				})
			},
			//获取医生排班数据
			getArrangeWater: function(doctorData) {
				var vm = this,
					reqPromise = [];
				_.map(doctorData, function(data) {
					var params = {
						pageIndex: vm.pageIndex,
						pageSize: vm.pageSize,
						hospitalId: vm.currentHospitalId,
						hosDeptId: vm.hosDeptId,
						doctorSn: data.doctorSn, //医生编号
						registerDate: "" //就诊日期
					}
					reqPromise.push(appointmentAPI.queryGhtArrangeWater(params));
				})
				
				Promise.all(reqPromise).then(function(datas) {
					_.map(datas, function(data) {
						if(data.successFlg && data.obj.Code == "10000") {
							vm.arrangeList.push(data.obj.Result);
						}
					})
					
					vm.arrangeList = _.map(vm.arrangeList, function(data) {
						_.map(data, function(item) {
							item.registerDate = item.registerDate.substring(5,10).replace("-","/");
							item.timeName = item.timeId==1?"上午":item.timeId==2?"下午":"晚上";
						})	
						return data;
					})
					 $(".doctor-ul li:lt(4)").hide()
				});
			},
			preClick:function(){
				
			},
			nextClick:function(){
				$(event.target).prev().find("li:lt(4)").hide();
			}
		}
	});

})()