"use strict";

var _interopRequireDefault = require("D:/git/\u6211\u7684/opu-components-vue/node_modules/@babel/runtime/helpers/interopRequireDefault.js").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _toConsumableArray2 = _interopRequireDefault(require("D:/git/\u6211\u7684/opu-components-vue/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js"));

var _objectSpread2 = _interopRequireDefault(require("D:/git/\u6211\u7684/opu-components-vue/node_modules/@babel/runtime/helpers/esm/objectSpread2.js"));

require("core-js/modules/es.object.keys.js");

require("core-js/modules/es.object.to-string.js");

require("core-js/modules/web.dom-collections.for-each.js");

require("core-js/modules/es.array.filter.js");

require("core-js/modules/es.array.find-index.js");

require("core-js/modules/es.array.map.js");

require("core-js/modules/es.function.name.js");

require("core-js/modules/es.regexp.exec.js");

require("core-js/modules/es.string.search.js");

require("core-js/modules/es.array.concat.js");

require("core-js/modules/es.array.splice.js");

require("core-js/modules/es.array.includes.js");

require("core-js/modules/es.string.includes.js");

require("core-js/modules/es.array.sort.js");

require("core-js/modules/es.regexp.to-string.js");

require("vxe-table/lib/index.css");

var _utils = _interopRequireDefault(require("../../utils"));

var _vxeTable = require("vxe-table");

var _dataForm = require("../../dataForm");

var _conf = _interopRequireDefault(require("../conf"));

var _setColumns = _interopRequireDefault(require("./setColumns"));

var _editRender = _interopRequireDefault(require("./mixin/editRender"));

var _modal = require("../../modal");

// import Vue from "vue";
var tablePropKeys = Object.keys(_vxeTable.Table.props);
var methods = {};
Object.keys(_vxeTable.Table.methods).forEach(function (name) {
  methods[name] = function () {
    var _this$$refs$dataGrid;

    return this.$refs.dataGrid && (_this$$refs$dataGrid = this.$refs.dataGrid)[name].apply(_this$$refs$dataGrid, arguments);
  };
}); // 渲染头部搜索表单

function renderHeadSearch(searchConfig, h, _vm) {
  var onSearchSubmit = _vm.onSearchSubmit,
      onButtonActionClick = _vm.onButtonActionClick,
      $scopedSlots = _vm.$scopedSlots;
  var items = searchConfig.items;
  var form = h("data-form", {
    ref: "headSearchForm",
    props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, searchConfig), {}, {
      items: items
    }),
    class: "head-search-form",
    style: searchConfig.style,
    on: (0, _objectSpread2.default)((0, _objectSpread2.default)({
      submit: onSearchSubmit
    }, searchConfig.on), {}, {
      buttonActionClick: onButtonActionClick
    }),
    scopedSlots: $scopedSlots
  });
  return form;
} // 渲染头部工具条搜索表单


function renderHeadToolbarSearch(searchConfig, h, _vm) {
  var onSearchSubmit = _vm.onSearchSubmit,
      onButtonActionClick = _vm.onButtonActionClick,
      $scopedSlots = _vm.$scopedSlots;

  var cloneSearchConfig = _utils.default.clone(searchConfig, true);

  var items = cloneSearchConfig.items.filter(function (item) {
    return !item.folding;
  }); // 生成查询按钮

  var actionButtons = [];

  if (cloneSearchConfig.submitButtonProps !== false) {
    var submitButtonProps = cloneSearchConfig.submitButtonProps && _utils.default.isObject(cloneSearchConfig.submitButtonProps) ? cloneSearchConfig.submitButtonProps : {};
    actionButtons.push({
      props: (0, _objectSpread2.default)({
        action: "submit",
        content: "查询",
        type: "primary"
      }, submitButtonProps)
    });
  } // 高级查询按钮


  var hasFolding = cloneSearchConfig.items.findIndex(function (p) {
    return p.folding;
  }) > -1;

  if (hasFolding && cloneSearchConfig.advancedSearchButtonProps !== false) {
    var advancedSearchButtonProps = cloneSearchConfig.advancedSearchButtonProps && _utils.default.isObject(cloneSearchConfig.advancedSearchButtonProps) ? cloneSearchConfig.advancedSearchButtonProps : {};
    actionButtons.push({
      props: (0, _objectSpread2.default)({
        action: "advancedQuery",
        content: "高级查询"
      }, advancedSearchButtonProps)
    });
  }

  if (actionButtons && actionButtons.length) {
    items.push({
      colon: false,
      titleWidth: 0,
      folding: false,
      itemRender: {
        name: "buttons",
        items: actionButtons
      }
    });
  }

  var form = h("data-form", {
    ref: "headSearch",
    props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, cloneSearchConfig), {}, {
      submitButtonProps: false,
      items: items
    }),
    class: "headtoolbar-search-form",
    on: (0, _objectSpread2.default)((0, _objectSpread2.default)({
      submit: onSearchSubmit
    }, cloneSearchConfig.on), {}, {
      buttonActionClick: onButtonActionClick
    }),
    style: (0, _objectSpread2.default)({}, cloneSearchConfig.style),
    scopedSlots: $scopedSlots
  });
  return form;
} // 渲染高级查询窗口


