Browse Source

清单工程量精度

zhongzewei 7 years ago
parent
commit
9f2e0068d1

+ 0 - 2
modules/complementary_glj_lib/controllers/gljController.js

@@ -128,8 +128,6 @@ class GljController extends BaseController{
     mixUpdateGljItems(req, res){
         let user_id = req.session.sessionUser.ssoId,
             compilation_id = req.session.sessionCompilation._id;
-        console.log(user_id);
-        console.log(compilation_id);
         let data = JSON.parse(req.body.data);
         let updateItems = data.updateItems,
             addItems = data.addItems,

+ 2 - 0
modules/pm/models/project_model.js

@@ -5,6 +5,7 @@ import mongoose from 'mongoose';
 import async_c from 'async';
 import UnitPriceFileModel from "../../glj/models/unit_price_file_model";
 import UnitPriceFiles from '../../glj/models/schemas/unit_price_file';
+import billsQuantityDecimal from './project_property_bills_quantity_decimal';
 let FeeRateFiles = mongoose.model('fee_rate_file');
 let counter = require("../../../public/counter/counter.js");
 
@@ -103,6 +104,7 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, datas, callbac
                 }
                 if(data.updateData.projType === projectType.tender){
                     data.updateData.property.decimal = defaultDecimal;
+                    data.updateData.property.billsQuantityDecimal = billsQuantityDecimal;
                 }
                 newProject = new Projects(data.updateData);
                 // 查找同级是否存在同名数据

+ 51 - 0
modules/pm/models/project_property_bills_quantity_decimal.js

@@ -0,0 +1,51 @@
+/**
+ * Created by Zhong on 2017/11/16.
+ */
+/*
+* 单位工程清单工程量精度模板
+* */
+const billsQuantityDecimal = [
+    {unit: '其他未列单位', decimal: 2},
+    {unit: 't', decimal: 3},
+    {unit: '吨', decimal: 3},
+    {unit: 'km', decimal: 3},
+    {unit: '千米', decimal: 3},
+    {unit: 'm', decimal: 2},
+    {unit: '米', decimal: 2},
+    {unit: 'm2', decimal: 2},
+    {unit: '平方米', decimal: 2},
+    {unit: 'm3', decimal: 2},
+    {unit: '立方米', decimal: 2},
+    {unit: 'kg', decimal: 2},
+    {unit: '千克', decimal: 2},
+    {unit: '公斤', decimal: 2},
+    {unit: '元', decimal: 2},
+    {unit: '工日', decimal: 0},
+    {unit: '台班', decimal: 0},
+    {unit: '个', decimal: 0},
+    {unit: '件', decimal: 0},
+    {unit: '根', decimal: 0},
+    {unit: '组', decimal: 0},
+    {unit: '宗', decimal: 0},
+    {unit: '付', decimal: 0},
+    {unit: '处', decimal: 0},
+    {unit: '系统', decimal: 0},
+    {unit: '部', decimal: 0},
+    {unit: '台', decimal: 0},
+    {unit: '辆', decimal: 0},
+    {unit: '套', decimal: 0},
+    {unit: '株', decimal: 0},
+    {unit: '从', decimal: 0},
+    {unit: '缸', decimal: 0},
+    {unit: '支', decimal: 0},
+    {unit: '只', decimal: 0},
+    {unit: '块', decimal: 0},
+    {unit: '座', decimal: 0},
+    {unit: '对', decimal: 0},
+    {unit: '份', decimal: 0},
+    {unit: '樘', decimal: 0},
+    {unit: '攒', decimal: 0},
+    {unit: '榀', decimal: 0}
+];
+
+export default billsQuantityDecimal;

+ 4 - 3
web/building_saas/main/html/main.html

@@ -264,7 +264,7 @@
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-2" role="tab">工程特征</a></li>
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-3" role="tab">指标信息</a></li>
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-4" role="tab">关于计算</a></li>
-                                <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-5" role="tab">清单工程精度</a></li>
+                                <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-billsQuanDecimal" id="tab_poj-settings-bqDecimal" role="tab">清单工程精度</a></li>
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-decimal" role="tab" id="tab_poj-settings-decimal">小数位数</a></li>
                                 <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#poj-settings-6" role="tab" id="tab_poj-settings-6">人工单价调整</a></li>
                             </ul>
@@ -337,8 +337,8 @@
                                     </div>
                                 </div>
                                 <!--清单工程精度-->
-                                <div class="tab-pane fade" id="poj-settings-5" role="tabpanel">
-                                    <div class="modal-auto-height" id="quantityPrecision">
+                                <div class="tab-pane fade" id="poj-settings-billsQuanDecimal" role="tabpanel">
+                                    <div class="modal-auto-height" style="overflow: hidden;" id="billsQuanDecimal">
                                     </div>
                                 </div>
                                 <!--小数位数-->
@@ -663,6 +663,7 @@
         <script type="text/javascript" src="/web/building_saas/main/js/views/project_info.js"></script>
         <script type="text/javascript" src="/web/building_saas/main/js/views/project_view.js"></script>
         <script type="text/javascript" src="/web/building_saas/main/js/views/options_view.js"></script>
+        <script type="text/javascript" src="/web/building_saas/main/js/views/project_property_bills_quantity_decimal.js"></script>
         <script type="text/javascript" src="/web/building_saas/main/js/views/project_property_decimal_view.js"></script>
         <script type="text/javascript" src="/web/building_saas/main/js/main_ajax.js"></script>
         <script type="text/javascript" src="/web/building_saas/main/js/main.js"></script>

+ 1 - 0
web/building_saas/main/js/views/project_info.js

@@ -28,6 +28,7 @@ var projectInfoObj = {
                 that.projectInfo = data;
                 //init decimal
                 setDecimal(decimalObj, data.property.decimal);
+                billsQuanDecimal.datas = data.property.billsQuantityDecimal;
                 $('#fullpath').html(that.getFullPathHtml(that.projectInfo));
             }
         });

