瀏覽代碼

替换工料机类型常量

caiaolin 8 年之前
父節點
當前提交
be506d963d

+ 34 - 0
modules/common/const/glj_type_const.js

@@ -0,0 +1,34 @@
+/**
+ * 工料机类型常量
+ *
+ * @author CaiAoLin
+ * @date 2017/7/7
+ * @version
+ */
+
+const gljType = {
+    // 人工
+    LABOUR: 1,
+    // ==============材料类型=================
+    // 普通材料
+    GENERAL_MATERIAL: 201,
+    // 混凝土
+    CONCRETE: 202,
+    // 砂浆
+    MORTAR: 203,
+    // 配合比
+    MIX_RATIO: 204,
+    // 商品混凝土
+    COMMERCIAL_CONCRETE: 205,
+    // 商品砂浆
+    COMMERCIAL_MORTAR: 206,
+    // ==============材料类型=================
+    // 机械
+    MACHINE: 3,
+    // 主材
+    MAIN_MATERIAL: 4,
+    // 设备
+    EQUIPMENT: 5
+};
+
+export default gljType;

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

@@ -6,6 +6,7 @@
  * @version
  */
 import BaseController from "../../common/base/base_controller";
+import GLJTypeConst from "../../common/const/glj_type_const";
 import GLJListModel from "../models/glj_list_model";
 import UnitPriceModel from "../models/unit_price_model";
 import UnitPriceFileModel from "../models/unit_price_file_model";
