| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date 2018/4/23
- * @version
- */
- $(document).ready(function () {
- const refreshDelParamVisible = function () {
- if ($('#rule').children().length > 1) {
- $('#delParam').show();
- } else {
- $('#delParam').hide();
- }
- };
- const addParamHtml = function (html, param) {
- html.push('<span class="badge badge-light" title="' + param.text() + '"');
- html.push(' name="' + param.text() + '"');
- html.push(' code="' + param.attr('value') + '">');
- html.push(param.text());
- html.push('</span>');
- };
- $('a[name=setRule]').click(function () {
- const rule = $(this).attr('value');
- const index = this.parentNode.parentNode;
- $('#rule').attr('curIndex', index.attributes['index_id'].nodeValue);
- $('span', $('#rule')).remove();
- const html = [];
- const params = rule.split('/');
- for (let i = 0, iLen = params.length; i < iLen; i++) {
- const p = $('option[value='+ params[i] +']');
- addParamHtml(html, p);
- if (i < iLen - 1) {
- html.push('<span class="badge badge-light" title="/" code="/" name="/">/ </span>');
- }
- }
- $('#delParam').before(html.join(''));
- refreshDelParamVisible();
- $('#set-count').modal('show');
- });
- $('#paramType').change(function () {
- const param = this.selectedIndex === 0 ? 'globalParams' : (this.selectedIndex === 1 ? 'nodeParams' : 'calcParams');
- $('div[name=param]').hide();
- $('#' + param).show();
- });
- $('#addParam').click(function () {
- const lastParam = $('#delParam').prev();
- const paramType = $('#paramType')[0];
- const addParam = function () {
- const paramId = paramType.selectedIndex === 0 ? 'globalParams' : (paramType.selectedIndex === 1 ? 'nodeParams' : 'calcParams');
- const paramSelect = $('select', $('#' + paramId))[0];
- if (paramSelect.children.length > 0 && paramSelect.selectedIndex >= 0) {
- const param = paramSelect.children[paramSelect.selectedIndex];
- const html = [];
- addParamHtml(html, $(param));
- $('#delParam').before(html.join(''));
- $('#paramAlert').hide();
- } else {
- $('#paramAlert').text('无选定参数').show();
- }
- }
- if (lastParam) {
- console.log(lastParam.attr('code'));
- if (lastParam.attr('code') !== '/' && paramType.selectedIndex !== 2) {
- $('#paramAlert').text('2个参数之间需要一个计算式').show();
- } else if (lastParam.attr('code') === '/' && paramType.selectedIndex === 2 ) {
- $('#paramAlert').text('计算式后只可添加参数').show();
- } else {
- addParam();
- }
- } else if (paramType.selectedIndex === 2) {
- $('#paramAlert').text('计算式前需含有参数').show();
- } else {
- addParam();
- }
- });
- $('#delParam').click(function () {
- $('#delParam').prev().remove();
- refreshDelParamVisible();
- });
- $('#ruleOk').click(function () {
- const lastParam = $('#delParam').prev();
- if (!lastParam) {
- $('#paramAlert').text('未设置计算规则').show();
- } else if (lastParam.attr('code') === lastParam.attr('name')) {
- $('#paramAlert').text('计算式后应添加参数').show();
- } else {
- const indexRow = $('tr[index_id=' + $('#rule').attr('curIndex') + ']');
- const params = $('span', $('#rule'));
- const data = {
- id: $('#rule').attr('curIndex'),
- rule: '',
- calc_rule: '',
- parse_rule: '',
- };
- for (const p of params) {
- const code = $(p).attr('code');
- const name = $(p).attr('name');
- data.rule = data.rule + name;
- data.calc_rule = data.calc_rule + code;
- data.parse_rule = code === name ? data.parse_rule + code : data.parse_rule + code + '(' + name + ')';
- }
- postData('/template/setIndexRule', data, function () {
- $('a', indexRow).val(data.calc_rule);
- $('td[name=rule]', indexRow).text(data.rule);
- const aHtml = $('a', indexRow)[0].outerHTML;
- $('td[name=parse_rule]', indexRow).empty();
- $('td[name=parse_rule]', indexRow).append(data.parse_rule + aHtml);
- $('paramAlert').hide();
- $('#set-count').modal('hide');
- }, function () {
- $('#paramAlert').text('提交计算规则失败,请重试').show();
- })
- }
- });
- });
|