/**
 * 评价管理
 * 2018/5/7 by liufang
 */
var userType = $("#userType").val();
var companyArr = []; // 运营中心列表
var companyId = '';
var orgArr = []; // 项目列表

$(function(){
	var layer;
	layui.use('layer', function(){
		   layer = layui.layer;
	});
	var contextPath = $("#contextPath").val();
	var tpl = {
			"personList" :' <% for(var j=0;j<userList.length;j++){%>\
				<div class="person-item">\
				<div class="radio-wp" >\
					<span class="radio-input">\
						<input type="radio" id="outdate-<%=j%>"  class="radio-item" name="date" data-id="<%=userList[j].id%>"/>\
						<span class="radio-inner"></span>\
					</span>		\
					<label class="radio-con" for="outdate-<%=j%>"><%=userList[j].name%></label>\
				</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-left">\
								<h2 class="title">维修类型</h2>\
								<ul class="repair-list">\
									<% for(var i=0;i<typeList.length;i++){%>\
										<li class="repair-item <%if(i==0){%>active<%}%>" data-id="<%=typeList[i].id%>"><%=typeList[i].itemname%></li>\
									<%}%>\
								</ul>\
							</div>\
							<div class="choose-person-right">\
								<h3 class="title">工程人员</h3>\
								<div class="person-list clearfloat">\
									<% for(var j=0;j<userList.length;j++){%>\
										<div class="person-item">\
											<div class="radio-wp" >\
												<span class="radio-input">\
													<input type="radio" id="outdate-<%=j%>"  class="radio-item" name="date" data-id="<%=userList[j].id%>"/>\
													<span class="radio-inner"></span>\
												</span>		\
												<label class="radio-con" for="outdate-<%=j%>"><%=userList[j].name%></label>\
											</div>\
										</div>\
									<%}%>\
								</div>\
							</div>\
						</div>\
						<div class="choose-person-btns">\
							<button class="btn-red choose-person-sure-btn">确认</button>\
						</div>\
					</div>\
				</div>\
			</div>	',
			"visitTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-visit-con">\
					<div class="title-wp">\
						<span>回访编辑</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-visit-wp">\
						<div class="visit-wp">\
							<span class="tips">回访星级：</span>\
							<div class="star-wp">\
								<span class="star"></span>\
								<span class="star"></span>\
								<span class="star"></span>\
								<span class="star"></span>\
								<span class="star"></span>\
							</div>\
						</div>\
						<div class="visit-wp visit-record-wp">\
							<span class="tips">回访记录：</span>\
							<textarea class="visit-record" data-id="<%=id%>"></textarea>\
						</div> \
						<div class="visit-btns-wp">\
							<button class="btn-red visit-btn">确认</button>\
						</div>\
					</div>\
				</div>\
			</div>	',
			"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==10){%>\
								（已取消）\
							<%} %>\
					  </span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-detail-wp">\
						<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>\
						<%if(baseDto.status==8){%>\
							<div class="detail-middle">\
								<div class="detail-line">\
									<span class="line-tips">评价星级：</span>\
									<div class="line-value">\
										<%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>\
								<div class="detail-line">\
									<span class="line-tips">评价标签：</span>\
									<div class="line-value">\
										<%=detailDto.serviceImpression%>\
									</div>\
								</div>\
								<div class="detail-line">\
									<span class="line-tips">评价内容：</span>\
									<div class="line-value">\
										<%=detailDto.description%>\
									</div>\
								</div>\
							</div>\
						\
						<div class="detail-btm">\
							<div class="detail-line">\
								<span class="line-tips">回访星级：</span>\
								<div class="line-value star-wp">\
								<%if(!!detailDto.visitStar){%>\
									<%for(var j=0;j<detailDto.visitStar;j++){%>\
										<span class="star active"></span>\
									<%}%>\
									<% for(var k=detailDto.visitStar;k<5;k++){%>\
										<span class="star"></span>\
									<%}%>\
								<%}else{%>\
									<%for(var j=0;j<5;j++){%>\
										<span class="star"></span>\
									<%}%>\
								<%}%>	\
									<%if(!detailDto.visitStar && baseDto.status==8 ){%>\
										<span class="evalu-edit-btn">回访编辑</span>\
									<%} %>\
								</div>\
							</div>\
							<div class="detail-line">\
								<span class="line-tips">评价记录：</span>\
								<div class="line-value descrip-wp">\
									<%=detailDto.visitDescription%>\
								</div>\
							</div>\
						</div>\
					<%}%>	\
					</div>\
				</div>\
			</div>	',
	}
	var launchRepair = {
			init: function(){
				this.render();
				this.bindEvent();
			},
			render: function(){
				var _this = this;
				_this.renderTable();
			},
			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").val("");
					$("#conditionform .choose-person-btn").data("id","");

					let contextPathURL = window.location.hostname === 'localhost' ? '//wx.palmnest.com/super_cloud' : "/super_cloud"
					if (userType == 1 || userType == 2|| userType == 6) {
						$("#conditionform input").val("");
						$('#comdId').val(companyArr[0].label).attr('comd__id', companyArr[0].value).attr('meetCode', companyArr[0].meetCode);
						companyId = $("#conditionform #comdId").attr('comd__id');
						_this.setOrgData(contextPathURL);
					} else {
						$("#conditionform input:not('#orgId')").val("");
						companyId = localStorage.getItem("companyId")
						_this.setOrgData(contextPathURL);
					}
				});
				//选择工程人员
				$(".choose-person-btn").on("click",function(){
					_this.ajaxRepairType(function(data){
						$("body").append(template.render(tpl.choosePersonTpl)(data));
						$(".close-btn").on("click",function(){
							$(".dialog-wp").remove();
						});
						$(".repair-item").on("click",function(){
							var  repairTypeId = $(this).data("id")
							$(this).addClass("active").siblings().removeClass("active");
							_this.ajaxRepairTypeUser(repairTypeId);
						});
						//确定选中工程人员
						$(".choose-person-sure-btn").on("click",function(){
							var length = $(".person-item .radio-item:checked").length;
							if(!length){
								layer.msg("请选择工程人员")
							}else{
								$("#conditionform .choose-person-btn").data("id",$(".person-item .radio-item:checked").data("id"));
								$(this).closest(".dialog-wp").remove();
							}

						})
					})

				});

				let contextPath = window.location.hostname === 'localhost' ? '//wx.palmnest.com/super_cloud' : "/super_cloud"
				if (userType == 1 || userType == 2|| userType == 6) {
					_this.getCompanyList({}, contextPath)
					$('body').on("focus", '#comdId', function (event) {
						_this.setOrgCompanyData($('#comdId'), 'comd__id', 'comd__span' , companyArr);
					});
					$('body').on('blur', '#comdId', function (event) {
						var _that = $(this)
						cjqt.search_fuzzy.event_blur(_that, 'comd__id')
					});
					$('body').on('click', '.select_wrap>.comd__span', function (event) {
						event.preventDefault();
						event.stopPropagation();
						/* Act on the event */
						var _that = $(this)
						cjqt.search_fuzzy.event_click(_that, 'comd__id', '#comdId')
						companyId = $("#conditionform #comdId").attr('comd__id')
						_this.setOrgData(contextPath);
					});
					$('body').on("input",'#comdId',function(event){ // input内容变化执行
						_this.setFuzzyFilter($('#comdId').val(), companyArr, backData => {
							_this.setOrgCompanyData($('#comdId'), 'comd__id', 'comd__span' , backData);
						})
					});
				} else {
					companyId = localStorage.getItem("companyId")
					_this.setOrgData(contextPath);
				}
			},
			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' //小尺寸的表格
					    ,cols: [[
						  {

							  title: '序号',
							  templet: '#indexTpl',
							  width: 80
						  } ,{
				    		   field:'code',
				    		   title: '维修单编号',
				    		   minWidth:200
				    	  },{
				    		  field:'repairUser',
				    		  title: '报修人',
				    		  minWidth: 120
			    		  },{
			    			  field:'contactWay',
			    			  title: '报修人手机',
			    			  minWidth:200,
							  templet: function (data) {
								  return _this.phoneLize(data.contactWay)
							  }
		    			  },{
		    				  field:'createTime',
		    				  title: '报修时间',
		    				  minWidth:200
		  				  },{
		  					  field:'repairWayName',
		  					  title: '报修方式',
		  					minWidth: 100
		  				  },{
		  					  field:'repairAreaName',
		  					  title: '维修区域',
		  					  minWidth:200

						  },{
							  field:'repairTypeName',
							  title: '维修类型',
								  minWidth:200

						  },{
							  field:'meetingTime',
							  title: '上门时间',
							  minWidth:200,
							  templet: function(data){
								  if(data.meetingTime){
									  return data.meetingTime
								  }else{
									  return '立即上门'
								  }
							  }

						  },{
		  					  field:'status',
		  					  title: '订单状态',
		  					  width: 100,
		  					  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 '已取消'
		  						  }
		  					  }
						  },{
							  field:'commentStar',
							  title: '评星星级',
							  width: 130,
							  templet: function(data){
								  if(!data.commentStar){
									 return '未评价'
								  }else{
									return data.commentStar+'星';
								  }
							  }

						  },{
							  field:'visitStar',
							  title: '回访星级',
							  width: 130,
							  templet: function(data){
								  if(!data.visitStar){
									 return '未回访'
								  }else{
									return data.visitStar+''+'星';
								  }
							  }


						  },{
								  field:'visitStar',
								  title: '工单星级',
								  width: 130,
								  templet: function(data){
								  	if (!data.commentStar&&!data.visitStar) {
										return '未评价'
									} else {
								  		if (data.commentStar&&data.visitStar) {
								  			if (Number(data.commentStar)>Number(data.visitStar)) {
												return data.commentStar+''+'星';
											} else {
												return data.visitStar+''+'星';
											}
										} else {
								  			if (data.commentStar) {
												return data.commentStar+''+'星';
											} else {
												return data.visitStar+''+'星';
											}
										}
									}
								  }
							  },{
//		  					  field:'id',
		  					  title: '订单详情',
		  					  width: 120,
		  					  templet: function(data){
		  						return "<span data-id="+data.id+" data-status= "+data.status+" class='check-blue-btn'>查看详情<span>"
		  					  }
						  }
						  ]]
						    ,id: 'testReload'
						    ,page: true,
						    where: {
								orgId: $("#conditionform  #orgId").attr('org__id'),
							},
						    response: {
						    	  statusName: 'code' //数据状态的字段名称，默认：code
						    	  ,statusCode: 200 //成功的状态码，默认：0
						    	  ,countName: "count"//数据总数的字段名称，默认：count
						    	  ,dataName: "data" //数据列表的字段名称，默认：data
						    	}   ,
						    done: function(res, curr, count){
						        //如果是异步请求数据方式，res即为你接口返回的信息。
						        $(".check-blue-btn").on("click",function(){
						        	var id = $(this).data("id")
						        	var status = $(this).data("status")
						        	//查看订单详情
						        	_this.ajaxDetail(id,status);
						        });

						      }
					  });
					  //查询
					  $('#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', {
						url: $("#contextPath").val() + "/repairBill/list",
						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(),
							hasComment: $(".select-evaluation").val(),
							hasReturnVisit: $(".select-record").val(),
							star: $(".select-evaluation-star").val(),
							serviceUsers: $("#conditionform .choose-person-btn").data("id")
						}
						, page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				} else {
					table.reload('testReload', {
						url: $("#contextPath").val()+ "/repairBill/list",
						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(),
							hasComment: $(".select-evaluation").val(),
							hasReturnVisit: $(".select-record").val(),
							star: $(".select-evaluation-star").val(),
							serviceUsers: $("#conditionform .choose-person-btn").data("id")
						}
						, page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				}

			},
			/**
			 * 手机号中间4位数字用*代替
			 * @param data 原始数据
			 */
			phoneLize: function(data){
				if(data){
					let start = data.slice(0, 3)
					let end = data.slice(-4)
					return start + '****' + end
				}
			},
			setOrgData: function(contextPath) {
				var _this = this;
				_this.getOrgList({
					pageNo: 1,
					pageSize: 9999,
					"conditions[companyId]": companyId
				}, contextPath)
				$('body').on("focus", '#orgId', function (event) {
					_this.setOrgCompanyData($('#orgId'), 'org__id', 'org__span' , orgArr);
				});
				$('body').on('blur', '#orgId', function (event) {
					var _that = $(this)
					cjqt.search_fuzzy.event_blur(_that, 'org__id')
				});
				$('body').on('click', '.select_wrap>.org__span', function (event) {
					event.preventDefault();
					event.stopPropagation();
					/* Act on the event */
					var _that = $(this)
					cjqt.search_fuzzy.event_click(_that, 'org__id', '#orgId')
				});
				$('body').on("input",'#orgId',function(event){
					_this.setFuzzyFilter($('#orgId').val(), orgArr, backData => {
						_this.setOrgCompanyData($('#orgId'), 'org__id', 'org__span' , backData);
					})
				});
			},
			// 获取运营中心数据
			getCompanyList: function (obj, contextPath) {
				var _this = this;
				companyArr = [];
				$.ajax({
					url: contextPath + '/api/organisation/company/getselectlist',
					type: "POST",
					dataType: "json",
					data: obj,
					success: function (data) {
						if (data.code == 200 && data.data) {
							companyArr = data.data;
							_this.setInputData($('#comdId'), 'comd__id', 'comd__span' , companyArr);
							companyId = $("#conditionform #comdId").attr('comd__id')
							_this.setOrgData(contextPath);
						} else {
							layer.msg(data.msg);
						}
					}
				});
			},
			// 获取项目数据
			getOrgList(obj, contextPath) {
				var _this = this;
				orgArr = [];
				$.ajax({
					url: contextPath + '/api/organisation/organization/getselectlist',
					type: "POST",
					dataType: "json",
					data: obj,
					success: function (data) {
						if (data.code == 200 && data.data) {
							orgArr = data.data;
							_this.setInputData($('#orgId'), 'org__id', 'org__span', orgArr);
						} else {
							layer.msg(data.msg);
						}
					}
				});
			},
			setInputData: function(_this, attrName, liClassName, dataArr) {
				// 先清空
				_this.attr(attrName, '')
				var html = ''
				if (dataArr.length) {
					_this.val(dataArr[0].label).attr(attrName, dataArr[0].value).attr('meetCode', dataArr[0].meetCode);
					if (attrName == 'org__id') {
						$('#conditionform  .search-btn').click();
					}
					$.each(dataArr, function (index, el) {
						var meetCode = el.meetCode || ''
						html += '<span class="' + liClassName + '" id="' + el.value + '" meetCode="' + meetCode + '">'
						html += el.label
						html += '</span>'
					});
					_this.parent().find('.select_wrap').empty().append(html);
				} else {
					_this.val('').attr(attrName, '').attr('meetCode', '');
					_this.parent().find('.select_wrap').empty().hide()
				}
			},
			setOrgCompanyData: function(_this, attrName, liClassName, dataArr) {
				var html = ''
				if (dataArr.length) {
					_this.parent().find('.select_wrap').show()
					$.each(dataArr, function (index, el) {
						var meetCode = el.meetCode || ''
						html += '<span class="' + liClassName + '" id="' + el.value + '" meetCode="' + meetCode + '">'
						html += el.label
						html += '</span>'
					});
					_this.parent().find('.select_wrap').empty().append(html)
				} else {
					_this.parent().find('.select_wrap').empty().hide()
				}
			},
			setFuzzyFilter: function (strLabel, dataArr, backData) {
				const fuzzyArr = dataArr; // 内容省略
				const objArr = [];
				fuzzyArr.forEach(item => {
					if (item.label.includes(strLabel)) {
						objArr.push(item);
					}
				});
				backData(objArr);
			},
			/*显示回访弹窗*/
			showVisitDialog: function($dom){
//				$("body").append(template.render(tpl.visitTpl));
//				 $(".close-btn").on("click",function(){
//					  $(this).closest(".dialog-wp").remove();
//				  });
				//评星
				$dom.find(".star-wp .star").on("click",function(){
					var index = $(this).index();

					$dom.find(".star-wp .star").each(function(ind,ele){
						$(ele).removeClass("active");
						if(index>=ind){
							$(ele).addClass("active");
						}
					})
				})
			},
			/**
			 * 获取详情
			 * @param id
			 */
			ajaxDetail: function(id){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/getDetail",
					   data: {
						   id: id
					   },
					   success: function(data){

						   if(data.code == '200'){
							  $("body").append(template.render(tpl.detailTpl)(data.data));
							  $(".close-btn").on("click",function(){
								  $(this).closest(".dialog-wp").remove();
							  });
							  //回访编辑
							  $(".evalu-edit-btn").on("click",function(){
								  $("body").append(template.render(tpl.visitTpl)({id: id}));
								  $(".close-btn").on("click",function(){
									  $(this).closest(".dialog-wp").remove();
								  });
								  _this.showVisitDialog($(".dialog-visit-wp"));
								  //确定回访编辑
								  $(".visit-btn").on("click",function(){
									  var $dom = $(this).closest(".dialog-wp");
									  _this.ajaxaddOrUpdateVisit(id,$dom,function(star,description){
//										  $(".detail-btm .evalu-edit-btn").hide();
										  $(".detail-btm .detail-line .line-value.descrip-wp").html(description);
										  $(".detail-btm .line-value.star-wp .star").each(function(index,ele){
											  if(index<star){
												  $(ele).addClass("active");
											  }
										  })
										  _this.againRenderTable();
									  })
								  })
							  })
						   }else{
							   layer.msg(data.msg)
						   }
					   },
					   error: function(){
						   layer.msg('error')
					   }
			   });
			},
			/**
			 * 确定回访编辑
			 * @param id
			 * @param $dom
			 * @param callback
			 */
			ajaxaddOrUpdateVisit: function(id,$dom,callback){
				var _this = this;
//				visit-record
				//评价星级
				var star = $(".visit-wp .star.active").length;
				if(!star){
					layer.msg("请选择回访星级");
					return false;
				};
				//描述
				var description = $(".visit-record").val();
				if(!description){
					layer.msg("请输入回访记录");
					return false;
				};
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/addOrUpdateVisit",
					   data: {
						   star: star,
						   billId: id,
						   description: description
					   },
					   success: function(data){

						   if(data.code == '200'){
							  $dom.remove();
							  callback(star,description);
						   }else{
							   layer.msg(data.msg)
						   }
					   },
					   error: function(){
						   layer.msg('error')
					   }
			   });
			},
			/**
			 * 获取维修类型
			 * callback
			 */
			ajaxRepairType: function(callback){
				var _this = this;
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/getRepairType",
					   success: function(data){

						   if(data.code == '200'){
							   var repairTypeId = data.data.length >0 && data.data[0].id;
							   //获取维修类型对应人员
							  _this.ajaxRepairTypeUser(repairTypeId,callback,data.data)
						   }else{
							   layer.msg(data.msg)
						   }
					   },
					   error: function(){
						   layer.msg('error')
					   }
			   });
			},
			/*
			 * 获取维修类型对应人员
			 * @param repairTypeId 维修类型id
			 * @param callback
			 * @param typeList 维修类型列表
			 */
			ajaxRepairTypeUser: function(repairTypeId,callback,typeList){
				var $orgId = $("#conditionform  .single-orgid");
				var orgId = $("#conditionform  #orgId").attr('org__id');

				var params = {
					repairTypeId: repairTypeId
				};
				if(!$orgId.length && orgId){
					params["orgId"] = orgId;
				}else if($orgId.length){
					params["orgId"] = $orgId.val();
				};
				console.log(params);
				$.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/repairBill/getRepairTypeUser",
					   data: params,
					   success: function(data){

						   if(data.code == '200'){
							   if(callback){
								   var list =  {
										   typeList: typeList,
										   userList : data.data
								   }
								   callback(list)
							   }else{
								   $(".dialog-wp .person-list").html(template.render(tpl.personList)({userList: data.data}));
							   }

						   }else{
							   layer.msg(data.msg)
						   }
					   },
					   error: function(){
						   layer.msg('error')
					   }
			   });
			}
	};
	launchRepair.init();
})
