|
@@ -3,12 +3,12 @@
|
|
|
*/
|
|
|
var rationCoeOprObj = {
|
|
|
sheet: null,
|
|
|
- libID: -1,
|
|
|
- currentRationItem: null,
|
|
|
+ libID: null,
|
|
|
+ curRation: null,
|
|
|
cache: {},
|
|
|
setting: {
|
|
|
header:[
|
|
|
- {headerName:"编号",headerWidth:120,dataCode:"ID", dataType: "Number"},
|
|
|
+ {headerName:"编码",headerWidth:120,dataCode:"ID", dataType: "Number"},
|
|
|
{headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"},
|
|
|
{headerName:"内容",headerWidth:300,dataCode:"content", dataType: "String"}
|
|
|
],
|
|
@@ -17,199 +17,216 @@ var rationCoeOprObj = {
|
|
|
lockColumns:[1,2]
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
buildSheet: function(sheet) {
|
|
|
var me = this;
|
|
|
me.sheet = sheet;
|
|
|
- //alert('0020 libID:' + JSON.stringify(me.libID));
|
|
|
- me.libID = storageUtil.getSessionCache("RationGrp","repositoryID");
|
|
|
- //alert('0021 libID:' + JSON.stringify(me.libID));
|
|
|
+ me.libID = storageUtil.getSessionCache("RationGrp","repositoryID"); // 不可靠,有时取不到
|
|
|
+ if (me.libID == undefined){me.libID = getQueryString('repository')};
|
|
|
sheetCommonObj.initSheet(me.sheet, me.setting, 30);
|
|
|
me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
|
|
|
me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
|
|
|
- me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
|
|
|
+ me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
|
|
|
me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
|
|
|
},
|
|
|
- onRangeChanged: function(sender, args) {
|
|
|
- if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
|
|
|
- var me = rationCoeOprObj, updateArr = [], removeArr = [];
|
|
|
- if (args.col == 0) {
|
|
|
- if (me.cache["_Coe_" + me.currentRationItem.ID]) {
|
|
|
- var cacheArr = me.cache["_Coe_" + me.currentRationItem.ID];
|
|
|
- for (var i = args.rowCount - 1; i >= 0; i--) {
|
|
|
- if (args.row + i < cacheArr.length) {
|
|
|
- cacheArr.splice(args.row + i, 1);
|
|
|
- }
|
|
|
- }
|
|
|
- me.updateRationItem();
|
|
|
- sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
|
|
|
- me.showCoeItems(me.currentRationItem.ID);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
- },
|
|
|
-/* onClipboardPasting: function(sender, args) {
|
|
|
+ onClipboardPasting: function(sender, args) {
|
|
|
var me = rationCoeOprObj;
|
|
|
- if (args.cellRange.colCount != 1 || args.cellRange.col != 0 || !(me.currentRationItem)) {
|
|
|
+ if (args.cellRange.colCount != 1 || args.cellRange.col != 0 || !(me.curRation)) {
|
|
|
args.cancel = true;
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
onClipboardPasted: function(e, info) {
|
|
|
var me = rationCoeOprObj;
|
|
|
if (me.libID) {
|
|
|
+ // 修改第一列(编号)
|
|
|
if (info.cellRange.col == 0) {
|
|
|
- var tmpCoeIDs = sheetCommonObj.analyzePasteData({header:[{dataCode: "ID"}] }, info);
|
|
|
- var IDs = [];
|
|
|
- for (var i = 0; i < tmpCoeIDs.length; i++) {
|
|
|
- IDs.push(tmpCoeIDs[i]);
|
|
|
- }
|
|
|
- me.addCoeItems(IDs);
|
|
|
+ var coeIDs = [];
|
|
|
+ var temp = sheetCommonObj.analyzePasteData({header:[{dataCode: "ID"}] }, info);
|
|
|
+ for (let obj of temp) {
|
|
|
+ coeIDs.push(obj.ID);
|
|
|
+ };
|
|
|
+ me.addCoeItems(coeIDs);
|
|
|
} else {
|
|
|
- //修改用量
|
|
|
+ //修改其它列。
|
|
|
}
|
|
|
}
|
|
|
- },*/
|
|
|
- onCellEditEnd: function(sender, args){
|
|
|
+ },
|
|
|
+
|
|
|
+ onEditEnded: function(sender, args){
|
|
|
var me = rationCoeOprObj;
|
|
|
if (args.col == 0) { // 编号列
|
|
|
- if (args.editingText == null || args.editingText.trim() == "") { //delete
|
|
|
- var cacheArr = me.cache["_Coe_" + me.currentRationItem.ID];
|
|
|
- if (cacheArr) {
|
|
|
- if (args.row < cacheArr.length) {
|
|
|
- cacheArr.splice(args.row, 1);
|
|
|
- me.updateRationItem();
|
|
|
+ //delete
|
|
|
+ if (args.editingText == null || args.editingText.trim() == "") {
|
|
|
+ var curCache = me.cache["_Coe_" + me.curRation.ID];
|
|
|
+ if (curCache) {
|
|
|
+ if (args.row < curCache.length) {
|
|
|
+ curCache.splice(args.row, 1);
|
|
|
+ me.updateCurRation();
|
|
|
sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
|
|
|
- me.showCoeItems(me.currentRationItem.ID);
|
|
|
+ me.showCoeItems(me.curRation.ID);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if (me.libID) {
|
|
|
- var coeIDs = [];
|
|
|
- coeIDs.push(args.editingText.trim());
|
|
|
- me.addCoeItems(coeIDs, me.libID);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ var ID = args.editingText.trim();
|
|
|
+ if (!isNaN(ID)) {
|
|
|
+ me.addCoeItems([ID]);
|
|
|
+ };
|
|
|
+ };
|
|
|
+ };
|
|
|
+ };
|
|
|
+ },
|
|
|
+
|
|
|
+ onRangeChanged: function(sender, args) {
|
|
|
+ if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
|
|
|
+ if (!confirm(`确定要删除选中的 ${args.rowCount} 条附注条件吗?`)){return; }
|
|
|
+ var me = rationCoeOprObj;
|
|
|
+ if (args.col == 0) {
|
|
|
+ var curCache = me.cache["_Coe_" + me.curRation.ID];
|
|
|
+ if (curCache) {
|
|
|
+ for (var i = args.rowCount - 1; i >= 0; i--) {
|
|
|
+ if (args.row + i < curCache.length) {
|
|
|
+ curCache.splice(args.row + i, 1);
|
|
|
+ };
|
|
|
+ };
|
|
|
+ me.updateCurRation();
|
|
|
+ sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
|
|
|
+ me.showCoeItems(me.curRation.ID);
|
|
|
+ };
|
|
|
+ };
|
|
|
+ };
|
|
|
},
|
|
|
|
|
|
addCoeItems: function(coeIDs) {
|
|
|
var me = this;
|
|
|
- $.ajax({
|
|
|
- type:"POST",
|
|
|
- url:"api/getCoeItemsByIDs",
|
|
|
- data: {"data": JSON.stringify({"libID": me.libID, "coeIDs": coeIDs})},
|
|
|
- dataType:"json",
|
|
|
- cache:false,
|
|
|
- timeout:5000,
|
|
|
- success:function(result){
|
|
|
- sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
|
|
|
- if (result) {
|
|
|
- var rstArr = [], newAddArr = [];
|
|
|
- for (var i = 0; i < result.data.length; i++) {
|
|
|
- rstArr.push(result.data[i]);
|
|
|
+ sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
|
|
|
+
|
|
|
+ var curCache = me.cache["_Coe_" + me.curRation.ID];
|
|
|
+ var temp = [];
|
|
|
+ if (curCache) {
|
|
|
+ for (var i = 0; i < coeIDs.length; i++) {
|
|
|
+ var isExist = false;
|
|
|
+ for (let obj of curCache) {
|
|
|
+ if (obj.ID == coeIDs[i]) {
|
|
|
+ isExist = true;
|
|
|
+ break;
|
|
|
};
|
|
|
- if (me.cache["_Coe_" + me.currentRationItem.ID]) {
|
|
|
- var cacheArr = me.cache["_Coe_" + me.currentRationItem.ID];
|
|
|
- for (var i = 0; i < rstArr.length; i++) {
|
|
|
- var hasDup = false;
|
|
|
- for (var j = 0; j < cacheArr.length; j++) {
|
|
|
- if (cacheArr[j] == rstArr[i]) {
|
|
|
- hasDup = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!hasDup) {
|
|
|
- newAddArr.push(rstArr[i]);
|
|
|
- }
|
|
|
+ };
|
|
|
+ if (!isExist) {
|
|
|
+ temp.push(coeIDs[i]);
|
|
|
+ };
|
|
|
+ };
|
|
|
+ }else{
|
|
|
+ for (let obj of coeIDs){temp.push(obj)};
|
|
|
+ };
|
|
|
+
|
|
|
+ if(temp.length == 0){
|
|
|
+ me.showCoeItems(me.curRation.ID);
|
|
|
+ sheetCommonObj.lockCells(me.sheet, me.setting);
|
|
|
+ }else{
|
|
|
+ $.ajax({
|
|
|
+ type:"POST",
|
|
|
+ url:"api/getCoeItemsByIDs",
|
|
|
+ data: {"data": JSON.stringify({"libID": me.libID, "coeIDs": temp})},
|
|
|
+ dataType:"json",
|
|
|
+ cache:false,
|
|
|
+ timeout:5000,
|
|
|
+ success:function(result){
|
|
|
+ if (result) {
|
|
|
+ var rstArr = [];
|
|
|
+ for (let obj of result.data){rstArr.push(obj)};
|
|
|
+ if (curCache) {
|
|
|
+ curCache = curCache.concat(rstArr);
|
|
|
+ }else{
|
|
|
+ curCache = rstArr;
|
|
|
}
|
|
|
- cacheArr.sort(function(a, b) {
|
|
|
+
|
|
|
+ curCache.sort(function(a, b) {
|
|
|
var rst = 0;
|
|
|
- if (a > b) rst = 1
|
|
|
- else if (a < b) rst = -1;
|
|
|
+ if (a.ID > b.ID) rst = 1
|
|
|
+ else if (a.ID < b.ID) rst = -1;
|
|
|
return rst;
|
|
|
});
|
|
|
- me.cache["_Coe_" + me.currentRationItem.ID] = cacheArr.concat(newAddArr);
|
|
|
- }
|
|
|
- me.showCoeItems(me.currentRationItem.ID);
|
|
|
- if (newAddArr.length > 0) {
|
|
|
- me.updateRationItem();
|
|
|
- }
|
|
|
+
|
|
|
+ me.cache["_Coe_" + me.curRation.ID] = curCache;
|
|
|
+ me.updateCurRation();
|
|
|
+ me.showCoeItems(me.curRation.ID);
|
|
|
+ };
|
|
|
+ sheetCommonObj.lockCells(me.sheet, me.setting);
|
|
|
+ },
|
|
|
+ error:function(err){
|
|
|
+ alert(err);
|
|
|
}
|
|
|
- sheetCommonObj.lockCells(me.sheet, me.setting);
|
|
|
- },
|
|
|
- error:function(err){
|
|
|
- alert(err);
|
|
|
- }
|
|
|
- })
|
|
|
+ });
|
|
|
+ };
|
|
|
},
|
|
|
|
|
|
- updateRationItem: function() {
|
|
|
- var me = this, updateArr = [];
|
|
|
- if (me.currentRationItem) {
|
|
|
- me.currentRationItem.rationCoeList = me.getCoeIDsArr();
|
|
|
- updateArr.push(me.currentRationItem);
|
|
|
- rationOprObj.mixUpdateRequest(updateArr, [], []);
|
|
|
- }
|
|
|
- },
|
|
|
+ getCoeItems: function(ration) {
|
|
|
+ var me = this;
|
|
|
+ me.curRation = ration;
|
|
|
|
|
|
- getCoeIDsArr: function(){
|
|
|
- var me = this, rst = [];
|
|
|
- if (me.currentRationItem && me.cache["_Coe_" + me.currentRationItem.ID]) {
|
|
|
- var cacheArr = me.cache["_Coe_" + me.currentRationItem.ID];
|
|
|
- for (var i = 0; i < cacheArr.length; i++) {
|
|
|
- rst.push(cacheArr[i].ID);
|
|
|
- }
|
|
|
- }
|
|
|
- return rst;
|
|
|
- },
|
|
|
+ if (ration == undefined || ration.rationCoeList == undefined ||
|
|
|
+ ration.rationCoeList.length == 0){return;};
|
|
|
|
|
|
- getCoeItems: function(rationItem) {
|
|
|
- var me = this, rationID = rationItem.ID, rationCoeList = rationItem.rationCoeList;
|
|
|
- if (rationCoeList == undefined){return;};
|
|
|
+ var coeList = ration.rationCoeList;
|
|
|
+ var curCache = me.cache["_Coe_" + ration.ID];
|
|
|
|
|
|
- me.currentRationItem = rationItem;
|
|
|
- //alert('0009 ' + JSON.stringify(me.cache));
|
|
|
- //alert('0010 ' + JSON.stringify(me.cache["_Coe_" + rationID]));
|
|
|
- //alert('0011 ' + JSON.stringify(me.libID));
|
|
|
- if (me.cache["_Coe_" + rationID]) {
|
|
|
- me.showCoeItems(rationID);
|
|
|
+ if (curCache && curCache.length > 0) {
|
|
|
+ me.showCoeItems(ration.ID);
|
|
|
sheetCommonObj.lockCells(me.sheet, me.setting);
|
|
|
} else {
|
|
|
+ var data = {"libID": me.libID, "coeIDs": coeList};
|
|
|
$.ajax({
|
|
|
type:"POST",
|
|
|
url:"api/getCoeItemsByIDs",
|
|
|
- data: {"data": JSON.stringify({"libID": me.libID, "coeIDs": rationCoeList})},
|
|
|
+ data: {"data": JSON.stringify(data)},
|
|
|
dataType:"json",
|
|
|
cache:false,
|
|
|
timeout:5000,
|
|
|
success:function(result){
|
|
|
sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
|
|
|
-
|
|
|
if (result.data) {
|
|
|
- var cacheArr = [];
|
|
|
- for (var i = 0; i < result.data.length; i++) {
|
|
|
- for (var j = 0; j < rationCoeList.length; j++) {
|
|
|
- if (rationCoeList[j] == result.data[i].ID) {
|
|
|
- cacheArr.push(result.data[i]);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ var tempResult = [];
|
|
|
+ for (let obj of result.data) {
|
|
|
+ tempResult.push(obj);
|
|
|
};
|
|
|
- me.cache["_Coe_" + rationID] = cacheArr;
|
|
|
- me.showCoeItems(rationID);
|
|
|
+
|
|
|
+ me.cache["_Coe_" + ration.ID] = tempResult;
|
|
|
+
|
|
|
+ me.showCoeItems(ration.ID);
|
|
|
}
|
|
|
sheetCommonObj.lockCells(me.sheet, me.setting);
|
|
|
},
|
|
|
error:function(err){
|
|
|
alert(err);
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
+ });
|
|
|
+ };
|
|
|
},
|
|
|
+
|
|
|
showCoeItems: function(rationID) {
|
|
|
var me = this;
|
|
|
- if (me.cache["_Coe_" + rationID]) {
|
|
|
- sheetCommonObj.showData(me.sheet, me.setting, me.cache["_Coe_" + rationID]);
|
|
|
+ var curCache = me.cache["_Coe_" + rationID];
|
|
|
+ if (curCache) {
|
|
|
+ sheetCommonObj.showData(me.sheet, me.setting, curCache);
|
|
|
}
|
|
|
+ },
|
|
|
+
|
|
|
+ updateCurRation: function() {
|
|
|
+ var me = this, updateArr = [];
|
|
|
+ if (me.curRation) {
|
|
|
+ var rst = [];
|
|
|
+ var curCache = me.cache["_Coe_" + me.curRation.ID];
|
|
|
+ if (curCache) {
|
|
|
+ for (let obj of curCache) {
|
|
|
+ rst.push(obj.ID);
|
|
|
+ };
|
|
|
+ me.curRation.rationCoeList = rst;
|
|
|
+ updateArr.push(me.curRation);
|
|
|
+ rationOprObj.mixUpdateRequest(updateArr, [], []);
|
|
|
+ };
|
|
|
+ };
|
|
|
}
|
|
|
}
|