"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ConditionRenderService = void 0;
var _CLowCodeService = require("../../../src/utils/CLowCodeService");
var _formKeyType = require("../formKeyType");
var _type = require("../treeDataRelationFn/type");
var _utils = require("../utils");
var _type2 = require("./type");
var _lodash = require("lodash");
var _comFn = require("../../_setters/cTreeDataRelation-setter/comFn");
var _bignumber = _interopRequireDefault(require("../../../src/utils/bignumber"));
var _index = require("../../../src/locale/index");
var _util = require("../../../src/utils/comfn/util");
var ConditionRenderService = exports.ConditionRenderService = /*#__PURE__*/function () {
  function ConditionRenderService() {
    this.relateObj = void 0;
    this.expressionRelate = void 0;
    this.computedRelate = void 0;
    this.conditionType = void 0;
    this.conditionData = void 0;
    this.loadCurrentProps = void 0;
    this.expressionRelate = this.getExpressionByRelate();
    this.computedRelate = this.getComputedByRelate();
    this.relateObj = this.getRelateList();
    this.conditionData = [];
    this.conditionType = _type2.ConditionType.computed;
    this.loadCurrentProps = {};
  }

  /**
   * 初始化数据内容
   * @param data 
   */
  var _proto = ConditionRenderService.prototype;
  _proto.load = function load(data, conditionType) {
    if (data === void 0) {
      data = [];
    }
    this.conditionData = data;
    if (conditionType) {
      this.conditionType = conditionType;
    }
  }
  /**
   * 注入当前模块的props
   * 最终是给CLowCodeService load注入props
   * @param data 
  */;
  _proto.loadProps = function loadProps(data) {
    this.loadCurrentProps = data;
  }

  /**
   * 增加
   * @param data 
   * @returns 
   */;
  _proto.addRowData = function addRowData(data) {
    this.conditionData = this.handleAddRowData(this.conditionData, data);
    return this.conditionData;
  }

  /**
   * 删除
   * @param data 
   */;
  _proto.removeRowData = function removeRowData(data) {
    this.conditionData = this.handleRemoveRowData(this.conditionData, data);
    return this.conditionData;
  }

  /**
   * 添加同行
   * @param data 
   * @returns 
   */;
  _proto.copyRowData = function copyRowData(data) {
    this.conditionData = this.handleCopyRowData(this.conditionData, data);
    return this.conditionData;
  }

  /**
   * 修改行属性
   * @param data 
   */;
  _proto.alterRowData = function alterRowData(data) {
    this.conditionData = this.handleAlterRowData(this.conditionData, data);
    return this.conditionData;
  }

  /**
   * 修改结果列表数据
   * @param data 
   */;
  _proto.alterResultData = function alterResultData(data) {
    // this.resultData.resultRowList = this.handleAlterRowResultData(this.resultData.resultRowList, data)
    return [];
  }

  /**
   * 判断是否是最后一个
   * @returns 
   */;
  _proto.isLastData = function isLastData(conditions) {
    return conditions.length && conditions.length === 1 && conditions[0].children.length === 0 || false;
  }

  /**
   * 初始化一个树数据
   * @param type 
   * @returns 
   */;
  _proto.createInitItemOneByType = function createInitItemOneByType(type) {
    return {
      relate: type === _type2.ConditionType.computed ? _type2.computedRelateType.add : _type2.computedRelateType.and,
      id: (0, _utils.uuid)(),
      rowData: {
        leftTree: {
          data: "",
          treeData: [],
          formKey: _formKeyType.DataSourceType.currentPageType
        },
        rightTree: {
          data: "",
          treeData: [],
          formKey: _formKeyType.DataSourceType.currentPageType
        },
        relate: type === _type2.ConditionType.computed ? _type2.computedRelateType.add : _type2.computedRelateType.equality
        // treeKeyAfter: "",
        // treeDataAfter: [],
        // formKeyAfter: DataSourceType.currentPageType,
      },
      children: []
    };
  }

  /**
   * 初始化一个结果返回数据结构
   * @returns 
   */;
  _proto.createInitResultData = function createInitResultData() {
    return {
      isHandle: false,
      resultRowList: [{
        id: (0, _utils.uuid)(),
        formKey: _formKeyType.DataSourceType.defaultType,
        data: '',
        relate: _type2.computedRelateType.equality,
        treeData: []
      }]
    };
  }

  /**
   * 得到关系下拉选择内容
   * @param type 
   * @returns 
   */;
  _proto.getSelectRelateByType = function getSelectRelateByType(type) {
    return this.relateObj[type] ? this.relateObj[type] : [];
  }

  /**
   * 得到整个处理的关系表达式,
   * 表达式`${(this.state.state.c5lt0_bt*3)}B`
   * 存在大数计算问题，解决方法
   * 将生成的表达式替换成this.state.expression.xxx
   * 收集此表达式里面的依赖项
   * 数据改变根据依赖项触发this.setSate中的 expressions改变
   * 
   * 拼接表达式复杂类型需要重新检查，只是简单拼接
   * 
   */;
  _proto.getConditionExpression = function getConditionExpression() {
    var result = '';
    result = this.handleConditionExpression(this.conditionData);
    result = this.handleExpressToSting(result);
    result = "${" + result + "}";
    return {
      "type": "JSExpression",
      "value": "`" + result + "`",
      "mock": result
    };
  }

  /**
  * 得到依赖订阅数据关系数据
  * @returns 
  */;
  _proto.getSubscribe = function getSubscribe() {
    var result = [];
    result = this.handleSubscribe(this.conditionData);
    result = Array.from(new Set(result));
    return result;
  }

  /**
   * 计算结果内容
   */;
  _proto.getComputedResult = function getComputedResult() {
    var result = null;
    result = this.handleComputedResult(this.conditionData);
    return result;
  }

  /**
   * 得到拷贝的新的关系，只重新生成id信息
   * @param list 
   */;
  _proto.getCopyConditionData = function getCopyConditionData(list) {
    return this.handleCopyConditionMain(list);
  };
  _proto.handleCopyConditionMain = function handleCopyConditionMain(list) {
    var _this = this;
    var result = list.map(function (item) {
      var _item$children;
      item.id = (0, _utils.uuid)();
      if ((_item$children = item.children) !== null && _item$children !== void 0 && _item$children.length) {
        item.children = _this.handleCopyConditionMain(item.children);
      }
      return item;
    });
    return result;
  }

  /**
   * 暂时只是把拼接出来成了+
   * @param str 
   * @returns 
   */;
  _proto.handleExpressToSting = function handleExpressToSting(str) {
    var _this2 = this;
    var result = str;
    if (str.includes(this.expressionRelate.join)) {
      var data = str.split(this.expressionRelate.join);
      var newData = data.map(function (item) {
        return _this2.getWordString(item);
      });
      result = newData.join("+");
    }
    return result;
  };
  _proto.getWordString = function getWordString(str) {
    if (str.includes("this.") || str.includes("this?.")) {
      return str;
    } else {
      var replaceStr = this.getRemoveBracket(str);
      return str.replace(replaceStr, "'" + replaceStr + "'");
    }
  }
  /**
   * 暂时不需要那么复杂的处理逻辑
   * @param str 
   * @returns 
   */;
  _proto._handleExpressToSting = function _handleExpressToSting(str) {
    // let result = str
    // result = this.getBracketByStr(str)
    // result = this.getRemoveBracket(result)
    // result = this.handleAndReplace(result)
    // if (result.includes(this.expressionRelate.join)) {
    //     result = result.replaceAll(this.expressionRelate.join, "");
    // }
    // result = this.getDefaultData(result)
    // return result
  }

  // private handleResultList(oldResult: any, list: ResultRowListType[]) {
  //     // 临时处理，暂时只支持结果处理的一条数据
  //     const resultRow = list[0]
  //     const cLowCodeService = new CLowCodeService()
  //     cLowCodeService.loadPageProps(this.loadCurrentProps)
  //     const VV: any = cLowCodeService.getHandleDataByFormKey()
  //     const rightData = this.handleComputedRowDataByFormKey(VV, resultRow.formKey, resultRow.treeData, resultRow.data)
  //     return this.handleComputedData(oldResult, resultRow.relate, rightData)
  // }
  ;
  _proto.getIndexById = function getIndexById(data, id) {
    var result = -1;
    for (var i = 0; i < data.length; i++) {
      if (data[i].id === id) {
        result = i;
        break;
      }
    }
    return result;
  };
  _proto.handleAddRowData = function handleAddRowData(oldData, data) {
    var _this3 = this;
    var newData = this.createInitItemOneByType(this.conditionType);
    var rowData = this.createInitItemOneByType(this.conditionType);
    newData.children = [data, rowData];
    var index = this.getIndexById(oldData, data.id);
    if (index !== -1) {
      oldData[index] = newData;
    } else {
      oldData = oldData.map(function (item) {
        if (item.children.length) {
          item.children = _this3.handleAddRowData(item.children, data);
        }
        return item;
      });
    }
    return oldData;
  };
  _proto.handleRemoveRowData = function handleRemoveRowData(oldData, data) {
    var _this4 = this;
    var index = this.getIndexById(oldData, data.id);
    if (index !== -1) {
      oldData = oldData.filter(function (item) {
        return item.id !== data.id;
      });
    } else {
      oldData = oldData.map(function (item) {
        if (item.children.length) {
          item.children = _this4.handleRemoveRowData(item.children, data);
        }
        if (item.children.length === 1) {
          item = item.children[0];
        }
        return item;
      });
    }
    return oldData;
  };
  _proto.handleCopyRowData = function handleCopyRowData(oldData, data) {
    var _this5 = this;
    var index = this.getIndexById(oldData, data.id);
    if (index !== -1) {
      var newData = this.createInitItemOneByType(this.conditionType);
      var newIndex = index + 1;
      newIndex === oldData.length ? oldData.push(newData) : oldData.splice(newIndex, 0, newData);
    } else {
      oldData = oldData.map(function (item) {
        if (item.children.length) {
          item.children = _this5.handleCopyRowData(item.children, data);
        }
        return item;
      });
    }
    return oldData;
  };
  _proto.handleAlterRowData = function handleAlterRowData(oldData, data) {
    var _this6 = this;
    var index = this.getIndexById(oldData, data.id);
    if (index !== -1) {
      oldData[index] = data;
    } else {
      oldData = oldData.map(function (item) {
        if (item.children.length) {
          item.children = _this6.handleAlterRowData(item.children, data);
        }
        return item;
      });
    }
    return oldData;
  };
  _proto.handleAlterRowResultData = function handleAlterRowResultData(oldData, data) {
    var index = this.getIndexById(oldData, data.id);
    if (index !== -1) {
      oldData[index] = data;
    }
    return oldData;
  };
  _proto.handleConditionExpression = function handleConditionExpression(oldData, parentRelate) {
    var _this7 = this;
    var result;
    var ExpRelate = this.expressionRelate;
    var rowExpression;
    oldData.forEach(function (item, index) {
      rowExpression = item.children.length ? _this7.handleConditionExpression(item.children, item.relate) : _this7.getRowExpression(item.rowData);
      var newRelate = parentRelate ? parentRelate : item.relate;
      var relateOut = ExpRelate[newRelate];
      result = index === 0 ? rowExpression : "(" + result + relateOut + rowExpression + ")";
    });
    return result;
  }

  /**
   * 赋值不参与表达式计算
   * @param rowData 
   * @returns 
   */;
  _proto.getRowExpression = function getRowExpression(rowData) {
    var ExpRelate = this.expressionRelate;
    var relate = ExpRelate[rowData.relate];
    if (relate === this.expressionRelate.assign) {
      return '';
    }
    var leftExp = this.getRowExpressionItem(rowData.leftTree.formKey, rowData.leftTree.treeData, rowData.leftTree.data);
    if (relate === this.expressionRelate.omit) {
      return "(" + leftExp + ")";
    }
    var rightExp = '';
    rightExp = this.getRowExpressionItem(rowData.rightTree.formKey, rowData.rightTree.treeData, rowData.rightTree.data);

    // 忽略大小写
    if (relate === _type2.computedRelateType.ignoreCaseEquality) {
      console.log('ignoreCaseEquality', leftExp, relate, rightExp);
      leftExp = leftExp.toLowerCase();
      rightExp = rightExp.toLowerCase();
      relate = ExpRelate[_type2.computedRelateType.equality];
    }
    return "(" + leftExp + relate + rightExp + ")";
  };
  _proto.getRowExpressionItem = function getRowExpressionItem(key, treeData, data) {
    var comKeyList = [_formKeyType.DataSourceType.dataSourceType, _formKeyType.DataSourceType.customStateType, _formKeyType.DataSourceType.modalDialogType, _formKeyType.DataSourceType.loopDataSelectedType, _formKeyType.DataSourceType.storageDataType];
    if (key === _formKeyType.DataSourceType.currentPageType) {
      return this.getCurrentPageExpression(treeData);
    } else if (key === _formKeyType.DataSourceType.defaultType) {
      // 这里可能存在问题
      return data;
    } else if (comKeyList.includes(key)) {
      var keyBefore = this.getCurrentPageExpression(treeData);
      var lastData = this.handleLastInputData(data);
      return lastData.length ? "" + keyBefore + lastData : "" + keyBefore;
    } else if (key === _formKeyType.DataSourceType.loopDataType) {
      var _keyBefore = "this?." + _type.PageStateFlag.LoopData;
      var _lastData = this.handleLastInputDataPro(data);
      return _lastData.length ? "" + _keyBefore + _lastData : "" + _keyBefore;
    } else if (key === _formKeyType.DataSourceType.currentWalletConnectType) {
      var _keyBefore2 = "this?.state?." + _type.PageStateFlag.WalletConnectData;
      return this.handleLastWalletConnect(_keyBefore2, data);
    } else if (key === _formKeyType.DataSourceType.engineRuleType) {
      // 引擎表达式
      var _keyBefore3 = "this?.state?." + _type.PageStateFlag.EngineRule;
      return this.handleEngineRuleExpression(_keyBefore3, data);
    } else if (key === _formKeyType.DataSourceType.locationType) {
      var _keyBefore4 = "this?.state?." + _type.PageStateFlag.LocationData;
      return this.handleLastLocationData(_keyBefore4, data);
    } else if (key === _formKeyType.DataSourceType.renderPropsDataType) {
      var _keyBefore5 = "this?.state?." + _type.PageStateFlag.RenderPropsData;
      return this.handleRenderPropsData(_keyBefore5, data);
    } else {
      console.error("--Please supplement the expression parsing variable:" + key);
    }
  }

  /**
   * 数据源，自定义参数，弹框等
   * 第二个参数可能存在一下情况
   * 1，纯字符串，则点拼接
   * 2，带[]则需要拼接
   */;
  _proto.handleLastInputData = function handleLastInputData(data) {
    var result = '';
    if ((0, _lodash.isArray)(data) && data.length === 2 && data[1] && data[1].length) {
      var str = data[1];
      result = this.handleLastInputDataPro(str);
    }
    return result;
  }

  /**
   * 第二个参数可以是 
   * 1, id
   * 2, [0].id
   * 3, data[0].id.test[0].xxx
   * 
   * 最终返回数据
   * 1, ?.id
   * 2, ?.[0].id
   * 3, ?.data?.[0]?.id?.test?.[0]?.xxx
   * 
   * @param str 
   * @returns 
   */;
  _proto.handleLastInputDataPro = function handleLastInputDataPro(str) {
    var res = this.handleExpressionData(str);
    return "?." + res;
  }

  /**
   * 处理表达式里面的.
   * @param str 
   * @returns 
   */;
  _proto.handleExpressionData = function handleExpressionData(str) {
    var _this8 = this;
    var result = str;
    if (str.includes('.')) {
      var data = str.split('.');
      result = data.reduce(function (pre, cur) {
        return _this8.handleArrayData(pre) + "?." + _this8.handleArrayData(cur);
      });
      result = "" + result;
    }
    return result;
  }

  /**
   * 处理类似这样的数据 data6SN0D[0]
   * 变成 data6SN0D?.[0]
   * @param str 
   */;
  _proto.handleArrayData = function handleArrayData(str) {
    var result = str;
    var reg = /\b(\w+)\[(\d+)\]/g;
    if (reg.test(str)) {
      result = str.replace(reg, '$1?.[$2]');
    }
    return result;
  };
  _proto.handleLastWalletConnect = function handleLastWalletConnect(keyBefore, data) {
    var result = keyBefore;
    if (data && data.length) {
      var firstData = data[0];
      var lastData = data[1];
      // 等于自定义
      if (firstData === _type.WalletConnectType.Custom) {
        var kk = this.handleLastInputDataPro(lastData);
        result = "" + result + kk;
      } else if (firstData === _type.WalletConnectType.Address) {
        result = result + "?.signer?." + firstData;
      } else {
        result = result + "?." + firstData;
      }
    }
    return result;
  };
  _proto.handleLastLocationData = function handleLastLocationData(keyBefore, data) {
    var result = keyBefore;
    if (data && data.length) {
      var firstData = data[0];
      var lastData = data[1];
      // 等于自定义
      if (firstData === _type.LocationUrlType.custom) {
        var kk = this.handleLastInputDataPro(lastData);
        result = "" + result + kk;
      } else {
        result = result + "?." + firstData;
      }
    }
    return result;
  };
  _proto.handleRenderPropsData = function handleRenderPropsData(keyBefore, data) {
    var result = keyBefore;
    if (data.length) {
      var kk = this.handleLastInputDataPro(data);
      result = "" + result + kk;
    }
    return result;
  };
  _proto.handleEngineRuleExpression = function handleEngineRuleExpression(keyBefore, data) {
    var result = keyBefore;
    if (data && data.length) {
      var firstData = data[0];
      var lastData = data[1];
      var base = this.handleExpressionData(firstData);
      result = keyBefore + "?." + base;
      if (firstData.endsWith('.data') && lastData.length) {
        var kk = this.handleLastInputDataPro(lastData);
        result = "" + result + kk;
      }
    }
    return result;
  };
  _proto.handleSubscribe = function handleSubscribe(oldData) {
    var _this9 = this;
    var result = [];
    oldData.forEach(function (item) {
      if (item.rowData.leftTree.formKey === _formKeyType.DataSourceType.currentPageType) {
        result = result.concat(_this9.collectTreeKey(item.rowData.leftTree.treeData));
      }
      if (item.rowData.rightTree.formKey === _formKeyType.DataSourceType.currentPageType) {
        result = result.concat(_this9.collectTreeKey(item.rowData.rightTree.treeData));
      }
      if (item.children.length) {
        result = result.concat(_this9.handleSubscribe(item.children));
      }
    });
    return result;
  }

  /**
   * 这里可以简单优化：
   *  且情况下只要有一个children结果为false则就结束循环，整体为false
   *  或情况下只要有一个children结果为true则就结束循环，整体为true
   * @param oldData 
   * @param parentRelate 
   * @returns 
   */;
  _proto.handleComputedResult = function handleComputedResult(oldData, parentRelate) {
    var result = 0;
    var rightData;
    for (var i = 0; i < oldData.length; i++) {
      var item = oldData[i];
      rightData = item.children.length ? this.handleComputedResult(item.children, item.relate) : this.handleComputedRowData(item.rowData);
      var newRelate = parentRelate ? parentRelate : item.relate;
      result = i === 0 ? rightData : this.handleComputedData(result, newRelate, rightData);

      // 且情况下只要有一个children结果为false则就结束循环，整体为false
      if (newRelate === _type2.computedRelateType.and && !result) {
        result = false;
        break;
      }
      // 或情况下只要有一个children结果为true则就结束循环，整体为true
      if (newRelate === _type2.computedRelateType.or && result) {
        result = true;
        break;
      }
    }
    return result;
  };
  _proto.handleComputedRowData = function handleComputedRowData(rowData) {
    var cLowCodeService = new _CLowCodeService.CLowCodeService();
    cLowCodeService.loadPageProps(this.loadCurrentProps);
    var VV = cLowCodeService.getHandleDataByFormKey();
    var leftData = this.handleComputedRowDataByFormKey(VV, rowData.leftTree.formKey, rowData.leftTree.treeData, rowData.leftTree.data);
    var rightData = this.handleComputedRowDataByFormKey(VV, rowData.rightTree.formKey, rowData.rightTree.treeData, rowData.rightTree.data);
    var res = this.handleComputedData(leftData, rowData.relate, rightData);
    return res;
  };
  _proto.handleComputedRowDataByFormKey = function handleComputedRowDataByFormKey(obj, key, treeData, data) {
    var result = null;
    var fn = obj[key];
    if (fn) {
      var params = this.createFormKeyParams(key, treeData, data);
      result = fn(params);
    }
    return result;
  };
  _proto.createFormKeyParams = function createFormKeyParams(formKey, treeData, data) {
    var params = (0, _comFn.createTreeRelationItem)({});
    params.formKey = formKey;
    params.treeData = treeData;
    params.data = data;
    return params;
  };
  _proto.handleComputedData = function handleComputedData(leftData, relate, rightData) {
    var obj = this.computedRelate;
    if (obj[relate]) {
      return obj[relate](leftData, rightData);
    }
    return null;
  };
  _proto.collectTreeKey = function collectTreeKey(data) {
    var _this10 = this;
    var result = [];
    data.forEach(function (item) {
      var _item$children2;
      if ((_item$children2 = item.children) !== null && _item$children2 !== void 0 && _item$children2.length) {
        result = result.concat(_this10.collectTreeKey(item.children));
      } else {
        if (item.key) {
          result.push(item.key);
        }
      }
    });
    return result;
  }

  /**
   * 表达式不可能存在多个情况
   * @param treeData 
   */;
  _proto.getCurrentPageExpression = function getCurrentPageExpression(treeData) {
    var result = '';
    if (treeData.length) {
      var _obj2;
      var data = treeData[0];
      var _obj = (_obj2 = {}, _obj2[_type.TreeType.stateItem] = _type.PageStateFlag.State, _obj2[_type.TreeType.dataSourceMapItem] = _type.PageStateFlag.DataSourceMap, _obj2[_type.TreeType.submitReturnDataItem] = _type.PageStateFlag.SubmitReturnData, _obj2[_type.TreeType.customStateItem] = _type.PageStateFlag.CustomState, _obj2[_type.TreeType.modalParamsValueItem] = _type.PageStateFlag.Modal, _obj2[_type.TreeType.loopDataSelectedItem] = _type.PageStateFlag.LoopDataSelected, _obj2[_type.TreeType.storageDataItem] = _type.PageStateFlag.StorageData, _obj2);
      var keyData = _obj[data.type];
      var lastKey = data.key;
      if (keyData) {
        result = "this?.state?." + keyData + "?." + lastKey;
      } else {
        console.error("--kk--Unsupplemented variable:" + data.type);
      }
    }
    return result;
  }

  /**
   * 去除收尾的()
   * @param str 
   * @returns 
   */;
  _proto.getRemoveBracket = function getRemoveBracket(str) {
    var result = str;
    if (str.includes('(') || str.includes(')')) {
      result = str.replaceAll(/\(/g, "").replaceAll(/\)/g, "");
    }
    return result;
  }

  /**
   * (((${this?.state?.state?.ci769_b*3})+(${this?.state?.state?.c6w76_a*2}))###(B))
   * @param str 处理中间有连接的需要将2个$变成一个
   * @returns 
   */;
  _proto.handleAndReplace = function handleAndReplace(str) {
    var result = str;
    var regList = this.getRegList();
    for (var i = 0; i < regList.length; i++) {
      var item = regList[i];
      if (item.reg.test(str)) {
        result = result.replaceAll(item.reg, item.replace);
        break;
      }
    }
    return result;
  };
  _proto.getDefaultData = function getDefaultData(str) {
    var result = str;
    if (str.includes("${") && str.includes("}")) {
      var reg = /\$\{(.+?)\}/g;
      result = str.replace(reg, function (match) {
        return match.replace("}", "||'--'}");
      });
    }
    return result;
  };
  _proto.getRelateList = function getRelateList() {
    var _ref;
    var computed = [{
      value: _type2.computedRelateType.add,
      label: (0, _index.t)('setter.add')
    }, {
      value: _type2.computedRelateType.sub,
      label: (0, _index.t)('setter.sub')
    }, {
      value: _type2.computedRelateType.mul,
      label: (0, _index.t)('setter.mul')
    }, {
      value: _type2.computedRelateType.div,
      label: (0, _index.t)('setter.div')
    }, {
      value: _type2.computedRelateType.modulo,
      label: (0, _index.t)('setter.modulo')
    }, {
      value: _type2.computedRelateType.omit,
      label: (0, _index.t)('setter.omit')
    }, {
      value: _type2.computedRelateType.join,
      label: (0, _index.t)('setter.join')
    }];
    var addAndOr = [{
      value: _type2.computedRelateType.and,
      label: (0, _index.t)('setter.and')
    }, {
      value: _type2.computedRelateType.or,
      label: (0, _index.t)('setter.or')
    }];
    var compare = [{
      value: _type2.computedRelateType.equality,
      label: (0, _index.t)('setter.equality')
    }, {
      value: _type2.computedRelateType.inequality,
      label: (0, _index.t)('setter.inequality')
    }, {
      value: _type2.computedRelateType.ignoreCaseEquality,
      label: (0, _index.t)('setter.ignoreCaseEquality')
    }, {
      value: _type2.computedRelateType.greater,
      label: (0, _index.t)('setter.greater')
    }, {
      value: _type2.computedRelateType.less,
      label: (0, _index.t)('setter.less')
    }, {
      value: _type2.computedRelateType.greaterEqu,
      label: (0, _index.t)('setter.greaterEqu')
    }, {
      value: _type2.computedRelateType.lessEqu,
      label: (0, _index.t)('setter.lessEqu')
    }];
    var all = [].concat(computed, addAndOr, compare);
    return _ref = {}, _ref[_type2.SelectRelateType.computed] = computed, _ref[_type2.SelectRelateType.addAndOr] = addAndOr, _ref[_type2.SelectRelateType.compare] = compare, _ref[_type2.SelectRelateType.all] = all, _ref;
  };
  _proto.getComputedByRelate = function getComputedByRelate() {
    var _this11 = this,
      _ref2;
    return _ref2 = {}, _ref2[_type2.computedRelateType.omit] = function (aa, bb) {
      return aa;
    }, _ref2[_type2.computedRelateType.join] = function (aa, bb) {
      return "" + aa + bb;
    }, _ref2[_type2.computedRelateType.assign] = function (aa, bb) {
      return bb;
    }, _ref2[_type2.computedRelateType.add] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.plus(b).toNumber();
      } else {
        return aa + bb;
      }
    }, _ref2[_type2.computedRelateType.sub] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.minus(b);
      } else {
        return (0, _lodash.toNumber)(aa) - (0, _lodash.toNumber)(bb);
      }
    }, _ref2[_type2.computedRelateType.mul] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.times(b);
      } else {
        return (0, _lodash.toNumber)(aa) * (0, _lodash.toNumber)(bb);
      }
    }, _ref2[_type2.computedRelateType.div] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.div(b);
      } else {
        return (0, _lodash.toNumber)(aa) / (0, _lodash.toNumber)(bb);
      }
    }, _ref2[_type2.computedRelateType.modulo] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.modulo(b);
      } else {
        return (0, _lodash.toNumber)(aa) % (0, _lodash.toNumber)(bb);
      }
    }, _ref2[_type2.computedRelateType.equality] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.eq(b);
      } else {
        return _this11.handleSpecialCompare(aa, bb);
      }
    }, _ref2[_type2.computedRelateType.ignoreCaseEquality] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.eq(b);
      } else {
        return _this11.handleCaseSpecialCompare(aa, bb);
      }
    }, _ref2[_type2.computedRelateType.inequality] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return !a.eq(b);
      } else {
        return !_this11.handleSpecialCompare(aa, bb);
      }
    }, _ref2[_type2.computedRelateType.greater] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.gt(b);
      } else {
        return (0, _lodash.toNumber)(aa) > (0, _lodash.toNumber)(bb);
      }
    }, _ref2[_type2.computedRelateType.greaterEqu] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.gte(b);
      } else {
        return (0, _lodash.toNumber)(aa) >= (0, _lodash.toNumber)(bb);
      }
    }, _ref2[_type2.computedRelateType.less] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.lt(b);
      } else {
        return (0, _lodash.toNumber)(aa) < (0, _lodash.toNumber)(bb);
      }
    }, _ref2[_type2.computedRelateType.lessEqu] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a.lte(b);
      } else {
        return (0, _lodash.toNumber)(aa) <= (0, _lodash.toNumber)(bb);
      }
    }, _ref2[_type2.computedRelateType.and] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a && b;
      } else {
        return aa && bb;
      }
    }, _ref2[_type2.computedRelateType.or] = function (aa, bb) {
      if (_this11.checkNumber(aa) && _this11.checkNumber(bb)) {
        var a = _this11.numberToBigNumber(aa);
        var b = _this11.numberToBigNumber(bb);
        return a || b;
      } else {
        return aa || bb;
      }
    }, _ref2;
  };
  _proto.checkNumber = function checkNumber(value) {
    if (!(0, _util.isEffectiveValue)(value)) {
      return false;
    }
    var res = /^-?\d+(\.\d+)?$/.test(value.toString());
    return res;
  };
  _proto.numberToBigNumber = function numberToBigNumber(num) {
    return new _bignumber["default"](num.toString());
  }

  /**
   * 处理特殊内容比较
   * false==='false', 布尔值
   * null==='null' 
   * undefined==='undefined'
   *
   * 支持 "",null,undefined 都是一样的false
   * 
   * @param a 
   * @param b 
   */;
  _proto.handleSpecialCompare = function handleSpecialCompare(a, b) {
    var aa = this.getSpecialValueByString(a);
    var bb = this.getSpecialValueByString(b);
    if (aa === undefined || aa === null) {
      aa = !!aa;
    }
    if (bb === undefined || bb === null) {
      bb = !!bb;
    }
    return aa === bb;
  };
  _proto.handleCaseSpecialCompare = function handleCaseSpecialCompare(a, b) {
    var aa = this.getSpecialValueByString(a);
    var bb = this.getSpecialValueByString(b);
    if (typeof aa === 'string' && typeof bb === 'string') {
      aa = aa.toLowerCase();
      bb = bb.toLowerCase();
      return aa === bb;
    }
    return this.handleSpecialCompare(aa, bb);
  }

  /**
   * 将特殊的值字符串转换成特殊内容
   * "false" =>false,
   * 'null' =>null
   * 'undefined'=>undefined
   * '', '""'=>false
   * " "=>false
   * @param a 
   */;
  _proto.getSpecialValueByString = function getSpecialValueByString(a) {
    var result = a;
    if (a === 'false' || a === 'true') {
      result = a === 'true';
    } else if (a === 'null') {
      result = null;
    } else if (a === 'undefined') {
      result = undefined;
    } else if (a === '' || a === '""' || a === ' ' || a === '" "') {
      result = false;
    }
    return result;
  };
  _proto.getBigNumber = function getBigNumber(value) {
    // 如果是数字字符串，则直接转成bigNumber
    if (this.checkNumber(value)) {
      return this.numberToBigNumber(value);
    } else if (typeof value === 'string') {
      return value.trim();
    } else {
      return this.numberToBigNumber(0);
    }
  };
  _proto.getExpressionByRelate = function getExpressionByRelate() {
    var _ref3;
    return _ref3 = {}, _ref3[_type2.computedRelateType.omit] = "#.#", _ref3[_type2.computedRelateType.join] = "#+#", _ref3[_type2.computedRelateType.assign] = "#=#", _ref3[_type2.computedRelateType.ignoreCaseEquality] = "~=", _ref3[_type2.computedRelateType.add] = "+", _ref3[_type2.computedRelateType.sub] = "-", _ref3[_type2.computedRelateType.mul] = "*", _ref3[_type2.computedRelateType.div] = "/", _ref3[_type2.computedRelateType.modulo] = "%", _ref3[_type2.computedRelateType.equality] = "==", _ref3[_type2.computedRelateType.inequality] = "!=", _ref3[_type2.computedRelateType.greater] = ">", _ref3[_type2.computedRelateType.greaterEqu] = ">=", _ref3[_type2.computedRelateType.less] = "<", _ref3[_type2.computedRelateType.lessEqu] = "<=", _ref3[_type2.computedRelateType.and] = "&&", _ref3[_type2.computedRelateType.or] = "||", _ref3;
  };
  _proto.getRegList = function getRegList() {
    return [{
      reg: /}\+\${/g,
      replace: "+"
    }, {
      reg: /}\-\${/g,
      replace: "-"
    }, {
      reg: /}\*\${/g,
      replace: "*"
    }, {
      reg: /}\/\${/g,
      replace: "+"
    }, {
      reg: /}\==\${/g,
      replace: "=="
    }, {
      reg: /}\!=\${/g,
      replace: "!="
    }, {
      reg: /}\>\${/g,
      replace: ">"
    }, {
      reg: /}\>=\${/g,
      replace: ">="
    }, {
      reg: /}\<\${/g,
      replace: "<"
    }, {
      reg: /}\<=\${/g,
      replace: "<="
    }, {
      reg: /}\&&\${/g,
      replace: "&&"
    }, {
      reg: /}\|\|\${/g,
      replace: "||"
    }];
  };
  return ConditionRenderService;
}();