Commit d52b91c5 authored by 覃振观's avatar 覃振观 👶

5555

parent db845d4a
......@@ -16,22 +16,21 @@ function mapping(dataMapping, rawData) {
}
let mapper = {}, returnData = {};
delete dataMapping.mapper;
let entitySet = Object.entries(dataMapping);
tryForEach(entitySet,(entity) => {
Object.entries(dataMapping).forEach((entity) => {
let beanName = entity[0], propertyNames = entity[1], entityData = rawData[beanName];
if(!isExist(rawData, beanName)) { throw {}; }
if(!isExist(rawData, beanName)) { return; }
if(!entityData) { entityData = {}; }
if(propertyNames instanceof Array) {
// Form 时执行此逻辑
tryForEach(propertyNames,(item) => {
if(!entityData) { entityData = {}; }
if(typeof item === "string") {
if(!isExist(entityData, item, beanName)) { throw {}; }
if(!isExist(entityData, item, beanName)) { return; }
associate(entityData, item, item, beanName,mapper, returnData);
return;
} else if(item instanceof Object) {
let entry = Object.entries(item)[0];
let property = entry[0], alias = entry[1];
if(!isExist(entityData, property, beanName)) { throw {}; }
if(!isExist(entityData, property, beanName)) { return; }
associate(entityData, property, alias, beanName,mapper, returnData)
} else {
console.error('The configuration of "'+item+'" in "'+beanName+'" is not recognized, and the required,' +
......@@ -108,7 +107,9 @@ function testTryForEach() {
const tryForEach = function(arrayObj, callback) {
try {
arrayObj.forEach(callback);
} catch { }
} catch(error) {
console.error(error);
}
}
/**
......@@ -176,39 +177,19 @@ function listeningGrid(elId, options) {
} else { data.Rows = options.data.raw; }
options.data = data;
// ------------------ 编辑框打开前记录当前行 ------------------
const originalOnBeforeEdit = options.onBeforeEdit;
options.onBeforeEdit = function(editParm, gg){
let domIds = editParm.column.__domid.split('|'), recordId = editParm.record.__id, colName = editParm.column.name;
let parentDomId = domIds[0]+'|'+2+'|'+recordId; // +'|'+domIds[2];
let rowDOM;
if(!(rowDOM = document.getElementById(parentDomId))) {
parentDomId = domIds[0]+'|'+1+'|'+recordId;
rowDOM = document.getElementById(parentDomId)
}
let mapper = window.dataMapping.mapper;
let rowId = rowDOM.childNodes[0].childNodes[0].innerText;
let mapperEntry = mapper[colName];
let currentMapper = checkArrayMapper(domIds[0]);
debugger;
if(currentMapper.hasOwnProperty("beanName")) {
if(!mapperEntry[currentMapper.beanName]) {
console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查!");
} else {
//mapperEntry[currentMapper.beanName]['rowId'] = parentDomId;
mapperEntry[currentMapper.beanName]['rowIndex'] = editParm.rowindex;
}
}
originalOnBeforeEdit.call(this, editParm, '11');
}
onBeforeEdit_(options);
const toolbar = options.toolbar;
if(toolbar) {
toolbar.items
tryForEach(toolbar.items, but => {
// ------------------ Grid 新增行时,设置 mapper、 newData -----------------
debugger;
if(but.id === "menuAdd") {
// 使用 gridManager 对象 可以省略 页面监听操作。需要修改。
const originalOnClick = but.click;
but.click = function() {
let mappingEntry = Object.entries(window.dataMapping);
mappingEntry.forEach(entry => {
Object.entries(window.dataMapping).forEach(entry => {
let beanName = entry[0];
if(elId.indexOf(beanName) >= 0) {
let idProperty = entry[1].id;
......@@ -250,7 +231,26 @@ function listeningGrid(elId, options) {
})
originalOnClick.call(this, data);
}
}
if(but.id === "menuDelete") {
const originalOnClick = but.click;
but.click = function() {
let selectRow = gridManager.getSelectedRow();
let currentMapper = checkArrayMapper(gridManager.id);
let beanName = currentMapper.beanName;
let currentData = window.dataSet.newData[beanName];
let propertyId = window.dataMapping[beanName].id;
let currentId = selectRow[propertyId];
delete currentData.compares[currentId];
currentData.ids.pop(currentId);
// window.dataMapping[beanName].columns.forEach(property => {
// window.dataMapping.mapper[property][beanName]
// });
gridManager.deleteSelectedRow();
originalOnClick.call(this, selectRow);
}
}
})
debugger;
......@@ -258,7 +258,37 @@ function listeningGrid(elId, options) {
addObserver(elId);
var gridManager = UICtrl.grid(elId, options);
return gridManager;
}
/**
* Grid 编辑前触发。 这里记录当前编辑框 对应的 Grid 行索引 GridRowIndex
* @param options
* @private
*/
function onBeforeEdit_(options) {
const originalOnBeforeEdit = options.onBeforeEdit;
options.onBeforeEdit = function(editParm, gg){
let domIds = editParm.column.__domid.split('|'), recordId = editParm.record.__id, colName = editParm.column.name;
let parentDomId = domIds[0]+'|'+2+'|'+recordId; // +'|'+domIds[2];
let rowDOM;
if(!(rowDOM = document.getElementById(parentDomId))) {
parentDomId = domIds[0]+'|'+1+'|'+recordId;
rowDOM = document.getElementById(parentDomId)
}
let mapper = window.dataMapping.mapper;
let rowId = rowDOM.childNodes[0].childNodes[0].innerText;
let mapperEntry = mapper[colName];
let currentMapper = checkArrayMapper(domIds[0]);
if(currentMapper.hasOwnProperty("beanName")) {
if(!mapperEntry[currentMapper.beanName]) {
console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查!");
} else {
//mapperEntry[currentMapper.beanName]['rowId'] = parentDomId;
mapperEntry[currentMapper.beanName]['rowIndex'] = editParm.rowindex;
}
}
originalOnBeforeEdit.call(this, editParm, '11');
}
}
/**
......
......@@ -93,6 +93,7 @@ function loadDataTest() {
faceGrid("#fronColorsGrid", data.rawData.fronColors);
faceGrid("#backColorsGrid", data.rawData.backColors);
processedGrid('#processedGrid', data.rawData.processed);
debugger;
productLossGrid('#productLossGrid', data.rawData.productLoss);
inputEventListener();
});
......@@ -104,12 +105,12 @@ function loadDataTest() {
// Grid: 需要监听 Grid Data 时,必须设置 唯一 id 列。
var dataMapping = {
Product: [
"productId", "brandName","productCategoryId", "productUnit", "productSizeGroupId", "confirmDate", "comfirmPerson",
"isFreeInspection", "isNoQualityLoss", "sampleOrderNo", "stockNo", "fileNo", "brandName"
"productId", "brandName","productCategoryId", "productUnit", "productSizeGroupId", "confirmDate", "comfirmPerson"
, "isFreeInspection", "isNoQualityLoss", "sampleOrderNo", "stockNo", "fileNo", "brandName"
],
ProductDetail: [
{"factoryName": "factoryName"}, "productLayout", "materialCode", "productCode", "productEnCode", "bodyColor",
"customerMaterialCode" ,"versionNo", "isNewSpecification", "specificationNo"
{"factoryName": "factoryName"}, "productLayout", "materialCode", "productCode", "productEnCode", "bodyColor"
, "customerMaterialCode" ,"versionNo", "isNewSpecification", "specificationNo"
],
ProductLooked: [
"productLength", "productWidth", "productHeight", "productThick", "productWeight", "productAngleType", "productAngle"
......@@ -117,8 +118,8 @@ var dataMapping = {
, "productSysCertification", "storeName", "productBuyUnit", "purchaseConversionValue", "coefficient"
],
ProductTechnology: [
"beerPlateNo", "goldPlateNo" , "dieCutPlateNo", "copperpResinLateNo", "netPlateNo",
"productTechnologyRequire", "packageStyle", "packageStyle", "physicalTest", "chemistryTest"
"beerPlateNo", "goldPlateNo" , "dieCutPlateNo", "copperpResinLateNo", "netPlateNo"
, "productTechnologyRequire", "packageStyle", "packageStyle", "physicalTest", "chemistryTest"
, "productMaterial"
, "copperpNo", "colorNoCard", "plateNo", "plasticBagStructure"
],
......@@ -151,8 +152,8 @@ function faceGrid(elId, data) {
updateHandler: function(){
updateHandler();
},
deleteHandler: () => {
gridManager.deleteSelectedRow();
deleteHandler: (rowData) => {
console.log(rawData);
},
});
var gridManager = listeningGrid(elId, {
......@@ -230,11 +231,11 @@ function productLossGrid(elId, data) {
});
var gridManager = listeningGrid(elId, {
columns: [
{ display: "客户名称", name: "customerName", width: 140, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true }},
{ display: "产品最大loss数量", name: "productLossMax", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } },
{ display: "loss比率", name: "productLossRate", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } },
{ display: "备注信息", name: "productLossRedundance", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } },
{ display: "产品最大loss数量", name: "productLossRemark", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } },
{ display: "客户名称", name: "customerName", width: 140, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false }},
{ display: "产品最大loss数量", name: "productLossMax", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false } },
{ display: "loss比率", name: "productLossRate", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false } },
{ display: "备注信息", name: "productLossRedundance", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false } },
{ display: "产品最大loss数量", name: "productLossRemark", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false } }
],
toolbar: toolbarOptions,
dataType: "local",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment