UNPKG

ming-demo3

Version:
1,050 lines (912 loc) 38.1 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireDefault(require("react")); var _fixedDataTable = require("fixed-data-table-2"); var _baseui = require("@mdf/baseui"); var _row = _interopRequireDefault(require("../basic/row")); var _col = _interopRequireDefault(require("../basic/col")); var _CellModel = _interopRequireDefault(require("./CellModel")); var _SvgIcon = _interopRequireDefault(require("@mdf/metaui-web/lib/components/common/SvgIcon")); var _util = require("@mdf/cube/lib/helpers/util"); var TableTouch = function (_React$Component) { (0, _inherits2["default"])(TableTouch, _React$Component); function TableTouch(props) { var _this; (0, _classCallCheck2["default"])(this, TableTouch); _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(TableTouch).call(this, props)); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "rowClassNameGetter", function (index) { if (index === _this.selectIndex) return 'public_fixedDataTableRow_selected'; if (_this.props.model) { var selectRows = _this.props.model.getSelectedRowIndexes(); for (var i = 0; i < selectRows.length; i++) { var rowIndex = selectRows[i]; if (index === rowIndex) return 'public_fixedDataTableRow_CheckedRow'; } } }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setListenerState", function (params) { if (params.columnMode === 'local' && _this.props.columns) { for (var attr in _this.props.columns) { Object.assign(_this.props.columns[attr], params.columns[attr]); } params.columns = _this.props.columns; } var tmp_ColIndexs = {}; var index = 0; if (params.cellState) { _this.cellState = params.cellState; } var hasColumn = false; var tableWidth = _this.props.width || 1100; for (var attr in params.columns) { if (_this.props.widthMode == 'percent') { var iColWidth = parseFloat(params.columns[attr].iColWidth); var width = isNaN(iColWidth) ? 25 : iColWidth; width = tableWidth * width / 100; params.columns[attr].iColWidth = width; } else { if (isNaN(params.columns[attr].iColWidth)) { params.columns[attr].iColWidth = 200; } else { params.columns[attr].iColWidth = parseFloat(params.columns[attr].iColWidth * 4 / 3); } } hasColumn = true; if (index === 0) { tmp_ColIndexs[attr] = 0; } else { tmp_ColIndexs[attr] = index; } index = index + 1; } if (params.pageInfo) { _this.setPageInfo(params.pageInfo); } _this.GridProps.showRowNo = params.showRowNo; _this.GridProps.showCheckBox = params.showCheckBox; _this.GridProps.isRadio = !params.multiple; _this.GridProps.showAggregates = params.showAggregates; _this.GridProps.showSubtotal = params.showSubtotal; _this.GridProps.isPagination = params.pagination; _this.GridProps.showColumnSetting = params.showColumnSetting; _this.ColIndexs = tmp_ColIndexs; if (hasColumn) { _this.columns = params.columns; if (params.rows && params.rows.length > 0) _this.dataList = params.rows; _this._InitCellStatus(params.columns, params.rows); _this.readOnly = params.readOnly; var columnset = _this.RemodelingColumn(params.rows, params.columns); _this.setState({ readOnly: params.readOnly, columnset: columnset, showColumnSetting: params.showColumnSetting }); } }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_InitCellStatus", function (Columns, DataSource) { var action = _this.props.action; if (action && action.cControlType && action.cControlType == 'Toolbar') { _this.action = action; } var PopMeta = {}; if (DataSource !== undefined) { var attr; var _ret = function () { var temp_cellState = cb.utils.extend(true, [], _this.cellState); var temp_isColErro = cb.utils.extend(true, [], _this.isColErro); var temp_actionState = cb.utils.extend(true, [], _this.actionState); var length = DataSource.length; if (length <= 0) return { v: void 0 }; var _loop = function _loop(i) { DataSource[i]._selected = false; if (_this.action && _this.action.controls) { var actionList = _this.action.controls; if (!temp_actionState[i]) temp_actionState[i] = {}; actionList.map(function (action) { if (!temp_actionState[i][action.cItemName]) temp_actionState[i][action.cItemName] = { disabled: false, visible: true }; }); } if (!temp_cellState[i]) temp_cellState[i] = {}; if (!temp_isColErro[i]) temp_isColErro[i] = {}; for (attr in Columns) { if (!temp_cellState[i][attr]) temp_cellState[i][attr] = { disabled: false, visible: false, readOnly: false, style: {} }; if (!temp_isColErro[i][attr]) temp_isColErro[i][attr] = false; } }; for (var i = 0; i < length; i++) { _loop(i); } if (temp_actionState) _this.actionState = temp_actionState; if (_this.props.model) _this.props.model.initActionsState(_this.actionState); _this.cellState = temp_cellState; _this.isColErro = temp_isColErro; }(); if ((0, _typeof2["default"])(_ret) === "object") return _ret.v; } }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setColumns", function (columns) { var columndata = cb.utils.extend(true, {}, columns); if (_this.props.widthMode == 'percent') { var tableWidth = _this.props.width || 1100; for (var key in columndata) { var iColWidth = parseFloat(columndata[key].iColWidth); var width = isNaN(iColWidth) ? 25 : iColWidth; width = tableWidth * width / 100; columndata[key].iColWidth = width; } } else { for (var attr in columndata) { if (isNaN(columndata[attr].iColWidth)) { columndata[attr].iColWidth = 200; } else { columndata[attr].iColWidth = parseFloat(columndata[attr].iColWidth * 4 / 3); } } } var columnset = _this.RemodelingColumn(_this.dataList, columndata); _this.columns = columndata; var length = _this.dataList.length; for (var i = 0; i < length; i++) { for (var attr in columndata) { if (!_this.cellState[i][attr]) { _this.cellState[i][attr] = { disabled: false, visible: false, readOnly: false, style: {} }; } } } _this.setState({ columnset: columnset }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setSum", function (sumData) { _this.setState({ sumData: sumData }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setDataSource", function (data) { _this.selectIndex = -1; _this.dataList = data; _this.indeterminate = false; _this.selectAll = false; var _this$state$paginatio = _this.state.pagination, current = _this$state$paginatio.current, pageSize = _this$state$paginatio.pageSize; if (data.length <= pageSize) { _this.scrollRow = 0; } else { _this.scrollRow = current * 10; } _this._InitCellStatus(_this.columns, data); var columnset = _this.RemodelingColumn(data, _this.columns); _this.setState({ columnset: columnset }); if (_this.props.onChangeData) _this.props.onChangeData(); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "RemodelingColumn", function (dataList, columnState) { var ret = [], columnData = [], actionAlign = '', Operation = {}; var readOnly = _this.readOnly; if (readOnly === false && _this.action.controls) { columnState.Operation = { 'cItemName': 'Operation', 'iColWidth': 40, 'cControlType': 'Action', 'iAlign': 3 }; columnData.push(columnState.Operation); } if (_this.GridProps.showRowNo) { if (!columnState.GridRowNo) columnState.GridRowNo = { 'cItemName': 'GridRowNo', 'iColWidth': 50, 'cControlType': 'Input', 'bFixed': '1' }; columnData.push(columnState.GridRowNo); } if (_this.GridProps.showCheckBox || _this.props.hasAction) { if (!columnState.CheckBox) columnState.CheckBox = { 'cItemName': 'CheckBox', 'iColWidth': 45, 'cControlType': 'SelectCheckBox' }; columnData.push(columnState.CheckBox); } for (var attr in columnState) { if (attr != 'CheckBox' && attr != 'GridRowNo' && attr != 'Operation') columnData.push(columnState[attr]); } _this.totalWidth = 0; columnData.map(function (col) { var column = this.setColumn(col.cItemName, col); this.totalWidth += col.iColWidth; ret.push(column); }, (0, _assertThisInitialized2["default"])(_this)); return ret; }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setColumn", function (attr, col) { var controlType = col.cControlType; var iColWidth = parseFloat(col.iColWidth); var width = isNaN(iColWidth) ? 200 : iColWidth; var headerCell, headerClassName = ''; var fiexd = col.bFixed == 1 ? true : false; var align = ''; if (col.iAlign === 1) { align = 'left'; } else if (col.iAlign === 2) { align = 'center'; } else { align = 'right'; } if (!col.bCanModify && !_this.readOnly) { headerClassName = 'public_fixedDataTableCell_disabled'; } else { headerClassName = 'headerName'; } headerCell = _react["default"].createElement(_fixedDataTable.Cell, { className: headerClassName }, _react["default"].createElement("div", { style: { textAlign: 'left', width: _this.props.width, display: "flex" }, id: col.index }, _react["default"].createElement("span", { style: { width: width }, className: "textCol table-header-name" }, col.cShowCaption))); if (attr === 'Operation') { headerCell = _react["default"].createElement(_fixedDataTable.Cell, null, _react["default"].createElement("div", { className: "headerName" })); return _react["default"].createElement(_fixedDataTable.Column, { key: attr, allowCellsRecycling: true, columnKey: attr, header: headerCell, cell: function cell(rowIndex) { return _this.setCell(rowIndex, col); }, width: width, align: "center", fixedRight: true, footer: _this._setFooter }); } if (attr === 'CheckBox') { var model = _this.props.model.getEditRowModel().get(attr); if (_this.GridProps.isRadio || _this.props.hasAction) { headerCell = _react["default"].createElement(_fixedDataTable.Cell, null); } else { headerCell = _react["default"].createElement(_fixedDataTable.Cell, null, _react["default"].createElement("div", { className: "checkboxHD" }, _react["default"].createElement(_baseui.Checkbox, { indeterminate: _this.indeterminate, checked: _this.selectAll, onChange: function onChange(e, i) { return _this.SelectChange(e, -1); } }))); } fiexd = true, align = 'center'; } return _react["default"].createElement(_fixedDataTable.Column, { key: attr, allowCellsRecycling: true, columnKey: attr, header: headerCell, cell: function cell(rowIndex) { return _this.setCell(rowIndex, col); }, width: width, align: align, fixed: fiexd, footer: _this._setFooter }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setCell", function (rowIndex, col) { var _React$createElement; var isColErro = _this.isColErro[rowIndex.rowIndex][rowIndex.columnKey] ? _this.isColErro[rowIndex.rowIndex][rowIndex.columnKey] : false; if (_this.state.style && _this.state.style.height) { _this.rowheight = _this.state.style.height; } return _react["default"].createElement(_CellModel["default"], (_React$createElement = { dataList: _this.dataList, hasAction: _this.props.hasAction, readOnly: _this.readOnly, selectIndex: _this.selectIndex, RowProperty: rowIndex, selectAllState: _this._selectAllState, action: _this.action, indeterminate: _this.indeterminate, selectAll: _this.selectAll, cellState: _this.cellState, isColErro: isColErro, Column: col, model: _this.props.model, GridProps: _this.GridProps, triggerRender: _this._triggerRender, columnsList: _this.columns, rowHeight: _this.props.rowHeight || _this.rowheight, setCellBlur: _this.setCellBlur, renderIndex: _this.renderIndex, ActionClick: _this.ActionClick }, (0, _defineProperty2["default"])(_React$createElement, "rowHeight", _this.rowheight), (0, _defineProperty2["default"])(_React$createElement, "actionState", _this.actionState), _React$createElement)); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_triggerRender", function () { var columnset = _this.RemodelingColumn(_this.dataList, _this.columns); _this.setState({ columnset: columnset }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_selectAllState", function (selectAll, indeterminate) { _this.selectAll = selectAll; _this.indeterminate = indeterminate; _this._triggerRender(); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "SelectChange", function (e, index) { if (!e.target.checked) { _this.props.model.unselectAll(); _this.indeterminate = false; } else { _this.props.model.selectAll(); } _this.dataList.map(function (item, index) { _this.dataList[index]._selected = e.target.checked; }); _this.selectAll = e.target.checked; var columnset = _this.RemodelingColumn(_this.dataList, _this.columns); _this.setState({ columnset: columnset }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_onRowClick", function (e, index) { if (_this.dataList.length == 0 || !_this.dataList[index]) return; if (!_this.GridProps.showCheckBox || _this.GridProps.isRadio || _this.props.hasAction) _this.props.model.select(index);else if (_this.props.tableMode == 'refer') _this.props.model.select(index, false); _this.props.model.setFocusedRowIndex(index); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setCellValue", function (data) { _this.dataList[data.rowIndex][data.cellName] = data.value; var columnset = _this.RemodelingColumn(_this.dataList, _this.columns); _this.setState({ columnset: columnset }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setCellBlur", function (data) { if (_this._triggerRender) _this._triggerRender(); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "select", function (indexes) { for (var i = 0; i < _this.dataList.length; i++) { _this.dataList[i]._selected = false; } for (var attr in indexes) { _this.dataList[indexes[attr]]._selected = true; } _this.selectIndex = indexes[0] * 1; _this.scrollRow = indexes[0]; _this._triggerRender(); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "unselect", function (indexes) { for (var attr in indexes) { _this.dataList[indexes[attr]]._selected = false; } _this._triggerRender(); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setActionState", function (data) { var actionState = _this.actionState; actionState[data.rowIndex][data.itemName][data.name] = data.value; _this._triggerRender(); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setActionsState", function (data) { _this.actionState = data; _this._triggerRender(); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setCellState", function (data) { var state = _this.cellState; if (state[data.rowIndex][data.cellName]) { if (state[data.rowIndex][data.cellName][data.propertyName] == data.value) return; state[data.rowIndex][data.cellName][data.propertyName] = data.value; _this._triggerRender(); } }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateRow", function (data) { _this.dataList[data.index] = data.row; _this._triggerRender(); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "insertRow", function (data) { _this.dataList.splice(data.index, 0, data.row); _this._InitCellStatus(_this.columns, _this.dataList); _this.scrollRow = _this.dataList.length - 1; _this._triggerRender(); _this.props.model.select(data.index); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "insertRows", function (data) { if (_this.dataList.length == 0) { _this.setDataSource(data.rows); } else { for (var i = 0; i < data.rows.length; i++) { _this.dataList.splice(data.index + i, 0, data.rows[i]); } _this._InitCellStatus(_this.columns, _this.dataList); _this._triggerRender(); _this.props.model.select(data.index + data.rows.length - 1); } }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteRows", function (indexes) {}); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "ActionClick", function (e, action, index) { var viewModel = _this.props.model.getParent(); while (viewModel.getParent()) { viewModel = viewModel.getParent(); } var params = { index: index, cItemName: action.cItemName }; viewModel.get(action.cItemName).fireEvent('click', params); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "validate", function (val) { if (val.type == 'error') { if (val.data) { var isColErro = _this.isColErro; isColErro.map(function (item) { for (var key in item) { item[key] = false; } }); val.data.map(function (item) { if (isColErro[item.rowIndex][item.cellName] != undefined && isColErro[item.rowIndex][item.cellName] != 'undefined') isColErro[item.rowIndex][item.cellName] = true; }); _this._triggerRender(); cb.utils.alert('表体存在必输项,请输入完整再尝试保存!', 'error'); } else { cb.utils.alert('表体数据为空!不允许保存!', 'error'); } } }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setPageInfo", function (paginationlist) { if (paginationlist.pageSize === -1) _this.GridProps.isPagination = false; var pageinfo = _this.state.pagination; pageinfo.total = paginationlist.recordCount; pageinfo.current = paginationlist.pageIndex; pageinfo.pageSize = paginationlist.pageSize; _this.setState({ pagination: pageinfo }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_PaginChange", function (page) { if (_this.props.model) _this.props.model.setPageIndex(page); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onShowSizeChange", function (current, size) { if (_this.props.model) _this.props.model.setPageSize(size); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setPage", function (pagination, isPage) { if (isPage && pagination.total !== 0) { var sumData = _this.state.sumData; var columns = _this.columns; var showSums = []; if (sumData.length > 0) { for (var key in sumData[0]) { if (!columns[key]) continue; if (sumData[0][key] == 0) continue; showSums.push(_react["default"].createElement(_col["default"], { span: 1, style: { fontSize: '18px' } }, columns[key].cCaption, "\uFF1A", sumData[0][key])); if (showSums.length > 2) { break; } } } var selectOptions = [{ "value": 10, "text": 10 }, { "value": 20, "text": 20 }, { "value": 30, "text": 30 }, { "value": 40, "text": 40 }, { "value": 50, "text": 50 }]; var selectOptionsControl = selectOptions.map(function (item, index) { return _react["default"].createElement(_baseui.Select.Option, { key: item.value, text: item.text }, item.text); }); return _react["default"].createElement("div", { className: "pagination-new" }, _react["default"].createElement(_baseui.Pagination, { showQuickJumper: true, showSizeChanger: true, pageSizeOptions: ['10', '20', '30', '50', '80', '100', '65536'], showTotal: function showTotal(total) { return "\u5171".concat(total, "\u6761"); }, size: "small", total: pagination.total, current: pagination.current, pageSize: pagination.pageSize, onShowSizeChange: _this.onShowSizeChange, onChange: _this._PaginChange })); } }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_setFooter", function (cellProps) { var column = _this.columns; if (_this.GridProps.showAggregates || _this.GridProps.showAggregates == 'local') { if (_this.GridProps.showCheckBox) { if (cellProps.columnKey === 'CheckBox') { return _react["default"].createElement("div", { className: "fixedDataTable-footer-title" }, _react["default"].createElement("div", { className: "public_fixedDataTableCell_cellContent" }, " \u5408\u8BA1")); } } else if (_this.GridProps.showRowNo) { if (cellProps.columnKey === 'GridRowNo') { return _react["default"].createElement("div", { className: "fixedDataTable-footer-title" }, _react["default"].createElement("div", { className: "public_fixedDataTableCell_cellContent" }, " \u5408\u8BA1")); } } else if (_this.ColIndexs[cellProps.columnKey] === 0) { return _react["default"].createElement("div", { className: "fixedDataTable-footer-title" }, _react["default"].createElement("div", { className: "public_fixedDataTableCell_cellContent" }, " \u5408\u8BA1")); } if (cellProps.columnKey == 'Setting') { return _react["default"].createElement("div", { className: "fixedDataTable-footer-title" }, _react["default"].createElement("div", { className: "public_fixedDataTableCell_cellContent" })); } var sumData = _this.state.sumData; if (sumData.length > 0) { var data = _this.dataList; var sum = 0; for (var key in sumData[0]) { if (key === cellProps.columnKey) { sum = _this._getDecimal(_this.columns[key], sumData[0][key]); return _react["default"].createElement(_fixedDataTable.Cell, null, _react["default"].createElement("div", { style: { "padding": "12px 10px", lineHeight: "14px" }, className: "textCol" }, sum)); } } } else { if (_this.GridProps.showAggregates == 'local') { if (column[cellProps.columnKey].bNeedSum) { var _data = _this.dataList; var _sum = 0; if (_data.length > 0) { for (var i = 0; i < _data.length; i++) { var val = _data[i][cellProps.columnKey]; val = val ? val : 0; _sum = _sum + val; } } _sum = _this._getDecimal(_this.columns[cellProps.columnKey], _sum); return _react["default"].createElement(_fixedDataTable.Cell, null, _react["default"].createElement("div", { style: { "padding": "12px 10px", lineHeight: "14px" }, className: "textCol" }, _sum)); } } else { return _react["default"].createElement(_fixedDataTable.Cell, null, _react["default"].createElement("div", { style: { "padding": "12px 10px", lineHeight: "14px" }, className: "textCol" })); } } } else if (_this.GridProps.showSubtotal) { if (cellProps.columnKey == 'Setting') { return _react["default"].createElement("div", { className: "fixedDataTable-footer-title" }, _react["default"].createElement("div", { className: "public_fixedDataTableCell_cellContent" })); } if (_this.GridProps.showCheckBox) { if (cellProps.columnKey === 'CheckBox') { return _react["default"].createElement("div", { className: "fixedDataTable-footer-title" }, _react["default"].createElement("div", { className: "public_fixedDataTableCell_cellContent" }, " \u5C0F\u8BA1")); } } else if (_this.GridProps.showRowNo) { if (cellProps.columnKey === 'GridRowNo') { return _react["default"].createElement("div", { className: "fixedDataTable-footer-title" }, _react["default"].createElement("div", { className: "public_fixedDataTableCell_cellContent" }, " \u5C0F\u8BA1")); } } else if (_this.ColIndexs[cellProps.columnKey] === 0) { return _react["default"].createElement("div", { className: "fixedDataTable-footer-title" }, _react["default"].createElement("div", { className: "public_fixedDataTableCell_cellContent" }, " \u5C0F\u8BA1")); } if (column[cellProps.columnKey].bNeedSum) { var _data2 = _this.dataList; var _sum2 = 0; if (_data2.length > 0) { for (var _i = 0; _i < _data2.length; _i++) { var _val = _data2[_i][cellProps.columnKey]; _val = _val ? _val : 0; _sum2 = _sum2 + _val; } } return _react["default"].createElement(_fixedDataTable.Cell, null, _react["default"].createElement("div", { style: { "padding": "12px 10px", lineHeight: "14px" }, className: "textCol" }, _sum2)); } } }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_getDecimal", function (col, sum) { var NumPoint = col.iNumPoint; var cFormatData = col.cFormatData; try { if (!cFormatData || cFormatData == '') { cFormatData = {}; } else { cFormatData = JSON.parse(cFormatData); } } catch (e) { cb.utils.alert('数量/金额/单价,预制错误!', 'error'); } var decimal = cFormatData.decimal ? (0, _util.getPredicateValue)(cFormatData.decimal) : null; var controlType = col.cControlType ? col.cControlType.trim().toLocaleLowerCase() : ''; if (controlType === 'money') { if (decimal) NumPoint = decimal;else NumPoint = cb.rest.AppContext.option.amountofdecimal; } else if (controlType === 'price') { if (decimal) NumPoint = decimal;else NumPoint = cb.rest.AppContext.option.monovalentdecimal; } else if (controlType === 'inputnumber') { if (decimal) NumPoint = decimal;else if (!NumPoint || NumPoint == '') NumPoint = 0; } else { NumPoint = null; } if (!isNaN(sum) && NumPoint) { sum = Number(sum); sum = sum.toFixed(NumPoint); } return sum; }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onScrollEnd", function (scrollx, scrolly, hideRows) { var rowCount = _this.dataList.length; if (_this.showRows + hideRows - 1 == rowCount || _this.showRows + hideRows - 1 == rowCount - 1 || _this.bodyHeight + scrolly == rowCount * _this.rowheight) { var pagination = _this.state.pagination; var newSize = pagination.current + 1; var pageCount = pagination.total / pagination.pageSize; pageCount = Math.ceil(pageCount); if (newSize > pageCount) return; if (_this.props.model) _this.props.model.setPageIndex(pagination.current + 1); } }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getEmptyData", function () { var data = _this.dataList; if (data.length) return; var text = _this.state.showSearch ? '搜索无结果' : '暂时没有数据哦~'; var icon = _this.props.emptyIcon || 'nodata'; return _react["default"].createElement("div", { className: "table-nodata" }, _react["default"].createElement(_SvgIcon["default"], { type: icon }), text); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getStringLength", function (str) { if (!str) str = ''; var realLength = 0, len = str.length, charCode = -1; for (var i = 0; i < len; i++) { charCode = str.charCodeAt(i); if (charCode >= 0 && charCode <= 128) { realLength += 1; } else { realLength += 2; } } return realLength; }); _this.state = { readOnly: true, visible: false, pagination: { total: 0, current: 0, pageSize: 0 }, sumData: [], style: props.style, gridWidth: props.width || 1100 }; _this.GridProps = { showRowNo: true, showCheckBox: false, isPagination: false }; _this.selectAll = false; _this.dataList = []; _this.columns = {}; _this.ColIndexs = {}; _this.selectIndex = -1; _this.scrollCol = null; _this.scrollRow = 0; _this.headerHeight = 46; _this.actionState = []; _this.CellState = []; _this.isColErro = []; _this.action = {}; _this.actionStyle = {}; _this.RowCol = {}; _this.renderIndex = 1; _this.rowheight = props.rowHeight || 56; _this.showRows = 0; _this.__isElectronic = false; _this.bodyHeight = 0; return _this; } (0, _createClass2["default"])(TableTouch, [{ key: "componentDidMount", value: function componentDidMount() { if (window.__isElectronic) { this.__isElectronic = true; if (this.props.rowHeight) this.rowheight = this.props.rowHeight;else this.rowheight = 46; this.headerHeight = 40; } if (this.props.model) { this.props.model.addListener(this); var scrollXWidth = this.totalWidth > (this.props.width || 1100) ? 17 : 2; var height = this.props.height ? this.props.height : 1020; var bodyHeight = height - this.headerHeight - scrollXWidth; var pageIndex = Math.ceil(bodyHeight / this.rowheight / 10); if (this.__isElectronic && this.props.tableMode == 'refer') { this.showRows = Math.ceil(bodyHeight / this.rowheight); this.props.model.setPageSize(10); } else { this.showRows = Math.ceil(bodyHeight / this.rowheight); var pageSize = pageIndex * 10; this.props.model.setPageSize(pageSize); } } var clientWidth = document.documentElement.clientWidth; if (clientWidth <= 1024 && clientWidth == this.state.gridWidth) { this.setState({ gridWidth: this.state.gridWidth - 20 }); } } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { if (this.props.height != nextProps.height) { if (nextProps.model && this.__isElectronic && this.props.tableMode == 'refer') { var scrollXWidth = this.totalWidth > (this.props.width || 1100) ? 17 : 2; var height = nextProps.height ? nextProps.height : 1020; this.bodyHeight = height - this.headerHeight - scrollXWidth; } } } }, { key: "componentDidUpdate", value: function componentDidUpdate() { if (this.props.model) this.props.model.addListener(this); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { if (this.props.model) this.props.model.removeListener(this); } }, { key: "setReadOnly", value: function setReadOnly(value) { this.readOnly = value; this.setState({ readOnly: value }); } }, { key: "render", value: function render() { var visible = this.state.visible; var style = this.state.style || {}; var gridHeight = this.props.height || 600; if (this.dataList.length == 0 && !this.props.height) gridHeight = 200; var footerHeight = this.props.footerHeight || 0; var calcHeightByRowCount = this.state.calcHeightByRowCount; if (calcHeightByRowCount) { gridHeight = this.rowheight * calcHeightByRowCount + (this.headerHeight || 40) + footerHeight + 8; if (gridHeight < 200) gridHeight = 200; } if (style.rowheight) this.rowheight = parseFloat(style.rowheight); if (visible) gridClassName = 'hide'; if (this.GridProps.showAggregates == 'local' && this.state.sumData.length > 0) footerHeight += this.rowheight; if (this.GridProps.showSubtotal) footerHeight += this.rowheight; if (this.dataList.length == 0) footerHeight = 0; var emptyData = this.getEmptyData(); return _react["default"].createElement("div", { className: "touch-grid" }, _react["default"].createElement(_row["default"], null, _react["default"].createElement(_fixedDataTable.Table, { rowHeight: this.rowheight, overflowY: 'auto', overflowX: 'auto', onScrollEnd: this.onScrollEnd, footerHeight: footerHeight, onRowTouchMove: this.onRowTouchMove, headerHeight: this.headerHeight || 40, rowsCount: this.dataList.length, width: this.state.gridWidth, height: gridHeight, isColumnResizing: false, onRowClick: this._onRowClick, rowClassNameGetter: this.rowClassNameGetter, scrollToRow: this.scrollRow, scrollToColumn: this.scrollCol, touchScrollEnabled: true }, this.state.columnset), emptyData)); } }]); return TableTouch; }(_react["default"].Component); exports["default"] = TableTouch; //# sourceMappingURL=Table.js.map