|
@@ -9,6 +9,7 @@ $("#gongliao").click(function(){
|
|
|
var rationOprObj = {
|
|
|
workBook: null,
|
|
|
currentRations: {},
|
|
|
+ currentEditingRation: null,
|
|
|
currentSectionId: -1,
|
|
|
setting: {
|
|
|
header:[
|
|
@@ -33,6 +34,58 @@ var rationOprObj = {
|
|
|
me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
|
|
|
me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
|
|
|
me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
|
|
|
+ me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
|
|
|
+ me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
|
|
|
+ me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
|
|
|
+ },
|
|
|
+ onRangeChanged: function(sender, args) {
|
|
|
+ if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
|
|
|
+ var me = rationOprObj, updateArr = [], addArr = [];
|
|
|
+ var cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
|
|
|
+ if (cacheSection) {
|
|
|
+ for (var i = 0; i < args.rowCount; i++) {
|
|
|
+ var hasUpdate = false, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row + i);
|
|
|
+ for (var j = 0; j < cacheSection.length; j++) {
|
|
|
+ if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
|
|
|
+ rObj["ID"] = cacheSection[j]["ID"];
|
|
|
+ hasUpdate = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (hasUpdate) {
|
|
|
+ updateArr.push(rObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //me.mixUpdateRequest(updateArr, addArr);
|
|
|
+ //removeRationItems
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onCellEditStart: function(sender, args) {
|
|
|
+ var me = rationOprObj;
|
|
|
+ var rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
|
|
|
+ me.currentEditingRation = rObj;
|
|
|
+ var cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
|
|
|
+ if (cacheSection) {
|
|
|
+ for (var j = 0; j < cacheSection.length; j++) {
|
|
|
+ if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
|
|
|
+ rObj["ID"] = cacheSection[j]["ID"];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onCellEditEnd: function(sender, args) {
|
|
|
+ var me = rationOprObj, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row),
|
|
|
+ updateArr = [], addArr = [];
|
|
|
+ if (me.currentEditingRation["ID"]) {
|
|
|
+ rObj["ID"] = me.currentEditingRation["ID"];
|
|
|
+ updateArr.push(rObj);
|
|
|
+ } else {
|
|
|
+ addArr.push(rObj);
|
|
|
+ }
|
|
|
+ me.currentEditingRation = null;
|
|
|
+ me.mixUpdateRequest(updateArr, addArr);
|
|
|
},
|
|
|
onClipboardPasting: function(sender, args) {
|
|
|
var me = rationOprObj;
|
|
@@ -65,40 +118,54 @@ var rationOprObj = {
|
|
|
}
|
|
|
};
|
|
|
if (updateArr.length > 0 || addArr.length > 0) {
|
|
|
- $.ajax({
|
|
|
- type:"POST",
|
|
|
- url:"api/mixUpdateRationItems",
|
|
|
- data:{"sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr)},
|
|
|
- dataType:"json",
|
|
|
- cache:false,
|
|
|
- timeout:5000,
|
|
|
- success:function(result){
|
|
|
- if (result.err) {
|
|
|
- alert(err);
|
|
|
- me.getRationItems(me.currentSectionId);
|
|
|
- } else {
|
|
|
- if (!(me.currentRations["_SEC_ID_" + me.currentSectionId])) {
|
|
|
- me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
|
|
|
- cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
|
|
|
- }
|
|
|
- if (addArr.length > 0) {
|
|
|
- me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
|
|
|
- cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
|
|
|
- }
|
|
|
- for (var i = 0; i < updateArr.length; i++) {
|
|
|
+ me.mixUpdateRequest(updateArr, addArr);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mixUpdateRequest: function(updateArr, addArr) {
|
|
|
+ var me = rationOprObj;
|
|
|
+ $.ajax({
|
|
|
+ type:"POST",
|
|
|
+ url:"api/mixUpdateRationItems",
|
|
|
+ data:{"sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr)},
|
|
|
+ dataType:"json",
|
|
|
+ cache:false,
|
|
|
+ timeout:5000,
|
|
|
+ success:function(result){
|
|
|
+ if (result.err) {
|
|
|
+ alert(err);
|
|
|
+ me.getRationItems(me.currentSectionId);
|
|
|
+ } else {
|
|
|
+ var cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
|
|
|
+ if (!(me.currentRations["_SEC_ID_" + me.currentSectionId])) {
|
|
|
+ me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
|
|
|
+ cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
|
|
|
+ }
|
|
|
+ if (addArr.length > 0) {
|
|
|
+ me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
|
|
|
+ cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
|
|
|
+ }
|
|
|
+ if (result.data.ops && result.data.ops.length > 0) {
|
|
|
+ for (var i = 0; i < result.data.ops.length; i++) {
|
|
|
for (var j = 0; j < cacheSection.length; j++) {
|
|
|
- if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
|
|
|
- cacheSection[j] = updateArr[i];
|
|
|
+ if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
|
|
|
+ cacheSection[j]["ID"] = result.data.ops[i]["ID"];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- me.showRationItems(me.currentSectionId);
|
|
|
}
|
|
|
- },
|
|
|
- error:function(){
|
|
|
+ for (var i = 0; i < updateArr.length; i++) {
|
|
|
+ for (var j = 0; j < cacheSection.length; j++) {
|
|
|
+ if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
|
|
|
+ cacheSection[j] = updateArr[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ me.showRationItems(me.currentSectionId);
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
+ },
|
|
|
+ error:function(){
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
getRationItems: function(sectionID){
|
|
|
if (sectionID != -1) {
|
|
@@ -118,8 +185,10 @@ var rationOprObj = {
|
|
|
if (result) {
|
|
|
me.currentRations["_SEC_ID_" + sectionID] = result.data;
|
|
|
me.showRationItems(sectionID);
|
|
|
+ sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
|
|
|
+ } else {
|
|
|
+ sheetCommonObj.shieldAllCells(me.workBook.getSheet(0), me.setting);
|
|
|
}
|
|
|
-
|
|
|
},
|
|
|
error:function(err){
|
|
|
alert(err);
|