function renderAdvancedSearch(searchConfig, h, _vm) {
  var onSearchSubmit = _vm.onSearchSubmit,
      advancedVisible = _vm.advancedVisible,
      onAdvancedReset = _vm.onAdvancedReset,
      onAdvancedcancel = _vm.onAdvancedcancel,
      onAdvancedSubmit = _vm.onAdvancedSubmit,
      $scopedSlots = _vm.$scopedSlots;

  var cloneSearchConfig = _utils.default.clone(searchConfig, true);

  var items = cloneSearchConfig.items.filter(function (item) {
    return item.folding !== false;
  });
  var formItems = items.map(function (p) {
    delete p.folding;
    return p;
  });
  var formProps = cloneSearchConfig.advancedSearchForm && cloneSearchConfig.advancedSearchForm.props ? cloneSearchConfig.advancedSearchForm.props : {};
  var form = h("data-form", {
    ref: "advancedSearch",
    props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, formProps), {}, {
      items: formItems,
      submitButtonProps: false
    }),
    class: "advanced-search-form",
    on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, cloneSearchConfig.on), {}, {
      submit: onSearchSubmit
    }),
    scopedSlots: $scopedSlots
  });
  var modalProps = cloneSearchConfig.advancedSearchModal && cloneSearchConfig.advancedSearchModal.props ? cloneSearchConfig.advancedSearchModal.props : {};
  return h("modal", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, cloneSearchConfig.advancedSearchModal), {}, {
    props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, modalProps), {}, {
      title: modalProps.title ? modalProps.title : "高级查询",
      value: advancedVisible,
      showFooter: true
    }),
    on: {
      cancel: onAdvancedcancel,
      ok: onAdvancedSubmit
    },
    class: "advanced-search-modal",
    scopedSlots: {
      footer: function footer() {
        return [h("a-button", {
          "props": (0, _objectSpread2.default)({}, {
            type: "danger"
          }),
          "on": (0, _objectSpread2.default)({}, {
            click: onAdvancedReset
          })
        }, ["\u91CD\u7F6E"]), h("a-button", {
          "on": (0, _objectSpread2.default)({}, {
            click: onAdvancedcancel
          })
        }, ["\u53D6\u6D88"]), h("a-button", {
          "props": (0, _objectSpread2.default)({}, {
            type: "primary"
          }),
          "on": (0, _objectSpread2.default)({}, {
            click: onAdvancedSubmit
          })
        }, ["\u786E\u8BA4"])];
      }
    }
  }), [form]);
} // 渲染设置表头窗口


function renderColumnsModal(h, _vm) {
  var backupColumns = _vm.backupColumns,
      setTableColumns = _vm.setTableColumns,
      setColumnsOpt = _vm.setColumnsOpt;
  return h("SetColumns", {
    ref: "setColumsModal",
    props: {
      option: setColumnsOpt,
      columns: backupColumns
    },
    on: {
      submit: setTableColumns
    }
  });
} // 渲染工具栏按钮


function renderButton(item, h, hasDropdown, _vm) {
  var name = item.name,
      icon = item.icon,
      disabled = item.disabled,
      code = item.code,
      on = item.on;
  var onToobarButtonClick = _vm.onToobarButtonClick;
  var iconContent = "";

  if (icon) {
    iconContent = h("a-icon", {
      props: {
        type: icon
      }
    });
  }

  var onClick = function onClick(e) {
    if (e) e.target.blur();
    onToobarButtonClick(code);

    if (on && on.click) {
      on.click(e);
    }
  }; // 下拉按钮


  if (hasDropdown) {
    return h("a-menu-item", {
      key: code,
      props: {
        disabled: disabled
      },
      on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, on), {}, {
        click: onClick
      })
    }, [iconContent, name]);
  }

  return h("a-button", {
    key: code,
    props: {
      type: item.type,
      disabled: disabled
    },
    on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, on), {}, {
      click: onClick
    })
  }, [iconContent, name]);
} // 渲染工具栏按钮组


function renderButtons(buttons, h, _vm) {
  return buttons ? buttons.map(function (item) {
    if (Object.prototype.toString.call(item) === "[object Array]") {
      // 数组，渲染按钮组
      var buttonGroups = item.map(function (p) {
        return renderButton(p, h, false, _vm);
      });
      return h("a-button-group", {}, [buttonGroups]);
    } else if (item.dropdowns && item.dropdowns.length) {
      var _buttonGroups = item.dropdowns.map(function (p) {
        return renderButton(p, h, true, _vm);
      });

      var menus = h("a-menu", {
        slot: "overlay"
      }, [_buttonGroups]);
      return h("a-dropdown", {
        props: {
          disabled: item.disabled
        },
        scopedSlots: {
          overlay: function overlay() {
            return menus;
          }
        }
      }, [h("a-button", {}, [item.name, h("a-icon", {
        props: {
          type: "down"
        }
      })])]);
    } else if (Object.prototype.toString.call(item) === "[object Object]") {
      // 对象，渲染单个按钮
      return renderButton(item, h, false, _vm);
    }
  }) : [];
} // 渲染头部工具栏


