(function() {
	Vue.component('dept-source', {
		template: '<div class="select-hospital">\
					<ul class="select-condition-list">\
						<li class="select-condition-list-item">\
							<div class="condition-name">医院</div>\
							<div class="condition-list">\
								<span>全部</span>\
								<span :class="{\'active\': hos.hospitalId==currentHospitalId}" v-for="hos in hospitalData" v-bind:data-id="hos.hospitalId">{{hos.hosName}}</span>\
							</div>\
							<div class="more-list">更多</div>\
						</li>\
						<li class="select-condition-list-item">\
							<div class="condition-name">就诊科室</div>\
							<div class="condition-list">\
								<span>全部</span>\
								<span  v-for="dept in deptData" v-bind:data-id="dept.hosDeptId">{{dept.deptName}}</span>\
							</div>\
							<div class="more-list">更多</div>\
						</li>\
						<li class="select-condition-list-item">\
							<div class="condition-name">就诊日期</div>\
							<div class="condition-list">\
								<span>全部</span>\
								<span data-val="{{nowDate}}">今天</span>\
								<span v-for="d in planDate" v-bind:data-val="d.date1">{{d.day}}({{d.date}})</span>\
							</div>\
							<div class="more-list">更多</div>\
						</li>\
						<li class="select-condition-list-item">\
							<div class="condition-name">医生类型</div>\
							<div class="condition-list">\
								<span>全部</span>\
								<span>主任医师</span>\
								<span>其他</span>\
							</div>\
							<div class="more-list">更多</div>\
						</li>\
					</ul>\
				</div>',
		props: ["info"],
		data: function() {
			return {
				hospitalData: [],
				deptData: [],
				subDeptData: [],
				planDate: [],
				currentHospitalId:"",
				nowDate:new Date().format("YYYY-MM-dd"),
				pageIndex:1,
				pageSize:10
			}
		},
		mounted: function() {
			var vm = this;
			setTimeout(function(){
				vm.currentHospitalId = JSON.parse(vm.info).hospitalId;
				vm.getHospitalList();
				vm.getDeptList();
				vm.getVisitDate();
				vm.bindEvents();
			},50);
		},
		methods: {
			bindEvents:function(){
				//查看更多
				$(".more-list").click(function() {
					var parent = $(this).parents(".select-condition-list-item");
					parent.toggleClass('select-condition-list-item-active');
					if(parent.hasClass("select-condition-list-item-active")) {
						$(this).text("收起")
					} else {
						$(this).text("更多")
					}
				})
			},
			//获取医院列表
			getHospitalList: function() {
				var vm = this;
				var params = {
					pageIndex: 1,
					pageSize: 99,
					provinceCode: 360000,
					cityCode: 361100
				}
				appointmentAPI.querySimpleHospitalList(params).then(function(res) {
					if(res.successFlg && res.obj.Code == "10000") {
						vm.hospitalData = res.obj.Result;
					}
				})
			},
			//获取科室列表
			getDeptList: function() {
				var vm = this;
				var params = {
					pageIndex: 1,
					pageSize: 99,
					hospitalId: vm.currentHospitalId
				}
				appointmentAPI.querySimpleHosDeptList(params).then(function(res) {
					if(res.successFlg && res.obj.Code == "10000") {
						vm.deptData = res.obj.Result;
					}
				})
			},
			//默认只有7天的号源
			getVisitDate: function() {
				var vm = this;
				var now = new Date(),d = new Date();
				for(i = 1; i < 8; i++) {
					var nDate = now.getDate();
					d.setDate(nDate + i);
					var obj = {
						date: d.format("MM月dd日"),
						date1: d.format("YYYY-MM-dd"),
						day: this.getWeekDay(d.getDay())
					}
					this.planDate.push(obj);
				}
			},
			getWeekDay: function(val) {
				switch(val) {
					case 0:
						return "周日";
						break;
					case 1:
						return "周一";
						break;
					case 2:
						return "周二";
						break;
					case 3:
						return "周三";
						break;
					case 4:
						return "周四";
						break;
					case 5:
						return "周五";
						break;
					case 6:
						return "周六";
						break;
				}
			}
		}
	});

	function getDeptList(vm) {

	}

})()