/**
 * app公告发布 发送历史
 * 2018/4/20 by liufang
 */
$(function(){
	
	var tpl = {
			"auditTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-audit-con">\
					<div class="title-wp">\
						<%if(status==21){%>\
							<span>客服专员审核</span>\
						<%}else if(status==22){%>\
							<span>客服主管审核</span>\
						<%}else if(status==23){%>\
							<span>工程主管审核</span>\
						<%}%>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-audit-wp">\
						<div class="audit-con">\
							<div class="audit-top">\
								<div class="audit-top-left">\
									<span class="icon"></span>\
									<span class="code">空调单号:<%=code%></span>\
								</div>\
								<div class="audit-top-right">\
									待审核\
								</div>\
							</div>\
							<div class="audit-list">\
								<div class="audit-item">\
									<div class="item-tip">公司名称:</div>\
									<div class="item-con"><%=virtualName%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">企业账号:</div>\
									<div class="item-con"><%=virAccountNo%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">申请时间:</div>\
									<div class="item-con"><%=applyTime%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">申请人:</div>\
									<div class="item-con"><%=applyUser%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">联系电话:</div>\
									<div class="item-con"><%=applyTel%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">申请位置:</div>\
									<div class="item-con"><%=roomNames%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">申请面积:</div>\
									<div class="item-con"><%=applyArea%>m²</div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">使用时间:</div>\
									<div class="item-con"><%=useDisplayTime%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">使用时长:</div>\
									<div class="item-con"><%=useLengthTime%>小时</div>\
								</div>\
							</div>\
							<div class="audit-list audit-list-right">\
								<div class="audit-item">\
									<div class="item-tip">单价:</div>\
									<div class="item-con"><%=priceDisplay%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">费用明细:</div>\
									<div class="item-con"><%=freeDetail%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">费用总结:</div>\
									<div class="item-con"><%=freeTotal%>元</div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">月结费用:</div>\
									<div class="item-con"><%=monthlyFree%>元</div>\
								</div>\
							</div>\
							<% if(status==22 || status==23){%>\
								<% if(operateDto.length>0){%>\
									<% for(var i=0;i<operateDto.length;i++){%>\
										<% if(operateDto[i].auditStatus == 21){%>\
											<div class="audit-list audit-list-long">\
												<div class="audit-item">\
													<div class="item-tip">客户专员审核时间:</div>\
													<div class="item-con"><%=operateDto[i].auditTime%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服专员审核人:</div>\
													<div class="item-con"><%=operateDto[i].auditUser%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服专员审核结果:</div>\
													<div class="item-con red"><%=operateDto[i].auditResult%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服专员审核意见:</div>\
													<div class="item-con"><%=operateDto[i].remark%></div>\
												</div>\
											</div>\
										<%}%>\
									<%}%>\
								<%}%>\
							<%}%>\
							<% if(status==23){%>\
								<% if(operateDto.length>0){%>\
									<% for(var j=0;j<operateDto.length;j++){%>\
										<% if(operateDto[j].auditStatus == 22){%>\
											<div class="audit-list audit-list-long">\
												<div class="audit-item">\
													<div class="item-tip">客服主管审核时间:</div>\
													<div class="item-con"><%=operateDto[j].auditTime%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服主管审核人:</div>\
													<div class="item-con"><%=operateDto[j].auditUser%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服主管审核结果:</div>\
													<div class="item-con red"><%=operateDto[j].auditResult%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服主管审核意见:</div>\
													<div class="item-con"><%=operateDto[j].remark%></div>\
												</div>\
											</div>\
										<%}%>\
									<%}%>\
								<%}%>\
							<%}%>\
							<div class="audit-reason-wp">\
								<span>审核结果：</span>\
								<div class="radio-wp">\
								   <span class="radio-input">\
									 <input type="radio" id="pass" class="radio-item audit-pass" data-status="1" name="result" />\
									  <span class="radio-inner"></span>\
								   </span>		\
								   <label class="radio-con" for="pass">通过</label>\
								</div>\
								<div class="radio-wp">\
								   <span class="radio-input">\
									 <input type="radio" id="no_pass" class="radio-item audit-no-pass" data-status="0" name="result"/>\
									  <span class="radio-inner"></span>\
								   </span>		\
								   <label class="radio-con" for="no_pass">不通过</label>\
								</div>\
							</div>\
							<% if(status==23){%>\
								<div  class="audit-person-wp">\
									<div class="person-title">指定开关空调人员：</div>\
									<div class="person-list">\
										<% for(var k=0;k<persons.length;k++){%>\
											<div class="radio-wp" >\
											   <span class="radio-input">\
												 <input type="radio" id="person_<%=k%>" class="radio-item audit-person" data-id="<%=persons[k].switchUserId%>" name="person" />\
												  <span class="radio-inner"></span>\
											   </span>		\
											   <label class="radio-con" for="person_<%=k%>"><%=persons[k].name%></label>\
											</div>\
										<%}%>\
									</div>\
								</div>\
							<%}%>\
							<div class="audit-suggest">\
								<div class="suggest-title">审核意见:</div>\
								<textarea class="suggest-text" placeholder="请输入审核意见"></textarea>\
							</div>\
						</div>\
						<div class="dialog-btm">\
							<button class="cancel-add-btn btn-white">取消</button>\
							<button class="sure-add-btn btn-red">保存</button>\
						</div>\
					</div>\
				</div>\
			</div>	',
			"detailTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-audit-con">\
					<div class="title-wp">\
						<span>空调加时详情</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-audit-wp">\
						<div class="audit-con">\
							<div class="audit-top">\
								<div class="audit-top-left">\
									<span class="icon"></span>\
									<span class="code">空调单号:<%=code%></span>\
								</div>\
								<div class="audit-top-right">\
									<%if(status==21 || status==22 || status==23){%>\
										待审核\
									<%}else if(status==31){%>\
										待使用\
									<%}else if(status==32){%>\
										已使用\
									<%}else if(status==33){%>\
										已取消\
									<%}else if(status==34){%>\
										已拒绝\
									<%}else if(status==35){%>\
										无效\
									<%}%>\
								</div>\
							</div>\
							<div class="audit-list">\
								<div class="audit-item">\
									<div class="item-tip">公司名称:</div>\
									<div class="item-con"><%=virtualName%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">企业账号:</div>\
									<div class="item-con"><%=virAccountNo%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">订单来源:</div>\
									<div class="item-con">\
										<%if(billSource==1){%>\
											空调加时\
										<%}else if(billSource==2){%>\
											预定会议室\
										<%}%>\
									</div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">申请时间:</div>\
									<div class="item-con"><%=applyTime%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">申请人:</div>\
									<div class="item-con"><%=applyUser%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">联系电话:</div>\
									<div class="item-con"><%=applyTel%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">申请位置:</div>\
									<div class="item-con"><%=roomNames%></div>\
								</div>\
								<% if(!!preBookUser){%>\
									<div class="audit-item">\
										<div class="item-tip">代订人:</div>\
										<div class="item-con"><%=preBookUser%></div>\
									</div>\
								<%}%>\
								<div class="audit-item">\
									<div class="item-tip">申请面积:</div>\
									<div class="item-con"><%=applyArea%>m²</div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">使用时间:</div>\
									<div class="item-con"><%=useDisplayTime%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">使用时长:</div>\
									<div class="item-con"><%=useLengthTime%>小时</div>\
								</div>\
							</div>\
							<div class="audit-list audit-list-right">\
								<div class="audit-item">\
									<div class="item-tip">单价:</div>\
									<div class="item-con"><%=priceDisplay%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">费用明细:</div>\
									<div class="item-con"><%=freeDetail%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">费用总结:</div>\
									<div class="item-con"><%=freeTotal%>元</div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">月结费用:</div>\
									<div class="item-con"><%=monthlyFree%>元</div>\
								</div>\
							</div>\
								<% if(operateDto.length>0){%>\
									<% for(var i=0;i<operateDto.length;i++){%>\
										<% if(operateDto[i].auditStatus == 21){%>\
											<div class="audit-list audit-list-long">\
												<div class="audit-item">\
													<div class="item-tip">客户专员审核时间:</div>\
													<div class="item-con"><%=operateDto[i].auditTime%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服专员审核人:</div>\
													<div class="item-con"><%=operateDto[i].auditUser%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服专员审核结果:</div>\
													<div class="item-con red"><%=operateDto[i].auditResult%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服专员审核意见:</div>\
													<div class="item-con"><%=operateDto[i].remark%></div>\
												</div>\
											</div>\
										<%}%>\
									<%}%>\
								<%}%>\
								<% if(operateDto.length>0){%>\
									<% for(var j=0;j<operateDto.length;j++){%>\
										<% if(operateDto[j].auditStatus == 22){%>\
											<div class="audit-list audit-list-long">\
												<div class="audit-item">\
													<div class="item-tip">客服主管审核时间:</div>\
													<div class="item-con"><%=operateDto[j].auditTime%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服主管审核人:</div>\
													<div class="item-con"><%=operateDto[j].auditUser%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服主管审核结果:</div>\
													<div class="item-con red"><%=operateDto[j].auditResult%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">客服主管审核意见:</div>\
													<div class="item-con"><%=operateDto[j].remark%></div>\
												</div>\
											</div>\
										<%}%>\
									<%}%>\
								<%}%>\
								<% if(operateDto.length>0){%>\
									<% for(var m=0;m<operateDto.length;m++){%>\
										<% if(operateDto[m].auditStatus == 23){%>\
											<div class="audit-list audit-list-long">\
												<div class="audit-item">\
													<div class="item-tip">工程主管审核时间:</div>\
													<div class="item-con"><%=operateDto[m].auditTime%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">工程主管审核人:</div>\
													<div class="item-con"><%=operateDto[m].auditUser%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">工程主管审核结果:</div>\
													<div class="item-con red"><%=operateDto[m].auditResult%></div>\
												</div>\
												<div class="audit-item">\
													<div class="item-tip">工程主管审核意见:</div>\
													<div class="item-con"><%=operateDto[m].remark%></div>\
												</div>\
											</div>\
										<%}%>\
									<%}%>\
							<%}%>\
							<div class="audit-list audit-list-long">\
								<div class="audit-item">\
									<div class="item-tip">开关负责人:</div>\
									<div class="item-con"><%=switchUser%></div>\
								</div>\
								<div class="audit-item">\
									<div class="item-tip">联系电话:</div>\
									<div class="item-con"><%=switchTel%></div>\
								</div>\
							</div>\
							<%if(status==33 || status==35 ){%>\
								<div class="audit-list audit-list-long">\
									<div class="audit-item">\
										<div class="item-tip">取消时间:</div>\
										<div class="item-con"><%=cancelTime%></div>\
									</div>\
									<div class="audit-item">\
										<div class="item-tip">取消操作人:</div>\
										<div class="item-con"><%=cancelUser%></div>\
									</div>\
									<div class="audit-item">\
										<div class="item-tip">取消原因:</div>\
										<div class="item-con"><%=cancelReason%></div>\
									</div>\
								</div>\
				  			<%}%>\
						</div>\
					</div>\
				</div>\
			</div>	',
			"cancelTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-cancel-con">\
					<div class="title-wp">\
						<span>空调加时取消</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-audit-wp">\
						<div class="cancel-con">\
							<div class="audit-suggest">\
								<div class="suggest-title">取消原因:</div>\
								<textarea class="suggest-text cancel-reason" placeholder="请输入取消原因"></textarea>\
							</div>\
						</div>\
						<div class="dialog-btm">\
							<button class="cancel-cel-btn btn-white">取消</button>\
							<button class="sure-cel-btn btn-red">保存</button>\
						</div>\
					</div>\
				</div>\
			</div>	'
	}
	template.config("escape", false);
	var contextPath =  $("#contextPath").val();
	var table;
	var appSend = {
			init: function(){
				this.render();
				this.bindEvent();
			},
			render: function(){
				this.rendertable();
				
			},
			bindEvent: function(){
				var _this = this;
				layui.use('laydate', function(){
					  var laydate = layui.laydate;
					  
					  //执行一个laydate实例
					  laydate.render({
					    elem: '#startTime' //提交开始时间
				    	
					  });
					  laydate.render({
						    elem: '#endTime' //提交结束时间
					  });
					
					});
				//重置
				$(".set-btn").on("click",function(){
					$("#conditionform input,#conditionform select").val("");
					
					 _this.againRenderTable();
				})
			},
			rendertable: function(){
				var _this = this;
				layui.use('table', function(){
					   table = layui.table;
					  
					  //方法级渲染
					  table.render({
					    elem: '#LAY_table_user'
					    ,url:contextPath + "/air/list"
					    ,skin: 'nob' //行边框风格
				    		  ,even: true //开启隔行背景
				    		  ,size: 'lg' //小尺寸的表格
					    ,cols: [[
					      {
//				    		   field:'billId', 
//				    		   title: 'ID', 
//				    		   minWidth:80
//				    	  },{
				    		  field:'code',
				    		  title: '订单号',
				    		  minWidth:200
			    		  },{
			    			  field:'virtualName', 
			    			  title: '企业名称', 
			    			  minWidth:200
//		    			  },{
//		    				  field:'fullName', 
//		    				  title: '企业账号', 
//		    				  width:120
	    				  },{
		    				  field:'roomNames', 
		    				  title: '房间号', 
		    				  minWidth:200
	    				  },{
		    				  field:'applyArea', 
		    				  title: '面积（m²）', 
		    				  minWidth:140
	    				  },{
		    				  field:'useDisplayTime', 
		    				  title: '使用时间', 
		    				  minWidth:250
	    				  },{
		    				  field:'useLengthTime', 
		    				  title: '使用时长（小时）', 
		    				  minWidth:180
	    				  },{
		    				  field:'priceDisplay', 
		    				  title: '单价', 
		    				  minWidth:200
	    				  },{
		    				  field:'freeTotal', 
		    				  title: '总价（元）', 
		    				  minWidth:120
	    				  },{
		    				  field:'applyUser', 
		    				  title: '申请人', 
		    				  minWidth:120
	    				  },{
		    				  field:'applyTime', 
		    				  title: '申请时间', 
		    				  minWidth:200
	    				  },{
		    				  field:'billSource', 
		    				  title: '订单来源', 
		    				  minWidth:200,
		    				  templet: function(data){
	    						  if(data.billSource == 1){
	    							  return "空调加时"
	    						  }else if(data.billSource == 2){
	    							  return '预定会议室'
	    						  }
	    					  }
	    				  },{
	    					  field:'billStatus', 
	    					  title: '状态',
	    					  minWidth: 200,
	    					  templet: function(data){
	    						  //\待客服专员审核21\待客服主管审核22\待工程主管审核23\待使用31\已使用32\已取消33\已拒绝34\无效35
	    						  if(data.billStatus == 21){
	    							  return "待审核（客服专员）"
	    						  }else if(data.billStatus == 22){
	    							  return "待审核（客服主管）"
	    						  }else if(data.billStatus == 23){
	    							  return "待审核（工程主管）"
	    						  }else if(data.billStatus == 31){
	    							  return "待使用"
	    						  }else if(data.billStatus == 32){
	    							  return "已使用"
	    						  }else if(data.billStatus == 33){
	    							  return "已取消"
	    						  }else if(data.billStatus == 34){
	    							  return "已拒绝"
	    						  }else if(data.billStatus == 35){
	    							  return "无效"
	    						  }else{
	    							  return ''
	    						  }
	    					  }
	    				  },{
	    					  field:'approval_user', 
	    					  title: '查看详情', 
	    					  minWidth:120,
	    					  templet: function(data){
		    						 return "<span data-id="+data.billId+" class='check-blue-btn check-detail'>详情<span>"
	    					  }
	  					  },{
							  field:'id', 
							  title: '操作', 
							  fixed: "right",
							  minWidth: 150,
							  templet: function(data){
								  var str = '';
								  if(data.billStatus == 21){
	    							  str+= "<span data-id="+data.billId+" data-status="+data.billStatus+" class='check-blue-btn audit-btn'>客服专员审核</span>"
	    						  }else if(data.billStatus == 22){
	    							  str+= "<span data-id="+data.billId+" data-status="+data.billStatus+" class='check-blue-btn audit-btn'>客服主管审核</span>"
	    						  }else if(data.billStatus == 23){
	    							  str+= "<span data-id="+data.billId+" data-status="+data.billStatus+" class='check-blue-btn audit-btn'>工程主管审核</span>"
	    						  };
	    						  if(data.billStatus == 31){
	    							  str+= "<span data-id="+data.billId+" data-status="+data.billStatus+" class='red cancel-btn'>取消</span>"
	    						  };
	    						 
	    						 return str;
	    					  }
						  }
						  ]]
						    ,id: 'testReload'
						    ,page: true,
						    method: 'post',
						    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即为你接口返回的信息。
						    	//审核
						        $(".audit-btn").on("click",function(){
						        	var id = $(this).data("id");
						        	var status = $(this).data("status")
						        	//显示审核弹窗
						        	_this.showAuditDialog(id,status)
						        });
						        //详情
						        $(".check-detail").on("click",function(){
						        	var id = $(this).data("id");
						        	
						        	//显示详情弹窗
						        	_this.showDetailDialog(id)
						        });
						        //取消
						        $(".cancel-btn").on("click",function(){
						        	var id = $(this).data("id");
						        	var status = $(this).data("status")
						        	//显示取消弹窗
						        	_this.showCancelDialog(id,status)
						        })
						      }
					  });
					  //查询
					  $('#conditionform  .search-btn').on('click', function(){
						  
						  _this.againRenderTable();
					  });
					});
			},
			/*重新渲染table*/
			againRenderTable: function(){
				table.reload('testReload', {
					where: {
						code: $("#conditionform .code").val(),
						companyName: $("#conditionform .companyName").val(),
						endTime: $("#conditionform #endTime").val(),
						startTime: $("#conditionform #startTime").val(),
						status: $("#conditionform .status").val(),
					} ,
					  page: {
					    curr: 1 //重新从第 1 页开始
					  }
				}); 
			},
			/**
			 * 显示审核弹窗
			 * @param id 单id
			 * @param status 单状态  //\待客服专员审核21\待客服主管审核22\待工程主管审核23\待使用31\已使用32\已取消33\已拒绝34\无效35
			 */
			showAuditDialog: function(id,status){
				var _this = this;
				_this.ajaxDetail(id,function(data){
					if(status==23){
						_this.ajaxPersons(function(persons){
							data.persons = persons;
							$("body").append(template.render(tpl.auditTpl)(data));
							// 空调加时审批 同意或不同意申请
							$(".dialog-wp .sure-add-btn").on("click",function(){
								var $this = $(this);
								$this.attr("disabled",true);
								_this.auditAjax(id,status,function(){
									_this.againRenderTable();
									$this.attr("disabled",false);
									$(".dialog-wp").remove();
								});
							});
							
							//关闭弹窗
							$(".close-btn,.dialog-wp .cancel-add-btn ").on("click",function(){
								$(".dialog-wp").remove();
							});
							//审核意见
							$(".audit-reason-wp .radio-wp").on("click",function(){
								var auditResult = $(".radio-wp .radio-item[name='result']:checked").data("status");
								if(auditResult ==1){
									$(".suggest-text").val("同意")
								}else{
									$(".suggest-text").val("")
								};
							})
						});	
					}else{
						$("body").append(template.render(tpl.auditTpl)(data));
						//关闭弹窗
						$(".close-btn,.dialog-wp .cancel-add-btn ").on("click",function(){
							$(".dialog-wp").remove();
						});
						// 空调加时审批 同意或不同意申请
						$(".dialog-wp .sure-add-btn").on("click",function(){
							var $this = $(this);
							$this.attr("disabled",true);
							_this.auditAjax(id,status,function(){
								_this.againRenderTable();
								$this.attr("disabled",false);
								$(".dialog-wp").remove();
							});
						})
						//审核意见
							$(".audit-reason-wp .radio-wp").on("click",function(){
								var auditResult = $(".radio-wp .radio-item[name='result']:checked").data("status");
								if(auditResult ==1){
									$(".suggest-text").val("同意")
								}else{
									$(".suggest-text").val("")
								};
							})
					}
					
			    	
				})
			},
			/**
			 * 显示详情弹窗
			 * @param id
			 */
			showDetailDialog: function(id){
				var _this = this;
				_this.ajaxDetail(id,function(data){
					
					$("body").append(template.render(tpl.detailTpl)(data));
			    	//关闭弹窗
					$(".close-btn").on("click",function(){
						$(".dialog-wp").remove();
					})
				})
				
			},
			ajaxDetail: function(id,callback){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: contextPath+ "/air/getDetail", 
					   data: {
						   "id": id
					   },
					   success: function(data){
						   if(data.code == 200){
							   callback(data.data);
						   }else{
							   layer.msg(data.msg)
						   }   
					   },
					   error: function(error){   
						   layer.msg('error')
					   }
			   });
			},
			/**
			 * 获取空调加时指定开关空调人员
			 *
			 */
			ajaxPersons: function(callback){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: contextPath+ "/air/getAirSwitchUser", 
					   success: function(data){
						   if(data.code == 200){
							   callback(data.data);
						   }else{
							   layer.msg(data.msg)
						   }   
					   },
					   error: function(error){   
						   layer.msg('error')
					   }
			   });
			},
			/**
			 * 空调加时审批 同意或不同意申请
			 * @param id
			 * @param status 状态 //\待客服专员审核21\待客服主管审核22\待工程主管审核23\待使用31\已使用32\已取消33\已拒绝34\无效35
			  * @param callback 刷新列表回调
			 */
			auditAjax: function(id,status,callback){
				var _this = this;
				var result = {
						billId: id,//单据ID
						currentBillStatus: status,//当前单据状态 防止重复提交
						auditResult: '',
						auditOpinion: '',
						switchUserId: ''
					}
				//审核结果 0不同意 1 同意
				var auditResult = $(".radio-wp .radio-item[name='result']:checked").data("status");
				if(auditResult!=1 && auditResult !=0){
					layer.msg('请勾选审核结果！');
					return false;
				};
				result['auditResult'] = auditResult;
				//空调开关人员ID
				var switchUserId = $(".radio-wp .radio-item[name='person']:checked").data("id");
				if(status==23){
					if(!switchUserId){
						layer.msg('请选择空调开关人员！');
						return false;
					}
				}
				result['switchUserId'] = !!switchUserId ? switchUserId : '';
				//审核意见
				var auditOpinion = $(".suggest-text").val();
				if(!auditOpinion){
					layer.msg('请输入审核意见！');
					return false;
				};
				result['auditOpinion'] = auditOpinion;
				
				$.ajax({
					   type: "post",
					   url: contextPath+ "/air/audit", 
					   data:result,
					   success: function(data){
						   if(data.code == 200){
							   callback();
						   }else{
							   layer.msg(data.msg)
						   }   
					   },
					   error: function(error){   
						   layer.msg('error')
					   }
			   });
			},
			/**
			 * 空调加时取消
			 * @param id
			 * @param status 状态 //\待客服专员审核21\待客服主管审核22\待工程主管审核23\待使用31\已使用32\已取消33\已拒绝34\无效35
			 */
			showCancelDialog: function(id,status){
				var _this = this;
				$("body").append(template.render(tpl.cancelTpl));
		    	//关闭弹窗
				$(".close-btn ,.dialog-wp .cancel-cel-btn").on("click",function(){
					$(".dialog-wp").remove();
				});
				// 确定取消
				$(".dialog-wp .sure-cel-btn").on("click",function(){
					var $this = $(this);
					$this.attr("disabled",true)
					_this.cancelAjax(id,status,function(){
						
						_this.againRenderTable();
						$this.attr("disabled",false)
						$(".dialog-wp").remove();
					});
				})
				
			},
			/**
			 * 空调加时取消
			 * @param id
			 * @param status 状态 //\待客服专员审核21\待客服主管审核22\待工程主管审核23\待使用31\已使用32\已取消33\已拒绝34\无效35
			 * @param callback 刷新列表回调
			 */
			cancelAjax: function(id,status,callback){
				var _this = this;
				var result = {
						billId: id,//单据ID
						currentBillStatus: status,//当前单据状态 防止重复提交
						cancelReason: ''
					}
				//取消原因
				var cancelReason = $(".cancel-reason").val();
				if(!cancelReason){
					layer.msg('请输入取消原因！');
					return false;
				};
				result['cancelReason'] = cancelReason;
				
				$.ajax({
					   type: "post",
					   url: contextPath+ "/air/cancel", 
					   data:result,
					   success: function(data){
						   if(data.code == 200){
							   callback();
						   }else{
							   layer.msg(data.msg)
						   }   
					   },
					   error: function(error){   
						   layer.msg('error')
					   }
			   });
			}
	};
	appSend.init();
})