123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- /**
- * Created by CSL on 2017-06-14.
- */
- var rationAssistOprObj = {
- sheet: null,
- libID: null,
- ration: null,
- setting: {
- header:[
- {headerName:"调整名称",headerWidth:200,dataCode:"name", dataType: "String", hAlign: "left"},
- {headerName:"辅助定额号",headerWidth:120,dataCode:"assistCode", dataType: "String", hAlign: "center"},
- {headerName:"标准值",headerWidth:100,dataCode:"stdValue", dataType: "String", hAlign: "right"},
- {headerName:"步距",headerWidth:100,dataCode:"stepValue", dataType: "String", hAlign: "right"},
- {headerName:"精度",headerWidth:80,dataCode:"decimal", dataType: "String", hAlign: "right"},
- {headerName:"进位方式",headerWidth:100,dataCode:"carryBit", dataType: "String", hAlign: "center"},
- {headerName:"最小值",headerWidth:100,dataCode:"minValue", dataType: "String", hAlign: "right"},
- {headerName:"最大值",headerWidth:100,dataCode:"maxValue", dataType: "String", hAlign: "right"}
- ],
- view:{},
- comboItems: ["四舍五入", "进一"]
- },
- 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.EditStarting, me.onEditStarting);
- me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
- me.sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
- },
- onEnterCell: function (sender, args) {
- let me = rationAssistOprObj;
- args.sheet.repaint();
- let cellType = args.sheet.getCellType(args.row, 5);
- if(cellType.typeName !== 'undefined' && cellType.typeName === '1'){
- // sheetCommonObj.setStaticCombo(args.sheet, 0, 5, 0, me.setting.comboItems, false);
- sheetCommonObj.setDynamicCombo(args.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
- }
- },
- onClipboardPasting: function(sender, args) {
- let me = rationAssistOprObj;
- let rationSection = rationOprObj.getCache();
- let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
- me.ration = rationRow < rationSection.length ? rationSection[rationRow] : null;
- if (!me.ration) {
- args.cancel = true;
- }
- },
- onClipboardPasted: function(e, info) {
- var me = rationAssistOprObj;
- if (!me.ration) {return;};
- var tempArr = sheetCommonObj.analyzePasteData(me.setting, info);
- var assList = me.ration.rationAssList;
- if (assList == undefined) {
- me.ration.rationAssList = tempArr;
- }else{
- assList = assList.concat(tempArr);
- me.ration.rationAssList = assList;
- };
- rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
- me.sheet.getParent().focus(true);
- });
- sheetCommonObj.cleanData(me.sheet, me.setting, -1);
- //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, me.ration.rationAssList.length, me.setting.comboItems, false, false);
- sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
- sheetCommonObj.showData(me.sheet, me.setting, me.ration.rationAssList);
- },
- onEditStarting: function (sender, args) {
- let me = rationAssistOprObj;
- let rationSection = rationOprObj.getCache();
- let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
- me.ration = rationRow < rationSection.length ? rationSection[rationRow] : null;
- if(!me.ration){
- args.cancel = true;
- }
- },
- onEditEnded: function(sender, args){
- var me = rationAssistOprObj;
- if (!me.ration) {return;};
- if(typeof me.ration.rationAssList === 'undefined'){
- me.ration.rationAssList = [];
- }
- var assList = me.ration.rationAssList;
- var assObj = sheetsOprObj.combineRationRowData(me.sheet, me.setting, args.row);
- let dataCode = me.setting.header[args.col].dataCode;
- if((args.col === 2 || args.col === 3 || args.col === 6 || args.col === 7)
- && args.editingText && args.editingText.toString().trim().length > 0 && isNaN(args.editingText)){
- args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : '');
- alert(me.setting.header[args.col].headerName + '只能为数值!');
- return;
- }
- else if(args.col === 4 && args.editingText && (args.editingText.toString().trim().length === 0 ||
- isNaN(args.editingText) || args.editingText % 1 !== 0)){
- args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : 0);
- alert(me.setting.header[args.col].headerName + '只能为整数!');
- return;
- }
- // 新增
- if (args.row >= assList.length) {
- if (assObj.decimal == undefined || assObj.decimal == null){assObj.decimal = '0';};
- if (assObj.carryBit == undefined || assObj.carryBit == null){assObj.carryBit = '四舍五入';};
- assList.push(assObj);
- }
- // 修改
- else{ assList[args.row] = assObj; };
- rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
- me.sheet.getParent().focus(true);
- });
- sheetCommonObj.cleanData(me.sheet, me.setting, -1);
- //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, assList.length, me.setting.comboItems, false, false);
- sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
- sheetCommonObj.showData(me.sheet, me.setting, assList);
- },
- onRangeChanged: function(sender, args) {
- if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
- if (!confirm(`确定要删除选中的 ${args.rowCount} 条辅助定额吗?`)){return; }
- var me = rationAssistOprObj;
- if (!me.ration) {return;};
- var assList = me.ration.rationAssList;
- for (var i = args.rowCount - 1; i >= 0; i--) {
- if (args.row + i < assList.length) {
- assList.splice(args.row + i, 1);
- };
- };
- rationOprObj.mixUpdateRequest([me.ration], [], []);
- sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
- sheetCommonObj.showData(me.sheet, me.setting, assList);
- };
- },
- bindRationAssDel: function () {
- let me = rationAssistOprObj;
- let workBook = me.sheet.getParent();
- workBook.commandManager().register('rationAssDel', function () {
- let sels = me.sheet.getSelections(), isUpdate = false;
- if(me.ration){
- let curCahe = me.ration.rationAssList;
- for(let i = 0, len = sels.length; i < len; i ++ ){
- if(sels[i].colCount === me.setting.header.length){
- if(sels[i].row < curCahe.length){
- isUpdate = true;
- curCahe.splice(sels[i].row, sels[i].rowCount);
- }
- }
- }
- if(isUpdate){
- rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
- workBook.focus(true);
- });
- sheetCommonObj.cleanData(me.sheet, me.setting, -1);
- //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, curCahe.length, me.setting.comboItems, false);
- sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false);
- sheetCommonObj.showData(me.sheet, me.setting, curCahe);
- }
- }
- });
- workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
- workBook.commandManager().setShortcutKey('rationAssDel', GC.Spread.Commands.Key.del, false, false, false, false);
- },
- getAssItems: function(ration) {
- var me = this;
- me.ration = ration;
- sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
- sheetCommonObj.unShieldAllCells(me.sheet);
- if (ration == undefined || ration.rationAssList == undefined ||
- ration.rationAssList.length == 0){
- //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, 0, me.setting.comboItems, false);
- sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
- return;
- }
- else {
- //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, ration.rationAssList.length, me.setting.comboItems, false);
- sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
- }
- sheetCommonObj.showData(me.sheet, me.setting, ration.rationAssList);
- }
- }
|