Browse Source

新增供货方式与甲供数量关系的处理

olym 7 years ago
parent
commit
7934c6df6d

+ 10 - 3
modules/glj/controllers/glj_controller.js

@@ -97,6 +97,7 @@ class GLJController extends BaseController {
     async updateData(request, response) {
         let field = request.body.field;
         let value = request.body.value;
+        let extend = request.body.extend;
         value = value === 'true' ? 1 : value;
         value = value === 'false' ? 0 : value;
         let id = request.body.id;
@@ -107,7 +108,8 @@ class GLJController extends BaseController {
         };
         try {
             // 可编辑的字段
-            let editableField = ['is_evaluate', 'unit_price.market_price', 'is_adjust_price', 'mix_ratio.consumption'];
+            let editableField = ['is_evaluate', 'unit_price.market_price', 'is_adjust_price', 'mix_ratio.consumption',
+                'supply'];
             if (editableField.indexOf(field) < 0) {
                 throw '对应字段不能编辑';
             }
@@ -126,13 +128,18 @@ class GLJController extends BaseController {
             let model = null;
             switch (modelString) {
                 case 'glj':
+                    if (extend !== '') {
+                        extend = JSON.parse(extend);
+                        for (let code in extend) {
+                            updateData[code] = extend[code];
+                        }
+                    }
+                    console.log(updateData);
                     model = new GLJListModel();
                     // 更新数据
                     result = await model.updateById(id, updateData);
-
                     break;
                 case 'unit_price':
-                    let extend = request.body.extend;
                     model = new UnitPriceModel();
                     // 更新数据
                     result = await model.updatePrice({id: id}, updateData, extend);

+ 2 - 2
modules/glj/models/schemas/glj.js

@@ -34,8 +34,8 @@ let modelSchema = {
     },
     // 供货方式
     supply: {
-        type: String,
-        default: ''
+        type: Number,
+        default: 0
     },
     // 甲供数量
     supply_quantity: {

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

@@ -70,7 +70,7 @@ CommonSpreadJs.prototype.getFieldColumn = function(field) {
             break;
         }
     }
-
+    result = parseInt(result);
     return result;
 };
 

+ 4 - 0
web/building_saas/glj/js/project_glj.js

@@ -305,6 +305,10 @@ function successTrigger(field, info) {
             socket.emit('dataNotify', JSON.stringify(info));
             console.log(info);
             break;
+        case 'supply':
+            // 供货方式更改成功后
+            projectGLJSpread.changeSupplyType(info);
+            break;
     }
     // 重新加载数据到缓存
     projectObj.project.projectGLJ.loadData();

+ 79 - 6
web/building_saas/glj/js/project_glj_spread.js

@@ -17,6 +17,9 @@ function ProjectGLJSpread() {
     this.firstMachineRow = -1;
     this.firstMixRatioRow = -1;
     this.successCallback = null;
+    this.supplyType = ['自行采购', '部分甲供', '完全甲供', '甲定乙供'];
+    // 工料机类型是混凝土、砂浆、配合比、机械(不包括机械组成物)时,供货方式列只读。
+    this.supplyReadonlyType = [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO, GLJTypeConst.GENERAL_MACHINE];
 }
 
 /**
@@ -25,7 +28,17 @@ function ProjectGLJSpread() {
  * @return {object}
  */
 ProjectGLJSpread.prototype.init = function () {
-
+    // 供货方式类型
+    let supplySelect = [];
+    for(let index in this.supplyType) {
+        supplySelect.push({
+            text: this.supplyType[index],
+            value: index
+        });
+    }
+    let selectBox = new GC.Spread.Sheets.CellTypes.ComboBox();
+    selectBox.items(supplySelect);
+    selectBox.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
     let header = [
         {name: '编码', field: 'code', visible: true},
         {name: '名称', field: 'name', visible: true},
@@ -44,7 +57,7 @@ ProjectGLJSpread.prototype.init = function () {
             cellType: new GC.Spread.Sheets.CellTypes.CheckBox(),
             validator: 'boolean'
         },
-        {name: '供货方式', field: 'supply', visible: true},
+        {name: '供货方式', field: 'supply', visible: true, cellType: selectBox},
         {name: '甲供数量', field: 'supply_quantity', visible: true},
         {name: '交货方式', field: 'delivery', visible: true},
         {name: '送达地点', field: 'delivery_address', visible: true},
@@ -74,6 +87,7 @@ ProjectGLJSpread.prototype.init = function () {
     let basePriceColumn = this.sheetObj.getFieldColumn('unit_price.base_price');
     let adjustPriceColumn = this.sheetObj.getFieldColumn('adjust_price');
     let marketPriceColumn = this.sheetObj.getFieldColumn('unit_price.market_price');
+    let supplyColumn = this.sheetObj.getFieldColumn('supply');
 
     // 居中样式
     let centerStyleSetting = {hAlign: 1};
@@ -92,6 +106,7 @@ ProjectGLJSpread.prototype.init = function () {
     this.sheetObj.setColumnEditable(marketPriceColumn);
     this.sheetObj.setColumnEditable(isEvaluateColumn);
     this.sheetObj.setColumnEditable(isAdjustPriceColumn);
+    this.sheetObj.setColumnEditable(11);
     this.sheetObj.setData(sourceData);
     // 取消正在加载字符提示
     $("#project-glj > p").hide();
@@ -179,6 +194,12 @@ ProjectGLJSpread.prototype.updateProjectGLJField = function(info, callback) {
         }
     }
 
+    // 如果是供货方式则需要处理数据
+    if (field === 'supply') {
+        value = this.supplyType.indexOf(value);
+        extend.supply_quantity = this.getSupplyQuantity(value, activeSheet, info);
+    }
+
     extend = Object.keys(extend).length > 0 ?  JSON.stringify(extend) : '';
     $.ajax({
         url: '/glj/update',
@@ -220,9 +241,9 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
     // 获取列号
     let isEvaluateColumn = this.sheetObj.getFieldColumn('is_evaluate');
     let marketPriceColumn = this.sheetObj.getFieldColumn('unit_price.market_price');
-
     let connectCodeColumn = this.sheetObj.getFieldColumn('connect_code');
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
+    let supplyColumn = this.sheetObj.getFieldColumn('supply');
     let activeSheet = this.sheetObj.getSheet();
 
     for (let data of sourceData) {
@@ -230,20 +251,33 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
         if (materialIdList.indexOf(data.unit_price.type) < 0) {
             let string = new GC.Spread.Sheets.CellTypes.Text();
             activeSheet.setCellType(rowCounter, isEvaluateColumn, string, GC.Spread.Sheets.SheetArea.viewport);
+
             // 锁定该单元格
-            activeSheet.getRange(rowCounter, isEvaluateColumn, 1, 1).locked(true);
+            activeSheet.getCell(rowCounter, isEvaluateColumn, GC.Spread.Sheets.SheetArea.viewport).locked(true);
             activeSheet.setValue(rowCounter, isEvaluateColumn, '');
         }
 
-        // 如果类型为混凝土、砂浆、配合比、机械,则市场单价不能修改
+        // 供货方式数据
+        let supplyIndex = parseInt(data.supply);
+        supplyIndex = isNaN(supplyIndex) ? 0 : supplyIndex;
+        let supplyText = this.supplyType[supplyIndex] !== undefined ? this.supplyType[supplyIndex] : '自行采购';
+        activeSheet.setValue(rowCounter, supplyColumn, supplyText);
+        if (this.supplyReadonlyType.indexOf(data.unit_price.type) >= 0) {
+            // 锁定该单元格
+            activeSheet.getCell(rowCounter, supplyColumn,  GC.Spread.Sheets.SheetArea.viewport).locked(true);
+        }
+
+        // 如果类型为混凝土、砂浆、配合比、机械,则市场单价和供货方式不能修改
         if (canNotChangeTypeId.indexOf(data.unit_price.type) >= 0) {
             this.firstMixRatioRow = this.firstMixRatioRow === -1 && data.unit_price.type !== GLJTypeConst.GENERAL_MACHINE ?
                 rowCounter : this.firstMixRatioRow;
             this.firstMachineRow = this.firstMachineRow === -1 && data.unit_price.type === GLJTypeConst.GENERAL_MACHINE ?
                 rowCounter : this.firstMachineRow;
             // 锁定该单元格
-            activeSheet.getRange(rowCounter, marketPriceColumn, 1, 1).locked(true);
+            activeSheet.getCell(rowCounter, marketPriceColumn,  GC.Spread.Sheets.SheetArea.viewport).locked(true);
+            activeSheet.getCell(rowCounter, supplyColumn,  GC.Spread.Sheets.SheetArea.viewport).locked(true);
         }
+
         // 处理数据
         if (data.ratio_data !== undefined && data.ratio_data.length > 0) {
             let connectCode = [];
@@ -257,6 +291,7 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
             activeSheet.setValue(rowCounter, connectCodeColumn, connectCodeString);
             activeSheet.setValue(rowCounter, consumptionColumn, consumptionString);
         }
+
         rowCounter++;
     }
 };
@@ -377,4 +412,42 @@ ProjectGLJSpread.prototype.priceCalculate = function(info) {
             this.compositionParentUpdate(info.parentMarketPrice);
             break;
     }
+};
+
+/**
+ * 更改供货方式
+ *
+ * @param {Object} info
+ * @return {void}
+ */
+ProjectGLJSpread.prototype.changeSupplyType = function(info) {
+    let supply = info.newValue;
+    let supplyNumber = this.supplyType.indexOf(supply) > -1 ? this.supplyType.indexOf(supply) : 0;
+    let supplyQuantityColumn = this.sheetObj.getFieldColumn('supply_quantity');
+    let activeSheet = this.sheetObj.getSheet();
+
+    // 部分甲供时可更改甲供数量数据,其余则只读
+    let locked = supplyNumber === 1 ? false : true;
+    activeSheet.getCell(info.row, supplyQuantityColumn,  GC.Spread.Sheets.SheetArea.viewport).locked(locked);
+
+    let supplyQuantity = this.getSupplyQuantity(supplyNumber, activeSheet, info);
+    activeSheet.setValue(info.row, supplyQuantityColumn, supplyQuantity);
+};
+
+/**
+ * 根据供货方式获取甲供数量
+ *
+ * @param {Number} supplyType
+ * @param {Object} activeSheet
+ * @param {Object} info
+ * @return {Number}
+ */
+ProjectGLJSpread.prototype.getSupplyQuantity = function(supplyType, activeSheet, info) {
+    let quantityColumn = this.sheetObj.getFieldColumn('quantity');
+    // 获取总消耗量
+    let quantity = activeSheet.getValue(info.row, quantityColumn);
+    // 自行采购和甲定乙供则把甲供数量设置为0,其余情况则设置为当前总消耗量
+    let supplyQuantity = supplyType === 0 || supplyType === 3 ? 0 : quantity;
+
+    return supplyQuantity;
 };