浏览代码

动态下拉框相关

zhongzewei 7 年之前
父节点
当前提交
b127dbe62b

+ 50 - 0
public/web/sheet/sheet_common.js

@@ -257,5 +257,55 @@ var sheetCommonObj = {
             }
         }
         return rst;
+    },
+    //add by zhong 2017-10-10
+    //动态下拉框
+    getDynamicCombo: function () {
+        let ComboCellForActiveCell = function () { };
+        ComboCellForActiveCell.prototype = new GC.Spread.Sheets.CellTypes.ComboBox();
+        ComboCellForActiveCell.prototype.paintValue = function (ctx, value, x, y, w, h, style, options) {
+            let sheet = options.sheet;
+            if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()) {
+                GC.Spread.Sheets.CellTypes.ComboBox.prototype.paintValue.apply(this, arguments);
+
+            } else {
+                GC.Spread.Sheets.CellTypes.Base.prototype.paintValue.apply(this, arguments);
+            }
+        };
+        ComboCellForActiveCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, options) {
+            let sheet = options.sheet;
+            if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()) {
+                return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
+
+            } else {
+                return GC.Spread.Sheets.CellTypes.Base.prototype.getHitInfo.apply(this, arguments);
+            }
+        };
+        return new ComboCellForActiveCell();
+    },
+    setDynamicCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
+        let me = this;
+        sheet.suspendPaint();
+        for(let i = 0, len = rowCount; i < len; i++){
+            let combo = me.getDynamicCombo();
+            if(itemsHeight) combo.itemHeight(itemsHeight);
+            if(itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
+            else if(itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
+            else combo.items(items);
+            sheet.getCell(beginRow + i, col).cellType(combo);
+        }
+        sheet.resumePaint();
+    },
+    setStaticCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
+        sheet.suspendPaint();
+        for(let i = 0, len = rowCount; i < len; i++){
+            let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
+            if(itemsHeight) combo.itemHeight(itemsHeight);
+            if(itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
+            else if(itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
+            else combo.items(items);
+            sheet.getCell(beginRow + i, col).cellType(combo);
+        }
+        sheet.resumePaint();
     }
 }

+ 1 - 1
web/maintain/ration_repository/dinge.html

@@ -399,7 +399,7 @@
                         </button>
                     </div>
                     <div class="modal-body">
-                        <h5 class="text-danger" id="alertRationTxt">编号不可为空!是否取消操作?</h5>
+                        <h5 class="text-danger" id="alertRationTxt">编码不可为空,继续新增定额?</h5>
                     </div>
                     <div class="modal-footer">
                         <button type="button" class="btn btn-secondary" id="rationAlertCac" data-dismiss="modal">取消</button>

+ 27 - 54
web/maintain/ration_repository/js/ration.js

@@ -9,7 +9,6 @@ $("#gongliao").click(function(){
 $("#fuzhu").click(function(){
     $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
 });
-
 let rationOprObj = {
     workBook: null,
     currentRations: {},
@@ -56,7 +55,6 @@ let rationOprObj = {
         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.EditEnded, me.onCellEditEnd);
-        //me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
     },
 
@@ -90,34 +88,6 @@ let rationOprObj = {
         }
     },
 
-    onCellClick: function(sender, args) {
-        let me = rationOprObj,
-            sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
-            sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
-            sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
-        sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
-        sheetCommonObj.shieldAllCells(sheetGLJ);
-        sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
-        sheetCommonObj.shieldAllCells(sheetCoe);
-        sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
-        sheetCommonObj.shieldAllCells(sheetAss);
-        if(!(args.sheetArea === GC.Spread.Sheets.SheetArea.colHeader || args.sheetArea === GC.Spread.Sheets.SheetArea.corner)){
-            let cacheSection = me.getCache();
-            if (cacheSection && args.row < cacheSection.length) {
-                rationGLJOprObj.getGljItems(cacheSection[args.row], function () {
-                    me.workBook.focus(true);
-                });
-                rationCoeOprObj.getCoeItems(cacheSection[args.row], function () {
-                    me.workBook.focus(true);
-                });
-                rationAssistOprObj.getAssItems(cacheSection[args.row]);
-            }
-            else {
-                rationGLJOprObj.currentRationItem = null;
-            }
-        };
-        me.workBook.focus(true);
-    },
     isInt: function (num) {
         return !isNaN(num) && num % 1 === 0;
     },
@@ -228,6 +198,7 @@ let rationOprObj = {
     },
     onEnterCell: function (sender, args) {
         let me = rationOprObj;
+        args.sheet.repaint();
         me.cellRowIdx = args.row;
         let isHasData = false;
         if(me.addRationItem){
@@ -246,16 +217,18 @@ let rationOprObj = {
                     me.workBook.getSheet(0).options.isProtected = true;
                     $('#rationAlertCac').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('');
+                        }
                     });
                     $('#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, focusToCol);
                     });
                 }
             }
