var permApprove = $("#perm-approve").val();//审核权限
var permAppeditor = $("#perm-appeditor").val();//编辑权限
var permAppecancel = $("#perm-appecancel").val();//取消订单权限

var userType = $("#userType").val();
var companyArr = []; // 运营中心列表
var companyId = '';
var orgArr = []; // 项目列表

/**
 * 维修订单详情
 * 2018/5/7 by liufang
 */
$(function () {
  console.log('permApprove', permApprove);
  console.log('permAppeditor', permAppeditor);
  console.log('permAppecancel', permAppecancel);

  var layer;
  var projectIsPersion;
  var dataList = []
  var showMaterManger = true
  var orgList = []
  var tableData = []
  var tableAddress = []
  var ERROR_OK = 200;
  var form = layui.form
  layui.use('layer', function () {
    layer = layui.layer;
  });
  var contextPath = $("#contextPath").val();
  var orderDetails;
  var repairAreaGroup = [];
  var maxTypeId = '';//选中大类id
  var repairTypeaDetailGroup = [];
  var minTypeId = '';//选中小类id

  var tpl = {
    "editorTpl": '<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||baseDto.status==11){%>\
							（已取消）\
						<%} %>\
						</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" style="height: 30px">\
									<span class="tips">报修人：</span>\
									<span class="top-item-value"><%=baseDto.repairUser %></span>\
								</div>\
								<div class="detail-top-item clearfloat" style="height: 30px">\
									<span class="tips">报修方式：</span>\
									<span class="top-item-value"><%=baseDto.repairWayName %></span>\
								</div>\
								<div class="detail-top-item clearfloat" style="height: 30px">\
									<span class="tips">报修人手机：</span>\
									<span class="top-item-value"><%=baseDto.contactWay %></span>\
								</div>\
								<div class="detail-top-item clearfloat" style="height: 30px">\
									<span class="tips">维修区域：</span>\
									<span class="top-item-value"><%=baseDto.repairAreaName %></span>\
								</div>\
								<div class="detail-top-item clearfloat" style="height: 30px">\
									<span class="tips">维修大类：</span>\
									<select class="default-select maxType-change" style="height: 30px !important; margin-top: -5px !important;" id="maxType">\
                                      <option value="0">选择维修大类</option>\
                                      <%for(var i=0;i<repairAreaGroup.length;i++){%>\
                                      <%if(repairAreaGroup[i].id==maxTypeId){%>\
                                      <option value="<%=repairAreaGroup[i].id%>" selected><%=repairAreaGroup[i].itemname%></option>\
                                      <%}else{%>\
                                      <option value="<%=repairAreaGroup[i].id%>"><%=repairAreaGroup[i].itemname%></option>\
                                      <%}%>\
                                      <%}%>\
                                    </select>\
								</div>\
								<div class="detail-top-item clearfloat" style="height: 30px">\
									<span class="tips">地址：</span>\
									<span class="top-item-value"><%=baseDto.address %></span>\
								</div>\
								<div class="detail-top-item clearfloat" style="height: 30px">\
									<span class="tips">维修小类：</span>\
									<select class="default-select minType-change" style="height: 30px !important;margin-top: -5px !important;" id="minType">\
                                      <option value="0">选择维修小类</option>\
                                      <%for(var i=0;i<repairTypeaDetailGroup.length;i++){%>\
                                      <option value="<%=repairTypeaDetailGroup[i].id%>"><%=repairTypeaDetailGroup[i].itemname%></option>\
                                      <%}%>\
                                    </select>\
								</div>\
								<div class="detail-top-item clearfloat style="height: 30px"">\
									<span class="tips">维修人：</span>\
									<span class="top-item-value"><%=detailDto.serverUser %></span>\
								</div>\
								<% if(baseDto.status==8){%>\
								<div class="detail-top-item clearfloat" style="height: 30px">\
									<span class="tips">维修费用：</span>\
									<span class="top-item-value"><%=detailDto.repairCost %></span>\
								</div>\
								<%}%>\
								<div class="detail-top-item clearfloat" style="height: 30px">\
									<span class="tips">协办人：</span>\
									<span class="top-item-value"><%=detailDto.supportUserNames %></span>\
								</div>\
								<div class="detail-top-item clearfloat" style="height: 30px">\
									<span class="tips">维修耗材：</span>\
									<span class="top-item-value"><%=detailDto.materialName %></span>\
								</div>\
								<% if(!!baseDto.completeDesc) {%>\
                                  <div class="detail-describe-item clearfloat">\
                                      <span class="tips">完成描述：</span>\
                                      <span class="top-item-value"><%=baseDto.completeDesc %></span>\
                                  </div>\
							    <%}%>\
							    <% if(!!baseDto.completePhotoUrl) {%>\
                                  <div class="detail-describe-item clearfloat">\
                                    <div class="tips">完成图片：</div>\
                                    <div class="top-item-value">\
                                       <% var compImgList = baseDto.completePhotoUrl.split(";")%>\
                                       <%for(var i=0;i<compImgList.length;i++){%>	\
                                          <div class="comp-img-box" >\
                                              <img src="<%=compImgList[i]%>" class="img" />\
                                          </div>\
                                       <%}%>\
                                    </div>\
                                  </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]%>" fit="cover" 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" style="display: flex;">\
												<span class="date"><%=operateDto[m].operateTime%></span>\
												\
												<span class="con"><%=operateDto[m].operateDescription%></span>\
												<%if (operateDto[m].isConfirm == 0||operateDto[m].isConfirm == 1) {%>\
												    <%if (operateDto[m].isConfirm == 1) {%>\
												      <span class="state-send">已确认</span>\
												    <%} else {%>\
												      <span class="state-send send-color">待确认</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">\
							<div class="detail-operate-btn">\
								<button class="btn-red send-editor">确定</button>\
							</div>\
						</div>\
				   </div>		\
				</div>\
			</div>	',
    "minTypeTpl": '<option value="0">选择维修小类</option>\
                                      <%for(var i=0;i<repairTypeaDetailGroup.length;i++){%>\
                                      <%if(repairTypeaDetailGroup[i].id==minTypeId){%>\
                                      <option value="<%=repairTypeaDetailGroup[i].id%>" selected><%=repairTypeaDetailGroup[i].itemname%></option>\
                                      <%}else{%>\
                                      <option value="<%=repairTypeaDetailGroup[i].id%>"><%=repairTypeaDetailGroup[i].itemname%></option>\
                                      <%}%>\
                                      <%}%>\  ',
    "decondaryTpl": '<div class="dialog-wp">\
                      <div class="alertMsg">\
                      <div class="alertBox">\
                           <div class="alert-title">取消订单</div>\
                           <div class="alert-content">是否确定取消订单?</div>\
                           <div class="alert-line1"></div>\
                           <button class="alert-cancel alert-color1 cancelAlert">\
                               <span style="margin: 10px">取消</span>\
                           </button>\
                           <button class="alert-cancel alert-color2 determineAlert">\
                               <span style="margin: 10px">确定</span>\
                           </button>\
                           <div class="alert-line2"></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==22){%>\
							(待派单)\
						<%}else if(baseDto.status==10||baseDto.status==11){%>\
							（已取消）\
						<%} %>\
						</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>\
									<% if(baseDto.meetingTime){%>\
									  <span class="top-item-value"><%=baseDto.meetingTime%></span>\
									<%}else{%>\
									  <span class="top-item-value">立即上门</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>\
								<div class="detail-top-item clearfloat">\
									<span class="tips">维修小类：</span>\
									<span class="top-item-value"><%=baseDto.repairTypeDetailName %></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>\
								<% if(!!baseDto.completeDesc) {%>\
                                  <div class="detail-describe-item clearfloat">\
                                      <span class="tips">完成描述：</span>\
                                      <span class="top-item-value"><%=baseDto.completeDesc %></span>\
                                  </div>\
							    <%}%>\
							    <% if(!!baseDto.completePhotoUrl) {%>\
                                  <div class="detail-describe-item clearfloat">\
                                    <div class="tips">完成图片：</div>\
                                    <div class="top-item-value">\
                                       <% var compImgList = baseDto.completePhotoUrl.split(";")%>\
                                       <%for(var i=0;i<compImgList.length;i++){%>	\
                                          <div class="comp-img-box" >\
                                              <img src="<%=compImgList[i]%>" class="img" />\
                                          </div>\
                                       <%}%>\
                                    </div>\
                                  </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" style="display: flex;">\
												<span class="date"><%=operateDto[m].operateTime%></span>\
												\
												<span class="con"><%=operateDto[m].operateDescription%></span>\
												<%if (operateDto[m].isConfirm == 0||operateDto[m].isConfirm == 1) {%>\
												    <%if (operateDto[m].isConfirm == 1) {%>\
												      <span class="state-send">已确认</span>\
												    <%} else {%>\
												      <span class="state-send send-color">待确认</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>	',
    "addMeatrial": '<div class="dialog-wp addMeatrial" style="top: -5%">\
			    <div class="mask"></div>\
			    <div class="dialog dialog-account-con" style="width: 900px">\
			      <div class="title-wp">\
			        <span>耗材管理</span>\
			        <span class="close-btn"></button>\
			      </div>\
			      <div class="dialog-account-wp ">\
			        <div class="account-list">\
					  	<% if(orgList!=null&&orgList.length>1){ %>\
						<div class="account-item required clearfloat">\
							<div class="item-tip ">项目：</div>\
							<div class="item-con">\
								<input class="pop-select orgId layui-input" 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="pop-select orgId layui-input" id="orgId" value="<%=orgList[0].name %>" org__id="<%=orgList[0].id %>"/>\
						<%}%>\
			          <div  style="width: 800px;">\
			            <div class="item-tip">耗材：</div>\
			            <div class="item-con" style="width:660px">\
			              <div class="tables" style="width:100%">\
			                <table class="layui-hide" id="demo" lay-filter="demo"></table>\
			                <div class="addBtn">\
			                  <button>+ 继续添加</button>\
			                </div>\
			              </div>\
			            </div>\
			           </div>\
						<div  style="width: 800px;margin-top:20%">\
			            <div class="item-tip">维修地址：</div>\
			            <div class="item-con" style="width:660px">\
			              <div class="tables" style="width:100%">\
			                <table class="layui-hide" id="demoAddress" lay-filter="demoAddress"></table>\
			                <div class="addBtnAddress">\
			                  <button>+ 继续添加</button>\
			                </div>\
			              </div>\
			            </div>\
			           </div>\
			          <div class="dialog-btns" style="border:0;width: 800px;float:left">\
			            <button class="sure-add-btn bt_blue_big_b_slot fs16" style="margin-top: 10px;">确定</button>\
				 		<button class=" bt_blue_big_b fs16 ml30 cancle-add-btn" style="margin-top: 10px;">取消</button>\
			          </div>\
			         </div>\
			      </div>\
			    </div>\
			  </div>	',
    "generatingCodeTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-wx-con">\
					<div class="title-wp">\
						<span>生成报修码</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-wx-wp">\
						<div class="dialog-wx-wrapper">\
							<div class="d-wx-top">\
								<% if(orgList!=null&&orgList.length>1){ %>\
								<div class="d-wx-wp d-wx-num-wp">\
									<span class="tips " style="text-align: center;">项目:</span>\
									<input class="default-select input-text-type" name="orgId" id="orgId" placeholder="请选择项目" autocomplete="off"/>\
					    			<span class="select_wrap _hide"></span>\
								</div>\
								<%}else if(list!=null&&list.length==1){%>\
									<input type="hidden" class="default-select single-orgid input-text-type" value="<%=orgList[0].id %>" org__id="<%=orgList[0].id %>"/>\
								<%}%>\
								 <div class="layui-form-item">\
							    <label class="layui-form-label  pad-none" style="margin-to:10px;">维修地址:</label>\
							    <div class="layui-input-block" style="margin-bottom:10px;">\
							      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入维修地址" class="layui-input input-text-type  repair-person">\
							    </div>\
								<div class="d-wx-wp d-wx-num-wp">\
									<span style="text-align: center;">大类:</span>\
									<select class="d-wx-num">\
										<option value="">请选择大类</option>\
									</select>\
								</div>\
							<div class="d-wx-wp d-wx-num-wp">\
							<span style="text-align: center;">小类:</span>\
							<select class="d-wx-num">\
								<option value="">请选择小类</option>\
							</select>\
							</div>\
						 </div>\
							<div class="layui-form-item">\
						    <label class="layui-form-label  pad-none">维修描述:</label>\
						    <div class="layui-input-block">\
						    <textarea class="layui-textarea input-text-type repair-descript" placeholder="请输入报修描述"></textarea>\
						    </div>\
						 </div>\
						  <div class="layui-form-item">\
						    <div class="layui-input-block">\
						      <div  class="layui-btn  btn-control-link">生成链接</div>\
						    </div>\
						  </div>	\
							<div class="layui-form-item">\
						    <label class="layui-form-label  pad-none">链接地址:</label>\
						    <div class="layui-input-block">\
						    <textarea class="layui-textarea input-text-type repair-linkurl" placeholder="请输入链接地址"></textarea>\
						    </div>\
						    </div>\
							</div>\
				     	</div>\
				<div class="layui-form-item">\
			    <div class="layui-input-block">\
			      <button type="submit" class="layui-btn  btn-style-ml btn-control-code" >生成二维码</button>\
			    </div>\
			  </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();
              }

              if (resultData.checkFloor == '1') {
                $("#checkFloor").prop("checked", true);
              } else {
                $("#checkFloor").prop("checked", false);
              }

              //开启报事
              if (resultData.supportReport == '1') {
                $("#supportRepairReport").prop("checked", true);
              } else {
                $("#supportRepairReport").prop("checked", false);
              }

              if (resultData.isDeliveryConfirm == '1') {
                $("#SendConfirm").prop("checked", true);
              } else {
                $("#SendConfirm").prop("checked", false);
              }

              $("#describeField").val(resultData.isCompleteDesc);
              $("#photoField").val(resultData.isCompletePhoto);

              //是否一单多人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("");

        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);
        }
      });
      //功能配置
      $(".function-btn").on("click", function () {
        $('.alert').css('display', 'block');
        var chooseOrgId = $("#organizationId").attr('org__id')
        operateSetting.getConfigInfo(chooseOrgId);
        console.log("第一次的项目id", chooseOrgId, '121212')

//				 	$("#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);
        });
      });
      //生成码
      $(".function-btn1").on("click", function () {
        $("body").append(template.render(tpl.generatingCodeTpl)({
          orgList: orgList,
        }));

        $(".close-btn").on("click", function () {
          $(".dialog-wp").remove();

        });
//
//				 	//生成二维码
        $(".btn-control-code").on("click", function () {
          $('.generatingCode_con').css('display', 'none');
          console.log("关闭生成码弹框")

        });
//					//生成链接
        $(".btn-control-link").on("click", function () {
          console.log("不关闭生成码弹框")

        });

      });


      //建议
      $(".function-btn2").on("click", function () {
        if (orgList && orgList.length > 0) {
          console.log(11111111111111111, orgList[0].id)
          //维修耗材查询列表 ,材料列表 //维修地址查询列表
          _this.getMaterListByOrgIdFirst(orgList[0].id)
          _this.getAddressListByOrgIdFirst(orgList[0].id)
        } else {
          _this.tableData = [{id: '', materialName: '',}]
          _this.tableAddress = [{id: '', address: ''}]
        }
//				        $("body").append(template.render(tpl.addMeatrial)({
//				        	orgList: orgList,
//				        }));

        //执行渲染
//				        console.log("tableData",_this.tableData)
//				        table.render({
//				          elem: '#demo'  ,data:_this.tableData ,height:250,cols: [[
//				        	{field: 'id', title: '耗材编号', width:100,event: 'setSign',},
//				            {field: 'materialName', title: '耗材名称', width:300,event: 'setSign',edit: 'false'},
//				            {
//				              title: '操作',
//				              width:80,
//				              templet: function(data) {
//				              var str = '';
//				              str += '<button class="t-delete-btn" style="border:0;background:#fff;color:red;cursor:pointer" lay-event="del">删除</button>';
//				              return str;
//				            }}
//				          ]]
//				          ,done : function(res, curr, count){
//				            // console.log(res.data,111)
//				          }
//				        });
//				        table.render({
//					          elem: '#demoAddress'
//					          ,data:_this.tableAddress,height:250
//					          ,cols: [[
//					        	  {field: 'id', title: '地址编号', width:100,event: 'setSign'},
//					            {field: 'address', title: '维修地址', width:300,event: 'setSign',edit: 'false'}
//					            ,{
//					              title: '操作',
//					              width:80,
//					              templet: function(data) {
//					              var str = '';
//					              str += '<button class="t-delete-btn" style="border:0;background:#fff;color:red;cursor:pointer" lay-event="del">删除</button>';
//					              return str;
//					            }}
//					          ]]
//					          ,done : function(res, curr, count){
//					            // console.log(res.data,111)
//					          }
//					        });
//				        //监听单元格编辑
//				        table.on('edit(demo)', function(obj){
//				          var value = obj.value //得到修改后的值
//				          ,data = obj.data //得到所在行所有键值
//				           console.log(obj,'编辑');
//				          if(obj.field == "materialName"){
//				            if(value.length>50){
//				              $(this).val(value.substring(0,50))
//				              data.materialName = value.substring(0,50)
//				              layer.msg("名称最多50个字符");
//				            }else{
//				              data.materialName = value
//				            }
//				          }
//				          _this.tableData.forEach(function(item,index){
//				            if(obj.data.LAY_TABLE_INDEX == index){
//				            	 _this.tableData[index].materialName = obj.data.materialName;
//				            	 _this.tableData[index].id = obj.data.id;
//				            }
//				          })
//				           //编辑一条之后保存或者修改
//				          console.log( _this.tableData,'编辑材料完成')
//				          _this.addOrUpdateMaterial(tableData[0].id,tableData[0].materialName);
//
//				        });
//				        table.on('edit(demoAddress)', function(obj){
//					          var value = obj.value //得到修改后的值
//					          ,data = obj.data //得到所在行所有键值
//					           console.log(data,'dataaddress');
//					          if(obj.field == "address"){
//					            if(value.length>50){
//					              $(this).val(value.substring(0,50))
//					              data.address = value.substring(0,50)
//					              layer.msg("名称最多50个字符");
//					            }else{
//					              data.address = value
//					            }
//					          }
//					          _this.tableAddress.forEach(function(item,index){
//					            if(obj.data.LAY_TABLE_INDEX == index){
//					            	_this.tableAddress[index].address = obj.data.address;
//					            	_this.tableAddress[index].id = obj.data.id;
//					            }
//					          })
//					          console.log(_this.tableAddress[0].id,_this.tableAddress[0].address,'编辑完成')
//					          //编辑一条之后保存或者修改
//					          _this.addOrUpdateAddress(_this.tableAddress[0].id,_this.tableAddress[0].name);
//					        });
//				        $(".addBtn button").on("click",function() {
//				          console.log(tableData,'添加之前');
//				          _this.tableData.push({
//				        	  id:'',
//				        	  materialName: '',
//				          })
//				          table.reload('demo',{
//				            data : _this.tableData
//				          });
//				        });
//				        $(".addBtnAddress button").on("click",function() {
//					          _this.tableAddress.push({
//					        	  id:'',
//					        	  address: '',
//					          })
//					          table.reload('demoAddress',{
//					            data : _this.tableAddress
//					          });
//					        });
//				        table.on('tool(demo)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
//				          if (obj.event === 'del') {
//				             console.log("删除操作",obj)
//				            var dataList = []
//				            obj.del();
//				            var arr = []
//				            _this.tableData.forEach(function(item,index){
//				              dataList.push(item)
//				              if(obj.data.materialName == item.materialName){
//				                arr.push(index)
//				              }
//				            })
//				            dataList.splice(arr[0],1);
//				            _this.tableData = dataList;
//				             console.log(_this.tableData,'deleteAfter')
//				          }else if(obj.event === 'setSign') {
//				            if (!$(".addMeatrial #orgId").attr('org__id')) {
//				              layer.msg("请选择项目");
//				              $("td").data('edit', false)
//				              return false;
//				            }
//				            $("td[data-field='name']").data('edit', 'text')
//				          }
//				        });
//				        table.on('tool(demoAddress)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
//					          if (obj.event === 'del') {
//					            var dataList = []
//					            obj.del();
//					            var arr = []
//					            _this.tableAddress.forEach(function(item,index){
//					              dataList.push(item)
//					              if(obj.data.address == item.address){
//					                arr.push(index)
//					              }
//					            })
//					            dataList.splice(arr[0],1);
//					            _this.tableAddress = dataList;
//					          }else if(obj.event === 'setSign') {
//					            if (!$(".addMeatrial #orgId").attr('org__id')) {
//					              layer.msg("请选择项目");
//					              $("td").data('edit', false)
//					              return false;
//					            }
//					            $("td[data-field='name']").data('edit', 'text')
//					          }
//					        });
//				        //关闭弹窗
//				        $(".close-btn,.cancel-add-btn,.cancle-add-btn").on("click", function () {
//				          $(".dialog-wp").remove();
//				        });
//				        //确认添加
//				        $(".sure-add-btn").on("click", function () {
//				          var materialJson = []
//				          var addrssJson=[]
//				          _this.tableData.forEach(function(item,index){
//				            if(item.name != ''){
//				            	materialJson.push(item)
//				            }
//				          })
//				          _this.tableAddress.forEach(function(item,index){
//				            if(item.name != ''){
//				            	addrssJson.push(item)
//				            }
//				          })
//				          if (!$(".addMeatrial #orgId").attr('org__id')) {
//				            layer.msg("请选择项目");
//				            return false;
//				          }
//				          _this.submitAddMaterial(JSON.stringify(materialJson,addrssJson),function () {
//				            $(".dialog-wp ").remove();
//				            _this.againRenderTable();
//				          });
//				        });
      });

      //功能配置-对话框确定
      $(".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)
        var checkFloor = $("#checkFloor").prop("checked") ? 1 : 0;

        var supportReport = $("#supportRepairReport").prop("checked") ? 1 : 0;
        var sendConfirm = $("#SendConfirm").prop("checked") ? 1 : 0;

        var isCompleteDesc = $("#describeField").val();
        var isCompletePhoto = $("#photoField").val();


        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,
          checkFloor: checkFloor,
          supportReport: supportReport,
          isDeliveryConfirm: sendConfirm,
          isCompleteDesc: isCompleteDesc,
          isCompletePhoto: isCompletePhoto
        }
        _this.saveDataInfo(data);
      });
      //功能配置-对话框取消
      $(".dialogCancelBtn").on("click", function () {
        console.log(11111111111111)
        $('.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);
        }
      });

      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);
      }

      // // 模糊搜索
      // _this.search_fuzzy()
      // _this.serach_project()
      // _this.serach_project_code()
      // _this.getProjectList();
      // _this.search_haocai();

    },
    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: 50
            }, {
              field: 'code',
              title: '维修单编号',
              minWidth: 200
            }, {
              field: 'repairTypeName',
              title: '维修类型',
              minWidth: 80

            }, {
              field: 'repairUser',
              title: '报修人',
              minWidth: 80
            }, {
              field: 'contactWay',
              title: '报修人手机',
              width: 120,
              templet: function (data) {
                return _this.phoneLize(data.contactWay)
              }
            }, {
              field: 'createTime',
              title: '报修时间',
              minWidth: 140
            }, {
              field: 'meetingTime',
              title: '上门时间',
              minWidth: 100,
              templet: function (data) {
                if (data.meetingTime) {
                  return data.meetingTime
                } else {
                  return '立即上门'
                }
              }

            }, {
              field: 'status',
              title: '订单状态',
              width: 80,
              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 || data.status == 11) {
                  return '已取消'
                } else if (data.status == 22) {
                  return '待派单'
                }
              }
            }, {
              field: 'repairWayName',
              title: '报修方式',
              minWidth: 80
            }, {
              field: 'repairAreaName',
              title: '维修区域',
              minWidth: 100

            },{
              field: 'confirmStatus',
              title: '确认状态',
              minWidth: 100,
              templet: function (data) {
                if (data.confirmStatus == 1) {
                  return '待确认'
                } else if (data.confirmStatus == 2) {
                  return '已确认'
                } else {
                  return ''
                }
              }
            }, {
              field: 'org_name',
              title: '项目名称',
              minWidth: 150
            }, {
              field: 'id',
              title: '操作',
              width: 250,
              maxWidth: 250,
              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>';
                  }
                }
                if (permAppeditor == 1) {
                  if (!(data.status == 8 || data.status == 10 || data.status == 11)) {
                    str += '<button class="t-btn t-red-btn t-editor-btn" data-id=' + data.id + ' data-type="1">编辑</button>';
                  }
                }
                if (permAppecancel == 1) {
                  if (!(data.status == 8 || data.status == 10 || data.status == 11)) {
                    str += '<button class="t-btn t-red-btn t-cancel-btn" data-id=' + data.id + '>取消</button>';
                  }
                }
                str += "<span data-id=" + data.id + " data-type='2'" + " class='check-blue-btn'>详情<span>";
                return str;
              }

            }
            // ,
            // {
            //   field:'id',
            //   title: '',
            //   width: 80,
            //   fixed: 'right',
            //   templet: function(data){
            // 	  return "<span data-id="+data.id+" data-status= "+data.status+" class='check-blue-btn'>详情<span>"
            //   }
            // }
          ]]
          , 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 type = $(this).data("type");
              //查看订单详情
              _this.ajaxDetail(id, type);
            });
            //拒绝
            $(".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-editor-btn").on("click", function () {
              var id = $(this).data("id");
              var type = $(this).data("type");

              //查看订单详情
              _this.ajaxDetail(id, type);
            });
            //取消订单
            $(".t-cancel-btn").on("click", function () {
              var id = $(this).data("id");

              $("body").append(template.render(tpl.decondaryTpl)({
                id: id
              }));
              //取消
              $(".cancelAlert").on("click", function () {
                $(this).closest(".dialog-wp").remove();
              });
              //确定
              $(".determineAlert").on("click", function () {
                //取消订单
                _this.cancelAjaxType(id);
                $(this).closest(".dialog-wp").remove();
              });

            });
            //派单
            $(".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 () {
          var org_Id = $("#conditionform #orgId").attr('org__id');
          if (!org_Id && userType != 1 && userType != 2) {
            layer.msg('请选择项目')
            return;
          }
          _this.againRenderTable();
        });
      });
    },
    /**
     * 手机号中间4位数字用*代替
     * @param data 原始数据
     */
    phoneLize: function (data) {
      if (data) {
        let start = data.slice(0, 3)
        let end = data.slice(-4)
        return start + '****' + end
      }
    },
    renderMaterialTable: function () {
      let _this = this
      $("body").append(template.render(tpl.addMeatrial)({
        orgList: orgList,
      }));

      //执行渲染
      console.log("tableData", _this.tableData)
      table.render({
        elem: '#demo', data: _this.tableData, height: 250, limit: 100, cols: [[
          {field: 'id', title: '耗材编号', width: 100, event: 'setSign',},
          {field: 'materialName', title: '耗材名称', width: 300, event: 'setSign', edit: 'true'},
          {
            title: '操作',
            width: 80,
            templet: function (data) {
              var str = '';
              str += '<button class="t-delete-btn" style="border:0;background:#fff;color:red;cursor:pointer" lay-event="del">删除</button>';
              return str;
            }
          }
        ]],
        id: 'testReloadMaterial'
        , done: function (res, curr, count) {
          // console.log(res.data,111)
        }
      });
      table.render({
        elem: '#demoAddress'
        , data: _this.tableAddress, height: 250, limit: 100
        , cols: [[
          {field: 'id', title: '地址编号', width: 100, event: 'setSign'},
          {field: 'address', title: '维修地址', width: 300, event: 'setSign', edit: 'true'}
          , {
            title: '操作',
            width: 80,
            templet: function (data) {
              var str = '';
              str += '<button class="t-delete-btn" style="border:0;background:#fff;color:red;cursor:pointer" lay-event="del">删除</button>';
              return str;
            }
          }
        ]],
        id: 'testReloadAddress'
        , done: function (res, curr, count) {
          // console.log(res.data,111)
        }
      });
      //监听单元格编辑
      table.on('edit(demo)', function (obj) {
        var value = obj.value //得到修改后的值
          , data = obj.data //得到所在行所有键值
        console.log(obj, '编辑');
        if (obj.field == "materialName") {
          if (value.length > 50) {
            $(this).val(value.substring(0, 50))
            data.materialName = value.substring(0, 50)
            layer.msg("名称最多50个字符");
          } else {
            data.materialName = value
          }
        }
        _this.tableData.forEach(function (item, index) {
          if (obj.data.LAY_TABLE_INDEX == index) {
            _this.tableData[index].materialName = obj.data.materialName;
            _this.tableData[index].id = obj.data.id;
          }
        })
        //编辑一条之后保存或者修改
//		          console.log(tableData,'编辑材料完成')
        _this.addOrUpdateMaterial(data.id, data.materialName);

      });
      table.on('edit(demoAddress)', function (obj) {
        var value = obj.value //得到修改后的值
          , data = obj.data //得到所在行所有键值
        console.log(data, 'dataaddress');
        if (obj.field == "address") {
          if (value.length > 50) {
            $(this).val(value.substring(0, 50))
            data.address = value.substring(0, 50)
            layer.msg("名称最多50个字符");
          } else {
            data.address = value
          }
        }
        _this.tableAddress.forEach(function (item, index) {
          if (obj.data.LAY_TABLE_INDEX == index) {
            _this.tableAddress[index].address = obj.data.address;
            _this.tableAddress[index].id = obj.data.id;
          }
        })
        console.log(_this.tableAddress[0].id, _this.tableAddress[0].address, '编辑完成')
        //编辑一条之后保存或者修改
        _this.addOrUpdateAddress(data.id, data.address);
      });
      $(".addBtn button").on("click", function () {
        console.log('添加材料之前', _this.tableData);
        _this.tableData.unshift({
          id: '',
          materialName: '',
        })
        table.reload('testReloadMaterial', {
          data: _this.tableData
        });
      });
      $(".addBtnAddress button").on("click", function () {
        _this.tableAddress.unshift({
          id: '',
          address: '',
        })
        table.reload('testReloadAddress', {
          data: _this.tableAddress
        });
      });
      table.on('tool(demo)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
        if (obj.event === 'del') {
          console.log("删除操作", obj.data.id)
          _this.delectMaterialItem(obj.data.id)
          var dataList = []
          obj.del();
          var arr = []
          _this.tableData.forEach(function (item, index) {
            dataList.push(item)
            if (obj.data.materialName == item.materialName) {
              arr.push(index)
            }
          })
          dataList.splice(arr[0], 1);
          _this.tableData = dataList;
          console.log(tableData, 'deleteAfter')
        } else if (obj.event === 'setSign') {
          if (!$(".addMeatrial #orgId").attr('org__id')) {
            layer.msg("请选择项目");
            $("td").data('edit', false)
            return false;
          }
          $("td[data-field='name']").data('edit', 'text')
        }
      });
      table.on('tool(demoAddress)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
        if (obj.event === 'del') {
          _this.delectAddressItem(obj.data.id)
          var dataList = []
          obj.del();
          var arr = []
          _this.tableAddress.forEach(function (item, index) {
            dataList.push(item)
            if (obj.data.address == item.address) {
              arr.push(index)
            }
          })
          dataList.splice(arr[0], 1);
          _this.tableAddress = dataList;
        } else if (obj.event === 'setSign') {
          if (!$(".addMeatrial #orgId").attr('org__id')) {
            layer.msg("请选择项目");
            $("td").data('edit', false)
            return false;
          }
          $("td[data-field='name']").data('edit', 'text')
        }
      });
      //关闭弹窗
      $(".close-btn,.cancel-add-btn,.cancle-add-btn").on("click", function () {
        $(".dialog-wp").remove();
      });
      $(".sure-add-btn").on("click", function () {
        $(".dialog-wp").remove();
      });
      //确认添加
