ming-demo3
Version:
mdf metaui web
376 lines (324 loc) • 13.5 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
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 _row = _interopRequireDefault(require("../basic/row"));
var _col = _interopRequireDefault(require("../basic/col"));
var _MCell = _interopRequireDefault(require("./MCell"));
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), "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 * 3 / 4);
}
}
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.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);
var columnset = _this.RemodelingColumn(params.rows, params.columns);
_this.setState({
columnset: columnset
});
}
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_InitCellStatus", function (Columns, DataSource) {
if (DataSource !== undefined) {
var temp_cellState = cb.utils.extend(true, [], _this.cellState);
var length = DataSource.length;
if (length <= 0) return;
for (var i = 0; i < length; i++) {
DataSource[i]._selected = false;
if (!temp_cellState[i]) temp_cellState[i] = {};
for (var attr in Columns) {
if (!temp_cellState[i][attr]) temp_cellState[i][attr] = {
disabled: false,
visible: false,
readOnly: false,
style: {}
};
}
}
_this.cellState = temp_cellState;
}
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setColumns", function (columns) {
var columndata = cb.utils.extend(true, {}, columns);
for (var attr in columndata) {
if (isNaN(columndata[attr].iColWidth)) columndata[attr].iColWidth = 200;else columndata[attr].iColWidth = parseFloat(columndata[attr].iColWidth * 3 / 4);
}
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), "setDataSource", function (data) {
_this.dataList = data;
_this._InitCellStatus(_this.columns, data);
var columnset = _this.RemodelingColumn(data, _this.columns);
_this.setState({
columnset: columnset
});
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "RemodelingColumn", function (dataList, columnState) {
var ret = [],
columnData = [];
if (_this.GridProps.showRowNo) {
if (!columnState.GridRowNo) columnState.GridRowNo = {
'cItemName': 'GridRowNo',
'iColWidth': 50,
'cControlType': 'Input',
'bFixed': '1'
};
columnData.push(columnState.GridRowNo);
}
for (var attr in columnState) {
if (attr != 'GridRowNo') columnData.push(columnState[attr]);
}
columnData.map(function (col) {
var column = this.setColumn(col.cItemName, col);
ret.push(column);
}, (0, _assertThisInitialized2["default"])(_this));
return ret;
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setColumn", function (attr, col) {
var iColWidth = parseFloat(col.iColWidth);
var width = isNaN(iColWidth) ? 200 : iColWidth;
var headerCell,
headerClassName = '';
var fiexd = col.bFixed == 1 ? true : false;
var align = 'left';
headerCell = _react["default"].createElement(_fixedDataTable.Cell, {
className: "mobile-header-cell"
}, _react["default"].createElement("div", {
style: {
"width": width
},
id: col.index
}, _react["default"].createElement("span", {
style: {
width: width
},
className: "textCol table-header-name"
}, col.cShowCaption)));
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
});
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setCell", function (rowIndex, col) {
return _react["default"].createElement(_MCell["default"], {
dataList: _this.dataList,
readOnly: true,
RowProperty: rowIndex,
Column: col,
model: _this.props.model,
columnsList: _this.columns,
rowHeight: _this.rowheight
});
});
(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);
_this.props.model.setFocusedRowIndex(index);
});
(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), "_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 == rowCount) {
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;
if (!_this.state.showSearch) return _react["default"].createElement("div", {
className: "eChartMobile-nodata"
}, _react["default"].createElement(_SvgIcon["default"], {
type: "huanxingtu"
}), _react["default"].createElement("div", {
className: "eChartMobile-nodata-text"
}, " \u6682\u65F6\u6CA1\u6709\u6570\u636E\u54E6~"));else return _react["default"].createElement("div", {
className: "refer_no_date"
});
});
_this.state = {
visible: false,
pagination: {
total: 0,
current: 0,
pageSize: 0
}
};
_this.GridProps = {
showRowNo: true,
showCheckBox: false,
isPagination: false
};
_this.dataList = [];
_this.columns = {};
_this.ColIndexs = {};
_this.headerHeight = 40;
_this.rowheight = props.rowHeight || 40;
_this.showRows = 0;
return _this;
}
(0, _createClass2["default"])(TableTouch, [{
key: "componentDidMount",
value: function componentDidMount() {
if (this.props.model) {
this.props.model.addListener(this);
var height = this.props.height ? this.props.height : 1020;
var bodyHeight = height - this.headerHeight;
this.showRows = Math.ceil(bodyHeight / this.rowheight);
}
}
}, {
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: "render",
value: function render() {
var emptyData = this.getEmptyData();
return _react["default"].createElement("div", {
className: "mobile-grid"
}, _react["default"].createElement(_row["default"], null, _react["default"].createElement(_fixedDataTable.Table, {
rowHeight: this.rowheight,
overflowY: 'auto',
overflowX: 'auto',
showScrollbarX: false,
showScrollbarY: false,
onScrollEnd: this.onScrollEnd,
footerHeight: 0,
headerHeight: this.headerHeight || 40,
rowsCount: this.dataList.length,
width: this.props.width,
height: this.props.height,
isColumnResizing: false,
onRowClick: this._onRowClick,
touchScrollEnabled: true
}, this.state.columnset), emptyData));
}
}]);
return TableTouch;
}(_react["default"].Component);
exports["default"] = TableTouch;
//# sourceMappingURL=MTable.js.map
;