"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _form = _interopRequireDefault(require("antd/lib/form"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _divider = _interopRequireDefault(require("antd/lib/divider"));
var _popconfirm = _interopRequireDefault(require("antd/lib/popconfirm"));
var _QuestionCircleOutlined = _interopRequireDefault(require("@ant-design/icons/QuestionCircleOutlined"));
var _vtxPageLayout = _interopRequireDefault(require("@vtx/components/lib/vtx-page-layout"));
var _ahooks = require("ahooks");
var _Filtrate = _interopRequireDefault(require("../Filtrate"));
var _MyTable = _interopRequireDefault(require("../MyTable"));
var _FormModal = _interopRequireDefault(require("../FormModal"));
var _useDeleteRows = _interopRequireDefault(require("../../hooks/useDeleteRows"));
var _http = _interopRequireDefault(require("../../_util/http"));
var _dayjs = _interopRequireDefault(require("dayjs"));
var _Statistics = _interopRequireDefault(require("../Statistics"));
var _excluded = ["columns", "hideOperation", "operation", "showFixed", "isView", "isDetail", "deleteMessage", "operationWidth", "tableTitle", "exportConfig", "importConfig", "handleTableData", "tablePropsConfig"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /**
 * permissions:
 *  add: 新增
 *  view: 查看
 *  edit: 编辑
 *  delete: 删除
 */
var TableLayout = _vtxPageLayout["default"].TableLayout;
var ScrollableRow = _Statistics["default"].ScrollableRow,
  StatisticsColumn = _Statistics["default"].StatisticsColumn;
var PublicTemple = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var onLyShowModal = props.onLyShowModal;
  var myForm = (0, _react.useRef)();
  var _Form$useForm = _form["default"].useForm(),
    _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
    form = _Form$useForm2[0];
  var _useState = (0, _react.useState)(_objectSpread({
      modalShow: false,
      modalTitle: ''
    }, onLyShowModal)),
    _useState2 = _slicedToArray(_useState, 2),
    modalConfig = _useState2[0],
    setModalConfig = _useState2[1];
  var _useState3 = (0, _react.useState)(_objectSpread({}, onLyShowModal)),
    _useState4 = _slicedToArray(_useState3, 2),
    formData = _useState4[0],
    setFormData = _useState4[1];
  var _useState5 = (0, _react.useState)({
      modalLoading: false,
      modalBtnLoading: false
    }),
    _useState6 = _slicedToArray(_useState5, 2),
    loadingConfig = _useState6[0],
    setLoadingConfig = _useState6[1];
  var _useState7 = (0, _react.useState)(false),
    _useState8 = _slicedToArray(_useState7, 2),
    status = _useState8[0],
    setStatus = _useState8[1];
  var _props$filtrate = props.filtrate,
    filtrate = _props$filtrate === void 0 ? {} : _props$filtrate,
    _props$statisticsShow = props.statisticsShow,
    statisticsShow = _props$statisticsShow === void 0 ? false : _props$statisticsShow,
    _props$statisticsColu = props.statisticsColumn,
    statisticsColumn = _props$statisticsColu === void 0 ? {} : _props$statisticsColu,
    _props$table = props.table,
    table = _props$table === void 0 ? {} : _props$table,
    _props$searchApi = props.searchApi,
    searchApi = _props$searchApi === void 0 ? '' : _props$searchApi,
    _props$requestMethod = props.requestMethod,
    requestMethod = _props$requestMethod === void 0 ? 'post' : _props$requestMethod,
    _props$addApi = props.addApi,
    addApi = _props$addApi === void 0 ? '' : _props$addApi,
    _props$extrAddParams = props.extrAddParams,
    extrAddParams = _props$extrAddParams === void 0 ? {} : _props$extrAddParams,
    _props$editApi = props.editApi,
    editApi = _props$editApi === void 0 ? '' : _props$editApi,
    _props$deleteApi = props.deleteApi,
    deleteApi = _props$deleteApi === void 0 ? '' : _props$deleteApi,
    _props$batchDeleteApi = props.batchDeleteApi,
    batchDeleteApi = _props$batchDeleteApi === void 0 ? '' : _props$batchDeleteApi,
    _props$detailApi = props.detailApi,
    detailApi = _props$detailApi === void 0 ? '' : _props$detailApi,
    _props$searchBefore = props.searchBefore,
    searchBefore = _props$searchBefore === void 0 ? null : _props$searchBefore,
    _props$searchAfter = props.searchAfter,
    searchAfter = _props$searchAfter === void 0 ? null : _props$searchAfter,
    _props$beforeExport = props.beforeExport,
    beforeExport = _props$beforeExport === void 0 ? null : _props$beforeExport,
    _props$deleteBefore = props.deleteBefore,
    deleteBefore = _props$deleteBefore === void 0 ? null : _props$deleteBefore,
    _props$modalShowBefor = props.modalShowBefore,
    modalShowBefore = _props$modalShowBefor === void 0 ? null : _props$modalShowBefor,
    _props$modalCloseBefo = props.modalCloseBefore,
    modalCloseBefore = _props$modalCloseBefo === void 0 ? null : _props$modalCloseBefo,
    _props$callBackModalV = props.callBackModalVal,
    callBackModalVal = _props$callBackModalV === void 0 ? null : _props$callBackModalV,
    _props$detailParamsBe = props.detailParamsBefore,
    detailParamsBefore = _props$detailParamsBe === void 0 ? null : _props$detailParamsBe,
    _props$saveBefore = props.saveBefore,
    saveBefore = _props$saveBefore === void 0 ? null : _props$saveBefore,
    _props$rowId = props.rowId,
    rowId = _props$rowId === void 0 ? 'id' : _props$rowId,
    _props$mulitDelParams = props.mulitDelParams,
    mulitDelParams = _props$mulitDelParams === void 0 ? '' : _props$mulitDelParams,
    _props$modal = props.modal,
    modal = _props$modal === void 0 ? {} : _props$modal,
    _props$exportParamBef = props.exportParamBefore,
    exportParamBefore = _props$exportParamBef === void 0 ? null : _props$exportParamBef,
    _props$uploadParamBef = props.uploadParamBefore,
    uploadParamBefore = _props$uploadParamBef === void 0 ? null : _props$uploadParamBef,
    _props$templateParamB = props.templateParamBefore,
    templateParamBefore = _props$templateParamB === void 0 ? null : _props$templateParamB,
    _props$searchPage = props.searchPage,
    searchPage = _props$searchPage === void 0 ? false : _props$searchPage;
  var _useState9 = (0, _react.useState)((statisticsColumn === null || statisticsColumn === void 0 ? void 0 : statisticsColumn.statisticData) || []),
    _useState10 = _slicedToArray(_useState9, 2),
    data = _useState10[0],
    setData = _useState10[1];
  var _table$columns = table.columns,
    columns = _table$columns === void 0 ? [] : _table$columns,
    hideOperation = table.hideOperation,
    operation = table.operation,
    _table$showFixed = table.showFixed,
    showFixed = _table$showFixed === void 0 ? false : _table$showFixed,
    _table$isView = table.isView,
    isView = _table$isView === void 0 ? false : _table$isView,
    _table$isDetail = table.isDetail,
    isDetail = _table$isDetail === void 0 ? false : _table$isDetail,
    deleteMessage = table.deleteMessage,
    _table$operationWidth = table.operationWidth,
    operationWidth = _table$operationWidth === void 0 ? 180 : _table$operationWidth,
    _table$tableTitle = table.tableTitle,
    tableTitle = _table$tableTitle === void 0 ? '' : _table$tableTitle,
    _table$exportConfig = table.exportConfig,
    exportConfig = _table$exportConfig === void 0 ? {} : _table$exportConfig,
    _table$importConfig = table.importConfig,
    importConfig = _table$importConfig === void 0 ? {} : _table$importConfig,
    handleTableData = table.handleTableData,
    _table$tablePropsConf = table.tablePropsConfig,
    tablePropsConfig = _table$tablePropsConf === void 0 ? {} : _table$tablePropsConf,
    tableOther = _objectWithoutProperties(table, _excluded);
  if (!addApi) {
    tableOther.hideAddBtn = true;
  }
  if (!batchDeleteApi) {
    tableOther.hideDeleteBtn = true;
  }
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      myForm: myForm,
      form: form,
      getDetails: getDetails,
      submit: submit,
      refresh: refresh,
      onModalShow: onModalShow,
      getTableData: getTableData
    };
  });
  (0, _react.useEffect)(function () {
    if (onLyShowModal) {
      var title = onLyShowModal.modalTitle || '查看';
      onModalShow(title, onLyShowModal);
    }
  }, []);
  function onModalShow(type, record) {
    modalConfig.modalTitle = type;
    modalConfig.modalShow = true;
    modalShowBefore && modalShowBefore(type, record);
    setModalConfig(_objectSpread({}, modalConfig));
    if (record && record.id) {
      getDetails(type, record);
    }
  }

  // 获取详情
  function getDetails(type, record) {
    loadingConfig.modalLoading = true;
    loadingConfig.modalBtnLoading = true;
    setLoadingConfig(_objectSpread({}, loadingConfig));
    // 详情接口不存在时使用列表行数据作为详情数据
    if (!detailApi) {
      setFormData(record);
      loadingConfig.modalLoading = false;
      loadingConfig.modalBtnLoading = false;
      setLoadingConfig(_objectSpread({}, loadingConfig));
      return;
    }
    var params = {
      id: record.id
    };
    var newParams = detailParamsBefore && detailParamsBefore(record) || params;
    _http["default"].get(detailApi, {
      body: newParams
    }).then(function (res) {
      var obj = {};
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        obj = _objectSpread(_objectSpread({}, record), res.data);
      }
      // 日期转换
      if (obj.buildTime && type !== '查看') {
        obj.buildTime = (0, _dayjs["default"])(obj.buildTime);
      }
      if (obj.layTimeStr && type !== '查看') {
        obj.layTimeStr = (0, _dayjs["default"])(obj.layTimeStr);
      }
      if (obj.monitorTimeStr && type !== '查看') {
        obj.monitorTimeStr = (0, _dayjs["default"])(obj.monitorTimeStr);
      }
      if (obj.monitorTime && type !== '查看') {
        obj.monitorTime = (0, _dayjs["default"])(obj.monitorTime);
      }
      if (obj.layTime && type !== '查看') {
        obj.layTime = (0, _dayjs["default"])(obj.layTime);
      }
      obj = callBackModalVal && callBackModalVal(obj, type);
      setFormData(obj);
      loadingConfig.modalLoading = false;
      loadingConfig.modalBtnLoading = false;
      setLoadingConfig(_objectSpread({}, loadingConfig));
    });
  }

  // 列表分页查询
  function getTableData(_ref, formData) {
    var current = _ref.current,
      pageSize = _ref.pageSize;
    var params = _objectSpread({
      current: current,
      size: pageSize
    }, formData);
    if (searchPage) {
      params = _objectSpread({
        page: current - 1,
        pageSize: pageSize
      }, formData);
    }
    if (searchBefore) {
      params = searchBefore(params);
    }
    var request = _http["default"].post;
    if (requestMethod === 'get') {
      request = _http["default"].get;
    }
    return request(searchApi, {
      body: params
    }).then(function (res) {
      var tableData = [],
        pageTotal = 0;
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        if (searchAfter) {
          res.data = searchAfter(res.data);
        }
        var _res$data = res.data,
          _res$data$records = _res$data.records,
          records = _res$data$records === void 0 ? [] : _res$data$records,
          _total = _res$data.total,
          _res$data$rows = _res$data.rows,
          rows = _res$data$rows === void 0 ? [] : _res$data$rows,
          _res$data$date = _res$data.date,
          date = _res$data$date === void 0 ? [] : _res$data$date;
        tableData = records.length ? records : rows.length ? rows : date.length ? date : [];
        pageTotal = Number(_total);
      }
      if (handleTableData) {
        tableData = handleTableData(tableData);
      }
      return {
        list: tableData,
        total: pageTotal
      };
    });
  }
  var _useAntdTable = (0, _ahooks.useAntdTable)(getTableData, {
      defaultPageSize: 10,
      form: form
    }),
    refresh = _useAntdTable.refresh,
    run = _useAntdTable.run,
    params = _useAntdTable.params,
    tableProps = _useAntdTable.tableProps,
    search = _useAntdTable.search,
    loading = _useAntdTable.loading;
  var _tableProps$paginatio = tableProps === null || tableProps === void 0 ? void 0 : tableProps.pagination,
    current = _tableProps$paginatio.current,
    pageSize = _tableProps$paginatio.pageSize,
    total = _tableProps$paginatio.total;
  var submit = search.submit,
    reset = search.reset;
  // 删除
  var deleteRows = (0, _useDeleteRows["default"])(function (ids) {
    var params = ids;
    // 处理删除前的参数
    if (deleteBefore) {
      params = deleteBefore(params);
    }
    // 删除函数
    return _http["default"].post(deleteApi, {
      body: params,
      headers: {
        ticket: true
      }
    }).then(function (res) {
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0') {
        _message["default"].success(res.msg);
        props.pageCallAgain && props.pageCallAgain();
        return true;
      }
    });
  }, {
    current: current || 1,
    pageSize: pageSize || 10,
    total: total || 0,
    formData: params[1],
    fetch: run
  });
  function renderFiltrate() {
    var _filtrate$showFiltrat = filtrate.showFiltrate,
      showFiltrate = _filtrate$showFiltrat === void 0 ? true : _filtrate$showFiltrat;
    if (!showFiltrate) return;
    return /*#__PURE__*/_react["default"].createElement(_Filtrate["default"], _extends({
      form: form,
      Form: _form["default"],
      onSubmit: submit,
      onReset: reset
    }, filtrate));
  }
  function renderScrollableRow() {
    var statisticData = statisticsColumn.statisticData,
      statistics = statisticsColumn.statistics;
    var view = function view(item) {
      setData([item]);
      setStatus(true);
      submit();
    };
    var back = function back() {
      setData(statisticData);
      setStatus(false);
      submit();
    };
    return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, data.length > 1 ? /*#__PURE__*/_react["default"].createElement(ScrollableRow, {
      data: data,
      statistics: statistics,
      back: back,
      view: view
    }) : /*#__PURE__*/_react["default"].createElement(StatisticsColumn, {
      data: data,
      statistics: statistics,
      back: back,
      view: view,
      status: status
    }));
  }
  function renderTable() {
    var columnData = [].concat(_toConsumableArray(columns), _toConsumableArray(!hideOperation && [{
      title: '操作',
      dataIndex: 'dataIndexId',
      align: 'center',
      width: operationWidth,
      fixed: showFixed ? 'right' : '',
      render: function render(text, record, index) {
        return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, !isDetail && /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            return onModalShow('查看', record);
          }
        }, "\u67E5\u770B"), !isView && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, !isDetail && /*#__PURE__*/_react["default"].createElement(_divider["default"], {
          type: 'vertical'
        }), /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            return onModalShow('编辑', record);
          }
        }, "\u7F16\u8F91")), (deleteApi || batchDeleteApi) && !isView && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_divider["default"], {
          type: 'vertical'
        }), /*#__PURE__*/_react["default"].createElement(_popconfirm["default"], {
          title: deleteMessage || '是否删除这条数据?',
          onConfirm: function onConfirm() {
            return deleteRows.run([record.id]);
          },
          icon: /*#__PURE__*/_react["default"].createElement(_QuestionCircleOutlined["default"], {
            style: {
              color: 'red'
            }
          })
        }, /*#__PURE__*/_react["default"].createElement("a", {
          style: {
            color: 'red'
          }
        }, "\u5220\u9664"))), (operation === null || operation === void 0 ? void 0 : operation.length) > 0 && operation.map(function (v) {
          return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_divider["default"], {
            type: 'vertical'
          }), v.customOperator ? v.customOperator(record) : /*#__PURE__*/_react["default"].createElement("a", {
            onClick: function onClick() {
              return v.onClick && v.onClick(record);
            }
          }, v.label));
        }));
      }
    }] || []));
    var getExtraParams = function getExtraParams(exportType) {
      var result = {};
      if (exportType === 'all') {
        var ret = form.getFieldsValue();
        if (beforeExport) {
          ret = beforeExport(ret);
        }
        result = _objectSpread(_objectSpread({}, result), ret);
      }
      if (exportParamBefore) {
        result = exportParamBefore(result);
      }
      return result;
    };

    // 获取导出数据
    var getExtraNewParams = function getExtraNewParams() {
      var result = {};
      if (exportParamBefore) {
        result = exportParamBefore(result);
      }
      return result;
    };
    return /*#__PURE__*/_react["default"].createElement(_MyTable["default"], _extends({
      columns: columnData,
      loading: loading,
      tableProps: _objectSpread(_objectSpread({}, tableProps), tablePropsConfig),
      params: params,
      run: run,
      refresh: refresh,
      toolbarTilte: tableTitle,
      onModalShow: onModalShow,
      mulitDelParams: mulitDelParams,
      deleteUrl: deleteApi,
      exportConfig: _objectSpread(_objectSpread({}, exportConfig), {}, {
        getExtraParams: getExtraParams,
        getExtraNewParams: getExtraNewParams
      }),
      importConfig: _objectSpread({
        getUploadParams: function getUploadParams() {
          var params = {};
          if (uploadParamBefore) {
            params = uploadParamBefore(params);
          }
          return params;
        },
        getTemplateParam: function getTemplateParam() {
          var params = {};
          if (templateParamBefore) {
            params = templateParamBefore(params);
          }
          return params;
        }
      }, importConfig)
    }, tableOther));
  }
  function renderModal() {
    var _modal$modalName = modal.modalName,
      modalName = _modal$modalName === void 0 ? '基础信息' : _modal$modalName,
      modalDisabled = modal.modalDisabled;
    var modalShow = modalConfig.modalShow,
      modalTitle = modalConfig.modalTitle;
    var modalLoading = loadingConfig.modalLoading,
      modalBtnLoading = loadingConfig.modalBtnLoading;
    var disabled = modalTitle === '查看' || modalDisabled;
    function onSave(val) {
      var _reqData, _reqData2;
      if (!(addApi || editApi)) {
        return _message["default"].error('缺少保存接口!');
      }
      // 如果为编辑操作并且存在编辑接口
      if (modalTitle === '编辑' && editApi) {
        addApi = editApi;
      }
      if (formData[rowId]) {
        val[rowId] = formData[rowId];
      }
      var reqData = _objectSpread(_objectSpread({}, val), extrAddParams);
      (_reqData = reqData) === null || _reqData === void 0 || delete _reqData.key;
      (_reqData2 = reqData) === null || _reqData2 === void 0 || delete _reqData2.num;
      // 处理保存前的参数
      if (saveBefore) {
        reqData = saveBefore(reqData, modalTitle);
      }
      var data = JSON.stringify(reqData);
      var url = addApi;
      if (url) {
        loadingConfig.modalBtnLoading = true;
        setLoadingConfig(_objectSpread({}, loadingConfig));
        _http["default"].post(url, {
          body: data,
          headers: {
            ticket: true
          }
        }).then(function (res) {
          if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
            _message["default"].success('操作成功');
            onCancel();
            refresh();
            props.pageCallAgain && props.pageCallAgain();
          }
          loadingConfig.modalBtnLoading = false;
          setLoadingConfig(_objectSpread({}, loadingConfig));
        });
      }
    }
    var onCancel = function onCancel() {
      // 处理模态框关闭前的参数
      modalCloseBefore && modalCloseBefore();
      setFormData({});
      modalConfig.modalShow = false;
      setModalConfig(_objectSpread({}, modalConfig));
    };
    if (modalShow) {
      return /*#__PURE__*/_react["default"].createElement(_FormModal["default"], _extends({
        width: 600,
        ref: myForm,
        visible: modalShow,
        formData: formData,
        title: "".concat(modalName, " > ").concat(modalTitle),
        onConfirm: onSave,
        onCancel: onCancel,
        disabled: disabled,
        footerShow: !disabled,
        modalLoading: modalLoading,
        modalBtnLoading: modalBtnLoading,
        formStyle: {
          width: '100%'
        },
        cancelTitle: modalTitle === '查看' ? '关闭' : '取消'
        // validateAdd={validate('add')} // 新增
        // validateDelete={validate('delete')} // 删除
        // validateImport={validate('import')} // 导入
        // validateExport={validate('export')} // 导出
      }, modal));
    }
  }
  if (onLyShowModal) {
    return renderModal();
  }
  return /*#__PURE__*/_react["default"].createElement(TableLayout.Page, {
    ref: ref
  }, renderFiltrate(), statisticsShow && renderScrollableRow(), renderTable(), renderModal());
});
var _default = exports["default"] = PublicTemple;
//# sourceMappingURL=index.js.map
