"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 _PublicTemple = _interopRequireDefault(require("../../../../PublicTemple"));
var _config = _interopRequireDefault(require("../../ServiceComponents/PublicPage/config"));
var _config2 = _interopRequireDefault(require("../../../../../_mapUtil/config"));
var _TimeLimit = _interopRequireDefault(require("../../TimeLimit"));
var _modal = _interopRequireDefault(require("antd/lib/modal"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _index = _interopRequireDefault(require("../../ServiceComponents/PublicPage/index.less"));
var _WorkOrderModal = _interopRequireDefault(require("../../WorkOrderModal"));
var _service = _interopRequireDefault(require("../../service"));
var _PublicService = _interopRequireDefault(require("../../../../../_mapUtil/PublicService"));
var _request = _interopRequireDefault(require("../../../../../_mapUtil/request"));
var _OperationBtns = _interopRequireDefault(require("./OperationBtns"));
var _umi = require("umi");
var _dayjs = _interopRequireDefault(require("dayjs"));
var _config3 = _interopRequireDefault(require("../../config"));
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 _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 _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 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; } /**
 *  内部工单公共页面---表格
 */
var workOrderParams = _config["default"].workOrderParams,
  timeLimit = _config["default"].timeLimit; // 页面配置，流程

var getOperateBtn = _OperationBtns["default"].getOperateBtn,
  getProcessArgument = _OperationBtns["default"].getProcessArgument; // 按钮相关

var getSourceData = _service["default"].getSourceData,
  getOrderNatureData = _service["default"].getOrderNatureData,
  getOrderCategoryData = _service["default"].getOrderCategoryData,
  getOrderStatusData = _service["default"].getOrderStatusData;
var processParams = _config3["default"].processParams;
function PublicPage(props) {
  var pageType = props.pageType,
    userRole = props.userRole,
    _props$pageParams = props.pageParams,
    pageParams = _props$pageParams === void 0 ? {} : _props$pageParams,
    refreshNumber = props.refreshNumber,
    _props$tableTitle = props.tableTitle,
    tableTitle = _props$tableTitle === void 0 ? '工单中心' : _props$tableTitle,
    _props$extraParams = props.extraParams,
    extraParams = _props$extraParams === void 0 ? {} : _props$extraParams,
    orderType = props.orderType,
    updateStatistics = props.updateStatistics;
  var publicTempleRef = (0, _react.useRef)();
  // 弹框相关参数
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    modalShow = _useState2[0],
    setModalShow = _useState2[1]; // 弹框显隐
  var _useState3 = (0, _react.useState)(''),
    _useState4 = _slicedToArray(_useState3, 2),
    modalType = _useState4[0],
    setModalType = _useState4[1]; // 弹框类型
  var _useState5 = (0, _react.useState)({}),
    _useState6 = _slicedToArray(_useState5, 2),
    modalVal = _useState6[0],
    setModalVal = _useState6[1]; // 表格详情
  // 下拉选数据
  var _useState7 = (0, _react.useState)([]),
    _useState8 = _slicedToArray(_useState7, 2),
    sourceData = _useState8[0],
    setSourceData = _useState8[1]; // 工单来源
  var _useState9 = (0, _react.useState)([]),
    _useState10 = _slicedToArray(_useState9, 2),
    orderNatureData = _useState10[0],
    setOrderNatureData = _useState10[1]; // 工单性质
  var _useState11 = (0, _react.useState)([]),
    _useState12 = _slicedToArray(_useState11, 2),
    orderCategoryData = _useState12[0],
    setOrderCategoryData = _useState12[1]; // 工单类别
  var _useState13 = (0, _react.useState)([]),
    _useState14 = _slicedToArray(_useState13, 2),
    orderStatusData = _useState14[0],
    setOrderStatusData = _useState14[1]; // 办理状态
  var userId = _PublicService["default"].getQueryString('userId') || _PublicService["default"].getSystemInfo('userId') || ''; // 登录人id---用于判定用户角色

  // 与超时数量统计联动
  (0, _react.useEffect)(function () {
    var _publicTempleRef$curr;
    // 刷新页面
    (publicTempleRef === null || publicTempleRef === void 0 || (_publicTempleRef$curr = publicTempleRef.current) === null || _publicTempleRef$curr === void 0 ? void 0 : _publicTempleRef$curr.refresh) && publicTempleRef.current.refresh();
  }, [pageParams === null || pageParams === void 0 ? void 0 : pageParams.overtimeStatus]);
  (0, _react.useEffect)(function () {
    getSourceSelect();
    getOrderNatureSelect();
    getOrderCategorySelect();
    getOrderStatusSelect();
  }, []);

  // 工单来源
  var getSourceSelect = function getSourceSelect() {
    getSourceData(_objectSpread({}, extraParams)).then(function (res) {
      var list = [];
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        list = _PublicService["default"].transformOptions({
          data: (res === null || res === void 0 ? void 0 : res.data) || [],
          valueIndex: 'code',
          labelIndex: 'name',
          paramsAll: true
        });
      }
      setSourceData(list);
    });
  };

  // 办理状态
  var getOrderStatusSelect = function getOrderStatusSelect() {
    getOrderStatusData(_objectSpread({}, extraParams)).then(function (res) {
      var list = [];
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        list = _PublicService["default"].transformOptions({
          data: (res === null || res === void 0 ? void 0 : res.data) || [],
          valueIndex: 'key',
          labelIndex: 'value',
          paramsAll: true
        });
      }
      setOrderStatusData(list);
    });
  };

  // 工单性质
  var getOrderNatureSelect = function getOrderNatureSelect() {
    getOrderNatureData(_objectSpread({}, extraParams)).then(function (res) {
      var list = [];
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        list = _PublicService["default"].transformOptions({
          data: (res === null || res === void 0 ? void 0 : res.data) || [],
          valueIndex: 'id',
          labelIndex: 'level',
          paramsAll: true
        });
      }
      setOrderNatureData(list);
    });
  };

  //递归
  var renderTree = function renderTree(data) {
    data.label = data === null || data === void 0 ? void 0 : data.name;
    data.title = data === null || data === void 0 ? void 0 : data.name;
    data.value = data === null || data === void 0 ? void 0 : data.key;
    if (['root', 'type'].includes(data === null || data === void 0 ? void 0 : data.type)) {
      data.disabled = true;
    }
    if (data.children && data.children.length) {
      data.disabled = true;
      data.children.map(function (val) {
        renderTree(val);
      });
    }
    return data;
  };

  // 工单类别
  var getOrderCategorySelect = function getOrderCategorySelect() {
    getOrderCategoryData(_objectSpread({}, extraParams)).then(function (res) {
      var list = [];
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        list = [res === null || res === void 0 ? void 0 : res.data] || [];
        list && list.length && list.map(function (item) {
          renderTree(item);
        });
      }
      setOrderCategoryData(list);
    });
  };

  // 渲染时限
  var renderTimeLimit = function renderTimeLimit(text, record) {
    return /*#__PURE__*/_react["default"].createElement(_TimeLimit["default"], {
      details: record
    });
  };

  // 打开弹框参数
  var onModalShow = function onModalShow(record, type) {
    setModalVal(record);
    setModalType(type);
    setModalShow(true);
  };
  var handleOperationBtn = function handleOperationBtn(record) {
    var _userRole = [];
    if ((record === null || record === void 0 ? void 0 : record.reportMan) === userId) {
      _userRole = [].concat(_toConsumableArray(userRole), [{
        code: 'report',
        name: '上报者'
      }]);
    } else {
      _userRole = _toConsumableArray(userRole);
    }
    var btnList = getOperateBtn({
      pageType: pageType,
      userRole: _userRole,
      record: record,
      onConfirm: onConfirm,
      onModalShow: onModalShow
    });
    return btnList;
  };

  // 关闭弹框
  var goBack = function goBack() {
    var _publicTempleRef$curr2;
    setModalVal({});
    setModalType('');
    setModalShow(false);
    // 刷新页面
    (publicTempleRef === null || publicTempleRef === void 0 || (_publicTempleRef$curr2 = publicTempleRef.current) === null || _publicTempleRef$curr2 === void 0 ? void 0 : _publicTempleRef$curr2.refresh) && publicTempleRef.current.refresh();
    refreshNumber && refreshNumber(); // 更新数量统计
  };

  // 二次确认框(撤销、催办)
  var onConfirm = function onConfirm(record) {
    var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'PressToDo';
    var mag = arguments.length > 2 ? arguments[2] : undefined;
    _modal["default"].confirm({
      title: mag,
      okText: '确认',
      okType: 'danger',
      cancelText: '取消',
      onOk: function onOk() {
        var _processParams$type;
        var url = (processParams === null || processParams === void 0 || (_processParams$type = processParams[type]) === null || _processParams$type === void 0 ? void 0 : _processParams$type.orderUrl) || '';
        if (['PressToDo'].includes(type)) {
          var hide = _message["default"].loading("\u50AC\u529E\u4E2D\xB7\xB7\xB7", 0);
          // 催办
          _request["default"].post("".concat(url, "?id=").concat(record === null || record === void 0 ? void 0 : record.id), {
            body: {},
            headers: {
              ticket: true
            }
          }).then(function (res) {
            hide();
            if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
              _message["default"].success('操作成功');
              goBack();
            }
          });
        } else {
          // 撤销
          getProcessArgument({
            modalType: type,
            modalVal: record
          }, function (list) {
            var hide = _message["default"].loading("".concat(list === null || list === void 0 ? void 0 : list.name, "\u4E2D\xB7\xB7\xB7"), 0);
            var val = _objectSpread(_objectSpread({
              id: record === null || record === void 0 ? void 0 : record.id,
              status: record === null || record === void 0 ? void 0 : record.status,
              statusStr: record === null || record === void 0 ? void 0 : record.statusStr,
              finishLimitTime: (0, _dayjs["default"])().format('YYYY-MM-DD HH:mm:ss')
            }, extraParams), list);
            _request["default"].post(url, {
              body: val,
              headers: {
                ticket: true
              }
            }).then(function (res) {
              hide();
              if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
                _message["default"].success('操作成功');
                goBack();
              }
            });
          });
        }
      }
    });
  };

  // 工单导入成功后的其他操作
  var handleImport = function handleImport(data) {
    setModalVal((data === null || data === void 0 ? void 0 : data.data) || {});
    setModalType('Import');
    setModalShow(true);
  };

  // 表格自定义名称
  var renderTableTitle = function renderTableTitle() {
    var list = timeLimit() || [];
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: _index["default"].tableTitle
    }, /*#__PURE__*/_react["default"].createElement("div", null, tableTitle), /*#__PURE__*/_react["default"].createElement("div", null, list && list.length && list.map(function (item, index) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: _index["default"].timeList,
        key: index
      }, /*#__PURE__*/_react["default"].createElement("img", {
        src: require("../../../assets/".concat(item === null || item === void 0 ? void 0 : item.index, ".png"))
      }), /*#__PURE__*/_react["default"].createElement("div", {
        className: _index["default"].timeLimitText
      }, item === null || item === void 0 ? void 0 : item.title));
    })));
  };
  var filterItems = [{
    type: 'select',
    label: '工单来源小类',
    paramName: 'caseSource',
    itemProps: {
      allowClear: true,
      options: sourceData
    }
  }, {
    type: 'treeSelect',
    label: '工单类别',
    paramName: 'eventAndComponentManageId',
    itemProps: {
      allowClear: true,
      treeData: orderCategoryData,
      treeDefaultExpandAll: true
    }
  }, {
    type: 'select',
    label: '工单性质',
    paramName: 'urgencyLevelId',
    itemProps: {
      allowClear: true,
      options: orderNatureData
    }
  }].concat(_toConsumableArray(['ToDo'].includes(pageType) ? [] : [{
    type: 'select',
    label: '办理状态',
    paramName: 'status',
    itemProps: {
      allowClear: true,
      options: orderStatusData
    }
  }]), [{
    type: 'rangePicker',
    label: '办理截止时间',
    paramName: 'finishLimitTime',
    itemProps: {
      // showTime: { format: 'HH:mm:ss' },
      // format: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD'
    }
  }, {
    type: 'input',
    label: '工单名称',
    paramName: 'taskName'
  }, {
    type: 'input',
    label: '工单编号',
    paramName: 'taskNo'
  }, {
    type: 'input',
    label: '工单描述',
    paramName: 'caseDesc'
  }]);
  var params = _objectSpread(_objectSpread({}, workOrderParams({
    pageType: pageType,
    pageParams: pageParams,
    extraParams: extraParams
  }) || {}), {}, {
    filtrate: {
      items: filterItems
    },
    table: {
      tableTitle: renderTableTitle(),
      hideOperation: true,
      selectShow: true,
      validateImport: false,
      tablePropsConfig: {
        indexFixed: true
      },
      exportConfig: {
        showExport: true,
        // downloadURL: `${config.publicUrlSJGD}/api/workOrder/exportExcel`,
        showNewExport: true,
        newExportConfig: {
          title: '工单中心',
          requestExportUrl: "".concat(_config2["default"].publicUrlSJGD, "/api/workOrder/export"),
          checkResultUrl: "".concat(_config2["default"].publicUrlSJGD, "/export/info/findOne"),
          downFileUrl: "".concat(_config2["default"].publicUrlSJGD, "/export/info/downloadTempFile")
        },
        method: 'GET',
        field: 'ids',
        selectType: 'String' // 选中行传参方式
      },
      isAccess: true,
      columns: [{
        title: '工单来源小类',
        dataIndex: 'caseSourceStr',
        width: 120,
        fixed: 'left'
      }, {
        title: '工单编号',
        dataIndex: 'taskNo',
        width: 180,
        render: function render(text, record) {
          return /*#__PURE__*/_react["default"].createElement("a", {
            onClick: function onClick() {
              return onModalShow(record, 'Details');
            }
          }, text);
        },
        fixed: 'left'
      }, {
        title: '工单类别',
        dataIndex: 'eventAndComponentManageName',
        width: 180
      }, {
        title: '工单名称',
        dataIndex: 'taskName',
        width: 200
      }, {
        title: '工单性质',
        dataIndex: 'urgencyLevel',
        width: 100,
        render: function render(text) {
          var _紧急$一般$无需紧张$3$4$text, _紧急$一般$无需紧张$3$;
          return /*#__PURE__*/_react["default"].createElement("span", {
            style: {
              color: (_紧急$一般$无需紧张$3$4$text = (_紧急$一般$无需紧张$3$ = {
                紧急: '#FF4D4F',
                // 紧急
                一般: '#1899FF',
                // 一般
                无需紧张: '#FFB84D',
                // 无需紧张
                3: '#18d2ff',
                // 紧急
                4: '#8E989F' // 紧急
              }) === null || _紧急$一般$无需紧张$3$ === void 0 ? void 0 : _紧急$一般$无需紧张$3$[text]) !== null && _紧急$一般$无需紧张$3$4$text !== void 0 ? _紧急$一般$无需紧张$3$4$text : '#0a0a0a'
            }
          }, text);
        }
      }].concat(_toConsumableArray(['HaveToDo'].includes(pageType) ? [{
        title: '流转时间',
        dataIndex: 'caseTime',
        width: 160,
        sorter: true
      }] : [{
        title: '流转时间',
        dataIndex: 'caseTime',
        width: 160,
        sortType: 'time'
      }]), [{
        title: '办理截止时间',
        dataIndex: 'finishLimitTime',
        width: 160,
        sortType: 'time'
      }, {
        title: '办理状态',
        dataIndex: 'statusStr',
        width: 120
      }, {
        title: '时限',
        dataIndex: 'remainingTimeStatus',
        width: 100,
        render: function render(text, record) {
          return renderTimeLimit(text, record);
        }
      }, {
        title: '操作',
        dataIndex: 'id',
        width: ['HaveToDo'].includes(pageType) ? 100 : 150,
        renderButtons: function renderButtons(text, record) {
          return handleOperationBtn(record);
        },
        fixed: 'right'
      }])
    },
    searchAfter: function searchAfter(tableData) {
      updateStatistics && updateStatistics();
      return tableData;
    }
  });
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, modalShow ? /*#__PURE__*/_react["default"].createElement(_WorkOrderModal["default"], {
    modalType: modalType,
    modalVal: modalVal,
    goBack: goBack,
    pageType: pageType,
    orderType: orderType,
    extraParams: extraParams
  }) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_PublicTemple["default"], _extends({}, params, {
    ref: publicTempleRef
  }))));
}
function mapStateToProps(_ref) {
  var userrole = _ref.userrole;
  return {
    userRole: userrole.userRole
  };
}
var _default = exports["default"] = (0, _umi.connect)(mapStateToProps)(PublicPage);
//# sourceMappingURL=index.js.map
