UNPKG

@ttk/component

Version:

ttk组件库

1,357 lines (1,166 loc) 49.2 kB
import { _ as _inherits, a as _getPrototypeOf, b as _possibleConstructorReturn, c as _classCallCheck, d as _createClass, e as _assertThisInitialized, f as _typeof } from '../getPrototypeOf-b95655c5.js'; import { _ as _toConsumableArray } from '../toConsumableArray-04633de7.js'; import { _ as _defineProperty } from '../defineProperty-847730aa.js'; import React__default, { Component, PureComponent } from 'react'; import ReactDOM from 'react-dom'; import { Map, List, fromJS } from 'immutable'; import Button from '../button'; import clonedeep from 'lodash.clonedeep'; import { _ as _extends } from '../extends-b1af4ff7.js'; import { InputNumber, Form } from 'antd'; import 'moment'; import DatePicker from '../datePicker'; import Checkbox from '../checkbox'; import Radio from '../radio'; import Input from '../input'; import Select from '../antdSelect'; import DateRangeMonthPicker from '../dateRangeMonthPicker'; import DateRangeDatePicker from '../dateRangeDatePicker'; import Icon from '../icon'; import Message from '../message'; import isequal from 'lodash.isequal'; import Select$1 from '../select'; import '../_commonjsHelpers-471920d6.js'; import '../unsupportedIterableToArray-01f9082a.js'; var antdFormItem = { Input: Input, Select: Select, DatePicker: DatePicker, Checkbox: Checkbox, Radio: Radio, InputNumber: InputNumber, DateRangeMonthPicker: DateRangeMonthPicker, DateRangeDatePicker: DateRangeDatePicker }; function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } var Option$1 = Select.Option; var FormList = /*#__PURE__*/function (_Component) { _inherits(FormList, _Component); var _super = _createSuper$2(FormList); function FormList(props) { var _this; _classCallCheck(this, FormList); _this = _super.call(this, props); _this.changeList = function (a, b) { var option = _this.state.option; option = JSON.parse(JSON.stringify(option)); var item1 = option[a]; var item2 = option[b]; option[a] = item2; option[b] = item1; return option; }; _this.moveToUp = function (key) { var option = _this.state.option; option = JSON.parse(JSON.stringify(option)); var index = option.findIndex(function (item) { return item.key == key; }); if (index == 0) { return; } var data = _this.changeList(index - 1, index); _this.setState({ option: data }); }; _this.moveToDown = function (key) { var option = _this.state.option; option = JSON.parse(JSON.stringify(option)); var index = option.findIndex(function (item) { return item.key == key; }); if (index == option.length - 1) { return; } var data = _this.changeList(index, index + 1); _this.setState({ option: data }); }; _this.checkboxChange = function (key) { var _this$state = _this.state, selectValue = _this$state.selectValue, option = _this$state.option; var pre = selectValue.length; var flag = selectValue.filter(function (item) { return item != key; }); var next = flag.length; if (pre == next) { flag.push(key); } if (flag.includes(key)) { _this.expandItem(key, true); } else { _this.setState({ expandKey: '' }); } var newOption = option.map(function (item) { if (!flag.includes(item.key)) { item.value = []; return item; } else { return item; } }); _this.setState({ selectValue: flag, option: newOption }); }; _this.expandItem = function (key, checkboxChange) { _this.setState({ expandKey: checkboxChange == true ? key : _this.state.expandKey == key ? '' : key }); }; _this.renderSelectChildren = function (data) { if (!data) { return null; } return data.map(function (item) { return /*#__PURE__*/React__default.createElement(Option$1, { key: item.value }, item.label); }); }; _this.renderList = function (data) { var _this$state2 = _this.state, selectValue = _this$state2.selectValue, expandKey = _this$state2.expandKey; return data.map(function (item) { return /*#__PURE__*/React__default.createElement("div", { className: "item-list", key: item.key }, /*#__PURE__*/React__default.createElement("div", { className: "item-list-top" }, /*#__PURE__*/React__default.createElement("div", { className: "item-list-top-title" }, /*#__PURE__*/React__default.createElement(Checkbox, { checked: selectValue.includes(item.key), onClick: function onClick() { return _this.checkboxChange(item.key); } }), /*#__PURE__*/React__default.createElement("span", null, item.name)), /*#__PURE__*/React__default.createElement("div", { className: "item-list-top-line-container", onClick: function onClick() { return _this.expandItem(item.key); } }, /*#__PURE__*/React__default.createElement("div", { className: "item-list-top-line" })), /*#__PURE__*/React__default.createElement("div", { className: "item-list-top-line-action" }, /*#__PURE__*/React__default.createElement("span", { onClick: function onClick() { return _this.expandItem(item.key); } }, /*#__PURE__*/React__default.createElement(Icon, { type: expandKey == item.key ? 'up' : 'down' })), /*#__PURE__*/React__default.createElement("span", { onClick: function onClick() { return _this.moveToUp(item.key); } }, /*#__PURE__*/React__default.createElement(Icon, { type: "arrow-up" })), /*#__PURE__*/React__default.createElement("span", { onClick: function onClick() { return _this.moveToDown(item.key); } }, /*#__PURE__*/React__default.createElement(Icon, { type: "arrow-down" })))), /*#__PURE__*/React__default.createElement("div", { className: "item-list-bottom", style: { display: "".concat(expandKey == item.key ? 'block' : 'none') } }, /*#__PURE__*/React__default.createElement(Select, { mode: "multiple", disabled: !selectValue.includes(item.key), style: { width: '100%' }, onChange: function onChange(value) { _this.iemtSelectChange(value, item.key); }, value: item.value, filterOption: function filterOption(input, option) { return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0; } }, _this.renderSelectChildren(item.children)))); }); }; _this.iemtSelectChange = function (value, key) { var option = _this.state.option; option = JSON.parse(JSON.stringify(option)); var index = option.findIndex(function (item) { return item.key == key; }); if (index == -1) { return; } option[index].value = value; _this.setState({ option: option }); }; _this.getValue = function () { var _this$state3 = _this.state, option = _this$state3.option, selectValue = _this$state3.selectValue; return { option: option, selectValue: selectValue }; }; _this.verify = function () { var selectValue = _this.state.selectValue; if (selectValue.length == 0) { Message.warn('辅助项目信息不能为空'); } return selectValue.length == 0 ? false : true; }; _this.state = { option: props.assistFormOption ? props.assistFormOption : [], selectValue: props.assistFormSelectValue ? props.assistFormSelectValue : [], expandKey: '' }; return _this; } _createClass(FormList, [{ key: "shouldComponentUpdate", value: function shouldComponentUpdate(nextProps, nextState) { return !isequal(nextProps.assistFormOption, this.props.assistFormOption) || !isequal(nextProps.assistFormSelectValue, this.props.assistFormSelectValue) || !isequal(nextState, this.state); } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { var state = this.state; if (!isequal(nextProps.assistFormOption, this.props.assistFormOption) || !isequal(nextProps.assistFormSelectValue, this.props.assistFormSelectValue)) { this.setState({ option: nextProps.assistFormOption ? nextProps.assistFormOption : state.option, selectValue: nextProps.assistFormSelectValue ? nextProps.assistFormSelectValue : state.selectValue }); } } }, { key: "render", value: function render() { var option = this.state.option; var _this$props = this.props, className = _this$props.className, style = _this$props.style; return /*#__PURE__*/React__default.createElement("div", { className: "FormList ".concat(className ? className : ''), style: style }, this.renderList(option)); } }]); return FormList; }(Component); function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } var Option = Select$1.Option; var FormItem = Form.Item; var SearchForm = /*#__PURE__*/function (_PureComponent) { _inherits(SearchForm, _PureComponent); var _super = _createSuper$1(SearchForm); function SearchForm(props) { var _this; _classCallCheck(this, SearchForm); _this = _super.call(this, props); _this.renderChildOption = function (type, option) { if (!option) { return null; } return option.map(function (item) { return /*#__PURE__*/React__default.createElement(type, item, /*#__PURE__*/React__default.createElement("span", { title: item.label }, item.label)); }); }; _this.renderCellContent = function (accountingSubjectOptions) { var res = []; if (!accountingSubjectOptions) { return res; } res = accountingSubjectOptions.map(function (item) { return /*#__PURE__*/React__default.createElement(Option, { key: item.id // className="app-proof-of-charge-form-details-account" , value: item.code // keyRandom={keyRandom} , title: item.codeAndName }, item.codeAndName); }); return res; }; _this.renderOption = function (type, data, childType, option) { if (data && data.props && data.props.accountingSubjectFlag) { return data; } else { var arr = type.split('.'); if (!childType) { if (arr.length == 1) { return /*#__PURE__*/React__default.createElement(antdFormItem[type], data); } else { return /*#__PURE__*/React__default.createElement(antdFormItem[arr[0]][arr[1]], data); } } else { if (arr.length == 1) { return /*#__PURE__*/React__default.createElement(antdFormItem[type], data, _this.renderChildOption(antdFormItem[type][childType], option)); } else { return /*#__PURE__*/React__default.createElement(antdFormItem[arr[0]][arr[1]], data, _this.renderChildOption(antdFormItem[type][childType], option)); } } } }; _this.needToBroadcast = function (key, value) { if (_this.props.onChange) { _this.props.onChange(key, value); } }; _this.renderProofFlag = function (data) { var name = data.key ? data.key.split('.')[data.key.split('.').length - 1] : data.props.key; var values = _this.props.values; var getFieldDecorator = _this.props.form.getFieldDecorator; var more = {}; var label = data.props.label; data.onChange = function (value) { _this.needToBroadcast(name, value); }; // data.onMouseEnter = data.props.onMouseEnter return /*#__PURE__*/React__default.createElement("div", { className: "select_proofFlag", onMouseEnter: data.props ? data.props.onMouseEnter(values) : '' }, /*#__PURE__*/React__default.createElement(FormItem, { label: /*#__PURE__*/React__default.createElement("span", null, label) }, getFieldDecorator(name, _objectSpread$1({ initialValue: values ? values[name] : '' }, more))(data.render ? data.render(data) : _this.renderOption(data.type, data, data.childType, data.option)))); }; _this.renderAssetFlag = function (data) { var name = data.key ? data.key.split('.')[data.key.split('.').length - 1] : data.props.key; var values = _this.props.values; var getFieldDecorator = _this.props.form.getFieldDecorator; var more = {}; var label = data.props.label; data.onChange = function (value) { _this.needToBroadcast(name, value); }; // data.onMouseEnter = data.props.onMouseEnter return /*#__PURE__*/React__default.createElement("div", { className: "select_assetFlag" }, /*#__PURE__*/React__default.createElement(FormItem, { label: /*#__PURE__*/React__default.createElement("span", null, label) }, getFieldDecorator(name, _objectSpread$1({ initialValue: values ? values[name] : '' }, more))(data.render ? data.render(data) : _this.renderOption(data.type, data, data.childType, data.option)))); }; _this.treeSelect = function (data) { var name = data.key ? data.key.split('.')[data.key.split('.').length - 1] : data.props.key; var values = _this.props.values; var getFieldDecorator = _this.props.form.getFieldDecorator; var more = {}; var label = data.props.label; data.onChange = function (value) { _this.needToBroadcast(name, value); }; // data.onChange = (value) => { data.props.onChange(value) } return /*#__PURE__*/React__default.createElement("div", { className: "select_proofFlag gaojichanxun-treeSelect", style: { width: '50%' }, onMouseEnter: data.props ? data.props.onMouseEnter(values) : '' }, /*#__PURE__*/React__default.createElement(FormItem, { label: /*#__PURE__*/React__default.createElement("span", { style: { marginRight: '-9px' } }, label) }, getFieldDecorator(name, _objectSpread$1({ initialValue: values ? values[name] : '' }, more))(data.render ? data.render(data) : _this.renderOption(data.type, data, data.childType, data.option)))); }; _this.renderRange = function (data) { var name = data.name, type = data.type, pre = data.pre, next = data.next, label = data.label, centerContent = data.centerContent; data.isTime; var values = _this.props.values; var getFieldDecorator = _this.props.form.getFieldDecorator; var more = type == 'Checkbox' ? { valuePropName: 'checked' } : {}; var nextMore = next.rules ? { rules: next.rules } : {}; var preMore = pre.rules ? { rules: pre.rules } : {}; var pre_name = pre.name ? pre.name : "".concat(name, "_start"); var next_name = next.name ? next.name : "".concat(name, "_end"); if (next.decoratorDate) { next.disabledDate = function (currentDate) { return next.decoratorDate(currentDate, values[pre_name]); }; next.onChange = function (value) { _this.needToBroadcast(next_name, value); }; pre.onChange = function (value) { _this.needToBroadcast(pre_name, value); }; pre.disabledDate = function (currentDate) { return pre.decoratorDate(currentDate, values[next_name]); }; } if (next.props && next.props.accountingSubjectFlag) { next_name = next.key.split('.')[next.key.split('.').length - 1]; pre_name = pre.key.split('.')[pre.key.split('.').length - 1]; next.onChange = function (value) { _this.needToBroadcast(next_name, value); }; pre.onChange = function (value) { _this.needToBroadcast(pre_name, value); }; return /*#__PURE__*/React__default.createElement("div", { className: "select_range", onMouseEnter: pre.props ? pre.props.onMouseEnter(values) : '' }, /*#__PURE__*/React__default.createElement("div", { className: "select_range_label", style: { width: '20%', paddingRight: '3px' } }, label), /*#__PURE__*/React__default.createElement(FormItem, null, getFieldDecorator(pre_name, _objectSpread$1(_objectSpread$1({ initialValue: values ? values[pre_name] : '' }, more), preMore))(pre.render ? pre.render(pre) : _this.renderOption(pre_name, pre, pre.childType, pre.option))), /*#__PURE__*/React__default.createElement("div", { className: "select_range_content" }, centerContent), /*#__PURE__*/React__default.createElement(FormItem, null, getFieldDecorator(next_name, _objectSpread$1(_objectSpread$1({ initialValue: values ? values[next_name] : '' }, more), nextMore))( // <div onChange={(value) => { this.needToBroadcast(next_name, value) }} onMouseEnter={next.props?next.props.onMouseEnter:''}> next.render ? next.render(next) : _this.renderOption(next_name, next, next.childType, next.option)))); } else { return /*#__PURE__*/React__default.createElement("div", { className: "select_range" }, /*#__PURE__*/React__default.createElement("div", { className: "select_range_label" }, label), /*#__PURE__*/React__default.createElement(FormItem, null, getFieldDecorator(pre_name, _objectSpread$1(_objectSpread$1({ initialValue: values ? values[pre_name] : '' }, more), preMore))(pre.render ? pre.render(pre) : _this.renderOption(pre.type, pre, pre.childType, pre.option))), /*#__PURE__*/React__default.createElement("div", { className: "select_range_content" }, centerContent), /*#__PURE__*/React__default.createElement(FormItem, null, getFieldDecorator(next_name, _objectSpread$1(_objectSpread$1({ initialValue: values ? values[next_name] : '' }, more), nextMore))(next.render ? next.render(next) : _this.renderOption(next.type, next, next.childType, next.option)))); } }; _this.renderItem = function () { var _this$props = _this.props, item = _this$props.item, values = _this$props.values; var getFieldDecorator = _this.props.form.getFieldDecorator; var allDom = []; var itemDom = []; item = item.filter(function (o) { return o._visible !== false; }); item.forEach(function (data, index) { var name = data.name, range = data.range, label = data.label, type = data.type; data.className; var render = data.render; data.children; var option = data.option, childType = data.childType; data._visible; //if(_visible===false)return if (range) { itemDom.push(_this.renderRange(data)); } else if (data.props && data.props.treeSelect) { if (data.props.isvisible) { itemDom.push(_this.treeSelect(data)); } } else if (data.props && data.props.proofFlag) { itemDom.push(_this.renderProofFlag(data)); } else if (data.props && data.props.assetFlag) { itemDom.push(_this.renderAssetFlag(data)); } else if (type == 'AssistForm') { if (itemDom.length > 0) { allDom.push( /*#__PURE__*/React__default.createElement("div", { className: "mk_search_row" }, itemDom, index == item.length - 1 && item.length % 2 != 0 ? /*#__PURE__*/React__default.createElement(FormItem, null) : null)); itemDom = []; } allDom.push( /*#__PURE__*/React__default.createElement(FormList, _extends({ ref: function ref(form) { return _this.props.target.assistForm = form; } }, data))); return; } else { var more = type == 'Checkbox' ? { valuePropName: 'checked' } : {}; itemDom.push( /*#__PURE__*/React__default.createElement(FormItem, { label: /*#__PURE__*/React__default.createElement("span", null, label) }, getFieldDecorator(name, _objectSpread$1({ initialValue: values ? values[name] : '' }, more))(render ? render(data) : _this.renderOption(type, data, childType, option)))); } if (itemDom.length == 2 || index == item.length - 1) { allDom.push( /*#__PURE__*/React__default.createElement("div", { className: "mk_search_row" }, itemDom, index == item.length - 1 && item.length % 2 != 0 ? /*#__PURE__*/React__default.createElement(FormItem, null) : null)); itemDom = []; } }); return allDom; }; _this.state = {}; return _this; } _createClass(SearchForm, [{ key: "render", value: function render() { this.props.form.getFieldDecorator; this.props.data; return /*#__PURE__*/React__default.createElement(Form, null, this.renderItem()); } }]); return SearchForm; }(PureComponent); var SearchForm$1 = Form.create()(SearchForm); var renderOption = function renderOption(type, data, childType, target) { if (type.includes('RangePicker')) { data.onPanelChange = function (e) { target.normalSearchChange(data.name, e, 'time'); }; data.className = "".concat(data.className, " ").concat(target.datePickerRandom); var DatePickerOpen = target.state.DatePickerOpen; data.renderExtraFooter = function () { return /*#__PURE__*/React__default.createElement(Button, { type: "primary", style: { float: 'right' }, size: "small", onClick: target.normalSelectDate }, "\u786E\u5B9A"); }; data.open = DatePickerOpen; } else if (type == 'Input') { data.onChange = function (e) { target.normalSearchChange(data.name, e, 'e'); }; } else if (type == 'DateRangeMonthPicker' || type == 'DateRangeDatePicker') { if (!data.onChange) { data.onChange = function (e) { target.normalSearchChange(data.name, e, 'time', true); }; } } else { data.onChange = function (e) { target.normalSearchChange(data.name, e, 'value'); }; } var arr = type.split('.'); if (!childType) { if (arr.length == 1) { return /*#__PURE__*/React__default.createElement(antdFormItem[type], data); } else { return /*#__PURE__*/React__default.createElement(antdFormItem[arr[0]][arr[1]], data); } } else { if (arr.length == 1) { return /*#__PURE__*/React__default.createElement(antdFormItem[type], data); } else { return /*#__PURE__*/React__default.createElement(antdFormItem[arr[0]][arr[1]], data); } } }; function normalSearch(data, target) { return renderOption(data.type, data, data.childType, target); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } var SearchComponent = /*#__PURE__*/function (_PureComponent) { _inherits(SearchComponent, _PureComponent); var _super = _createSuper(SearchComponent); function SearchComponent(props) { var _this2; _classCallCheck(this, SearchComponent); _this2 = _super.call(this, props); _this2.state = { data: Map({ initMeta: '', initData: '', className: '', visible: false, displayText: '', childVisible: false }) }; _this2.dateWindowChange = function (type, status, key) { if (type == 'next') { _this2.setState(_defineProperty({}, key, status)); } }; _this2.showPickerDidMount = function () { var normalSearch = _this2.props.normalSearch; if (!normalSearch || normalSearch.length == 0) { return; } var flag = normalSearch.find(function (item) { return item.type == 'DatePicker.RangePicker'; }); if (!flag) { return; } var dateDom = document.getElementsByClassName(_this2.datePickerRandom)[0]; if (!dateDom) { setTimeout(function () { _this2.showPickerDidMount(); }, 50); return; } dateDom.addEventListener('click', _this2.rangePickerClick, false); }; _this2.showMoreSearch = function (bol) { var _this2$state = _this2.state, data = _this2$state.data; _this2$state.count; data = _this2.set(null, { childVisible: bol }); // TTK-18160 if (bol) { var dom = document.querySelector('.mk-search-high-search'); if (dom && _toConsumableArray(dom.classList).indexOf('slideOutUp') > -1) { dom.style.display = 'block'; } _this2.showThis = true; } _this2.props.queryAccountSubjects && _this2.props.queryAccountSubjects(); _this2.setState({ data: data, count: 1 }); }; _this2.confirmClick = function () { var _this2$props = _this2.props, searchClick = _this2$props.searchClick, moreSearchRules = _this2$props.moreSearchRules; var _this = _assertThisInitialized(_this2); _this2.form.validateFields(function (err, values) { if (err) { return; } var flag = true; var option; if (_this.props.moreSearchItem.findIndex(function (item) { return item.type == 'AssistForm'; }) > -1) { flag = _this.assistForm.verify(); if (flag) { var getValue = _this.assistForm.getValue(); values.groupStr = _this2.sortAssitItem(getValue.option, getValue.selectValue); values.whereStr = _this.getWhereStr(getValue.option, getValue.selectValue); option = getValue; } } if (moreSearchRules) { flag = moreSearchRules(values, _this.form); } if (!flag) { return; } _this.showMoreSearch(false); _this2.showThis = false; if (searchClick) { setTimeout(function () { if (_this.props.moreSearchItem.findIndex(function (item) { return item.type == 'AssistForm'; }) > -1) { searchClick(values, option); } else { searchClick(values); } }, 800); } }); }; _this2.sortAssitItem = function (data, selectValue) { var arr = []; data.forEach(function (item) { if (selectValue.includes(item.key)) { arr.push(item.key); } }); return arr.join(','); }; _this2.getWhereStr = function (option, selectLabel) { var arr = []; option.forEach(function (item) { if (item.value && item.value.length > 0 && selectLabel.includes(item.key)) { arr.push("".concat(item.key, ":").concat(item.value.join(','))); } }); return arr.join(';'); }; _this2.cancelClick = function () { var cancelClick = _this2.props.cancelClick; _this2.showMoreSearch(false); _this2.showThis = false; _this2.setState({ searchValue: clonedeep(_this2.props.moreSearch), key: Math.random() }); if (cancelClick) { setTimeout(function () { cancelClick(clonedeep(_this2.props.moreSearch)); }, 800); } cancelClick && cancelClick(); }; _this2.clearClick = function () { var clearClick = _this2.props.clearClick; var value = _this2.clearValue('clear'); clearClick && clearClick(value); }; _this2.clearValue = function (status) { var searchValue = _this2.state.searchValue; var _this2$props2 = _this2.props; _this2$props2.clearClick; var moreSearchItem = _this2$props2.moreSearchItem; var clearValue = {}; moreSearchItem.forEach(function (item) { if (item.range) { if (!item.pre.noClear) { clearValue[item.pre.name] = null; } if (!item.next.noClear) { clearValue[item.next.name] = null; } } else if (!item.noClear) { if (item.props && item.props.accountingSubjectFlag) { var name = item.key ? item.key.split('.')[item.key.split('.').length - 1] : item.props.key; clearValue[name] = item.props && item.props.multipleSelect ? undefined : null; } else { clearValue[item.name] = null; } // if (status == 'clear' && item.allowClear) item.allowClear = false } }); _this2.setState({ searchValue: _objectSpread(_objectSpread({}, searchValue), clearValue), key: Math.random() }); return _objectSpread(_objectSpread({}, searchValue), clearValue); }; _this2.normalSearchChange = function (name, e, type, bol) { var normalSearch = _this2.state.normalSearch; var value = e && e.target ? e.target.value : e; normalSearch[name] = value; _this2.setState({ normalSearch: normalSearch }); if (name == 'date' && !bol) { // if (this.state.normalSearch[name] == value && this.props.normalSearchChange) { // let initValue = this.clearValue() // this.props.normalSearchChange(name, value, initValue, type) // } return; } var normalSearchMeta = _this2.props.normalSearch; var isImmediatelyChange; // 检查查询组件的属性,代表值变更时是否立即执行简单查询(false:不执行,undefined和true:立即执行) for (var i = 0; i < normalSearchMeta.length; i++) { if (normalSearchMeta[i].name == name) { isImmediatelyChange = normalSearchMeta[i].isImmediatelyChange; } } // 测试说简单搜索的情况下要清空高级搜索的内容 setTimeout(function () { if (_this2.state.normalSearch[name] == value && _this2.props.normalSearchChange && isImmediatelyChange != false) { var initValue = _this2.clearValue(); _this2.props.normalSearchChange(name, value, initValue, type); } }, 1000); }; _this2.renderNormalSearch = function () { var normalSearch$1 = _this2.props.normalSearch; if (!normalSearch$1) { return null; } var normalSearchValue = _this2.state.normalSearch; return normalSearch$1.map(function (item, index) { item.key = "normal-search-item-".concat(index); item.value = normalSearchValue[item.name]; return normalSearch(item, _assertThisInitialized(_this2)); }); }; _this2.trantoNumber = function (num) { if (!num) { return 0; } try { return parseInt(num.format('YYYYMMDD')); } catch (err) { console.log(err); return 0; } }; _this2.someChange = function (key, value) { try { var searchValue = _this2.state.searchValue; searchValue[key] = value; if (_this2.state["showDateWin_".concat(key)] != undefined) { var nextKey; _this2.props.moreSearchItem.forEach(function (item) { if (item.next && item.pre && item.pre.name == key) { nextKey = item.next.name; } if (_this2.trantoNumber(value) > _this2.trantoNumber(searchValue[nextKey])) { searchValue[nextKey] = value; } }); _this2.setState(_defineProperty({}, "showDateWin_".concat(key), true)); } _this2.setState({ searchValue: searchValue }); } catch (err) { console.log(err); } }; _this2.normalSelectDate = function () { var name = 'date'; var normalSearch = _this2.state.normalSearch; var value = normalSearch.date; _this2.setState({ DatePickerOpen: false }); if (_this2.state.normalSearch[name] == value && _this2.props.normalSearchChange) { var initValue = _this2.clearValue(); _this2.props.normalSearchChange(name, value, initValue); } }; _this2.rangePickerClick = function () { _this2.setState({ DatePickerOpen: true }); }; _this2.handleAnimationEnd = function () { var dom = document.querySelector('.mk-search-high-search'); if (dom && _toConsumableArray(dom.classList).indexOf('slideOutUp') > -1) { // setTimeout(() => { dom.style.display = 'none'; // }, 1000) } }; _this2.getAbsPoint = function (e) { var x = e.offsetLeft; var y = e.offsetTop; while (e = e.offsetParent) { x += e.offsetLeft; y += e.offsetTop; } return { x: x, y: y }; }; _this2.computed = function () { var table = ReactDOM.findDOMNode(_assertThisInitialized(_this2)); if (table) { var point = _this2.getAbsPoint(table); var height = window.innerHeight - point.y; _this2.setState({ containerHeight: height - 5 }); } }; _this2.state = { data: _this2.computeState(_this2.props), visible: false, searchValue: clonedeep(props.moreSearch), key: '', height: 10000, normalSearch: props.normalSearchValue ? clonedeep(props.normalSearchValue) : {}, count: 0, containerHeight: 500 }; _this2.value = {}; _this2.datePickerRandom = Math.floor(Math.random() * 100000000); _this2.props.didMount && _this2.props.didMount(_assertThisInitialized(_this2)); _this2.props.moreSearchItem && _this2.props.moreSearchItem.map(function (item) { if (item.type == 'accountCodeTest') ; else if (item.pre && item.pre.type && item.pre.type.includes('DatePicker') && item.next && item.next.type && item.next.type.includes('DatePicker')) { _this2.state["showDateWin_".concat(item.pre.name)] = false; } }); return _this2; } _createClass(SearchComponent, [{ key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { this.setState(this.computeState(nextProps)); this.setState({ searchValue: clonedeep(nextProps.moreSearch), normalSearch: clonedeep(nextProps.normalSearchValue) }); } }, { key: "computeState", value: function computeState(props) { var data = this.state.data; var value = props.value, height = props.height, width = props.width, style = props.style, className = props.className, placement = props.placement, refName = props.refName, child = props.child, okText = props.okText, cancelText = props.cancelText, resetText = props.resetText, btnTextAlign = props.btnTextAlign, loadApp = props.loadApp; if (!Map.isMap(value) && !List.isList(value) && _typeof(value) == 'object') { value = fromJS(value); } data = data.set('value', value); data = data.set('height', height); data = data.set('width', width); data = data.set('style', style); data = data.set('className', className); data = data.set('placement', placement); data = data.set('refName', refName); data = data.set('child', child); data = data.set('okText', okText); data = data.set('cancelText', cancelText); data = data.set('resetText', resetText); data = data.set('btnTextAlign', btnTextAlign); data = data.set('loadApp', loadApp); this.oldValue = value; return data; } }, { key: "componentDidMount", value: function componentDidMount() { if (document.getElementsByClassName('mk-search-high-search') && Array.isArray(document.getElementsByClassName('mk-search-high-search'))) { this.setState({ height: document.getElementsByClassName('mk-search-high-search')[0].offsetHeight + 300 }); this.showPickerDidMount(); this.computed(); window.addEventListener('resize', this.computed, false); } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { window.removeEventListener('resize', this.computed, false); var dateDom = document.getElementsByClassName(this.datePickerRandom)[0]; if (dateDom) { dateDom.removeEventListener('click', this.rangePickerClick, false); } } }, { key: "getPopupContainer", value: function getPopupContainer() { return document.querySelector('.app-proof-of-list'); } }, { key: "get", value: function get(propertyName) { if (!propertyName || propertyName === '') { return this.state.data; } return this.state.data.getIn(propertyName.split('.')); } }, { key: "set", value: function set(propertyName, value) { var data = this.state.data; if (!propertyName || propertyName === '') { return data.merge(value); } if (_typeof(value) === 'object') { return data.mergeIn(propertyName.split('.'), value); } else { return data.setIn(propertyName.split('.'), value); } } }, { key: "render", value: function render() { var _this3 = this; var data = this.state.data.get('value') && this.state.data.get('value').get('data'); data = data && data.size ? data : fromJS(data); var _this$props = this.props, confirmBtn = _this$props.confirmBtn, cancelBtn = _this$props.cancelBtn, clearBtn = _this$props.clearBtn, refreshBtn = _this$props.refreshBtn; var containerHeight = this.state.containerHeight; var This = this; if (!this.showThis) { return /*#__PURE__*/React__default.createElement("div", { className: "retrieveWrap mk-search", style: { position: 'relative' }, onAnimationEnd: function onAnimationEnd() { return _this3.handleAnimationEnd(); } }, /*#__PURE__*/React__default.createElement("div", { className: "mk-normal-search", style: { display: 'flex', justifyContent: 'space-between' } }, /*#__PURE__*/React__default.createElement("div", { className: "mk-normal-search-left", style: { display: 'flex' } }, this.props.selectDate ? this.props.selectDate : null, this.renderNormalSearch(), this.props.normalSearcChildren ? this.props.normalSearcChildren : null, this.props.moreSearchItem ? /*#__PURE__*/React__default.createElement("span", { className: "mk-span", onClick: this.showMoreSearch.bind(this, true), style: { zIndex: '3', fontSize: '14px', display: 'flex', marginRight: '1px', flexDirection: 'column', justifyContent: 'center', width: '55px' } }, /*#__PURE__*/React__default.createElement("a", { className: "searchBtn" }, "\u9AD8\u7EA7\u67E5\u8BE2")) : null, refreshBtn, this.props.leftMenuBtn ? this.props.leftMenuBtn : null), /*#__PURE__*/React__default.createElement("div", { className: "mk-title-otherBtn" }, this.props.menuBtn))); } var moreSearchItem = this.props.moreSearchItem ? this.props.moreSearchItem.filter(function (item) { if (item.type != 'accountCodeTest' && item.pre && item.next && item.pre.type.includes('DatePicker') && item.next.type.includes('DatePicker')) { return _objectSpread(_objectSpread({}, item), {}, { next: _objectSpread(_objectSpread({}, item.next), {}, { onOpenChange: function onOpenChange(status) { return _this3.dateWindowChange('next', status, "showDateWin_".concat(item.pre.name)); }, open: _this3.state["showDateWin_".concat(item.pre.name)] }), pre: _objectSpread(_objectSpread({}, item.pre), {}, { onOpenChange: function onOpenChange(status) { return _this3.dateWindowChange('pre', status, "showDateWin_".concat(item.pre.name)); } }) }); } if (!item.visible) return item; }) : null; return /*#__PURE__*/React__default.createElement("div", { className: "retrieveWrap mk-search", style: { position: 'relative' }, onAnimationEnd: function onAnimationEnd() { return _this3.handleAnimationEnd(); } }, /*#__PURE__*/React__default.createElement("div", { className: "mk-normal-search", style: { display: 'flex', justifyContent: 'space-between' } }, /*#__PURE__*/React__default.createElement("div", { className: "mk-normal-search-left", style: { display: 'flex' } }, this.props.selectDate ? this.props.selectDate : null, this.renderNormalSearch(), this.props.normalSearcChildren ? this.props.normalSearcChildren : null, this.props.moreSearchItem ? /*#__PURE__*/React__default.createElement("span", { className: "mk-span", onClick: this.showMoreSearch.bind(this, true), style: { zIndex: '3', fontSize: '14px', display: 'flex', marginRight: '1px', flexDirection: 'column', justifyContent: 'center', width: '55px' } }, /*#__PURE__*/React__default.createElement("a", { className: "searchBtn" }, "\u9AD8\u7EA7\u67E5\u8BE2")) : null, refreshBtn, this.props.leftMenuBtn ? this.props.leftMenuBtn : null), /*#__PURE__*/React__default.createElement("div", { className: "mk-title-otherBtn" }, this.props.menuBtn)), /*#__PURE__*/React__default.createElement("div", { style: { width: '100%', height: '0', position: 'absolute', top: '0px', zIndex: '101', background: '#fff', boxShadow: '0 0 5px #999', display: "".concat(this.state.count == 1 ? 'block' : 'none') } }, /*#__PURE__*/React__default.createElement("div", { style: { width: '100%', maxHeight: "".concat(containerHeight, "px") // top: `${this.state.data.get('childVisible') ? '0' : `-${this.state.height}px`}` }, className: "mk-search-high-search ".concat(this.state.data.get('childVisible') ? '' : 'slideOutUp') }, /*#__PURE__*/React__default.createElement("h2", null, /*#__PURE__*/React__default.createElement("div", null, "\u9AD8\u7EA7\u67E5\u8BE2")), /*#__PURE__*/React__default.createElement("div", { className: "search-form-contaienr", style: { maxHeight: "".concat(containerHeight - 90, "px") } }, this.props.treeSelect ? this.props.treeSelect : null, this.props.moreSearchItem && /*#__PURE__*/React__default.createElement(SearchForm$1, { target: this, onChange: this.someChange, item: moreSearchItem, key: this.state.key, ref: function ref(form) { _this3.form = form; }, values: this.state.searchValue }), this.props.assistForm ? /*#__PURE__*/React__default.createElement(FormList, { ref: function ref(form) { return _this3.assistForm = form; }, option: this.props.assistFormOption, selectValue: this.props.assistFormSelectValue }) : null), /*#__PURE__*/React__default.createElement("div", { className: "mk-search-high-search-bottomBtn", style: { textAlign: This.get('btnTextAlign') } }, /*#__PURE__*/React__default.createElement("span", { id: "btnClick" }, cancelBtn && cancelBtn.hidden ? null : /*#__PURE__*/React__default.createElement(Button, { onClick: this.cancelClick, className: "cancel" }, cancelBtn && cancelBtn.text ? cancelBtn.text : '取消'), clearBtn && clearBtn.hidden ? null : /*#__PURE__*/React__default.createElement(Button, { onClick: this.clearClick, className: "clear_btn", style: { marginLeft: '8px' } }, clearBtn && clearBtn.text ? clearBtn.text : '清空'), confirmBtn && confirmBtn.hidden ? null : /*#__PURE__*/React__default.createElement(Button, { onClick: this.confirmClick, className: "query", type: "primary", style: { marginLeft: '8px' } }, confirmBtn && confirmBtn.text ? confirmBtn.text : '查询')))))); } }]); return SearchComponent; }(PureComponent); export { SearchComponent as default };