text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = void 0;
  
  var _xeUtils = _interopRequireDefault(require("xe-utils/methods/xe-utils"));
  
  var _tools = require("../../tools");
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  var _default = {
    methods: {
      /**
       * 手动调用筛选的方法
       * 如果不传回调则返回一个选项列表的 Promise 对象
       * 如果传回调则通过回调返回的值更新选项列表，并返回一个新选项列表的 Promise 对象
       * @param {String} field 字段名
       * @param {Function} callback 重置列表的回调函数，返回新的选项列表
       */
      _filter: function _filter(field, callback) {
        var column = this.getColumnByField(field);
  
        if (column) {
          var filters = column.filters;
  
          if (callback) {
            var rest = callback(filters);
  
            if (_xeUtils.default.isArray(rest)) {
              column.filters = _tools.UtilTools.getFilters(rest);
            }
          }
  
          return this.$nextTick().then(function () {
            return filters;
          });
        }
  
        return this.$nextTick();
      },
  
      /**
       * 点击筛选事件
       * 当筛选图标被点击时触发
       * 更新选项是否全部状态
       * 打开筛选面板
       * @param {Event} evnt 事件
       * @param {ColumnConfig} column 列配置
       * @param {Object} params 参数
       */
      triggerFilterEvent: function triggerFilterEvent(evnt, column, params) {
        var $refs = this.$refs,
            filterStore = this.filterStore;
  
        if (filterStore.column === column && filterStore.visible) {
          filterStore.visible = false;
        } else {
          var filterWrapper = $refs.filterWrapper;
          var bodyElem = $refs.tableBody.$el;
          var targetElem = evnt.target,
              pageX = evnt.pageX;
  
          var _DomTools$getDomNode = _tools.DomTools.getDomNode(),
              visibleWidth = _DomTools$getDomNode.visibleWidth;
  
          Object.assign(filterStore, {
            args: params,
            multiple: column.filterMultiple,
            options: column.filters,
            column: column,
            style: null,
            visible: true
          });
          filterStore.isAllSelected = filterStore.options.every(function (item) {
            return item.checked;
          });
          filterStore.isIndeterminate = !filterStore.isAllSelected && filterStore.options.some(function (item) {
            return item.checked;
          });
          this.$nextTick(function () {
            var filterWrapperElem = filterWrapper.$el;
            var filterWidth = filterWrapperElem.offsetWidth;
            var centerWidth = filterWidth / 2;
            var minMargin = 32;
            var left, right;
            var style = {
              top: "".concat(targetElem.offsetTop + targetElem.offsetParent.offsetTop + targetElem.offsetHeight + 8, "px")
            };
  
            if (column.fixed === 'left') {
              left = targetElem.offsetLeft + targetElem.offsetParent.offsetLeft - centerWidth;
            } else if (column.fixed === 'right') {
              right = targetElem.offsetParent.offsetWidth - targetElem.offsetLeft + (targetElem.offsetParent.offsetParent.offsetWidth - targetElem.offsetParent.offsetLeft) - column.renderWidth - centerWidth;
            } else {
              left = targetElem.offsetLeft + targetElem.offsetParent.offsetLeft - centerWidth - bodyElem.scrollLeft;
            }
  
            if (left) {
              var overflowWidth = pageX + filterWidth - centerWidth + minMargin - visibleWidth;
  
              if (overflowWidth > 0) {
                left -= overflowWidth;
              }
  
              style.left = "".concat(Math.max(minMargin, left), "px");
            } else if (right) {
              var _overflowWidth = pageX + filterWidth - centerWidth + minMargin - visibleWidth;
  
              if (_overflowWidth > 0) {
                right += _overflowWidth;
              }
  
              style.right = "".concat(right, "px");
            }
  
            filterStore.style = style;
          });
        }
      },
  
      /**
       * 确认筛选
       * 当筛选面板中的确定按钮被按下时触发
       * @param {Event} evnt 事件
       */
      confirmFilterEvent: function confirmFilterEvent(evnt) {
        var visibleColumn = this.visibleColumn,
            filterStore = this.filterStore,
            remoteFilter = this.remoteFilter,
            filterOpts = this.filterOpts,
            scrollXLoad = this.scrollXLoad,
            scrollYLoad = this.scrollYLoad;
        var column = filterStore.column;
        var property = column.property;
        var values = [];
        var datas = [];
        column.filters.forEach(function (item) {
          if (item.checked) {
            values.push(item.value);
            datas.push(item.data);
          }
        });
        filterStore.visible = false; // 如果是服务端筛选，则跳过本地筛选处理
  
        if (!(filterOpts.remote || remoteFilter)) {
          this.handleTableData(true);
        }
  
        var filterList = [];
        visibleColumn.filter(function (column) {
          var property = column.property,
              filters = column.filters;
          var valueList = [];
          var dataList = [];
  
          if (filters && filters.length) {
            filters.forEach(function (item) {
              if (item.checked) {
                valueList.push(item.value);
                dataList.push(item.data);
              }
            }); // 在 v3.0 中废弃 prop
  
            filterList.push({
              column: column,
              property: property,
              field: property,
              prop: property,
              values: valueList,
              datas: dataList
            });
          }
        }); // 在 v3.0 中废弃 prop
  
        _tools.UtilTools.emitEvent(this, 'filter-change', [{
          column: column,
          property: property,
          field: property,
          prop: property,
          values: values,
          datas: datas,
          filters: filterList,
          $table: this
        }]);
  
        this.updateFooter();
  
        if (scrollXLoad || scrollYLoad) {
          this.clearScroll();
  
          if (scrollYLoad) {
            this.updateScrollYSpace();
          }
        }
  
        this.closeFilter();
        this.$nextTick(this.recalculate);
      },
  
      /**
       * 重置筛选
       * 当筛选面板中的重置按钮被按下时触发
       * @param {Event} evnt 事件
       */
      resetFilterEvent: function resetFilterEvent(evnt) {
        this.filterStore.options.forEach(function (item) {
          item.checked = false;
          item.data = item._data;
        });
        this.confirmFilterEvent(evnt);
      },
  
      /**
       * 清空指定列的筛选条件
       * 如果为空则清空所有列的筛选条件
       * @param {String} field 字段名
       */
      _clearFilter: function _clearFilter(field) {
        var column = arguments.length ? this.getColumnByField(field) : null;
        var filterStore = this.filterStore;
  
        var handleClear = function handleClear(column) {
          var filters = column.filters;
  
          if (filters && filters.length) {
            filters.forEach(function (item) {
              item.checked = false;
              item.data = item._data;
            });
          }
        };
  
        if (column) {
          handleClear(column);
        } else {
          this.visibleColumn.forEach(handleClear);
        }
  
        if (!column || column !== filterStore.column) {
          Object.assign(filterStore, {
            isAllSelected: false,
            isIndeterminate: false,
            style: null,
            options: [],
            column: null,
            multiple: false,
            visible: false
          });
        }
  
        return this.updateData();
      }
    }
  };
  exports.default = _default;