ソースを参照

修复配合比和机械单价的前端js bug

caiaolin 8 年 前
コミット
6eb1fd212b

+ 1 - 0
web/glj/js/common_spread.js

@@ -191,6 +191,7 @@ CommonSpreadJs.prototype.filterData = function(field, filterList) {
     this.sheet.rowFilter(filter);
 
     let rowFilter = this.sheet.rowFilter();
+    rowFilter.filterButtonVisible(false);
     rowFilter.removeFilterItems(fieldColumn);
     for (let tmp of filterList) {
         let condition = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.numberCondition, {

+ 18 - 11
web/glj/js/composition.js

@@ -5,15 +5,12 @@
  * @date 2017/7/10
  * @version
  */
-let compositionSpread = null;
-let mixRatioSheet = null;
-let machineSheet = null;
+let mixRatioSpread = null;
+let machineSpread = null;
 let mixRatioRightClickTarget = null;
 let isDeleting = false;
 $(document).ready(function() {
 
-    compositionSpread = new CompositionSpread();
-    compositionSpread.successCallback = mixRatioSuccess;
 
     // 切换tab触发refresh
     $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
@@ -22,27 +19,37 @@ $(document).ready(function() {
         // 获取工料机当前选中的行号
         let projectGLJId = 0;
         if (currentTag === "mix-ratio") {
-            mixRatioSheet = mixRatioSheet === null ? compositionSpread.init(currentTag) : mixRatioSheet;
-            compositionSpread.initRightClick();
+            if (mixRatioSpread === null) {
+                mixRatioSpread = new CompositionSpread();
+                mixRatioSpread.init(currentTag);
+                mixRatioSpread.initRightClick(currentTag);
+                mixRatioSpread.successCallback = mixRatioSuccess;
+            }
+
             // 筛选数据显示(显示混凝土、砂浆、配合比)
             projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO]);
             projectGLJSheet.selectRow(projectGLJSpread.firstMixRatioRow);
             projectGLJId = projectGLJSheet.getActiveDataByField('id');
 
             // 获取数据
-            compositionSpread.getRatioData(projectGLJId);
+            mixRatioSpread.getRatioData(projectGLJId);
         }
 
         if (currentTag === "machine") {
-            machineSheet = machineSheet === null ? compositionSpread.init(currentTag) : machineSheet;
-            compositionSpread.initRightClick();
+            if (machineSpread === null) {
+                machineSpread = new CompositionSpread();
+                machineSpread.init(currentTag);
+                machineSpread.initRightClick(currentTag);
+                machineSpread.successCallback = mixRatioSuccess;
+            }
+
             // 筛选数据显示(显示普通机械)
             projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.GENERAL_MACHINE]);
             projectGLJSheet.selectRow(projectGLJSpread.firstMachineRow);
             projectGLJId = projectGLJSheet.getActiveDataByField('id');
 
             // 获取数据
-            compositionSpread.getRatioData(projectGLJId);
+            machineSpread.getRatioData(projectGLJId);
         }
 
     });

+ 12 - 9
web/glj/js/composition_spread.js

@@ -15,6 +15,7 @@ function CompositionSpread () {
     this.isChanging = false;
     this.sheetObj = null;
     this.successCallback = null;
+    this.rightClickTarget = null;
 }
 
 /**
@@ -34,7 +35,7 @@ CompositionSpread.prototype.init = function(target) {
         {name: '基价单价', field: "unit_price.base_price", visible: true},
         {name: '调整基价', field: 'adjust_price', visible: true},
         {name: '市场单价', field: "unit_price.market_price", visible: true},
-        {name: '消耗量', field: 'consumption', visible: true, validator: 'number'},
+        {name: name, field: 'consumption', visible: true, validator: 'number'},
         {name: 'CID', field: 'mix_ratio_id', visible: false},
     ];
 
@@ -67,27 +68,28 @@ CompositionSpread.prototype.init = function(target) {
 /**
  * 初始化右键
  *
+ * @param {String} target
  * @return {void}
  */
-CompositionSpread.prototype.initRightClick = function() {
+CompositionSpread.prototype.initRightClick = function(target) {
     let activeSheet = this.sheetObj.getSheet();
     let self = this;
     $.contextMenu({
-        selector: '#mix-ratio',
+        selector: '#' + target,
         build: function ($trigger, e) {
-            mixRatioRightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, self.sheetObj.spread);
-            return mixRatioRightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
-                mixRatioRightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
+            self.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, self.sheetObj.spread);
+            return self.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
+                self.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
         },
         items: {
             "deleteMixRatio": {
                 name: "删除",
                 icon: 'fa-trash-o',
                 disabled: function () {
-                    return mixRatioRightClickTarget.row === undefined;
+                    return self.rightClickTarget.row === undefined;
                 },
                 callback: function (key, opt) {
-                    let row = mixRatioRightClickTarget.row;
+                    let row = self.rightClickTarget.row;
                     let idColumn = self.sheetObj.getFieldColumn('mix_ratio_id');
                     let deleteId = activeSheet.getValue(row, idColumn);
                     self.deleteComposition(deleteId, row, mixRatioSuccess);
@@ -286,6 +288,7 @@ CompositionSpread.prototype.deleteComposition = function (id, row, callback) {
     // 获取当前行的消耗量
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
     let consumption = activeSheet.getValue(row, consumptionColumn);
+    let self = this;
     $.ajax({
         url: '/glj/delete-ratio',
         type: 'post',
@@ -301,7 +304,7 @@ CompositionSpread.prototype.deleteComposition = function (id, row, callback) {
         success: function(response) {
             if (response.err === 0) {
                 // 计算同级的市场单价和基价单价
-                let [parentMarketPrice, parentBasePrice] = this.getCompositionSumPrice('delete', row);
+                let [parentMarketPrice, parentBasePrice] = self.getCompositionSumPrice('delete', row);
                 let info = {
                     parentMarketPrice: parentMarketPrice,
                     parentBasePrice: parentBasePrice,

+ 1 - 1
web/glj/js/project_glj_spread.js

@@ -32,7 +32,7 @@ ProjectGLJSpread.prototype.init = function () {
         {name: '规格型号', field: 'unit_price.specs', visible: true},
         {name: '单位', field: 'unit_price.unit', visible: true},
         {name: 'ID', field: 'id', visible: false},
-        {name: '类型', field: 'unit_price.type', visible: true},
+        {name: '类型', field: 'unit_price.type', visible: false},
         {name: '总消耗量', field: 'quantity', visible: true},
         {name: '基价单价', field: "unit_price.base_price", visible: true},
         {name: '调整基价', field: 'adjust_price', visible: true},