/** * 编办管理相关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 = "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 = ''; let tmpHtml = '

' + removeHtml + addLib.name + '" + "

"; $("." + 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(""); $("#norm_lib").val(""); }); //新增计税组合 $("#add-group").click(function () { let taxMap = { 1: "一般计税", 2: "简易计税" }; let actionType = $("#groupEditType").val(); let normValue = $("#norm_lib").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 = "" + taxName + "" + "" + p_name + "" + "" + normValue + "" + "" + t_name + "" + "" + c_name + "" + "" + f_name + "" + " 编辑/删除 " + "" + "" + ""; 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"); }); $("#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 () { let rationLib = $("select[name='ration_lib']").children("option:selected").val(); let rationLibString = $("select[name='ration_lib']").children("option:selected").text(); if (rationLib == undefined || rationLib == '') { alert("请选择定额库"); return; } if ($("input:hidden[name=ration_lib][data-id = " + rationLib + "]").length <= 0) { let tem = { id: rationLib, name: rationLibString, isDefault: false }; let htmlString = ` ${tem.name}