Forráskód Böngészése

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost

zhangweicheng 7 éve
szülő
commit
bec60bc83e

+ 59 - 0
modules/glj/controllers/glj_controller.js

@@ -428,6 +428,65 @@ class GLJController extends BaseController {
     }
 
     /**
+     * 获取项目中所有组成物数据(用户缓存到前端变量)
+     *
+     * @param {object} request
+     * @param {object} response
+     * @return {void}
+     */
+    async getComposition(request, response) {
+        let projectId = request.body.project_id;
+        projectId = parseInt(projectId);
+
+        let responseData = {
+            err: 0,
+            data: null
+        };
+        try {
+            // 当前单价文件id
+            let currentUnitPriceId = await ProjectModel.getUnitPriceFileId(projectId);
+            if (currentUnitPriceId <= 0) {
+                throw '没有找到对应的单价文件';
+            }
+
+            // 获取组成物数据
+            let mixRatioModel = new MixRatioModel();
+            let compositionData = await mixRatioModel.findDataByCondition({unit_price_file_id: currentUnitPriceId}, null, false);
+            if (compositionData === null) {
+                throw '没有找到组成物数据';
+            }
+            compositionData = JSON.parse(JSON.stringify(compositionData));
+            // 查找对应的单价数据
+            let unitPriceModel = new UnitPriceModel();
+            let unitPriceData = await unitPriceModel.findDataByCondition({unit_price_file_id: currentUnitPriceId}, null, false, 'code');
+
+            // 整理数据
+            let result = {};
+            for(let composition of compositionData) {
+                let tmpData = {
+                    market_price: unitPriceData[composition.connect_code] !== undefined ?
+                        unitPriceData[composition.connect_code].market_price : 0,
+                    base_price: unitPriceData[composition.connect_code] !== undefined ?
+                        unitPriceData[composition.connect_code].base_price : 0,
+                    consumption: composition.consumption,
+                    glj_type: composition.glj_type,
+                    connect_code: composition.connect_code
+                };
+                if (result[composition.connect_code] === undefined) {
+                    result[composition.connect_code] = [];
+                }
+                result[composition.connect_code].push(tmpData);
+            }
+            responseData.data = result;
+        } catch (error) {
+            responseData.err = 1;
+            responseData.data = null;
+        }
+
+        response.json(responseData);
+    }
+
+    /**
      * 模拟定额插入
      *
      * @param {object} request

+ 1 - 0
modules/glj/routes/glj_router.js

@@ -20,6 +20,7 @@ router.post('/delete-ratio', gljController.init, gljController.deleteMixRatio);
 router.post('/get-project-info', gljController.init, gljController.getProjectInfo);
 router.post('/change-file', gljController.init, gljController.changeUnitPriceFile);
 router.post('/save-as', gljController.init, gljController.unitPriceSaveAs);
+router.post('/get-composition', gljController.init, gljController.getComposition);
 
 router.get('/test', gljController.init, gljController.test);
 router.get('/testModify', gljController.init, gljController.testModify);

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

@@ -194,7 +194,7 @@ CommonSpreadJs.prototype.filterData = function(field, filterList) {
     let fieldColumn = this.getFieldColumn(field);
     fieldColumn = parseInt(fieldColumn);
 
-    let filter = new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 5, -1, 1));
+    let filter = new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, fieldColumn, -1, 1));
     this.sheet.rowFilter(filter);
 
     let rowFilter = this.sheet.rowFilter();

+ 1 - 0
web/building_saas/main/html/main.html

@@ -719,6 +719,7 @@
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/glj.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/project_glj.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/models/composition.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/fee_rate.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_glj.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_coe.js"></script>

+ 77 - 0
web/building_saas/main/js/models/composition.js

@@ -0,0 +1,77 @@
+/**
+ * 组成物相关数据
+ *
+ * @author CaiAoLin
+ * @date 2017/10/27
+ * @version
+ */
+
+function Composition() {
+    this.datas = null;
+    this.isLoading = false;
+}
+/**
+ * 加载数据
+ *
+ * @param {function} callback
+ * @return {boolean}
+ */
+Composition.prototype.loadData = function (callback = null) {
+    let self = this;
+    if (self.isLoading) {
+        return false;
+    }
+    // 加载组成物数据
+    $.ajax({
+        url: '/glj/get-composition',
+        type: 'post',
+        dataType: 'json',
+        data: {project_id: scUrlUtil.GetQueryString('project')},
+        error: function() {
+            // alert('数据传输错误');
+        },
+        beforeSend: function() {
+            self.isLoading = true;
+        },
+        success: function(response) {
+            self.isLoading = false;
+            if (response.err === 1) {
+                let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取组成物数据失败!';
+                alert(msg);
+                return false;
+            }
+            self.datas = response.data;
+            // 回调函数
+            if (callback !== null) {
+                callback(response.data);
+            }
+            // 存入缓存
+            projectObj.project.composition = self;
+        }
+    });
+};
+
+/**
+ * 获取对应code的组成物数据
+ *
+ * @param {String} code
+ * @param {Number} gljType
+ * @return {Array}
+ */
+Composition.prototype.getCompositionByCode = function(code, gljType = 0) {
+    let result = [];
+    if (code === '') {
+        return result;
+    }
+    if (gljType === 0) {
+        return this.datas[code];
+    }
+
+    for(let composition of this.datas[code]) {
+        if (composition.glj_type === gljType) {
+            result.push(composition);
+        }
+    }
+
+    return result;
+};

+ 2 - 0
web/building_saas/main/js/models/project.js

@@ -80,6 +80,8 @@ var PROJECT = {
             this.VolumePrice = VolumePrice.createNew(this);
             this.projectGLJ = new ProjectGLJ();
             this.projectGLJ.loadData();
+            this.composition = new Composition();
+            this.composition.loadData();
             this.Decimal = {
                 common: {
                     quantity: 3,