function renderHeadToolbar(h, _vm) {
  var headToolbar = _vm.headToolbar,
      $nextTick = _vm.$nextTick,
      $refs = _vm.$refs,
      showSetColumns = _vm.showSetColumns,
      setcolumnsConfig = _vm.setcolumnsConfig,
      $slots = _vm.$slots;

  if (!headToolbar) {
    return false;
  }

  var headToolbarProps = {
    ref: "headToolbar",
    props: {},
    class: "head-toolbar",
    scopedSlots: {}
  }; // 渲染按钮

  var headButtons = "";

  if ($slots.headToolbar_buttons) {
    headButtons = $slots.headToolbar_buttons;
  } else if (headToolbar.buttons) {
    var buttons = renderButtons(headToolbar.buttons, h, _vm);
    headButtons = buttons;
  }

  if (headButtons) {
    if (headToolbar.search && headToolbar.search.position === "left") {
      headToolbarProps.scopedSlots.tools = function () {
        return headButtons;
      };
    } else {
      headToolbarProps.scopedSlots.buttons = function () {
        return headButtons;
      };
    }
  } // 渲染头部搜索表单


  var advancedSearch = "";
  var headSearchTools = "";

  if (headToolbar.search) {
    headSearchTools = renderHeadToolbarSearch(headToolbar.search, h, _vm);
    advancedSearch = renderAdvancedSearch(headToolbar.search, h, _vm);
  }

  if (headSearchTools) {
    if (headToolbar.search.position === "left") {
      headToolbarProps.scopedSlots.buttons = function () {
        return headSearchTools;
      };
    } else {
      headToolbarProps.scopedSlots.tools = function () {
        return headSearchTools;
      };
    }
  } // 渲染头部工具


  var setColumnsModal = "";

  if (headToolbar.tools) {
    headToolbarProps.props = (0, _objectSpread2.default)({}, headToolbar.tools); // 自定义的 setColumns

    if (headToolbar.tools.setColumns) {
      var buttonProps = _utils.default.isObject(headToolbar.tools.setColumns) ? headToolbar.tools.setColumns : {};
      var setColumnsBtn = h("a-button", {
        props: (0, _objectSpread2.default)({
          circle: true,
          icon: "setting",
          shape: "circle"
        }, buttonProps),
        class: "tool-btn-setcolumns",
        style: {
          marginRight: "10px"
        },
        on: {
          click: showSetColumns
        }
      });

      if (headSearchTools) {
        headToolbarProps.scopedSlots.tools = function () {
          return h("div", {
            style: {
              display: "flex"
            }
          }, [headSearchTools, setColumnsBtn]);
        };
      } else {
        headToolbarProps.scopedSlots.tools = function () {
          return setColumnsBtn;
        };
      }

      if (!setcolumnsConfig) {
        setColumnsModal = renderColumnsModal(h, _vm);
      }
    }

    $nextTick(function () {
      $refs.dataGrid.connect($refs.headToolbar);
    });
  }

  return h("div", {
    class: "head-toolbar-box"
  }, [h("vxe-toolbar", headToolbarProps, []), advancedSearch, setColumnsModal]);
} //处理api获取的表头数据


