/**
 * 订餐管理>餐品管理
 * 2018/4/20 by liufang
 */
$(function() {
	$.ajaxSetup({
	  async: false
	});
	var ERROK = 200;
	var contextPath = $("#contextPath").val()
	var table;
	var orgList = []; //校区
	var allMealnameList = [] // 所有菜品
	var mealnameList = []; // 组合
	var mealnameSlist = []; // 单品
	var specList = []; // 规格
	var foodList = []; // 主食
	var isMax = 0 //新增单品还是组合
	var tpl = {
		"addTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-meal-con">\
					<div class="title-wp">\
						<span>新增餐品</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-meal-wp">\
						<div class="choose-wrapper">\
							<h3 class="title">请选择餐品类型</h3>\
							<div class="circle-wp">\
								<div class="circle-con group-btn" data-type="2"></div>\
								<div class="name">组&nbsp;合</div>\
							</div>\
							<div class="circle-wp">\
								<div class="circle-con single-btn" data-type="1"></div>\
								<div class="name">单&nbsp;品</div>\
							</div>\
						</div>\
						<div class="choose-meal-wp">\
							<div class="choose-again"><span class="arrow-left"></span>重选食品类型</div>\
							<div class="meal-list ">\
				           	<% if(orgList!=null&&orgList.length>1){ %>\
								<div class="meal-item clearfloat required">\
									<div class="meal-tip ">校区：</div>\
									<div class="meal-con">\
										<input class="meal-select organ-id mut_org" name="orgId" id="orgId"  autocomplete="off" value="<%=orgList[0].name %>" org__id="<%=orgList[0].id %>"/>\
										<span class="select_wrap _hide"></span>\
									</div>\
								</div>\
							<%}else if(orgList!=null&&orgList.length==1){%>\
								<input type="hidden" class="meal-select organ-id sin_org" id="orgId" value="<%=orgList[0].id %>" org__id="<%=orgList[0].id %>"/>\
							<%}%>\
								<div class="meal-item clearfloat required">\
									<div class="meal-tip ">餐品名：</div>\
									<div class="meal-con">\
										<select  class="meal-select meal-name group-meal-name" >\
											<option value="">请选择餐品名</option>\
											<%for(var i=0;i<mealnameList.length;i++){%>\
												<option value="<%=mealnameList[i].id%>"><%=mealnameList[i].itemname%></option>\
											<%}%>\
										</select>\
										<select  class="meal-select meal-name single-meal-name" >\
											<option value="">请选择餐品名</option>\
											<%for(var i=0;i<mealnameSlist.length;i++){%>\
												<option value="<%=mealnameSlist[i].id%>"><%=mealnameSlist[i].itemname%></option>\
											<%}%>\
										</select>\
									</div>\
								</div>\
								<div class="meal-item clearfloat">\
									<div class="meal-tip">状态：</div>\
									<div class="meal-con meal-height">\
										<div class="radio-wp">\
										   <span class="radio-input">\
											 <input type="radio" id="status1" class="radio-item status" data-status="1" name="status" checked/>\
											  <span class="radio-inner"></span>\
										   </span>		\
										   <label class="radio-con" for="status1">上架</label>\
										</div>\
										<div class="radio-wp">\
										   <span class="radio-input">\
											 <input type="radio" id="status2" class="radio-item status" data-status="2" name="status" />\
											  <span class="radio-inner"></span>\
										   </span>		\
										   <label class="radio-con" for="status2">下架</label>\
										</div>\
									</div>\
								</div>\
								<div class="meal-item clearfloat group-item">\
								<div class="meal-tip">是否会议餐：</div>\
								<div class="meal-con meal-height is-meeting">\
									<div class="radio-wp">\
									   <span class="radio-input">\
										 <input type="radio" id="meeting1" class="radio-item isMeetFood" data-status="0" name="isMeetFood" checked/>\
										  <span class="radio-inner"></span>\
									   </span>		\
									   <label class="radio-con" for="meeting1">否</label>\
									</div>\
									<div class="radio-wp">\
									   <span class="radio-input">\
										 <input type="radio" id="meeting2" class="radio-item isMeetFood" data-status="1" name="isMeetFood" />\
										  <span class="radio-inner"></span>\
									   </span>		\
									   <label class="radio-con" for="meeting2">是</label>\
									</div>\
									<div class="meal-tips">会议餐不需要消费积分，只有管理员可以预定</div>\
								</div>\
							</div>\
								<div class="meal-item clearfloat group-item ">\
									<div class="meal-tip">规格：</div>\
									<div class="meal-con  meal-height gg_wrap">\
										<% for(var n=0;n<specList.length;n++){%>\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="zu-<%=n%>" class="radio-item spec" data-status="<%=specList[n].id%>" name="spec" <%if(n==0){%> checked <%}%>/>\
												  <span class="radio-inner"></span>\
											   </span>		\
											   <label class="radio-con" for="zu-<%=n%>"><%=specList[n].itemname%></label>\
											</div>\
										<%}%>\
									</div>\
								</div>\
								<div class="meal-item clearfloat required  group-item">\
									<div class="meal-tip">搭配主食：</div>\
									<div class="meal-con  meal-height dpzs_wrap">\
										<%for(var j=0;j<foodList.length;j++){%>\
											<div class="checkbox-wp">\
											   <span class="checkbox-input">\
												  <input type="checkbox" id="wx-<%=j%>" class="check-item staple-food" data-id="<%=foodList[j].id%>"/>\
												  <span class="checkbox-inner"></span>\
											   </span>		\
											   <label class="checkbox-con" for="wx-<%=j%>"><%=foodList[j].itemname%></label>\
											</div>\
										<%}%>\
									</div>\
								</div>\
								\
								<div class="meal-item clearfloat required">\
									<div class="meal-tip">餐品描述：</div>\
									<div class="meal-con">\
										<textarea class="meal-describe" placeholder="请输入餐品描述"></textarea>\
									</div>\
								</div>\
								<div class="meal-item clearfloat ">\
									<div class="meal-tip ">送餐时间：</div>\
									<div class="meal-con">\
										<input class="meal-input delivery-time-str" placeholder="请选择送餐时间"/>\
									</div>\
								</div>\
								<div class="meal-item clearfloat ">\
									<div class="meal-tip ">供应时间：</div>\
									<div class="meal-con">\
										<div class="long-time">\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="time1" class="radio-item supply-type" data-status="1" name="supplyType" checked/>\
												  <span class="radio-inner"></span>\
											   </span>		\
											   <label class="radio-con" for="time1">长期有效</label>\
											</div>\
										</div>\
										<div class="short-time">\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="time2" class="radio-item supply-type" data-status="2" name="supplyType" />\
												  <span class="radio-inner"></span>\
											   </span>		\
											   <label class="radio-con" for="time2">按具体时间供应</label>\
											</div>\
											<input class="supply-time" id="supplyTime" placeholder="请选择供应时间" readonly/>\
										</div>\
									</div>\
								</div>\
								<div class="meal-item clearfloat group-item">\
								<div class="meal-tip">设为模板：</div>\
								<div class="meal-con meal-height">\
									<div class="radio-wp">\
									   <span class="radio-input">\
										 <input type="radio" id="model1" class="radio-item isModel" data-status="0" name="isModel" checked/>\
										  <span class="radio-inner"></span>\
									   </span>		\
									   <label class="radio-con" for="model1">否</label>\
									</div>\
									<div class="radio-wp">\
									   <span class="radio-input">\
										 <input type="radio" id="model2" class="radio-item isModel" data-status="1" name="isModel" />\
										  <span class="radio-inner"></span>\
									   </span>		\
									   <label class="radio-con" for="model2">是</label>\
									</div>\
									<div class="meal-tips">设为模版后导入的川菜、粤菜、会议餐将使用本模版的餐品信息自动添加餐品</div>\
								</div>\
							</div>\
							\
								<div class="meal-item clearfloat required">\
									<div class="meal-tip ">餐品照片：</div>\
									<div class="meal-con">\
										<div class="photo-list-wp clearfloat">\
											<div class="photo-list clearfloat">\
												\
											</div>\
											<div class="photo-btn">\
												<input class="photo-file" type="file" />\
											</div>\
										</div>\
										<div class="photo-tip">精美食品照片1～5张(尺寸750*580px，格式png或jpg，文件小于1Mb)</div>\
									</div>\
								</div>\
							</div>\
							<div class="dialog-btns">\
								<button class="cancel-add-btn btn-white">取消</button>\
								<button class="sure-add-btn btn-red">确定</button>\
							</div>\
						</div>\
					</div>\
				</div>\
			</div>	',
		gg:'<% for(var n=0;n<data.length;n++){%>\
					<div class="radio-wp">\
					   <span class="radio-input">\
						 <input type="radio" id="zu-<%=n%>" class="radio-item spec" data-status="<%=data[n].id%>" name="spec" <%if(n==0){%> checked <%}%>/>\
						  <span class="radio-inner"></span>\
					   </span>		\
					   <label class="radio-con" for="zu-<%=n%>"><%=data[n].itemname%></label>\
					</div>\
				<%}%>',
		dpzs:'<%for(var j=0;j<data.length;j++){%>\
					<div class="checkbox-wp">\
					   <span class="checkbox-input">\
						  <input type="checkbox" id="wx-<%=j%>" class="check-item staple-food" data-id="<%=data[j].id%>"/>\
						  <span class="checkbox-inner"></span>\
					   </span>		\
					   <label class="checkbox-con" for="wx-<%=j%>"><%=data[j].itemname%></label>\
					</div>\
				<%}%>',
		"updateTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-meal-con">\
					<div class="title-wp">\
						<span>修改餐品-<%if(detailData.spec==1){%>单品<%}else{%>组合<%}%></span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-meal-wp dialog-update-meal">\
						<div class="choose-meal-wp" data-type="<%=detailData.spec%>">\
							<div class="meal-list ">\
								<input type="hidden" id="orgId" value="<%=detailData.orgId%>" org__id="<%=detailData.orgId%>"/>\
								<div class="meal-item clearfloat required">\
									<div class="meal-tip ">餐品名：</div>\
									<div class="meal-con">\
										<%if(detailData.spec==1){%>\
											<select  class="meal-select  meal-name" >\
												<option value="">请选择餐品名</option>\
												<%for(var i=0;i<mealnameSlist.length;i++){%>\
													<option value="<%=mealnameSlist[i].id%>" <%if(detailData.mealCodeId==mealnameSlist[i].id){%> selected <%}%> ><%=mealnameSlist[i].itemname%></option>\
												<%}%>\
											</select>\
										<%}else{%>	\
											<select  class="meal-select  meal-name" >\
												<option value="">请选择餐品名</option>\
												<%for(var i=0;i<mealnameList.length;i++){%>\
													<option value="<%=mealnameList[i].id%>" <%if(detailData.mealCodeId==mealnameList[i].id){%> selected <%}%> ><%=mealnameList[i].itemname%></option>\
												<%}%>\
											</select>\
										<%}%>\
									</div>\
								</div>\
								<div class="meal-item clearfloat">\
									<div class="meal-tip">状态：</div>\
									<div class="meal-con meal-height">\
										<div class="radio-wp">\
										   <span class="radio-input">\
											 <input type="radio" id="status1" class="radio-item status" data-status="1" name="status" <%if(detailData.status==1){%>checked<%}%> />\
											  <span class="radio-inner"></span>\
										   </span>		\
										   <label class="radio-con" for="status1">上架</label>\
										</div>\
										<div class="radio-wp">\
										   <span class="radio-input">\
											 <input type="radio" id="status2" class="radio-item status" data-status="2" name="status" <%if(detailData.status==2){%>checked<%}%>/>\
											  <span class="radio-inner"></span>\
										   </span>		\
										   <label class="radio-con" for="status2">下架</label>\
										</div>\
									</div>\
								</div>\
				\
								<%if(detailData.spec!=1 ){%>\
								<div class="meal-item clearfloat ">\
									<div class="meal-tip">是否会议餐:</div>\
									<div class="meal-con  meal-height is-meeting">\
										<div class="radio-wp">\
										   <span class="radio-input">\
											 <input type="radio" id="meeting1" class="radio-item isMeetFood" data-status="0" name="isMeetFood" <%if(detailData.isMeetFood==0){%>checked<%}%>/>\
											  <span class="radio-inner"></span>\
										   </span>		\
										   <label class="radio-con" for="meeting1">否</label>\
										</div>\
										<div class="radio-wp">\
										   <span class="radio-input">\
											 <input type="radio" id="meeting2" class="radio-item isMeetFood" data-status="1" name="isMeetFood" <%if(detailData.isMeetFood==1){%>checked<%}%>/>\
											  <span class="radio-inner"></span>\
										   </span>		\
										   <label class="radio-con" for="meeting2">是</label>\
										</div>\
										<div class="meal-tips">会议餐不需要消费积分，只有管理员可以预定</div>\
									</div>\
								</div>\
								<div class="meal-item clearfloat ">\
									<div class="meal-tip">规格：</div>\
									<div class="meal-con  meal-height">\
										<% for(var n=0;n<specList.length;n++){%>\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="zu-<%=n%>" class="radio-item spec" data-status="<%=specList[n].id%>" name="spec" <%if(detailData.spec==specList[n].id){%> checked <%}%>/>\
												  <span class="radio-inner"></span>\
											   </span>		\
											   <label class="radio-con" for="zu-<%=n%>"><%=specList[n].itemname%></label>\
											</div>\
										<%}%>\
										\
									</div>\
								</div>\
								<div class="meal-item clearfloat required  ">\
									<div class="meal-tip">搭配主食：</div>\
									<div class="meal-con  meal-height">\
										<%for(var j=0;j<foodList.length;j++){%>\
											<div class="checkbox-wp">\
											   <span class="checkbox-input">\
												  <input type="checkbox" id="wx-<%=j%>" class="check-item staple-food" data-id="<%=foodList[j].id%>" <%if(detailData.stapleFood.indexOf(foodList[j].id)!=-1){%>checked<%}%>/>\
												  <span class="checkbox-inner"></span>\
											   </span>		\
											   <label class="checkbox-con" for="wx-<%=j%>"><%=foodList[j].itemname%></label>\
											</div>\
										<%}%>\
									</div>\
								</div>\
								<%}%>\
								<div class="meal-item clearfloat required">\
									<div class="meal-tip">餐品描述：</div>\
									<div class="meal-con">\
										<textarea class="meal-describe" placeholder="请输入餐品描述" ><%=detailData.mealDescribe%></textarea>\
									</div>\
								</div>\
								<div class="meal-item clearfloat ">\
									<div class="meal-tip ">送餐时间：</div>\
									<div class="meal-con">\
										<input class="meal-input delivery-time-str" placeholder="请选择送餐时间" value="<%=detailData.deliveryTimeStr%>"/>\
									</div>\
								</div>\
								<div class="meal-item clearfloat ">\
									<div class="meal-tip ">供应时间：</div>\
									<div class="meal-con">\
										<div class="long-time">\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="time1" class="radio-item supply-type" data-status="1" name="supplyType" <%if(detailData.supplyType==1){%>checked<%}%>/>\
												  <span class="radio-inner"></span>\
											   </span>		\
											   <label class="radio-con" for="time1">长期有效</label>\
											</div>\
										</div>\
										<div class="short-time">\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="time2" class="radio-item supply-type" data-status="2" name="supplyType" <%if(detailData.supplyType==2){%>checked<%}%>/>\
												  <span class="radio-inner"></span>\
											   </span>		\
											   <label class="radio-con" for="time2">按具体时间供应</label>\
											</div>\
											<input class="supply-time" id="supplyTime" placeholder="请选择供应时间" value="<%=detailData.supplyTime%>" readonly/>\
										</div>\
									</div>\
								</div>\
								<%if(detailData.spec!=1 ){%>\
									<div class="meal-item clearfloat ">\
										<div class="meal-tip">设为模版:</div>\
										<div class="meal-con  meal-height">\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="model1" class="radio-item isModel" data-status="0" name="isModel" <%if(!detailData.isModel || detailData.isModel==0){%>checked<%}%>/>\
												  <span class="radio-inner"></span>\
											   </span>		\
											   <label class="radio-con" for="model1">否</label>\
											</div>\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="model2" class="radio-item isModel" data-status="1" name="isModel" <%if(detailData.isModel==1){%>checked<%}%>/>\
												  <span class="radio-inner"></span>\
											   </span>		\
											   <label class="radio-con" for="model2">是</label>\
											</div>\
											<div class="meal-tips">设为模版后导入的川菜、粤菜、会议餐将使用本模版的餐品信息自动添加餐品</div>\
										</div>\
									</div>\
									\
								<%}%>\
								<div class="meal-item clearfloat required">\
									<div class="meal-tip ">餐品照片：</div>\
									<div class="meal-con">\
										<div class="photo-list-wp clearfloat">\
											<div class="photo-list clearfloat">\
												<%if(detailData.urlList!=null&&detailData.urlList.length>0){for(var k=0;k<detailData.urlList.length;k++){%>\
													<div class="photo-item" data-url="<%=detailData.urls[k]%>">\
														<div class="photo-item-img" style="background-image: url(<%=detailData.urlList[k]%>)"></div>\
														<div class="del-btn"></div>\
													</div>\
												<%}}%>\
											</div>\
											<div class="photo-btn">\
												<input class="photo-file" type="file" />\
											</div>\
										</div>\
										<div class="photo-tip">精美食品照片1～5张(尺寸750*580px，格式png或jpg，文件小于1Mb)</div>\
									</div>\
								</div>\
							</div>\
							<div class="dialog-btns">\
								<button class="cancel-add-btn btn-white">取消</button>\
								<button class="sure-add-btn btn-red">确定</button>\
							</div>\
						</div>\
					</div>\
				</div>\
			</div>	',
		"photoTpl": '<div class="photo-item" data-url="<%=url%>">\
							<div class="photo-item-img" style="background-image: url(<%=preview%>)"></div>\
							<div class="del-btn"></div>\
						</div>',
		"detailTpl": '<div class="dialog-wp">\
					<div class="mask"></div>\
					<div class="dialog dialog-meal-con">\
					<div class="title-wp">\
						<span>餐品详情-<%if(spec==1){%>单品<%}else{%>组合<%}%></span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-detail-meal-wp ">\
			 			<div class="detail-list">\
			 				<div class="detail-item clearfloat">\
				 				<div class="detail-tip">餐品名:</div>\
				 				<div class="detail-con"><%=mealName%></div>\
			 				</div>\
							 <div class="detail-item clearfloat">\
								<div class="detail-tip">状态:</div>\
								<div class="detail-con">\
			 						<%if(status==1){%>\
			 							上架\
			 						<%}else{%>\
			 							下架\
			 						<%}%>\
			 					</div>\
							</div>\
			 				<%if(spec!=1){%>\
							\
							 <div class="detail-item clearfloat">\
								<div class="detail-tip">规格:</div>\
								<div class="detail-con">\
									<%=specStr%>\
			 					</div>\
							</div>\
							 <div class="detail-item clearfloat">\
								<div class="detail-tip">搭配主食:</div>\
								<div class="detail-con"><%=stapleFoodStr%></div>\
							</div>\
							<%}%>	\
							 <div class="detail-item clearfloat">\
								<div class="detail-tip">餐品描述:</div>\
								<div class="detail-con"><%=mealDescribe%></div>\
							</div>\
							 <div class="detail-item clearfloat">\
								<div class="detail-tip">送餐时间:</div>\
								<div class="detail-con"><%=deliveryTimeStr%></div>\
							</div>\
							 <div class="detail-item clearfloat">\
								<div class="detail-tip">供应时间:</div>\
								<div class="detail-con">\
									 <%if(supplyType==1){%>\
										长期有效\
									<%}else{%>\
			 							<%=supplyTime%>\
									<%}%>\
			 					</div>\
							</div>\
						 <%if(spec!=1){%>\
						 <div class="detail-item clearfloat">\
							<div class="detail-tip">设为模版:</div>\
							<div class="detail-con">\
						 <%if(isModel==1){%>\
							是\
						<%}else{%>\
							否\
						<%}%>\
							</div>\
						</div>\
						 <div class="detail-item clearfloat">\
							<div class="detail-tip">是否会议餐:</div>\
							<div class="detail-con">\
								 <%if(isMeetFood==0){%>\
									否\
								<%}else if(isMeetFood==1){%>\
									是\
								<%}%>\
							</div>\
						</div>\
						 <%}%>\
							 <div class="detail-item clearfloat">\
								<div class="detail-tip">餐品照片:</div>\
								<div class="detail-con clearfloat">\
			 						<% var urlList = mealImagesUrl.substring(0,mealImagesUrl.length-1).split(";") %>\
			 						<%for(var i=0;i<urlList.length;i++){%>\
			 							<div class="img"  style="background-image: url(<%=urlList[i]%>)" data-img="<%=urlList[i]%>" onclick="hideEnlarge(this)"></div>\
			 						<%}%>\
			 					</div>\
							</div>\
			 			</div>\
					</div>\
					</div>\
			</div>	',
		mealNameTpl: '<option value="">请选择餐品名</option>\
				<%for(var i=0;i<data.length;i++){%>\
				<option value="<%=data[i].id%>"><%=data[i].itemname%></option>\
			<%}%>\
			',
		exportTpl: '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog export-or-download-con">\
					<div class="title-wp">\
						<span>导入账号</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="export-or-download-wp">\
						<div class="choose-item-wp">\
							<span class="tip">校区</span>\
				            <input class="d-orgid" name="orgId" id="orgId" org__id="" autocomplete="off"/>\
				            <span class="select_wrap _hide"></span>\
						</div>\
						<div class="export-or-download-btns">\
					 		<button class="sure-operate-btn btn-red-width90" type="button">导入<input class="excelFile" type="file" id="excelFile" name="excelFile" /></button> \
						</div>\
					</div>\
				</div>\
			</div>',
	}
	template.config("escape", false);
	var mealManage = {
		init: function() {
			this.render();
			this.bindEvent();
		},
		render: function() {
			this.rendertable();
			this.itemAjax();
			this.ajaxinitData();
		},
		bindEvent: function() {
			var _this = this;
			layui.use('laydate', function() {
				var laydate = layui.laydate;

				//执行一个laydate实例
				laydate.render({
					elem: '#beginTime' //提交开始时间

				});
				laydate.render({
					elem: '#endTime' //提交结束时间
				});
			});
			//重置
			$(".set-btn").on("click", function() {
				var $orgId = $("#conditionform  .single-orgid");
				var $dom = $("#conditionform input,#conditionform select")
				if($orgId.length){
					$dom.val("").removeAttr('com__id dep__id')
				}else{
					$dom.val("").removeAttr('org__id com__id dep__id')
				}
				_this.againRenderTable({type:1});
			});

			//导入模板
			//单校区
			$(".main-operate-wp #excelFile").live("change", function() {
				var $orgId = $("#conditionform  .single-orgid");
				_this.exportFile($orgId.length);
				//_this.exportFile();
			});
			//多校区
			$(".main-operate-wp .export-btn").on("click", function() {
				_this.exportFile();
			})
			//下载模板
			$("#importTemplate").on("click", function() {
				location.href = $("#contextPath").val() + "/upload/Meal.xlsx";
			});
			//新增
			$(".add-ele-btn").on("click", function() {
				//显示弹窗
				$("body").append(template.render(tpl.addTpl)({
					orgList: orgList,
					foodList: foodList,
					mealnameList: mealnameList,
					specList: specList,
					mealnameSlist: mealnameSlist
				}));
				//关闭弹窗
				$(".close-btn,.cancel-add-btn").on("click", function() {
					$(".dialog-wp").remove();
				});
				layui.use('laydate', function() {
					var laydate = layui.laydate;
					laydate.render({
						elem: '#supplyTime' //提交结束时间
					});
				});
				//选择单品还是组合
				$(".circle-con").on("click", function() {
					var type = $(this).data("type"); //type 为1 单品 为2组合
					// 点之前先清空所有的数据，给一个初始化的校区
					$('.mut_org').val(orgList[0]['name']).attr('org__id',orgList[0]['id'])
					$(".group-meal-name").html(template.render(tpl.mealNameTpl)({'data':mealnameList}))
					$(".single-meal-name").html(template.render(tpl.mealNameTpl)({'data':mealnameSlist}))
					// 
					$(".choose-wrapper").hide();
					$(".choose-meal-wp").data("type", type).show();
					//重选食品类型，置空之前所选的值
					$(".choose-meal-wp input:not('#orgId'),.choose-meal-wp select,.choose-meal-wp textarea").val("");
					$(".photo-list").html("");
					//单品和组合显示不同
					if (type == 2) {
						isMax = 1
						$(".single-meal-name").hide();
						$(".group-meal-name").show();
						$(".meal-item.group-item").show();
					} else {
						isMax = 0
						$(".single-meal-name").show();
						$(".group-meal-name").hide();
						$(".meal-item.group-item").hide();
					}
				});
				//返回选择
				$(".choose-again").on("click", function() {
					$(".choose-wrapper").show();
					$(".choose-meal-wp").hide();
				});
				//确定新增餐品
				$(".sure-add-btn").on("click", function() {
					_this.addOrUpdate(function() {
						$(".dialog-wp").remove();
						_this.againRenderTable();
					})
				});
				//上传餐品图片
				$(".photo-file").on("change", function() {

					var file = $(this)[0].files[0];
					var fileName = $(this)[0].value;
					var suffixIndex = fileName.lastIndexOf(".");
					var suffix = fileName.substring(suffixIndex + 1).toUpperCase();
					if ($(".photo-item").length == 5) {
						layer.msg("餐品照片最多上传5张!");
						return false;
					}
					if (suffix != "BMP" && suffix != "JPG" && suffix != "JPEG" && suffix != "PNG" && suffix != "GIF") {
						layer.alert("请上传图片（格式BMP、JPG、JPEG、PNG等）!");
						return false;
					}
					_this.uploadImg(file)
					//						
				})
				_this.meetingChoose()

			})
			_this.search_fuzzy()
		},
		// 模糊搜索事件
		search_fuzzy: function(){
			var _this = this
			var default_option = {
				org_attrName:'org__id',
				com_attrName:'com__id',
				dep_attrName:'dep__id',
				org_spanName:'org__span',
				com_spanName:'com__span',
				dep_spanName:'dep__span',
				org_path:'/admin/templ/getOrgListByName',
				com_path:'/admin/templ/getVirList',
				dep_path:'/admin/templ/getDept',
				contextPath:$("#contextPath").val()
			}
			var option_1 = $.extend(true,{},default_option,{
				org_target:'.default-select#orgId'
			});
			var option_2 = $.extend(true,{},default_option,{
				org_target:'.d-orgid#orgId'
			});
			var option_3 = $.extend(true,{},default_option,{
				org_target:'.meal-select#orgId'
			});
			 
			

			function eve(option_,otherOption){
				var obj = $.extend(true, {}, option_, otherOption);
				var type = obj.type
				var _path, _target, _attrName, _spanName
				if(type == 1){
					_path = obj.org_path
					_target = obj.org_target
					_attrName = obj.org_attrName
					_spanName = obj.org_spanName
				}else if(type == 2){
					_path = obj.com_path
					_target = obj.com_target
					_attrName = obj.com_attrName
					_spanName = obj.com_spanName
				}else if(type == 3){
					_path = obj.dep_path
					_target = obj.dep_target
					_attrName = obj.dep_attrName
					_spanName = obj.dep_spanName
				}
				$('body').on("input",_target,function(event){
					var _this = $(this)
					var obj_input = $.extend(true,{}, obj,{"_this":_this});
					cjqt.search_fuzzy.event_input(_this,_attrName,_spanName,contextPath,_path,obj_input)
				});
				$('body').on("focus",_target,function(event){
					var _this = $(this)
					var obj_focus = $.extend(true,{},obj,{"_this":_this});
					cjqt.search_fuzzy.event_focus(_this,_attrName,_spanName,contextPath,_path,obj_focus)
				});
				$('body').on('blur',_target,function(event) {
					var _this = $(this)
					var obj_blur = $.extend(true,{},obj,{"_this":_this});
					cjqt.search_fuzzy.event_blur(_this,_attrName,obj_blur)
				});
				$('body').on('click',_target+'~.select_wrap>.'+_spanName, function(event) {
					event.preventDefault();
					event.stopPropagation();
					/* Act on the event */
					var _this = $(this)
					var obj_click = $.extend(true,{},obj,{"_this":_this});
					cjqt.search_fuzzy.event_click(_this,_attrName,_target,obj_click)
				});
			}
			// 搜索绑定
			eve(option_1,{
				type:1,
				input_callback:function(){
					$(".mealName").html('<option value="">请选择餐品名</option>')
				},
				click_callback:function(){
					var orgId = $('.default-select#orgId').attr('org__id')
					// 改变餐品名
					_this.getAllInfo(orgId,5,function(data){
						$(".mealName").html(template.render(tpl.mealNameTpl)(data))
					})
				}
			})
			// 导入绑定
			eve(option_2,{type:1})
			// 新增
			eve(option_3,{
				type:1,
				input_callback:function(){
					$(".group-meal-name").html('<option value="">请选择餐品名</option>')
				},
				click_callback:function(){
					var orgId = $('.meal-select#orgId').attr('org__id')
					// 改变餐品名
					if(isMax == 1){
						_this.getAllInfo(orgId,3,function(data){
							$(".group-meal-name").html(template.render(tpl.mealNameTpl)(data))
						})
						// 改变规格
						_this.getAllInfo(orgId,2,function(data){
							console.log(data)
							$(".gg_wrap").html(template.render(tpl.gg)(data))
						})
						// 改变搭配主食
						_this.getAllInfo(orgId,1,function(data){
							console.log(data)
							$(".dpzs_wrap").html(template.render(tpl.dpzs)(data))
						})
					}else if(isMax == 0){
						_this.getAllInfo(orgId,4,function(data){
							$(".single-meal-name").html(template.render(tpl.mealNameTpl)(data))
						})
					}
					
				}
			})
		},
		rendertable: function() {
			var _this = this;
			layui.use('table', function() {
				table = layui.table;

				//方法级渲染
				table.render({
					elem: '#LAY_table_user',
					url: $("#contextPath").val() + "/admin/dinner/getMealList",
					method: "post",
					skin: 'nob' //行边框风格
						,
					even: true //开启隔行背景
						,
					size: 'lg' //小尺寸的表格
						,
					cols: [
						[{
							field: 'index',
							title: '序号',
							width: '80',
							templet: '#indexTpl'
						}, {
							field: 'mealName',
							title: '餐品名',
							minWidth: 200
						},{
							field: 'supplyTime',
							title: '供应时间',
							minWidth: 200,
							templet: function(data) {
								//1长期供应
								if (data.supplyType == 1) {
									return '长期有效'
								} else if (data.supplyType == 2) {
									return data.supplyTime
								} else {
									return ''
								}
							}
						}, {
							field: 'mealDescribe',
							title: '餐品描述',
							minWidth: 200
						},{
							field: 'isMeetFood',
							title: '是否会议餐',
							minWidth: 150,
							templet: function(data) {
								//
								if (data.isMeetFood == 1) {
									return '是'
								} else {
									return '否'
								}
							}
						}, {
							field: 'isModel',
							title: '设为模板',
							minWidth: 100,
							templet: function(data) {
								//
								if (data.isModel == 1) {
									return '是'
								} else {
									return '否'
								}
							}
						}, {
							field: 'specStr',
							title: '规格',
							minWidth: 150
						}, {
							field: 'stapleFoodStr',
							title: '主食',
							minWidth: 200
						},  {
							field: 'deliveryTimeStr',
							title: '送餐时间',
							minWidth: 200
						},  {
							field: 'status',
							title: '状态',
							width: 120,
							templet: function(data) {
								//1上架2下架
								if (data.status == 1) {
									return '上架'
								} else if (data.status == 2) {
									return '下架'
								} else {
									return ''
								}
							}
						}, {

							title: '可操作',
							fixed: 'right',
							width: 260,
							align: 'center',
							templet: function(data) {
								var str = '';
								if (data.status == 1) {
									str += '<button class="t-btn t-red-btn t-delete-btn" data-id=' + data.id + ' data-type="2">下架</button>';
								} else if (data.status == 2 || data.status == '' || data.status == null) {
									str += '<button class="t-btn t-red-btn t-delete-btn" data-id=' + data.id + ' data-type="1">上架</button>';
								}
								str += '<button class="t-btn t-red-btn t-edit-btn" data-id=' + data.id + ' data-spec = ' + data.spec + '>修改</button>';
								str += '<button class="t-btn t-red-btn t-detail-btn" data-id=' + data.id + '   >详情</button>';
								str += '<button class="t-btn t-white-btn t-delete-btn" data-id=' + data.id + ' data-type="3">删除</button>';

								return str;
							}
						}]
					],
					id: 'testReload',
					page: true,
					response: {
						statusName: 'code' //数据状态的字段名称，默认：code
							,
						statusCode: 200 //成功的状态码，默认：0
							,
						countName: "count" //数据总数的字段名称，默认：count
							,
						dataName: "data" //数据列表的字段名称，默认：data
					},
					request: {
						pageName: 'pageNo' //页码的参数名称，默认：page
							,
						limitName: 'pageSize' //每页数据量的参数名，默认：limit
					},
					done: function(res, curr, count) {
						//如果是异步请求数据方式，res即为你接口返回的信息。
						//删除/上架/下架
						$(".t-delete-btn").on("click", function() {
							var id = $(this).data("id");
							var type = $(this).data("type");
							_this.ajaxDelTemp(id, type, function() {
								_this.againRenderTable();
							})
						});
						//修改
						$(".t-edit-btn").on("click", function() {
							var id = $(this).data("id");
							_this.getDetail(id, function(detailData) {
								var orgId = detailData.orgId
								_this.showUpdateDialog(detailData, orgId)
							})
						});
						//详情
						$(".t-detail-btn").on("click", function() {
							var id = $(this).data("id");
							//				    		
							_this.getDetail(id, function(detailData) {
								$("body").append(template.render(tpl.detailTpl)(detailData));
								//关闭弹窗
								$(".close-btn").on("click", function() {
									$(".dialog-wp").remove();
								});
							})
						})

					}
				});
				//查询
				$('#conditionform  .search-btn').on('click', function() {
					_this.againRenderTable();
				});
			});
		},
		/*重新渲染table*/
		againRenderTable: function(option) {
			var obj = $.extend(true, {}, option);
			var type =  obj.type || ''
			var $orgId = $("#conditionform  .single-orgid");
			var orgId = $("#conditionform  #orgId").attr('org__id')
			if(type == 1){
				table.reload('testReload', {
					where: {
						mealName: '',
						status: '',
						beginTime: '',
						endTime: '', 
						orgId: ''
					},
					page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}else{
				table.reload('testReload', {
					where: {
						mealName: $("#conditionform .mealName").val(),
						status: $("#conditionform .status").val(),
						beginTime: $("#conditionform #beginTime").val(),
						endTime: $("#conditionform #endTime").val(), //楼宇id
						orgId: $("#conditionform  #orgId").attr('org__id'),
					},
					page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}
		},
		//请求校区列表
		itemAjax: function() {
			$.ajax({
				type: "post",
				url: contextPath + "/admin/templ/getOrgList",
				success: function(data) {
					if (data.code == ERROK) {
						orgList = data.data;
					} else {
						layer.msg(data.msg)
					}

				},
				error: function(error) {
					layer.msg('error')
				}
			});
		},
		/**
		 * 初始化所有参数
		 * @param id 校区id
		 */
		ajaxinitData: function() {
			var _this = this;
			var orgId = orgList[0]['id'] || ''
			// 获取全部餐品名
			_this.getAllInfo(orgId,5,function(data){
				allMealnameList = data.data;
				// 单校区的时候把搜索餐品名补全
				if(orgList.length == 1){
					$(".mealName").html(template.render(tpl.mealNameTpl)(data))
				}
			})
			// 主食搭配
			_this.getAllInfo(orgId,1,function(data){
				foodList = data.data;	
			})
			// 组合餐品名
			_this.getAllInfo(orgId,3,function(data){
				mealnameList = data.data;
			})
			// 单品餐品名
			_this.getAllInfo(orgId,4,function(data){
				mealnameSlist = data.data;
			})
			// 规格
			_this.getAllInfo(orgId,2,function(data){
				specList = data.data;
			})
		},
		/**
		 * 获取所有信息
		 * @param id 1:搭配主食 2:获取规格 3:获取组合 4:获取单品 5:获取餐品列表
		 * 
		 */
		getAllInfo:function(orgId, type, callback){
			$.ajax({
				type: "post",
				url: contextPath + "/admin/dinner/getStapleFood",
				data: {
					type: type,
					orgId:orgId
				},
				success: function(data) {
					if (data && data.code == 200 && data.data) {
						var _data = data.data
						if(callback != undefined && (typeof callback) == "function"){
							callback(data)
						}
					} else {
						layer.msg(data.msg)
					}
				},
				error: function(error) {
					layer.msg('error')
				}
			});
		},
		/**
		 * 获取详情
		 * @param id 餐品id
		 * @param callback
		 */
		getDetail: function(id, callback) {
			var _this = this;
			$.ajax({
				type: "post",
				url: contextPath + "/admin/dinner/getMealInfo",
				data: {
					id: id
				},
				success: function(data) {
					if (data.code == ERROK) {
						callback(data.data);
					} else {
						layer.msg(data.msg)
					}
				},
				error: function(error) {
					layer.msg('error')
				}
			});
		},
		/**
		 * 删除/上架/下架 模板
		 * @param id 模板id
		 * @param type 1位上架 2为下架 3为删除
		 * @param callback
		 */
		ajaxDelTemp: function(id, type, callback) {
			var str = "";
			if (type == "1") {
				str = "确认上架?";
			} else if (type == "2") {
				str = "确认下架?";
			} else if (type == "3") {
				str = "确认删除?";
			}
			layer.confirm(str, {
				btn: ['确定', '取消']
			}, function(index, layero) {
				layer.close(index); //如果设定了yes回调，需进行手工关闭
				$.ajax({
					type: "post",
					url: contextPath + "/admin/dinner/updateMeal",
					data: {
						"id": id,
						"type": type
					},
					success: function(data) {
						if (data.code == ERROK) {
							callback();
						} else {
							layer.msg(data.msg)
						}
					},
					error: function(error) {
						layer.msg('error')
					}
				});
			}, function(index) {

			});
		},
		/**
		 * 上传图片
		 * @param file file文件
		 */
		uploadImg: function(filedata) {
			var _this = this;
			var formData = new FormData();
			formData.append("filedata", filedata)
			$.ajax({
				type: "post",
				url: contextPath + "/admin/enter/uploadImage",
				data: formData,
				cache: false, // 不缓存
				processData: false, // 告诉jQuery不要去处理发送的数据
				contentType: false, // 告诉jQuery不要去设置Content-Type请求头
				success: function(data) {
					if (data.code == ERROK) {
						$(".photo-list").append(template.render(tpl.photoTpl)(data.data));
						$(".del-btn").on("click", function() {
							$(this).closest(".photo-item").remove();
						})
					} else {
						layer.msg(data.msg)
					}
				},
				error: function(error) {
					layer.msg('error')
				}
			});
		},
		/**
		 * 显示修改弹窗
		 * @param detailData 餐品详情数据
		 * @param foodList 主食列表数据
		 */
		showUpdateDialog: function(detailData, orgId) {
			var _this = this;
			var foodList, mealnameList, mealnameSlist, specList
			//请求一波对应校区的所有信息
			// 主食搭配
			_this.getAllInfo(orgId,1,function(data){
				foodList = data.data;	
			})
			// 组合餐品名
			_this.getAllInfo(orgId,3,function(data){
				mealnameList = data.data;
			})
			// 单品餐品名
			_this.getAllInfo(orgId,4,function(data){
				mealnameSlist = data.data;
			})
			// 规格
			_this.getAllInfo(orgId,2,function(data){
				specList = data.data;
			})
			//
			//显示弹窗
			if (detailData.mealImagesUrl) {
				detailData.urlList = detailData.mealImagesUrl.substring(0, detailData.mealImagesUrl.length - 1).split(";");
			}
			if (detailData.mealImages) {
				detailData.urls = detailData.mealImages.substring(0, detailData.mealImages.length - 1).split(";")
			}

			$("body").append(template.render(tpl.updateTpl)({
				detailData: detailData,
				foodList: foodList,
				mealnameList: mealnameList,
				mealnameSlist: mealnameSlist,
				specList: specList
			}));
			//关闭弹窗
			$(".close-btn,.cancel-add-btn").on("click", function() {
				$(".dialog-wp").remove();
			});
			layui.use('laydate', function() {
				var laydate = layui.laydate;
				laydate.render({
					elem: '#supplyTime' //提交结束时间
				});
			});
			//确定新增餐品
			$(".sure-add-btn").on("click", function() {
				_this.addOrUpdate(function() {
					$(".dialog-wp").remove();
					_this.againRenderTable();
				}, detailData.id)
			});
			//删除餐品图片
			$(".del-btn").on("click", function() {
				$(this).closest(".photo-item").remove();
			})
			//上传餐品图片
			$(".photo-file").on("change", function() {
				var file = $(this)[0].files[0];
				var fileName = $(this)[0].value;
				var suffixIndex = fileName.lastIndexOf(".");
				var suffix = fileName.substring(suffixIndex + 1).toUpperCase();
				if ($(".photo-item").length == 5) {
					layer.msg("餐品照片最多上传5张!");
					return false;
				}
				if (suffix != "BMP" && suffix != "JPG" && suffix != "JPEG" && suffix != "PNG" && suffix != "GIF") {
					layer.alert("请上传图片（格式BMP、JPG、JPEG、PNG等）!");
					return false;
				}
				_this.uploadImg(file)
				//				
			})
			_this.meetingChoose(1);
		},
		/**
		 * 新增修改餐品
		 * @param callback
		 * @param id 餐品id
		 */
		addOrUpdate: function(callback, id) {
			var _this = this;
			var mealType = $(".choose-meal-wp").data("type"); //1为单品 2为组合
			var formData = new FormData();
			//id
			formData.append("id", !!id ? id : '');
			//校区
			var orgId = $(".choose-meal-wp #orgId").attr('org__id')
			if (!orgId) {
				layer.msg("请选择校区");
				return false;
			};
			formData.append("orgId", orgId);
			//餐品名
			if (!!id) {
				var mealName = $(".meal-name").val();
			} else if (mealType != 1) {
				var mealName = $(".group-meal-name").val();
			} else {
				var mealName = $(".single-meal-name").val();
			}

			if (!mealName) {
				layer.msg("请选择餐品名");
				return false;
			} else if (_this.strlen(mealName) > 40) {
				layer.msg("餐品名最多20个汉字");
				return false;
			};

			formData.append("mealCodeId", mealName);

			//状态
			var status = $(".meal-con .status:checked").data("status")
			formData.append("status", !!status ? status : '');



			if (mealType != 1) {

				//规格
				var spec = $(".meal-con .spec:checked").data("status")
				formData.append("spec", !!spec ? spec : '');

				//设为模板
				var isModel = $(".meal-con .isModel:checked").data("status")
				formData.append("isModel", isModel);

				//会议餐
				var isMeetFood = $(".meal-con .isMeetFood:checked").data("status")
				formData.append("isMeetFood", isMeetFood);

				//搭配主食

				var foodList = $(".meal-con .staple-food:checked");
				if (foodList.length == 0) {
					layer.msg("请选择搭配主食");
					return false;
				} else {
					var foodArr = [];
					//stapleFood
					for (var i = 0; i < foodList.length; i++) {
						foodArr.push($(foodList[i]).data("id"));
					}
					formData.append("stapleFood", foodArr.join(";") + ";");
				};
			} else {
				//规格
				formData.append("spec", 1);
			};
			//餐品描述
			var mealDescribe = $(".meal-describe").val();
			if (!mealDescribe) {
				layer.msg("请输入餐品描述");
				return false;
			} else if (_this.strlen(mealDescribe) > 100) {
				layer.msg("餐品描述最多50个汉字");
				return false;
			};;
			formData.append("mealDescribe", mealDescribe);

			//送餐时间
			formData.append("deliveryTimeStr", $(".delivery-time-str").val());

			//供应类型
			var supplyType = $(".meal-con .supply-type:checked").data("status");
			formData.append("supplyType", !!supplyType ? supplyType : '');
			if (supplyType == 2) {
				//供应时间
				var supplyTime = $(".supply-time").val();
				if (!supplyTime) {
					layer.msg("请选择供应时间");
					return false;
				};
				formData.append("supplyTime", supplyTime);
			};
			//餐品照片	
			var photoList = $(".photo-item");
			if (photoList.length == 0) {
				layer.msg("请上传餐品照片");
				return false;
			} else {
				var photoArr = [];
				for (var i = 0; i < photoList.length; i++) {
					photoArr.push($(photoList[i]).data("url"));
				}
				formData.append("mealImages", photoArr.join(";") + ";");
			};
			$.ajax({
				type: "post",
				url: contextPath + "/admin/dinner/saveAndUpdateMeal",
				data: formData,
				cache: false, // 不缓存
				processData: false, // 告诉jQuery不要去处理发送的数据
				contentType: false, // 告诉jQuery不要去设置Content-Type请求头
				success: function(data) {
					if (data.code == ERROK) {
						callback();
					} else {
						layer.msg(data.msg)
					}
				},
				error: function(error) {
					layer.msg('error')
				}
			});
		},
		strlen: function(str) {
			var len = 0;
			for (var i = 0; i < str.length; i++) {
				var c = str.charCodeAt(i);
				//单字节加1   
				if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
					len++;
				} else {
					len += 2;
				}
			}
			return len;
		},
		/**
		 * 导入账号数据
		 * @param length 判断是单校区还是多校区 ，为0多校区 不为0单校区 
		 */
		exportFile: function(length) {
			var _this = this;
			if (!!length) {
				_this.exportFileAjax($("#conditionform  .single-orgid").attr('org__id'))
			} else {
				$("body").append(template.render(tpl.exportTpl)({
					orgList: orgList
				}));
				$(".close-btn").on("click", function() {
					$(".dialog-wp").remove();
				});
				$(".sure-operate-btn input").on("change", function() {
					var orgId = $(".d-orgid").attr('org__id');
					if (!orgId) {
						layer.msg("请选择校区");
						//						$(this).val("").change();
						return false;
					};
					_this.exportFileAjax(orgId, function() {
						$(".dialog-wp").remove();
					})
				});

			}


		},
		/**
		 * 导入用户请求
		 * @param orgId 校区id
		 * @param callback
		 */
		exportFileAjax: function(orgId, callback) {
			var _this = this;
			var fileName = $("#excelFile").val();
			var extension = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length);
			var formData = new FormData();
			if (extension == "xlsx") {
				if (fileName == null || fileName == "") {
					layer.alert("数据导入为空,请按照模板填写资料后再导入!");
					return;
				};

				formData.append("orgId", orgId);
				formData.append("excelFile", $("#excelFile")[0].files[0]);

				$.ajax({
					type: "post",
					url: $("#contextPath").val() + "/admin/dinner/importMeal",
					data: formData,
					cache: false, // 不缓存
					processData: false, // 告诉jQuery不要去处理发送的数据
					contentType: false, // 告诉jQuery不要去设置Content-Type请求头			 
					success: function(data) {


						if (data.code == '200') {
							callback && callback();
							_this.againRenderTable();
						} else {
							layer.msg(data.msg)
						}
					},
					error: function() {

						layer.msg('error')
					}
				});
			} else {
				layer.alert("请上传xlsx格式的文件");
			}
		},
		meetingChoose: function(type) {
			//是否会议餐控制规格和主食
			$(".is-meeting .radio-wp").on("click", function() {
				var status = $(".meal-con .isMeetFood:checked").data("status");
				if (status == 0) {
					$(".meal-con .spec").attr("disabled", false);
					$(".meal-con .staple-food").attr("disabled", false);
				} else {
					$(".meal-con .spec").attr("disabled", true).prop("checked", false);
					$(".meal-con .staple-food").attr("disabled", true).prop("checked", false);
					$(".meal-con .spec").eq($(".meal-con .spec").length - 1).attr("disabled", false).prop("checked", true);
					$(".meal-con .staple-food").eq(0).attr("disabled", false).prop("checked", true);

				}
			})
			//修改时选择是会议室 ，数据重现
			if (type == 1) {
				var status = $(".meal-con .isMeetFood:checked").data("status");
				if (status == 0) {
					$(".meal-con .spec").attr("disabled", false);
					$(".meal-con .staple-food").attr("disabled", false);
				} else {
					$(".meal-con .spec").attr("disabled", true).prop("checked", false);
					$(".meal-con .staple-food").attr("disabled", true).prop("checked", false);
					$(".meal-con .spec").eq($(".meal-con .spec").length - 1).attr("disabled", false).prop("checked", true);
					$(".meal-con .staple-food").eq(0).attr("disabled", false).prop("checked", true);
				}
			}
		}
	};
	mealManage.init();
})