Browse Source

造价书列设置

MaiXinRong 8 years ago
parent
commit
ea0d84d406

+ 2 - 0
modules/users/controllers/compilation_controller.js

@@ -140,6 +140,8 @@ class CompilationController extends BaseController {
             compilationList: compilationList,
             billList: JSON.stringify(billList),
             rationList: JSON.stringify(rationList),
+
+            mainTreeCol: JSON.stringify(valuationData.main_tree_col),
             engineeringList: EngineeringList,
             selectedCompilation: selectedCompilation,
             valuationData: valuationData,

+ 2 - 0
modules/users/models/compilation_model.js

@@ -124,6 +124,8 @@ class CompilationModel extends BaseModel {
         updateData[sectionString + ".$.ration_lib"] = data.ration_lib;
         updateData[sectionString + ".$.name"] = data.name;
         updateData[sectionString + ".$.engineering"] = data.engineering;
+        console.log(data.main_tree_col);
+        updateData[sectionString + ".$.main_tree_col"] = JSON.parse(data.main_tree_col);
 
         let result = await this.db.update(condition, updateData);
 

+ 11 - 0
modules/users/models/schemas/compilation.js

@@ -35,6 +35,17 @@ let childrenSchema = new Schema({
     // 类型
     type: {
         type: Number
+    },
+    // 列设置
+    main_tree_col: {
+        type: Schema.Types.Mixed,
+        default: {
+            "emptyRows":3,
+            "headRows":0,
+            "treeCol": 0,
+            "headRowHeight":[],
+            "cols":[]
+        }
     }
 });
 let modelSchema = {

+ 22 - 18
public/web/sheet/sheet_data_helper.js

@@ -40,25 +40,29 @@ var SheetDataHelper = {
         return spread;
     },
     loadSheetHeader: function (setting, sheet) {
-        sheet.setColumnCount(setting.cols.length);
         sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader);
-        setting.headRowHeight.forEach(function (rowHeight, index) {
-            sheet.setRowHeight(index, rowHeight, GC.Spread.Sheets.SheetArea.colHeader);
-        })
-        setting.cols.forEach(function (col, index) {
-            var i, iRow = 0, cell;
-            for (i = 0; i < col.head.spanCols.length; i++) {
-                if (col.head.spanCols[i] !== 0) {
-                    cell = sheet.getCell(iRow, index, GC.Spread.Sheets.SheetArea.colHeader);
-                    cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
-                }
-                if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
-                    sheet.addSpan(iRow, index, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.colHeader);
-                }
-                iRow += col.head.spanRows[i];
-            };
-            sheet.setColumnWidth(index, col.width);
-        });
+        if (setting.headRowHeight) {
+            setting.headRowHeight.forEach(function (rowHeight, index) {
+                sheet.setRowHeight(index, rowHeight, GC.Spread.Sheets.SheetArea.colHeader);
+            });
+        }
+        if (setting.cols) {
+            sheet.setColumnCount(setting.cols.length);
+            setting.cols.forEach(function (col, index) {
+                var i, iRow = 0, cell;
+                for (i = 0; i < col.head.spanCols.length; i++) {
+                    if (col.head.spanCols[i] !== 0) {
+                        cell = sheet.getCell(iRow, index, GC.Spread.Sheets.SheetArea.colHeader);
+                        cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
+                    }
+                    if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
+                        sheet.addSpan(iRow, index, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.colHeader);
+                    }
+                    iRow += col.head.spanRows[i];
+                };
+                sheet.setColumnWidth(index, col.width);
+            });
+        }
     },
     protectdSheet: function (sheet) {
         var option = {

+ 239 - 0
web/users/js/col_setting.js

@@ -0,0 +1,239 @@
+/**
+ * Created by Mai on 2017/8/14.
+ */
+
+let ColSettingObj = {
+    colSetting: null,
+    DEFAULT_TITLE_STYLE: null,
+    DEFAULT_DATA_STYLE: null,
+    Rows: {data: 0, filedName: 0, width: 1, readOnly: 2},
+    getCellStyle: function (font, hAlign, vAlign) {
+        var style = new GC.Spread.Sheets.Style();
+        style.font = font;
+        style.hAlign = hAlign;
+        style.vAlign = vAlign;
+        style.wordWrap = true;
+        return style;
+    },
+    initSheet: function (sheet, setting) {
+        sheet.setColumnCount(2, GC.Spread.Sheets.SheetArea.rowHeader);
+        sheet.setColumnWidth(0, 80, GC.Spread.Sheets.SheetArea.rowHeader);
+        sheet.setColumnWidth(1, 70, GC.Spread.Sheets.SheetArea.rowHeader);
+        sheet.setRowCount(setting.headRows + this.Rows.readOnly + 1);
+
+        sheet.setText(setting.headRows + this.Rows.data, 0, 'Data', GC.Spread.Sheets.SheetArea.rowHeader);
+        sheet.setStyle(setting.headRows + this.Rows.data, -1, this.DEFAULT_DATA_STYLE);
+
+        sheet.setText(setting.headRows + this.Rows.filedName, 1, 'FieldName', GC.Spread.Sheets.SheetArea.rowHeader);
+
+        sheet.setText(setting.headRows + this.Rows.width, 0, 'width', GC.Spread.Sheets.SheetArea.rowHeader);
+        sheet.addSpan(setting.headRows + this.Rows.width, 0, 1, 2, GC.Spread.Sheets.SheetArea.rowHeader);
+
+        sheet.setText(setting.headRows + this.Rows.readOnly, 0, 'ReadOnly', GC.Spread.Sheets.SheetArea.rowHeader);
+        sheet.addSpan(setting.headRows + this.Rows.readOnly, 0, 1, 2, GC.Spread.Sheets.SheetArea.rowHeader);
+    },
+    initColSetting: function (setting) {
+        this.DEFAULT_TITLE_STYLE = this.getCellStyle('Arial', GC.Spread.Sheets.HorizontalAlign.center, GC.Spread.Sheets.VerticalAlign.center);
+        this.DEFAULT_DATA_STYLE = this.getCellStyle('Arial', GC.Spread.Sheets.HorizontalAlign.left, GC.Spread.Sheets.VerticalAlign.center);
+
+        $('#empty-rows').val(setting.emptyRows);
+        $('#col-count').val(setting.cols ? setting.cols.length : 0);
+        $('#header-row-count').val(setting.headRows);
+
+        colEditSpread = new GC.Spread.Sheets.Workbook($('#colEditSpread')[0], {sheetCount: 1});
+        colEditSpread.options.tabStripVisible = false;
+        this.initSheet(colEditSpread.getActiveSheet(), setting);
+        this.setColCount(this.colSetting.cols.length);
+        this.setHeaderRowCount(this.colSetting.headRows);
+    },
+    setColCount: function (count) {
+        let sheet = colEditSpread.getActiveSheet();
+        sheet.setColumnCount(count);
+        for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
+            sheet.setValue(this.colSetting.headRows + this.Rows.width, iCol, sheet.getColumnWidth(iCol), GC.Spread.Sheets.SheetArea.viewport);
+            sheet.setValue(this.colSetting.headRows + this.Rows.readOnly, iCol, false, GC.Spread.Sheets.SheetArea.viewport);
+        }
+    },
+    setHeaderRowCount: function (count) {
+        let sheet = colEditSpread.getActiveSheet(), orgCount = this.colSetting.headRows;
+        if (count < orgCount) {
+            sheet.deleteRows(count, orgCount - count);
+        } else if (count > orgCount) {
+            sheet.addRows(orgCount, count - orgCount);
+            sheet.addSpan(0, 0, count, 1, GC.Spread.Sheets.SheetArea.rowHeader);
+            for (let iRow = orgCount; iRow < count; iRow++) {
+                sheet.setStyle(iRow, -1, this.DEFAULT_TITLE_STYLE);
+            }
+        }
+    },
+    getActualCellRange: function (cellRange, rowCount, columnCount) {
+        if (cellRange.row == -1 && cellRange.col == -1) {
+            return new spreadNS.Range(0, 0, rowCount, columnCount);
+        }
+        else if (cellRange.row == -1) {
+            return new spreadNS.Range(0, cellRange.col, rowCount, cellRange.colCount);
+        }
+        else if (cellRange.col == -1) {
+            return new spreadNS.Range(cellRange.row, 0, cellRange.rowCount, columnCount);
+        }
+
+        return cellRange;
+    },
+    // 批量操作Spread选择的单元格
+    controlSelectCells: function (spread, control) {
+        let sheet = colEditSpread.getActiveSheet();
+        let sel = sheet.getSelections(), i, j;
+
+        sel = this.getActualCellRange(sel[sel.length - 1], sheet.getRowCount(), sheet.getColumnCount());
+        for (i = 0; i < sel.rowCount; i++) {
+            for (j = 0; j < sel.colCount; j++) {
+                control(sheet.getCell(sel.row + i, sel.col + j));
+            }
+        }
+    },
+    generateColSetting: function () {
+        let setting = {}, sheet = colEditSpread.getActiveSheet();
+        setting.emptyRows = parseInt($('#empty-rows').val());
+        setting.headRows = parseInt($('#header-row-count').val());
+        if ($('#is-tree').checked) {
+            setting.treeCol = parseInt($('#treeCol').val());
+        }
+        setting.headRowHeight = [];
+        for (let iRow = 0; iRow < setting.headRows; iRow++) {
+            setting.headRowHeight.push(sheet.getRowHeight(iRow, GC.Spread.Sheets.SheetArea.viewport));
+        };
+        setting.cols = [];
+        for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
+            let col = {};
+            col.width = sheet.getColumnWidth(iCol);
+            col.readOnly = sheet.getValue(setting.headRows + this.Rows.readOnly, iCol) || false;
+
+            col.head = {};
+            col.head.titleNames = [];
+            col.head.spanCols = [];
+            col.head.spanRows = [];
+            col.head.vAlign = [];
+            col.head.hAlign = [];
+            col.head.font = [];
+            for (let iRow = 0; iRow < setting.headRows; iRow++) {
+                let cell = sheet.getCell(iRow, iCol);
+                col.head.titleNames.push(cell.text());
+                let span = sheet.getSpan(iRow, iCol);
+                if (span) {
+                    if (span.col === iCol && span.row === iRow) {
+                        col.head.spanCols.push(span.colCount);
+                        col.head.spanRows.push(span.rowCount);
+                    } else {
+                        col.head.spanCols.push(0);
+                        col.head.spanRows.push(1);
+                    }
+                } else {
+                    col.head.spanCols.push(1);
+                    col.head.spanRows.push(1);
+                }
+                col.head.vAlign.push(cell.vAlign());
+                col.head.hAlign.push(cell.hAlign());
+                col.head.font.push(cell.font());
+            }
+
+            col.data = {};
+            let cell = sheet.getCell(setting.headRows, iCol);
+            col.data.field = cell.text();
+            col.data.vAlign = cell.vAlign();
+            col.data.hAlign = cell.hAlign();
+            col.data.font = cell.font();
+            setting.cols.push(col);
+        }
+        return setting;
+    }
+};
+
+$('#set-column').on('shown.bs.modal', function () {
+    if (!colEditSpread) {
+        ColSettingObj.colSetting = JSON.parse(mainTreeCol);
+        ColSettingObj.initColSetting(ColSettingObj.colSetting);
+    }
+});
+$('#col-count').change(function () {
+    ColSettingObj.setColCount(parseInt($(this).val()));
+});
+$('#header-row-count').change(function () {
+    ColSettingObj.setHeaderRowCount(parseInt($(this).val()));
+    ColSettingObj.colSetting.headRows = parseInt($(this).val());
+});
+$('#merge').click(function () {
+    let sheet = colEditSpread.getActiveSheet();
+    let sel = sheet.getSelections();
+
+    if (sel.length > 0) {
+        sel = ColSettingObj.getActualCellRange(sel[sel.length - 1], sheet.getRowCount(), sheet.getColumnCount());
+        if (sel.row + sel.rowCount > ColSettingObj.colSetting.headRows) {
+            alert('仅HeaderTitle部分可以合并单元格');
+        } else {
+            sheet.addSpan(sel.row, sel.col, sel.rowCount, sel.colCount);
+            //sheet.setTag(sel.row, sel.col, 1);
+        }
+    }
+});
+$('#unmerge').click(function () {
+    let sheet = colEditSpread.getActiveSheet();
+    let sel = sheet.getSelections();
+
+    if (sel.length > 0) {
+        sel = ColSettingObj.getActualCellRange(sel[sel.length - 1], sheet.getRowCount(), sheet.getColumnCount());
+        sheet.suspendPaint();
+        for (var i = 0; i < sel.rowCount; i++) {
+            for (var j = 0; j < sel.colCount; j++) {
+                sheet.removeSpan(i + sel.row, j + sel.col);
+            }
+        }
+        sheet.resumePaint();
+    }
+});
+$('#save-col-setting').click(function () {
+    ColSettingObj.colSetting = ColSettingObj.generateColSetting();
+    mainTreeCol = JSON.stringify(ColSettingObj.colSetting);
+    $('input:hidden[name="main_tree_col"]').val(mainTreeCol);
+    $('#set-column').modal('hide');
+    SheetDataHelper.loadSheetHeader(ColSettingObj.colSetting, colSpread.getActiveSheet());
+});
+
+$('#h-left').click(function () {
+    ColSettingObj.controlSelectCells(spread, function (cell) {
+        cell.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
+    });
+});
+$('#h-center').click(function () {
+    ColSettingObj.controlSelectCells(spread, function (cell) {
+        cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
+    });
+});
+
+$('#h-right').click(function () {
+    ColSettingObj.controlSelectCells(spread, function (cell) {
+        cell.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
+    });
+});
+
+$('#v-top').click(function () {
+    ColSettingObj.controlSelectCells(spread, function (cell) {
+        cell.vAlign(GC.Spread.Sheets.VerticalAlign.top);
+    });
+});
+$('#v-center').click(function () {
+    ColSettingObj.controlSelectCells(spread, function (cell) {
+        cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
+    });
+});
+$('#v-bottom').click(function () {
+    ColSettingObj.controlSelectCells(spread, function (cell) {
+        cell.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
+    });
+});
+
+$('#set-font').click(function () {
+    var sFont = $('#font').val();
+    ColSettingObj.controlSelectCells(spread, function (cell) {
+        cell.font(sFont);
+    });
+});

