import 'antd/es/row/style';
import _Row from 'antd/es/row';
import 'antd/es/checkbox/style';
import _Checkbox from 'antd/es/checkbox';
import 'antd/es/col/style';
import _Col from 'antd/es/col';
import 'antd/es/tabs/style';
import _Tabs from 'antd/es/tabs';
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/modal/style';
import _Modal from 'antd/es/modal';
import 'antd/es/input/style';
import _Input from 'antd/es/input';
import 'antd/es/message/style';
import _message from 'antd/es/message';
import _omit from 'lodash/omit';
import _includes from 'lodash/includes';
import _size from 'lodash/size';
import _filter from 'lodash/filter';
import _last from 'lodash/last';
import _first from 'lodash/first';
import _get from 'lodash/get';
import _map from 'lodash/map';
import { s as styleInject, b as __awaiter, c as __generator, _ as __extends, e as api, a as __spreadArray } from './index.js';
import React__default, { Component } from 'react';
import { CloseOutlined } from '@ant-design/icons';
import { request } from '@lm_fe/utils';
import { MyForm } from '@lm_fe/components_m';
import '@lm_fe/env';
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';
import '@lm_fe/service';
import '@lm_fe/pages';
var config = [{
  name: 'plan',
  key: '.*',
  label: '',
  input_type: 'prenatalReturnTable',
  input_props: {
    editable: true,
    hiddenSelection: true,
    tableColumns: [{
      key: 'no',
      title: '编号',
      width: 10,
      editor: {
        name: '',
        key: '',
        input_type: 'input',
        unEditable: false
      },
      render: function render(value, rowData, index) {
        return index + 1;
      }
    }, {
      key: 'gestationalWeek',
      title: '孕周',
      width: 20,
      editor: {
        name: '',
        key: '',
        input_type: 'input',
        input_props: {
          type: 'number'
        },
        max: 42
      }
    }, {
      key: 'remind',
      title: '提醒事件',
      width: 100,
      editor: {
        name: '',
        key: '',
        input_type: 'input'
      }
    }]
  }
}];
var css_248z = ".further-manage-modal .ant-modal-body {\n  max-height: 600px;\n  overflow: auto;\n}\n.further-manage-modal table {\n  table-layout: fixed !important;\n}\n.further-manage-modal .manage-title {\n  margin-bottom: 15px;\n}\n.further-manage-modal .manage-title .manage-btn {\n  margin-left: 20px;\n}\n.further-manage-modal .import-btn {\n  display: block;\n  margin-top: 20px;\n}\n.further-template-modal .ant-modal-body {\n  max-height: 600px;\n  overflow: auto;\n}\n.further-template-modal table {\n  table-layout: fixed !important;\n}\n.further-template-modal .add-btn {\n  margin-left: 15px;\n}\n.further-template-modal .ant-tabs-tab-btn:hover .confirm-icon {\n  visibility: visible;\n}\n.further-template-modal .confirm-icon {\n  visibility: hidden;\n  margin: 0px 0px 0px 8px;\n}\n";
styleInject(css_248z);
function getPlanVisitsOfOutpatient(id) {
  return __awaiter(this, void 0, void 0, function () {
    var res;
    return __generator(this, function (_a) {
      switch (_a.label) {
        case 0:
          return [4, request.get('/api/doctor/getPlanVisitsOfOutpatient?id=' + id)];
        case 1:
          res = _a.sent();
          return [2, res.data];
      }
    });
  });
}
function updateOutpatient(data) {
  return __awaiter(this, void 0, void 0, function () {
    var res;
    return __generator(this, function (_a) {
      switch (_a.label) {
        case 0:
          return [4, request.post('/api/doctor/updatePlanVisitsOfOutpatient', data)];
        case 1:
          res = _a.sent();
          return [2, res.data];
      }
    });
  });
}
var requestMethods = {
  getPlanVisitsOfOutpatient: getPlanVisitsOfOutpatient,
  updateOutpatient: updateOutpatient
};
var Index = function (_super) {
  __extends(Index, _super);
  function Index() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.state = {
      formHandler: {},
      modalFormHandler: {},
      isShowTemplateModal: false,
      isShowAddModal: false,
      planData: [],
      selectedKeys: [],
      activeKey: '',
      templateName: '',
      currentTemplateName: '',
      templateData: [],
      planTypesData: []
    };
    _this.getPlanData = function () {
      return __awaiter(_this, void 0, void 0, function () {
        var headerInfo, res;
        return __generator(this, function (_a) {
          switch (_a.label) {
            case 0:
              headerInfo = this.props.headerInfo;
              return [4, requestMethods.getPlanVisitsOfOutpatient(_get(headerInfo, "id"))];
            case 1:
              res = _a.sent();
              this.setState({
                planData: _get(res, "visitPlans", [])
              });
              return [2];
          }
        });
      });
    };
    _this.getPlanTypeData = function (operation) {
      return __awaiter(_this, void 0, void 0, function () {
        var activeKey, planTypesData, showData;
        return __generator(this, function (_a) {
          switch (_a.label) {
            case 0:
              activeKey = this.state.activeKey;
              return [4, api.further.getPrenatalVisitPlanTypes()];
            case 1:
              planTypesData = _a.sent();
              showData = {};
              switch (operation) {
                case 'update':
                  showData = _get(_filter(planTypesData, function (item) {
                    return item.id == activeKey;
                  }), '0');
                  break;
                case 'add':
                  showData = _last(planTypesData);
                  break;
                default:
                  showData = _first(planTypesData);
                  break;
              }
              this.setState({
                planTypesData: planTypesData,
                activeKey: _get(showData, 'id') + '',
                currentTemplateName: _get(showData, 'name'),
                templateData: _get(showData, 'prenatalVisitPlanTemplates')
              });
              return [2];
          }
        });
      });
    };
    _this.handleSavePlan = function () {
      return __awaiter(_this, void 0, void 0, function () {
        var headerInfo, formHandler, planData, data;
        return __generator(this, function (_a) {
          switch (_a.label) {
            case 0:
              headerInfo = this.props.headerInfo;
              formHandler = this.state.formHandler;
              planData = formHandler.plan.actions.getValue().value;
              data = {
                id: _get(headerInfo, 'id'),
                visitPlans: planData
              };
              return [4, requestMethods.updateOutpatient(data)];
            case 1:
              _a.sent();
              this.getPlanData();
              return [2];
          }
        });
      });
    };
    _this.handleImport = function () {
      var _a = _this.state,
        selectedKeys = _a.selectedKeys,
        planTypesData = _a.planTypesData,
        planData = _a.planData;
      if (_size(selectedKeys) > 0) {
        var addPlanTemplates_1 = [];
        var addPlans_1 = [];
        _map(planTypesData, function (item) {
          if (_includes(selectedKeys, item.id) && _size(item.prenatalVisitPlanTemplates) > 0) {
            addPlanTemplates_1 = addPlanTemplates_1.concat(item.prenatalVisitPlanTemplates);
          }
        });
        if (_size(addPlanTemplates_1) > 0) {
          _map(addPlanTemplates_1, function (item) {
            item = _omit(item, 'id');
            addPlans_1.push(item);
          });
        }
        _this.setState({
          planData: __spreadArray(__spreadArray([], planData, true), addPlans_1, true)
        });
      }
    };
    _this.handleDeletePlanType = function (item) {
      return __awaiter(_this, void 0, void 0, function () {
        return __generator(this, function (_a) {
          switch (_a.label) {
            case 0:
              return [4, api.further.deletePrenatalVisitPlanTypes(_get(item, 'id'))];
            case 1:
              _a.sent();
              this.getPlanTypeData();
              return [2];
          }
        });
      });
    };
    _this.handleAddPlanType = function () {
      return __awaiter(_this, void 0, void 0, function () {
        var templateName, data;
        return __generator(this, function (_a) {
          switch (_a.label) {
            case 0:
              templateName = this.state.templateName;
              if (!templateName) {
                _message.info('请输入模板名称！');
                return [2];
              }
              data = {
                name: templateName
              };
              return [4, api.further.addPrenatalVisitPlanTypes(data)];
            case 1:
              _a.sent();
              this.getPlanTypeData('add');
              this.setState({
                isShowAddModal: false,
                templateName: ''
              });
              return [2];
          }
        });
      });
    };
    _this.handleSaveTemplate = function () {
      return __awaiter(_this, void 0, void 0, function () {
        var _a, modalFormHandler, activeKey, currentTemplateName, templateData, data;
        return __generator(this, function (_b) {
          switch (_b.label) {
            case 0:
              _a = this.state, modalFormHandler = _a.modalFormHandler, activeKey = _a.activeKey, currentTemplateName = _a.currentTemplateName;
              templateData = modalFormHandler.plan.actions.getValue().value;
              data = {
                id: activeKey,
                name: currentTemplateName,
                prenatalVisitPlanTemplates: templateData
              };
              return [4, api.further.updatePrenatalVisitPlanTypes(data)];
            case 1:
              _b.sent();
              this.getPlanTypeData('update');
              return [2];
          }
        });
      });
    };
    _this.handleTabsChange = function (key) {
      var planTypesData = _this.state.planTypesData;
      var filterData = _filter(planTypesData, function (item) {
        return item.id == key;
      });
      _this.setState({
        activeKey: _get(filterData, '0.id') + '',
        currentTemplateName: _get(filterData, '0.name'),
        templateData: _get(filterData, '0.prenatalVisitPlanTemplates')
      });
    };
    return _this;
  }
  Index.prototype.componentDidMount = function () {
    this.getPlanTypeData();
    this.getPlanData();
  };
  Index.prototype.renderAddModal = function () {
    var _this = this;
    var _a = this.state,
      isShowAddModal = _a.isShowAddModal,
      templateName = _a.templateName;
    return /*#__PURE__*/React__default.createElement(_Modal, {
      width: 500,
      title: "\u65B0\u589E\u6A21\u677F",
      cancelText: "\u5173\u95ED",
      visible: isShowAddModal,
      onCancel: function onCancel() {
        return _this.setState({
          isShowAddModal: false
        });
      },
      onOk: this.handleAddPlanType,
      maskClosable: false
    }, /*#__PURE__*/React__default.createElement("div", null, "\u6A21\u677F\u540D\u79F0\uFF1A", /*#__PURE__*/React__default.createElement(_Input, {
      style: {
        width: '180px'
      },
      value: templateName,
      onChange: function onChange(e) {
        return _this.setState({
          templateName: e.target.value
        });
      }
    })));
  };
  Index.prototype.renderManageModal = function () {
    var _this = this;
    var _a = this.state,
      isShowTemplateModal = _a.isShowTemplateModal,
      planTypesData = _a.planTypesData,
      modalFormHandler = _a.modalFormHandler,
      templateData = _a.templateData,
      activeKey = _a.activeKey,
      currentTemplateName = _a.currentTemplateName;
    if (modalFormHandler.subscribe) {
      modalFormHandler.subscribe('plan', 'tableAdd', function () {
        return __awaiter(_this, void 0, void 0, function () {
          var currentData;
          return __generator(this, function (_a) {
            currentData = this.state.modalFormHandler.plan.actions.getValue().value;
            this.setState({
              templateData: __spreadArray(__spreadArray([], currentData, true), [{}], false)
            });
            return [2];
          });
        });
      });
      modalFormHandler.subscribe('plan', 'tableDelete', function (data) {
        return __awaiter(_this, void 0, void 0, function () {
          var keysArr, tableData, key;
          return __generator(this, function (_a) {
            keysArr = data.selectedRowKeys;
            tableData = data.dataSource;
            if (keysArr.length > 0) {
              key = keysArr[0];
              tableData.splice(key, 1);
              this.setState({
                templateData: tableData
              });
            }
            return [2];
          });
        });
      });
    }
    return /*#__PURE__*/React__default.createElement(_Modal, {
      className: "further-template-modal",
      width: "80%",
      title: /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u4EA7\u68C0\u8BA1\u5212\u6A21\u677F", /*#__PURE__*/React__default.createElement(_Button, {
        className: "add-btn",
        onClick: function onClick() {
          _this.setState({
            isShowAddModal: true
          });
        }
      }, "\u65B0\u589E\u6A21\u677F")),
      cancelText: "\u5173\u95ED",
      visible: isShowTemplateModal,
      onCancel: function onCancel() {
        return _this.setState({
          isShowTemplateModal: false
        });
      },
      onOk: this.handleSaveTemplate,
      maskClosable: false
    }, /*#__PURE__*/React__default.createElement(_Tabs, {
      tabPosition: "left",
      activeKey: activeKey,
      onChange: this.handleTabsChange
    }, _map(planTypesData, function (item) {
      return /*#__PURE__*/React__default.createElement(_Tabs.TabPane, {
        tab: /*#__PURE__*/React__default.createElement(React__default.Fragment, null, item.name, /*#__PURE__*/React__default.createElement(_Popconfirm, {
          className: "confirm-icon",
          placement: "topRight",
          title: "\u662F\u5426\u5220\u9664\u6B64\u6761\u6A21\u677F\uFF1F",
          onConfirm: function onConfirm() {
            return _this.handleDeletePlanType(item);
          },
          okText: "\u786E\u5B9A",
          cancelText: "\u53D6\u6D88"
        }, /*#__PURE__*/React__default.createElement(CloseOutlined, null))),
        key: item.id
      }, /*#__PURE__*/React__default.createElement("div", null, "\u6A21\u677F\u540D\u79F0\uFF1A", /*#__PURE__*/React__default.createElement(_Input, {
        style: {
          width: '180px'
        },
        value: currentTemplateName,
        onChange: function onChange(e) {
          return _this.setState({
            currentTemplateName: e.target.value
          });
        }
      })), activeKey == item.id && /*#__PURE__*/React__default.createElement(MyForm, {
        config: config,
        value: templateData,
        getFormHandler: function getFormHandler(modalFormHandler) {
          return _this.setState({
            modalFormHandler: modalFormHandler
          });
        },
        submitChange: false
      }));
    })));
  };
  Index.prototype.render = function () {
    var _this = this;
    var _a = this.state,
      planTypesData = _a.planTypesData,
      planData = _a.planData,
      formHandler = _a.formHandler,
      isShowTemplateModal = _a.isShowTemplateModal,
      isShowAddModal = _a.isShowAddModal;
    var _b = this.props,
      isShowManageModal = _b.isShowManageModal,
      closeModal = _b.closeModal;
    if (formHandler.subscribe) {
      formHandler.subscribe('plan', 'tableAdd', function () {
        return __awaiter(_this, void 0, void 0, function () {
          var currentData;
          return __generator(this, function (_a) {
            currentData = this.state.formHandler.plan.actions.getValue().value;
            this.setState({
              planData: __spreadArray(__spreadArray([], currentData, true), [{}], false)
            });
            return [2];
          });
        });
      });
      formHandler.subscribe('plan', 'tableDelete', function (data) {
        return __awaiter(_this, void 0, void 0, function () {
          var keysArr, tableData, key;
          return __generator(this, function (_a) {
            keysArr = data.selectedRowKeys;
            tableData = data.dataSource;
            if (keysArr.length > 0) {
              key = keysArr[0];
              tableData.splice(key, 1);
              this.setState({
                planData: tableData
              });
            }
            return [2];
          });
        });
      });
    }
    return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(_Modal, {
      className: "further-manage-modal",
      width: "80%",
      title: "\u4EA7\u68C0\u8BA1\u5212",
      cancelText: "\u5173\u95ED",
      visible: isShowManageModal,
      onOk: this.handleSavePlan,
      onCancel: function onCancel() {
        return closeModal('isShowManageModal');
      },
      maskClosable: false
    }, /*#__PURE__*/React__default.createElement(_Row, null, /*#__PURE__*/React__default.createElement(_Col, {
      span: 18
    }, /*#__PURE__*/React__default.createElement(MyForm, {
      config: config,
      value: planData,
      getFormHandler: function getFormHandler(formHandler) {
        return _this.setState({
          formHandler: formHandler
        });
      },
      submitChange: false
    })), /*#__PURE__*/React__default.createElement(_Col, {
      span: 5,
      offset: 1
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "manage-title"
    }, "\u4EA7\u68C0\u8BA1\u5212\u6A21\u677F", /*#__PURE__*/React__default.createElement(_Button, {
      className: "manage-btn",
      onClick: function onClick() {
        _this.setState({
          isShowTemplateModal: true
        });
      }
    }, "\u7BA1\u7406\u6A21\u677F")), /*#__PURE__*/React__default.createElement(_Checkbox.Group, {
      onChange: function onChange(selectedKeys) {
        return _this.setState({
          selectedKeys: selectedKeys
        });
      }
    }, _map(planTypesData, function (item) {
      return /*#__PURE__*/React__default.createElement(_Checkbox, {
        value: item.id,
        style: {
          marginLeft: 0,
          width: '100%'
        }
      }, item.name);
    })), /*#__PURE__*/React__default.createElement(_Button, {
      className: "import-btn",
      onClick: this.handleImport,
      type: "primary"
    }, "\u5BFC\u5165")))), isShowTemplateModal && this.renderManageModal(), isShowAddModal && this.renderAddModal());
  };
  return Index;
}(Component);
export { Index as default };
//# sourceMappingURL=prenatal-visit.pregnancy.doctor-end13.js.map