+ 348 - 0
web/building_saas/main/js/views/project_property_bills_quantity_decimal.js

@@ -0,0 +1,348 @@
+/**
+ * Created by Zhong on 2017/11/15.
+ */
+/*
+* 清单工程量精度
+* */
+let billsQuanDecimal = {
+    datas: [],
+    //根据单位获取精度, 需要用清单工程量精度的调用此接口
+    decimal: function (unit) {
+        for(let i = 0, len = this.datas.length; i < len; i++){
+            if(unit === this.datas[i].unit){
+                return this.datas[i].decimal;
+            }
+        }
+        return this.datas[0].decimal;
+    }
+};
+
+//点了确定才更新数据
+let billsDecimalView = {
+    default: {min: 0, max: 4, decimal: 3},//以防后面修改,小数数位的取值范围, default.decimal为新增时默认的小数位
+    angleDecimal: {unit: '其他未列单位', decimal: 2},//防止出现工程没有初始默认的清单工程量精度模板(正常不会出现)
+    cache: [],//temp
+    workBook: null,
+    setting:{
+        header: [
+            {name: '计量单位', dataCode: 'unit', width: 120, vAlign: 'center', hAlign: 'left'},
+            {name: '小数位数', dataCode: 'decimal', width: 80, vAlign: 'center', hAlign: 'center'}
+        ],
+        options: {
+            tabStripVisible:  false,
+            allowCopyPasteExcelStyle : false,
+            allowUserDragDrop : false,
+            allowUserDragFill: false,
+            scrollbarMaxAlign : true
+        }
+    },
+
+    renderSheetFuc: function (sheet, fuc) {
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        fuc();
+        sheet.resumePaint();
+        sheet.resumeEvent();
+    },
+
+    setOptions: function (workbook, opts) {
+        for(let opt in opts){
+            workbook.options[opt] = opts[opt];
+        }
+    },
+
+    getComboItems: function (min, max) {
+        let rst = [];
+        while (min <= max){
+            rst.push(min);
+            min ++;
+        }
+        return rst;
+    },
+    
+    setComboBox: function (sheet, items) {
+        let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
+        combo.items(items);
+        combo.editable(true);
+        sheet.getRange(-1, 1, -1, 1).cellType(combo);
+    },
+
+    buildHeader: function (sheet, headers) {
+        let me = billsDecimalView;
+        let fuc = function () {
+            sheet.setColumnCount(headers.length);
+            sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
+            me.setComboBox(sheet, me.getComboItems(me.default.min, me.default.max));
+            for(let i = 0, len = headers.length; i < len; i++){
+                sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
+                sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
+            }
+        };
+        me.renderSheetFuc(sheet, fuc);
+    },
+
+    buildSheet: function () {
+        if(!this.workBook){
+            this.workBook = new GC.Spread.Sheets.Workbook($('#billsQuanDecimal')[0], {sheetCount: 1});
+            this.setOptions(this.workBook, this.setting.options);
+            this.buildHeader(this.workBook.getActiveSheet(), this.setting.header);
+            this.bindEvent(this.workBook);
+            this.onContextmenuOpr();
+        }
+    },
+
+    bindEvent: function (workBook) {
+        const _events = GC.Spread.Sheets.Events;
+        let sheet = workBook.getActiveSheet();
+        sheet.bind(_events.EditStarting, this.onEditStarting);
+        sheet.bind(_events.EditEnded, this.onEditEnded);
+        sheet.bind(_events.ClipboardPasting, this.onClipboardPasting);
+        sheet.bind(_events.ClipboardPasted, this.onClipboardPasted);
+    },
+
+    showData(datas){
+        let sheet = this.workBook.getActiveSheet();
+        let cols = this.setting.header;
+        let fuc = function () {
+            sheet.setRowCount(datas.length);
+            for(let col = 0, cLen = cols.length; col < cLen; col++){
+                sheet.getRange(-1, col, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[cols[col]['hAlign']]);
+                sheet.getRange(-1, col, -1, 1).hAlign(GC.Spread.Sheets.VerticalAlign[cols[col]['vAlign']]);
+                for(let row = 0, rLen = datas.length; row < rLen; row++){
+                    sheet.setValue(row, col, datas[row][cols[col]['dataCode']]);
+                }
+            }
+        };
+        this.renderSheetFuc(sheet, fuc);
+    },
+
+    onEditStarting: function (sender, args) {
+        if(args.col === 0 && args.row === 0){//其他未列单位不可编辑
+            args.cancel = true;
+        }
+    },
+
+    onEditEnded: function (sender, args) {
+        let me = billsDecimalView;
+        let v =  args.editingText ? args.editingText.toString().trim() : '';
+        if(v.length === 0){
+            return;
+        }
+        if(args.col === 0){
+            if(me.hasUnit(me.cache, v)){
+                alert('已存在此计量单位');
+                args.sheet.setValue(args.row, args.col, me.isDef(me.cache[args.row]) ? me.cache[args.row].unit : '');
+            }
+            else {
+                me.cache[args.row].unit = v;
+                if(!me.isValidDecimal(me.cache[args.row].decimal)){
+                    me.cache[args.row].decimal = me.default.decimal;
+                    args.sheet.setValue(args.row, 1, me.default.decimal);
+                }
+            }
+        }
+        else if(args.col === 1){
+            if(!me.isValidDecimal(v)){
+                alert('小数位数只能是'+ me.default.min + '-' + me.default.max + '的整数');
+                args.sheet.setValue(args.row, args.col, me.isDef(me.cache[args.row]) ? me.cache[args.row].decimal : '');
+            }
+            else {
+                me.cache[args.row].decimal = v;
+            }
+        }
+    },
+
+    onClipboardPasting: function (sender, args) {
+        if(args.cellRange.row === 0 && args.cellRange.col === 0){
+            args.cancel = true;
+            alert('不可更改其他未列计量单位');
+        }
+    },
+
+    onClipboardPasted: function (sender, args) {
+        let me = billsDecimalView;
+        let items = sheetCommonObj.analyzePasteData(me.setting, args);
+        for(let i = 0, len = items.length; i < len; i++){
+            let row = args.cellRange.row + i;
+            if(me.isDef(me.cache[row])){
+                if(me.isDef(items[i].unit) && !me.hasUnit(me.cache, items[i].unit)){
+                    me.cache[row].unit = items[i].unit;
+                }
+                if(me.isValidDecimal(items[i].decimal)){
+                    me.cache[row].decimal = items[i].decimal;
+                }
+            }
+        }
+        me.showData(me.cache);
+    },
+
+    onContextmenuOpr: function () {//右键菜单
+        let me = billsDecimalView;
+        $.contextMenu({
+            selector: '#billsQuanDecimal',
+            build: function($triggerElement, e){
+                //控制允许右键菜单在哪个位置出现
+                let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
+                let sheet = me.workBook.getSheet(0);
+                if(target.hitTestType === 3 && typeof target.row !== 'undefined'){//在表格内
+                    let delDis = false;
+                    let insertDis = false;
+                    //控制按钮是否可用
+                    sheet.setActiveCell(target.row, target.col);
+                    if(target.row === 0){//不可删除其他未列单位行
+                        delDis = true;
+                    }
+                    if(!me.isDef(me.cache) || target.row >= me.cache.length){//有数据才能删除
+                        delDis = true;
+                    }
+                    return {
+                        callback: function(){},
+                        items: {
+                            "insert": {name: "添加", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
+                                //插入空行
+                                me.addRow(me.cache, sheet, target.row);
+                            }},
+                            "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
+                               me.deleteRow(me.cache, sheet, target.row);
+                            }}
+                        }
+                    };
+                }
+                else{
+                    return false;
+                }
+            }
+        });
+    },
+    //新增一空白行
+    addRow: function (all, sheet, row) {
+        let func = function () {
+            let data = Object.create(null);
+            data.unit = '';
+            data.decimal = '';
+            //新增空行
+            if(row === 0){//保证其他未列单位在第一行
+                row = 1;
+            }
+            //新增空白数据
+            all.splice(row, 0, data);
+            sheet.addRows(row, 1);
+        };
+        this.renderSheetFuc(sheet, func);
+    },
+
+    deleteRow: function (all, sheet, row) {
+        let func = function () {
+            all.splice(row, 1);
+            sheet.deleteRows(row, 1);
+        };
+        this.renderSheetFuc(sheet, func);
+    },
+
+    isDef: function (v) {
+        return v !== undefined && v !== null;
+    },
+
+    isData: function (v) {
+        return this.isDef(v) && v.toString().trim().length > 0;
+    },
+
+    isValidDecimal: function (v) {
+        return this.isData(v) && !isNaN(v) && parseInt(v) % 1 === 0 && parseInt(v) >= this.default.min && parseInt(v) <= this.default.max;
+    },
+
+    hasUnit: function (all, v) {
+        for(let i = 0, len = all.length; i < len; i++){
+            if(all[i].unit === v){
+                return true;
+            }
+        }
+        return false;
+    },
+
+    rowHasData: function (sheet, row) {
+        let v = sheet.getValue(row, 0);
+        if(v && v.toString().trim().length > 0) {
+            return true;
+        }
+        return false;
+    },
+
+    toUpdate: function (orgV, newV) {//org: billsDecimal.datas, newV: toBillsDecimalDatas(cache)
+        for(let i = 0, len = orgV.length; i < len; i++){
+            if(!this.isDef(newV[i])){
+                return true;
+            }
+            else {
+                if(orgV[i].unit !== newV[i].unit || orgV[i].decimal !== newV[i].decimal){
+                    return true;
+                }
+            }
+        }
+        return false;
+    },
+
+    //将tempDatas提取出新的请单工程量精度数据
+    toBillsDecimalDatas: function (datas) {
+        let rst = [];
+        for(let i = 0, len = datas.length; i < len; i++){
+            if(this.isData(datas[i].unit) && this.isValidDecimal(datas[i].decimal)){
+                datas[i].decimal = parseInt(datas[i].decimal);
+                rst.push(datas[i]);
+            }
+        }
+        return rst;
+    },
+    
+    a_update: function (datas) {
+        let url = '/pm/api/updateProjects';
+        let updateData = {
+            updateType: 'update',
+            updateData: {
+                ID: parseInt(scUrlUtil.GetQueryString('project')),
+                'property.billsQuantityDecimal': datas
+            }
+        };
+        let postData = {
+            user_id: userID,
+            updateData: [updateData]
+        };
+        CommonAjax.post(url, postData, function () {
+            billsQuanDecimal.datas = datas;
+        });
+    }
+};
+
+$(document).ready(function () {
+    $('#poj-set').on('shown.bs.modal', function (e) {
+        //init Spread
+        if(billsDecimalView.isDef(billsQuanDecimal.datas)){
+            billsDecimalView.cache = billsDecimalView.cache.concat(billsQuanDecimal.datas);
+        }
+        if(billsDecimalView.cache.length === 0){
+            billsDecimalView.cache.push(billsDecimalView.angleDecimal);
+        }
+        billsDecimalView.buildSheet();
+        billsDecimalView.showData(billsDecimalView.cache);
+    });
+
+    $('#poj-set').on('hidden.bs.modal', function (e) {
+        //destroy Spread
+        if(billsDecimalView.workBook){
+            billsDecimalView.workBook.destroy();
+            billsDecimalView.workBook = null;
+        }
+        billsDecimalView.cache = [];
+    });
+
+    $('#tab_poj-settings-bqDecimal').on('shown.bs.tab', function () {
+        billsDecimalView.workBook.refresh();
+    });
+
+    $('#property_ok').bind('click', function () {
+        let newBillsDecimalDatas = billsDecimalView.toBillsDecimalDatas(billsDecimalView.cache);
+        if(billsDecimalView.toUpdate(billsQuanDecimal.datas, newBillsDecimalDatas)){
+            billsDecimalView.a_update(newBillsDecimalDatas);
+        }
+    });
+});