function handleColumnsData(data, columns, configProps, _vm) {
  var sortable = _vm.sortable,
      notSortableFields = _vm.notSortableFields,
      tableProps = _vm.tableProps,
      proxyColumns = _vm.proxyColumns;
  var copyColumns = columns ? _utils.default.clone(columns) : [];
  var apiColumns = [];
  var otherColumns = [];

  var _loop = function _loop(i) {
    var item = data[i]; // 替换字段

    var obj = (0, _objectSpread2.default)({}, item);

    for (var key in configProps) {
      if (key !== "list") {
        var value = item[configProps[key]];

        if (key === "fixed" && value == "none") {
          value = "";
        }

        obj[key] = value;
      }
    }

    if (sortable) {
      var currentNotSortableFields = notSortableFields && notSortableFields.length ? notSortableFields : [];
      var configNotSortableFields = tableProps.props && tableProps.props.sortConfig && tableProps.props.sortConfig.notSortableFields ? tableProps.props.sortConfig.notSortableFields : [];
      var allNotSortableFields = [].concat((0, _toConsumableArray2.default)(configNotSortableFields), (0, _toConsumableArray2.default)(currentNotSortableFields));

      if (!allNotSortableFields.includes(obj.field) && obj.sortable !== false) {
        obj.sortable = true;
      }
    }

    var copyColumnChildren = []; // 合并传入的定义

    if (copyColumns && copyColumns.length) {
      var findIndex = copyColumns.findIndex(function (p) {
        return p.field === obj.field;
      });

      if (findIndex > -1) {
        var find = copyColumns[findIndex];
        copyColumnChildren = find.children ? find.children : [];

        if (proxyColumns.mergeColumns !== false) {
          obj = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, obj), find), {}, {
            children: obj.children
          });
        } else {
          obj = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, obj), {}, {
            children: obj.children
          });
        }

        copyColumns.splice(findIndex, 1);
      }
    }

    if (obj.children && obj.children.length) {
      obj.children = handleColumnsData(obj.children, copyColumnChildren, configProps, _vm);
    }

    if (obj.colIndex || obj.colIndex === 0) {
      otherColumns.push(obj);
    } else {
      apiColumns.push(obj);
    }
  };

  for (var i = 0; i < data.length; i++) {
    _loop(i);
  }

  copyColumns = copyColumns.concat(otherColumns);
  /*
  data.map(item => {
    // 替换字段
    let obj = {
      ...item
    };
      for (const key in configProps) {
      if (key !== "list") {
        let value = item[configProps[key]];
        if (key === "fixed" && value == "none") {
          value = "";
        }
        obj[key] = value;
      }
    }
    if (sortable) {
      const currentNotSortableFields =
        notSortableFields && notSortableFields.length ? notSortableFields : [];
      const configNotSortableFields =
        tableProps.props &&
        tableProps.props.sortConfig &&
        tableProps.props.sortConfig.notSortableFields
          ? tableProps.props.sortConfig.notSortableFields
          : [];
      const allNotSortableFields = [
        ...configNotSortableFields,
        ...currentNotSortableFields
      ];
      if (!allNotSortableFields.includes(obj.field) && obj.sortable !== false) {
        obj.sortable = true;
      }
    }
    let copyColumnChildren = [];
    // 合并传入的定义
    if (copyColumns && copyColumns.length) {
      const findIndex = copyColumns.findIndex(p => p.field === obj.field);
      if (findIndex > -1) {
        const find = copyColumns[findIndex];
        copyColumnChildren = find.children ? find.children : [];
        obj = { ...obj, ...find, children: obj.children, copyIndex: findIndex };
        find.copyIndex = findIndex;
        copyColumns.splice(findIndex, 1);
      }
    }
    if (obj.children && obj.children.length) {
      obj.children = handleColumnsData(
        obj.children,
        copyColumnChildren,
        configProps,
        _vm
      );
    }
    return obj;
  });
  */
  //处理插入指定位置的传入配置项

  if (copyColumns && copyColumns.length) {
    copyColumns = copyColumns.map(function (item) {
      if (item.colIndex || item.colIndex === 0) {
        apiColumns.splice(item.colIndex, 0, item);
        return "";
      }

      return item;
    }).filter(function (p) {
      return p != "";
    });
  }

  var columnsData = [];

  if (copyColumns && copyColumns.length) {
    columnsData = apiColumns.concat(copyColumns);
  } else {
    columnsData = apiColumns;
  } // this.backupColumns = utils.clone(columnsData);
  // columnsData = columnsData.filter(p => p[configProps.show] !== false);


  return columnsData;
}

