123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- /**
- * Created by CSL on 2017-06-08.
- */
- var rationCoeOprObj = {
- sheet: null,
- libID: null,
- curRation: null,
- cache: {},
- setting: {
- header:[
- {headerName:"编码",headerWidth:120,dataCode:"ID", dataType: "Number"},
- {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"},
- {headerName:"内容",headerWidth:300,dataCode:"content", dataType: "String"}
- ],
- view:{
- comboBox:[],
- lockColumns:[1,2]
- }
- },
- buildSheet: function(sheet) {
- var me = this;
- me.sheet = sheet;
- 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.onEditEnded);
- me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
- },
- onClipboardPasting: function(sender, args) {
- var me = rationCoeOprObj;
- 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 coeIDs = [];
- var temp = sheetCommonObj.analyzePasteData({header:[{dataCode: "ID"}] }, info);
- for (let obj of temp) {
- coeIDs.push(obj.ID);
- };
- me.addCoeItems(coeIDs);
- } else {
- //修改其它列。
- }
- }
- },
- onEditEnded: function(sender, args){
- var me = rationCoeOprObj;
- if (args.col == 0) { // 编号列
- //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.curRation.ID);
- }
- }
- } else {
- if (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;
- 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 (!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;
- }
- curCache.sort(function(a, b) {
- var rst = 0;
- if (a.ID > b.ID) rst = 1
- else if (a.ID < b.ID) rst = -1;
- return rst;
- });
- 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);
- }
- });
- };
- },
- getCoeItems: function(ration) {
- var me = this;
- me.curRation = ration;
- if (ration == undefined || ration.rationCoeList == undefined ||
- ration.rationCoeList.length == 0){return;};
- var coeList = ration.rationCoeList;
- var curCache = me.cache["_Coe_" + ration.ID];
- 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(data)},
- dataType:"json",
- cache:false,
- timeout:5000,
- success:function(result){
- sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
- if (result.data) {
- var tempResult = [];
- for (let obj of result.data) {
- tempResult.push(obj);
- };
- 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;
- 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, [], []);
- };
- };
- }
- }
|