import 'antd/es/button/style';
import _Button from 'antd/es/button';
import 'antd/es/result/style';
import _Result from 'antd/es/result';
import 'antd/es/form/style';
import _Form from 'antd/es/form';
import _set from 'lodash/set';
import _get from 'lodash/get';
import { b as __awaiter, c as __generator, i as DoctorEnd_ImageReport, j as DoctorEnd_SurveyReport, a as __spreadArray } from './index.js';
import { PanelTitle, MyFormSectionForm, OkButton, LoadingPlaceholder } from '@lm_fe/components_m';
import { defineFormConfig, SLocal_State } from '@lm_fe/service';
import { getSearchParamsValue, formatDate, sleep, request, getSearchParamsAll } from '@lm_fe/utils';
import React__default, { useState, useEffect } from 'react';
import { mchcEnv, mchcLogger } from '@lm_fe/env';
import { Page_DocRecord, BF_Wrap2, mchcModal__ } from '@lm_fe/pages';
function load_form_config_women_exam_records() {
  return __awaiter(this, void 0, void 0, function () {
    return __generator(this, function (_a) {
      if (mchcEnv.is('建瓯')) return [2, import('./women.women-exam-records.form_config.js')];
      return [2, import('./women.women-exam-records.form_config2.js')];
    });
  });
}
var 知情同意书_tab = defineFormConfig([{
  label: '知情同意书',
  children: [{
    inputType: 'node',
    inputProps: {
      node: /*#__PURE__*/React__default.createElement(Page_DocRecord, {
        type: "\u95E8\u8BCA"
      })
    }
  }]
}, {
  label: '影像报告',
  children: [{
    inputType: 'component',
    name: 'gynecologicalPatient',
    inputProps: {
      component: function component(_a) {
        var value = _a.value;
        return /*#__PURE__*/React__default.createElement(DoctorEnd_ImageReport, {
          headerInfo: value
        });
      }
    }
  }]
}, {
  label: '检验报告',
  children: [{
    inputType: 'component',
    name: 'gynecologicalPatient',
    inputProps: {
      component: function component(_a) {
        var value = _a.value;
        return /*#__PURE__*/React__default.createElement(DoctorEnd_SurveyReport, {
          headerInfo: value
        });
      }
    }
  }]
}], {
  containerType: 'tabs'
});
var a = function a(props) {
  var _a;
  var id = getSearchParamsValue('id');
  var patientId = getSearchParamsValue('patientId');
  var form = _Form.useForm()[0];
  var _b = useState(),
    data = _b[0],
    setData = _b[1];
  var _c = useState(false),
    loading = _c[0],
    setLoading = _c[1];
  var _d = BF_Wrap2({
      default_conf: {
        title: '妇女档案-健康检查',
        tableColumns: load_form_config_women_exam_records
      }
    }),
    Wrap = _d.Wrap,
    config = _d.config;
  console.log('config', {
    config: config
  });
  function fetch_data() {
    return __awaiter(this, void 0, void 0, function () {
      var login_res;
      var _a;
      var _b;
      return __generator(this, function (_c) {
        switch (_c.label) {
          case 0:
            mchcLogger.log({
              id: id,
              patientId: patientId
            });
            if (!patientId) return [3, 2];
            _a = {};
            return [4, request.get("/api/gynecological-patients/".concat(patientId))];
          case 1:
            return [2, (_a.gynecologicalPatient = _c.sent().data, _a.archivistNo = SLocal_State.userData.id, _a.archivist = SLocal_State.userData.firstName, _a)];
          case 2:
            if (!id) return [3, 4];
            return [4, request.get("/api/gynecological-visits/".concat(id))];
          case 3:
            return [2, _c.sent().data];
          case 4:
            if (!__DEV__) return [3, 6];
            return [4, sleep(2)];
          case 5:
            _c.sent();
            return [2, null];
          case 6:
            return [4, request.post("/api/gynecological-patients/login", getSearchParamsAll())];
          case 7:
            login_res = _c.sent();
            return [2, (_b = login_res.data) === null || _b === void 0 ? void 0 : _b.gynecologicalVisit];
        }
      });
    });
  }
  useEffect(function () {
    setLoading(true);
    fetch_data().then(function (res) {
      return __awaiter(void 0, void 0, void 0, function () {
        var _a, _b, _c;
        return __generator(this, function (_d) {
          switch (_d.label) {
            case 0:
              mchcLogger.log('fetch', {
                res: res,
                form: form
              });
              _set(res, 'visitDate', (_a = res === null || res === void 0 ? void 0 : res.visitDate) !== null && _a !== void 0 ? _a : formatDate());
              _set(res, 'doctorName', (_b = res === null || res === void 0 ? void 0 : res.doctorName) !== null && _b !== void 0 ? _b : (_c = SLocal_State.userData) === null || _c === void 0 ? void 0 : _c.login);
              setData(res);
              return [4, sleep(1)];
            case 1:
              _d.sent();
              form.setFieldsValue(res);
              return [2];
          }
        });
      });
    })["finally"](function () {
      return setLoading(false);
    });
    return function () {};
  }, []);
  var h = [{
    title: '姓名',
    value: _get(data, 'gynecologicalPatient.name')
  }, {
    title: '年龄',
    value: _get(data, 'gynecologicalPatient.age')
  }, {
    title: '门诊号',
    value: _get(data, 'gynecologicalPatient.outpatientNO')
  }];
  var empty_node = loading ? /*#__PURE__*/React__default.createElement(LoadingPlaceholder, null) : /*#__PURE__*/React__default.createElement(_Result, {
    status: "warning",
    title: "\u8BF7\u5230\u62A4\u58EB\u7AD9\u62A5\u5230"
  });
  return data ? /*#__PURE__*/React__default.createElement("div", {
    style: {
      background: '#fff',
      height: '100%',
      overflowY: 'scroll'
    }
  }, /*#__PURE__*/React__default.createElement(PanelTitle, {
    headerItems: h
  }), /*#__PURE__*/React__default.createElement(Wrap, null, /*#__PURE__*/React__default.createElement(MyFormSectionForm, {
    style: {
      paddingTop: 0
    },
    form: form,
    formDescriptions: __spreadArray(__spreadArray([], (_a = config === null || config === void 0 ? void 0 : config.tableColumns) !== null && _a !== void 0 ? _a : [], true), 知情同意书_tab.__lazy_config, true)
  })), /*#__PURE__*/React__default.createElement("div", {
    style: {
      height: 40,
      margin: 12
    }
  }, /*#__PURE__*/React__default.createElement(_Button.Group, {
    style: {
      "float": 'right'
    }
  }, /*#__PURE__*/React__default.createElement(OkButton, {
    primary: true,
    size: "large",
    onClick: function onClick() {
      var values = form.getFieldsValue();
      var gynecologicalPatient = Object.assign({}, data.gynecologicalPatient, values.gynecologicalPatient);
      var submitData = Object.assign({}, data, form.getFieldsValue(), {
        gynecologicalPatient: gynecologicalPatient
      });
      var p = (data === null || data === void 0 ? void 0 : data.id) ? request.put('/api/gynecological-visits', submitData, {
        successText: '操作成功！'
      }) : request.post('/api/gynecological-visits', submitData, {
        successText: '操作成功！'
      });
      p.then(function (res) {
        return setData(res.data);
      });
    }
  }, "\u4FDD\u5B58"), /*#__PURE__*/React__default.createElement(OkButton, {
    primary: true,
    size: "large",
    onClick: function onClick() {
      mchcModal__.open('print_modal', {
        modal_data: {
          requestData: {
            url: '/api/gynecological-visits/print',
            id: data === null || data === void 0 ? void 0 : data.id
          }
        }
      });
    }
  }, "\u6253\u5370")))) : empty_node;
};
var index = {
  __proto__: null,
  'default': a
};
export { a, index as i, 知情同意书_tab as 知 };
//# sourceMappingURL=index3.js.map
