| 1 |
- "use strict";$(document).ready(function(){const t=function(t){return"+-*/".indexOf(t)>-1},e=function(){$("#rule").children().length>1?$("#delParam").show():$("#delParam").hide()},a=function(t,e){e&&0!==e.length&&(t.push('<span class="badge badge-light" title="'+e.text()+'"'),t.push(' name="'+e.text()+'"'),t.push(' code="'+e.attr("value")+'">'),t.push(e.text()),t.push("</span>"))};$("a[name=setRule]").click(function(){const t=function(t){return"+-*/()".indexOf(t)>-1},r=$(this).attr("value"),n=this.parentNode.parentNode;$("#rule").attr("curIndex",n.attributes.index_id.nodeValue),$("span",$("#rule")).remove();const l=[],c=function(e){const a=[],r=[];for(let t=0,r=e.length;t<r;t++){const r=e[t];" "!==r&&a.push(r)}let n="",l=!1;for(;a.length>0;){const e=a.shift();t(e)?(l&&(r.push(n),n=""),r.push(e),l=!1):(n+=e,l=!0,0===a.length&&(r.push(n),n=""))}return r}(r);for(let e=0,r=c.length;e<r;e++)if(t(c[e]))l.push('<span class="badge badge-light" title="'+c[e]+'" code="'+c[e]+'" name="'+c[e]+'">'+c[e]+"</span>");else{const t=$("option[value="+c[e]+"]:first");a(l,t)}$("#delParam").before(l.join("")),e(),$("#set-count").modal("show")}),$("#paramType").change(function(){const t=0===this.selectedIndex?"globalParams":1===this.selectedIndex?"nodeParams":"calcParams";$("div[name=param]").hide(),$("#"+t).show()}),$("#addParam").click(function(){const e=$("#delParam").prev(),r=$("#paramType")[0],n=function(){const t=0===r.selectedIndex?"globalParams":1===r.selectedIndex?"nodeParams":"calcParams",e=$("select",$("#"+t))[0];if(e.children.length>0&&e.selectedIndex>=0){const t=e.children[e.selectedIndex],r=[];a(r,$(t)),$("#delParam").before(r.join("")),$("#paramAlert").hide()}else $("#paramAlert").text("无选定参数").show()};if(e&&e.length>0){const a=$("select",$("#calcParams"))[0];t(e.attr("code"))?2===r.selectedIndex&&4!==a.selectedIndex?$("#paramAlert").text("计算式后请输入参数").show():n():"("===e.attr("code")?2===r.selectedIndex?$("#paramAlert").text("左括号后请输入参数").show():n():")"===e.attr("code")?2===r.selectedIndex&&a.selectedIndex<4?n():$("#paramAlert").text("右括号后请输入计算式").show():2===r.selectedIndex?4===a.selectedIndex?$("#paramAlert").text("2个参数之间需要一个计算式").show():n():$("#paramAlert").text("2个参数之间需要一个计算式").show()}else if(2===r.selectedIndex){4===$("select",$("#calcParams")).selectedIndex?n():$("#paramAlert").text("计算式前需含有参数").show()}else n()}),$("#delParam").click(function(){$("#delParam").prev().remove(),e()}),$("#ruleOk").click(function(){const e=$("#delParam").prev(),a=$("span[code='(']").length,r=$("span[code=')']").length;if(e)if(t(e.attr("code")))$("#paramAlert").text("计算式后应添加参数").show();else if("("===e.attr("code")||a!==r)$("#paramAlert").text("计算式错误,请检查").show();else{const t=$("tr[index_id="+$("#rule").attr("curIndex")+"]"),e=$("span",$("#rule")),a={id:$("#rule").attr("curIndex"),rule:"",calc_rule:"",parse_rule:""};for(const t of e){const e=$(t).attr("code"),r=$(t).attr("name");a.rule=a.rule+r,a.calc_rule=a.calc_rule+e,a.parse_rule=e===r?a.parse_rule+e:a.parse_rule+e+"("+r+")"}postData("/template/setIndexRule",a,function(){$("a",t).val(a.calc_rule),$("td[name=rule]",t).text(a.rule);const e=$("a",t)[0].outerHTML;$("td[name=parse_rule]",t).empty(),$("td[name=parse_rule]",t).append(a.parse_rule+e),$("paramAlert").hide(),$("#set-count").modal("hide")},function(){$("#paramAlert").text("提交计算规则失败,请重试").show()})}else $("#paramAlert").text("未设置计算规则").show()}),$("#nodeMatchCode").blur(function(){const t=$(this);if(t.val()===t.attr("org-value"))return;const e=GetUrlQueryString("id");postData("/template/updateNodeMatch",{id:e||1,match_key:$(this).val()},function(e){t.attr("org-value",e.match_key),t.attr("title",e.match_type_str),t.attr("data-original-title",e.match_type_str)},function(e){t.val(e.match_key),t.attr("org-value",e.match_key),t.attr("title",e.match_type_str),t.attr("data-original-title",e.match_type_str)})}),$("input[name=nodeParamMatchCode]").blur(function(){const t=$(this);if(t.val()===t.attr("org-value"))return;const e=GetUrlQueryString("id"),a=$(this).parent().parent().prev().attr("code");postData("/template/updateParamMatch",{node_id:e||1,code:a,match_key:$(this).val()},function(e){t.attr("org-value",e.match_key)},function(){t.val(t.attr("org-value"))})}),$("input[name=globalParamMatchCode]").blur(function(){const t=$(this);if(t.val()===t.attr("org-value"))return;GetUrlQueryString("id");const e=$(this).parent().parent().prev().attr("code");postData("/template/updateParamMatch",{node_id:0,code:e,match_key:$(this).val()},function(e){t.attr("org-value",e.match_key)},function(){t.val(t.attr("org-value"))})}),$("a[name=nodeParamMatchNum]").click(function(){const t=$(this),e=t.attr("value");if(e===t.parent().prev().val())return;const a=GetUrlQueryString("id"),r=$(this).parent().parent().parent().parent().prev().attr("code");postData("/template/updateParamMatch",{node_id:a||1,code:r,match_num:e},function(e){t.parent().prev().val(e.match_num),t.parent().prev().text(e.match_num_str)},function(e){t.parent().prev().val(e.match_num),t.parent().prev().text(e.match_num_str)})}),$("a[name=globalParamMatchNum]").click(function(){const t=$(this),e=t.attr("value");if(e===t.parent().prev().val())return;const a=$(this).parent().parent().parent().parent().prev().attr("code");postData("/template/updateParamMatch",{node_id:0,code:a,match_num:e},function(e){t.parent().prev().val(e.match_num),t.parent().prev().text(e.match_num_str)},function(e){t.parent().prev().val(e.match_num),t.parent().prev().text(e.match_num_str)})})});
|