ming-demo3
Version:
mdf metaui web
743 lines (645 loc) • 25.5 kB
JavaScript
"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 _antd = require("antd");
var _table = _interopRequireDefault(require("./table"));
var table2D = function (_React$Component) {
(0, _inherits2["default"])(table2D, _React$Component);
function table2D(props) {
var _this;
(0, _classCallCheck2["default"])(this, table2D);
_this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(table2D).call(this, props));
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onOk", function (e) {
var validDataSource = _this.getValidDataSource();
if (validDataSource.length > 0) {
var gridModel = _this.source.gridModel;
var length = gridModel.getRows().length;
gridModel.setReadOnly(false);
gridModel.deleteRows(_this.source.focusedIndex);
gridModel.insertRows(_this.source.focusedIndex, validDataSource);
}
_this.doClose();
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onCancel", function (e) {
var gridModel = _this.source.gridModel;
gridModel.updateRow(_this.source.focusedIndex, _this.config.originRowBackup);
_this.doClose();
});
_this.bInitOK = true;
_this.billNo = props.billNo;
_this.needLog = true;
_this.bInitOK = _this.initData();
if (_this.bInitOK == false) {
_this.doClose();
}
_this.state = {};
return _this;
}
(0, _createClass2["default"])(table2D, [{
key: "componentDidMount",
value: function componentDidMount() {}
}, {
key: "initConfigSetting",
value: function initConfigSetting() {
var config = {};
config.headDisplayFields = ["product_cCode", "product_cName"];
config.rowKeyFields = {
fieldNames: ["product_cCode"]
};
config.rowTitleData = {
fieldNames: ["vendor", "vendor_name"],
fieldValues: []
};
config.colTitleData = {
fieldNames: ["project_name", "requirementDate"],
fieldValues: []
};
config.measureData = {
fieldNames: ["invExchRate"],
sumSetting: {}
};
config.crossPointData = {
fieldNames: ["qty", "purQty"],
sumSetting: {}
};
return config;
}
}, {
key: "isNoValue",
value: function isNoValue(value) {
if ((0, _typeof2["default"])(value) == "object") {
if (_.isEmpty(value)) return true;
} else if (value == undefined) {
return true;
} else if (value == "") {
return true;
}
return false;
}
}, {
key: "initConfigData",
value: function initConfigData(gridModel, focusedIndex, config) {
var _this2 = this;
var self = this;
var rowKeyFields = config.rowKeyFields;
var field = rowKeyFields.fieldNames[0];
var rowTitleFields = config.rowTitleData.fieldNames;
var colTitleFields = config.colTitleData.fieldNames;
var value = gridModel.getRow(focusedIndex)[field];
var rows = _.filter(gridModel.getRows(), function (o) {
return o[field] == value;
});
var arr_CheckRepeat = [];
var arr_RowValues = [];
var arr_ColValues = [];
try {
rows.forEach(function (row) {
var obj = {};
var rowValue = [];
var colValue = [];
rowTitleFields.forEach(function (field) {
var value = row[field];
if (self.isNoValue(value)) {
throw new Error("存在行标题的值为空的行。fieldName=" + field);
}
obj[field] = value;
rowValue.push(value);
});
colTitleFields.forEach(function (field) {
var value = row[field];
if (_this2.isNoValue(value)) {
throw new Error("存在列标题的值为空的行。fieldName=" + field);
}
obj[field] = value;
colValue.push(value);
});
arr_CheckRepeat.push(JSON.stringify(obj));
arr_RowValues.push(JSON.stringify(rowValue));
arr_ColValues.push(JSON.stringify(colValue));
});
} catch (e) {
cb.utils.alert(e.message);
self.doClose();
return;
}
arr_CheckRepeat = arr_CheckRepeat.sort();
this.LogInfo("arr_RowValues = " + JSON.stringify(arr_RowValues));
this.LogInfo("arr_ColValues = " + JSON.stringify(arr_ColValues));
arr_RowValues = _.sortBy(_.uniq(arr_RowValues));
arr_ColValues = _.sortBy(_.uniq(arr_ColValues));
this.LogInfo("arr_RowValues 2 = " + JSON.stringify(arr_RowValues));
this.LogInfo("arr_ColValues 2 = " + JSON.stringify(arr_ColValues));
if (arr_CheckRepeat.length > 1) {
for (var i = 0; i < arr_CheckRepeat.length - 1; i++) {
if (arr_CheckRepeat[i] == arr_CheckRepeat[i + 1]) {
cb.utils.alert("存在重复行。信息如下" + arr_CheckRepeat[i]);
i = arr_CheckRepeat.length;
self.doClose();
}
}
}
return config;
}
}, {
key: "getHeaderData",
value: function getHeaderData() {
var _this3 = this;
var headerData = [];
var headDisplayFields = this.config.headDisplayFields;
if (_.isEmpty(headDisplayFields) == false) {
headDisplayFields.forEach(function (field) {
var col = _this3.source.gridModel.getColumn(field);
if (col) {
var tmp = {};
tmp.cShowCaption = col.cShowCaption || col.cCaption;
tmp.fieldValue = _this3.source.originRowBackup[field];
headerData.push(tmp);
}
});
}
return headerData;
}
}, {
key: "initData",
value: function initData() {
this.source = {};
this.source.gridModel = this.props.gridModel;
this.source.parentModel = this.source.gridModel && this.source.gridModel.getParent();
this.source.params = this.source.parentModel && this.source.parentModel.getParams();
this.source.focusedIndex = this.source.gridModel ? this.source.gridModel.getFocusedRowIndex() : -1;
if (this.source.focusedIndex < 0) {
cb.utils.alert("请选择某一行。");
return false;
}
this.source.originRowBackup = undefined;
if (this.source.gridModel) {
this.source.originRowBackup = _.cloneDeep(this.source.gridModel.getRow(this.source.focusedIndex));
}
var config = this.initConfigSetting();
this.config = this.checkConfig(this.source.gridModel, config);
this.config = this.initConfigData(this.source.gridModel, this.source.focusedIndex, this.config);
this.headerData = this.getHeaderData();
this.initColumnsAndData(this.config);
this.gridModel = new cb.models.GridModel({
columns: this.t2dColumns,
independent: true,
readOnly: false,
showRowNo: false,
pagination: false,
dataSourceMode: 'local',
isDirty: false,
showCheckBox: false,
showColumnSetting: false,
showAggregates: false
});
this.gridModel.setDataSource(this.dataSource);
this.setTrigger();
return true;
}
}, {
key: "setTrigger",
value: function setTrigger() {
var self = this;
self.gridModel.on('beforeCellValueChange', function (data) {
return self.beforeCellValueChange(data);
});
self.source.gridModel.on('afterCellValueChange', function (data) {
var sourceRow = self.source.gridModel.getRow(data.rowIndex);
if (sourceRow) {
var t2DRowKey = sourceRow.t2DRowKey;
var t2DColKey = sourceRow.t2DColKey;
self.originDataSource.forEach(function (row) {
if (row.t2DRowKey === t2DRowKey && row.t2DColKey === t2DColKey) {
row = cb.utils.extend(row, sourceRow);
var t2dRows = self.gridModel.getRows();
var t2dRowIndex = _.findIndex(t2dRows, function (o) {
return o.t2DRowKey == t2DRowKey;
});
if (t2dRowIndex >= 0) {
var obj = {};
Object.values(self.t2dColumns).forEach(function (col) {
if (col.t2DColType == "measure") {
obj[col.fieldName] = row[col.fieldName];
} else if (col.t2DColType == "crossPoint" && col.t2DColKey == t2DColKey) {
obj[col.fieldName] = row[col.t2DFieldsInfo.originField];
}
});
self.gridModel.updateRow(t2dRowIndex, obj);
}
}
});
}
});
}
}, {
key: "findOriginIndexs",
value: function findOriginIndexs(t2DColType, t2DRowKey, t2DColKey) {
var arr = [];
this.originDataSource.forEach(function (ele, index) {
if ((!t2DRowKey || ele.t2DRowKey == t2DRowKey) && (!t2DColKey || ele.t2DColKey == t2DColKey)) arr.push(index);
});
return arr;
}
}, {
key: "checkValueChanged",
value: function checkValueChanged(t2DColType, originIndexs, originField, newValue) {
var isChanged = false;
var originDataSource = this.originDataSource;
originIndexs.forEach(function (index) {
var row = originDataSource[index];
if (row[originField] != newValue) {
isChanged = true;
}
});
return isChanged;
}
}, {
key: "beforeCellValueChange",
value: function beforeCellValueChange(data) {
var self = this;
var rowInfo = this.gridModel.getRow(data.rowIndex);
var colInfo = this.gridModel.getColumn(data.cellName);
var t2DColType = colInfo.t2DColType;
var t2DColKey = colInfo.t2DColKey;
var t2DRowKey = rowInfo.t2DRowKey;
var t2DFieldsInfo = colInfo.t2DFieldsInfo;
var originField = "";
var originIndexs = [];
if (t2DColType == "crossPoint") {
originIndexs = this.findOriginIndexs(t2DColType, t2DRowKey, t2DColKey);
originField = t2DFieldsInfo && t2DFieldsInfo.originField;
} else if (t2DColType == "measure") {
originIndexs = this.findOriginIndexs(t2DColType, t2DRowKey);
originField = colInfo.fieldName;
}
var valueChanged = this.checkValueChanged(t2DColType, originIndexs, originField, data.value);
if (valueChanged) {
if (colInfo.bCheck) {
var sourceRow = this.source.gridModel.getRow(this.source.focusedIndex);
var curRow = this.originDataSource[originIndexs[0]];
this.source.gridModel.updateRow(this.source.focusedIndex, curRow);
this.source.gridModel.setCellValue(this.source.focusedIndex, originField, data.value, true, false);
return false;
} else {
var _curRow = this.originDataSource[originIndexs[0]];
_curRow[originField] = data.value;
return true;
}
}
}
}, {
key: "doClose",
value: function doClose() {
this.bInitOK = false;
if (this.props.close) this.props.close(true);
}
}, {
key: "checkConfig",
value: function checkConfig(gridModel, config) {
var config2 = _.cloneDeep(config);
var isNeedLog = false;
var isNeedClose = false;
if (_.isEmpty(config2.headDisplayFields) == false) {
var length = config2.headDisplayFields.length;
if (length) {
for (var i = length - 1; i >= 0; i--) {
if (gridModel.hasColumn(config2.headDisplayFields[i]) == false) {
isNeedLog = true;
config2.headDisplayFields.splice(i, 1);
}
}
}
}
var rowTitleData = config2 && config2.rowTitleData;
if (_.isEmpty(rowTitleData) == false) {
var fieldNames = rowTitleData.fieldNames;
var fieldValues = rowTitleData.fieldValues;
var _length = fieldNames.length;
if (_length) {
for (var i = _length - 1; i >= 0; i--) {
var fieldName = fieldNames[i];
if (gridModel.hasColumn(fieldName) == false) {
isNeedLog = true;
fieldNames.splice(i, 1);
fieldValues.forEach(function (arr) {
arr.splice(i, 1);
});
}
}
if (fieldNames.length == 0) rowTitleData.fieldValues = [];
}
}
var colTitleData = config2 && config2.colTitleData;
if (_.isEmpty(colTitleData) == false) {
var _fieldNames = colTitleData.fieldNames;
var _fieldValues = colTitleData.fieldValues;
var _length2 = _fieldNames.length;
if (_length2) {
for (var i = _length2 - 1; i >= 0; i--) {
var _fieldName = _fieldNames[i];
if (gridModel.hasColumn(_fieldName) == false) {
isNeedLog = true;
_fieldNames.splice(i, 1);
_fieldValues.forEach(function (arr) {
arr.splice(i, 1);
});
}
}
if (_fieldNames.length == 0) colTitleData.fieldValues = [];
}
}
if (_.isEmpty(config2.measureData.fieldNames) == false) {
var _length3 = config2.measureData.fieldNames.length;
if (_length3) {
for (var i = _length3 - 1; i >= 0; i--) {
if (gridModel.hasColumn(config2.measureData.fieldNames[i]) == false) {
isNeedLog = true;
config2.measureData.fieldNames.splice(i, 1);
}
}
}
}
if (_.isEmpty(config2.crossPointData.fieldNames) == false) {
var _length4 = config2.crossPointData.fieldNames.length;
if (_length4) {
for (var i = _length4 - 1; i >= 0; i--) {
if (gridModel.hasColumn(config2.crossPointData.fieldNames[i]) == false) {
isNeedLog = true;
config2.crossPointData.fieldNames.splice(i, 1);
}
}
}
}
if (_.isEmpty(rowTitleData) || _.isEmpty(rowTitleData.fieldNames)) {
cb.utils.alert("配置文件中行标题为空或者配置字段不存在于源表栏目中,请检查。");
isNeedLog = true;
isNeedClose = true;
} else if (_.isEmpty(config2.crossPointData.fieldNames)) {
cb.utils.alert("配置文件中交叉点为空或者配置字段不存在于源表栏目中,请检查。");
isNeedLog = true;
isNeedClose = true;
}
if (isNeedLog) {
this.LogInfo("配置信息中字段验证失败。包含栏目中不存在的字段 转换前 " + JSON.stringify(config), true);
this.LogInfo("配置信息中字段验证失败。包含栏目中不存在的字段 转换后 " + JSON.stringify(config2), true);
} else {
this.LogInfo("配置信息中栏目验证OK ", true);
}
if (isNeedClose) {
this.doClose();
}
return config2;
}
}, {
key: "LogInfo",
value: function LogInfo(info, bMust) {
if (this.needLog || bMust) {
if (!(typeof info == "string" || typeof info == "number")) info = JSON.stringify(info);
console.log("2维表录入 " + info);
}
}
}, {
key: "GetSourceOriginTpl",
value: function GetSourceOriginTpl(gridModel, focusedIndex, config) {
var row = gridModel.getRow(focusedIndex);
config.rowTitleData.fieldNames.forEach(function (field) {
if (row.hasOwnProperty(field)) delete row[field];
});
config.colTitleData.fieldNames.forEach(function (field) {
if (row.hasOwnProperty(field)) delete row[field];
});
config.crossPointData.fieldNames.forEach(function (field) {
if (row.hasOwnProperty(field)) delete row[field];
});
config.measureData.fieldNames.forEach(function (field) {
if (row.hasOwnProperty(field)) delete row[field];
});
return row;
}
}, {
key: "getNumPoint",
value: function getNumPoint(field, defaultValue) {
var model = this.source.gridModel && this.source.gridModel.getEditRowModel();
var fieldModel = model && model.get(field);
var iNumPoint = fieldModel && fieldModel.get("iNumPoint");
return iNumPoint || defaultValue;
}
}, {
key: "initColumnsAndData",
value: function initColumnsAndData(config) {
var _this4 = this;
var self = this;
var columns2 = {};
var rowTitleData = config.rowTitleData;
var colTitleData = config.colTitleData;
var measureFields = config.measureData.fieldNames;
var crossPointFields = config.crossPointData.fieldNames;
var gridModel = this.source.gridModel;
var originRows = [];
var originDataSource = [];
if (_.isEmpty(rowTitleData) == false && _.isEmpty(rowTitleData.fieldNames) == false) {
rowTitleData.fieldNames.forEach(function (fieldName) {
var column = gridModel.getColumn(fieldName);
column.t2DColType = "rowTitle";
column.bCanModify = false;
columns2[fieldName] = column;
columns2[fieldName].iOrder = Object.keys(columns2).length + 1;
});
}
if (_.isEmpty(measureFields) == false) {
measureFields.forEach(function (fieldName) {
var column = gridModel.getColumn(fieldName);
column.t2DColType = "measure";
column.cFormatData = undefined;
column.iNumPoint = self.getNumPoint(fieldName, column.iNumPoint);
columns2[fieldName] = column;
columns2[fieldName].iOrder = Object.keys(columns2).length + 1;
});
}
var multiCols = [];
if (colTitleData.fieldNames.length > 0 && colTitleData.fieldValues.length > 0) {
colTitleData.fieldValues.forEach(function (titleValueArr) {
var obj = {};
var t2DFieldsInfo = {};
if (_.isEmpty(titleValueArr) == false) {
titleValueArr.forEach(function (titleValue, index) {
var obj2 = {};
var cFieldName = "";
var path = "";
if (_.isEmpty(obj)) {
obj2.cFieldName = "field" + titleValue;
obj2.path = "field" + titleValue;
} else {
obj2.cFieldName = titleValue;
obj2.path = obj.path + "|" + titleValue;
obj2.parent = obj;
}
obj2.cCaption = titleValue;
obj2.cShowCaption = titleValue;
obj2.bVmExclude = 0;
obj2.iOrder = 0;
obj2.uncopyable = false;
obj = obj2;
t2DFieldsInfo[colTitleData.fieldNames[index]] = titleValue;
});
}
obj.t2DFieldsInfo = t2DFieldsInfo;
multiCols.push(obj);
});
}
var originRowTpl = this.GetSourceOriginTpl(gridModel, this.source.focusedIndex, config);
if (multiCols.length > 0) {
multiCols.forEach(function (multiCol, index) {
var t2DColKey = _this4.getRandomKey("Col_");
var tmpSourceOriginRow = _.cloneDeep(originRowTpl);
tmpSourceOriginRow.t2DColKey = t2DColKey;
tmpSourceOriginRow = Object.assign(tmpSourceOriginRow, multiCol.t2DFieldsInfo);
originRows.push(tmpSourceOriginRow);
crossPointFields.forEach(function (field) {
var col = _.cloneDeep(self.source.gridModel.getColumn(field));
col.parent = multiCol;
col.t2DFieldsInfo = _.cloneDeep(multiCol.t2DFieldsInfo);
col.t2DFieldsInfo.originField = field;
var cFieldName = multiCol.path + "|" + field;
col.cFieldName = cFieldName;
col.cItemName = cFieldName;
col.fieldName = cFieldName;
col.cFormatData = undefined;
col.iNumPoint = self.getNumPoint(field, col.iNumPoint);
col.path = cFieldName;
col.t2DColType = "crossPoint";
col.iOrder = Object.keys(columns2).length + 1;
col.t2DColKey = t2DColKey;
columns2[cFieldName] = col;
});
delete multiCol.t2DFieldsInfo;
});
} else {
var t2DColKey = this.getRandomKey("Col_");
var tmpSourceOriginRow = _.cloneDeep(originRowTpl);
tmpSourceOriginRow.t2DColKey = t2DColKey;
originRows.push(tmpSourceOriginRow);
crossPointFields.forEach(function (field) {
var col = _.cloneDeep(self.source.gridModel.getColumn(field));
col.t2DFieldsInfo = {};
col.t2DFieldsInfo.originField = field;
var cFieldName = field;
col.cFieldName = cFieldName;
col.cItemName = cFieldName;
col.fieldName = cFieldName;
col.cFormatData = undefined;
col.iNumPoint = self.getNumPoint(field, col.iNumPoint);
col.path = cFieldName;
col.t2DColType = "crossPoint";
col.iOrder = Object.keys(columns2).length + 1;
col.t2DColKey = t2DColKey;
columns2[cFieldName] = col;
});
}
var dataSource = [];
if (_.isEmpty(rowTitleData) == false) {
rowTitleData.fieldValues.forEach(function (row) {
var t2DRowKey = _this4.getRandomKey("row_");
var tmpOriginRows = _.cloneDeep(originRows);
var obj = {};
row.forEach(function (value, index) {
obj[rowTitleData.fieldNames[index]] = value;
tmpOriginRows.forEach(function (ele) {
ele[rowTitleData.fieldNames[index]] = value;
ele.t2DRowKey = t2DRowKey;
});
});
obj.t2DRowKey = t2DRowKey;
dataSource.push(obj);
originDataSource = _.concat(originDataSource, tmpOriginRows);
});
}
Object.values(columns2).forEach(function (col) {
col.bShowIt = true;
col.bHidden = false;
});
this.t2dColumns = columns2;
this.dataSource = dataSource;
this.originDataSource = originDataSource;
this.LogInfo("栏目信息 this.t2dColumns = " + JSON.stringify(columns2));
this.LogInfo("数据源信息 this.dataSource = " + JSON.stringify(dataSource));
}
}, {
key: "getValidDataSource",
value: function getValidDataSource() {
var measureFields = this.config.measureData.fieldNames;
var crossPointFields = this.config.crossPointData.fieldNames;
var arr = [];
this.originDataSource.forEach(function (ele) {
var bHasValue = false;
measureFields.forEach(function (field) {
if (ele.hasOwnProperty(field) && ele[field].toString() != "") bHasValue = true;
});
crossPointFields.forEach(function (field) {
if (ele.hasOwnProperty(field) && ele[field].toString() != "") bHasValue = true;
});
if (bHasValue) {
arr.push(ele);
}
});
return arr;
}
}, {
key: "getRandomKey",
value: function getRandomKey(str) {
return str + Math.floor(Math.random() * 10000000000);
}
}, {
key: "getHeaderContent",
value: function getHeaderContent() {
var arr = [];
if (this.headerData.length > 0) {
this.headerData.forEach(function (ele) {
arr.push(_react["default"].createElement("div", null, _react["default"].createElement("span", null, ele.cShowCaption), _react["default"].createElement("span", null, ele.fieldValue)));
});
}
if (arr.length > 0) return _react["default"].createElement("div", null, arr);else return undefined;
}
}, {
key: "getContent",
value: function getContent() {
return _react["default"].createElement(_table["default"], {
width: 800,
height: 441,
model: this.gridModel
});
}
}, {
key: "render",
value: function render() {
var header = this.getHeaderContent();
var content = this.getContent();
if (this.bInitOK) return _react["default"].createElement(_antd.Modal, {
title: "2D Input",
width: 800,
visible: true,
className: "Table2D_Modal",
onOk: this.onOk,
onCancel: this.onCancel,
okText: "\u786E\u5B9A",
cancelText: "\u53D6\u6D88",
maskClosable: false
}, _react["default"].createElement("div", null, header, content));else return null;
}
}]);
return table2D;
}(_react["default"].Component);
exports["default"] = table2D;
//# sourceMappingURL=table2D.js.map