| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537 | /** * 编办管理相关js * * @author CaiAoLin * @date 2017/7/28 * @version */const delayTime = 500;let keyupTime;function delayKeyup(callback) {  let nowTime = Date.now();  keyupTime = nowTime;  setTimeout(function () {    if (nowTime - keyupTime == 0 && callback) {      callback();    }  }, delayTime);}$(document).ready(function () {  let isAdding = false;  let model = "";  let section =    $(".nav-tabs li.active > a").text() === "建议估算" ? "suggestion" : "bill";  let id = $("#compilation-id").val();  // 计价规则页面初始化数据  if ($("#save-lib").length > 0) {    initCompilation();  }  // 计价类型选择  $(".nav-tabs li > a").click(function () {    section = $(this).attr("aria-controls");  });  // 新增编办  $("#add-compilation").click(function () {    try {      let data = getAndValidData(model);      let url = "/compilation/add";      if (model === "all") {        // 新增编办操作        $.ajax({          url: url,          type: "post",          data: { name: data.name },          error: function () {            isAdding = false;          },          beforeSend: function () {            isAdding = true;          },          success: function (response) {            isAdding = false;            if (response.err === 0) {              window.location.reload();            } else {              let msg = response.msg === undefined ? "未知错误" : response.msg;              alert(msg);            }          },        });      } else {        // 新增标准清单/定额库        let addLib = {          name: data[model].name,          id: data[model].id,        };        // 判断是否有重复的数据        if (          $(            "input:hidden[name='" +              model +              "_lib'][data-id='" +              addLib.id +              "']"          ).length > 0        ) {          alert("重复添加数据!");          return false;        }        let removeHtml =          '<a class="pull-right text-danger remove-lib" data-model="' +          model +          '" ' +          'title="移除"><span class="glyphicon glyphicon-remove"></span></a>';        let tmpHtml =          '<p class="form-control-static">' +          removeHtml +          addLib.name +          '<input type="hidden" data-id="' +          addLib.id +          "\" name='" +          model +          "_lib' value='" +          JSON.stringify(addLib) +          "'>" +          "</p>";        $("." + model + "-list").append(tmpHtml);        $("#addcompilation").modal("hide");      }    } catch (error) {      alert(error);    }  });  $("#addTaxGroupBtn").click(function () {    $("#groupEditType").val("add");    $("#taxType").val("");    $("#program_lib").val("");    $("#template_lib").val("");    $("#col_lib").val("");    $("#fee_lib").val("");  });  //新增计税组合  $("#add-group").click(function () {    let taxMap = { 1: "一般计税", 2: "简易计税" };    let actionType = $("#groupEditType").val();    let groupData = getTaxGroupData();    let groupIndex = getGroupIndex(groupData); //用来做重复判断    if (!_.isEmpty(groupData)) {      //重复判断 todo      if ($("input[data-id = " + groupIndex + "]").length <= 0) {        let taxName = groupData.taxType ? taxMap[groupData.taxType] : "";        let p_name = groupData.program_lib          ? groupData.program_lib.displayName          : "";        let t_name = groupData.template_lib ? groupData.template_lib.name : "";        let c_name = groupData.col_lib ? groupData.col_lib.name : "";        let f_name = groupData.fee_lib ? groupData.fee_lib.name : "";        let htmlString =          "<tr class='taxGroup_tr'><td><span>" +          taxName +          "</span></td>" +          "<td><span>" +          p_name +          "</span></td>" +          "<td><span>" +          t_name +          "</span></td>" +          "<td><span>" +          c_name +          "</span></td>" +          "<td><span>" +          f_name +          "</span></td>" +          "<td> <a class='btn btn-link btn-sm' style='padding: 0px' onclick='editTaxGroup(this)'> 编辑</a>/<a class='btn btn-link btn-sm ' style='padding: 0px' onclick='deleteTableTr(this,\"taxGroup_tr\")'>删除</a> " +          "<input type='hidden' name='tax_group' data-id ='" +          groupIndex +          "' value='" +          JSON.stringify(groupData) +          "'>" +          "</td>" +          "</tr>";        if (actionType == "add") {          $("#tax_group_tbody").append(htmlString);        } else if (actionType == "modify") {          let oldIndex = $("#groupIndex").val();          let parentTr = $("input[data-id = " + oldIndex + "]").parents(            ".taxGroup_tr"          );          parentTr.after(htmlString);          parentTr.remove();        }      } else {        alert("已存在相同的组合!");      }    }    $("#addTaxGroup").modal("hide");  });  $("#addRatioBtn").click(function () {    let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);    let unSelectLibs = [];    for (let lib of rationLibData) {      if (        $("input:hidden[name=ration_lib][data-id = " + lib.id + "]").length > 0      ) {        continue;      }      unSelectLibs.push(lib);    }    let html = "";    for (let tmp of unSelectLibs) {      let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";      html += tmpHtml;    }    $("select[name='ration_lib']").html(html);  });  $("#addRatioBtn").click(function () {    let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);    let unSelectLibs = [];    for (let lib of rationLibData) {      if (        $("input:hidden[name=ration_lib][data-id = " + lib.id + "]").length > 0      ) {        continue;      }      unSelectLibs.push(lib);    }    let html = "";    for (let tmp of unSelectLibs) {      let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";      html += tmpHtml;    }    $("select[name='ration_lib']").html(html);  });  $("#ration_lib-search-box").on("input", function () {    var keyword = $(this).val().toLowerCase().trim(); // 获取输入的关键字并转为小写    // 遍历所有option元素    $('select[name="ration_lib"] option').each(function () {      var optionText = $(this).text().toLowerCase(); // 获取option的文本并转为小写      // 如果option文本包含关键字,则显示,否则隐藏      if (optionText.indexOf(keyword) !== -1) {        $(this).show();      } else {        $(this).hide();      }    });  });  //新增定额库  $("#add-ration").click(function () {    const options = $("select[name='ration_lib']").children("option:selected");    let alertArr = [];    let htmlString = "";    for (const option of options) {      const rationLib = $(option).val();      const rationLibString = $(option).text();      if (!rationLib) {        alertString.push(`“${rationLibString}”为无效定额库`);        continue;      }      if (        $("input:hidden[name=ration_lib][data-id = " + rationLib + "]").length >        0      ) {        alertArr.push(`“${rationLibString}”已存在`);        continue;      }      const tem = {        id: rationLib,        name: rationLibString,        onlyProfession: false,        isDefault: false,      };      htmlString += `                 <tr class='ration_tr' draggable="true">                    <td><span class="cursor-default">${tem.name}</span></td>                     <td><label class="form-check-label"> <input class="form-check-input" name="ration_onlyProfession"  value="${                       tem.id                     }" type="checkbox"></td>                     <td><label class="form-check-label"> <input class="form-check-input" name="ration_isDefault"  value="${                      tem.id                    }" type="radio"></td>                      <td>                        <a class='btn btn-link btn-sm ' style="padding: 0px" onclick='deleteTableTr(this,"ration_tr")'>删除</a>                        <input type="hidden" name="ration_lib" data-id="${                          tem.id                        }" value='${JSON.stringify(tem)}'>                    </td>                </tr>`;    }    if (alertArr.length) {      alert(alertArr.join("\n"));    } else {      $("#ration_tbody").append(htmlString);      $("#addRation").modal("hide");    }  });  // 复制定额库  $("#copy-lib-confirm").click(async function () {    try {      $.bootstrapLoading.start();      const [valuationID, engineeringID] = window.location.pathname        .split("/")        .slice(-2);      await ajaxPost("/compilation/copyRationLibs", {        valuationID,        engineeringID,      });    } catch (err) {      console.log(err);    } finally {      $.bootstrapLoading.end();    }  });  // 拖动排序  const dragSelector = ".ration_tr[draggable=true]";  const rationBodySelector = "#ration_tbody";  const wrapper = $(".panel-content")[0];  let dragged;  let rID = null;  const scrollStep = 6;  // 表格数据过多的时候,靠下方的条目想要移动到上方,需要滚动条滚动到相应位置,滚动条向上滚动需要代码自行处理  function scroll(ele, step) {    wrapper.scrollTop -= step;    rID = window.requestAnimationFrame(() => {      scroll(ele, step);    });  }  // 动态绑定(新增的也能监听到)  $(rationBodySelector).on("drag", dragSelector, function (ev) {    const { clientX, clientY } = ev;    const dom = document.elementFromPoint(clientX, clientY);    if (dom.tagName === "H2" && !rID) {      rID = window.requestAnimationFrame(() => {        scroll(wrapper, scrollStep);      });    } else if (dom.tagName !== "H2" && rID) {      window.cancelAnimationFrame(rID);      rID = null;    }  });  $(rationBodySelector).on("dragstart", dragSelector, function (ev) {    dragged = this;    $(this).addClass("dragging");    ev.originalEvent.dataTransfer.effectAllowed = "move";  });  $(rationBodySelector).on("dragend", dragSelector, function (ev) {    $(this).removeClass("dragging");    if (rID) {      window.cancelAnimationFrame(rID);      rID = null;    }  });  $(rationBodySelector).on("dragover", dragSelector, function (ev) {    ev.preventDefault(); // 必须调用此方法,否则drop事件不触发  });  $(rationBodySelector).on("dragenter", dragSelector, function (ev) {    if (this !== dragged) {      $(this).addClass("highlight");    }  });  $(rationBodySelector).on("dragleave", dragSelector, function (ev) {    if (this !== dragged) {      $(this).removeClass("highlight");    }  });  $(rationBodySelector).on("drop", dragSelector, function (ev) {    $(this).removeClass("highlight");    $(this).after($(dragged));  });  // 新增计价规则  $("#add-valuation").click(function () {    try {      if (id === "") {        throw "页面数据有误";      }      let name = $("input[name='valuation_name']").val();      if (name === "") {        throw "请填写计价规则名称";      }      $.ajax({        url: "/compilation/add-valuation",        type: "post",        data: { name: name, id: id, section: section },        error: function () {          isAdding = false;        },        beforeSend: function () {          isAdding = true;        },        success: function (response) {          isAdding = false;          if (response.err === 0) {            window.location.reload();          } else {            let msg = response.msg === undefined ? "未知错误" : response.msg;            alert(msg);          }        },      });    } catch (error) {      alert(error);      return false;    }  });  // 排序点击  $("#openBillSort").click(function () {    let html = "";    const libs = $("input:hidden[name='bill_lib']");    for (let libEle of libs) {      let lib = JSON.parse($(libEle).val());      html += `      <p class="form-control-static billLibItem">      <a class="pull-right "  title="上移" id="list_${lib.id}" onclick="libUp(${        lib.id      })">          <span class="glyphicon glyphicon-arrow-up"></span>          <input type="hidden" class="sort_temp_value"  value='${JSON.stringify(            { id: lib.id, name: lib.name }          )}'>      </a>      <a class="pull-right stdBillUp"  title="下移" onclick="libDown(${        lib.id      })">          <span class="glyphicon glyphicon-arrow-down"></span>      </a>      ${lib.name}     </p> `;    }    $("#stdBillList").html(html);    $("#stdBillSort").modal("show");  });  $("#billSortConfirm").click(function () {    let html = "";    const libs = $(".sort_temp_value");    libs.each(function (index) {      const lib = JSON.parse($(this).val());      html += `      <p class="form-control-static">        <a class="pull-right text-danger remove-lib" data-model="bill" title="移除">          <span class="glyphicon glyphicon-remove"></span>        </a>        <input type="hidden" name="bill_lib" data-id="${          lib.id        }" value='${JSON.stringify({ id: lib.id, name: lib.name })}'>        ${index === 0 ? '<i class="glyphicon glyphicon-flag"></i> ' : ""}${        lib.name      }      </p>`;    });    $(".bill-list").html(html);    $("#stdBillSort").modal("hide");  });  // 添加  $(".add-compilation").click(function () {    model = $(this).data("model");    $("#addcompilation .modal-body > div").hide();    switch (model) {      case "all":        $("#name-area").show();        $("#add-compilation-title").text("添加新费用定额");        break;      case "bill":        $("#bill-area").show();        $("#add-compilation-title").text("添加标准清单");        break;      case "ration":        $("#ration-area").show();        $("#add-compilation-title").text("添加定额库");        break;      case "glj":        $("#glj-area").show();        $("#add-compilation-title").text("添加定额库");        break;      case "billsGuidance":        $("#billsGuidance-area").show();        $("#add-compilation-title").text("添加清单指引库");        break;      case "fee":        $("#fee-area").show();        $("#add-compilation-title").text("添加费率标准");        break;      case "artificial":        $("#artificial-area").show();        $("#add-compilation-title").text("添加人工系数");        break;      case "program":        $("#program-area").show();        $("#add-compilation-title").text("添加计算程序");        break;      case "feature":        $("#feature-area").show();        $("#add-compilation-title").text("添加工程特征");        break;      case "info":        $("#info-area").show();        $("#add-compilation-title").text("添加基本信息");        break;      case "progressive":        $("#progressive-area").show();        $("#add-compilation-title").text("添加累进区间");        break;      case "vvTax":        $("#vvTax-area").show();        $("#add-compilation-title").text("添加车船税");        break;      case "billCode":        $("#billCode-area").show();        $("#add-compilation-title").text("添加递延清单库");        break;    }    $("#addcompilation").modal("show");  });  // 保存专业工程标准库  $("#save-lib").click(function () {    if (validLib()) {      $("form").submit();    }  });  // 保存计价规则  $("#save-valuation").click(function () {    $("#saveValuation").submit();  });  // 移除操作  $(    ".bill-list, .ration-list, .glj-list, .fee-list, .artificial-list, .program-list, .billsGuidance-list,.feature-list,.info-list,.progressive-list,.vvTax-list,.billCode-list"  ).on("click", ".remove-lib", function () {    $(this).parent().remove();  });  //更改描述  $("#description").change(function () {    let description = $(this).val();    $.ajax({      url: "/compilation/setDescription",      type: "post",      dataType: "json",      data: { id: id, description: description },      success: function (response) {        if (response.err !== 0) {          alert("更改失败");        }      },    });  });  //更改代码覆盖路径  $("#overWriteUrl").change(function () {    let overWriteUrl = $(this).val();    if (overWriteUrl == "") overWriteUrl = undefined;    $.ajax({      url: "/compilation/setOverWriteUrl",      type: "post",      dataType: "json",      data: { id: id, overWriteUrl: overWriteUrl },      success: function (response) {        if (response.err !== 0) {          alert("更改失败");        }      },    });  });  //例题建设项目ID, 用英文字符;分隔建设项目ID  $("#example").keyup(function () {    let exampleVal = $(this).val();    let tempExample = exampleVal.split(/[;,;]/g),      example = [];    for (let te of tempExample) {      if (te.trim() !== "") {        example.push(te.trim());      }    }    example = Array.from(new Set(example));    delayKeyup(function () {      $.ajax({        url: "/compilation/setExample",        type: "post",        dataType: "json",        data: { id: id, example: example },        success: function (response) {          if (response.err !== 0) {            alert("更改失败");          }        },      });    });  });  // 计价规则启用/禁止  $(".enable").click(function () {    let goingChangeStatus = switchChange($(this));    let id = $(this).data("id");    if (id === undefined || id === "" || isAdding) {      return false;    }    $.ajax({      url: "/compilation/valuation/" + section + "/enable",      type: "post",      dataType: "json",      data: { id: id, enable: goingChangeStatus },      error: function () {        isAdding = false;        switchChange($(this));      },      beforeSend: function () {        isAdding = true;      },      success: function (response) {        isAdding = false;        if (response.err !== 0) {          switchChange($(this));          alert("更改失败");        }      },    });  });  // 设置适用类型  $(".fileType").change(function () {    let id = $(this).data("id");    if (id === undefined || id === "" || isAdding) {      return false;    }    let fileTypes = [];    let oldVal = $(this).attr("checked");    if (oldVal) {      $(this).removeAttr("checked");    } else {      $(this).attr("checked", "checked");    }    if ($("#" + id + "_suggest_gusuan").attr("checked")) fileTypes.push(16);    if ($("#" + id + "_investment_estimate").attr("checked")) {      fileTypes.push(17);    }    if ($("#" + id + "_gusuan").attr("checked")) fileTypes.push(15);    if ($("#" + id + "_estimate").attr("checked")) fileTypes.push(5);    if ($("#" + id + "_submission").attr("checked")) fileTypes.push(1);    if ($("#" + id + "_three_bill_budget").attr("checked")) fileTypes.push(18);    if ($("#" + id + "_bill_budget").attr("checked")) fileTypes.push(19);    if ($("#" + id + "_changeBudget").attr("checked")) fileTypes.push(4);    if ($("#" + id + "_settlement").attr("checked")) fileTypes.push(10);    let current = $(this);    console.log(id, this);    $.ajax({      url: "/compilation/valuation/" + section + "/fileTypes",      type: "post",      dataType: "json",      data: { id: id, fileTypes: fileTypes },      error: function () {        //恢复原值        if (oldVal) {          current.attr("checked", "checked");        } else {          current.removeAttr("checked");        }      },      success: function (response) {        if (response.err !== 0) {          switchChange($(this));          alert("更改失败");        }      },    });  });  //计价规则删除  $("#delete-confirm").click(function () {    let id = $("#del").attr("selectedId");    if (id === undefined || id === "") {      return false;    }    window.location.href = `/compilation/valuation/${section}/delete/${id}`;  });  // 发布编办  $("#release").click(function () {    let id = $(this).data("id");    let status = $(this).data("status");    status = parseInt(status);    if (isAdding || id === "" || isNaN(status)) {      return false;    }    $.ajax({      url: "/compilation/release",      type: "post",      data: { id: id, status: status },      dataType: "json",      error: function () {        isAdding = false;      },      beforeSend: function () {        isAdding = true;      },      success: function (response) {        isAdding = false;        if (response.err === 0) {          window.location.reload();        } else {          let msg = response.msg === undefined ? "未知错误" : response.msg;          alert(msg);        }      },    });  });  //添加工程专业  $("#addEngineerConfirm").click(async function () {    if ($("#name").val() == "") {      $("#nameError").show();      return;    }    if ($("#feeName").val() == "") {      $("#feeNameError").show();      return;    }    if ($("#engineeringInput").val() == "") {      $("#engineeringError").show();      return;    }    if ($("#projectEngineering").val() == "") {      $("#projectError").show();      return;    }    $("#addEngineerConfirm").attr("disabled", true); //防止重复提交    $("#addEngineerForm").submit();  });  //  // CLD 办事处选择  $("#category-select").change(function () {    $.ajax({      url: "/compilation/changeCategory",      type: "post",      data: { id: id, category: $(this).val() },      dataType: "json",      success: function (response) {        if (response.error !== 0) {          alert("更改失败");        }      },    });  });  // 选择默认所在地  $("#location-select").change(function () {    $.ajax({      url: "/compilation/changeLocation",      type: "post",      data: { id: id, location: $(this).val() },      dataType: "json",      success: function (response) {        if (response.error !== 0) {          alert("更改失败");        }      },    });  });  // 选择编办类型  $("#type-select").change(function () {    $.ajax({      url: "/compilation/changeCompilation",      type: "post",      data: { id: id, update: { type: $(this).val() } },      dataType: "json",      success: function (response) {        if (response.error !== 0) {          alert("更改失败");        }      },    });  });  // 修改是否提供免费版  $("#freeUse").change(function (val) {    $.ajax({      url: "/compilation/changeFreeUse",      type: "post",      data: { id: id, freeUse: $(this).prop("checked") },      dataType: "json",      success: function (response) {        if (response.error !== 0) {          alert("更改失败");        }      },    });  });  // 选择编办类型  $("#customMade").change(function () {    $.ajax({      url: "/compilation/changeCompilation",      type: "post",      data: { id: id, update: { customMade: $(this).prop("checked") } },      dataType: "json",      success: function (response) {        if (response.error !== 0) {          alert("更改失败");        }      },    });  });  //更改版本号  $("#compilationArea").change(function () {    let compilationArea = $(this).val();    $.ajax({      url: "/compilation/setCompilationArea",      type: "post",      dataType: "json",      data: { id, compilationArea },      success: function (response) {        if (response.err !== 0) {          alert("更改失败");        }      },    });  });  //更改版本号  $("#edition").change(function () {    let edition = $(this).val();    $.ajax({      url: "/compilation/setEdition",      type: "post",      dataType: "json",      data: { id: id, edition: edition },      success: function (response) {        if (response.err !== 0) {          alert("更改失败");        }      },    });  });  //更改序号  $("#serialNumber").change(function () {    let serialNumber = Number($(this).val());    $.ajax({      url: "/compilation/setSerialNumber",      type: "post",      dataType: "json",      data: { id: id, serialNumber: serialNumber },      success: function (response) {        if (response.err !== 0) {          alert("更改失败");        }      },    });  });});function libUp(id) {  const $item = $(`#list_${id}`).closest(".billLibItem");  const $prevItem = $item.prev();  if ($prevItem.length) {    $item.fadeOut(200, function () {      $prevItem.before($item);      $item.fadeIn(200);    });  }}function libDown(id) {  const $item = $(`#list_${id}`).closest(".billLibItem");  const $nextItem = $item.next();  if ($nextItem.length) {    $item.fadeOut(200, function () {      $nextItem.after($item);      $item.fadeIn(200);    });  }}/** * 初始化 * * @return {void|boolean} */function initCompilation() {  let billListData = billList === undefined ? [] : JSON.parse(billList);  let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);  let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);  let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);  let artificialCoefficientData =    artificialCoefficientList === undefined      ? []      : JSON.parse(artificialCoefficientList);  let programData = programList === undefined ? [] : JSON.parse(programList);  let billsGuidanceData =    billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);  let billTemplateData =    billTemplateList == undefined ? [] : JSON.parse(billTemplateList);  let mainTreeColData =    mainTreeColList == undefined ? [] : JSON.parse(mainTreeColList);  let featureData = featureList == undefined ? [] : JSON.parse(featureList);  let infoData = infoList == undefined ? [] : JSON.parse(infoList);  let progressiveData =    progressiveList == undefined ? [] : JSON.parse(progressiveList);  let vvTaxData = vvTaxList == undefined ? [] : JSON.parse(vvTaxList);  let billCodeData = billCodeList == undefined ? [] : JSON.parse(billCodeList);  /*mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;    billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');    let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);    // 初始化 造价书列设置    colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);    let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});    billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));    if (mainTreeCol !== '' && mainTreeColObj.cols.length > 0) {        TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());        TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);    }*/  /*     if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {        return false;    } */  // 标准清单  let html = "";  for (let tmp of billListData) {    let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='standard_bill']").children("option").first().after(html);  // 定额库  html = "";  for (let tmp of rationLibData) {    let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='ration_lib']").html(html);  // 工料机库  html = "";  for (let tmp of gljLibData) {    let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='glj_lib']").children("option").first().after(html);  // 清单指引库  html = "";  for (let tmp of billsGuidanceData) {    let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='billsGuidance_lib']").children("option").first().after(html);  // 人工系数标准库  html = "";  for (let tmp of artificialCoefficientData) {    let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='artificial_lib']").children("option").first().after(html);  // 计算程序标准库  html = "";  for (let tmp of programData) {    let tmpHtml =      '<option value="' + tmp.id + '">' + tmp.displayName + "</option>";    html += tmpHtml;  }  $("select[name='program_lib']").children("option").first().after(html);  //模板库  html = "";  for (let tmp of billTemplateData) {    let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='template_lib']").children("option").first().after(html);  //列设置  html = "";  for (let tmp of mainTreeColData) {    let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='col_lib']").children("option").first().after(html);  // 费率标准库  html = "";  for (let tmp of feeLibData) {    let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='fee_lib']").children("option").first().after(html);  //工程特征库  html = "";  for (let tmp of featureData) {    let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='feature_lib']").children("option").first().after(html); //工程特征库  //基本信息库  html = "";  for (let tmp of infoData) {    let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='info_lib']").children("option").first().after(html);  //累进区间库  html = "";  for (let tmp of progressiveData) {    let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='progressive_lib']").children("option").first().after(html);  //车船税文件  html = "";  for (let tmp of vvTaxData) {    let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='vvTax_lib']").children("option").first().after(html);  //递延清单库文件  html = "";  for (let tmp of billCodeData) {    let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";    html += tmpHtml;  }  $("select[name='billCode_lib']").children("option").first().after(html);}/** * 校验数据 * * @param {String} model * @return {Object} */function getAndValidData(model) {  let name = $("input[name='compilation_name']").val();  let standardBill = $("select[name='standard_bill']")    .children("option:selected")    .val();  let rationLib = $("select[name='ration_lib']")    .children("option:selected")    .val();  let gljLib = $("select[name='glj_lib']").children("option:selected").val();  // let feeLib = $("select[name='fee_lib']").children("option:selected").val();  let artificialLib = $("select[name='artificial_lib']")    .children("option:selected")    .val();  let programLib = $("select[name='program_lib']")    .children("option:selected")    .val();  let billsGuidanceLib = $("select[name='billsGuidance_lib']")    .children("option:selected")    .val();  let featureLib = $("select[name='feature_lib']")    .children("option:selected")    .val();  let infoLib = $("select[name='info_lib']").children("option:selected").val();  let progressiveLib = $("select[name='progressive_lib']")    .children("option:selected")    .val();  let vvTaxLib = $("select[name='vvTax_lib']")    .children("option:selected")    .val();  let billCodeLib = $("select[name='billCode_lib']")    .children("option:selected")    .val();  if (name === "" && model === "all") {    throw "编办名字不能为空";  }  if (model === "bill" && (standardBill === "" || standardBill === undefined)) {    throw "请选择标准清单库";  }  if (model === "ration" && (rationLib === "" || rationLib === undefined)) {    throw "请选择定额库";  }  if (model === "feature" && (featureLib === "" || featureLib === undefined)) {    throw "请选择工程特征库";  }  if (    model === "progressive" &&    (progressiveLib === "" || progressiveLib === undefined)  ) {    throw "请选择累进区间库";  }  if (model === "vvTax" && (vvTaxLib === "" || vvTaxLib === undefined)) {    throw "请选择车船税文件";  }  if (    model === "billCode" &&    (billCodeLib === "" || billCodeLib === undefined)  ) {    throw "请选择递延清单库文件";  }  if (model === "glj" && (gljLib === "" || gljLib === undefined)) {    throw "请选择人材机库";  }  if (    model === "artificial" &&    (artificialLib === "" || artificialLib === undefined)  ) {    throw "请选择人工系数库";  }  if (model === "program" && (programLib === "" || programLib === undefined)) {    throw "请选择计算程序";  }  if (    model === "billsGuidance" &&    (billsGuidanceLib === "" || billsGuidanceLib === undefined)  ) {    throw "请选择清单指引库";  }  let standardBillString = $("select[name='standard_bill']")    .children("option:selected")    .text();  let rationLibString = $("select[name='ration_lib']")    .children("option:selected")    .text();  let gljLibString = $("select[name='glj_lib']")    .children("option:selected")    .text();  //  let feeLibString = $("select[name='fee_lib']").children("option:selected").text();  let artificialString = $("select[name='artificial_lib']")    .children("option:selected")    .text();  let programString = $("select[name='program_lib']")    .children("option:selected")    .text();  let billsGuidanceString = $("select[name='billsGuidance_lib']")    .children("option:selected")    .text();  let featrueString = $("select[name='feature_lib']")    .children("option:selected")    .text();  let infoString = $("select[name='info_lib']")    .children("option:selected")    .text();  let progressiveString = $("select[name='progressive_lib']")    .children("option:selected")    .text();  let vvTaxString = $("select[name='vvTax_lib']")    .children("option:selected")    .text();  let billCodeLibString = $("select[name='billCode_lib']")    .children("option:selected")    .text();  let result = {    name: name,    bill: {      id: standardBill,      name: standardBillString,    },    ration: {      id: rationLib,      name: rationLibString,    },    glj: {      id: gljLib,      name: gljLibString,    },    /*  fee: {              id: feeLib,              name: feeLibString          },*/    artificial: {      id: artificialLib,      name: artificialString,    },    program: {      id: programLib,      name: programString,    },    billsGuidance: {      id: billsGuidanceLib,      name: billsGuidanceString,    },    feature: {      id: featureLib,      name: featrueString,    },    info: {      id: infoLib,      name: infoString,    },    progressive: {      id: progressiveLib,      name: progressiveString,    },    vvTax: {      id: vvTaxLib,      name: vvTaxString,    },    billCode: {      id: billCodeLib,      name: billCodeLibString,    },  };  return result;}/** * 验证标准库数据 * * @return {boolean} */function validLib() {  let result = false;  try {    let valuationName = $("input[name='name']").val();    if (valuationName === "") {      throw "请填写计价规则名称";    }    let engineering = $("select[name='engineering']").val();    if (engineering === "" || engineering <= 0) {      throw "请选择工程专业";    }    //按新需求,清单库、定额库等不做非空验证    /*  if ($("input:hidden[name='bill_lib']").length <= 0) {              throw '请添加标准清单';          }            if ($("input:hidden[name='ration_lib']").length <= 0) {              throw '请添加定额库';          }            if ($("input:hidden[name='glj_lib']").length <= 0) {              throw '请添加人材机库';          }            if ($("input:hidden[name='fee_lib']").length <= 0) {              throw '请添加费率标准';          }            if ($("input:hidden[name='artificial_lib']").length <= 0) {              throw '请添加人工系数';          }            if ($("input:hidden[name='program_lib']").length <= 0) {              throw '请添加计算程序';          }            if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {              throw '请添加清单指引库';          }*/    result = true;  } catch (error) {    alert(error);    result = false;  }  return result;}/** * 切换switch效果 * * @param {Object} element * @return {boolean} */function switchChange(element) {  // 第一个元素判断当前的状态  let firstButton = element.children("button").first();  let secondButton = element.children("button").eq(1);  let currentStatus = firstButton.is(":disabled");  if (currentStatus) {    // 当前为true切换到false    firstButton      .removeClass("btn-success")      .removeClass("disabled")      .addClass("btn-default")      .removeAttr("disabled");    firstButton.text("开启");    secondButton      .removeClass("btn-default")      .addClass("btn-danger")      .addClass("disabled")      .attr("disabled", "disabled");    secondButton.text("已禁用");  } else {    // 当前false切换到true    firstButton      .removeClass("btn-default")      .addClass("btn-success")      .addClass("disabled")      .attr("disabled", "disabled");    firstButton.text("已开启");    secondButton      .removeClass("btn-danger")      .removeClass("disabled")      .addClass("btn-default")      .removeAttr("disabled");    secondButton.text("禁用");  }  return !currentStatus;}/* function editEngineer(selector) {    let engineerName = $(selector).prev("span").text();    let parentDiv = $(selector).parent("div");    parentDiv.next("div").find("input").val(engineerName);    parentDiv.hide();    parentDiv.next("div").show();} */function editEngineer(selector, key) {  let editText = $(selector).prev("span").text();  let parentDiv = $(selector).parent("div");  let width = key == "seq" ? 70 : 200;  parentDiv.next("div").css("width", width);  parentDiv.next("div").find("input").val(editText);  parentDiv.hide();  parentDiv.next("div").show();}/* function confirmUpdate(selector, engineerID) {    let inputDiv = $(selector).parents(".input_group_div");    let input = $(selector).parent(".input-group-btn").prev("input");    let oldValue = inputDiv.prev("div").find("span").text();    let newValue = input.val();    let key = input.attr("name");    if (newValue == "" || newValue == oldValue || !engineerID) {        inputDiv.prev("div").show();        inputDiv.hide();        return;    }    let updateData = {};    updateData[key] = newValue;    updateEngineer(engineerID, updateData, function () {        inputDiv.prev("div").find("span").text(newValue);    });    inputDiv.prev("div").show();    inputDiv.hide();} */function confirmUpdate(selector, engineerID) {  let inputDiv = $(selector).parents(".input_group_div");  let input = $(selector).parent(".input-group-btn").prev("input");  let oldValue = inputDiv.prev("div").find("span").text();  let newValue = input.val();  let key = input.attr("name");  if (newValue == oldValue || !engineerID) {    //不做非空判断    inputDiv.prev("div").show();    inputDiv.hide();    return;  }  let updateData = {};  updateData[key] = newValue;  updateEngineer(engineerID, updateData, function () {    if (key == "seq") {      window.location.reload();    } else {      inputDiv.prev("div").find("span").text(newValue);    }  });  inputDiv.prev("div").show();  inputDiv.hide();}function deleteEngineerClick(engineerID, element) {  hintBox.infoBox(    "操作确认",    "是否删除所选工程专业?",    2,    async function () {      try {        let result = await ajaxPost("/compilation/delete-engineer", {          id: engineerID,        });        $(element).parent("td").parent("tr").remove();      } catch (err) {        console.log(err);      }    },    null,    ["确定", "取消"],    false  );}function copyEngineerClick(engineerID) {  hintBox.infoBox(    "操作确认",    "是否拷贝所选工程专业?",    2,    async function () {      try {        await ajaxPost("/compilation/copy-engineer", { id: engineerID });        window.location.reload();      } catch (err) {        console.log(err);      }    },    null,    ["确定", "取消"],    false  );}function engineerVisibleChange(checkBox, engineerID) {  if (engineerID) {    updateEngineer(engineerID, { visible: checkBox.checked });  }}function updateEngineer(engineerID, data, callback) {  CommonAjax.post(    "/compilation/update-engineer",    { id: engineerID, updateData: data },    function (data) {      if (callback) {        callback();      }    }  );}function editTaxGroup(ele) {  $("#groupEditType").val("modify");  let groupData = $(ele).nextAll("input[name = 'tax_group']").val();  groupData = JSON.parse(groupData);  if (!_.isEmpty(groupData)) {    $("#taxType").val(groupData.taxType ? groupData.taxType : "");    $("#program_lib").val(      groupData.program_lib ? groupData.program_lib.id : ""    );    $("#template_lib").val(      groupData.template_lib ? groupData.template_lib.id : ""    );    $("#col_lib").val(groupData.col_lib ? groupData.col_lib.id : "");    $("#fee_lib").val(groupData.fee_lib ? groupData.fee_lib.id : "");  } else {    $("#taxType").val("");    $("#program_lib").val("");    $("#template_lib").val("");    $("#col_lib").val("");    $("#fee_lib").val("");  }  $("#groupIndex").val(getGroupIndex(groupData));  $("#addTaxGroup").modal({ show: true });}function deleteTableTr(ele, classString) {  let parentTr = $(ele).parents(`.${classString}`);  parentTr.remove();}function getGroupIndex(groupData) {  //用来做唯一标识  let index = "";  if (groupData) {    if (groupData.taxType) index = index + groupData.taxType;    if (groupData.program_lib) index = index + groupData.program_lib.id;    if (groupData.template_lib) index = index + groupData.template_lib.id;    if (groupData.col_lib) index = index + groupData.col_lib.id;    if (groupData.fee_lib) index = index + groupData.fee_lib.id;  }  return index;}function getTaxGroupData() {  let programData =    programList === undefined ? [] : _.indexBy(JSON.parse(programList), "id");  let billTemplateData =    billTemplateList == undefined      ? []      : _.indexBy(JSON.parse(billTemplateList), "ID");  let mainTreeColData =    mainTreeColList == undefined      ? []      : _.indexBy(JSON.parse(mainTreeColList), "ID");  let feeLibData =    feeRateList === undefined ? [] : _.indexBy(JSON.parse(feeRateList), "id");  let groupData = {};  if ($("#taxType").val() !== "") {    groupData.taxType = $("#taxType").val();  }  if ($("#program_lib").val() !== "") {    let program = programData[$("#program_lib").val()];    if (program) {      groupData.program_lib = {        id: program.id,        name: program.name,        displayName: program.displayName,      };    }  }  if ($("#template_lib").val() !== "") {    let template = billTemplateData[$("#template_lib").val()];    if (template) {      groupData.template_lib = {        id: template.ID,        name: template.name,      };    }  }  if ($("#col_lib").val() !== "") {    let col = mainTreeColData[$("#col_lib").val()];    if (col) {      groupData.col_lib = {        id: col.ID,        name: col.name,      };    }  }  if ($("#fee_lib").val() !== "") {    let feeRate = feeLibData[$("#fee_lib").val()];    if (feeRate) {      groupData.fee_lib = {        id: feeRate.id,        name: feeRate.name,      };    }  }  return groupData;}function intChecking(e, elemt) {  //限制输入正整数  let code = e.which || e.keyCode;  if (code == 46 || code == 45) {    //不能输入小数点和-号    e.preventDefault();  }  if (elemt.value == "" && code == 48) {    //当输入框为空时不能输入0    e.preventDefault();  }}
 |