(function() {
	Vue.component('hospital-source', {
		template: '<div class="plr20 ptb15 clearfix">\
                      <div class="clearfix">\
       				    <div class="c-f20 c-323232">按医院</div>\
					    <div :class="{\'pr15\': (index%2==0)}" class="c-50 fl mt10" v-for="(data, index) in hospitalData" @click="hostipalClick(data)">\
							<div class="ui-grid h160 c-border ptb15 plr15">\
								<div class="ui-col-0 hospital-photo-box mr20">\
							        <img v-bind:src="data.photoUri">\
								</div>\
								<div class="ui-col-1">\
									<div class="c-f16 c-323232">{{data.hosName}}<span class="ml10 c-f14 c-ef6b00">[{{data.levelName}}]</span></div>\
									<div class="mt16 c-f14">\
										<span class="c-0AD9C9">{{data.doctorNum}}</span>\
										<span class="c-909090">个推荐医生</span>\
									</div>\
									<div class="mt20">\
										<img src="../../../images/icon_dizhi.png" width="24" height="24" />\
										<span class="ml5 c-f14 c-909090">{{data.address}}</span>\
									</div>\
								</div>\
							</div>\
						</div>\
				    </div>\
				    <div id="page" class="page_div"></div>\
       		 </div>',
		props: [],
		data: function() {
			return {
				isInit: true,
				hospitalData: [],
				currentPage: 1,
				pageSize: 10,
				totalPage: 0
			}
		},
		mounted: function() {
			var vm = this;
			getHospitalList(vm);
		},
		methods: {
			hostipalClick: function(data) {
				location.href = "../html/select-hospital.html?hospitalId=" + data.hospitalId + "&hosName=" + data.hosName;
			},
			getHospitalList: function() {
				var vm = this;
				var params = {
					pageIndex: vm.currentPage,
					pageSize: vm.pageSize,
					provinceCode: 360000,
					cityCode: 361100
				}
				appointmentAPI.querySimpleHospitalList(params).then(function(res) {
					if(res.successFlg && res.obj.Code == "10000") {
						var hospitalData = res.obj;
						//				vm.hospitalData = hospitalData.Result;
						if(vm.isInit) {
							vm.totalPage = Math.ceil(hospitalData.Total / vm.pageSize);
							//分页初始化
							$("#page").paging({
								pageNo: 1,
								totalPage: vm.totalPage,
								totalSize: hospitalData.Total,
								callback: function(num) {
									vm.currentPage = num; //回调的页数
									getHospitalList(vm);
								}
							})
							vm.isInit = false;

							//查询医生总数
							var doctorParams = {
								pageIndex: vm.currentPage,
								pageSize: vm.pageSize,
								hospitalId: hospitalData.Result[0].hospitalId
							}
							appointmentAPI.querySimpleDoctorList(doctorParams).then(function(doctorRes) {
								if(doctorRes.successFlg && doctorRes.obj.Code == "10000") {
									hospitalData.Result[0].doctorNum = doctorRes.obj.Total;
									vm.hospitalData = hospitalData.Result;
								}

							})
						}
					}
				})
			}
		}
	});

})()