|
@@ -31,7 +31,126 @@ var rationCoeOprObj = {
|
|
|
me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
|
|
|
me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
|
|
|
me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
|
|
|
- // me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
|
|
|
+ //右键
|
|
|
+ me.onContextmenuOpr();
|
|
|
+ },
|
|
|
+
|
|
|
+ isDef: function (v) {
|
|
|
+ return v !== undefined && v !== null;
|
|
|
+ },
|
|
|
+
|
|
|
+ onContextmenuOpr: function () {
|
|
|
+ let me = rationCoeOprObj;
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#rdSpread',
|
|
|
+ build: function($triggerElement, e){
|
|
|
+ //控制允许右键菜单在哪个位置出现
|
|
|
+ let sheet = me.sheet;
|
|
|
+ let offset = $("#rdSpread").offset(),
|
|
|
+ x = e.pageX - offset.left,
|
|
|
+ y = e.pageY - offset.top;
|
|
|
+ let target = sheet.hitTest(x, y);
|
|
|
+ if(sheet.getParent().getActiveSheetIndex() === 2 && target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
|
|
|
+ let currentCache = me.isDef(me.cache["_Coe_" + me.curRation.ID]) ? me.cache["_Coe_" + me.curRation.ID] : [];
|
|
|
+ sheet.setActiveCell(target.row, target.col);
|
|
|
+ //控制按钮是否可用
|
|
|
+ let upDis = false,
|
|
|
+ downDis = false,
|
|
|
+ refDis = false;
|
|
|
+ if(target.row >= currentCache.length){
|
|
|
+ upDis = true;
|
|
|
+ downDis = true;
|
|
|
+ refDis = true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if(!me.isDef(currentCache[target.row - 1])){
|
|
|
+ upDis = true;
|
|
|
+ }
|
|
|
+ if(!me.isDef(currentCache[target.row + 1])){
|
|
|
+ downDis = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ callback: function(){},
|
|
|
+ items: {
|
|
|
+ "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
|
|
|
+ me.upMove(currentCache[target.row], currentCache[target.row - 1], {row: target.row - 1, col: target.col});
|
|
|
+ }},
|
|
|
+ "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
|
|
|
+ me.downMove(currentCache[target.row], currentCache[target.row + 1], {row: target.row + 1, col: target.col});
|
|
|
+ }},
|
|
|
+ "ref": {name: "添加到本节其他定额", disabled: refDis, icon: "fa-arrow-left", callback: function (key, opt) {
|
|
|
+ me.updateSectionRation(rationOprObj.currentRations["_SEC_ID_" + rationOprObj.currentSectionId], currentCache[target.row], function (updateArr) {
|
|
|
+ for(let i = 0, len = updateArr.length; i < len; i++){
|
|
|
+ let ration = updateArr[i];
|
|
|
+ let rationCoeList = updateArr[i].rationCoeList;
|
|
|
+ let newNo = 1;
|
|
|
+ for(let j = 0, jLen = rationCoeList.length; j < jLen; j++){
|
|
|
+ if(rationCoeList[j].no >= newNo){
|
|
|
+ newNo = rationCoeList[j].no + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let theCache = me.cache["_Coe_" + ration.ID];
|
|
|
+ if(theCache !== undefined && theCache !== null){
|
|
|
+ let newCoe = {};
|
|
|
+ for(let attr in currentCache[target.row]){
|
|
|
+ newCoe[attr] = currentCache[target.row][attr];
|
|
|
+ }
|
|
|
+ newCoe.no = newNo;
|
|
|
+ theCache.push(newCoe);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }}
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ upMove: function (thisObj, preObj, cell) {
|
|
|
+ let me = this;
|
|
|
+ let tempNo = thisObj.no;
|
|
|
+ thisObj.no = preObj.no;
|
|
|
+ preObj.no = tempNo;
|
|
|
+ //ajax
|
|
|
+ me.updateCurRation(function () {
|
|
|
+ me.showCoeItems(me.curRation.ID);
|
|
|
+ me.sheet.setActiveCell(cell.row, cell.col);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ downMove: function (thisObj, nextObj, cell) {
|
|
|
+ let me = this;
|
|
|
+ let tempNo = thisObj.no;
|
|
|
+ thisObj.no = nextObj.no;
|
|
|
+ nextObj.no = tempNo;
|
|
|
+ me.updateCurRation(function () {
|
|
|
+ me.showCoeItems(me.curRation.ID);
|
|
|
+ me.sheet.setActiveCell(cell.row, cell.col);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ //本节所有使用此条件
|
|
|
+ useAll: function (coe) {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ sortByNo: function (cache) {
|
|
|
+ cache.sort(function (a, b) {
|
|
|
+ let rst = 0;
|
|
|
+ if(a.no > b.no){
|
|
|
+ rst = 1;
|
|
|
+ }
|
|
|
+ else if(a.no < b.no){
|
|
|
+ rst = -1;
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
onClipboardPasting: function(sender, args) {
|
|
@@ -221,7 +340,11 @@ var rationCoeOprObj = {
|
|
|
success:function(result){
|
|
|
if (result) {
|
|
|
var rstArr = [];
|
|
|
- for (let obj of result.data){rstArr.push(obj)};
|
|
|
+ let newNo = curCache && curCache.length > 0 ? curCache[curCache.length - 1].no + 1 : 1;
|
|
|
+ for (let obj of result.data){
|
|
|
+ obj.no = newNo++;
|
|
|
+ rstArr.push(obj)
|
|
|
+ }
|
|
|
if (curCache) {
|
|
|
curCache = curCache.concat(rstArr);
|
|
|
}else{
|
|
@@ -254,12 +377,16 @@ var rationCoeOprObj = {
|
|
|
ration.rationCoeList.length == 0){return;};*/
|
|
|
|
|
|
var coeList = ration.rationCoeList;
|
|
|
+ let coeIDs = [];
|
|
|
+ for(let i = 0, len = coeList.length; i < len; i++){
|
|
|
+ coeIDs.push(coeList[i].ID);
|
|
|
+ }
|
|
|
var curCache = me.cache["_Coe_" + ration.ID];
|
|
|
if (curCache) {
|
|
|
me.showCoeItems(ration.ID);
|
|
|
//sheetCommonObj.lockCells(me.sheet, me.setting);
|
|
|
} else if(!curCache && typeof coeList !== 'undefined' && coeList.length > 0) {
|
|
|
- var data = {"libID": me.libID, "coeIDs": coeList};
|
|
|
+ var data = {"libID": me.libID, "coeIDs": coeIDs};
|
|
|
$.ajax({
|
|
|
type:"POST",
|
|
|
url:"api/getCoeItemsByIDs",
|
|
@@ -272,9 +399,16 @@ var rationCoeOprObj = {
|
|
|
if (result.data) {
|
|
|
var tempResult = [];
|
|
|
for (let obj of result.data) {
|
|
|
- tempResult.push(obj);
|
|
|
+ for(let i = 0, len = coeList.length; i < len; i++){
|
|
|
+ if(obj.ID === coeList[i].ID){
|
|
|
+ obj.no = coeList[i].no;
|
|
|
+ tempResult.push(obj);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
+
|
|
|
me.cache["_Coe_" + ration.ID] = tempResult;
|
|
|
|
|
|
me.showCoeItems(ration.ID);
|
|
@@ -295,8 +429,8 @@ var rationCoeOprObj = {
|
|
|
if (curCache) {
|
|
|
curCache.sort(function(a, b) {
|
|
|
var rst = 0;
|
|
|
- if (a.serialNo > b.serialNo) rst = 1
|
|
|
- else if (a.serialNo < b.serialNo) rst = -1;
|
|
|
+ if (a.no > b.no) rst = 1
|
|
|
+ else if (a.no < b.no) rst = -1;
|
|
|
return rst;
|
|
|
});
|
|
|
sheetsOprObj.showData(me.sheet, me.setting, curCache);
|
|
@@ -310,15 +444,45 @@ var rationCoeOprObj = {
|
|
|
var curCache = me.cache["_Coe_" + me.curRation.ID];
|
|
|
if (curCache) {
|
|
|
for (let obj of curCache) {
|
|
|
- rst.push(obj.ID);
|
|
|
- };
|
|
|
+ rst.push({ID: obj.ID, no: obj.no});
|
|
|
+ }
|
|
|
me.curRation.rationCoeList = rst;
|
|
|
updateArr.push(me.curRation);
|
|
|
rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
|
|
|
if(callback) callback();
|
|
|
});
|
|
|
- };
|
|
|
- };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ //更新本节所有定额
|
|
|
+ updateSectionRation: function (rations, coe, callback) {
|
|
|
+ let me = this;
|
|
|
+ let updateArr = [];
|
|
|
+ for(let i = 0, len = rations.length; i < len; i++){
|
|
|
+ if(rations[i].ID !== me.curRation.ID){
|
|
|
+ let rationCoeList = rations[i].rationCoeList;
|
|
|
+ let isExist = false;
|
|
|
+ let newNo = 1;
|
|
|
+ for(let j = 0, jLen = rationCoeList.length; j < jLen; j++){
|
|
|
+ if(rationCoeList[j].no >= newNo){
|
|
|
+ newNo = rationCoeList[j].no + 1;
|
|
|
+ }
|
|
|
+ if(rationCoeList[j].ID === coe.ID){
|
|
|
+ isExist = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!isExist){
|
|
|
+ rationCoeList.push({ID: coe.ID, no: newNo});
|
|
|
+ updateArr.push(rations[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(updateArr.length > 0){
|
|
|
+ rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
|
|
|
+ if(callback) callback(updateArr);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|