+ 4 - 1
web/users/js/compilation.js

@@ -233,6 +233,10 @@ function initCompilation() {
     let billListData = billList === undefined ? [] : JSON.parse(billList);
     let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
 
+    // 初始化 造价书列设置
+    colSpread = SheetDataHelper.createNewSpread($('#main-tree-col')[0]);
+    SheetDataHelper.loadSheetHeader(JSON.parse(mainTreeCol), colSpread.getActiveSheet());
+
     if (billListData.length <= 0 || rationLibData.length <= 0) {
         return false;
     }
@@ -251,7 +255,6 @@ function initCompilation() {
         html += tmpHtml;
     }
     $("select[name='ration_lib']").children("option").first().after(html);
-
 }
 
 /**

+ 6 - 2
web/users/views/compilation/add.html

@@ -86,8 +86,8 @@
                     </div>
                     <div class="col-md-8">
                         <legend>造价书列设置<a href="javascript:void(0)" data-toggle="modal" data-target="#set-column" class="btn btn-primary btn-sm pull-right">设置</a></legend>
-                        <div>
-                            S JS预览在此
+                        <input type="hidden" name="main_tree_col" value="<%= mainTreeCol %>">
+                        <div id="main-tree-col">
                         </div>
                     </div>
                 </div>
@@ -100,6 +100,10 @@
 <script type="text/javascript">
     let billList = '<%- billList %>';
     let rationList = '<%- rationList %>';
+    let mainTreeCol = '<%- mainTreeCol %>';
+    let colSpread = null;
+    let colEditSpread = null;
 </script>
+<script type="text/javascript" src="/public/web/sheet/sheet_data_helper.js"></script>
 <script type="text/javascript" src="/web/users/js/compilation.js"></script>
 <%include ../compilation/modal.html %>

+ 18 - 18
web/users/views/compilation/modal.html

@@ -75,25 +75,25 @@
                     <div class="col-md-3">
                         <div class="input-group">
                             <span class="input-group-addon" id="basic-addon1">空行</span>
-                            <input type="number" class="form-control input-sm" value="3">
+                            <input type="number" class="form-control input-sm" value="3" id="empty-rows">
                         </div>
                     </div>
                     <div class="col-md-3">
                         <div class="input-group">
                             <span class="input-group-addon" id="basic-addon1">数据绑定列数</span>
-                            <input type="number" class="form-control input-sm" value="4">
+                            <input type="number" class="form-control input-sm" value="4" id="col-count">
                         </div>
                     </div>
                     <div class="col-md-3">
                         <div class="input-group">
                             <span class="input-group-addon" id="basic-addon1">表头行数</span>
-                            <input type="number" class="form-control input-sm" value="1">
+                            <input type="number" class="form-control input-sm" value="1" id="header-row-count">
                         </div>
                     </div>
                     <div class="col-md-3">
                         <div class="checkbox">
                             <label>
-                                <input type="checkbox"> 是否包含树结构
+                                <input type="checkbox" id="is-tree"> 是否包含树结构
                             </label>
                         </div>
                     </div>
@@ -101,38 +101,38 @@
                 <div class="">
                     <div class="btn-toolbar" role="toolbar">
                         <div class="btn-group" role="group" >
-                            <a href="#" class="btn btn-default btn-sm">合并</a>
-                            <a href="#" class="btn btn-default btn-sm">拆分</a>
+                            <a href="#" class="btn btn-default btn-sm" id="merge">合并</a>
+                            <a href="#" class="btn btn-default btn-sm" id="unmerge">拆分</a>
                         </div>
                         <div class="btn-group" role="group">
-                            <a href="#" class="btn btn-default btn-sm">左对齐</a>
-                            <a href="#" class="btn btn-default btn-sm">居中</a>
-                            <a href="#" class="btn btn-default btn-sm">右对齐</a>
+                            <a href="#" class="btn btn-default btn-sm" id="h-left">左对齐</a>
+                            <a href="#" class="btn btn-default btn-sm" id="h-center">居中</a>
+                            <a href="#" class="btn btn-default btn-sm" id="h-right">右对齐</a>
                         </div>
                         <div class="btn-group" role="group">
-                            <a href="#" class="btn btn-default btn-sm">上对齐</a>
-                            <a href="#" class="btn btn-default btn-sm">垂直居中</a>
-                            <a href="#" class="btn btn-default btn-sm">下对齐</a>
+                            <a href="#" class="btn btn-default btn-sm" id="v-top">上对齐</a>
+                            <a href="#" class="btn btn-default btn-sm" id="v-center">垂直居中</a>
+                            <a href="#" class="btn btn-default btn-sm" id="v-bottom">下对齐</a>
                         </div>
                         <div class="btn-group" role="group">
                             <div class="input-group">
                                 <span class="input-group-addon" id="basic-addon1">字体</span>
-                                <input type="text" class="form-control input-sm" >
+                                <input type="text" class="form-control input-sm" id="font">
                                 <div class="input-group-btn">
-                                    <a href="#" class="btn btn-default btn-sm">设置</a>
+                                    <a href="#" class="btn btn-default btn-sm" id="set-font">设置</a>
                                 </div>
                             </div>
                         </div>
                     </div>
                 </div>
-                <div>
-                    S JS在此
+                <div id="colEditSpread">
                 </div>
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
-                <button type="button" class="btn btn-primary">确定</button>
+                <button type="button" class="btn btn-primary" id="save-col-setting">确定</button>
             </div>
         </div>
     </div>
-</div>
+</div>
+<script type="text/javascript" src="/web/users/js/col_setting.js"></script>

+ 4 - 0
web/users/views/layout/layout.html

@@ -9,6 +9,7 @@
     <meta name=copyright content="smartcost.com.cn">
     <link rel="stylesheet" href="/web/users/css/bootstrap.min.css">
     <link rel="stylesheet" href="/web/users/css/style.css">
+    <link rel="stylesheet" href="/lib/spreadjs/sheets/css/gc.spread.sheets.excel2013lightGray.10.0.1.css" type="text/css">
     <script src="/lib/jquery/jquery.min.js"></script>
     <script src="/web/users/js/lib/bootstrap.min.js"></script>
     <script src="/web/users/js/global.js"></script>
@@ -16,6 +17,9 @@
     <script src="/web/users/js/lib/validate.extend.js"></script>
     <script src="/web/users/js/lib/messages_zh.js"></script>
     <script src="/web/users/js/lib/bootstrap-paginator.js"></script>
+    <!-- spreadJs -->
+    <script type="text/javascript" src="/lib/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js"></script>
+    <script>GC.Spread.Sheets.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";</script>
 </head>
 <body>
 <div class="header">