|
@@ -15,6 +15,7 @@ var rationOprObj = {
|
|
currentRations: {},
|
|
currentRations: {},
|
|
currentEditingRation: null,
|
|
currentEditingRation: null,
|
|
currentSectionId: -1,
|
|
currentSectionId: -1,
|
|
|
|
+ rationsCodes: [],
|
|
setting: {
|
|
setting: {
|
|
header:[
|
|
header:[
|
|
{headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
|
|
{headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
|
|
@@ -40,11 +41,15 @@ var rationOprObj = {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
buildSheet: function(container) {
|
|
buildSheet: function(container) {
|
|
|
|
+ let rationRepId = getQueryString("repository");
|
|
var me = rationOprObj;
|
|
var me = rationOprObj;
|
|
me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
|
|
me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
|
|
|
|
+ me.workBook.options.showHorizontalScrollbar = true;
|
|
|
|
+ me.getRationsCodes(rationRepId);
|
|
me.rationDelOpr();
|
|
me.rationDelOpr();
|
|
me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
|
|
me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
|
|
me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
|
|
me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
|
|
|
|
+ me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
|
|
me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
|
|
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.EditEnded, me.onCellEditEnd);
|
|
//me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
|
|
//me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
|
|
@@ -121,15 +126,12 @@ var rationOprObj = {
|
|
return cacheSection;
|
|
return cacheSection;
|
|
},
|
|
},
|
|
rationDelOpr: function () {
|
|
rationDelOpr: function () {
|
|
|
|
+ console.log(`rebuildDelete`);
|
|
let me = rationOprObj;
|
|
let me = rationOprObj;
|
|
me.workBook.commandManager().register('rationDelete', function () {
|
|
me.workBook.commandManager().register('rationDelete', function () {
|
|
let rationSheet = me.workBook.getActiveSheet();
|
|
let rationSheet = me.workBook.getActiveSheet();
|
|
let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
|
|
let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
|
|
let cacheSection = me.getCache();
|
|
let cacheSection = me.getCache();
|
|
- console.log(`sels`);
|
|
|
|
- console.log(sels);
|
|
|
|
- console.log(`cache`);
|
|
|
|
- console.log(cacheSection);
|
|
|
|
if(sels.length > 0){
|
|
if(sels.length > 0){
|
|
for(let sel = 0; sel < sels.length; sel++){
|
|
for(let sel = 0; sel < sels.length; sel++){
|
|
if(sels[sel].colCount === me.setting.header.length){
|
|
if(sels[sel].colCount === me.setting.header.length){
|
|
@@ -137,6 +139,9 @@ var rationOprObj = {
|
|
for(let i = 0; i < sels[sel].rowCount; i++){
|
|
for(let i = 0; i < sels[sel].rowCount; i++){
|
|
if(sels[sel].row + i < cacheSection.length){
|
|
if(sels[sel].row + i < cacheSection.length){
|
|
removeArr.push(cacheSection[sels[sel].row + i].ID);
|
|
removeArr.push(cacheSection[sels[sel].row + i].ID);
|
|
|
|
+ me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code), 1);
|
|
|
|
+ console.log(`me.rationsCodes`);
|
|
|
|
+ console.log(me.rationsCodes);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -157,7 +162,7 @@ var rationOprObj = {
|
|
if(cacheSection){
|
|
if(cacheSection){
|
|
for(let i =0; i < sels[sel].rowCount; i++){
|
|
for(let i =0; i < sels[sel].rowCount; i++){
|
|
if(sels[sel].row + i < cacheSection.length){
|
|
if(sels[sel].row + i < cacheSection.length){
|
|
- for(let col = sels[sel].col; col < sels[sel].col + sels[sel].colCount - 1; col++){
|
|
|
|
|
|
+ for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
|
|
if(lockCols.indexOf(col) === -1){
|
|
if(lockCols.indexOf(col) === -1){
|
|
cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
|
|
cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
|
|
}
|
|
}
|
|
@@ -170,12 +175,8 @@ var rationOprObj = {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- console.log(`updateArr`);
|
|
|
|
- console.log(updateArr);
|
|
|
|
- console.log(`removeArr`);
|
|
|
|
- console.log(removeArr);
|
|
|
|
if(updateArr.length > 0 || removeArr.length > 0){
|
|
if(updateArr.length > 0 || removeArr.length > 0){
|
|
- //me.mixUpdateRequest(updateArr, [], removeArr);
|
|
|
|
|
|
+ me.mixUpdateRequest(updateArr, [], removeArr);
|
|
}
|
|
}
|
|
|
|
|
|
});
|
|
});
|
|
@@ -187,10 +188,6 @@ var rationOprObj = {
|
|
if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
|
|
if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
|
|
var me = rationOprObj, updateArr = [], removeArr = [];
|
|
var me = rationOprObj, updateArr = [], removeArr = [];
|
|
var cacheSection = me.getCache();
|
|
var cacheSection = me.getCache();
|
|
- console.log(`cacheSection`);
|
|
|
|
- console.log(cacheSection);
|
|
|
|
- console.log(`args`);
|
|
|
|
- console.log(args);
|
|
|
|
if (cacheSection) {
|
|
if (cacheSection) {
|
|
for (var i = 0; i < args.rowCount; i++) {
|
|
for (var i = 0; i < args.rowCount; i++) {
|
|
//var hasUpdate = false, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row + i),
|
|
//var hasUpdate = false, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row + i),
|
|
@@ -229,13 +226,51 @@ var rationOprObj = {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ onEnterCell: function (sender, args) {
|
|
|
|
+ let me = rationOprObj;
|
|
|
|
+ me.cellRowIdx = args.row;
|
|
|
|
+ let isHasData = false;
|
|
|
|
+ if(me.addRationItem){
|
|
|
|
+ for(let i=0; i<me.setting.header.length; i++){
|
|
|
|
+ if(me.addRationItem[me.setting.header[i].dataCode]){
|
|
|
|
+ isHasData = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(isHasData){
|
|
|
|
+ if(me.editingRowIdx !== me.cellRowIdx) {
|
|
|
|
+ let focusToCol = !me.addRationItem.code ? 0 : -1;
|
|
|
|
+ // else {
|
|
|
|
+ if(focusToCol !== -1){
|
|
|
|
+ $('#rationAlertBtn').click();
|
|
|
|
+ me.workBook.getSheet(0).options.isProtected = true;
|
|
|
|
+ $('#rationAlertCac').click(function () {
|
|
|
|
+ me.workBook.getSheet(0).options.isProtected = false;
|
|
|
|
+ me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
|
|
|
|
+ });
|
|
|
|
+ $('#rationAlertCls').click(function () {
|
|
|
|
+ me.workBook.getSheet(0).options.isProtected = false;
|
|
|
|
+ me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
|
|
|
|
+ });
|
|
|
|
+ $('#rationAlertCof').click(function () {
|
|
|
|
+ me.workBook.getSheet(0).options.isProtected = false;
|
|
|
|
+ me.addRationItem = null;
|
|
|
|
+ for(let col=0; col<me.setting.header.length; col++){
|
|
|
|
+ me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value(me.currentEditingRation[me.setting.header[col].dataCode]);
|
|
|
|
+ }
|
|
|
|
+ me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ // }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
onCellEditStart: function(sender, args) {
|
|
onCellEditStart: function(sender, args) {
|
|
var me = rationOprObj;
|
|
var me = rationOprObj;
|
|
//var rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
|
|
//var rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
|
|
var rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
|
|
var rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
|
|
me.currentEditingRation = rObj;
|
|
me.currentEditingRation = rObj;
|
|
- console.log(`currentEditingRation`);
|
|
|
|
- console.log(me.currentEditingRation);
|
|
|
|
var cacheSection = me.getCache();
|
|
var cacheSection = me.getCache();
|
|
if (cacheSection) {
|
|
if (cacheSection) {
|
|
for (var j = 0; j < cacheSection.length; j++) {
|
|
for (var j = 0; j < cacheSection.length; j++) {
|
|
@@ -251,16 +286,50 @@ var rationOprObj = {
|
|
var me = rationOprObj, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
|
|
var me = rationOprObj, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
|
|
updateArr = [], addArr = [];
|
|
updateArr = [], addArr = [];
|
|
let dataCode = me.setting.header[args.col].dataCode;
|
|
let dataCode = me.setting.header[args.col].dataCode;
|
|
- if (me.currentEditingRation["ID"] && me.currentEditingRation[dataCode] !== args.editingText) {
|
|
|
|
|
|
+ me.editingRowIdx = args.row;
|
|
|
|
+ if (me.currentEditingRation["ID"]) {
|
|
rObj["ID"] = me.currentEditingRation["ID"];
|
|
rObj["ID"] = me.currentEditingRation["ID"];
|
|
- updateArr.push(rObj);
|
|
|
|
|
|
+ //updateArr.push(rObj);
|
|
|
|
+ for(let col =0; col< me.setting.header.length; col++){
|
|
|
|
+ if(me.currentEditingRation[me.setting.header[col].dataCode] !== rObj[me.setting.header[col].dataCode]){
|
|
|
|
+ me.addRationItem = rObj;
|
|
|
|
+ if(rObj[me.setting.header[0].dataCode]){
|
|
|
|
+ updateArr.push(rObj);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
} else if(!me.currentEditingRation["ID"]) {
|
|
} else if(!me.currentEditingRation["ID"]) {
|
|
if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
|
|
if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
|
|
- addArr.push(rObj);
|
|
|
|
|
|
+ //addArr.push(rObj);
|
|
|
|
+ me.addRationItem = rObj;
|
|
|
|
+ if(rObj.code){
|
|
|
|
+ if(me.rationsCodes.indexOf(rObj.code) === -1){
|
|
|
|
+ addArr.push(rObj);
|
|
|
|
+ me.rationsCodes.push(rObj.code);
|
|
|
|
+ me.addRationItem = null;
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ $('#alertModalBtn').click();
|
|
|
|
+ me.workBook.getSheet(0).options.isProtected = true;
|
|
|
|
+ $('#alertModalCls').click(function () {
|
|
|
|
+ me.workBook.getSheet(0).options.isProtected = false;
|
|
|
|
+ me.addRationItem.code = '';
|
|
|
|
+ me.workBook.getSheet(0).setValue(args.row, args.col, '');
|
|
|
|
+ me.workBook.getSheet(0).setActiveCell(args.row, args.col);
|
|
|
|
+ });
|
|
|
|
+ $('#alertModalCof').click(function () {
|
|
|
|
+ me.workBook.getSheet(0).options.isProtected = false;
|
|
|
|
+ me.addRationItem.code = '';
|
|
|
|
+ me.workBook.getSheet(0).setValue(args.row, args.col, '');
|
|
|
|
+ me.workBook.getSheet(0).setActiveCell(args.row, args.col);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- me.currentEditingRation = null;
|
|
|
|
if (updateArr.length > 0 || addArr.length > 0) {
|
|
if (updateArr.length > 0 || addArr.length > 0) {
|
|
|
|
+ me.currentEditingRation = null;
|
|
me.mixUpdateRequest(updateArr, addArr, []);
|
|
me.mixUpdateRequest(updateArr, addArr, []);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -312,6 +381,20 @@ var rationOprObj = {
|
|
//me.mixUpdateRequest(updateArr, addArr, []);
|
|
//me.mixUpdateRequest(updateArr, addArr, []);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ getRationsCodes: function (repId) {
|
|
|
|
+ let me = rationOprObj;
|
|
|
|
+ $.ajax({
|
|
|
|
+ type: 'post',
|
|
|
|
+ url: 'api/getRationsCodes',
|
|
|
|
+ data: {data: JSON.stringify({repId: repId})},
|
|
|
|
+ dataType: 'json',
|
|
|
|
+ success: function (result) {
|
|
|
|
+ if(!result.error){
|
|
|
|
+ me.rationsCodes = result.data;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
mixUpdateRequest: function(updateArr, addArr, removeIds) {
|
|
mixUpdateRequest: function(updateArr, addArr, removeIds) {
|
|
var me = rationOprObj;
|
|
var me = rationOprObj;
|
|
$.ajax({
|
|
$.ajax({
|