//		        $(".sure-add-btn").on("click", function () {
//		          var materialJson = []
//		          var addrssJson=[]
//		          _this.tableData.forEach(function(item,index){
//		            if(item.name != ''){
//		            	materialJson.push(item)
//		            }
//		          })
//		          _this.tableAddress.forEach(function(item,index){
//		            if(item.name != ''){
//		            	addrssJson.push(item)
//		            }
//		          })
//		          if (!$(".addMeatrial #orgId").attr('org__id')) {
//		            layer.msg("请选择项目");
//		            return false;
//		          }
//		          _this.submitAddMaterial(JSON.stringify(materialJson,addrssJson),function () {
//		            $(".dialog-wp ").remove();
//		            _this.againRenderTable();
//		          });
//		        });
    },
    //删除单条材料
    delectMaterialItem: function (id) {
      console.log("id", id)
      layer.confirm('确定删除?', {
        btn: ['确定', '取消']
      }, function (index, layero) {
        layer.close(index); //如果设定了yes回调，需进行手工关闭
        $.ajax({
          type: "post",
          url: $("#contextPath").val() + "/repairMaterial/delete",
          data: {
            "id": id
          },
          success: function (data) {
            if (data.code == 200) {
//									   callback();
            }
          },
          error: function () {
          }
        });
      }, function (index) {

      });
    },
    //删除单条地址
    delectAddressItem: function (id) {

      layer.confirm('确定删除?', {
        btn: ['确定', '取消']
      }, function (index, layero) {
        layer.close(index); //如果设定了yes回调，需进行手工关闭
        $.ajax({
          type: "post",
          url: $("#contextPath").val() + "/repairAddress/delete",
          data: {
            "id": id
          },
          success: function (data) {
            if (data.code == 200) {
//									   callback();
            }
          },
          error: function () {
          }
        });
      }, function (index) {

      });
    },
    //弹框出现，查询材料的列表，初始化材料列表
    getMaterListByOrgIdFirst: function (orgid) {
      var _this = this;
      var formData = new FormData();
      formData.append("orgId", orgid);
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairMaterial/getMaterialList",
        data: formData,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
            console.log("材料列表 ", data.data)
            _this.tableData = data.data
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },
    //弹框出现，查询材料的列表，初始化材料列表
    getMaterListByOrgId: function (orgid) {
      var _this = this;
      var formData = new FormData();
      formData.append("orgId", orgid);
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairMaterial/getMaterialList",
        data: formData,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
            console.log("材料列表 ", data.data)
            _this.tableData = data.data
            table.reload('testReloadMaterial', {
              data: _this.tableData
            });

          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },
    getAddressListByOrgIdFirst: function (orgid) {
      var _this = this;
      var formData = new FormData();
      formData.append("orgId", orgid);
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairAddress/getAddressList",
        data: formData,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
            console.log("地址列表 ", data.data)
            _this.tableAddress = data.data
            setTimeout(function () {
              _this.renderMaterialTable()
            }, 500)
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },

    //弹框出现，查询地址的列表，初始化地址列表
    getAddressListByOrgId: function (orgid) {
      var _this = this;
      var formData = new FormData();
      formData.append("orgId", orgid);
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairAddress/getAddressList",
        data: formData,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
            console.log("地址列表 ", data.data)
            _this.tableAddress = data.data
            table.reload('testReloadAddress', {
              data: _this.tableAddress
            });
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },

    //新增单条地址
    addOrUpdateAddress: function (id, addressName) {
      var _this = this;
      var formData = new FormData();
      if (id != undefined) {
        formData.append("id", id);
      }
      formData.append("address", addressName);
      formData.append("orgId", $(".addMeatrial #orgId").attr('org__id'));
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairAddress/addOrUpdate",
        data: formData,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
            _this.getAddressListByOrgId($(".addMeatrial #orgId").attr('org__id'))

          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },
    //新增单条耗材
    addOrUpdateMaterial: function (id, materialName) {
      console.log("11111")
      var _this = this;
      var formData = new FormData();
      if (id != undefined) {
        formData.append("id", id);
      }
      formData.append("materialName", materialName);
      formData.append("orgId", $(".addMeatrial #orgId").attr('org__id'));
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairMaterial/addOrUpdate",
        data: formData,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
            _this.getMaterListByOrgId($(".addMeatrial #orgId").attr('org__id'))
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },
    //批量添加添加地址
    submitAddAddress: function (addressJson, callback) {
      var _this = this;
      var formData = new FormData();
      formData.append("addressList", addressJson);
      formData.append("orgId", $(".addMeatrial #orgId").attr('org__id'));
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairAddress/addOrUpdateBatch",
        data: formData,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
            callback();
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },
    //批量确定添加材料的接口
    submitAddMaterial: function (materialJson, addressJson, callback) {
      var _this = this;
      var formData = new FormData();
      formData.append("repairMaterialDtoList", materialJson);
      formData.append("orgId", $(".addMeatrial #orgId").attr('org__id'));
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairMaterial/addOrUpdateBatch",
        data: formData,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
            _this.submitAddAddress(addressJson, callback)
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },
    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);
    },
    search_gencode: 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: '.gencode-selectt#orgId',
        com_target: '.default-select#companyId',
        dep_target: '.default-select#apartId',
      });
      var option_2 = $.extend(true, {}, default_option, {
        org_target: '.gencode-select#orgId',
        com_target: '.pop-select#companyId',
      });
      var option_3 = $.extend(true, {}, default_option, {
        org_target: '.d-orgid',
        com_target: '.d-companyid'
      });

      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})
      eve(option_2, {
        type: 2,
        click_callback: function () {
          $("td[data-field='name']").data('edit', 'text')
          $("td[data-field='orderNum']").data('edit', 'number')
          $("td[data-field='shortName']").data('edit', 'text')
          // $("td").data('edit', 'text')
        }
      })
      //导入联动
      eve(option_3, {type: 1})
      eve(option_3, {type: 2})
    },
    search_haocai: 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#apartId',
      });
      var option_2 = $.extend(true, {}, default_option, {
        org_target: '.pop-select#orgId',
        com_target: '.pop-select#companyId',
      });
      var option_3 = $.extend(true, {}, default_option, {
        org_target: '.d-orgid',
        com_target: '.d-companyid'
      });

      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})
      eve(option_2, {
        type: 2,
        click_callback: function () {
          $("td[data-field='name']").data('edit', 'text')
          $("td[data-field='orderNum']").data('edit', 'number')
          $("td[data-field='shortName']").data('edit', 'text')
          // $("td").data('edit', 'text')
        }
      })
      //导入联动
      eve(option_3, {type: 1})
      eve(option_3, {type: 2})
    },
    getProjectList: function () {
      var _this = this;
      $.ajax({
        type: "post",
        url: contextPath + "/admin/templ/getOrgList",
        success: function (data) {
          if (data.code == 200) {
            orgList = data.data;
          } else {
            layer.msg(data.msg)
          }
          $(".addMeatrial #orgId").on("change", function () {
            var that = this
            setTimeout(function () {
              var id = $(that).attr('org__id');
              _this.getMaterListByOrgId(id);
              _this.getAddressListByOrgId(id)
            }, 200)

          })

        },
        error: function (error) {
          layer.msg('error')
        }
      });
    },
    /*重新渲染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(),
            managerName: $(".send-single").val(),
            confirmStatus: $("#confirmStatus").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(),
            managerName: $(".send-single").val(),
            confirmStatus: $("#confirmStatus").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,
          "checkFloor": data.checkFloor,
          "supportReport": data.supportReport,
          "isCompleteDesc": data.isCompleteDesc,
          "isCompletePhoto": data.isCompletePhoto,
          "isDeliveryConfirm": data.isDeliveryConfirm
        },
        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')
        }
      });
    },
    /**
     * 请求大类
     * @param id
     *
     */
    ajaxAllType: function (id) {
      var _this = this;
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairType/getTypeList",
        data: {
          orgId: id
        },
        success: function (data) {
          if (data.code == 200) {
            repairAreaGroup = data.data['repairTypeGroup'];
            if (maxTypeId != '' && maxTypeId != null && maxTypeId != undefined) {
              _this.ajaxType(maxTypeId);
            }
          } else {
            layer.msg(data.msg);
          }
          $("body").append(template.render(tpl.editorTpl)({
            maxTypeId: maxTypeId,
            baseDto: orderDetails.baseDto,
            detailDto: orderDetails.detailDto,
            operateDto: orderDetails.operateDto,
            repairAreaGroup: repairAreaGroup,
            repairTypeaDetailGroup: repairTypeaDetailGroup
          }));
          //关闭编辑弹窗
          $(".close-btn").on("click", function () {
            $(this).closest(".dialog-wp").remove();
          });
          $(".dialog .repair-img-item .img").zoomify();
          $(".dialog .comp-img-box .img").zoomify();

          //大类选中
          $(".maxType-change").on("change", function () {
            console.log('选中大类！', $(this)[0].value);
            maxTypeId = $(this)[0].value;
            if (maxTypeId === 0) {
              maxTypeId = '';
              repairTypeaDetailGroup = [];
              $("#minType").html(template.render(tpl.minTypeTpl)({
                repairTypeaDetailGroup: repairTypeaDetailGroup
              }));
            } else {
              _this.ajaxType(maxTypeId);
            }
          });
          //小类选中
          $(".minType-change").on("change", function () {
            console.log('选中小类！', $(this)[0].value);
            minTypeId = $(this)[0].value;
            if (maxTypeId == 0) {
              maxTypeId = '';
            }
          });
          //确定
          $(".send-editor").on("click", function () {
            if (maxTypeId == '' || maxTypeId == null || maxTypeId == undefined) {
              layer.msg('未选择大类');
            } else if (minTypeId == '' || minTypeId == null || minTypeId == undefined) {
              layer.msg('未选择小类');
            } else {
              _this.saveAjaxType(orderDetails.baseDto.id);
            }
          });
        },
        error: function () {
        }
      });
    },
    /**
     * 请求小类
     * @param repairTypeId
     *
     */
    ajaxType: function (repairTypeId) {
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairType/getTypeItemList",
        data: {
          repairTypeId: repairTypeId
        },
        success: function (data) {
          if (data.code == 200) {
            repairTypeaDetailGroup = data.data;
            if (minTypeId == '' || minTypeId == null || minTypeId == undefined) {
              minTypeId = 0;
            }
            $("#minType").html(template.render(tpl.minTypeTpl)({
              minTypeId: minTypeId,
              repairTypeaDetailGroup: repairTypeaDetailGroup
            }));
          } else {
            layer.msg(data.msg);
          }
        },
        error: function () {
        }
      });
    },
    /**
     * 保存修改
     * @param id订单ID
     */
    saveAjaxType: function (id) {
      let _this = this;
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairBill/updateBillType",
        data: {
          id: id,
          repairTypeId: maxTypeId,
          repairTypeDetailId: minTypeId
        },
        success: function (data) {
          if (data.code == 200) {
            $(".dialog-wp").remove();
            _this.againRenderTable()
          } else {
            layer.msg(data.msg);
          }
        },
        error: function () {
        }
      });
    },
    /**
     * 取消订单
     * @param id订单ID
     */
    cancelAjaxType: function (id) {
      let _this = this;
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/repairBill/cancelOrder",
        data: {
          id: id
        },
        success: function (data) {
          if (data.code == 200) {
            _this.againRenderTable()
          } else {
            layer.msg(data.msg);
          }
        },
        error: function () {
        }
      });
    },
    // 模糊搜索事件
    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})
    },

    serach_project_code: 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#organId',
        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 = $("#organId").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 type 功能跳转：1.编辑页 2.详情页
     *
     */
    ajaxDetail: function (id, type) {
      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') {
            orderDetails = data.data;
            if (type == 1) {
              maxTypeId = orderDetails.baseDto.repairTypeId;
              minTypeId = orderDetails.baseDto.repairTypeDetailId;
              for (var i = 0; i < dataList.length; i++) {
                if (id == dataList[i].id) {
                  var orgId = dataList[i].orgId;
                  _this.ajaxAllType(orgId)
                }
              }
            } else {
              $("body").append(template.render(tpl.detailTpl)(orderDetails));
              //关闭详情弹窗
              $(".close-btn").on("click", function () {
                $(this).closest(".dialog-wp").remove();
              });
              $(".dialog .repair-img-item .img").zoomify();
              $(".dialog .comp-img-box .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();
})
