|
@@ -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"}
|
|
|
],
|
|
@@ -20,9 +20,9 @@ var rationCoeOprObj = {
|
|
|
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')};
|
|
|
+ //alert('0000 初始化libID: ' + JSON.stringify(me.libID));
|
|
|
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);
|
|
@@ -33,63 +33,68 @@ var rationCoeOprObj = {
|
|
|
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];
|
|
|
+ var curCache = me.cache["_Coe_" + me.curRation.ID];
|
|
|
+ if (curCache) {
|
|
|
for (var i = args.rowCount - 1; i >= 0; i--) {
|
|
|
- if (args.row + i < cacheArr.length) {
|
|
|
- cacheArr.splice(args.row + i, 1);
|
|
|
- }
|
|
|
- }
|
|
|
- me.updateRationItem();
|
|
|
+ if (args.row + i < curCache.length) {
|
|
|
+ curCache.splice(args.row + i, 1);
|
|
|
+ };
|
|
|
+ };
|
|
|
+ me.updateCurRation();
|
|
|
sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
|
|
|
- me.showCoeItems(me.currentRationItem.ID);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ me.showCoeItems(me.curRation.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);
|
|
|
+ };
|
|
|
+ //alert('0009 ' + JSON.stringify(IDs));
|
|
|
+ me.addCoeItems(coeIDs);
|
|
|
} else {
|
|
|
//修改用量
|
|
|
}
|
|
|
}
|
|
|
- },*/
|
|
|
+ },
|
|
|
onCellEditEnd: 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]);
|
|
|
+ };
|
|
|
+ };
|
|
|
+ };
|
|
|
+ };
|
|
|
},
|
|
|
|
|
|
addCoeItems: function(coeIDs) {
|
|
@@ -105,36 +110,38 @@ var rationCoeOprObj = {
|
|
|
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]);
|
|
|
- };
|
|
|
- if (me.cache["_Coe_" + me.currentRationItem.ID]) {
|
|
|
- var cacheArr = me.cache["_Coe_" + me.currentRationItem.ID];
|
|
|
+ for (let obj of result.data){rstArr.push(obj)};
|
|
|
+
|
|
|
+ var curCache = me.cache["_Coe_" + me.curRation.ID];
|
|
|
+ if (curCache) {
|
|
|
for (var i = 0; i < rstArr.length; i++) {
|
|
|
var hasDup = false;
|
|
|
- for (var j = 0; j < cacheArr.length; j++) {
|
|
|
- if (cacheArr[j] == rstArr[i]) {
|
|
|
+ for (let obj of curCache) {
|
|
|
+ if (obj.ID == rstArr[i].ID) {
|
|
|
hasDup = true;
|
|
|
break;
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
if (!hasDup) {
|
|
|
newAddArr.push(rstArr[i]);
|
|
|
- }
|
|
|
- }
|
|
|
- cacheArr.sort(function(a, b) {
|
|
|
+ };
|
|
|
+ };
|
|
|
+ curCache.sort(function(a, b) {
|
|
|
var rst = 0;
|
|
|
if (a > b) rst = 1
|
|
|
else if (a < b) 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.concat(newAddArr);
|
|
|
+ if (newAddArr.length > 0) {
|
|
|
+ me.updateCurRation();
|
|
|
+ };
|
|
|
+ }else{
|
|
|
+ me.cache["_Coe_" + me.curRation.ID] = rstArr;
|
|
|
+ me.updateCurRation();
|
|
|
+ };
|
|
|
+ me.showCoeItems(me.curRation.ID);
|
|
|
+ };
|
|
|
sheetCommonObj.lockCells(me.sheet, me.setting);
|
|
|
},
|
|
|
error:function(err){
|
|
@@ -143,73 +150,74 @@ var rationCoeOprObj = {
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- updateRationItem: function() {
|
|
|
+ updateCurRation: function() {
|
|
|
var me = this, updateArr = [];
|
|
|
- if (me.currentRationItem) {
|
|
|
- me.currentRationItem.rationCoeList = me.getCoeIDsArr();
|
|
|
- updateArr.push(me.currentRationItem);
|
|
|
- rationOprObj.mixUpdateRequest(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, [], []);
|
|
|
+ };
|
|
|
+ };
|
|
|
},
|
|
|
|
|
|
- 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;
|
|
|
- },
|
|
|
+ getCoeItems: function(ration) {
|
|
|
+ var me = this;
|
|
|
+ me.curRation = ration;
|
|
|
+
|
|
|
+ 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);
|
|
|
+ //alert('0001 缓存:' + JSON.stringify(curCache));
|
|
|
+ if (curCache && curCache.length > 0) {
|
|
|
+ me.showCoeItems(ration.ID);
|
|
|
sheetCommonObj.lockCells(me.sheet, me.setting);
|
|
|
} else {
|
|
|
+ var data = {"libID": me.libID, "coeIDs": coeList};
|
|
|
+ //alert('0002 进入后台:' + JSON.stringify(data));
|
|
|
$.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);
|
|
|
-
|
|
|
+ //alert('0003 后台结果:' + JSON.stringify(result.data));
|
|
|
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);
|
|
|
}
|
|
|
+ rationOprObj.workBook.focus(true);
|
|
|
}
|
|
|
}
|