var permApprove = $("#perm-approve").val();//审核权限

/**
 * 维修订单详情
 * 2018/5/7 by liufang
 */
$(function(){
	var layer;
	var projectIsPersion;
	var dataList=[]
	var ERROR_OK = 200;
	var form = layui.form
	layui.use('layer', function(){
		   layer = layui.layer;  
	}); 
	var contextPath = $("#contextPath").val();
	var tpl = {
			"detailTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-detail-con">\
					<div class="title-wp">\
						<span>维修单编号：<%=baseDto.code %>\
						<% if(baseDto.status==1){%>\
							（待审核）\
						<%}else if(baseDto.status==2){%>\
							(可抢单)\
						<%}else if(baseDto.status==3){%>\
							(进行中)\
						<%}else if(baseDto.status==4){%>\
							(挂单中)\
						<%}else if(baseDto.status==5){%>\
							(转单中)\
						<%}else if(baseDto.status==8){%>\
							(已完成)\
						<%}else if(baseDto.status==22){%>\
							(待派单)\
						<%}else if(baseDto.status==10){%>\
							（已取消）\
						<%} %>\
						</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-detail-wp">\
						<div class="dialog-detail-header">\
							<div class="detail-top clearfloat">\
								<div class="detail-top-item clearfloat">\
									<span class="tips">报修人：</span>\
									<span class="top-item-value"><%=baseDto.repairUser %></span>\
								</div>\
								<div class="detail-top-item clearfloat">\
									<span class="tips">报修方式：</span>\
									<span class="top-item-value"><%=baseDto.repairWayName %></span>\
								</div>\
								<div class="detail-top-item clearfloat">\
									<span class="tips">报修人手机：</span>\
									<span class="top-item-value"><%=baseDto.contactWay %></span>\
								</div>\
								<div class="detail-top-item clearfloat">\
									<span class="tips">维修区域：</span>\
									<span class="top-item-value"><%=baseDto.repairAreaName %></span>\
								</div>\
								<div class="detail-top-item clearfloat">\
									<span class="tips">地址：</span>\
									<span class="top-item-value"><%=baseDto.address %></span>\
								</div>\
								<div class="detail-top-item clearfloat">\
									<span class="tips">维修类型：</span>\
									<span class="top-item-value"><%=baseDto.repairTypeName %></span>\
								</div>\
								\
								<div class="detail-top-item clearfloat">\
									<span class="tips">维修人：</span>\
									<span class="top-item-value"><%=detailDto.serverUser %></span>\
								</div>\
								<% if(baseDto.status==8){%>\
								<div class="detail-top-item clearfloat">\
									<span class="tips">维修费用：</span>\
									<span class="top-item-value"><%=detailDto.repairCost %></span>\
								</div>\
								<%}%>\
								<div class="detail-top-item clearfloat">\
									<span class="tips">协办人：</span>\
									<span class="top-item-value"><%=detailDto.supportUserNames %></span>\
								</div>\
								<div class="detail-top-item clearfloat">\
									<span class="tips">维修耗材：</span>\
									<span class="top-item-value"><%=detailDto.materialName %></span>\
								</div>\
							</div>\
							<div class="detail-middle">\
								<div class="repair-descript">报修描述：<%=baseDto.description %></div>\
								<div class="repair-img-list clearfloat">\
								<% if(!!baseDto.picUrl){%>\
									<% var imgList = baseDto.picUrl.split(";")%>\
									<%for(var i=0;i<imgList.length;i++){%>	\
										<div class="repair-img-item " >\
											<img src="<%=imgList[i]%>" class="img" />\
										</div>\
									<%}%>	\
							    <%} %>		\
								</div>\
							</div>\
							<div class="detail-btm clearfloat">\
								<div class="tips">订单状态:</div>\
								<% if(!!operateDto && operateDto.length>0){%>\
									<%if( operateDto.length == 1){%>\
										<div class="order-status-1"><%=operateDto[0].operateTime%>&nbsp;&nbsp;<%=operateDto[0].operateDescription%></div>\
									<%}else{%>\
										<ul class="layui-timeline">\
										<% for(var m=0;m<operateDto.length;m++){%>\
										  <li class="layui-timeline-item">\
										    <i class="layui-icon layui-timeline-axis">&#xe63f;</i>\
										    <div class="layui-timeline-content layui-text">\
										      <h3 class="layui-timeline-title clearfloat">\
												<span class="date"><%=operateDto[m].operateTime%></span>\
												\
												<span class="con"><%=operateDto[m].operateDescription%></span>\
											 </h3>\
											</div>\
										  </li>\
										<%}%>\
										</ul>\
								   <%} %>	\
								<%}%>\
							</div>\
							<% if(baseDto.status==8){%>\
								<div class="user-grade-wp">\
									<div class="user-grade-top clearfloat">\
										<span class="tips">评星等级：</span>\
										<%if(!!detailDto.star){%>\
											<%for(var j=0;j<detailDto.star;j++){%>\
												<span class="star active"></span>\
											<%}%>\
											<% for(var k=detailDto.star;k<5;k++){%>\
												<span class="star"></span>\
											<%}%>\
										<%}else{%>\
											<%for(var j=0;j<5;j++){%>\
												<span class="star"></span>\
											<%}%>\
										<%}%>	\
									</div>\
									<div class="user-grade-btm clearfloat">\
										<span class="tips">客户评价：</span>\
										<span class="con"><%=detailDto.serviceImpression%></span>\
									</div>\
								</div>\
						  <% }%>	\
					   </div>\
						<div class="dialog-detial-footer">\
							<% if(baseDto.status==1){%>\
								<div class="detail-operate-btn">\
									<button class="btn-white detail-reject-btn">拒绝</button>\
									<button class="btn-red detail-pass-btn">通过</button>\
								</div>\
							<% } %>\
							<% if(baseDto.status==2 || baseDto.status==3 || baseDto.status==4){%>\
							<div class="detail-operate-btn">\
								<button class="btn-red send-order">派单</button>\
							</div>\
							<%} %>\
						</div>\
				   </div>		\
				</div>\
			</div>	',
			"choosePersonTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-choose-con">\
					<div class="title-wp">\
						<span>选择派单对象</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-choose-wp">\
						<div class="choose-person-wp clearfloat">\
							<div class="choose-person-right">\
								<h3 class="title">工程人员</h3>\
								<div class="person-list clearfloat">\
									<% for(var i=0;i<data.length;i++){%>\
									<div class="person-item">\
										<div class="radio-wp" >\
											<span class="radio-input" style="display:none">\
												<input type="radio" id="outdate-<%=i%>"  class="radio-item" name="date" data-id="<%=data[i].id%>" <%if(i==0){%> checked <%}%>/>\
												<span class="radio-inner"></span>\
											</span>		\
				                    <% if(data[i].repairpass==1){%>\
											<span class="radio-input">\
												<input type="checkbox" id="outdate-<%=i%>"  class="radio-item" name="dataRepair" value="<%=data[i].id%>"  data-id="<%=data[i].id%>" />\
				 								<span class="radio-inner"></span>\
											</span>		\
										<label class="radio-con" for="outdate-<%=i%>"><%=data[i].name%>&nbsp;(<%=data[i].repaircount%>单)</label>\
									<% } %>\
									<% if(data[i].repairpass<1){%>\
									<span class="radio-input">\
										<input type="checkbox"  disabled id="outdate-<%=i%>"  class="radio-item" name="dataRepair" value="<%=data[i].id%>"  data-id="<%=data[i].id%>" />\
											<span class="radio-inner"></span>\
									</span>		\
								<label class="radio-con"  style="color:#CCCCCC" for="outdate-<%=i%>"><%=data[i].name%>&nbsp;(<%=data[i].repaircount%>单)</label>\
							        <% } %>\
										</div>\
									</div>\
									<%}%>\
								</div>\
							</div>\
						</div>\
						<div class="choose-person-btns">\
							<button class="btn-red choose-perosn-btn">确认</button>\
						</div>\
					</div>\
				</div>\
			</div>	',
	};
	var layer;
	var table;
	layui.use('layer', function(){
		   layer = layui.layer;  
	}); 
	
	var operateSetting={
		    //通过校区id 获取已经配置信息
			getConfigInfo:function (id) {
				var _this = this;
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/getconfigbyorg", 
					   data: {
						   "org_id": id,
					   },
					   success: function(data){
						   if(data.code == '200'){
//							   console.log("获取配置数据",data);
							   if(data.data&&data.data!=null){
								   let resultData=data.data
								   _this.projectMaxBills=resultData.max_bills
//								   console.log("projectMaxBills", _this.projectMaxBills)
								   $("#amontNum").val(resultData.max_bills)
								   //1-抢单模式 2-派单模式
								   if(resultData.repair_type=='1'){//抢单模式
									   _this.qiangdanMode();
								   }else if(resultData.repair_type=='2'){//派单模式
									   _this.paidanMode();
								   }
								   
								   //是否一单多人1-开启 2-不开启
								   if(resultData.repair_type=='1'){//抢单
									   $(".onePersonType").hide()
									   $("#TypePersion").prop("checked", false); 
								   }else{
									   if(resultData.ispersons=='1'){//开启
										   $("#TypePersion").prop("checked", true);  
									   }else if(resultData.ispersons=='2'){//关闭
										   $("#TypePersion").prop("checked", false);
									   }  
								   }
								   
								   //1-收款 2-不收款
								   if(resultData.ispay=='1'){//收费模式
									   _this.shoufeiMode();
								   }else if(resultData.ispay=='2'){//不收费模式
									   _this.bushoufeiMode();
								   }
							            layui.form.render();
							            $(".form_alert .layui-form-radio").eq(0).on("click",function (){
							    	    	 $(".onePersonType").hide()
							    	    	
							    	    });
							    	    //派单模式
							    	    $(".form_alert .layui-form-radio").eq(1).on("click",function (){
							    	    	 $(".onePersonType").show();
							    	    	 $('.form_alert   input:checkbox[name="openPersion"]').eq(0).attr("checked",false);
							    	    });
							       }else{
									$("#amontNum").val("3")
								 	//模式 --默认是抢单模式
								    _this.qiangdanMode()
						            $(".onePersonType").hide()
						             $("#TypePersion").prop("checked", false);
						            //收费模式 默认不收费
						            _this.bushoufeiMode();
						           
						            layui.form.render();
						            $(".form_alert .layui-form-radio").eq(0).on("click",function (){
						    	    	 $(".onePersonType").hide()
						    	    });
						    	    //派单模式
						    	    $(".form_alert .layui-form-radio").eq(1).on("click",function (){
						    	    	 $(".onePersonType").show();
						    	    	 $('.form_alert   input:checkbox[name="openPersion"]').eq(0).attr("checked",false);
						    	    });
							   }
						   }else{
							   //layer.msg(data.msg)
						   }   
					   },
					   error: function(error){  
						   layer.msg('error')
					   }
			   });
			},
			//抢单模式
			qiangdanMode:function(){
				$('.form_alert   input:radio[name="mode-type"]').eq(1).attr("checked",'checked');
	    	    $('.form_alert   input:radio[name="mode-type"]').eq(1).attr("checked",true);
	    	    $("input[name=mode-type][value=0]").prop("checked","true");
	            $("input[name=mode-type][value=1]").prop("checked","false");
	            
			},
			//派单模式
			paidanMode:function(){
				    $('.form_alert   input:radio[name="mode-type"]').eq(0).attr("checked",'checked');
		    	    $('.form_alert   input:radio[name="mode-type"]').eq(0).attr("checked",true);
		    	    $("input[name=mode-type][value=1]").prop("checked","true");
		            $("input[name=mode-type][value=0]").prop("checked","false");
		            $(".onePersonType").show()
			},
			//收费
			shoufeiMode:function(){
				 $('.form_alert   input:radio[name="collention_type"]').eq(1).attr("checked",'checked');
		    	    $('.form_alert   input:radio[name="collention_type"]').eq(1).attr("checked",true);
		    	    $("input[name=collention_type][value=0]").prop("checked","false");
		            $("input[name=collention_type][value=1]").prop("checked","true");
			},
			//不收费
			bushoufeiMode:function(){
				   $('.form_alert   input:radio[name="collention_type"]').eq(0).attr("checked",'checked');
		    	    $('.form_alert   input:radio[name="collention_type"]').eq(0).attr("checked",true);
		    	    $("input[name=collention_type][value=1]").prop("checked","false");
		            $("input[name=collention_type][value=0]").prop("checked","true");	
			},
			
		}
	var launchRepair = {
			init: function(){
				this.render();
				this.bindEvent();
			},
			render: function(){
				var _this = this;
				_this.renderTable();
//				$("body").append(template.render(tpl.detailTpl));
//				$(".close-btn").on("click",function(){
//					$(".dialog-wp").remove();
//				});
//				//回访编辑
//				$(".evalu-edit-btn").on("click",function(){
//					_this.showVisitDialog();
//				})
			},
			bindEvent: function(){
				var _this = this;
				
				//查询
				$("#conditionform input[type='text']").on("keydown",function(event){
					if(event.keyCode == 13){
						$("#conditionform .search-btn").click();
					}
				});
				layui.use('laydate', function(){
					  var laydate = layui.laydate;
					  
					  //执行一个laydate实例
					  laydate.render({
					    elem: '#c_startTime' //提交开始时间
				    	
					  });
					  laydate.render({
						    elem: '#c_endTime' //提交结束时间
					   
						  })
					});
//				
				//重置
				$(".set-btn").on("click",function(){
					$("#conditionform select,#conditionform input").val("");
					$("#conditionform select").val("");
					_this.againRenderTable({type:1});
				});
				//功能配置
				$(".function-btn").on("click",function(){
				 	$('.alert').css('display', 'block');
				 	var chooseOrgId= $("#organizationId").attr('org__id')
				 	operateSetting.getConfigInfo(chooseOrgId);
				 	console.log("第一次的校区id",chooseOrgId)
//				 	$("#amontNum").val("3")
//				 	//模式 --默认是抢单模式
//				 	 $('.form_alert   input:radio[name="mode-type"]').eq(1).attr("checked",'checked');
//		    	    $('.form_alert   input:radio[name="mode-type"]').eq(1).attr("checked",true);
//		    	    $("input[name=mode-type][value=0]").prop("checked","true");
//		            $("input[name=mode-type][value=1]").prop("checked","false");
//		            $(".onePersonType").hide()
//		            $('.form_alert   input:checkbox[name="openPersion"]').eq(0).attr("checked",false);
//		            //收费模式 默认不收费
//		            $('.form_alert   input:radio[name="collention_type"]').eq(0).attr("checked",'checked');
//		    	    $('.form_alert   input:radio[name="collention_type"]').eq(0).attr("checked",true);
//		    	    $("input[name=collention_type][value=1]").prop("checked","false");
//		            $("input[name=collention_type][value=0]").prop("checked","true");
//		            layui.form.render();
		            //模式
		          //抢单模式
		    	    $(".form_alert .layui-form-radio").eq(0).on("click",function (){
		    	    	 $(".onePersonType").hide()
		    	    	
		    	    });
		    	    //派单模式
		    	    $(".form_alert .layui-form-radio").eq(1).on("click",function (){
		    	    	 $(".onePersonType").show();
		    	    	 $('.form_alert   input:checkbox[name="openPersion"]').eq(0).attr("checked",false);
		    	    });
				});
				//功能配置-对话框确定
				$(".dialogSaveBtn").on("click",function(){
					let newModeType,newPayType,newPsersion;
					var modeType=$('input:radio[name="mode-type"]:checked').val();
					var payType=$('input:radio[name="collention_type"]:checked').val();
					  var newPsersionss= $("#TypePersion").prop("checked");
					 console.log("modeType模式",modeType)
					 console.log("payType收款功能",payType)
					  console.log("newPsersion1",newPsersionss)
					            
					 if(modeType==0){//派单
						 newModeType="2"
					 }else{//抢单
						 newModeType="1"
					 }
					 if(payType==0){//关闭
						 newPayType="2"
					 }else{
						 newPayType="1"
					 }
					 if(newModeType=='1'){//抢单模式 ，不存在一单多人情况
						 if(newPsersionss){//不开启
							 newPsersion='2'
						 }else{//关闭
							 newPsersion='2'
						 } 
					 }else{
						 if(newPsersionss){//开启
							 newPsersion='1'
						 }else{//关闭
							 newPsersion='2'
						 }  
					 }
					    let data = {
					    	  org_id: $('#organizationId').attr('org__id'),
					    	  max_bills: $('input[name="amount"]').val(),
					    	  repair_type: newModeType,
					    	  ispersons: newPsersion,
					    	  ispay: newPayType,
			    	  			}
					 _this.saveDataInfo(data);
				});
				//功能配置-对话框取消
				$(".dialogCancelBtn").on("click",function(){
				 	$('.alert').css('display', 'none');
				});
				$(".close-btn").on("click",function(){
				 	$('.alert').css('display', 'none');
				});
				
				$('input#amontNum').keyup(function(){
					   var c=$(this);
					   if(/[^\d]/.test(c.val())){//替换非数字字符
					    var temp_amount=c.val().replace(/[^\d]/g,'');
					    $(this).val(temp_amount);
					   }
					   });
				
				
				// 模糊搜索
				_this.search_fuzzy()
				_this.serach_project()
				
			},
			renderTable: function(){
				var _this = this;
				layui.use('table', function(){
					  table = layui.table;
					  
					  //方法级渲染
					  table.render({
					    elem: '#LAY_table_user',
					    method: 'post'
					    	 ,skin: 'nob' //行边框风格
					    		  ,even: true //开启隔行背景
					    		  ,size: 'lg' //小尺寸的表格
					    ,url: $("#contextPath").val()+ "/repairBill/list"
					    ,cols: [[
						  {

							  title: '序号',
							  templet: '#indexTpl',
							  width: 80
						  } ,{
				    		   field:'code', 
				    		   title: '维修单编号', 
				    		   minWidth:200
				    	  },{
				    		   field:'org_name', 
				    		   title: '校区名称', 
				    		   minWidth:200
				    	  },{
				    		  field:'repairUser',
				    		  title: '报修人',
				    		  minWidth:200
			    		  },{
			    			  field:'contactWay', 
			    			  title: '报修人手机', 
			    			  width:180
		    			  },{
		    				  field:'createTime', 
		    				  title: '报修时间', 
		    				  minWidth:200
		  				  },{
		  					  field:'repairWayName', 
		  					  title: '报修方式',
		  					 minWidth:100				 
		  				  },{
		  					  field:'repairAreaName', 
		  					  title: '维修区域',
		  					 minWidth:150
		  					 
						  },{
							  field:'repairTypeName', 
							  title: '维修类型',
							  minWidth:150
							
						  },{
							  field:'meetingTime', 
							  title: '上门时间',
							  minWidth:200,
							  templet: function(data){
								  if(data.meetingTime){
									  return data.meetingTime
								  }else{
									  return '立即上门'
								  }
							  }
							
						  },{
		  					  field:'status', 
		  					  title: '订单状态', 
		  					 width: 120,
		  					  templet: function(data){
		  						  if(data.status==1){
		  							  return '待审核'
		  						  }else if(data.status==2){
		  							  return '可抢单'
		  						  }else if(data.status ==3){
		  							  return '进行中'
		  						  }else if(data.status==4){
		  							  return '挂单中'
		  						  }else if(data.status==5){
		  							  return '转单中'
		  						  }else if(data.status==8){
		  							  return '已完成'
		  						  }else if(data.status==10){
		  							  return '已取消'
		  						  }else if(data.status==22){
		  							  return '待派单'
		  						  }
		  					  }
						  },{
		  					  field:'id', 
		  					  title: '订单详情', 
		  					 width: 120,
		  					  templet: function(data){
		  						return "<span data-id="+data.id+" data-status= "+data.status+" class='check-blue-btn'>查看详情<span>"
		  					  }
						  },{
							  field:'id', 
							  title: '操作', 
							  width: 150,
							  fixed: 'right', 
							  templet: function(data){
								  var str = '';
								  if (permApprove == 1){
                                      if(data.status == 1){
                                          str += '<button class="t-btn t-red-btn t-publish-btn" data-id='+data.id+' data-type="1">通过</button>';
                                          str += '<button class="t-btn t-white-btn t-reject-btn" data-id='+data.id+' data-type="2">拒绝</button>';
                                      }else if(data.status == 2 || data.status == 3 || data.status == 4||data.status==22){
                                          str += '<button class="t-btn t-red-btn t-send-btn" data-id='+data.id+' >派单</button>';
                                      }
								  }
								    
								  return str;
							  }
						  }
						  ]]
						    ,id: 'testReload'
						    ,page: true,
						    response: {
						    	  statusName: 'code' //数据状态的字段名称，默认：code
						    	  ,statusCode: 200 //成功的状态码，默认：0
						    	  ,countName: "count"//数据总数的字段名称，默认：count
						    	  ,dataName: "data" //数据列表的字段名称，默认：data
						    	}   ,
						    	 where: {
										orgId: $("#conditionform  #orgId").attr('org__id'),
									},
						    done: function(res, curr, count){
						    	dataList=res.data
//						    	console.log('dataList',dataList);
						    	
						        //如果是异步请求数据方式，res即为你接口返回的信息。
						        $(".check-blue-btn").on("click",function(){
						        	var id = $(this).data("id")
						        	var status = $(this).data("status")
						        	//查看订单详情
						        	_this.ajaxDetail(id,status);	
						        });
						        //拒绝
						        $(".t-reject-btn").on("click",function(){
						        	var id = $(this).data("id");
						        	var type = $(this).data("type");
						        	_this.ajaxPass(type,id);
						        });
						        //通过
						        $(".t-publish-btn").on("click",function(){
						        	var id = $(this).data("id");
						        	var type = $(this).data("type");
						        	_this.ajaxPass(type,id);
						        });
						        //派单
						        $(".t-send-btn").on("click",function(){
						        	var id = $(this).data("id");
						        	for (var i = 0; i < dataList.length; i++) {
						        		if(id==dataList[i].id){
						        			var orgId = dataList[i].orgId
											_this.getMaxIdByOrg(orgId)	
						        		}
										
									}
						        	_this.showChoosePersonDialog(id);
						        })
						      }
					  });
					  //查询
					  $('#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: { //设定异步数据接口的额外参数，任意设
							  orgId:  $orgId.length?orgId:'',
							  status: $(".repair-status").val(),
						    	startTime: $("#c_startTime").val(),
					  			endTime: $("#c_endTime").val(),
					  			repairWay: $(".select-repair-way").val(),
					  			repairArea: $(".select-repair-place").val(),
					  			repairType: $(".select-repair-type").val(),
					  			code: $(".repair-code").val()
						  }
						  ,page: {
						    curr: 1 //重新从第 1 页开始
						  }
					}); 
				}else{
					table.reload('testReload', {
						  where: { //设定异步数据接口的额外参数，任意设
							  orgId: orgId,
							  status: $(".repair-status").val(),
						    	startTime: $("#c_startTime").val(),
					  			endTime: $("#c_endTime").val(),
					  			repairWay: $(".select-repair-way").val(),
					  			repairArea: $(".select-repair-place").val(),
					  			repairType: $(".select-repair-type").val(),
					  			code: $(".repair-code").val()
						  }
						  ,page: {
						    curr: 1 //重新从第 1 页开始
						  }
					}); 
				}
				
			},
			//保存数据
			saveDataInfo:function(data){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/configsave", 
					   data: {
						   "org_id": data.org_id,
						   "max_bills": data.max_bills,
						   "repair_type": data.repair_type,
						   "ispersons": data.ispersons,
						   "ispay": data.ispay,
					   },
					   success: function(data){
						   if(data.code == '200'){
							 layer.msg('配置成功！');
							 $('.alert').css('display', 'none');
							  _this.againRenderTable()
						   }else{
							   layer.msg(data.msg)
						   }   
					   },
					   error: function(error){  
						   layer.msg('error')
					   }
			   });
			},
			getMaxIdByOrg:function(id){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/getconfigbyorg", 
					   data: {
						   "org_id": id,
					   },
					   success: function(data){
						   if(data.code == '200'){
							   console.log("获取配置数据",data);
							   if(data.data&&data.data!=null){
								   let resultData=data.data
								   if(resultData.repair_type=='1'){//抢单模式
									   _this.projectIsPersion='2'  
								   }else{
									   if(resultData.ispersons=='1'){//开启多人
										   _this.projectIsPersion='1'
									   }else{//关闭多人
										   _this.projectIsPersion='2' 
									   }   
								    }
							       }else{//默认关闭
							    	   _this.projectIsPersion='2'    
							   }
						   }else{
							   //layer.msg(data.msg)
						   }   
					   },
					   error: function(error){  
						   layer.msg('error')
					   }
			   });
			},
			// 模糊搜索事件
			serach_project: function(){
				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#organizationId',
					com_target:'.default-select#companyId',
					dep_target:'.default-select#departmentId',
				});
				var option_2 = $.extend(true,{},default_option,{
					org_target:'.item-select.organ-id',
				});

				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)
						var chooseId= $("#organizationId").attr('org__id')
						console.log('选择之后的校区id',chooseId)
						operateSetting.getConfigInfo(chooseId);
					});

				}
				// 搜索联动
				eve(option_1,{type:1})
				eve(option_1,{type:2})
				eve(option_1,{type:3})
				// 自动充值
				eve(option_2,{type:1})
			},
			// 模糊搜索事件
			search_fuzzy: function(){
				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',
					com_target:'.default-select#companyId',
					dep_target:'.default-select#departmentId',
				});
				var option_2 = $.extend(true,{},default_option,{
					org_target:'.item-select.organ-id',
				});

				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})
				eve(option_1,{type:2})
				eve(option_1,{type:3})
				// 自动充值
				eve(option_2,{type:1})
			},
			/*
			 * 通过
			 * @param type 1 通过 2 拒绝
			 * @param id 维修单id
			 */
			ajaxPass: function(type,id){
				var _this = this;
				if(type==1){
					layer.confirm('确定通过?', {
						  btn: ['确定', '取消'] 
						}, function(index, layero){
							 layer.close(index); //如果设定了yes回调，需进行手工关闭
							_this.ajaxPassC(type,id);
						}, function(index){
							
						});
				}else{
					layer.confirm('确定拒绝?', {
						  btn: ['确定', '取消'] 
						}, function(index, layero){
							 layer.close(index); //如果设定了yes回调，需进行手工关闭
							_this.ajaxPassC(type,id);
						}, function(index){
							
						});
				}
				
				
			},
			/*
			 * @param type 1 通过 2 拒绝
			 * @param id 维修单id
			 */
			ajaxPassC:function(type,id){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/auditBill", 
					   data: {
						   "operateType": type,
						   "id": id
					   },
					   success: function(data){
						   if(data.code == '200'){
							   if(type==1){
								   layer.msg('通过成功！');
							   }else{
								   layer.msg('拒绝成功！');
							   }
							   $(".dialog-wp").remove();
							   _this.againRenderTable()
						   }else{
							   layer.msg(data.msg)
						   }   
					   },
					   error: function(error){  
						   layer.msg('error')
					   }
			   });
			},
			/**
			 * 显示获取可指派人员的弹窗
			 * @param id 维修单id
			 */
			showChoosePersonDialog: function(id){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/getRepairUser", 
					   data:{
						   "id": id
					   },
					   success: function(data){
//						   var data = JSON.parse(data);
						   if(data.code == '200'){
							   //显示可指派弹窗
							  $("body").append(template.render(tpl.choosePersonTpl)(data));
							  $(".close-btn").on("click",function(){
									 $(this).closest(".dialog-wp").remove();
								 })
							  //派单
							  $(".choose-perosn-btn").on("click",function(){
								  var obj=document.getElementsByName('dataRepair')
								  var check_war=[]
								  for(k in obj){
									  if(obj[k].checked){
										  check_war.push(obj[k].value)
									  }
								  }
								  console.log("选择的维修人员",check_war);
								  if(_this.projectIsPersion=='1'){//开启多人派单
									  if(check_war.length>3){
										  layer.msg('抱歉，每个维修单最多可指派3个维修人！');  
										  return 
									  }else{
										  _this.ajaxSlip(id,check_war.join(','),$(".dialog-wp"));  
									  }  
								  }else{
									  if(check_war.length>1){
										  layer.msg('抱歉，当前维修单只允许最多配送给1位工程师！');  
										  return 
									  }else{
										  _this.ajaxSlip(id,check_war.join(','),$(".dialog-wp"));  
									  }
								  }
//								  var receiverId = $(".person-item .radio-item:checked").data("id");
//								  console.log("选择的维修人员",receiverId);
								 // _this.ajaxSlip(id,receiverId,$(".dialog-wp"));
							  })
						   }else{
							   layer.msg(data.msg)
						   }   
					   },
					   error: function(error){  
						   layer.msg('error')
					   }
			   });
			},
		
			/**
			 * 派单
			 * @param id 维修单id
			 * @param receiverId 接收人ID
			 * @param $dom 弹窗
			 */
			ajaxSlip: function(id,receiverId){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/sendBill", 
					   data:{
						   "id": id,
						   "receiverId": receiverId
					   },
					   success: function(data){
//						   var data = JSON.parse(data);
						   if(data.code == '200'){
							  layer.msg("派单成功！");
							  $(".dialog-wp").remove();
							  _this.againRenderTable()
						   }else{
							   layer.msg(data.msg)
						   }   
					   },
					   error: function(error){  
						   layer.msg('error')
					   }
			   });
			},
		
			/**
			 * 查看订单详情
			 * @param id 维修单id
			 * @param status  维修单状态
			 * 
			 */
			ajaxDetail: function(id,status){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/getDetail", 
					   data:{
						   "id": id
					   },
					   success: function(data){
//						   var data = JSON.parse(data);
						   if(data.code == '200'){
							 $("body").append(template.render(tpl.detailTpl)(data.data));
							 //关闭详情弹窗
							 $(".close-btn").on("click",function(){
								 $(this).closest(".dialog-wp").remove();
							 });
							 $(".dialog .repair-img-item .img").zoomify()
							 //拒绝
							 $(".detail-reject-btn").on("click",function(){
								 _this.ajaxPass(2,id);
								
							 });
							 //通过
							 $(".detail-pass-btn").on("click",function(){
								 _this.ajaxPass(1,id);
							 });
							 //派单
							 $(".dialog-wp .send-order").on("click",function(){
								 _this.showChoosePersonDialog(id);
							 })
						   }else{
							   layer.msg(data.msg)
						   }   
					   },
					   error: function(error){  
						   layer.msg('error')
					   }
			   });
			}
	};
	launchRepair.init();
})