"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;

require("regenerator-runtime/runtime.js");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

var _babelHelperVueJsxMergeProps = _interopRequireDefault(require("@vue/babel-helper-vue-jsx-merge-props"));

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

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

var _moment = _interopRequireDefault(require("moment"));

var _lodash = require("lodash");

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

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

var _inputNumber = _interopRequireDefault(require("../../../dataForm/src/inputNumber"));

var _select = _interopRequireDefault(require("../../../dataForm/src/select"));

var _datePicker = _interopRequireDefault(require("../../../dataForm/src/datePicker"));

var _timePicker = _interopRequireDefault(require("../../../dataForm/src/timePicker"));

var _autoComplete = _interopRequireDefault(require("../../../dataForm/src/autoComplete"));

// 请求表单项可选数据
var fetchItemPropsOptionsApiList = /*#__PURE__*/function () {
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_vm) {
    var that, onEditOptionsLoadBefore, editApiList, optionDataRender, list, beforeRes, promises;
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            that = _vm;
            onEditOptionsLoadBefore = that.onEditOptionsLoadBefore, editApiList = that.editApiList, optionDataRender = that.optionDataRender;
            list = editApiList;

            if (!onEditOptionsLoadBefore) {
              _context.next = 10;
              break;
            }

            beforeRes = onEditOptionsLoadBefore(list);

            if (!(beforeRes === false)) {
              _context.next = 9;
              break;
            }

            return _context.abrupt("return", false);

          case 9:
            if (beforeRes) {
              list = beforeRes;
            }

          case 10:
            promises = list.map(function (p) {
              return p.api(p.param);
            });
            Promise.all(promises).then(function (res) {
              var editOptions = that.editOptions,
                  editDefaultOption = that.editDefaultOption,
                  onOptionsLoadAfter = that.onOptionsLoadAfter;
              list.forEach(function (item, index) {
                var defaultField = item.defaultField,
                    field = item.field,
                    fields = item.fields;
                var data = res[index];

                if (fields && fields.length) {
                  fields.forEach(function (p) {
                    var optionsData = handlefieldOptionsDataField(p, data, that);
                    field = p.field;
                    editOptions[field] = optionsData.map(function (o) {
                      o = optionDataRender(o, field);

                      if (o[defaultField]) {
                        editDefaultOption[field] = o.value;
                      }

                      return o;
                    });
                  });
                } else {
                  // 字段单独配置api的可选数据的处理
                  var optionsData = handlefieldOptionsDataField(item, data, that);
                  editOptions[field] = optionsData.map(function (p) {
                    p = optionDataRender(p, field);

                    if (p[defaultField]) {
                      editDefaultOption[field] = p.value;
                    }

                    return p;
                  });
                }
              });

              if (that.onOptionsAllLoad) {
                editOptions = that.onOptionsAllLoad(editOptions);
              }

              that.editOptions = editOptions;
              that.editDefaultOption = editDefaultOption;

              if (onOptionsLoadAfter) {
                onOptionsLoadAfter(editOptions, editDefaultOption);
              }

              that.$refs.dataGrid && that.$refs.dataGrid.updateData();
            });

          case 12:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));

  return function fetchItemPropsOptionsApiList(_x) {
    return _ref.apply(this, arguments);
  };
}(); // 驼峰转换下划线


function toLine(name) {
  name = name.replace(/([A-Z])/g, "-$1").toLowerCase();
  return name[0] == "-" ? name.slice(1) : name;
} //单行编辑时 数据转换


function dataFormat(value, props, name, event) {
  if (props.default) {
    value = props.default(event);
  } else if (value.format) {
    if (props.format) {
      value = value.format(props.format);
    } else if (name == "a-date-picker") {
      if (props.showTime) {
        value = value.format("YYYY-MM-DD HH:mm:ss");
      } else {
        value = value.format("YYYY-MM-DD");
      }
    } else {
      value = value.format("HH:mm:ss");
    }
  }

  return value;
} //根据路径参数 查找对应数据


function handlefieldOptionsDataField(item, json) {
  var optionData = json;

  if (item) {
    var dataField = item.dataField != undefined ? item.dataField : _conf.default.getSelectOptions.dataField;
    optionData = _utils.default.getObjData(dataField, json);
  }

  return optionData;
} //插槽class  style 等重写


function editSlotItemRender(name, e) {
  if (typeof name == "function") {
    return name(e);
  } else {
    return name;
  }
}
/**
 * @description: 查询对应属性 根据属性类型做对应处理
 * @param {*} row
 * @param {*} props
 * @param {*} key
 * @param {*} event
 * @param {*} defaultKey
 * @return {*}
 */


