import 'antd/es/message/style';
import _message from 'antd/es/message';
import 'antd/es/switch/style';
import _Switch from 'antd/es/switch';
import _map from 'lodash/map';
import _get from 'lodash/get';
import _find from 'lodash/find';
import { _ as __extends, s as styleInject, f as __rest, d as __assign, b as __awaiter, c as __generator } from './index.js';
import classnames from 'classnames';
import 'antd/es/button/style';
import _Button from 'antd/es/button';
import { RedoOutlined, SearchOutlined } from '@ant-design/icons';
import React__default, { useEffect } from 'react';
import { BaseQuery, BaseTableOld, CustomIcon, BaseListOld } from '@lm_fe/components_m';
import 'antd/es/modal/style';
import _Modal from 'antd/es/modal';
import { request } from '@lm_fe/utils';
import { APP_CONFIG } from '@lm_fe/env';
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';
import '@lm_fe/service';
import '@lm_fe/pages';
var queryFormDescriptions = {
  title: {
    label: '文章标题',
    inputType: 'input',
    filterType: '',
    style: {
      width: 100
    }
  },
  type: {
    label: '文章类型',
    inputType: 'select',
    filterType: 'in',
    options: [{
      label: '全部',
      value: null
    }, {
      label: '诊疗指南',
      value: '1'
    }, {
      label: '科室流程',
      value: '2'
    }],
    style: {
      width: 86
    }
  },
  readingState: {
    label: '阅读状态',
    inputType: 'select',
    filterType: 'equals',
    options: [{
      label: '全部',
      value: null
    }, {
      label: '未读',
      value: '0'
    }, {
      label: '已读',
      value: '1'
    }],
    style: {
      width: 86
    }
  },
  createDate: {
    label: '创建时间',
    inputType: 'rangeDate',
    filterType: ''
  }
};
var Query = function (_super) {
  __extends(Query, _super);
  function Query() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.state = {
      queryFormDescriptions: queryFormDescriptions
    };
    _this.renderBtn = function () {
      return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(_Button, {
        icon: /*#__PURE__*/React__default.createElement(RedoOutlined, null),
        onClick: _this.handleReset
      }, "\u91CD\u7F6E"), /*#__PURE__*/React__default.createElement(_Button, {
        type: "primary",
        icon: /*#__PURE__*/React__default.createElement(SearchOutlined, null),
        htmlType: "submit"
      }, "\u67E5\u8BE2"));
    };
    return _this;
  }
  return Query;
}(BaseQuery);
var RepositoryTable = function (_super) {
  __extends(RepositoryTable, _super);
  function RepositoryTable() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.renderAdd = function () {
      var _a = _this.props,
        onAdd = _a.onAdd,
        addText = _a.addText,
        disabled = _a.disabled;
      if (onAdd) {
        return /*#__PURE__*/React__default.createElement(_Button, {
          disabled: disabled,
          type: "primary",
          onClick: onAdd
        }, addText || '新增');
      }
      return;
    };
    return _this;
  }
  return RepositoryTable;
}(BaseTableOld);
var css_248z$1 = ".article-modal-container .article-content {\n  height: 500px;\n  overflow: auto;\n}\n";
styleInject(css_248z$1);
function ArticleModal(_a) {
  var sureRead = _a.sureRead,
    articleData = _a.articleData,
    onCancle = _a.onCancle,
    visible = _a.visible;
  __rest(_a, ["sureRead", "articleData", "onCancle", "visible"]);
  useEffect(function () {
    console.log({
      articleData: articleData
    });
  }, [articleData]);
  function handleOk() {
    sureRead(__assign(__assign({}, articleData), {
      readingState: true
    }));
    handleCancle();
  }
  function handleCancle() {
    onCancle && onCancle('visible', false);
  }
  function footer() {
    return /*#__PURE__*/React__default.createElement(_Button, {
      type: "primary",
      onClick: handleOk,
      disabled: _get(articleData, "readingState") == '1' ? true : false
    }, "\u786E\u8BA4\u5DF2\u8BFB");
  }
  return /*#__PURE__*/React__default.createElement(_Modal, {
    title: _get(articleData, "title") || '阅读文章',
    className: "article-modal-container",
    width: 600,
    style: {
      top: '50px'
    },
    visible: visible,
    footer: footer(),
    onCancel: handleCancle
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "article-content",
    dangerouslySetInnerHTML: {
      __html: _get(articleData, "content")
    }
  }));
}
var departmentScope = [{
  key: '1',
  value: '产科'
}, {
  key: '2',
  value: '妇科'
}, {
  key: '3',
  value: '儿科'
}];
function addMedicalPractices(postData) {
  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/medical-practices', postData)];
        case 1:
          res = _a.sent();
          return [2, res.data];
      }
    });
  });
}
function updateMedicalPractices(postData) {
  return __awaiter(this, void 0, void 0, function () {
    var res;
    return __generator(this, function (_a) {
      switch (_a.label) {
        case 0:
          return [4, request.put('/api/medical-practices', postData)];
        case 1:
          res = _a.sent();
          return [2, res.data];
      }
    });
  });
}
function getMedicalById(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/medical-practices/".concat(id))];
        case 1:
          res = _a.sent();
          return [2, res.data];
      }
    });
  });
}
function delMediacalById(id) {
  return __awaiter(this, void 0, void 0, function () {
    var res;
    return __generator(this, function (_a) {
      switch (_a.label) {
        case 0:
          return [4, request["delete"]('/api/medical-practices/' + id)];
        case 1:
          res = _a.sent();
          return [2, res.data];
      }
    });
  });
}
function medicalRead(postData) {
  return __awaiter(this, void 0, void 0, function () {
    var res;
    return __generator(this, function (_a) {
      switch (_a.label) {
        case 0:
          return [4, request.put('/api/medical-practices/reading', postData)];
        case 1:
          res = _a.sent();
          return [2, res.data];
      }
    });
  });
}
function medicalTop(postData) {
  return __awaiter(this, void 0, void 0, function () {
    var res;
    return __generator(this, function (_a) {
      switch (_a.label) {
        case 0:
          return [4, request.put('/api/medical-practices/top', postData)];
        case 1:
          res = _a.sent();
          return [2, res.data];
      }
    });
  });
}
var requestMethods = {
  addMedicalPractices: addMedicalPractices,
  updateMedicalPractices: updateMedicalPractices,
  getMedicalById: getMedicalById,
  delMediacalById: delMediacalById,
  medicalRead: medicalRead,
  medicalTop: medicalTop
};
var css_248z = ".table-title-span {\n  color: #007aff;\n  cursor: pointer;\n}\n.read-content {\n  display: flex;\n  justify-content: center;\n}\n.read-content .cus-icon {\n  font-size: 20px;\n  margin-right: 10px;\n}\n.read-content .icon-read {\n  color: #6d7278;\n}\n.read-content .icon-noread {\n  color: #007aff;\n  position: relative;\n}\n.read-content .icon-noread::after {\n  content: ' ';\n  position: absolute;\n  width: 6px;\n  height: 6px;\n  top: -4px;\n  right: 0px;\n  border-radius: 50%;\n  background-color: #fd617f;\n}\n.read-content .noread {\n  color: #007aff;\n}\n.read-content .read {\n  color: #6d7278;\n}\n";
styleInject(css_248z);
var List = function (_super) {
  __extends(List, _super);
  function List() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.state = {
      total: 0,
      defaultQuery: _this.staticDefaultQuery,
      dataSource: [],
      selectedRowKeys: [],
      selectedRows: [],
      visible: false,
      editable: false,
      id: undefined,
      editKey: undefined,
      loading: false,
      isSearchColumnModal: false,
      selectArticle: null
    };
    _this.columns = [{
      title: '文章标题',
      dataIndex: 'title',
      ellipsis: true,
      width: APP_CONFIG.CELL_WIDTH_SMALL,
      align: 'center',
      render: function render(recordstate, rowData) {
        return /*#__PURE__*/React__default.createElement("span", {
          className: "table-title-span",
          onClick: _this.handleTitleClick.bind(_this, rowData)
        }, recordstate);
      }
    }, {
      title: '文章类型',
      dataIndex: 'type',
      ellipsis: true,
      width: APP_CONFIG.CELL_WIDTH_SMALL,
      align: 'center',
      render: function render(recordstate, rowData) {
        return recordstate == 1 ? '诊疗指南' : '科室流程';
      }
    }, {
      title: '科室范围',
      dataIndex: 'departmentScope',
      ellipsis: true,
      width: APP_CONFIG.CELL_WIDTH_SMALL,
      align: 'center',
      render: function render(recordstate, rowData) {
        var data = recordstate && JSON.parse(recordstate);
        var str = '';
        _map(data, function (item, index) {
          var val = _get(_find(departmentScope, function (i) {
            return i.key == item;
          }), "value");
          str += val + '; ';
        });
        return str;
      }
    }, {
      title: '阅读状态',
      dataIndex: 'readingState',
      ellipsis: true,
      width: APP_CONFIG.CELL_WIDTH_SMALL,
      align: 'center',
      render: function render(recordstate, rowData) {
        return /*#__PURE__*/React__default.createElement("div", {
          className: "read-content"
        }, /*#__PURE__*/React__default.createElement(CustomIcon, {
          type: recordstate ? 'icon-finish' : 'icon-eyes',
          className: "cus-icon ".concat(recordstate ? 'icon-read' : 'icon-noread')
        }), /*#__PURE__*/React__default.createElement("span", {
          className: classnames('noread', {
            read: recordstate
          })
        }, recordstate ? '已读' : '未读'));
      }
    }, {
      title: '创建者',
      dataIndex: 'createDoctor',
      ellipsis: true,
      width: APP_CONFIG.CELL_WIDTH_SMALL,
      align: 'center'
    }, {
      title: '创建时间',
      dataIndex: 'createDate',
      ellipsis: true,
      width: APP_CONFIG.CELL_WIDTH_SMALL,
      align: 'center'
    }, {
      title: '置顶',
      dataIndex: 'stickyReader',
      width: 68,
      ellipsis: true,
      align: 'center',
      fixed: 'right',
      render: function render(recordstate, rowData) {
        return /*#__PURE__*/React__default.createElement(_Switch, {
          disabled: _get(rowData, "sticky"),
          checked: _get(rowData, "sticky") || recordstate,
          onChange: _this.releaseChange.bind(_this, rowData),
          size: 'small'
        });
      }
    }];
    _this.renderOthersModal = function () {
      var _a = _this.state,
        visible = _a.visible,
        selectArticle = _a.selectArticle;
      return visible ? /*#__PURE__*/React__default.createElement(ArticleModal, {
        visible: visible,
        articleData: selectArticle,
        onCancle: _this.changeState.bind(_this),
        sureRead: _this.handleSureRead.bind(_this)
      }) : /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
    };
    return _this;
  }
  List.prototype.releaseChange = function (rowData, checked) {
    return __awaiter(this, void 0, void 0, function () {
      var postData;
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            postData = __assign(__assign({}, rowData), {
              stickyReader: checked
            });
            return [4, requestMethods.medicalTop(postData)];
          case 1:
            _a.sent();
            this.handleSearch();
            _message.success("".concat(checked ? '开启' : '关闭', "\u7F6E\u9876"));
            return [2];
        }
      });
    });
  };
  List.prototype.handleTitleClick = function (rowData) {
    this.changeState('visible', true);
    this.setState({
      selectArticle: rowData
    });
    console.log({
      rowData: rowData
    });
  };
  List.prototype.changeState = function (key, value) {
    var _a;
    this.setState((_a = {}, _a[key] = value, _a));
  };
  List.prototype.handleSureRead = function (data) {
    return __awaiter(this, void 0, void 0, function () {
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            return [4, requestMethods.medicalRead(data)];
          case 1:
            _a.sent();
            this.handleSearch();
            return [2];
        }
      });
    });
  };
  List.defaultProps = {
    baseUrl: '/api/medical-practices-departments',
    baseTitle: '我的知识库',
    needPagination: true,
    showQuery: true,
    showAdd: false,
    addText: '返回孕册',
    tableColumns: [],
    rowKey: 'id',
    Table: RepositoryTable,
    Query: Query,
    otherTableProps: {
      scroll: {
        x: 1140
      }
    }
  };
  return List;
}(BaseListOld);
export { List as default };
//# sourceMappingURL=pages.my-knowledge.list.js.map
