|
@@ -998,6 +998,89 @@ var projectObj = {
|
|
|
if (selectedArea.colCount <= 1 && selectedArea.rowCount <= 1) {
|
|
|
return false;
|
|
|
}
|
|
|
+ //获取最左最右坐标
|
|
|
+ let maxCell = {row: selectedArea.row, col: selectedArea.col + selectedArea.colCount};
|
|
|
+ let maxCellX = sheet.getCellRect(maxCell.row, maxCell.col).x ? sheet.getCellRect(maxCell.row, maxCell.col).x : sheet.getCellRect(maxCell.row, maxCell.col - 1).x;
|
|
|
+ let minCell = {row: selectedArea.row, col: selectedArea.col};
|
|
|
+ let minCellX = sheet.getCellRect(minCell.row, minCell.col).x ? sheet.getCellRect(minCell.row, minCell.col).x : sheet.getCellRect(minCell.row, minCell.col + 1).x;
|
|
|
+ // 获取鼠标位置
|
|
|
+ let x = window.event.clientX;
|
|
|
+ let y = window.event.clientY;
|
|
|
+
|
|
|
+ // 匹配数字或小数
|
|
|
+ const regular = /^([0-9]+[.]{1}[0-9]+)$|^([1-9]{1}\d*)$/;
|
|
|
+ // 小数点最高位数
|
|
|
+ let max = 0;
|
|
|
+ let total = 0;
|
|
|
+ let counter = 0;
|
|
|
+ for (let col = selectedArea.col; col < (selectedArea.colCount + selectedArea.col); col++) {
|
|
|
+ for (let row = selectedArea.row; row < (selectedArea.rowCount + selectedArea.row); row++) {
|
|
|
+ const value = sheet.getCell(row, col).text();
|
|
|
+ if (!regular.test(value)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ counter++;
|
|
|
+ // 获取当前数据小数位数
|
|
|
+ let pointPosition = value.toString().indexOf(".");
|
|
|
+ pointPosition = pointPosition < 0 ? pointPosition : pointPosition + 1;
|
|
|
+ const current = pointPosition > 0 ? value.toString().substring(pointPosition, value.toString().length).length : 0;
|
|
|
+ max = current > max ? current : max;
|
|
|
+ total += parseFloat(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果不为0则悬浮显示
|
|
|
+ if (total > 0 && counter > 1) {
|
|
|
+ const div = $('<div id="total-tips"><p>合计: <input type="text" id="total" readonly="readonly" style="border: none;"/></p><p><a href="javascript:void(0);">复制</a></p></div>');
|
|
|
+ div.css({
|
|
|
+ position: "absolute",
|
|
|
+ border: "1px #C0C0C0 solid",
|
|
|
+ background: "#fff",
|
|
|
+ boxShadow: "1px 2px 5px rgba(0,0,0,0.4)",
|
|
|
+ });
|
|
|
+ div.children("p").css({
|
|
|
+ textAlign: "center",
|
|
|
+ padding: 8,
|
|
|
+ marginBottom: 2,
|
|
|
+ });
|
|
|
+ div.children("p").first().css({
|
|
|
+ borderBottom: "1px #C0C0C0 solid"
|
|
|
+ });
|
|
|
+ const totalString = total.toFixed(max);
|
|
|
+ // input长度
|
|
|
+ const inputWidth = totalString.length * 8;
|
|
|
+ // 计算是否会超出显示范围
|
|
|
+ const baseWidth = 48;
|
|
|
+ const baseHeight = 81;
|
|
|
+ const canvasWidth = $("#billsSpreadvp_vp").width();
|
|
|
+ const canvasHeight = $("#billsSpreadvp_vp").height();
|
|
|
+ //x = x + baseWidth + inputWidth > canvasWidth ? x - baseWidth - inputWidth : x;
|
|
|
+ x = maxCellX + baseWidth + inputWidth > canvasWidth ? minCellX - baseWidth - inputWidth : maxCellX + baseWidth;
|
|
|
+ y = y + baseHeight > canvasHeight ? y - baseHeight : y;
|
|
|
+ //test
|
|
|
+ let testT = sheet.getParent().hitTest(x, y);
|
|
|
+ //test
|
|
|
+ div.css({
|
|
|
+ left: x,
|
|
|
+ top: y,
|
|
|
+ });
|
|
|
+
|
|
|
+ div.children().children("#total").width(inputWidth).val(totalString);
|
|
|
+ $("body").append(div);
|
|
|
+ // 用于判断是否要关闭窗体
|
|
|
+ setTimeout(function() {
|
|
|
+ isTotalShowing = true;
|
|
|
+ }, 200);
|
|
|
+ };
|
|
|
+ },
|
|
|
+ /*amountAreaNumber: function(e, info) {
|
|
|
+ if (info.newSelections === undefined || info.newSelections.length <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const selectedArea = info.newSelections[0];
|
|
|
+ const sheet = info.sheet;
|
|
|
+ if (selectedArea.colCount <= 1 && selectedArea.rowCount <= 1) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
// 获取鼠标位置
|
|
|
let x = window.event.clientX;
|
|
|
let y = window.event.clientY;
|
|
@@ -1050,6 +1133,10 @@ var projectObj = {
|
|
|
const canvasHeight = $("#billsSpreadvp_vp").height();
|
|
|
x = x + baseWidth + inputWidth > canvasWidth ? x - baseWidth - inputWidth : x;
|
|
|
y = y + baseHeight > canvasHeight ? y - baseHeight : y;
|
|
|
+ //test
|
|
|
+ let testT = sheet.getParent().hitTest(x, y);
|
|
|
+ console.log(sheet.getCellRect(0, 0));
|
|
|
+ //test
|
|
|
div.css({
|
|
|
left: x,
|
|
|
top: y,
|
|
@@ -1062,7 +1149,7 @@ var projectObj = {
|
|
|
isTotalShowing = true;
|
|
|
}, 200);
|
|
|
};
|
|
|
- },
|
|
|
+ },*/
|
|
|
|
|
|
onButtonClick: function (e, info) {
|
|
|
let colSetting = projectObj.mainController.setting.cols[info.col];
|