function editSlotPropInit(row, props, key, event) {
  var defaultKey = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  return !props[key] && props[key] != 0 ? defaultKey : typeof props[key] == "function" ? props[key](row, event) : props[key];
}

var editRender = {
  components: {
    OpuInputNumber: _inputNumber.default,
    OpuSelect: _select.default,
    OpuDatePicker: _datePicker.default,
    OpuTimePicker: _timePicker.default,
    OpuAutoComplete: _autoComplete.default
  },
  props: {
    onEditOptionsLoadBefore: {
      type: Function,
      default: null
    },
    editSize: {
      type: String,
      default: ""
    },
    onOptionsLoadAfter: {
      type: Function,
      default: null
    },
    onOptionsAllLoad: {
      type: Function,
      default: null
    },
    editLine: {
      type: Boolean,
      default: false
    },
    isCacheOption: {
      type: Boolean,
      default: true
    }
  },
  data: function data() {
    return {
      editType: ["a-input", "a-input-number", "a-select", "a-auto-complete", "a-date-picker", "a-time-picker", "a-switch", "a-checkbox", "pulldown-table"],
      editTypeTargetName: {
        "a-input-number": "OpuInputNumber",
        "a-select": "OpuSelect",
        "a-auto-complete": "OpuAutoComplete",
        "a-date-picker": "OpuDatePicker",
        "a-time-picker": "OpuTimePicker"
      },
      componentsFocusItemTypes: ["a-input", "a-input-number", "a-select", "a-auto-complete", "a-date-picker", "a-time-picker", "pulldown-table"],
      lineEditTypes: ["pulldown-table", "a-input", "a-input-number", "a-auto-complete", "a-select", "a-date-picker", "a-time-picker"],
      enterTypes: ["pulldown-table", "a-input", "a-input-number", "a-auto-complete", "a-select", "a-date-picker", "a-time-picker"],
      //enter  数组
      pressEnterItems: [],
      //用于加减field
      leftPressEnterItems: [],
      editOptions: {},
      editApiList: [],
      editDefaultOption: {},
      editFieldList: {},
      currentCell: null,
      columnsIndexs: []
    };
  },
  computed: {
    editItemSize: function editItemSize() {
      var editSize = this.editSize;

      if (editSize === "") {
        editSize = _conf.default.editSize;
      }

      return editSize;
    }
  },
  mounted: function mounted() {},
  methods: {
    /**
     * @description: 设置下拉数据
     * @param {*} data
     * @return {*}
     */
    setFieldsOptions: function setFieldsOptions(data, callback) {
      var _this = this;

      var editOptions = this.editOptions,
          editFieldList = this.editFieldList;

      var _loop = function _loop(key) {
        var item = data[key];

        if (editFieldList[key]) {
          // editOptions[key] = item;
          editOptions[key] = item.map(function (p) {
            return _this.optionDataRender(p, key);
          });
        }
      };

      for (var key in data) {
        _loop(key);
      }

      this.editOptions = editOptions;
      this.$refs.dataGrid.updateData();
      this.$nextTick(function () {
        callback && callback();
      });
    },

    /**
     * @description: 获取下拉数据
     * @param {*}
     * @return {*}
     */
    getFieldsOptions: function getFieldsOptions() {
      return this.editOptions;
    },

    /**
     * @description: 获取默认数据
     * @param {*}
     * @return {*}
     */
    getEditDefaultOption: function getEditDefaultOption() {
      return this.editDefaultOption;
    },

    /**
     * @description: 表格编辑行点击
     * @param {*}
     * @return {*}
     */
    onEditTableCurrentRowCellClick: function onEditTableCurrentRowCellClick(e) {
      var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      var that = this;
      var currentCell = that.currentCell || {};
      var currentRowIndex = currentCell.rowIndex;
      that.currentCell = e;

      if (e && this.editLine) {
        if (e.rowIndex === currentRowIndex) {
          return;
        }

        var item = that.pressEnterItems.find(function (p) {
          if (e.field) {
            return p.field == e.field;
          } else {
            return p.columnIndex == e.$columnIndex;
          }
        });

        if (item) {
          e.field = item.field;
          that.itemFocus(e, type);
        }

        setTimeout(function () {
          document.body.removeEventListener("click", that.onBlurEditTable);
          document.body.addEventListener("click", that.onBlurEditTable, false);
        }, 50);
      }
    },

    /**
     * @description: 离开行编辑
     * @param {*}
     * @return {*}
     */
    onBlurEditLine: function onBlurEditLine() {
      this.currentCell = null;
    },
    onBlurEditTable: function onBlurEditTable(e) {
      var that = this;
      var event = e || window.event;
      var target = event.target || event.srcElement;
      var pathIndex = 0;
      var dataGrid = this.$refs.dataGrid;

      while (target.parentNode === null) {
        pathIndex++;
        target = event.path[pathIndex];
      }

      this.$nextTick(function () {
        //时间
        var timeEl = document.getElementsByClassName("ant-time-picker-panel"); //日期

        var dateEl = document.getElementsByClassName("ant-calendar-picker-container"); //下拉

        var selectEl = document.getElementsByClassName("ant-select-dropdown"); //下拉表格

        var tableEl = document.getElementsByClassName("vxe-pulldown--panel"); //特殊处理数组

        var specialEl = [].concat((0, _toConsumableArray2.default)(timeEl), (0, _toConsumableArray2.default)(dateEl), (0, _toConsumableArray2.default)(selectEl), (0, _toConsumableArray2.default)(tableEl));
        var isContains = false;

        for (var i = 0; i < specialEl.length; i++) {
          var el = specialEl[i];
          isContains = el.contains(target);
          if (isContains) break;
        }

        if (!isContains && dataGrid && !dataGrid.$el.contains(target)) {
          that.onBlurEditLine();
          document.body.removeEventListener("click", that.onBlurEditTable);
        }
      });
    },

    /**
     * @description: 重构下拉数据option
     * @param {*} o
     * @param {*} field
     * @param {*} pValue
     * @param {*} editFieldList
     * @return {*}
     */
    optionDataRender: function optionDataRender(o, field) {
      var _this2 = this;

      var pValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
      var editFieldList = arguments.length > 3 ? arguments[3] : undefined;
      if (!editFieldList) editFieldList = this.editFieldList;

      if (editFieldList[field]) {
        var _editFieldList$field = editFieldList[field],
            labelField = _editFieldList$field.labelField,
            valueField = _editFieldList$field.valueField,
            childrenField = _editFieldList$field.childrenField;

        if ((o.value || o.value == 0) && !o[_conf.default.originalValueKey]) {
          o[_conf.default.originalValueKey || "originalValueKey"] = o.value;
        }

        if (labelField != "label") {
          o.label = o[labelField];
        }

        if (valueField != "value") {
          o.value = o[valueField];
        }

        if (pValue) {
          o._pValue = pValue;
        }

        if (childrenField != "children" && o[childrenField].length > 0) {
          o.children = o[childrenField].map(function (p) {
            return _this2.optionDataRender(p, field, o.value);
          });
        }
      }

      return o;
    },

    /**
     * @description: 表格列重构
     * @param {*} data
     * @param {*} filterCallback
     * @param {*} isAll
     * @return {*}
     */
    editColumnsInit: function editColumnsInit(data, filterCallback, isAll) {
      var that = this;
      var getSelectOptions = _conf.default.getSelectOptions;

      var _this$editColumnsRend = this.editColumnsRender({
        data: data,
        getSelectOptions: getSelectOptions,
        unifyApiList: {
          api: getSelectOptions && getSelectOptions.api,
          param: {},
          fields: []
        },
        otherApiList: [],
        enterItems: {
          left: [],
          center: [],
          right: []
        },
        columnsIndexs: {},
        isAll: isAll,
        filterCallback: filterCallback
      }),
          tableData = _this$editColumnsRend.data,
          unifyApiList = _this$editColumnsRend.unifyApiList,
          otherApiList = _this$editColumnsRend.otherApiList,
          enterItems = _this$editColumnsRend.enterItems,
          columnsIndexs = _this$editColumnsRend.columnsIndexs;

      if (unifyApiList.fields.length > 0) {
        otherApiList = otherApiList.concat(unifyApiList);
      }

      that.columnsIndexs = columnsIndexs;
      that.pressEnterItems = [].concat((0, _toConsumableArray2.default)(enterItems.left), (0, _toConsumableArray2.default)(enterItems.center), (0, _toConsumableArray2.default)(enterItems.right));
      that.editApiList = otherApiList; // that.editFieldList = editFieldList;

      if (otherApiList.length > 0) {
        that.loadOptionsData();
      }

      return tableData;
    },

    /**
     * @description: 重构表格编辑列
     * @param {*}
     * @return {*}
     */
    editColumnsRender: function editColumnsRender(_ref2) {
      var _this3 = this;

      var data = _ref2.data,
          _ref2$index = _ref2.index,
          index = _ref2$index === void 0 ? 0 : _ref2$index,
          getSelectOptions = _ref2.getSelectOptions,
          unifyApiList = _ref2.unifyApiList,
          otherApiList = _ref2.otherApiList,
          enterItems = _ref2.enterItems,
          columnsIndexs = _ref2.columnsIndexs,
          isAll = _ref2.isAll,
          filterCallback = _ref2.filterCallback;
      var h = this.$createElement;
      var that = this;
      var editType = that.editType,
          enterTypes = that.enterTypes,
          isCacheOption = that.isCacheOption,
          editFieldList = that.editFieldList,
          editOptions = that.editOptions,
          editDefaultOption = that.editDefaultOption;
      var tableData = data.filter(function (p) {
        if (filterCallback && !filterCallback(p)) return false;

        if (p.children && p.children.length > 0) {
          var res = _this3.editColumnsRender({
            data: p.children,
            index: index,
            getSelectOptions: getSelectOptions,
            unifyApiList: unifyApiList,
            otherApiList: otherApiList,
            enterItems: enterItems,
            columnsIndexs: columnsIndexs,
            isAll: isAll,
            filterCallback: filterCallback
          });

          index = res.index - 1;
          enterItems = res.enterItems;
          columnsIndexs = res.columnsIndexs;
          p.children = res.data;
        } else {
          var field = p.field;
          p.columnIndex = index++;
          columnsIndexs[field] = p;
          var itemRender = p.itemRender;

          if (itemRender) {
            itemRender.name = toLine(itemRender.name || editType[0]);
            var name = itemRender.name;

            if (editType.includes(name)) {
              itemRender = itemRender || {};
              itemRender.props = itemRender.props || {};
              itemRender.on = itemRender.on || {};
              if (!p.slots) p.slots = {};

              if (enterTypes.includes(name)) {
                enterItems[p.fixed || "center"].push(p);
              }

              p.slots.default = function (e) {
                return [h("div", (0, _babelHelperVueJsxMergeProps.default)([{}, {
                  on: {
                    click: function click(event) {
                      var currentCell = that.currentCell;

                      if (currentCell) {
                        var currentColumnIndex = currentCell.columnIndex,
                            currentRowIndex = currentCell.rowIndex;
                        var columnIndex = e.columnIndex,
                            rowIndex = e.rowIndex;

                        if (currentRowIndex !== undefined && currentColumnIndex !== undefined && columnIndex === currentColumnIndex && rowIndex === currentRowIndex) {
                          event.stopPropagation(); // event.preventDefault();

                          return;
                        }
                      }
                    },
                    keyup: function () {
                      var _keyup = (0, _asyncToGenerator2.default)( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(event) {
                        var _res, _that$currentCell, rowIndex, row;

                        return regeneratorRuntime.wrap(function _callee2$(_context2) {
                          while (1) {
                            switch (_context2.prev = _context2.next) {
                              case 0:
                                if (!itemRender.on.keyup) {
                                  _context2.next = 6;
                                  break;
                                }

                                _context2.next = 3;
                                return itemRender.on.keyup(e, event);

                              case 3:
                                _res = _context2.sent;

                                if (!(_res === false)) {
                                  _context2.next = 6;
                                  break;
                                }

                                return _context2.abrupt("return");

                              case 6:
                                if (name == "a-select" && event.keyCode == 13) {
                                  _that$currentCell = that.currentCell, rowIndex = _that$currentCell.rowIndex, row = _that$currentCell.row;
                                  setTimeout(function () {
                                    that.pressEnterItem({
                                      columnIndex: index,
                                      rowIndex: rowIndex,
                                      row: row,
                                      field: field
                                    });
                                  }, 50);
                                }

                              case 7:
                              case "end":
                                return _context2.stop();
                            }
                          }
                        }, _callee2);
                      }));

                      function keyup(_x2) {
                        return _keyup.apply(this, arguments);
                      }

                      return keyup;
                    }()
                  },
                  style: "display:flex;align-items: center;"
                }]), [itemRender.before && itemRender.before(e), h("div", {
                  "style": "flex:1;max-width: 100%;"
                }, [that.editSlotRender(name)(e)]), itemRender.after && itemRender.after(e)])];
              };

              if (name == "a-switch" || name == "a-checkbox") p.align = "center";
              var props = itemRender.props;

              if (["a-select", "a-auto-complete"].includes(name) && props) {
                var valueField = props.valueField || getSelectOptions.valueField;
                var labelField = props.labelField || getSelectOptions.labelField;
                var childrenField = props.childrenField || getSelectOptions.childrenField;
                var dataField = props.dataField || getSelectOptions.dataField;
                var defaultField = props.defaultField || getSelectOptions.defaultField;
                var searchFields = props.searchFields || _conf.default.defaultProps.select.searchFields || [];

                if (!(editFieldList[field] && props.api == editFieldList[field].api && _utils.default.isEqual(editFieldList[field].param, props.param))) {
                  editFieldList[field] = {
                    valueField: valueField,
                    labelField: labelField,
                    childrenField: childrenField,
                    defaultField: defaultField,
                    searchFields: searchFields,
                    api: props.api,
                    param: props.param
                  };

                  if (props.options) {
                    editOptions[field] = (0, _lodash.cloneDeep)(props.options).map(function (o) {
                      o = that.optionDataRender(o, field, "", (0, _defineProperty2.default)({}, field, {
                        valueField: valueField,
                        labelField: labelField,
                        childrenField: childrenField
                      }));

                      if (o[defaultField]) {
                        editDefaultOption[field] = p.value;
                      }

                      return o;
                    });
                  } else if (!props.optionsField && (props.api || props.dataField || props.param) && (!isCacheOption || !editOptions[field] || isAll)) {
                    var item = {
                      field: field,
                      api: props.api,
                      valueField: valueField,
                      labelField: labelField,
                      childrenField: childrenField,
                      dataField: dataField,
                      defaultField: defaultField,
                      param: props.param || {}
                    };

                    if (props.api) {
                      otherApiList.push(item);
                    } else {
                      for (var key in props.param) {
                        if (unifyApiList.param[key] && _utils.default.isArray(unifyApiList.param[key])) {
                          unifyApiList.param[key].push(props.param[key]);
                        } else {
                          unifyApiList.param[key] = [props.param[key]];
                        }
                      }

                      unifyApiList.fields.push(item);
                    }
                  }
                }
              }
            }
          }
        }

        return true;
      });
      return {
        data: tableData,
        index: index,
        unifyApiList: unifyApiList,
        otherApiList: otherApiList,
        enterItems: enterItems,
        columnsIndexs: columnsIndexs
      };
    },
    loadOptionsData: function loadOptionsData(isAll) {
      if (isAll) {
        this.setTableColumns(this.columns, isAll);
      } else {
        fetchItemPropsOptionsApiList(this);
      }
    },

    /**
     * @description: 选中某一行 并且触发表格编辑
     * @param {*} rowIndex
     * @return {*}
     */
    focusEditRow: function focusEditRow() {
      var _this4 = this;

      var rowIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
      var pressEnterItems = this.pressEnterItems;
      var dataGrid = this.$refs.dataGrid;
      var data = this.data || dataGrid.getData();
      var row = data[rowIndex];

      if (row && pressEnterItems.length > 0) {
        dataGrid.setCurrentRow(row);
        setTimeout(function () {
          _this4.onEditTableCurrentRowCellClick({
            row: row,
            rowIndex: rowIndex,
            columnIndex: pressEnterItems[0].columnIndex,
            field: pressEnterItems[0].field
          });
        }, 50);
      }
    },

    /**
     * @description: 表格编辑 选中元素 按下enter
     * @param {*}
     * @return {*}
     */
    pressEnterItem: function pressEnterItem(event) {
      var that = this;
      var pressEnterItems = that.pressEnterItems;
      var rowIndex = event.rowIndex,
          row = event.row,
          field = event.field;
      var index = pressEnterItems.findIndex(function (p) {
        return p.field == field;
      });
      var data = that.data || that.$refs.dataGrid.getData();
      if (!row) row = data[rowIndex]; //换下一行

      if (index == pressEnterItems.length - 1) {
        rowIndex += 1; //如果是最后一个

        if (data.length == rowIndex) {
          this.$emit("enterLastItem");
        } else {
          row = data[rowIndex];
          that.$refs.dataGrid.setCurrentRow(row);
          that.onEditTableCurrentRowCellClick({
            row: row,
            rowIndex: rowIndex,
            columnIndex: pressEnterItems[0].columnIndex,
            field: pressEnterItems[0].field
          }, true);
        }
      } else {
        var nextItem = pressEnterItems[index + 1];
        var nextEvent = {
          row: row,
          rowIndex: event.rowIndex,
          columnIndex: nextItem.columnIndex,
          field: nextItem.field
        };
        var disabled = editSlotPropInit(row, nextItem.itemRender.props, "disabled", nextEvent); //如果禁用 跳转下一个

        if (disabled) {
          that.pressEnterItem(nextEvent);
        } else {
          that.itemFocus(nextEvent);
        }
      }
    },

    /**
     * @description: 指定行 field focus
     * @param {*} event
     * @return {*}
     */
    itemFieldFocus: function itemFieldFocus(event) {
      var that = this;
      var pressEnterItems = that.pressEnterItems,
          editLine = that.editLine;
      var field = event.field,
          rowIndex = event.rowIndex;
      var index = pressEnterItems.findIndex(function (p) {
        return p.field == field;
      });
      var newEvent = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, event), {}, {
        rowIndex: rowIndex,
        columnIndex: pressEnterItems[index].columnIndex
      });
      var dataGrid = that.$refs.dataGrid;
      var data = that.data || dataGrid.getData();
      var row = data[rowIndex];

      if (row) {
        document.body.removeEventListener("click", that.onBlurEditTable);
        that.currentCell = newEvent;
        dataGrid.setCurrentRow(row);
        that.itemFocus(newEvent);

        if (editLine) {
          setTimeout(function () {
            document.body.addEventListener("click", that.onBlurEditTable, false);
          }, 50);
        }
      }
    },

    /**
     * @description: 选中某个表格编辑项
     * @param {*} rowIndex
     * @param {*} columnIndex
     * @param {*} field
     * @return {*}
     */
    itemFocus: function itemFocus(event) {
      var _this5 = this;

      var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
      var that = this;
      that.$nextTick(function () {
        var input = that.$refs["input-" + event.rowIndex + "-" + event.field];
        input;

        if (input) {
          var field = event.field;
          that.$refs.dataGrid.scrollToColumn(field);
          input.focus && input.focus();
          input.select && input.select();
        } else if (type) {
          _this5.pressEnterItem(event);
        }
      });
    },
    editSlotRender: function editSlotRender() {
      var _this6 = this;

      var h = this.$createElement;
      return function (event) {
        var that = _this6;
        var currentCell = that.currentCell,
            editLine = that.editLine,
            lineEditTypes = that.lineEditTypes;
        var rowIndex = event.rowIndex,
            row = event.row,
            column = event.column;
        var field = column.field;
        var item = that.columnsIndexs[field];
        if (!item) return;
        var itemRender = item.itemRender;

        if (itemRender) {
          event.field = field;
          var name = itemRender.name;
          var props = itemRender.props;
          var disabled = editSlotPropInit(row, props, "disabled", event);
          var element;

          if ((0, _typeof2.default)(disabled) == "object") {
            return [disabled];
          } else if (editLine && (!currentCell || currentCell.rowIndex != rowIndex) && lineEditTypes.includes(name)) {
            var value = dataFormat(_utils.default.getObjData(item.field, row) || "", props, name, event);
            return [h("div", {
              "class": "edit-input ".concat(name)
            }, [value])];
          } else {
            props = (0, _objectSpread2.default)((0, _objectSpread2.default)({
              size: that.editItemSize
            }, props), {}, {
              value: _utils.default.getObjData(field, row),
              disabled: disabled
            });
            var attr = {
              class: editSlotItemRender(itemRender.class, event),
              style: editSlotItemRender(itemRender.style, event),
              ref: "input-" + rowIndex + "-" + field
            };
            var optionsField, options, trueValue, falseValue;
            var ons = {
              change: function change(e) {
                _utils.default.setObjData(field, row, e);

                row.ISEDIT = true;

                if (itemRender.on.change) {
                  itemRender.on.change(e, event);
                }
              }
            };

            for (var i in itemRender.on) {
              if (i != "change") {
                (function () {
                  var fuc = itemRender.on[i];

                  ons[i] = function () {
                    for (var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++) {
                      arg[_key] = arguments[_key];
                    }

                    fuc.apply(void 0, arg.concat([event]));
                  };
                })();
              }
            }

            var elementAttribute = {};

            switch (name) {
              case "a-input":
                elementAttribute = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attr), {}, {
                  props: props,
                  on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
                    change: function change(e) {
                      var value = e.target.value;

                      _utils.default.setObjData(field, row, value);

                      row.ISEDIT = true;

                      if (itemRender.on.change) {
                        itemRender.on.change(e, event);
                      }
                    },
                    keyup: function () {
                      var _keyup2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(e) {
                        var res;
                        return regeneratorRuntime.wrap(function _callee3$(_context3) {
                          while (1) {
                            switch (_context3.prev = _context3.next) {
                              case 0:
                                if (!itemRender.on.keyup) {
                                  _context3.next = 6;
                                  break;
                                }

                                _context3.next = 3;
                                return itemRender.on.keyup(e, event);

                              case 3:
                                res = _context3.sent;

                                if (!(res === false)) {
                                  _context3.next = 6;
                                  break;
                                }

                                return _context3.abrupt("return");

                              case 6:
                                if (e.keyCode == 13) {
                                  that.pressEnterItem(event);
                                }

                              case 7:
                              case "end":
                                return _context3.stop();
                            }
                          }
                        }, _callee3);
                      }));

                      function keyup(_x3) {
                        return _keyup2.apply(this, arguments);
                      }

                      return keyup;
                    }()
                  })
                });
                break;

              case "a-input-number":
                elementAttribute = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attr), {}, {
                  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
                    max: editSlotPropInit(row, props, "max", event, Infinity),
                    min: editSlotPropInit(row, props, "min", event, -Infinity)
                  }),
                  style: (0, _objectSpread2.default)({
                    width: "100%"
                  }, attr.style),
                  on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
                    keyup: function () {
                      var _keyup3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(e) {
                        var res;
                        return regeneratorRuntime.wrap(function _callee4$(_context4) {
                          while (1) {
                            switch (_context4.prev = _context4.next) {
                              case 0:
                                if (!itemRender.on.keyup) {
                                  _context4.next = 6;
                                  break;
                                }

                                _context4.next = 3;
                                return itemRender.on.keyup(e, event);

                              case 3:
                                res = _context4.sent;

                                if (!(res === false)) {
                                  _context4.next = 6;
                                  break;
                                }

                                return _context4.abrupt("return");

                              case 6:
                                if (e.keyCode == 13) {
                                  that.pressEnterItem(event);
                                }

                              case 7:
                              case "end":
                                return _context4.stop();
                            }
                          }
                        }, _callee4);
                      }));

                      function keyup(_x4) {
                        return _keyup3.apply(this, arguments);
                      }

                      return keyup;
                    }()
                  })
                });
                break;

              case "a-select":
                optionsField = props && props.optionsField || "";
                options = optionsField ? row[optionsField] : that.editOptions[field];

                if (props.optionsFilter) {
                  options = props.optionsFilter((0, _lodash.cloneDeep)(options), props.value, event);
                  delete props.optionsFilter;
                }

                elementAttribute = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attr), {}, {
                  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({
                    showSearch: true
                  }, props), {}, {
                    options: options
                  }),
                  style: (0, _objectSpread2.default)({
                    width: "100%"
                  }, attr.style),
                  on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
                    change: function change(value, option, pOption) {
                      _utils.default.setObjData(field, row, value);

                      row.ISEDIT = true;

                      if (itemRender.on.change) {
                        itemRender.on.change(value, option, event, pOption);
                      }
                    }
                  })
                });
                break;

              case "a-auto-complete":
                optionsField = props && props.optionsField || "";
                options = optionsField ? row[optionsField] : that.editOptions[field];

                if (props.optionsFilter) {
                  options = props.optionsFilter((0, _lodash.cloneDeep)(options), props.value, event);
                  delete props.optionsFilter;
                }

                if (props.search) {
                  props.search = function (value, dataSource) {
                    itemRender.props.search(value, dataSource, row, event);
                  };
                }

                elementAttribute = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attr), {}, {
                  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
                    options: options
                  }),
                  style: (0, _objectSpread2.default)({
                    width: "100%"
                  }, itemRender.style),
                  on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
                    select: function select(value, optionRow) {
                      _utils.default.setObjData(field, row, props.valueField ? optionRow[props.valueField] : value);

                      row.ISEDIT = true;

                      if (itemRender.on.select) {
                        itemRender.on.select(value, optionRow, event);
                      }
                    },
                    inputPressEnter: function () {
                      var _inputPressEnter = (0, _asyncToGenerator2.default)( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(e) {
                        var res;
                        return regeneratorRuntime.wrap(function _callee5$(_context5) {
                          while (1) {
                            switch (_context5.prev = _context5.next) {
                              case 0:
                                if (!itemRender.on.inputPressEnter) {
                                  _context5.next = 6;
                                  break;
                                }

                                _context5.next = 3;
                                return itemRender.on.inputPressEnter(e, event);

                              case 3:
                                res = _context5.sent;

                                if (!(res === false)) {
                                  _context5.next = 6;
                                  break;
                                }

                                return _context5.abrupt("return");

                              case 6:
                                if (e.keyCode == 13) {
                                  that.pressEnterItem(event);
                                }

                              case 7:
                              case "end":
                                return _context5.stop();
                            }
                          }
                        }, _callee5);
                      }));

                      function inputPressEnter(_x5) {
                        return _inputPressEnter.apply(this, arguments);
                      }

                      return inputPressEnter;
                    }()
                  })
                });
                break;

              case "a-date-picker":
                var dateValue = !props.value ? null : props.value.format ? props.value : (0, _moment.default)(props.value);
                elementAttribute = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attr), {}, {
                  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
                    value: dateValue
                  }),
                  on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
                    inputPressEnter: function () {
                      var _inputPressEnter2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(e) {
                        var res;
                        return regeneratorRuntime.wrap(function _callee6$(_context6) {
                          while (1) {
                            switch (_context6.prev = _context6.next) {
                              case 0:
                                if (!itemRender.on.inputPressEnter) {
                                  _context6.next = 6;
                                  break;
                                }

                                _context6.next = 3;
                                return itemRender.on.inputPressEnter(e, event);

                              case 3:
                                res = _context6.sent;

                                if (!(res === false)) {
                                  _context6.next = 6;
                                  break;
                                }

                                return _context6.abrupt("return");

                              case 6:
                                if (e.keyCode == 13) {
                                  that.pressEnterItem(event);
                                }

                              case 7:
                              case "end":
                                return _context6.stop();
                            }
                          }
                        }, _callee6);
                      }));

                      function inputPressEnter(_x6) {
                        return _inputPressEnter2.apply(this, arguments);
                      }

                      return inputPressEnter;
                    }()
                  })
                });
                break;

              case "a-time-picker":
                elementAttribute = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attr), {}, {
                  props: (0, _objectSpread2.default)({
                    clearIcon: true
                  }, props),
                  style: (0, _objectSpread2.default)({
                    width: "100%"
                  }, attr.style),
                  on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
                    inputPressEnter: function () {
                      var _inputPressEnter3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(e) {
                        var res;
                        return regeneratorRuntime.wrap(function _callee7$(_context7) {
                          while (1) {
                            switch (_context7.prev = _context7.next) {
                              case 0:
                                if (!itemRender.on.inputPressEnter) {
                                  _context7.next = 6;
                                  break;
                                }

                                _context7.next = 3;
                                return itemRender.on.inputPressEnter(e, event);

                              case 3:
                                res = _context7.sent;

                                if (!(res === false)) {
                                  _context7.next = 6;
                                  break;
                                }

                                return _context7.abrupt("return");

                              case 6:
                                if (e.keyCode == 13) {
                                  that.pressEnterItem(event);
                                }

                              case 7:
                              case "end":
                                return _context7.stop();
                            }
                          }
                        }, _callee7);
                      }));

                      function inputPressEnter(_x7) {
                        return _inputPressEnter3.apply(this, arguments);
                      }

                      return inputPressEnter;
                    }()
                  })
                });
                break;

              case "pulldown-table":
                elementAttribute = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attr), {}, {
                  props: props,
                  on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
                    change: function change(e, option) {
                      _utils.default.setObjData(field, row, e);

                      row.ISEDIT = true;

                      if (itemRender.on.change) {
                        itemRender.on.change(e, option, event);
                      }
                    },
                    inputPressEnter: function () {
                      var _inputPressEnter4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(e) {
                        var res;
                        return regeneratorRuntime.wrap(function _callee8$(_context8) {
                          while (1) {
                            switch (_context8.prev = _context8.next) {
                              case 0:
                                if (!itemRender.on.inputPressEnter) {
                                  _context8.next = 6;
                                  break;
                                }

                                _context8.next = 3;
                                return itemRender.on.inputPressEnter(e, event);

                              case 3:
                                res = _context8.sent;

                                if (!(res === false)) {
                                  _context8.next = 6;
                                  break;
                                }

                                return _context8.abrupt("return");

                              case 6:
                                if (e.keyCode == 13) {
                                  that.pressEnterItem(event);
                                }

                              case 7:
                              case "end":
                                return _context8.stop();
                            }
                          }
                        }, _callee8);
                      }));

                      function inputPressEnter(_x8) {
                        return _inputPressEnter4.apply(this, arguments);
                      }

                      return inputPressEnter;
                    }()
                  })
                });
                break;

              case "a-switch":
                trueValue = props.trueValue ? props.trueValue : true;
                falseValue = props.falseValue ? props.falseValue : false;
                if (editSlotPropInit(row, props, "hidden", event)) return "";
                elementAttribute = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attr), {}, {
                  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
                    checked: props.value == trueValue
                  }),
                  on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
                    change: function change(e) {
                      var value = e ? trueValue : falseValue;

                      _utils.default.setObjData(field, row, value);

                      row.ISEDIT = true;

                      if (itemRender.on.change) {
                        itemRender.on.change(e, event);
                      }
                    }
                  })
                });
                break;

              case "a-checkbox":
                trueValue = props.trueValue ? props.trueValue : true;
                falseValue = props.falseValue ? props.falseValue : false;
                if (editSlotPropInit(row, props, "hidden", event)) return "";
                elementAttribute = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attr), {}, {
                  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
                    checked: row[field] == trueValue
                  }),
                  on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
                    change: function change(e) {
                      var value = e.target.checked ? trueValue : falseValue;

                      _utils.default.setObjData(field, row, value);

                      row.ISEDIT = true;

                      if (itemRender.on.change) {
                        itemRender.on.change(e, event);
                      }
                    }
                  })
                });
                break;
            }

            element = that.$createElement(that.editTypeTargetName[name] || name, elementAttribute);
          }

          return [element];
        }
      };
    }
  }
};
var _default = editRender;
exports.default = _default;