@@ -263,14 +236,19 @@ let rationOprObj = {
     },
     onCellEditStart: function(sender, args) {
         let me = rationOprObj;
-        let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
-        me.currentEditingRation = rObj;
-        let cacheSection = me.getCache();
-        if (cacheSection) {
-            for (let 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;
+        if(!me.canRations){
+            args.cancel = true;
+        }
+        else{
+            let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
+            me.currentEditingRation = rObj;
+            let cacheSection = me.getCache();
+            if (cacheSection) {
+                for (let 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;
+                    }
                 }
             }
         }
@@ -367,7 +345,11 @@ let rationOprObj = {
     },
     onClipboardPasting: function(sender, args) {
         let me = rationOprObj;
+        if(!me.canRations){
+            args.cancel = true;
+        }
     },
+    //todo: overwrite
     onClipboardPasted: function(e, info) {
         let me = rationOprObj;
         let cacheSection = me.getCache();
@@ -590,16 +572,6 @@ let rationOprObj = {
             }
         }
     },
-    setCombo: function (sheet, items) {
-        sheet.suspendPaint();
-        for(let i = 0, len = sheet.getRowCount(); i < len; i++){
-            let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
-            combo.items(items);
-            combo.itemHeight(10);
-            sheet.getCell(i, 2).cellType(combo);
-        }
-        sheet.resumePaint();
-    },
     showRationItems: function(sectionID){
         let me = rationOprObj,
             sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
@@ -608,12 +580,12 @@ let rationOprObj = {
         if (me.workBook) {
             if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
                 let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
-                //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
                 sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
                 sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
                 sheetCommonObj.setLockCol(me.workBook.getSheet(0), 4, true);
                 //combo
-                me.setCombo(me.workBook.getActiveSheet(), rationUnits);
+                sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 2, cacheSection.length, rationUnits, 10, false);
+                sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), cacheSection.length, 2, me.workBook.getActiveSheet().getRowCount() - cacheSection.length, rationUnits, 10, false);
                 if(me.mixDel === 1){
                     let row = me.workBook.getSheet(0).getSelections()[0].row;
                     if (cacheSection && row < cacheSection.length) {
@@ -627,6 +599,7 @@ let rationOprObj = {
                 }
 
             } else {
+                sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
                 //清除ration数据及工料机数据
                 rationGLJOprObj.currentRationItem = null;
                 sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);

+ 35 - 10
web/maintain/ration_repository/js/ration_assist.js

@@ -9,14 +9,15 @@ var rationAssistOprObj = {
         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: "Number", hAlign: "right"},
-            {headerName:"步距",headerWidth:100,dataCode:"stepValue", dataType: "Number", hAlign: "right"},
-            {headerName:"精度",headerWidth:80,dataCode:"decimal", formatter: "0", dataType: "Number", hAlign: "right"},
+            {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: "Number", hAlign: "right"},
-            {headerName:"最大值",headerWidth:100,dataCode:"maxValue", dataType: "Number", hAlign: "right"}
+            {headerName:"最小值",headerWidth:100,dataCode:"minValue", dataType: "String", hAlign: "right"},
+            {headerName:"最大值",headerWidth:100,dataCode:"maxValue", dataType: "String", hAlign: "right"}
         ],
-        view:{}
+        view:{},
+        comboItems: ["四舍五入", "进一"]
     },
 
     buildSheet: function(sheet) {
@@ -27,16 +28,21 @@ var rationAssistOprObj = {
 
         sheetCommonObj.initSheet(me.sheet, me.setting, 30);
 
-        var carryBit = new GC.Spread.Sheets.CellTypes.ComboBox();
+        /*var carryBit = new GC.Spread.Sheets.CellTypes.ComboBox();
         carryBit.items(["四舍五入","进一"]);
-        me.sheet.getRange(-1, 5, -1, 1).cellType(carryBit);
+        me.sheet.getRange(-1, 5, -1, 1).cellType(carryBit);*/
 
         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.EnterCell, me.onEnterCell);
         //me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
     },
 
