import 'antd/es/message/style';
import _message from 'antd/es/message';
import 'antd/es/popconfirm/style';
import _Popconfirm from 'antd/es/popconfirm';
import 'antd/es/button/style';
import _Button from 'antd/es/button';
import 'antd/es/form/style';
import _Form from 'antd/es/form';
import 'lodash/set';
import 'lodash/map';
import _get from 'lodash/get';
import { a as __spreadArray, b as __awaiter, c as __generator, d as __assign } from './index.js';
import { PrinterOutlined, SaveOutlined } from '@ant-design/icons';
import { BaseEditPanelFormFC } from '@lm_fe/components_m';
import store from 'store';
import { SMchc_Doctor, SLocal_State, SLocal_History } from '@lm_fe/service';
import { getSearchParamsValue } from '@lm_fe/utils';
import React__default, { useState, useEffect } from 'react';
import { getOptionValue, mchcEnv } from '@lm_fe/env';
import { mchcModal__ } from '@lm_fe/pages';
import 'antd/es/tabs/style';
import 'antd/es/tabs';
import 'lodash/size';
import 'lodash/orderBy';
import '@lm_fe/components';
import 'antd/es/collapse/style';
import 'antd/es/collapse';
import 'antd/es/badge/style';
import 'antd/es/badge';
import 'lodash/assign';
var deliveryForm = ['deliveryDate', 'deliveryGestationalWeek', 'deliveryMode'];
var terminationForm = ['closingDate', 'closingGestationalWeek', 'closingNote'];
var referralForm = ['referralOutReason', 'referralOutReferralDate', 'referralOutReferralOrganization', 'referralOutReferralDept', 'referralOutReferralDirection', 'referralOutReferralDoctor', 'referralOutReferralContactNumber', 'referralOutRecorder'];
__spreadArray(__spreadArray(__spreadArray([], deliveryForm, true), terminationForm, true), referralForm, true);
var form_config = function form_config() {
  var value_已分娩 = getOptionValue('孕期状态', '已分娩') + '';
  var value_终止妊娠 = getOptionValue('孕期状态', '终止妊娠') + '';
  var value_转院 = getOptionValue('孕期状态', '转院') + '';
  return [{
    "key": "recordstate",
    "label": "档案状态",
    "inputType": "normal_select",
    "specialConfig": {
      'type': 'recordStateMapping'
    },
    "span": 8,
    "offset": 0,
    "formItemLayout": {
      'labelCol': {
        'span': 6
      },
      'wrapperCol': {
        'span': 16
      }
    }
  }, {
    "key": "periodState",
    "label": "孕期状态",
    "inputType": "MS",
    inputProps: {
      optionKey: '孕期状态',
      marshal: 0
    },
    "span": 8,
    "offset": 0,
    "formItemLayout": {
      'labelCol': {
        'span': 6
      },
      'wrapperCol': {
        'span': 16
      }
    }
  }, {
    "key": "closingDate",
    "label": "终止时间",
    "inputType": "DatePicker",
    isNewRow: 1,
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_终止妊娠]
        }
      }
    },
    layout: '1/3'
  }, {
    "key": "closingGestationalWeek",
    "label": "终止孕周",
    "inputType": "input",
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_终止妊娠]
        }
      }
    },
    layout: '1/3'
  }, {
    "key": "closingNote",
    "label": "终止原因",
    "inputType": "input",
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_终止妊娠]
        }
      }
    },
    layout: '1/3'
  }, {
    "key": "deliveryDate",
    "label": "分娩时间",
    "inputType": "DatePicker",
    isNewRow: 1,
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_已分娩]
        }
      }
    },
    layout: '1/3'
  }, {
    "key": "deliveryGestationalWeek",
    "label": "分娩孕周",
    "inputType": "input",
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_已分娩]
        }
      }
    },
    layout: '1/3'
  }, {
    "key": "deliveryMode",
    "label": "分娩方式",
    inputType: 'MS',
    "inputProps": {
      optionKey: mchcEnv["in"](['南医增城']) ? '分娩方式' : '分娩方式s',
      marshal: 0,
      dependency: {
        show: {
          key: 'periodState',
          value: [value_已分娩]
        }
      }
    },
    layout: '1/3'
  }, {
    "key": "referralOutInfo.reason",
    "label": "转出原因",
    "inputType": "text_area",
    isNewRow: 1,
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_转院]
        }
      }
    },
    "rules": [{
      'required': true,
      'message': '转入原因是必填项'
    }],
    layout: '2/3'
  }, {
    "key": "referralOutInfo.referralDate",
    "label": "转出时间",
    "inputType": "DatePicker",
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_转院]
        }
      }
    },
    "rules": [{
      'required': true,
      'message': '转入时间是必填项'
    }],
    layout: '1/3'
  }, {
    "key": "referralOutInfo.organizationId",
    "label": "转至单位",
    "inputType": "MyReferralOrganizationSelect",
    "inputProps": {
      directionKey: 'referralOutInfo.referralDirection',
      dependency: {
        show: {
          key: 'periodState',
          value: [value_转院]
        }
      }
    },
    "rules": [{
      'required': true,
      'message': '转至单位是必填项'
    }],
    layout: '1/3'
  }, {
    "key": "referralOutInfo.referralDept",
    "label": "转至科室",
    "inputType": "input",
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_转院]
        }
      }
    },
    layout: '1/3'
  }, {
    "key": "referralOutInfo.referralDirection",
    "label": "转诊类型",
    "inputType": "checkbox_group",
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_转院]
        }
      }
    },
    "specialConfig": {
      'type': 'single',
      'options': [{
        'value': 1,
        'label': '平级',
        'span': 6,
        'withInput': false
      }, {
        'value': 2,
        'label': '上级',
        'withInput': false,
        'span': 6
      }, {
        'value': 3,
        'label': '下级',
        'withInput': false,
        'span': 6
      }]
    },
    layout: '1/3'
  }, {
    "key": "referralOutInfo.referralDoctor",
    "label": "申请者",
    "inputType": "input",
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_转院]
        }
      }
    },
    layout: '1/3'
  }, {
    "key": "referralOutInfo.referralContactNumber",
    "label": "科室联系电话",
    "inputType": "input",
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_转院]
        }
      }
    },
    layout: '1/3'
  }, {
    "key": "referralOutInfo.recorder",
    "label": "记录者",
    "inputType": "input",
    "inputProps": {
      dependency: {
        show: {
          key: 'periodState',
          value: [value_转院]
        }
      }
    },
    "rules": [{
      'required': true,
      'message': '记录者是必填项'
    }],
    layout: '1/3'
  }];
};
function ClosingArchives_Inner(_a) {
  var headerInfo = _a.headerInfo,
    isSingle = _a.isSingle,
    _b = _a.form,
    form = _b === void 0 ? _Form.useForm()[0] : _b;
  var _c = useState(),
    data = _c[0],
    setData = _c[1];
  useEffect(function () {
    var _a;
    var id = (_a = headerInfo === null || headerInfo === void 0 ? void 0 : headerInfo.id) !== null && _a !== void 0 ? _a : getSearchParamsValue('id');
    SMchc_Doctor.getOutpatientDocumentStatus(id).then(function (res) {
      var _a, _b;
      res.referralOutInfo = (_a = res.referralOutInfo) !== null && _a !== void 0 ? _a : {};
      res.referralOutInfo.recorder = res.referralOutInfo.recorder || ((_b = SLocal_State.getUserData()) === null || _b === void 0 ? void 0 : _b.firstName) || '';
      form.setFieldsValue(res);
      setData(res);
    });
    return function () {};
  }, []);
  function handlePrint() {
    return __awaiter(this, void 0, void 0, function () {
      var localData;
      var _a;
      return __generator(this, function (_b) {
        localData = store.get('localData');
        mchcModal__.open('print_modal', {
          modal_data: {
            requestData: {
              url: '/api/pdf-preview',
              resource: '',
              template: _get(localData, "referralStyle", 2),
              version: '',
              note: '',
              id: (_a = data === null || data === void 0 ? void 0 : data.referralOutInfo) === null || _a === void 0 ? void 0 : _a.id
            }
          }
        });
        return [2];
      });
    });
  }
  function showPrint() {
    var _a;
    return ((_a = data === null || data === void 0 ? void 0 : data.referralOutInfo) === null || _a === void 0 ? void 0 : _a.id) && data.periodState === '5';
  }
  function renderPrintBtn() {
    return showPrint() ? /*#__PURE__*/React__default.createElement(_Button, {
      type: "primary",
      size: "large",
      icon: /*#__PURE__*/React__default.createElement(PrinterOutlined, null),
      onClick: function onClick() {
        handlePrint();
      }
    }, "\u6253\u5370\u8F6C\u8BCA\u5355") : null;
  }
  function renderSubmitBtn() {
    return (data === null || data === void 0 ? void 0 : data.recordstate) === '6' ? /*#__PURE__*/React__default.createElement(_Popconfirm, {
      placement: "topRight",
      title: "\u4F60\u786E\u5B9A\u8981\u7ED3\u6848\u5417\uFF1F\u7ED3\u6848\u540E\u5C06\u65E0\u6CD5\u4FEE\u6539\u6863\u6848\u7684\u4EFB\u4F55\u4FE1\u606F\uFF0C\u8BF7\u8C28\u614E\u64CD\u4F5C\uFF01",
      onConfirm: handleFinish,
      okText: "\u786E\u5B9A",
      cancelText: "\u53D6\u6D88"
    }, /*#__PURE__*/React__default.createElement(_Button, {
      size: "large",
      type: "primary",
      icon: /*#__PURE__*/React__default.createElement(SaveOutlined, null)
    }, "\u4FDD\u5B58")) : /*#__PURE__*/React__default.createElement(_Button, {
      size: "large",
      type: "primary",
      icon: /*#__PURE__*/React__default.createElement(SaveOutlined, null),
      htmlType: "submit",
      onClick: handleFinish
    }, "\u4FDD\u5B58");
  }
  function handleFinish() {
    return __awaiter(this, void 0, void 0, function () {
      var _this = this;
      return __generator(this, function (_a) {
        form.validateFields().then(function () {
          return __awaiter(_this, void 0, void 0, function () {
            var params, newData;
            return __generator(this, function (_a) {
              switch (_a.label) {
                case 0:
                  params = __assign(__assign({}, form.getFieldsValue()), {
                    id: _get(data, 'id')
                  });
                  return [4, SMchc_Doctor.updateOutpatientDocumentStatus(params)];
                case 1:
                  newData = _a.sent();
                  _message.success("\u4FEE\u6539\u6210\u529F");
                  setData(newData);
                  if (_get(params, 'recordstate') === '6' && (isSingle || __DEV__)) {
                    if (confirm('此份档案已结案，是否需要新建档案？')) {
                      SLocal_History.closeAndReplace({
                        pathname: '/single/add-archival',
                        state: {
                          pregnancyData: headerInfo,
                          isSingle: isSingle,
                          location: _get(history, 'location')
                        }
                      });
                    }
                  }
                  return [2];
              }
            });
          });
        })["catch"](function (error) {
          _message.error(_get(error, 'errorFields.0.errors.0'));
          form.scrollToField(_get(error, 'errorFields.0.name.0'));
        });
        return [2];
      });
    });
  }
  return /*#__PURE__*/React__default.createElement(BaseEditPanelFormFC, {
    form: form,
    formDescriptions: form_config(),
    renderBtns: function renderBtns(form) {
      return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, renderPrintBtn(), renderSubmitBtn());
    }
  });
}
export { ClosingArchives_Inner as default };
//# sourceMappingURL=pregnancy.nurse-end.close-archives.js.map
