'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _desc, _value, _class, _class2, _temp; /* eslint-disable no-console */


var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _coreDecorators = require('core-decorators');

var _components = require('../../../components');

var _mxa = require('../../../components/mxa');

var _longRunOpt = require('../../system/longRunOpt');

var _dictCodes = require('../../constant/dictCodes');

var _util = require('./util');

var _MenuHelper = require('../../utils/MenuHelper');

var _sideMenu = require('../info/sideMenu');

var _sideMenu2 = _interopRequireDefault(_sideMenu);

var _processMenu = require('./processMenu');

var _processMenu2 = _interopRequireDefault(_processMenu);

var _dictActions = require('../../constant/dictActions');

var _toolBar = require('./toolBar');

var _toolBar2 = _interopRequireDefault(_toolBar);

var _EmptyUtils = require('../../utils/EmptyUtils');

var _StringUtils = require('../../utils/StringUtils');

var _editableCell = require('./editableCell');

var _editableCell2 = _interopRequireDefault(_editableCell);

var _JSExecutor = require('../../utils/JSExecutor');

var _ProcessHelper = require('../../utils/ProcessHelper');

var _processButtonCodes = require('../../constant/processButtonCodes');

var _SessionStorage = require('../../service/SessionStorage');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
  var desc = {};
  Object['ke' + 'ys'](descriptor).forEach(function (key) {
    desc[key] = descriptor[key];
  });
  desc.enumerable = !!desc.enumerable;
  desc.configurable = !!desc.configurable;

  if ('value' in desc || desc.initializer) {
    desc.writable = true;
  }

  desc = decorators.slice().reverse().reduce(function (desc, decorator) {
    return decorator(target, property, desc) || desc;
  }, desc);

  if (context && desc.initializer !== void 0) {
    desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
    desc.initializer = undefined;
  }

  if (desc.initializer === void 0) {
    Object['define' + 'Property'](target, property, desc);
    desc = null;
  }

  return desc;
}

