extends ../layout
block content
	div.searchDiv
		.card.opt
			.card-body
				label 조회일자
				input.form-control(type="date" id="startDate" class="searchDate" ) 
				label ~
				input.form-control(type="date" id="endDate" class="searchDate" ) 
				label 신청항목 
				select.form-control(id="selectOptionType" class="selectType" v-on:change="dietChange")
					option 전체
					option(selected='true') 기호도
					option 보호자식
					option 선택식
					
					
				input(class="search btn btn-secondary btn-align" type="button" id="searchBtn" v-on:click="search" value="검색")
				input(class="search btn btn-secondary btn-align" type="button" id="downLoad" v-on:click="downLoad" value="인쇄")

	.card
		div#dvData
			table.table.table-stripped
				thead.hd
					tr
						td
							label(class="result") 조식
							template(v-for="o in selectMorningCnt")
								input(type="text" style="text-align:center" :value="o.cnt" disabled)
					
						td
							label(class="result") 중식
							template(v-for="o in selectLunchCnt")
								input(type="text" style="text-align:center" :value="o.cnt" disabled)
						
						td
							label(class="result") 석식
							template(v-for="o in selectNightCnt")
								input(type="text" style="text-align:center" :value="o.cnt" disabled)
					
						td
							label(class="result") 총계
							template(v-for="o in selectSumCnt")
								input(type="text" style="text-align:center" :value="o.cnt" disabled)
					tr
						template(v-for="o in selectSumlist")
						
					tr
						th 병동
						th 끼니
						th 환자처방명
						th 신청수					
						
				tbody
					
					tr
					template(v-for="o in selectSumlist")
					
						template(v-if="o.mealtime==='조식' || o.mealtime==='아침'")
							tr	
								td {{o.ward}}
								td {{o.mealtime}}
								td {{o.mealtype}}
								td 
									a(href=""){{o.cnt}}
							
					template(v-for="o in selectSumlist")	
						template(v-if="o.mealtime==='중식' || o.mealtime==='점심'")
							tr
								td {{o.ward}}
								td {{o.mealtime}}
								td {{o.mealtype}}
								td 
									a(href=""){{o.cnt}}
					template(v-for="o in selectSumlist")	
						template(v-if="o.mealtime==='석식' || o.mealtime==='저녁'")
							tr
								td {{o.ward}}
								td {{o.mealtime}}
								td {{o.mealtype}}
								td 
									a(href=""){{o.cnt}}
					
				
		div#dvData2
			table.table.table-stripped
				thead.hd
					tr
						th 식사처방
						th 내용
						th 신청수
						
				tbody
					template(v-for="o in selectChoiceMeal")
						tr
						td {{o.name}}
						td {{o.content}}
						td(v-if="o.cnt==1")0
						td(v-if="o.cnt!=1"){{o.cnt}}
						 
				tr 
					td 총계
					td
					template(v-for="o in selectChoiceSum")
						td {{o.cnt}}
						 
block script
	script.
		
		$('#dvData').hide();
		//$('#dvData2').hide();

		/* scripts here */
		var app = new Vue({
			el: '#app',
			data: {
				category:'#{category}',
				selectSumlist: !{JSON.stringify(selectSumlist)},
				selectChoiceMeal: !{JSON.stringify(selectChoiceMeal)}, 
				selectOptionType: !{JSON.stringify(selectOptionType)},
				selectMealTime: !{JSON.stringify(selectMealTime)},
				selectMorningCnt: !{JSON.stringify(selectMorningCnt)},
				selectLunchCnt: !{JSON.stringify(selectLunchCnt)},
				selectNightCnt: !{JSON.stringify(selectNightCnt)},
				selectSumCnt: !{JSON.stringify(selectSumCnt)},
				selectChoiceSum: !{JSON.stringify(selectChoiceSum)},
				today : '',
			},
			methods: {
				dietChange: function(){
					if($('#selectOptionType').val()==='기호도'){
						$('#dvData').hide();
						$('#dvData2').show();
						
					}else{
						$('#dvData').show();
						$('#dvData2').hide();
						
					}
					$.post("Diet/api/searchSummary", {
						hid: "IM39",
						startDate: $("#startDate").val(),
						endDate: $("#endDate").val(),
						selectOptionType : $('#selectOptionType').val(),
					}, o=>{
						console.log(o);
						this.selectSumlist = o.selectSumlist;
						this.selectChoiceMeal = o.selectChoiceMeal;
						this.selectMorningCnt = o.selectMorningCnt;
						this.selectLunchCnt = o.selectLunchCnt;
						this.selectNightCnt = o.selectNightCnt;
						this.selectSumCnt = o.selectSumCnt;
						this.selectChoiceSum = o.selectChoiceSum;
					}, 'json').fail(e=>{
						console.log(e.responseText);
						alert('error');
					});
				},
			
				search: function(){
					$.post("Diet/api/searchSummary", {
						hid: "IM39",
						startDate: $("#startDate").val(),
						endDate: $("#endDate").val(),
						selectOptionType : $('#selectOptionType').val(),
					}, o=>{
						console.log(o);
						this.selectSumlist = o.selectSumlist;
						this.selectChoiceMeal = o.selectChoiceMeal;
						this.selectMorningCnt = o.selectMorningCnt;
						this.selectLunchCnt = o.selectLunchCnt;
						this.selectNightCnt = o.selectNightCnt;
						this.selectSumCnt = o.selectSumCnt;
						this.selectChoiceSum = o.selectChoiceSum;

					}, 'json').fail(e=>{
						console.log(e.responseText);
						alert('error');
					});
				},
				
				downLoad : function(e){
					
					window.print();
				},
				
				downloadExcel : function(e){
					window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#dvData').html()));
					e.preventDefault();	
					
				},
			},
			created(){
				//오늘 날짜 계산
				var date = new Date();
				this.tomonth = date.getMonth()+1;
				this.todate = date.getDate();
				this.week = date.getDay();
				this.intmonth = date.getMonth()+1;
				if(this)
					this.tomonth = "0"+this.tomonth;
				this.today = date.getFullYear()+"-"+this.tomonth+"-"+this.todate;
			},
		});
		
		
	
block css
	style.
		/* styles here */
		.cancelTr{
			background-color :gray;
		}
		table {
			font-size : 11px;
		}
		.download.btn.btn-secondary{
			//margin-left : 86%;
			margin-bottom : 5px;
		}
		.btn-align {
			margin-left: 10px;
			margin-bottom: 8px;
		}
		label {
			margin-left: 5px;
			margin-right: 5px;
		}
		.result{
			width : 60px;

		}
		.form-control {
			display: inline;
			width: 100px;
		}
		.searchDate {
			width: 170px;
		}
		.searchDiv {
			text-align: center;
		}