+    onEnterCell: function (sender, args) {
+        args.sheet.repaint();
+    },
+
     onClipboardPasting: function(sender, args) {
         var me = rationAssistOprObj;
         if (!me.ration) {
@@ -60,6 +66,8 @@ var rationAssistOprObj = {
             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, assList.length, 5, me.sheet.getRowCount() - assList.length, me.setting.comboItems, false, false);
         sheetCommonObj.showData(me.sheet, me.setting, me.ration.rationAssList);
     },
 
@@ -69,7 +77,18 @@ var rationAssistOprObj = {
         var assList = me.ration.rationAssList;
         //var assObj = sheetCommonObj.combineRowData(me.sheet, me.setting, args.row);
         var assObj = sheetsOprObj.combineRationRowData(me.sheet, me.setting, args.row);
-        if(args.col === 2 || args.col === 3 || args.col === 6 || args.col === 7){
+        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 ((assList == undefined) || (assList && args.row >= assList.length)) {
@@ -84,6 +103,8 @@ var rationAssistOprObj = {
             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, assList.length, 5, me.sheet.getRowCount() - assList.length, me.setting.comboItems, false, false);
         sheetCommonObj.showData(me.sheet, me.setting, assList);
     },
 
@@ -125,6 +146,8 @@ var rationAssistOprObj = {
                         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, curCahe.length, 5, me.sheet.getRowCount() - curCahe.length, me.setting.comboItems, false);
                     sheetCommonObj.showData(me.sheet, me.setting, curCahe);
                 }
             }
@@ -140,9 +163,11 @@ var rationAssistOprObj = {
         sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
         sheetCommonObj.unShieldAllCells(me.sheet);
 
+        sheetCommonObj.setStaticCombo(me.sheet, 0, 5, ration.rationAssList.length, me.setting.comboItems, false);
+        sheetCommonObj.setDynamicCombo(me.sheet, ration.rationAssList.length, 5, me.sheet.getRowCount() - ration.rationAssList.length, me.setting.comboItems, false, false);
+
         if (ration == undefined || ration.rationAssList == undefined ||
             ration.rationAssList.length == 0){return;};
-
         sheetCommonObj.showData(me.sheet, me.setting, ration.rationAssList);
     }
 }

+ 3 - 1
web/maintain/ration_repository/js/ration_coe.js

@@ -240,8 +240,10 @@ var rationCoeOprObj = {
             ration.rationCoeList.length == 0){return;};*/
 
         var coeList = ration.rationCoeList;
+        console.log(`me.cache["_Coe_" + ration.ID]`);
+        console.log(me.cache["_Coe_" + ration.ID]);
         var curCache = me.cache["_Coe_" + ration.ID];
-        if (curCache && curCache.length > 0) {
+        if (curCache) {
             me.showCoeItems(ration.ID);
             sheetCommonObj.lockCells(me.sheet, me.setting);
         } else {

+ 2 - 0
web/maintain/ration_repository/js/ration_glj.js

@@ -516,6 +516,8 @@ var rationGLJOprObj = {
     getGljItems: function(rationItem, callback) {
         var me = this, rationID = rationItem.ID, rationGljList = rationItem.rationGljList;
         me.currentRationItem = rationItem;
+        console.log(`me.cache["_GLJ_" + rationID]`);
+        console.log(me.cache["_GLJ_" + rationID]);
         if (me.cache["_GLJ_" + rationID]) {
             me.showGljItems(rationID);
             sheetCommonObj.lockCells(me.sheet, me.setting);

+ 4 - 0
web/maintain/ration_repository/js/section_tree.js

@@ -349,9 +349,13 @@ var zTreeOprObj = {
         annotationOprObj.clickUpdate($('#fzTxtareaAll'));
         var sectionID = treeNode.ID;
         if (!(treeNode.items) || treeNode.items.length == 0) {
+            rationOprObj.canRations = true;
             rationOprObj.workBook.getSheet(0).clearSelection();
             rationOprObj.getRationItems(sectionID);
         } else {
+            rationOprObj.canRations = false;
+            rationOprObj.currentSectionId = sectionID;
+            sheetCommonObj.unsetCombo(rationOprObj.workBook.getActiveSheet(), 0, 2, rationOprObj.workBook.getActiveSheet().getRowCount());
             jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
             jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
             annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);

+ 5 - 5
web/maintain/std_glj_lib/js/glj.js

@@ -98,9 +98,9 @@ let repositoryGljObj = {
                 if(!result.error && callback){
                     me.distTypeTree = me.getComboData(result.data);
                     console.log(me.distTypeTree);
-                    let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
+                    /*let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
                     combo.items(me.distTypeTree.comboDatas).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
-                    me.workBook.getSheet(0).getCell(-1, 5, GC.Spread.Sheets.SheetArea.viewport).cellType(combo).value(me.distTypeTree.comboDatas[0].text);
+                    me.workBook.getSheet(0).getCell(-1, 5, GC.Spread.Sheets.SheetArea.viewport).cellType(combo);*/
                     callback();
                 }
             }
@@ -191,10 +191,10 @@ let repositoryGljObj = {
                     cacheSection.push(data[i]);
                 }
             }
-            //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
             sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
             sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree);
-
+            sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 5, cacheSection.length, me.distTypeTree.comboDatas, false, 'text');
+            sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), cacheSection.length, 5, me.workBook.getActiveSheet().getRowCount() - cacheSection.length, me.distTypeTree.comboDatas, false, 'text');
             cacheSection = null;
         }
     },
@@ -319,6 +319,7 @@ let repositoryGljObj = {
     },
     onEnterCell: function (sender, args) {
         let me = repositoryGljObj;
+        args.sheet.repaint();
         me.cellRowIdx = args.row;
         let isHasData = false;
         if(me.addGljObj){
@@ -916,7 +917,6 @@ let repositoryGljObj = {
             success:function(result){
                 if (result.error) {
                     alert(result.message);
-                    me.getRationItems(me.currentRepositoryId);
                 } else {
                     me.updateCache(addArr, updateArr, removeIds, result);
                     me.sortGlj();