var _default2 = {
  name: "DataTable",
  components: {
    DataForm: _dataForm.DataForm,
    SetColumns: _setColumns.default,
    Modal: _modal.Modal
  },
  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _vxeTable.Table.props), {}, {
    columns: Array,
    pagerConfig: {
      type: [Boolean, Object],
      default: function _default() {}
    },
    proxyConfig: Object,
    toolbar: [Boolean, Object],
    formConfig: [Boolean, Object],
    zoomConfig: Object,
    searchConfig: Object,
    headToolbar: Object,
    setcolumnsConfig: Object,
    proxyColumns: Object,
    // 高亮行是否可反选
    highlightCurrentUnselect: Boolean,
    defaultSelectFristRow: {
      type: Boolean,
      default: false
    },
    tableIndex: {
      type: String,
      default: ""
    },
    sortable: {
      type: Boolean,
      default: false
    },
    keyboardSpace: {
      type: [Boolean, String],
      default: null
    },
    notSortableFields: Array // tableHeight: {
    //   type: String,
    //   default: "auto"
    // }

  }),
  mixins: [_editRender.default],
  watch: {
    columns: function columns(val) {
      this.setTableColumns(val);
    }
  },
  data: function data() {
    return {
      backupColumns: [],
      tableColumns: [],
      advancedVisible: false,
      searchData: {},
      tableHeight: "",
      currentRow: {},
      hasAjaxQuery: false,
      hasCheckbox: false //是否存在checkbox

    };
  },
  computed: {
    tableExtendProps: function tableExtendProps() {
      var _this = this;

      var rest = {};
      tablePropKeys.forEach(function (key) {
        rest[key] = _this[key];
      });
      return rest;
    },
    pagerConfigOpt: function pagerConfigOpt() {
      if (this.pagerConfig) {
        return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.pagerConfig), this.pagerConfig);
      } else if (!this.pagerConfig && this.pagerConfig !== false) {
        return _conf.default.pagerConfig;
      }

      return false;
    },
    setColumnsOpt: function setColumnsOpt() {
      if (this.setcolumnsConfig) {
        var modalProps = this.setcolumnsConfig && this.setcolumnsConfig.modal && this.setcolumnsConfig.modal.props ? this.setcolumnsConfig.modal.props : {};
        var proxyConfigProps = this.setcolumnsConfig && this.setcolumnsConfig.proxyConfig && this.setcolumnsConfig.proxyConfig.props ? this.setcolumnsConfig.proxyConfig.props : {};
        var proxyConfigAjax = this.setcolumnsConfig && this.setcolumnsConfig.proxyConfig && this.setcolumnsConfig.proxyConfig.ajax ? this.setcolumnsConfig.proxyConfig.ajax : {};
        var proxyConfigOn = this.setcolumnsConfig && this.setcolumnsConfig.proxyConfig && this.setcolumnsConfig.proxyConfig.on ? this.setcolumnsConfig.proxyConfig.on : {};
        var tableConfig = this.setcolumnsConfig && this.setcolumnsConfig.tableConfig ? this.setcolumnsConfig.tableConfig : {};
        return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.setColumns), {}, {
          modal: {
            props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.setColumns.modal.props), modalProps)
          },
          proxyConfig: {
            params: this.setcolumnsConfig && this.setcolumnsConfig.proxyConfig && this.setcolumnsConfig.proxyConfig.params ? this.setcolumnsConfig.proxyConfig.params : null,
            props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.setColumns.proxyConfig.props), proxyConfigProps),
            ajax: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.setColumns.proxyConfig.ajax), proxyConfigAjax),
            on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.setColumns.proxyConfig.on), proxyConfigOn)
          },
          tableConfig: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.setColumns.tableConfig), tableConfig)
        });
      } else {
        return _conf.default.setColumns;
      }
    },
    proxyConfigOpt: function proxyConfigOpt() {
      if (this.proxyConfig) {
        var proxyConfigProps = this.proxyConfig && this.proxyConfig.props ? this.proxyConfig.props : {};
        return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.proxyConfig), this.proxyConfig), {}, {
          props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.proxyConfig.props), proxyConfigProps)
        });
      }
    },
    tableProps: function tableProps() {
      var _this2 = this;

      var that = this;
      var $listeners = that.$listeners,
          $scopedSlots = that.$scopedSlots,
          tableExtendProps = that.tableExtendProps,
          handleTableQuery = that.handleTableQuery,
          pagerConfigOpt = that.pagerConfigOpt,
          proxyConfigOpt = that.proxyConfigOpt,
          height = that.height,
          onCurrentRowCellClick = that.onCurrentRowCellClick,
          onCurrentRowChange = that.onCurrentRowChange,
          onKeyDownSpace = that.onKeyDownSpace,
          keyboardSpace = that.keyboardSpace;
      var propsData = that.$options.propsData;
      var props = Object.assign({}, tableExtendProps);
      Object.assign(props, {
        props: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.props), propsData), {}, {
          data: proxyConfigOpt ? null : propsData.data,
          proxyConfig: _utils.default.clone(proxyConfigOpt, true),
          // columns: columns,
          loading: propsData.loading
        })
      });

      if (height && _utils.default.isString(height) && height.indexOf("calc") > -1) {
        props.props.height = "auto";
      }

      var ons = {};

      _utils.default.each($listeners, function (cb, type) {
        ons[type] = function () {
          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }

          that.$emit.apply(that, [type].concat(args));
        };
      });

      ons["cell-click"] = onCurrentRowCellClick;
      ons["current-change"] = onCurrentRowChange;
      var isKeyboardSpace = keyboardSpace !== null ? keyboardSpace : _conf.default.keyboardSpace;

      if (isKeyboardSpace) {
        ons["keydown"] = function (e) {
          var event = e.$event;

          if (_this2.hasCheckbox && event.code == "Space") {
            event.preventDefault();
            event.stopPropagation();
            onKeyDownSpace(e);
          }

          that.$emit("keyDown", e);
        };
      }

      if (proxyConfigOpt && proxyConfigOpt.ajax && proxyConfigOpt.ajax.query) {
        that.hasAjaxQuery = true;

        props.props.proxyConfig.ajax.query = function (arr) {
          var json = handleTableQuery(arr);

          if (json === false) {
            return false;
          } else if (json) {
            arr = json;
          }

          arr = that.handleServerSort(arr);
          return new Promise(function (resolve, reject) {
            proxyConfigOpt.ajax.query(arr).then(function (res) {
              resolve(res);

              if (that.defaultSelectFristRow) {
                that.$nextTick(function () {
                  var data = _utils.default.getObjData(props.props.proxyConfig.props.result, res);

                  if (data && data.length) {
                    var grid = that.$refs.dataGrid;

                    if (grid) {
                      grid.setCurrentRow(data[0]);
                      grid.focus();
                      that.onCurrentRowChange({
                        row: data[0],
                        rowIndex: 0,
                        $rowIndex: 0
                      });
                    }
                  }
                });
              }
            }).catch(function (err) {
              reject(err);
            });
          }); // return proxyConfigOpt.ajax.query(arr);
        };
      } // 默认添加分页


      if (props.props.pagerConfig !== false && that.hasAjaxQuery) {
        props.props.pagerConfig = pagerConfigOpt;
      } // 合并排序配置


      if (_conf.default.sortConfig && _utils.default.isObject(_conf.default.sortConfig)) {
        if (props.props.sortConfig) {
          props.props.sortConfig = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.sortConfig), props.props.sortConfig);
        } else {
          props.props.sortConfig = (0, _objectSpread2.default)({}, _conf.default.sortConfig);
        }
      } // 全局处理服务端排序
      // if (
      //   props.props.sortConfig &&
      //   props.props.sortConfig.remote &&
      //   !$listeners["sort-change"]
      // ) {
      //   ons["sort-change"] = handleServerSort;
      // }


      props.on = ons;
      props.ref = "dataGrid";
      props.scopedSlots = $scopedSlots;
      return props;
    }
  },
  created: function created() {
    var columns = this.columns,
        proxyColumns = this.proxyColumns,
        fetchColumns = this.fetchColumns,
        proxyConfigOpt = this.proxyConfigOpt;

    if (proxyColumns) {
      // 表头代理
      fetchColumns(proxyColumns);
    } else {
      this.setTableColumns(columns);
    }

    if (proxyConfigOpt && proxyConfigOpt.ajax && proxyConfigOpt.ajax.query) {
      this.hasAjaxQuery = true;
    }
  },
  mounted: function mounted() {},
  destroyed: function destroyed() {},
  methods: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, methods), {}, {
    headSearch: function headSearch() {
      var _this3 = this;

      this.$nextTick(function () {
        _this3.$refs.headSearch.onSubmit();
      });
    },
    reload: function reload() {
      var proxyConfig = this.proxyConfig;

      if (proxyConfig && proxyConfig.ajax && proxyConfig.ajax.query) {
        this.$refs.dataGrid.commitProxy("query");
      }
    },
    query: function query(params) {
      var proxyConfig = this.proxyConfig;

      if (proxyConfig && proxyConfig.ajax && proxyConfig.ajax.query) {
        if (params) {
          this.searchData = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.searchData), params);
        }

        this.$refs.dataGrid.commitProxy("reload");
      }
    },
    onSearchSubmit: function onSearchSubmit(values) {
      this.searchData = values;
      this.query();
    },
    // 处理调用 proxyConfig.ajax 的query查询方法前处理请求参数
    handleTableQuery: function handleTableQuery(arr) {
      var searchData = this.searchData,
          pagerConfigOpt = this.pagerConfigOpt; // 头部搜索表单数据
      // let headSearchFormData = {}
      // if (headToolbar && headToolbar.searchConfig && headToolbar.searchConfig.items) {
      //   const headSearchForm = this.$refs.headSearch;
      //   headSearchFormData = headSearchForm.getData();
      // }
      // 分页参数

      var pageData = {};

      if (pagerConfigOpt && arr.page) {
        var pageField = pagerConfigOpt.props.currentPage;

        if (pagerConfigOpt.pageIndex === 0) {
          pageData[pageField] = arr.page.currentPage - 1;
        } else if (pagerConfigOpt.pageIndex) {
          pageData[pageField] = arr.page.currentPage - 1 + pagerConfigOpt.pageIndex;
        } else {
          pageData[pageField] = arr.page.currentPage;
        }

        var pageSizeField = pagerConfigOpt.props.pageSize;
        pageData[pageSizeField] = arr.page.pageSize;
      } else if (arr && arr.$grid) {
        pageData = {};
      } else {
        pageData = arr;
      }

      var json = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, pageData), searchData);

      if (arr.filters.length) {
        json.filters = arr.filters;
      }

      if (arr.sort) {
        json.sort = arr.sort;
      } // this.tableAjaxJson = json;


      return json;
    },
    onButtonActionClick: function onButtonActionClick(action, e) {
      var _this4 = this;

      var searchData = this.searchData;

      if (action === "advancedQuery") {
        if (e) e.target.blur(); // 显示高级查询

        this.advancedVisible = true;
        this.$nextTick(function () {
          _this4.$refs.advancedSearch.setData(searchData);

          var advancedSearchForm = _utils.default.clone(_this4.headToolbar.search, true).advancedSearchForm;

          if (advancedSearchForm && advancedSearchForm.on && advancedSearchForm.on.open) {
            advancedSearchForm.on.open(_this4.$refs.advancedSearch, searchData);
          }
        });
      }
    },
    onAdvancedReset: function onAdvancedReset() {
      var $refs = this.$refs;
      $refs.advancedSearch.resetFields();

      if (_conf.default.advancedResetClearHeadSearchForm) {
        $refs.headSearch.resetFields();
        this.searchData = {};
      }
    },
    onAdvancedSubmit: function onAdvancedSubmit() {
      var _this5 = this;

      var $refs = this.$refs,
          onAdvancedcancel = this.onAdvancedcancel;
      $refs.advancedSearch.validateFields(function (err, values) {
        //同步值到headform
        var headSearchForm = _this5.$refs.headSearch;
        headSearchForm.setData(values);
        _this5.searchData = values;

        _this5.query();

        onAdvancedcancel();
      });
    },
    onAdvancedcancel: function onAdvancedcancel() {
      this.advancedVisible = false;
    },
    // 显示表头设置窗口
    showSetColumns: function showSetColumns() {
      if (this.$refs.setColumsModal) {
        this.$refs.setColumsModal.show();
      }
    },
    // 设置表头
    setTableColumns: function setTableColumns(data) {
      var proxyColumns = this.proxyColumns,
          fetchColumns = this.fetchColumns,
          sortable = this.sortable,
          notSortableFields = this.notSortableFields;

      if (data) {
        var columnsData = _utils.default.clone(data);

        if (sortable) {
          var currentNotSortableFields = notSortableFields && notSortableFields.length ? notSortableFields : [];
          var configNotSortableFields = _conf.default.sortConfig && _conf.default.sortConfig.notSortableFields ? _conf.default.sortConfig.notSortableFields : [];
          var allNotSortableFields = [].concat((0, _toConsumableArray2.default)(configNotSortableFields), (0, _toConsumableArray2.default)(currentNotSortableFields));
          columnsData = columnsData.map(function (p) {
            if (!allNotSortableFields.includes(p.field) && p.sortable !== false) {
              p.sortable = true;
            }

            return p;
          });
        }

        this.backupColumns = columnsData;
        var configProps = proxyColumns && proxyColumns.props && _utils.default.isObject(proxyColumns.props) ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.proxyColumns.props), proxyColumns.props) : _conf.default.proxyColumns.props;
        var hasCheckbox = false;
        this.tableColumns = this.editColumnsInit(columnsData, function (p) {
          if (!hasCheckbox && p.type == "checkbox") {
            hasCheckbox = true;
          }

          return p[configProps.show] !== false;
        });
        this.hasCheckbox = hasCheckbox;
      } else if (proxyColumns) {
        fetchColumns(proxyColumns);
      }
    },
    // // 渲染ACheckbox编辑组件
    // renderCheckbox(scope) {
    //   const vm = new Vue();
    //   const h = vm.$createElement;
    //   const currentColumn = this.tableColumns[scope.columnIndex];
    //   return h("a-checkbox", {
    //     props: {
    //       ...currentColumn.editRender.props,
    //       checked: scope.row[scope.column.property]
    //     },
    //     on: {
    //       input(val) {
    //         scope.row[scope.column.property] = val;
    //         if (
    //           currentColumn.editRender.on &&
    //           currentColumn.editRender.on.change
    //         ) {
    //           currentColumn.editRender.on.change(scope);
    //         }
    //       }
    //     }
    //   });
    // },
    // // 渲染ASwitch编辑组件
    // renderSwitch(scope) {
    //   const vm = new Vue();
    //   const h = vm.$createElement;
    //   const currentColumn = this.tableColumns[scope.columnIndex];
    //   return h("a-switch", {
    //     props: {
    //       ...currentColumn.editRender.props,
    //       checked: scope.row[scope.column.property]
    //     },
    //     on: {
    //       input: val => {
    //         scope.row[scope.column.property] = val;
    //       },
    //       update: val => {
    //         scope.row[scope.column.property] = val;
    //       },
    //       change(val) {
    //         scope.row[scope.column.property] = val;
    //         if (
    //           currentColumn.editRender.on &&
    //           currentColumn.editRender.on.change
    //         ) {
    //           currentColumn.editRender.on.change(scope);
    //         }
    //       }
    //     }
    //   });
    // },
    // // 渲染下拉面板显示组件
    // renderPulldownTableView(scope) {
    //   const vm = new Vue();
    //   const h = vm.$createElement;
    //   const value = scope.row[scope.column.property];
    //   const currentColumn = this.tableColumns[scope.columnIndex];
    //   const taxtField =
    //     currentColumn.editRender.props &&
    //     currentColumn.editRender.props.textField
    //       ? currentColumn.editRender.props.textField
    //       : "name";
    //   let text = "";
    //   if (value && utils.isArray(value)) {
    //     text = value.map(p => p[taxtField]).join(",");
    //   } else if (value && utils.isObject(value)) {
    //     text = value[taxtField];
    //   } else if (value) {
    //     text = value;
    //   }
    //   return h("div", {}, [text]);
    // },
    // // 渲染下拉面板组件
    // renderPulldownTable(scope) {
    //   // const { handlePulldownTableChange } = this;
    //   const vm = new Vue();
    //   const h = vm.$createElement;
    //   const currentColumn = this.tableColumns[scope.columnIndex];
    //   return h("pulldownTable", {
    //     props: {
    //       ...currentColumn.editRender.props
    //     },
    //     on: {
    //       change(val) {
    //         scope.row[scope.column.property] = val;
    //         if (
    //           currentColumn.editRender.on &&
    //           currentColumn.editRender.on.change
    //         ) {
    //           currentColumn.editRender.on.change(scope);
    //         }
    //       }
    //     }
    //   });
    // },
    // api获取表头
    fetchColumns: function fetchColumns(opt) {
      var _this6 = this;

      var columns = this.columns;
      var that = this;
      var defaultAjax = _conf.default.proxyColumns && _conf.default.proxyColumns.defaultAjax ? _conf.default.proxyColumns.defaultAjax : {};
      var params = {
        columns: columns
      };
      var queryApi = null;

      if (opt.params) {
        params = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), opt.params);

        if (defaultAjax && defaultAjax.query && !(opt.ajax && opt.ajax.query)) {
          queryApi = defaultAjax.query;
        }
      }

      if (opt.ajax && opt.ajax.query) {
        queryApi = opt.ajax.query;
      }

      if (queryApi) {
        queryApi(params).then(function (res) {
          var configProps = opt.props && _utils.default.isObject(opt.props) ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _conf.default.proxyColumns.props), opt.props) : _conf.default.proxyColumns.props;

          var data = _utils.default.getObjData(configProps.list, res);

          var tableColumns = handleColumnsData(data, columns, configProps, that);
          _this6.backupColumns = _utils.default.clone(tableColumns); // this.tableColumns = tableColumns.filter(
          //   p => p[configProps.show] !== false
          // );

          var hasCheckbox = false;
          _this6.tableColumns = _this6.editColumnsInit(tableColumns, function (p) {
            if (!hasCheckbox && p.type == "checkbox") {
              hasCheckbox = true;
            }

            return p[configProps.show] !== false;
          });
          _this6.hasCheckbox = hasCheckbox;
        });
      }
    },
    // 工具条按钮点击
    onToobarButtonClick: function onToobarButtonClick(code) {
      this.$emit("toobarButtonClick", code);
    },
    // 设置搜索表单的值
    setSearchData: function setSearchData(values) {
      var headSearchForm = this.$refs.headSearchForm;

      if (headSearchForm && headSearchForm.setData) {
        headSearchForm.setData(values);
      }

      var headToolbarSearch = this.$refs.headSearch;

      if (headToolbarSearch && headToolbarSearch.setData) {
        headToolbarSearch.setData(values);
      }

      this.searchData = values;
    },
    // 获取搜索表单的值
    getSearchData: function getSearchData() {
      return this.searchData;
    },
    // 允许反选高亮行时接管，高亮行选中事件
    onCurrentRowChange: function onCurrentRowChange(e) {
      var that = this;
      setTimeout(function () {
        that.currentRow = e.row;
      }, 10);
      this.$emit("current-change", e);
    },
    //当表格被激活且键盘被按下空格时
    onKeyDownSpace: _utils.default.debounce(function () {
      var _this7 = this;

      var grid = this.$refs.dataGrid;
      var row = this.currentRow;
      grid.setCheckboxRow(row, !grid.isCheckedByCheckboxRow(row));
      this.$nextTick(function () {
        _this7.$emit("checkbox-change", {
          records: grid.getCheckboxRecords()
        });
      });
    }, 300),
    // 允许反选高亮行时接管，单元格点击事件
    onCurrentRowCellClick: function onCurrentRowCellClick(e) {
      var that = this;

      if (that.highlightCurrentUnselect) {
        if (that.currentRow._X_ROW_KEY && e.row._X_ROW_KEY === that.currentRow._X_ROW_KEY) {
          that.$refs.dataGrid.clearCurrentRow();
          that.currentRow = {};
          that.$emit("current-change", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, e), {}, {
            row: null
          }));
        }
      }

      that.$emit("cell-click", e); //表格  行编辑 专用

      that.onEditTableCurrentRowCellClick(e);
    },
    handleServerSort: function handleServerSort(params) {
      var tableProps = this.tableProps;

      if (tableProps.props.sortConfig && tableProps.props.sortConfig.handleServerSortParams) {
        params = tableProps.props.sortConfig.handleServerSortParams(params);
      }

      return params;
    }
  }),
  beforeDestroy: function beforeDestroy() {},
  render: function render(h) {
    var tableProps = this.tableProps,
        headToolbar = this.headToolbar,
        setcolumnsConfig = this.setcolumnsConfig,
        height = this.height,
        searchConfig = this.searchConfig;
    var nodes = [];

    if (headToolbar && headToolbar.tools && headToolbar.tools.setColumns || setcolumnsConfig) {
      nodes.push(renderColumnsModal(h, this));
    }

    var tableHeight = "";

    if (height && _utils.default.isString(height) && height.indexOf("calc") > -1) {
      tableHeight = height;
    } // // 渲染头部搜索表单


    var headSearchForm = "";

    if (searchConfig) {
      // 头部搜索
      headSearchForm = renderHeadSearch(searchConfig, h, this);
    }

    return h("div", {
      class: "data-table"
    }, [headSearchForm, renderHeadToolbar(h, this), h("div", {
      style: {
        height: tableHeight
      },
      attrs: {
        "table-index": this.tableIndex.toString()
      }
    }, [h("vxe-grid", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, tableProps), {}, {
      props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, tableProps.props), {}, {
        columns: this.tableColumns
      })
    }))])].concat(nodes));
  }
};
exports.default = _default2;