@@ -55,7 +56,8 @@ class GLJController extends BaseController {
                 gljList: JSON.stringify(gljList),
                 materialIdList: gljListModel.materialIdList,
                 hostname: request.hostname,
-                roomId: unitPriceFileId
+                roomId: unitPriceFileId,
+                GLJTypeConst: JSON.stringify(GLJTypeConst)
             };
             response.render('glj/html/glj_index', renderData);
         } catch (error) {
@@ -168,11 +170,17 @@ class GLJController extends BaseController {
     async testModify(request, response) {
         let projectId = request.query.project;
         // // 修改数据
+        // let updateData = {
+        //     code: '00010201',
+        //     market_price: '49',
+        //     name: '土石方综合工日',
+        //     project_id: projectId
+        // };
         let updateData = {
+            market_price: '60.00',
             code: '00010201',
-            market_price: '49',
             name: '土石方综合工日',
-            project_id: projectId
+            project_id: 90
         };
 
         try {

+ 11 - 9
modules/glj/models/glj_list_model.js

@@ -10,6 +10,7 @@ import {default as GLJSchemas, collectionName as gljCollectionName} from "./sche
 import CounterModel from "./counter_model";
 import UnitPriceModel from "./unit_price_model";
 import UnitPriceFileModel from "./unit_price_file_model";
+import GLJTypeConst from "../../common/const/glj_type_const";
 
 class GLJListModel extends BaseModel {
 
@@ -18,7 +19,8 @@ class GLJListModel extends BaseModel {
      *
      * @var {Array}
      */
-    materialIdList = [5, 6, 7];
+    materialIdList = [GLJTypeConst.GENERAL_MATERIAL, GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO,
+        GLJTypeConst.COMMERCIAL_CONCRETE, GLJTypeConst.COMMERCIAL_MORTAR];
 
     /**
      * 构造函数
@@ -96,24 +98,24 @@ class GLJListModel extends BaseModel {
      * @return {void}
      */
     combineUnitPrice(gljList, unitPriceList) {
-        // @todo 以后从js获取?
-        let labour = 2;
-        let machine = 64;
-
         // 循环组合数据
         for(let glj of gljList) {
             if (glj.code === undefined) {
                 continue;
             }
-            glj.unit_price = unitPriceList[glj.code + glj.name] !== undefined ? unitPriceList[glj.code + glj.name] : null;
+            glj.unit_price = unitPriceList !== null && unitPriceList[glj.code + glj.name] !== undefined ? unitPriceList[glj.code + glj.name] : null;
+
+            if (glj.unit_price === null) {
+                continue;
+            }
             // 计算调整基价
-            switch (glj.type + '') {
+            switch (glj.unit_price.type + '') {
                 // 人工: 调整基价=基价单价*调整系数
-                case labour:
+                case GLJTypeConst.LABOUR:
                     glj.adjust_price = glj.adjustment * glj.unit_price.base_price;
                     break;
                 // 机械类型的算法
-                case machine:
+                case GLJTypeConst.MACHINE:
                     console.log('机械');
                     break;
                 // 材料、主材、设备

+ 3 - 2
modules/glj/models/unit_price_model.js

@@ -6,6 +6,7 @@
  * @version
  */
 import BaseModel from "../../common/base/base_model"
+import GLJTypeConst from "../../common/const/glj_type_const"
 import CounterModel from "./counter_model"
 import {default as UnitPriceSchema, collectionName as collectionName} from "./schemas/unit_price";
 
@@ -179,8 +180,8 @@ class UnitPriceModel extends BaseModel {
         // 基价单价的计算
         switch (unitPriceData.type) {
             // 主材、设备自动赋值基价单价=市场单价
-            case 6:
-            case 7:
+            case GLJTypeConst.MAIN_MATERIAL:
+            case GLJTypeConst.EQUIPMENT:
                 updateData.base_price = updateData.market_price;
                 break;
         }

+ 7 - 4
web/glj/html/glj_index.html

@@ -32,13 +32,16 @@
     let jsonData = '<%- gljList %>';
     let materialIdList = '<%- materialIdList %>';
     materialIdList = materialIdList !== '' ? materialIdList.split(",") : '';
-    // 不能修改市场价格的类型id
-    let canNotChangeTypeId = '64';
-    canNotChangeTypeId = canNotChangeTypeId !== '' ? canNotChangeTypeId.split(",") : '';
     let host = '<%= hostname %>';
     let socket = null;
-    let roomId = <%= roomId %>;
+    let roomId = '<%= roomId %>';
     let changeInfo = [];
+    let GLJTypeConst = '<%- GLJTypeConst %>';
+    GLJTypeConst = JSON.parse(GLJTypeConst);
+
+    // 混凝土、砂浆、配合比、机械 市场单价不能修改
+    let canNotChangeTypeId = [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO, GLJTypeConst.MACHINE];
+
 </script>
 <%include footer.html %>
 <script type="text/javascript" src="/web/glj/js/socket.js"></script>

+ 9 - 10
web/glj/js/glj_index.js

@@ -94,7 +94,7 @@ $(document).ready(function () {
             }
 
             // 如果类型为混凝土、砂浆、配合比、机械,则市场单价不能修改
-            if (columnInfo.field === 'unit_price.market_price' && canNotChangeTypeId.indexOf(data.unit_price.type + '') >= 0) {
+            if (columnInfo.field === 'unit_price.market_price' && canNotChangeTypeId.indexOf(data.unit_price.type) >= 0) {
                 // 锁定该单元格
                 sheet.getRange(rowCounter, columnCounter, 1, 1).locked(true);
             }
@@ -194,7 +194,7 @@ $(document).ready(function () {
         let type = sheet.getValue(row, typeColumn);
 
         // 如果类型为混凝土、砂浆、配合比、机械,则提示
-        if (field === 'unit_price.market_price' && canNotChangeTypeId.indexOf(type + '') >= 0) {
+        if (field === 'unit_price.market_price' && canNotChangeTypeId.indexOf(type) >= 0) {
             alert('当前工料机的市场单价由组成物计算得出,不可直接修改');
         }
     });
@@ -298,8 +298,8 @@ function basePriceCalculate(type, info) {
     let basePriceColumn = getFieldColumn(header, 'unit_price.base_price');
     switch (type) {
         // 主材、设备自动赋值基价单价=市场单价
-        case 6:
-        case 7:
+        case GLJTypeConst.MAIN_MATERIAL:
+        case GLJTypeConst.EQUIPMENT:
             sheet.setValue(info.row, basePriceColumn, info.newValue);
             break;
     }
@@ -317,10 +317,9 @@ function adjustPriceCalculate(type, info) {
     let adjustPriceColumn = getFieldColumn(header, 'adjust_price');
     switch (type) {
         // 材料、主材、设备 调整基价=基价单价
-        case 5:
-        case 6:
-        case 7:
-            let basePrice = sheet.getValue(row, basePriceColumn);
+        case GLJTypeConst.MAIN_MATERIAL:
+        case GLJTypeConst.EQUIPMENT:
+            let basePrice = sheet.getValue(info.row, basePriceColumn);
             sheet.setValue(info.row, adjustPriceColumn, basePrice);
             break;
 
@@ -337,8 +336,8 @@ function adjustPriceCalculate(type, info) {
 function marketPriceCalculate(type, info) {
     switch (type) {
         // 人工、材料(普通材料)触发 需计算混凝土、砂浆、配合比、机械的市场单价 @todo 后续添加
-        case 2:
-        case 5:
+        case GLJTypeConst.LABOUR:
+        case GLJTypeConst.LABOUR:
             // 计算
             console.log('触发计算');
             break;