var ListView = (_class = (_temp = _class2 = function (_React$Component) {
  _inherits(ListView, _React$Component);

  function ListView(props) {
    _classCallCheck(this, ListView);

    // initial state
    var _this = _possibleConstructorReturn(this, (ListView.__proto__ || Object.getPrototypeOf(ListView)).call(this, props));

    _this._getRowSaveActionName = function () {
      if (_this.state.buttons.row && _this.state.buttons.row.length > 0) {
        return _this.state.buttons.row[0].actionLink;
      }
      return null;
    };

    var _this$props = _this.props,
        domainLink = _this$props.domainLink,
        dataSource = _this$props.dataSource,
        readonly = _this$props.readonly;

    _this.refStr = 'table-' + new Date().getTime();
    _this.isApply = (0, _ProcessHelper.isApply)(domainLink);
    _this.isReview = (0, _ProcessHelper.isReview)(domainLink);
    _this.contentList = dataSource.pageResult.contentList || [];
    var initState = { readonly: _this.dealReadonly(readonly, dataSource) };
    _this.state = _this._processData(_this.props.dataSource, initState);
    window.scrollTo(0, 0);
    return _this;
  }

  _createClass(ListView, [{
    key: 'dealReadonly',
    value: function dealReadonly(readonly, dataSource) {
      // TODO 后面要用privilegeType = COMMON 来处理
      if (readonly === 'true' || readonly === true || dataSource.readOnly) {
        var buttons = dataSource.buttons.filter(function (item) {
          return item.privilegeType !== 'EDIT';
        });
        this.props.dataSource.buttons = buttons;
        return true;
      }
      return false;
    }
  }, {
    key: '_renderColumnAction',
    value: function _renderColumnAction(text, record, buttons, mainEntityKey) {
      var _this2 = this;

      var _props = this.props,
          prefixCls = _props.prefixCls,
          query = _props.query,
          inject = _props.inject;

      var toolbarClassName = prefixCls + '-inline-toolbar';
      var buttonClassName = prefixCls + '-inline-button';
      return _react2.default.createElement(
        'div',
        { key: 'inline-operation', className: toolbarClassName },
        buttons.map(function (item, index) {
          return _react2.default.createElement(_components.ExtendButton, _extends({}, item, {
            inline: true,
            key: index,
            mainEntityKey: mainEntityKey,
            record: record,
            inject: inject,
            className: buttonClassName,
            query: query,
            onRefresh: _this2._onSearch
          }));
        })
      );
    }
  }, {
    key: 'onCellChange',
    value: function onCellChange(record, name, editType) {
      var _this3 = this;

      return function (value) {
        // console.log('mainEntityKey:', this.state.mainEntityKey);
        console.log('record', record);
        console.log('name: ', name, ' value: ', value);
        var link = _this3._getRowSaveActionName();
        if (!link && editType !== 'GLOBAL') {
          console.error('row save link is null');
          return null;
        }
        // TODO: save api
        if (editType === 'GLOBAL') {
          _this3.changeLocalData(record, name, value);
        } else {
          _this3.props.exec(function () {
            return _this3.props.fetch(link, _extends({}, record, _defineProperty({}, name, value))).then(function (response) {
              console.log('result: ', response);
            });
          }).then(function () {
            _this3.changeLocalData(record, name, value);
          });
        }
        return true;
      };
    }
  }, {
    key: 'changeLocalData',
    value: function changeLocalData(record, name, value) {
      var _this4 = this;

      var dataSource = this.state.dataSource.map(function (item) {
        if (item[_this4.state.mainEntityKey] === record[_this4.state.mainEntityKey]) {
          return _extends({}, item, _defineProperty({}, name, value));
        }
        return item;
      });
      // 修改本地
      this.setState({ dataSource: dataSource });
    }
  }, {
    key: '_renderColumn',
    value: function _renderColumn(text, fieldContent, record) {
      var temp = (0, _util.renderColumn)(text, fieldContent, record);
      var tdRender = _react2.default.createElement(
        'span',
        null,
        temp
      );
      // if (typeof temp === 'string' && temp.length > 18) {
      //   tdRender = (
      //     <Tooltip title={temp} placement="top">
      //       <span>{temp.substring(0, 16) + '...'}</span>
      //     </Tooltip>
      //   );
      // }
      return tdRender;
    }
  }, {
    key: '_filterProcessButton',
    value: function _filterProcessButton(datas, menuCode) {
      var dataButtons = datas;
      if (dataButtons[0].name) {
        dataButtons = dataButtons.filter(function (item) {
          return _processButtonCodes.ProcessButtonCodes[menuCode].indexOf(item.name) !== -1;
        });
      }
      var buttons = { row: [], top: [] };
      if (dataButtons) {
        buttons.row = dataButtons.filter(function (item) {
          return item.displayPosition === _dictCodes.BUTTON_POSITION.ROW;
        });
        buttons.top = dataButtons.filter(function (item) {
          return item.displayPosition === _dictCodes.BUTTON_POSITION.TOP;
        });
        buttons.hidden = dataButtons.filter(function (item) {
          return item.displayPosition === _dictCodes.BUTTON_POSITION.HIDDEN;
        });
      }
      return buttons;
    }
  }, {
    key: '_processData',
    value: function _processData(data, initState) {
      var _this5 = this;

      var _props2 = this.props,
          query = _props2.query,
          params = _props2.params;

      var variantFields = Object.assign({}, query, params);
      var dataButtons = data.buttons;
      var buttons = {};
      if ((this.isApply || this.isReview) && !variantFields.menu) {
        if (this.isApply) {
          variantFields.menu = 'BPMApply.QueryToDo';
          (0, _SessionStorage.saveProcessMenuCode)('BPMApply.QueryToDo');
        } else if (this.isReview) {
          variantFields.menu = 'BPMReview.QueryToDo';
          (0, _SessionStorage.saveProcessMenuCode)('BPMReview.QueryToDo');
        }
        buttons = this._filterProcessButton(dataButtons, variantFields.menu);
      } else {
        buttons = { row: [], top: [] };
        if (dataButtons) {
          buttons.row = dataButtons.filter(function (item) {
            return item.displayPosition === _dictCodes.BUTTON_POSITION.ROW;
          });
          buttons.top = dataButtons.filter(function (item) {
            return item.displayPosition === _dictCodes.BUTTON_POSITION.TOP;
          });
        }
      }
      // const orderItems = handleOrderItems(data.orderItems);
      var ordered = data.orderItems && data.orderItems.length > 0;
      var mainEntityKey = '';
      var columns = [];
      data.fields && data.fields.sort(function (a, b) {
        return a.index - b.index;
      }).forEach(function (item, index) {
        if (item.isMainEntityKey) mainEntityKey = item.name;
        if (_this5.dealIsVisibleField(item.isVisible)) {
          columns.push({
            width: (item.displayColumnLength || 18) * 12,
            key: index,
            title: item.description,
            dataIndex: item.name,
            // sorter: !!orderItems[item.name],
            render: function render(text, record) {
              var fieldContent = _this5.state.fieldsObject[item.name];
              if (item.editable && !_this5.state.readonly) {
                return _react2.default.createElement(_editableCell2.default, {
                  value: text,
                  renderColumn: _this5._renderColumn,
                  getCurrentRecord: function getCurrentRecord() {
                    return _this5.state.dataSource.find(function (element) {
                      return element[_this5.state.mainEntityKey] === record[_this5.state.mainEntityKey];
                    });
                  },
                  onChange: _this5.onCellChange(record, item.name, _this5.props.dataSource.editType),
                  fieldContent: fieldContent
                });
              }
              return _this5._renderColumn(text, fieldContent, record);
            }
          });
        }
      });

      // fix first column
      // if (columns.length > 0) {
      //   columns[0].fixed = true;
      // }

      // add operation
      if (buttons && buttons.row && buttons.row.length > 0) {
        columns.push({
          key: 'inline-operation',
          title: '操作',
          dataIndex: 'inline-operation',
          // fixed: 'right',
          // width: 300,
          render: function render(text, record) {
            return _this5._renderColumnAction(text, record, buttons.row, mainEntityKey);
          }
        });
      }

      var pageIndex = data && data.pageResult && data.pageResult.pageIndex;
      var itemsPerPage = data && data.pageResult && data.pageResult.itemsPerPage;
      var pagination = {
        total: data && data.pageResult && data.pageResult.totalItems,
        pageSize: itemsPerPage,
        showSizeChanger: false,
        showQuickJumper: true,
        showTotal: function showTotal(total) {
          return '\u5171 ' + total + ' \u9879';
        }
      };

      var fieldsObject = (0, _util.arr2obj)(data.fields, 'name');
      var filters = (0, _util.handleFilterItems)(data.filterItems, fieldsObject);
      var dataSource = this.addKeyForDataSource(data, itemsPerPage);

      var selectedType = data.selectType;
      // const selectedType = this.props.isModal ? LIST_SELECTTYPE.RADIO : data.selectType;
      var selectedRowKeys = [];
      var selectedRows = [];
      dataSource.filter(function (item) {
        return item.isSelected === 'Y';
      }).forEach(function (selectedRow) {
        selectedRowKeys.push(selectedRow[mainEntityKey]);
        selectedRows.push(selectedRow);
      });
      return _extends({}, initState, {
        columns: columns,
        dataSource: dataSource,
        buttons: buttons,
        pagination: pagination,
        fieldsObject: fieldsObject,
        filters: filters,
        pageIndex: pageIndex,
        itemsPerPage: itemsPerPage,
        requestFilterFields: [],
        variantFields: variantFields,
        ordered: ordered,
        orderFields: [],
        mainEntityKey: mainEntityKey,
        selectedType: selectedType,
        selectedRowKeys: selectedRowKeys,
        selectedRows: selectedRows,
        advancedSearch: null,
        isAdvance: false, // 查询模式
        y: null, // 控制表格头部fix
        menuTaskCount: this.props.dataSource.pageResult && this.props.dataSource.pageResult.menuTaskCount
      });
    }
  }, {
    key: 'addKeyForDataSource',
    value: function addKeyForDataSource(data, itemsPerPage) {
      return data.pageResult.contentList && data.pageResult.contentList.map(function (r, key) {
        return _extends({ key: key + '-' + itemsPerPage }, r);
      }) || [];
    }
  }, {
    key: 'dealIsVisibleField',
    value: function dealIsVisibleField(isVisible) {
      if (isVisible === 'true') {
        return true;
      } else if (isVisible === 'false') {
        return false;
      } else if (isVisible && isVisible !== false && isVisible !== true) {
        return (0, _JSExecutor.createFunc)(isVisible)();
      }
      return isVisible;
    }
  }, {
    key: '_onFilterChange',
    value: function _onFilterChange(value, isAdvance) {
      console.log('_onFilterChange ' + value);
      this.state.requestFilterFields = value;
      this.state.isAdvance = !!isAdvance;
      this.state.pageIndex = 1;
      this._onSearch();
    }
  }, {
    key: '_onChange',
    value: function _onChange(pagination, filters, sorter, isKeepSelectedKeys) {
      var _this6 = this;

      console.log('params', pagination, filters, sorter);
      if (this.state.ordered && !(0, _EmptyUtils.isEmpty)(sorter)) {
        var orderFields = [];
        orderFields.push({
          orderField: sorter.field,
          orderType: sorter.order === 'descend' ? 'DESC' : 'ASC'
        });

        this.setState({
          pageIndex: pagination.current,
          itemsPerPage: pagination.pageSize,
          orderFields: orderFields
        }, function () {
          _this6._onSearch(isKeepSelectedKeys);
        });
      } else {
        this.setState({
          pageIndex: pagination.current,
          itemsPerPage: pagination.pageSize
          // orderFields,
        }, function () {
          _this6._onSearch(isKeepSelectedKeys);
        });
      }
    }

    // isKeepSelectedKeys may be true or object

  }, {
    key: '_onSearch',
    value: function _onSearch(isKeepSelectedKeys, isFromAddOrReduce) {
      var _this7 = this;

      console.log('***-----LIST REFRESH-----***');
      var searchUrl = (0, _StringUtils.trimStart)(this.props.domainLink.replace(/^(.*\/)render(\w*)$/, '$1search$2'), '/');
      var param = {
        pageIndex: this.state.pageIndex,
        itemsPerPage: this.state.itemsPerPage,
        requestParamsBean: Object.assign({}, this.state.variantFields, this.state.requestParamsBean), // issue #5
        requestFilterFields: this.state.requestFilterFields,
        requestOrderFields: this.state.orderFields,
        isAdvance: this.state.isAdvance
      };
      this.props.exec(function () {
        return _this7.props.fetch(searchUrl, param).then(function (data) {
          if (data.contentList && data.contentList.length === 0 && _this7.state.pageIndex > 1) {
            // TODO: will not render;
            _this7.state.pageIndex = _this7.state.pageIndex - 1;
            param.pageIndex = _this7.state.pageIndex;
            return _this7.props.fetch(searchUrl, param);
          }
          return data;
        }).then(function (data) {
          var dataSource = data.contentList && data.contentList.map(function (r, key) {
            return _extends({ key: key + '-' + _this7.state.pageIndex + '-' + r[_this7.state.mainEntityKey] }, r);
          }) || [];
          _this7.contentList = data.contentList || [];
          var pagination = {
            current: _this7.state.pageIndex,
            total: data && data.totalItems,
            pageSize: data.itemsPerPage,
            showSizeChanger: false,
            showQuickJumper: true,
            showTotal: function showTotal(total) {
              return '\u5171 ' + total + ' \u9879';
            }
          };
          var selectedRowKeys = [];
          var selectedRows = [];
          dataSource.filter(function (item) {
            return item.isSelected === 'Y';
          }).forEach(function (selectedRow) {
            selectedRowKeys.push(selectedRow[_this7.state.mainEntityKey]);
            selectedRows.push(selectedRow);
          });
          _this7.setState({
            dataSource: dataSource,
            pagination: pagination,
            selectedRowKeys: selectedRowKeys,
            selectedRows: selectedRows,
            menuTaskCount: _this7.dealMenuTaskCount(isFromAddOrReduce)
          });
        });
      });
    }
  }, {
    key: 'dealMenuTaskCount',
    value: function dealMenuTaskCount(isFromAddOrReduce) {
      var menuTaskCount = this.state.menuTaskCount;
      if (isFromAddOrReduce) {
        if (isFromAddOrReduce === 'add') {
          menuTaskCount[this.tag.menuCode] = menuTaskCount[this.tag.menuCode] + 1;
        } else {
          menuTaskCount[this.tag.menuCode] = menuTaskCount[this.tag.menuCode] - 1;
        }
      }
      return menuTaskCount;
    }
  }, {
    key: '_getRelatedState',
    value: function _getRelatedState(item) {
      if (item.relatedData === _dictCodes.BUTTON_RELATEDDATA.SINGLE) {
        if (this.state.selectedRowKeys.length !== 1) {
          return true;
        }
        var relatedItems = item.relatedItems && item.relatedItems.relatedItemList || [];
        var prolog = item.relatedItems && item.relatedItems.prolog;
        if (prolog === 'AND') {
          return relatedItems.some(this.relatedItemsCallback);
        }
        if (prolog === 'OR') {
          return relatedItems.every(this.relatedItemsCallback);
        }
      }
      if (item.relatedData === _dictCodes.BUTTON_RELATEDDATA.MULTIPLE && this.state.selectedRowKeys.length < 1) {
        return true;
      }
      return false;
    }
  }, {
    key: 'relatedItemsCallback',
    value: function relatedItemsCallback(i) {
      if (i.operator === 'greaterThan') {
        return this.state.selectedRows[0][i.relatedKey] <= i.relatedValue;
      } else if (i.operator === 'lessThan') {
        return this.state.selectedRows[0][i.relatedKey] >= i.relatedValue;
      } else if (i.operator === 'greaterOrEqual') {
        return this.state.selectedRows[0][i.relatedKey] < i.relatedValue;
      } else if (i.operator === 'lessOrEqual') {
        return this.state.selectedRows[0][i.relatedKey] > i.relatedValue;
      } else if (i.operator === 'noEqual') {
        return this.state.selectedRows[0][i.relatedKey] === i.relatedValue;
      } else if (i.operator === 'isNull') {
        return !this.state.selectedRows[0][i.relatedKey];
      }
      return this.state.selectedRows[0][i.relatedKey] !== i.relatedValue;
    }
  }, {
    key: '_renderTopButtons',
    value: function _renderTopButtons(filter) {
      var _this8 = this;

      var _props3 = this.props,
          prefixCls = _props3.prefixCls,
          query = _props3.query,
          inject = _props3.inject;

      var buttonClass = prefixCls + '-button';

      var btnJsonObject = this.state.buttons && this.state.buttons.top && this.state.buttons.top;
      if (filter) {
        btnJsonObject = btnJsonObject.filter(filter);
      }
      var btns = btnJsonObject.map(function (item) {
        var ButtonComp = _components.ExtendButton;
        if (_this8.props.renderButtonsSelf) {
          var myBtn = _this8.props.renderButtonsSelf(item, _this8.props);
          if (myBtn) {
            ButtonComp = myBtn;
          }
        }
        /* eslint-disable */
        return _react2.default.createElement(ButtonComp, _extends({
          inline: false,
          buttonProps: {
            type: 'ghost'
          }
        }, item, {
          disabled: _this8._getRelatedState(item),
          key: item.buttonDescription,
          mainEntityKey: _this8.state.mainEntityKey,
          selectedType: _this8.state.selectedType,
          record: _this8.props.dataSource.editType === 'GLOBAL' ? _this8.state.dataSource : _this8.state.variantFields.menu ? _this8.state.selectedRows.map(function (item1) {
            return Object.assign(item1, { menuCode: _this8.state.variantFields.menu });
          }) : _this8.state.selectedRows,
          className: buttonClass,
          query: query,
          inject: inject,
          isModal: _this8.props.isModal,
          modalCallback: _this8.props.modalCallback,
          onRefresh: function onRefresh() {
            return _this8.buttonClickOnRefresh(item);
          },
          clickCallback: function clickCallback() {
            item.relatedData !== _dictCodes.BUTTON_BINDPARAMETERTYPE.NONE && _this8.refs['toolbar']._switchToolBar();
          },
          refreshCallback: _this8.props.refreshCallback,
          readonly: _this8.state.readonly
        }));
      });
      if (this.props.createTopButtons) {
        this.props.createTopButtons(btns);
        return _react2.default.createElement('div', null);
      }
      return btns;
    }
  }, {
    key: 'buttonClickOnRefresh',
    value: function buttonClickOnRefresh(item) {
      if (item.name === 'PROCESS_APPLY_ADD') {
        this._onSearch(true, 'add');
      } else {
        if (item.name === 'PROCESS_APPLY_CANCEL') {
          this._onSearch(true, 'reduce');
        } else {
          this._onSearch();
        }
      }
      if (this.props.refreshCallback) {
        this.props.refreshCallback();
      }
    }
  }, {
    key: '_onRowClick',
    value: function _onRowClick(record, index) {
      if (this.state.selectedType === _dictCodes.LIST_SELECTTYPE.INLINE) return;
      console.log('onRowClick ==> ', record, index);

      var selectedIndex = this.state.selectedRowKeys.indexOf(record.key);
      if (selectedIndex > -1) {
        this.setState({
          selectedRowKeys: this.state.selectedRowKeys.filter(function (item) {
            return item !== record.key;
          }),
          selectedRows: this.state.selectedRows.filter(function (item) {
            return item.key !== record.key;
          })
        });
      } else if (this.state.selectedType === _dictCodes.LIST_SELECTTYPE.RADIO) {
        this.setState({
          selectedRowKeys: [record.key],
          selectedRows: [record]
        });
      } else {
        this.setState({
          selectedRowKeys: this.state.selectedRowKeys.concat(record.key),
          selectedRows: this.state.selectedRows.concat(record)
        });
      }
    }
  }, {
    key: 'renderList',
    value: function renderList(isProcess) {
      var _this9 = this;

      // const selectedRows = [];
      var rowSelection = this.state.selectedType === _dictCodes.LIST_SELECTTYPE.INLINE ? null : {
        type: this.state.selectedType,
        onChange: function onChange(selectedRowKeys, selectedRows) {
          console.log('onChange ==> ', 'selectedRowKeys: ' + selectedRowKeys, 'selectedRows: ', selectedRows);
          _this9.setState({ selectedRowKeys: selectedRowKeys, selectedRows: selectedRows });
        },
        onSelect: function onSelect(record, selected) {
          console.log('onSelect ==> ', record, selected);
          // this.setState({ selectedRows });
        },
        onSelectAll: function onSelectAll(selected, selectedRows, changeRows) {
          console.log('onSelectAll ==> ', selected, selectedRows, changeRows);
          var selectedRowKeys = [];
          if (selected) {
            selectedRowKeys = selectedRows.map(function (row) {
              return row.key;
            });
          }
          _this9.setState({ selectedRows: selectedRows, selectedRowKeys: selectedRowKeys });
        },
        selectedRowKeys: this.state.selectedRowKeys
      };

      if (this.state.columns && this.state.columns.length > 0) {
        // console.log('Search[data] ===> ', this.state.filters);
        var prefixCls = this.props.prefixCls;

        var listContainer = prefixCls + '-container';
        console.log(this.state.selectedRows);
        var columns = this.dealColumns(this.state.columns);
        return _react2.default.createElement(
          'div',
          { className: prefixCls + ' ' + this.refStr, style: this.props.customStyle },
          _react2.default.createElement(_toolBar2.default, {
            ref: 'toolbar',
            prefixCls: prefixCls,
            filters: this.state.filters,
            requestFilterFields: [].concat(_toConsumableArray(this.state.requestFilterFields)),
            onSearch: this._onFilterChange,
            renderTopButtons: this._renderTopButtons,
            toolBarType: this.state.selectedRows && this.state.selectedRows.length > 0,
            isModal: this.props.isModalInput || this.props.isModal,
            isProcess: isProcess,
            isInfo: this.props.isInfo,
            modalCallback: this.props.modalCallback,
            selectRows: this.state.selectedRows.length,
            closeCallback: function closeCallback() {
              _this9.setState({
                selectedRows: [],
                selectedRowKeys: []
              });
            }
          }),
          _react2.default.createElement(
            'div',
            { className: listContainer },
            _react2.default.createElement(_mxa.Table, {
              requestFilterFields: [].concat(_toConsumableArray(this.state.requestFilterFields)),
              locale: { emptyText: '无符合条件的相关数据' },
              rowSelection: rowSelection,
              columns: columns,
              dataSource: this.dealListDataSource(this.state.dataSource),
              sortOrder: false,
              pagination: this.state.pagination,
              onChange: this._onChange,
              onRowClick: this._onRowClick,
              prefixCls: 'mx-table-self',
              isModal: this.props.isModal,
              scopeStr: this.refStr,
              menuCode: this.tag ? this.tag.menuCode : null,
              refStr: this.props.refStr
            })
          )
        );
      }
      console.error('template list', 'columns is null!');
      return _react2.default.createElement('div', null);
    }
  }, {
    key: 'dealListDataSource',
    value: function dealListDataSource(dataSource) {
      var fields = this.props.dataSource.fields;

      var hasDefaultValueFields = fields.filter(function (item) {
        return item.defaultValue;
      });
      if (hasDefaultValueFields.length > 0) {
        (function () {
          var FieldNames = '';
          var FieldObjects = {};
          hasDefaultValueFields.forEach(function (item) {
            FieldNames = FieldNames + item.name + ',';
            FieldObjects[item.name] = item.defaultValue;
          });
          dataSource.map(function (item) {
            Object.keys(item).forEach(function (item1) {
              if (FieldNames.indexOf(item1) >= 0 && !item[item1]) {
                item[item1] = FieldObjects[item1];
              }
            });
            return item;
          });
        })();
      }
      return dataSource;
    }
  }, {
    key: 'dealColumns',
    value: function dealColumns(columns) {
      var _this10 = this;

      var fieldsSetting = this.props.dataSource.fieldsSetting;
      if (this.tag && fieldsSetting) {
        var _ret2 = function () {
          var currentMenu = fieldsSetting.filter(function (item) {
            return item.name === _this10.tag.menuCode;
          });
          var disableFieldsStr = currentMenu && currentMenu.length > 0 && currentMenu[0].fieldNames && currentMenu[0].fieldNames.join(',');
          if (disableFieldsStr) {
            return {
              v: columns.filter(function (item) {
                return disableFieldsStr.indexOf(item.dataIndex) === -1;
              })
            };
          }
        }();

        if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") return _ret2.v;
      }
      return columns;
    }
  }, {
    key: 'menuClick',
    value: function menuClick(m) {
      var _this11 = this;

      (0, _SessionStorage.saveProcessMenuCode)(m.menuCode);
      this.tag = m;
      this.setState({
        requestParamsBean: Object.assign({}, this.state.requestParamsBean, { menu: m.menuCode }),
        buttons: this._filterProcessButton(this.props.dataSource.buttons, m.menuCode),
        variantFields: Object.assign(this.state.variantFields, { menu: m.menuCode }),
        pageIndex: 1
      }, function () {
        _this11._onSearch();
      });
    }
  }, {
    key: 'getSideMenu',
    value: function getSideMenu() {
      if ((0, _ProcessHelper.isApply)(this.props.domainLink)) {
        return _processMenu2.default.apply;
      }
      return _processMenu2.default.review;
    }
  }, {
    key: 'componentDidMount',
    value: function componentDidMount() {
      if ((!this.state.dataSource || this.state.dataSource.length === 0) && this.props.dataSource.emptyListPrompt) {
        _mxa.Modal.error({
          title: '提示',
          content: _react2.default.createElement(_longRunOpt.ContentRender, { message: this.props.dataSource.emptyListPrompt })
        });
      }
    }
  }, {
    key: 'componentWillReceiveProps',
    value: function componentWillReceiveProps(nextProps) {
      this.setState({
        dataSource: this.addKeyForDataSource(nextProps.dataSource, this.state.itemsPerPage)
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var _props4 = this.props,
          domainType = _props4.domainType,
          domainLink = _props4.domainLink,
          dataSource = _props4.dataSource,
          switchNavBar = _props4.switchNavBar;

      var isProcess = (this.isApply || this.isReview) && domainType !== _dictActions.PAGE_TYPE_SUMMARY_LIST;
      var menu = null;
      if (isProcess) {
        menu = this.getSideMenu(domainLink);
        !this.tag && (this.tag = (0, _MenuHelper.getMenuItemByFunc)(function (m) {
          return m.isSelected === true;
        }, menu) || {});
      }
      var main = this.renderList(isProcess);
      if (isProcess) {
        setTimeout(function () {
          if (switchNavBar) {
            switchNavBar(false);
          }
        });
        return _react2.default.createElement(
          'div',
          { className: 'info-container' },
          _react2.default.createElement(
            _sideMenu.SideMenuContainer,
            null,
            _react2.default.createElement(_sideMenu2.default, {
              menu: menu,
              menuClick: this.menuClick,
              selectedItem: this.tag,
              menuTaskCount: this.state.menuTaskCount
            })
          ),
          _react2.default.createElement(
            'div',
            { className: 'main-grid' },
            _react2.default.createElement(
              'div',
              { className: 'main_grid_middlle', style: { height: '100%', backgroundColor: '#e6e9f0' } },
              main
            )
          )
        );
      }
      return main;
    }
  }]);

  return ListView;
}(_react2.default.Component), _class2.propTypes = {
  prefixCls: _react.PropTypes.string,
  isModal: _react.PropTypes.bool,
  isInfo: _react.PropTypes.bool,
  modalCallback: _react.PropTypes.func,
  inject: _react.PropTypes.object // inject for customize, key is 'buttonDescription'
  // hiddenSearchBar: PropTypes.bool,
}, _class2.defaultProps = {
  prefixCls: 'mx-list',
  isModal: false,
  isInfo: false
}, _temp), (_applyDecoratedDescriptor(_class.prototype, 'dealReadonly', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealReadonly'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_renderColumnAction', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_renderColumnAction'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'onCellChange', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'onCellChange'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'changeLocalData', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'changeLocalData'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_renderColumn', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_renderColumn'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_filterProcessButton', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_filterProcessButton'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_processData', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_processData'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'addKeyForDataSource', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'addKeyForDataSource'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'dealIsVisibleField', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealIsVisibleField'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_onFilterChange', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_onFilterChange'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_onChange', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_onChange'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_onSearch', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_onSearch'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'dealMenuTaskCount', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealMenuTaskCount'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_getRelatedState', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_getRelatedState'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'relatedItemsCallback', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'relatedItemsCallback'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_renderTopButtons', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_renderTopButtons'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'buttonClickOnRefresh', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'buttonClickOnRefresh'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_onRowClick', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_onRowClick'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'dealListDataSource', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealListDataSource'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'dealColumns', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'dealColumns'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'menuClick', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'menuClick'), _class.prototype)), _class);
exports.default = ListView;