"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 _FormModal = _interopRequireDefault(require("../../../../FormModal"));
var _MyEditable = _interopRequireDefault(require("../../../../MyEditable"));
var _config = _interopRequireDefault(require("../../../../../_mapUtil/config"));
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
var _FileView = _interopRequireDefault(require("./FileView"));
var _config2 = _interopRequireDefault(require("../../config"));
var _propTypes = _interopRequireDefault(require("prop-types"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 && Object.prototype.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() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
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(arr) { if (Array.isArray(arr)) return arr; } /**
 * @returns 周期任务详情弹窗
 */
// 任务周期
var rateObj = {
  1: '小时',
  2: '日',
  3: '周',
  4: '季',
  5: '月',
  6: '年'
};
// 作业模式名称
var jobModelObj = {
  1: '连续作业模式',
  2: '单点打卡模式',
  3: '起始点打卡模式'
};
var getStaffUserTree = _config2["default"].getStaffUserTree;
function DetailModal(props) {
  var titleConfig = props.titleConfig,
    _props$formData = props.formData,
    formData = _props$formData === void 0 ? {} : _props$formData,
    onPreview = props.onPreview,
    missionType = props.missionType,
    handleFormData = props.handleFormData;
  var editable = (0, _react.useRef)();
  var _useState = (0, _react.useState)([]),
    _useState2 = _slicedToArray(_useState, 2),
    dataList = _useState2[0],
    setDataList = _useState2[1];
  var _useState3 = (0, _react.useState)(false),
    _useState4 = _slicedToArray(_useState3, 2),
    modalShow = _useState4[0],
    setModalShow = _useState4[1];
  var _useState5 = (0, _react.useState)(''),
    _useState6 = _slicedToArray(_useState5, 2),
    fileId = _useState6[0],
    setFileId = _useState6[1];
  var _useState7 = (0, _react.useState)(''),
    _useState8 = _slicedToArray(_useState7, 2),
    fileUrl = _useState8[0],
    setFileUrl = _useState8[1];
  var _useState9 = (0, _react.useState)([]),
    _useState10 = _slicedToArray(_useState9, 2),
    unitList = _useState10[0],
    setUnitList = _useState10[1]; // 所属单位下拉选数据

  (0, _react.useEffect)(function () {
    initFormData();
  }, [formData.id]);
  (0, _react.useEffect)(function () {
    getStaffUserTree(function (data) {
      setUnitList(data);
    });
  }, []);
  var initDataList = function initDataList() {
    var _formData$objectInfos = formData.objectInfos,
      objectInfos = _formData$objectInfos === void 0 ? [] : _formData$objectInfos;
    if (objectInfos !== null && objectInfos !== void 0 && objectInfos.length) {
      objectInfos.map(function (item) {
        var _item$jobObject = item.jobObject,
          jobObject = _item$jobObject === void 0 ? [] : _item$jobObject;
        var jobObjectName = '';
        if (jobObject !== null && jobObject !== void 0 && jobObject.length) {
          jobObject.map(function (childItem, index) {
            var name = childItem.name,
              code = childItem.code,
              roadName = childItem.roadName;
            var itemName = "".concat(name, "(").concat(code).concat(roadName ? "-".concat(roadName) : '', ")");
            if (index !== jobObject.length - 1) {
              jobObjectName += "".concat(itemName, "\uFF0C");
            } else {
              jobObjectName += itemName;
            }
          });
        }
        item.jobObjectName = jobObjectName;
      });
      setDataList(_toConsumableArray(objectInfos));
    }
  };
  var initFormData = function initFormData() {
    var newFormData = (0, _cloneDeep["default"])(formData);
    var userName = newFormData.userName,
      _newFormData$count = newFormData.count,
      count = _newFormData$count === void 0 ? '' : _newFormData$count,
      rate = newFormData.rate,
      startTime = newFormData.startTime,
      endTime = newFormData.endTime,
      jobModel = newFormData.jobModel,
      state = newFormData.state,
      method = newFormData.method,
      files = newFormData.files,
      staffList = newFormData.staffList;
    var staffName = [];
    if (staffList && staffList.length) {
      staffList.map(function (item) {
        staffName.push(item.staffName);
      });
      newFormData.userName = staffName === null || staffName === void 0 ? void 0 : staffName.join(',');
    } else {
      newFormData.userName = '排班人员';
    }

    // if (!userName) {

    // }
    // 任务有效时间
    if (startTime && endTime) {
      newFormData.effectiveTime = startTime && endTime && "".concat(startTime.split(' ')[0], " ~ ").concat(endTime.split(' ')[0]);
      // (startTime && startTime.split(' ')[0]) + '~' + (endTime && endTime.split(' ')[0]);
    } else {
      newFormData.effectiveTime = '永久';
    }
    newFormData.dutyCycle = "".concat(count).concat(rateObj[rate] || '', "1\u6B21"); // 任务周期
    newFormData.jobModelName = jobModelObj[jobModel] || ''; // 作业模式
    newFormData.taskStatus = {
      0: '禁用',
      1: '启用'
    }[state] || ''; // 任务启停
    newFormData.methodName = {
      1: '定位',
      2: '扫码',
      3: '无'
    }[method] || ''; // 打卡方式
    newFormData.fileList = (files || []).map(function (v) {
      return v.id;
    }); // 打卡方式
    handleFormData && handleFormData(newFormData);
    initDataList();
  };
  var modalItems = [{
    type: 'card',
    label: '基本信息',
    items: [{
      type: 'input',
      label: '任务编号',
      paramName: 'code'
    }, {
      type: 'input',
      label: '任务名称',
      paramName: 'name'
    }, {
      type: 'input',
      label: '业务类型',
      paramName: 'businessTypeName'
    }, {
      type: 'input',
      label: '巡检人员',
      paramName: 'userName'
    }, {
      type: 'input',
      label: '联系方式',
      paramName: 'phone'
    }, {
      type: 'select',
      label: '组织机构',
      paramName: 'orgId',
      itemProps: {
        options: unitList
      }
    }, {
      type: 'input',
      label: '巡查偏离范围(m)',
      paramName: 'deviationDistance'
    }].concat(_toConsumableArray((formData === null || formData === void 0 ? void 0 : formData.patrolCode) === 'DLXC' ? [{
      type: 'input',
      label: '限定速度(m/s)',
      paramName: 'speedLimit'
    }] : []), _toConsumableArray(missionType === 'cycle' ? [{
      type: 'input',
      label: '任务周期',
      paramName: 'dutyCycle'
    }] : []), [{
      type: 'input',
      label: '作业模式',
      paramName: 'jobModelName'
    }, {
      type: 'input',
      label: '任务有效时间',
      paramName: 'effectiveTime'
    }], _toConsumableArray(missionType === 'temporary' ? [{
      type: 'input',
      label: '打卡方式',
      paramName: 'methodName'
    }] : []), _toConsumableArray(missionType === 'cycle' ? [{
      type: 'input',
      label: '任务触发时间',
      paramName: 'triggerTime'
    }] : []), [{
      type: 'input',
      label: '任务启停',
      paramName: 'taskStatus'
    }, {
      type: 'input',
      label: '创建时间',
      paramName: 'createTime'
    }, {
      type: 'input',
      label: '创建人',
      paramName: 'createByName'
    }, {
      type: 'textArea',
      label: '备注',
      paramName: 'remark',
      weights: 3,
      itemProps: {
        maxLength: 100
      }
    }, {
      type: 'vtxUpload',
      label: '图片',
      paramName: 'imgDTOList',
      formItemLayout: {
        initialValue: (formData === null || formData === void 0 ? void 0 : formData.pics) || [],
        tooltip: '(限制大小不超过10mb)'
      },
      weights: 3,
      itemProps: {
        maxLength: 4,
        maxSize: 10 * 1024 * 1024,
        accept: '.jpg, .jpeg, .png'
      }
    }, {
      type: 'vtxUpload',
      label: '附件',
      paramName: 'fileList',
      itemProps: {
        maxSize: 1024 * 1024 * 1024,
        maxLength: 5,
        listType: 'text',
        // previewFile: file => {},
        onPreview: function onPreview(file) {
          setModalShow(true);
          setFileId(file.id);
          setFileUrl("".concat(_config["default"].filePdfViewUrl, "?id=").concat(file.id, "&openmode=inline"));

          // if (record.fileFormat === 'mp4') {
          //   setFileUrl(`${config.videoViewUrl}/${record.cloudFileId}`);
          // } else if (['jpg', 'jpeg', 'png', 'gif'].includes(record.fileFormat)) {
          //   setFileUrl(
          //     `${config.imgUrl}/cloudFile/common/downloadFile?id=${record.cloudFileId}&openmode=inline`,
          //   );
          // } else {
          //   setFileUrl(
          //     `${config.imgUrl}/cloudFile/common/downloadPdfFile?id=${record.cloudFileId}&openmode=inline`,
          //   );
          // }
        }
      },
      formItemLayout: {
        initialValue: formData.files
      },
      weights: 3
    }])
  }, {
    type: 'card',
    label: '巡检对象',
    items: [{
      type: 'blank',
      content: renderEditable()
    }]
  }];
  function renderEditable() {
    var preview = function preview(id) {
      onPreview && onPreview(id);
    };
    var columns = [{
      title: '对象小类',
      dataIndex: 'jobObjectTypeName',
      width: 120,
      onCell: function onCell(_, index) {
        return {
          rowSpan: _.rows
        };
      }
    }, {
      title: '巡检对象',
      dataIndex: 'jobObjectName',
      width: 120,
      onCell: function onCell(_, index) {
        return {
          rowSpan: _.rows
        };
      }
    }, {
      title: '关联表单',
      dataIndex: 'formName',
      width: 120,
      onCell: function onCell(_, index) {
        return {
          rowSpan: _.rows
        };
      },
      render: function render(text, record) {
        if (text !== '无') {
          var _record$customForms = record.customForms,
            customForms = _record$customForms === void 0 ? [] : _record$customForms;
          return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, customForms && customForms.map(function (item, index) {
            return /*#__PURE__*/_react["default"].createElement("div", {
              key: index
            }, /*#__PURE__*/_react["default"].createElement("a", {
              onClick: function onClick() {
                return preview(item.formId);
              }
            }, item.formName));
          }));
        } else {
          return text;
        }
      }
    }];
    return /*#__PURE__*/_react["default"].createElement(_MyEditable["default"], {
      title: '',
      ref: editable,
      showSerialNum: true,
      columns: columns,
      hideOperation: true,
      multiple: true,
      tableData: dataList
    });
  }
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_FormModal["default"], _extends({
    width: 1200,
    disabled: true,
    formData: formData,
    items: modalItems,
    title: "".concat(titleConfig, ">\u8BE6\u60C5"),
    column: 3,
    footerShow: true,
    size: "middle",
    saveBtn: false,
    cancelTitle: "\u5173\u95ED",
    returnBtn: false
  }, props)), modalShow && /*#__PURE__*/_react["default"].createElement(_FileView["default"], {
    visible: modalShow,
    fileId: fileId,
    fileUrl: fileUrl,
    onModalClose: function onModalClose() {
      setFileUrl('');
      setFileId('');
      setModalShow(false);
    }
  }));
}
DetailModal.propTypes = {
  titleConfig: _propTypes["default"].any,
  formData: _propTypes["default"].any,
  onPreview: _propTypes["default"].any,
  missionType: _propTypes["default"].any,
  handleFormData: _propTypes["default"].any
};
var _default = exports["default"] = DetailModal;
//# sourceMappingURL=index.js.map
