|
@@ -48,17 +48,31 @@ function calcOneBQJC(xmj) {
|
|
|
return jiacha;
|
|
|
}
|
|
|
|
|
|
+function getPasteHint (str, row = '') {
|
|
|
+ let returnObj = str;
|
|
|
+ if (row) {
|
|
|
+ returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
|
|
|
+ }
|
|
|
+ return returnObj;
|
|
|
+}
|
|
|
+
|
|
|
+const is_numeric = (value) => {
|
|
|
+ if (typeof(value) === 'object') {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
$(document).ready(() => {
|
|
|
function TipCellType()
|
|
|
{
|
|
|
}
|
|
|
TipCellType.prototype = new GC.Spread.Sheets.CellTypes.ColumnHeader();
|
|
|
TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
|
|
|
- var hitInfo = { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
|
|
|
- return hitInfo;
|
|
|
+ return { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
|
|
|
};
|
|
|
TipCellType.prototype.processMouseEnter = function (hitInfo){
|
|
|
- console.log(hitInfo);
|
|
|
if (!this._toolTipElement) {
|
|
|
var div = document.createElement("div");
|
|
|
$(div).css("position", "absolute")
|
|
@@ -124,7 +138,7 @@ $(document).ready(() => {
|
|
|
// console.log(gcl.leafXmjs);
|
|
|
SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gcl.leafXmjs);
|
|
|
// 对清单调差工料table的单位数量进行改变
|
|
|
- materialSpreadSetting.cols[materialSpreadSetting.cols.length - 1].title = '|' + gcl.unit + '数量�';
|
|
|
+ materialSpreadSetting.cols[materialSpreadSetting.cols.length - 1].title = '|' + gcl.unit + '数量 �';
|
|
|
SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
|
|
|
} else {
|
|
|
SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
|
|
@@ -184,7 +198,7 @@ $(document).ready(() => {
|
|
|
{title: '清单调差工料|编号', colSpan: '4|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
|
|
|
{title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
|
|
|
{title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
|
|
|
- {title: '|数量�', colSpan: '1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
|
|
|
+ {title: '|数量 �', colSpan: '1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
|
|
|
],
|
|
|
emptyRows: 0,
|
|
|
headRows: 2,
|
|
@@ -403,12 +417,16 @@ $(document).ready(() => {
|
|
|
SpreadJsObj.reLoadRowData(lsheet, iRow);
|
|
|
});
|
|
|
},
|
|
|
+ deletePress: function (sheet) {
|
|
|
+ return;
|
|
|
+ },
|
|
|
editEnded: function (e, info) {
|
|
|
if (info.sheet.zh_setting) {
|
|
|
const select = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
const col = info.sheet.zh_setting.cols[info.col];
|
|
|
// 未改变值则不提交
|
|
|
- const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
|
|
|
+ // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
|
|
|
+ const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
|
|
|
const orgValue = select[col.field];
|
|
|
if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
|
|
|
SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
@@ -442,9 +460,102 @@ $(document).ready(() => {
|
|
|
SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
});
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ clipboardPasted(e, info) {
|
|
|
+ const hint = {
|
|
|
+ cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
|
|
|
+ numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
|
|
|
+ numberCan: {type: 'error', msg: '请粘贴大于0并且小于6位小数的浮点数'},
|
|
|
+ };
|
|
|
+ const range = info.cellRange;
|
|
|
+ const sortData = info.sheet.zh_data || [];
|
|
|
+ if (range.row + range.rowCount > sortData.length) {
|
|
|
+ toastMessageUniq(hint.cellError);
|
|
|
+ SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
|
|
|
+ SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (sortData.length > 0 && range.col + range.colCount > 4) {
|
|
|
+ toastMessageUniq(hint.cellError);
|
|
|
+ SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
|
|
|
+ SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log(info);
|
|
|
+ // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
+ const data = [];
|
|
|
+ // const rowData = [];
|
|
|
+ for (let iRow = 0; iRow < range.rowCount; iRow++) {
|
|
|
+ let bPaste = true;
|
|
|
+ const curRow = range.row + iRow;
|
|
|
+ // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
|
|
|
+ const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
|
|
|
+ const hintRow = range.rowCount > 1 ? curRow : '';
|
|
|
+ let sameCol = 0;
|
|
|
+ for (let iCol = 0; iCol < range.colCount; iCol++) {
|
|
|
+ const curCol = range.col + iCol;
|
|
|
+ const colSetting = info.sheet.zh_setting.cols[curCol];
|
|
|
+ if (!colSetting) continue;
|
|
|
+
|
|
|
+ let validText = info.sheet.getText(curRow, curCol);
|
|
|
+ validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
|
|
|
+ const orgValue = sortData[curRow][colSetting.field];
|
|
|
+ if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
|
|
|
+ sameCol++;
|
|
|
+ if (range.colCount === sameCol) {
|
|
|
+ bPaste = false;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (colSetting.field === 'quantity') {
|
|
|
+ if (isNaN(validText)) {
|
|
|
+ toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
|
|
|
+ bPaste = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ const num = parseFloat(validText);
|
|
|
+ if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
|
|
|
+ toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
|
|
|
+ bPaste = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ materialData[colSetting.field] = validText;
|
|
|
+ }
|
|
|
+ if (bPaste) {
|
|
|
+ data.push(materialData);
|
|
|
+ // rowData.push(curRow);
|
|
|
+ } else {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, curRow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (data.length === 0) {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log(data);
|
|
|
+ // 更新至服务器
|
|
|
+ // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
|
|
|
+ // materialBillsData = result.info;
|
|
|
+ // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
|
|
|
+ // }, function () {
|
|
|
+ // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
+ // return;
|
|
|
+ // });
|
|
|
+ // 更新至服务器
|
|
|
+ postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
|
|
|
+ materialListData = result;
|
|
|
+ const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
|
|
|
+ gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
|
|
|
+ SpreadJsObj.reLoadRowData(sheet, iRow);
|
|
|
+ }, function () {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
+ });
|
|
|
+ },
|
|
|
};
|
|
|
materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
|
|
|
+ materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
|
|
|
+ SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
|
|
|
const sheet = materialSpread.getActiveSheet();
|
|
|
sheet.suspendPaint();
|
|
|
// const basic_range = sheet.getRange(1, 3);
|