import 'antd/es/modal/style';
import _Modal from 'antd/es/modal';
import 'antd/es/row/style';
import _Row from 'antd/es/row';
import 'antd/es/spin/style';
import _Spin from 'antd/es/spin';
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/button/style';
import _Button from 'antd/es/button';
import 'antd/es/input/style';
import _Input from 'antd/es/input';
import 'antd/es/message/style';
import _message from 'antd/es/message';
import _throttle from 'lodash/throttle';
import _size from 'lodash/size';
import _set from 'lodash/set';
import _map from 'lodash/map';
import _isString from 'lodash/isString';
import _get from 'lodash/get';
import _findIndex from 'lodash/findIndex';
import _find from 'lodash/find';
import _filter from 'lodash/filter';
import _cloneDeep from 'lodash/cloneDeep';
import { s as styleInject, b as __awaiter, c as __generator, h as DoctorEnd_TemplateTree, e as api, a as __spreadArray } from './index.js';
import { CustomIcon, HighRiskGradeSelect } from '@lm_fe/components_m';
import { mchcEnv } from '@lm_fe/env';
import { SLocal_State } from '@lm_fe/service';
import { request } from '@lm_fe/utils';
import React__default, { useState, useRef, useEffect } from 'react';
import { D as DiagnosesWeek, a as DiagnosesItem, r as requestMethods_further } from './diagnoses-week.js';
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 '@ant-design/icons';
import '@lm_fe/pages';
var css_248z = ".diag-template {\n  width: 900px !important;\n  height: 600px;\n}\n.diag-template .diag-ipt {\n  width: 80%;\n}\n.diag-template .search-info {\n  color: #242741;\n  font-size: 12px;\n  margin: 8px 0 0 5px;\n}\n.diag-template .ant-tabs-content {\n  height: 450px;\n  overflow-y: auto;\n}\n.diag-template .ant-tabs-top > .ant-tabs-nav::before {\n  border: none;\n}\n.diag-template .ant-tabs-bar {\n  border-bottom: none;\n}\n.diag-template .ant-tabs-tab-active .list-btn {\n  color: #3d8bf7;\n  border: 1px solid #007aff;\n  border-radius: 4px;\n}\n.diag-template .ant-tabs-ink-bar {\n  display: none !important;\n}\n.diag-template .ant-tabs-nav {\n  margin-bottom: 0;\n}\n.diag-template .ant-tabs-nav .ant-tabs-tab-inner {\n  padding: 0;\n  padding-bottom: 3px;\n}\n.diag-template .ant-tabs-nav .ant-tabs-tab {\n  margin-right: 12px;\n}\n.diag-template .diag-item {\n  padding-left: 3px;\n  color: #383f4a;\n  font-size: 14px;\n  font-weight: 600;\n  margin-bottom: 6px;\n  cursor: pointer;\n}\n.diag-template .diag-item .diag-icon {\n  margin-left: 8px;\n  display: none;\n}\n.diag-template .diag-item:hover {\n  font-size: 14px;\n  color: #007aff;\n  border-radius: 6px;\n  background-color: #f2f2fa;\n}\n.diag-template .diag-item:hover .diag-icon {\n  display: inline-block;\n}\n.diag-template .diag-item .diag-code {\n  display: inline-block;\n  border: 1px #007aff solid;\n  margin-right: 6px;\n  font-size: 12px;\n  border-radius: 4px;\n  padding: 0 3px;\n  height: 16px;\n  line-height: 16px;\n}\n.diag-template .ant-tree {\n  padding: 0;\n  font-weight: 600;\n}\n.diag-template .ant-tree .ant-tree-title {\n  padding-left: 3px;\n  color: #383f4a;\n  font-weight: 600;\n  margin-bottom: 0;\n  cursor: pointer;\n}\n.diag-template .ant-tree .ant-tree-title:hover {\n  font-size: 18px;\n  color: #007aff;\n  border-radius: 6px;\n  background-color: #f2f2fa;\n}\n.diag-template .list-btn {\n  height: 32px;\n  color: #535881;\n  font-weight: 600;\n  padding: 0 15px;\n  background-color: #fff;\n  border: 1px solid #d8dce6;\n  display: flex;\n  align-items: center;\n}\n.diag-template .list-btn .ant-tabs-tab .anticon {\n  display: flex;\n  align-items: center;\n  margin-right: 0px;\n}\n.diag-template .diag-title {\n  line-height: 50px;\n}\n.diag-template .diag-content {\n  overflow: auto;\n  height: 450px;\n}\n.diag-template .diag-content .singleDiag {\n  display: flex;\n  align-items: center;\n  margin: 7px 0 7px 5px;\n  font-weight: 600;\n  color: #150f55;\n}\n.diag-template .diag-content input::-webkit-input-placeholder {\n  /* WebKit browsers */\n}\n.diag-template .diag-content input:-moz-placeholder {\n  /* Mozilla Firefox 4 to 18 */\n}\n.diag-template .diag-content input::-moz-placeholder {\n  /* Mozilla Firefox 19+ */\n}\n.diag-template .diag-content input:-ms-input-placeholder {\n  /* Internet Explorer 10+ */\n}\n.diag-template .diag-content .diagGP {\n  display: inline-block;\n  width: 12px;\n  height: 21px;\n  line-height: 21px;\n  border-bottom: 1px #fe708b solid;\n}\n.diag-template .diag-content .diagWeek {\n  width: 34px;\n  padding: 0 2px;\n}\n.diag-template .diag-content .diagWord {\n  display: flex;\n  align-items: center;\n  border-radius: 2px;\n  color: #150f55;\n  cursor: pointer;\n  flex-wrap: wrap;\n}\n.diag-template .diag-content .remark {\n  color: #a39b9b;\n}\n.diag-template .diag-content .diagNote {\n  height: 28px;\n  border: 0 none;\n  outline: none;\n  box-shadow: none;\n  background-color: transparent;\n  border-bottom: 1px #fe708b solid;\n}\n.diag-template .diag-content .diagNote::-ms-input-placeholder {\n  text-align: center;\n}\n.diag-template .diag-content .diagNote::-webkit-input-placeholder {\n  text-align: center;\n}\n.diag-template .diag-content .preInput {\n  width: 90px;\n  color: #242741;\n}\n.diag-template .diag-content .Input {\n  flex: 1;\n  color: #242741;\n}\n.diag-template .diag-content .diag-popover {\n  display: flex;\n  align-items: center;\n}\n.diag-template .diag-content .diag-words {\n  overflow: hidden;\n  text-overflow: ellipsis;\n  display: -webkit-box !important;\n  -webkit-box-orient: vertical;\n  -webkit-line-clamp: 2;\n}\n.diag-template .diag-content .delBtn {\n  color: #8a8a8a;\n  font-size: 24px;\n}\n";
styleInject(css_248z);
function DiagnosesTemplateOld(props) {
  var _this = this;
  var _a;
  var isShowDiagnosesTemplate = props.isShowDiagnosesTemplate,
    diagnosesWord = props.diagnosesWord,
    diagnosesList = props.diagnosesList,
    headerInfo = props.headerInfo,
    saveHeaderInfo = props.saveHeaderInfo;
  props.getHighriskDiagnosis;
  var setDiagnosesList = props.setDiagnosesList,
    closeTemplate = props.closeTemplate,
    addDiag = props.addDiag;
  var userid = (_a = SLocal_State.getUserData()) === null || _a === void 0 ? void 0 : _a.id;
  var _b = useState([]),
    allDiagnosesTemplate = _b[0],
    set_allDiagnosesTemplate = _b[1];
  var _c = useState([]),
    filterDiagnosesTemplate = _c[0],
    set_filterDiagnosesTemplate = _c[1];
  var _d = useState(false);
  _d[0];
  _d[1];
  var _e = useState(''),
    searchValue = _e[0],
    set_searchValue = _e[1];
  var _f = useState('1'),
    activeKey = _f[0],
    set_activeKey = _f[1];
  var page = useRef(0);
  var loading = useRef(false);
  var empty = useRef(false);
  var timer = useRef(null);
  useEffect(function () {
    getDiagnosesTemplate(diagnosesWord);
  }, [diagnosesWord]);
  var scrollHandler = _throttle(function (e) {
    if (loading.current || empty.current) return;
    var target = e.nativeEvent.target;
    var clientHeight = target.clientHeight;
    var scrollTop = target.scrollTop;
    var scrollHeight = target.scrollHeight;
    if (clientHeight + scrollTop > scrollHeight * .8 || scrollTop < 10) getDiagnosesTemplatePage(searchValue, ++page.current);
  }, 100);
  useEffect(function () {
    set_filterDiagnosesTemplate(filterDiagnoses(allDiagnosesTemplate, diagnosesList));
  }, [diagnosesList]);
  function filterDiagnoses(remoteData, diagnoses) {
    var newTemplate = _filter(remoteData, function (item) {
      var ind = _findIndex(diagnoses, function (i) {
        return i.diagnosis == item.val;
      });
      return ind == -1 ? true : false;
    });
    return newTemplate;
  }
  function getDiagnosesTemplate(value) {
    return __awaiter(this, void 0, void 0, function () {
      var res;
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            return [4, api.components.getDiagnosesTemplate(value)];
          case 1:
            res = _a.sent();
            set_filterDiagnosesTemplate(filterDiagnoses(res, diagnosesList));
            set_allDiagnosesTemplate(res);
            return [2];
        }
      });
    });
  }
  function getDiagnosesTemplatePage(value_1) {
    return __awaiter(this, arguments, void 0, function (value, page) {
      var res;
      if (page === void 0) {
        page = 0;
      }
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            loading.current = true;
            _a.label = 1;
          case 1:
            _a.trys.push([1,, 3, 4]);
            return [4, api.components.getDiagnosesTemplate(value, page)];
          case 2:
            res = _a.sent();
            if (!(res === null || res === void 0 ? void 0 : res.length)) empty.current = true;
            set_filterDiagnosesTemplate(__spreadArray(__spreadArray([], filterDiagnosesTemplate, true), filterDiagnoses(res, diagnosesList), true));
            return [3, 4];
          case 3:
            loading.current = false;
            return [7];
          case 4:
            return [2];
        }
      });
    });
  }
  function handleChangeTab(activeKey) {
    set_activeKey(activeKey);
  }
  function handleChange(value) {
    return __awaiter(this, void 0, void 0, function () {
      return __generator(this, function (_a) {
        page.current = 0;
        empty.current = false;
        if (timer.current) clearTimeout(timer.current);
        timer.current = setTimeout(function () {
          set_searchValue(value);
          if (activeKey == '1') {
            getDiagnosesTemplate(value);
          }
        }, 500);
        return [2];
      });
    });
  }
  function findMaxSort() {
    var max = 0;
    _map(diagnosesList, function (item) {
      var sort = _get(item, "sort");
      if (sort > max) {
        max = sort;
      }
    });
    return max + 1;
  }
  function handleSearch(item) {
    var postdata = {
      diagnosis: '',
      diagnosisCode: '',
      highrisk: false,
      note: '',
      sort: findMaxSort(),
      outEmrId: _get(headerInfo, "id")
    };
    if (item) {
      if (!_isString(item) && _size(item.children) > 0) return;
      if (_isString(item)) {
        _set(postdata, "diagnosis", item);
        var itemObj = _find(filterDiagnosesTemplate, function (tem) {
          return tem.val == item;
        });
        if (itemObj) {
          _set(postdata, 'diagnosisCode', _get(itemObj, 'code'));
        }
      } else {
        _set(postdata, 'diagnosis', _get(item, 'val'));
        _set(postdata, 'diagnosisCode', _get(item, 'code'));
      }
      addDiag(postdata);
    }
  }
  function handleCancel() {
    closeTemplate();
  }
  function handleAddIcon(item, type) {
    return __awaiter(this, void 0, void 0, function () {
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            delete item.id;
            _set(item, 'pid', 0);
            _set(item, 'type', type);
            if (type === 2) {
              _set(item, 'depid', type);
            } else {
              _set(item, 'userid', userid);
            }
            return [4, api.components.addTemplateTree(item)];
          case 1:
            _a.sent();
            _message.info("".concat(_get(item, "val"), "\u540C\u6B65\u5230").concat(type == 2 ? '科室' : '个人'));
            return [2];
        }
      });
    });
  }
  function changeHeaderInfo() {
    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/getOutpatientHeaderInfo?id=' + _get(headerInfo, "id"))];
          case 1:
            res = _a.sent().data;
            saveHeaderInfo(res);
            return [2];
        }
      });
    });
  }
  function handleDelete(item, i) {
    return __awaiter(this, void 0, void 0, function () {
      var newList, delArr;
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            newList = _cloneDeep(diagnosesList);
            delArr = newList.splice(i, 1);
            return [4, requestMethods_further.deleteDiagnosis(_get(delArr, "[0].id"))];
          case 1:
            _a.sent();
            _message.info('删除成功！');
            setDiagnosesList(newList);
            changeHeaderInfo();
            return [2];
        }
      });
    });
  }
  function changeNote(v, i, key) {
    var newList = _cloneDeep(diagnosesList);
    var item = newList[i];
    item["".concat(key)] = v;
    setDiagnosesList(newList);
  }
  function updateNote(value, i, key) {
    var newList = _cloneDeep(diagnosesList);
    var item = newList[i];
    item["".concat(key)] = value;
    setDiagnosesList(newList);
    requestMethods_further.newAddDiagnosis(item);
  }
  var style = {
    fontSize: '24px',
    marginRight: '0px',
    display: 'flex',
    alignItems: 'center'
  };
  return /*#__PURE__*/React__default.createElement(_Modal, {
    centered: true,
    title: /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(CustomIcon, {
      type: 'icon-doctor',
      style: {
        color: '#150F55',
        fontSize: '24px',
        marginRight: '10px'
      }
    }), /*#__PURE__*/React__default.createElement("span", {
      style: {
        color: '#150F55',
        fontSize: '16px',
        fontWeight: 500
      }
    }, "\u8BCA\u65AD\u7BA1\u7406\u9875")),
    className: "diag-template",
    footer: null,
    visible: isShowDiagnosesTemplate,
    onCancel: handleCancel
  }, /*#__PURE__*/React__default.createElement(_Row, null, /*#__PURE__*/React__default.createElement(_Col, {
    span: 14
  }, /*#__PURE__*/React__default.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center'
    }
  }, /*#__PURE__*/React__default.createElement(_Input.Search, {
    placeholder: "\u8BF7\u8F93\u5165\u8BCA\u65AD\u4FE1\u606F",
    enterButton: "\u6DFB\u52A0\u8BCA\u65AD",
    defaultValue: diagnosesWord,
    onChange: function onChange(e) {
      return handleChange(e.target.value);
    },
    onSearch: handleSearch
  }), !mchcEnv.is('郫都') && /*#__PURE__*/React__default.createElement(HighRiskGradeSelect, {
    headerInfo: headerInfo
  })), /*#__PURE__*/React__default.createElement(_Tabs, {
    activeKey: activeKey,
    onChange: handleChangeTab
  }, /*#__PURE__*/React__default.createElement(_Tabs.TabPane, {
    tab: /*#__PURE__*/React__default.createElement(_Button, {
      className: "list-btn",
      icon: /*#__PURE__*/React__default.createElement(CustomIcon, {
        type: "icon-all",
        style: style
      })
    }, "\u5168\u90E8"),
    key: "1"
  }, /*#__PURE__*/React__default.createElement("div", {
    onScroll: scrollHandler,
    style: {
      height: '100%',
      overflowY: 'scroll'
    }
  }, _map(filterDiagnosesTemplate, function (item) {
    return /*#__PURE__*/React__default.createElement("p", {
      className: "diag-item"
    }, /*#__PURE__*/React__default.createElement("span", {
      onClick: function onClick() {
        return handleSearch(item);
      }
    }, _get(item, 'code') ? '（icd）' : null, _get(item, 'val')), /*#__PURE__*/React__default.createElement(CustomIcon, {
      className: "diag-icon",
      title: "\u540C\u6B65\u5230\u79D1\u5BA4\u8BCA\u65AD",
      onClick: function onClick() {
        return handleAddIcon(item, 2);
      },
      type: "icon-department"
    }), /*#__PURE__*/React__default.createElement(CustomIcon, {
      className: "diag-icon",
      title: "\u540C\u6B65\u5230\u4E2A\u4EBA\u8BCA\u65AD",
      onClick: function onClick() {
        return handleAddIcon(item, 3);
      },
      type: "icon-individual1"
    }));
  }))), "(", /*#__PURE__*/React__default.createElement(_Tabs.TabPane, {
    tab: /*#__PURE__*/React__default.createElement(_Button, {
      className: "list-btn",
      icon: /*#__PURE__*/React__default.createElement(CustomIcon, {
        style: style,
        type: "icon-department"
      })
    }, "\u79D1\u5BA4"),
    key: "2"
  }, activeKey === '2' && /*#__PURE__*/React__default.createElement(DoctorEnd_TemplateTree, {
    type: 2,
    depid: 2,
    checkable: false,
    onSelected: handleSearch,
    editable: true,
    showIcd: true,
    searchValue: searchValue
  })), ") (", /*#__PURE__*/React__default.createElement(_Tabs.TabPane, {
    tab: /*#__PURE__*/React__default.createElement(_Button, {
      className: "list-btn",
      icon: /*#__PURE__*/React__default.createElement(CustomIcon, {
        style: style,
        type: "icon-individual1"
      })
    }, "\u4E2A\u4EBA"),
    key: "3"
  }, activeKey === '3' && /*#__PURE__*/React__default.createElement(DoctorEnd_TemplateTree, {
    type: 3,
    userid: userid,
    checkable: false,
    onSelected: handleSearch,
    editable: true,
    showIcd: true,
    searchValue: searchValue
  })), ")")), /*#__PURE__*/React__default.createElement(_Col, {
    span: 10
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "diag-title"
  }, "\u5DF2\u9009\u8BCA\u65AD"), /*#__PURE__*/React__default.createElement("div", {
    id: "diag-content",
    className: "diag-content"
  }, /*#__PURE__*/React__default.createElement(DiagnosesWeek, {
    first: false,
    headerInfo: headerInfo
  }), diagnosesList ? diagnosesList.map(function (item, i) {
    return /*#__PURE__*/React__default.createElement(DiagnosesItem, {
      key: "".concat(_get(item, 'id'), "-true"),
      diagnose: item,
      changeNote: changeNote,
      updateNote: updateNote.bind(_this),
      index: i,
      handleDelete: handleDelete,
      edit: true,
      headerInfo: headerInfo,
      saveHeaderInfo: props.saveHeaderInfo,
      diagnosesList: diagnosesList,
      setDiagnosesList: props.setDiagnosesList,
      isShowDiagnosesTemplate: true
    });
  }) : /*#__PURE__*/React__default.createElement(_Spin, null)))));
}
export { DiagnosesTemplateOld as default };
//# sourceMappingURL=prenatal-visit.pregnancy.doctor-end6.js.map
