Browse Source

1. 台账分解,批量插入清单部位,右键提供,新增行,删除行功能
2. 台账分解,添加标准工程量清单,选中工程量清单时,无调整允许添加
3. 调整Spreadjs的自定义CellType组成
4. 备注列,使用EllipsisText和AutoTip的复合单元格

MaiXinRong 5 years ago
parent
commit
00255c70e3
3 changed files with 97 additions and 97 deletions
  1. 2 2
      app/const/spread.js
  2. 41 1
      app/public/js/ledger.js
  3. 54 94
      app/public/js/spreadjs_rela/spreadjs_zh.js

+ 2 - 2
app/const/spread.js

@@ -34,7 +34,7 @@ const withCl = {
             {title: '小计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', readOnly: true},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number', readOnly: true},
             {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
-            {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'}
+            {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'}
         ],
         emptyRows: 3,
         headRows: 2,
@@ -72,7 +72,7 @@ const withoutCl = {
             {title: '施工图复核|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.quantity'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sgfh_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
             {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
-            {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'}
+            {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'}
         ],
         emptyRows: 3,
         headRows: 2,

+ 41 - 1
app/public/js/ledger.js

@@ -1195,7 +1195,7 @@ $(document).ready(function() {
                 const mainNode = mainTree.nodes[sel.row];
                 if (!stdNode) { return; }
                 if (stdType === 'bills') {
-                    if (!mainTree.isLeafXmj(mainNode)) {
+                    if (!(mainNode.b_code && mainNode.b_code !== '') && !mainTree.isLeafXmj(mainNode)) {
                         toast('非最底层项目下,不应添加清单', 'warning');
                         return;
                     }
@@ -1343,6 +1343,46 @@ $(document).ready(function() {
             this.initView();
             SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
             SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
+            $.contextMenu({
+                selector: '.batch-l-t',
+                build: function ($trigger, e) {
+                    const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
+                    return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
+                },
+                items: {
+                    'create': {
+                        name: '新增行',
+                        icon: 'fa-sign-in',
+                        callback: function (key, opt) {
+                            const qdSheet = self.qdSpread.getActiveSheet();
+                            const posSheet = self.posSpread.getActiveSheet();
+                            qdSheet.addRows(qdSheet.getRowCount(), 1);
+                            const index = qdSheet.getRowCount();
+                            qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
+                            posSheet.addColumns(posSheet.getColumnCount(), 1);
+                            posSheet.getCell(0, index + 2, spreadNS.SheetArea.colHeader).text('清单' + index);
+                        },
+                    },
+                    'delete': {
+                        name: '删除行',
+                        icon: 'fa-remove',
+                        callback: function (key, opt) {
+                            const qdSheet = self.qdSpread.getActiveSheet();
+                            const posSheet = self.posSpread.getActiveSheet();
+                            const sel = qdSheet.getSelections()[0];
+                            qdSheet.deleteRows(sel.row, sel.rowCount);
+                            posSheet.deleteColumns(sel.row + 2, sel.rowCount);
+                            for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
+                                qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
+                            }
+                            for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
+                                posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
+                            }
+                            qdSheet.setSelection(sel.row, sel.col, 1, 1);
+                        },
+                    },
+                }
+            });
             // 拉取签约清单数据
             if (dealBills) {
                 SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);

+ 54 - 94
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -345,6 +345,12 @@ const SpreadJsObj = {
             }
             sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.ellipsis);
         }
+        if(colSetting.cellType === 'ellipsisAutoTip') {
+            if (!sheet.extendCellType.ellipsisAutoTip) {
+                sheet.extendCellType.ellipsisAutoTip = this.CellType.getEllipsisTextAutoTipCellType();
+            }
+            sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.ellipsisAutoTip);
+        }
         if(colSetting.cellType === 'html') {
             if (!sheet.extendCellType.html) {
                 sheet.extendCellType.html = this.CellType.getHtmlCellType();
@@ -998,99 +1004,23 @@ const SpreadJsObj = {
          * @returns {TipCellType}
          */
         getTipCellType: function () {
-            const maxHintWidth = 200;
-            const TipCellType = function () {};
-            // 继承 SpreadJs定义的 普通的TextCellType
-            TipCellType.prototype = new spreadNS.CellTypes.Text();
-            const proto = TipCellType.prototype;
-
-            const showTip = function (hitinfo, text) {
-                return text && text !== '';
-            };
-            /**
-             * 获取点击信息
-             * @param {Number} x
-             * @param {Number} y
-             * @param {Object} cellStyle
-             * @param {Object} cellRect
-             * @param {Object} context
-             * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
-             */
-            proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
-                return {
-                    x: x,
-                    y: y,
-                    row: context.row,
-                    col: context.col,
-                    cellStyle: cellStyle,
-                    cellRect: cellRect,
-                    sheet: context.sheet,
-                    sheetArea: context.sheetArea,
-                };
-            };
-            /**
-             * 鼠标进入单元格事件 - 显示悬浮提示
-             * @param {Object} hitinfo - 见getHitInfo返回值
-             */
-            proto.processMouseEnter = function (hitinfo) {
-                let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
-                const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
-                if (col.getTip && Object.prototype.toString.apply(col.getTip) === "[object Function]") {
-                    const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
-                    text = col.getTip(sortData[hitinfo.row]);
-                }
-                const pos = SpreadJsObj.getObjPos(hitinfo.sheet.getParent().qo);
-                if (pos && showTip(hitinfo, text)) {
-                    if (!this._toolTipElement) {
-                        let div = $('#autoTip')[0];
-                        if (!div) {
-                            div = document.createElement("div");
-                            $(div).css("position", "absolute")
-                                .css("border", "1px #C0C0C0 solid")
-                                .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
-                                .css("font", "9pt Arial")
-                                .css("background", "white")
-                                .css("padding", 5).css("z-index", 999).css("word-wrap", "break-word")
-                                .attr("id", 'autoTip');
-                            //$(div).attr("id", "autoTip").attr("class", "sjs-tooltip").css("word-wrap", "break-word");
-                            //$(div).hide();
-                            document.body.insertBefore(div, null);
-                        }
-                        this._toolTipElement = div;
-                        const validWidth = Math.min($(window).width() - (pos.x + hitinfo.x + 15) - 10, maxHintWidth);
-                        $(this._toolTipElement).text(text).css("top", pos.y + hitinfo.y + 15).css("left", pos.x + hitinfo.x + 15)
-                            .css("max-width", validWidth);
-                        $(this._toolTipElement).show("fast");
-                    }
-                }
-            };
-            /**
-             * 鼠标移出单元格事件 - 隐藏悬浮提示
-             * @param {Object} hitinfo - 见getHitInfo返回值
-             */
-            proto.processMouseLeave = function (hitinfo) {
-                if (this._toolTipElement) {
-                    $(this._toolTipElement).hide();
-                    this._toolTipElement = null;
-                }
-            };
-
-            return new TipCellType();
-        },
-        getAutoTipCellType: function () {
-            const maxHintWidth = 200;
+            const maxHintWidth = 200, indent = 15, borderIndent = 10;
             const TipCellType = function () {};
             // 继承 SpreadJs定义的 普通的TextCellType
             TipCellType.prototype = new spreadNS.CellTypes.Text();
             const proto = TipCellType.prototype;
-            const getTextDisplayWidth = function(hitinfo, str) {
+            proto.getTextDisplayWidth = function(hitinfo, str, font) {
                 const xs = hitinfo.sheet.getParent().xs;
                 const ctx = xs.childNodes[0].getContext("2d");
-                ctx.font = hitinfo.cellStyle.font;
+                if (font && font !== '') {
+                    ctx.font = font;
+                } else {
+                    ctx.font = hitinfo.cellStyle.font;
+                }
                 return ctx.measureText(str).width;
             };
-            const showTip = function (hitinfo, text) {
-                return text && text !== '' && getTextDisplayWidth(hitinfo, text) > hitinfo.cellRect.width;
+            proto.showTip = function (hitinfo, text) {
+                return text && text !== '';
             };
             /**
              * 获取点击信息
@@ -1126,7 +1056,7 @@ const SpreadJsObj = {
                     text = col.getTip(sortData[hitinfo.row]);
                 }
                 const pos = SpreadJsObj.getObjPos(hitinfo.sheet.getParent().qo);
-                if (pos && showTip(hitinfo, text)) {
+                if (pos && this.showTip(hitinfo, text)) {
                     if (!this._toolTipElement) {
                         let div = $('#autoTip')[0];
                         if (!div) {
@@ -1136,16 +1066,24 @@ const SpreadJsObj = {
                                 .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
                                 .css("font", "9pt Arial")
                                 .css("background", "white")
-                                .css("padding", 5).css("z-index", 999).css("word-wrap", "break-word")
+                                .css("padding", 5)
+                                .css("z-index", 999)
+                                .css("max-width", maxHintWidth)
+                                .css("word-wrap", "break-word")
                                 .attr("id", 'autoTip');
-                            //$(div).attr("id", "autoTip").attr("class", "sjs-tooltip");
                             document.body.insertBefore(div, null);
                         }
+                        const validWidth = $(window).width() - (pos.x + hitinfo.x + indent) - borderIndent;
+                        const textWidth = this.getTextDisplayWidth(hitinfo, text, "9pt Arial");
+                        if (validWidth >= maxHintWidth || textWidth <= validWidth) {
+                            $(div).text(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x + indent);
+                        } else if (textWidth > maxHintWidth) {
+                            $(div).text(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x - indent - maxHintWidth);
+                        } else {
+                            $(div).text(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x - indent - textWidth);
+                        }
                         this._toolTipElement = div;
-                        const validWidth = Math.min($(window).width() - (pos.x + hitinfo.x + 15) - 10, maxHintWidth);
-                        $(this._toolTipElement).text(text).css("top", pos.y + hitinfo.y + 15).css("left", pos.x + hitinfo.x + 15)
-                            .css("max-width", validWidth);
-                        $(this._toolTipElement).show("fast");
+                        $(div).show("fast");
                     }
                 }
             };
@@ -1162,6 +1100,17 @@ const SpreadJsObj = {
 
             return new TipCellType();
         },
+        getAutoTipCellType: function () {
+            const AutoTipCellType = function () {};
+            // 继承 TipCellType
+            AutoTipCellType.prototype = SpreadJsObj.CellType.getTipCellType();
+            const proto = AutoTipCellType.prototype
+            proto.showTip = function (hitinfo, text) {
+                return text && text !== '' && this.getTextDisplayWidth(hitinfo, text) > hitinfo.cellRect.width;
+            };
+
+            return new AutoTipCellType();
+        },
         /**
          * 获取 带图片的cellType(图片需在document中定义好img,并写入col的img属性)
          *
@@ -1515,7 +1464,7 @@ const SpreadJsObj = {
             const EllipsisTextCellType = function (){};
             EllipsisTextCellType.prototype = new spreadNS.CellTypes.Text;
             const proto = EllipsisTextCellType.prototype;
-            const getEllipsisText = function(c, str, maxWidth) {
+            proto.getEllipsisText = function(c, str, maxWidth) {
                 var width = c.measureText(str).width;
                 var ellipsis = '…';
                 var ellipsisWidth = c.measureText(ellipsis).width;
@@ -1532,11 +1481,22 @@ const SpreadJsObj = {
             };
             proto.paint = function (ctx, value, x, y, w, h, style, context) {
                 ctx.font = style.font;
-                value = getEllipsisText(ctx, value, w - 2);
+                value = this.getEllipsisText(ctx, value, w - 2);
                 spreadNS.CellTypes.Text.prototype.paint.apply(this, [ctx, value, x, y, w, h, style, context]);
             };
             return new EllipsisTextCellType();
         },
+        getEllipsisTextAutoTipCellType: function () {
+            const CellType = function () {};
+            // 继承 TipCellType
+            CellType.prototype = SpreadJsObj.CellType.getAutoTipCellType();
+            const proto = CellType.prototype;
+            const ellipsisTextCellType = SpreadJsObj.CellType.getEllipsisTextCellType();
+            proto.getEllipsisText = ellipsisTextCellType.getEllipsisText;
+            proto.paint = ellipsisTextCellType.paint;
+
+            return new CellType();
+        },
         /**
          * 获取 动态显示ComboBox的cellType
          * @returns {ActiveComboCellType}