/** * Created by CSL on 2017-05-18. */ //modiyied by zhong on 2017/9/21 function refreshALlWorkBook() { if (sectionTreeObj.workBook) { sectionTreeObj.workBook.refresh(); } if (rationOprObj.workBook) { rationOprObj.workBook.refresh(); } if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) { rationGLJOprObj.sheet.getParent().refresh(); } if (coeOprObj.workBook) { coeOprObj.workBook.refresh(); } if (gljAdjOprObj.workBook) { gljAdjOprObj.workBook.refresh(); } if (typeof lossObj !== "undefined" && lossObj.workBook) { lossObj.workBook.refresh(); } } $(document).ready(function () { //定额章节树与定额表 let leftElesObj = {}; leftElesObj.module = moduleName; leftElesObj.resize = $("#slideResizeLeft"); leftElesObj.parent = $("#dataRow"); leftElesObj.left = $("#leftContent"); leftElesObj.right = $("#mainContent"); let maxEval = `$('#rightContent').is(':visible') ? $('#dataRow').width() - $('#rightContent').width() - 300 : $('#dataRow').width() - 300`; SlideResize.horizontalSlide( leftElesObj, { min: 300, max: maxEval }, function () { refreshALlWorkBook(); sectionTreeObj.loadRateWidth(); } ); SlideResize.loadHorizonWidth( moduleName, [$("#slideResizeLeft")], [$("#leftContent"), $("#mainContent")], function () { //refreshAfterZmhs(false); let leftContentWidth = parseFloat( $("#leftContent")[0].style.width.replace("%", "") ), mainContentWidth = parseFloat( $("#mainContent")[0].style.width.replace("%", "") ); let surplus = 100 - leftContentWidth - mainContentWidth; $("#leftContent").css("width", `${leftContentWidth + surplus / 2}%`); $("#mainContent").css("width", `${mainContentWidth + surplus / 2}%`); refreshALlWorkBook(); } ); //定额表与子目换算表 let rightElesObj = {}; rightElesObj.module = moduleName; rightElesObj.resize = $("#slideResizeRight"); rightElesObj.parent = $("#dataRow"); rightElesObj.left = $("#mainContent"); rightElesObj.right = $("#rightContent"); let maxEvalRight = `$('#dataRow').width() - $('#leftContent').width() - 200`; SlideResize.horizontalSlide( rightElesObj, { min: 200, max: maxEvalRight }, function () { refreshALlWorkBook(); } ); //设置水平拖动条的宽度 //@param {Object dom}resize滚动条 function setResizeWidth(resize) { const fixedWidth = 10; //跟滚动条同层的其他节点 let bros = resize.parent().children(); //滚动条节点 及 同层非滚动条节点的索引 let index = bros.index(resize), otherIndex = index ? 0 : 1; const other = resize.parent().children(`:eq(${otherIndex})`); let resizeParentWidth = resize.parent().width(); let resizeDecimalWidth = fixedWidth / resizeParentWidth, otherDecimalWidth = 1 - resizeDecimalWidth; let resizePercentWidth = resizeDecimalWidth * 100 + "%", otherPercentWidth = otherDecimalWidth * 100 + "%"; resize.css("width", resizePercentWidth); other.css("width", otherPercentWidth); } function refreshAfterZmhs(visible) { const min = 20; //宽度比例localstorage key let leftContentKey = `${moduleName}${$("#leftContent").attr("id")}Width`, mainContentKey = `${moduleName}${$("#mainContent").attr("id")}Width`, zmhsContentKey = `${moduleName}${$("#rightContent").attr("id")}Width`; let zmhsWidth = getLocalCache(zmhsContentKey) ? getLocalCache(zmhsContentKey) : $("#rightContent")[0].style.width, mainContentWidth = $("#mainContent")[0].style.width, leftContentWidth; zmhsWidth = parseFloat(zmhsWidth.replace("%", "")); mainContentWidth = parseFloat(mainContentWidth.replace("%", "")); if (visible) { mainContentWidth = mainContentWidth - zmhsWidth / 2 < min ? min : mainContentWidth - zmhsWidth / 2; if (100 - mainContentWidth - zmhsWidth < min) { leftContentWidth = min; zmhsWidth = 100 - mainContentWidth - leftContentWidth; } else { leftContentWidth = 100 - mainContentWidth - zmhsWidth; } } else { mainContentWidth += zmhsWidth / 2; leftContentWidth = 100 - mainContentWidth; } $("#leftContent").css("width", `${leftContentWidth}%`); setLocalCache(leftContentKey, `${leftContentWidth}%`); $("#mainContent").css("width", `${mainContentWidth}%`); setLocalCache(mainContentKey, `${mainContentWidth}%`); $("#rightContent").css("width", `${zmhsWidth}%`); setLocalCache(zmhsContentKey, `${zmhsWidth}%`); let resizes = [$("#slideResizeLeft"), $("#slideResizeRight")]; for (let resize of resizes) { setResizeWidth(resize); } sectionTreeObj.loadRateWidth(); } $("#zmhs").click(function () { if (!$(this).hasClass("active")) { $("#loss").removeClass("active"); $(this).addClass("active"); refreshAfterZmhs(true); $("#zmhsWrap").show(); $("#lossWrap").hide(); $("#rightContent").show(); if (!coeOprObj.workBook) { pageObj.initPage(); } refreshALlWorkBook(); } else { $(this).removeClass("active"); refreshAfterZmhs(false); $("#rightContent").hide(); $("#zmhsWrap").hide(); $("#lossWrap").hide(); refreshALlWorkBook(); } }); //子目换算和调整表上下拖动 let zmhsAdjResize = getZmhsAdjResize(); SlideResize.verticalSlide( zmhsAdjResize.eleObj, zmhsAdjResize.limit, function () { if (coeOprObj.workBook) { coeOprObj.workBook.refresh(); } if (gljAdjOprObj.workBook) { gljAdjOprObj.workBook.refresh(); } } ); loadZmhsAdjSize(zmhsAdjResize); }); function getZmhsAdjResize() { let zmhsAdjResize = {}; zmhsAdjResize.eleObj = { module: moduleName, resize: $("#zmhsAdjResize"), top: $("#mainSpread"), topSpread: $("#mainSpread"), bottom: $("#contentSpread"), bottomSpread: $("#contentSpread"), }; zmhsAdjResize.limit = { min: 150, max: `$(window).height()-$('.header').height()-150-verticalResize`, totalHeight: `$(window).height()-$('.header').height()-verticalResize`, notTopSpread: 0, notBottomSpread: 0, }; return zmhsAdjResize; } function loadZmhsAdjSize(resizeObj) { if (!resizeObj) { resizeObj = getZmhsAdjResize(); } SlideResize.loadVerticalHeight( resizeObj.eleObj.module, resizeObj.eleObj, resizeObj.limit, function () { if (coeOprObj.workBook) { coeOprObj.workBook.refresh(); } if (gljAdjOprObj.workBook) { gljAdjOprObj.workBook.refresh(); } } ); } var pageObj = { initPage: function () { coeOprObj.buildSheet($("#mainSpread")[0]); gljAdjOprObj.buildSheet($("#contentSpread")[0]); coeOprObj.getCoeList(); gljAdjOprObj.getGljItemsOcc(); lockUtil.lockSpreads([coeOprObj.workBook, gljAdjOprObj.workBook], locked); }, showData: function (sheet, setting, data) { let me = pageObj, ch = GC.Spread.Sheets.SheetArea.viewport; sheet.suspendPaint(); sheet.suspendEvent(); sheet.clear( 0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data ); sheet.setRowCount(data.length + 3); for (let col = 0; col < setting.header.length; col++) { var hAlign = "left", vAlign = "center"; if (setting.header[col].hAlign) { hAlign = setting.header[col].hAlign; } else if (setting.header[col].dataType !== "String") { hAlign = "right"; } if (setting.header[col].readOnly) { sheet.getRange(-1, col, -1, 1).locked(true); } else { sheet.getRange(-1, col, -1, 1).locked(false); } vAlign = setting.header[col].vAlign ? setting.header[col].vAlign : vAlign; sheetCommonObj.setAreaAlign( sheet.getRange(-1, col, -1, 1), hAlign, vAlign ); if (setting.header[col].formatter) { sheet.setFormatter( -1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport ); } for (let row = 0; row < data.length; row++) { let val = data[row][setting.header[col].dataCode]; sheet.setValue(row, col, val, ch); } } sheet.resumeEvent(); sheet.resumePaint(); }, }; let coeOprObj = { workBook: null, workSheet: null, currentCoeList: [], currentCoe: null, currentMaxNo: null, setting: { header: [ { headerName: "编号", headerWidth: 50, dataCode: "serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false, }, { headerName: "名称", headerWidth: 200, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false, }, { headerName: "内容", headerWidth: 150, dataCode: "content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false, }, { headerName: "原人材机编码", headerWidth: 90, dataCode: "original_code", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false, }, { headerName: "可选人材机编码", headerWidth: 150, dataCode: "option_codes", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false, }, ], }, buildSheet: function (container) { let me = coeOprObj; me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30); sheetCommonObj.bindEscKey(me.workBook, [ { sheet: me.workBook.getSheet(0), editStarting: null, editEnded: me.onEditEnded, }, ]); me.workSheet = me.workBook.getSheet(0); me.workSheet.options.isProtected = true; me.onDelOpr(me.workBook, me.setting); me.initContextMenu(); me.workSheet.bind( GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged ); me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded); me.workBook.bind( GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting ); me.workBook.bind( GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted ); }, onSelectionChanged: function (sender, info) { if ( (info.oldSelections.length === 0 && info.newSelections.length > 0) || info.oldSelections[0].row !== info.newSelections[0].row ) { const row = info.newSelections[0].row; coeOprObj.coeSelInit(row); } }, coeSelInit: function (row) { const me = coeOprObj; const adj = gljAdjOprObj; if (row < me.currentCoeList.length) { me.currentCoe = me.currentCoeList[row]; adj.currentGljAdjList = me.currentCoe.coes; adj.buildDynamicComboBox(adj.workSheet); } else { me.currentCoe = null; adj.currentGljAdjList = []; adj.buildBaseCell(adj.workSheet); } //refresh & show coes sheetCommonObj.cleanSheet(adj.workSheet, adj.setting, -1); me.workBook.focus(true); adj.show(adj.currentGljAdjList); }, onEditEnded: function (sender, args) { let me = coeOprObj, addArr = [], updateArr = [], dataCode = me.setting.header[args.col].dataCode; if (args.editingText && args.editingText.toString().trim().length > 0) { let inputT = args.editingText.toString().trim(); //update if (args.row < me.currentCoeList.length) { let updateObj = me.currentCoeList[args.row]; if (updateObj[dataCode] != inputT) { if (dataCode === "serialNo") { if (me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)) { me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT; updateObj[dataCode] = inputT; updateArr.push(updateObj); me.save([], updateArr, [], true); } else if (!me.isInt(inputT)) { alert("编号只能为整数!"); args.sheet.setValue(args.row, args.col, updateObj[dataCode] + ""); } else if (me.hasTisNo(me.currentCoeList, inputT)) { alert("该编号已存在!"); args.sheet.setValue(args.row, args.col, updateObj[dataCode] + ""); } } else { updateObj[dataCode] = inputT; me.setOptionList(dataCode, inputT, updateObj); updateArr.push(updateObj); me.save([], updateArr, [], true); } } } //insert else { let newCoe = {}; newCoe.libID = pageOprObj.rationLibId; if (dataCode === "serialNo") { if (me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)) { me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT; newCoe[dataCode] = inputT; addArr.push(newCoe); me.save(addArr, [], [], true, function (result) { me.updateCurrentCoeList(result); }); } else if (!me.isInt(inputT)) { args.sheet.setValue(args.row, args.col, ""); alert("编号只能为整数!"); } else if (me.hasTisNo(me.currentCoeList, inputT)) { args.sheet.setValue(args.row, args.col, ""); alert("该编号已存在!"); } } else { newCoe.serialNo = ++me.currentMaxNo; newCoe[dataCode] = inputT; me.setOptionList(dataCode, inputT, newCoe); addArr.push(newCoe); me.save(addArr, [], [], true, function (result) { me.updateCurrentCoeList(result); }); } } } }, setOptionList: function (dataCode, inputT, obj) { if (dataCode == "option_codes") { //所选人材的情况,要获取人材机下拉列表 inputT = inputT.replace(/[\s\r\n]/g, ""); //去掉空格换行等字符 let optionList = []; let options = inputT.split("|"); for (let code of options) { let name = gljAdjOprObj.getGljName(code, gljAdjOprObj.gljList, true); if (name) optionList.push({ text: name, value: code }); } obj.option_list = optionList; } }, onClipboardPasting: function (sender, info) { let me = coeOprObj, maxCol = info.cellRange.col + info.cellRange.colCount - 1; if (maxCol > me.setting.header.length) { info.cancel = true; } }, onClipboardPasted: function (sender, info) { let me = coeOprObj, addArr = [], updateArr = []; let items = sheetCommonObj.analyzePasteData(me.setting, info); let uniqItems = me.makeUniqItems(items); for (let i = 0, len = uniqItems.length; i < len; i++) { let row = i + info.cellRange.row; //update if (row < me.currentCoeList.length) { let updateObj = me.currentCoeList[row]; for (let attr in uniqItems[i]) { if (attr === "serialNo") { if ( me.isInt(uniqItems[i][attr]) && !me.hasTisNo(me.currentCoeList, uniqItems[i][attr]) ) { me.currentMaxNo = me.currentMaxNo >= uniqItems[i][attr] ? me.currentMaxNo : uniqItems[i][attr]; updateObj[attr] = uniqItems[i][attr]; } } else { updateObj[attr] = uniqItems[i][attr]; } } updateArr.push(updateObj); } //insert else { if ( typeof uniqItems[i].serialNo !== "undefined" && uniqItems[i] && me.isInt(uniqItems[i].serialNo) && !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo) ) { me.currentMaxNo = me.currentMaxNo >= uniqItems[i].serialNo ? me.currentMaxNo : uniqItems[i].serialNo; } else { uniqItems[i].serialNo = ++me.currentMaxNo; } uniqItems[i].libID = pageOprObj.rationLibId; addArr.push(uniqItems[i]); } } if (addArr.length > 0 || updateArr.length > 0) { me.save(addArr, updateArr, [], true, function (result) { me.updateCurrentCoeList(result); }); } }, onDelOpr: function (workBook, setting) { let me = coeOprObj, that = gljAdjOprObj; workBook.commandManager().register("coeListDel", function () { let deleteArr = []; let sheet = workBook.getSheet(0); let sels = sheet.getSelections(); let idx = sels[0].row; for (let i = 0, len = sels.length; i < len; i++) { if (idx > sels[i].row) { idx = sels[i].row; } if (sels[i].colCount === setting.header.length) { //can del for (let r = 0, rLen = sels[i].rowCount; r < rLen; r++) { let row = sels[i].row + r; if (row < me.currentCoeList.length) { deleteArr.push({ libID: me.currentCoeList[row].libID, ID: me.currentCoeList[row].ID, }); } } me.currentCoeList.splice(sels[i].row, sels[i].rowCount); } } if (deleteArr.length > 0) { let coeID = deleteArr[0].ID; me.referenceCheck(coeID, function (info) { if (info.length > 0) { alert("该子目换算已被引用,不能删除!"); } else { me.save([], [], deleteArr, true); me.currentCoe = typeof me.currentCoeList[idx] !== "undefined" ? me.currentCoeList[idx] : null; that.currentGljAdjList = me.currentCoe ? me.currentCoe.coes : []; gljAdjOprObj.show(that.currentGljAdjList); } }); } }); workBook .commandManager() .setShortcutKey( null, GC.Spread.Commands.Key.del, false, false, false, false ); workBook .commandManager() .setShortcutKey( "coeListDel", GC.Spread.Commands.Key.del, false, false, false, false ); }, initContextMenu: function () { const me = this; $.contextMenu({ selector: "#mainSpread", build: function ($triggerElement, e) { //控制允许右键菜单在哪个位置出现 const target = SheetDataHelper.safeRightClickSelection( $triggerElement, e, me.workBook ); const sheet = me.workBook.getSheet(0); if (target.hitTestType === 3) { //在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined' if (typeof target.row !== "undefined") { //控制按钮是否可用 sheet.setActiveCell(target.row, target.col); me.coeSelInit(target.row); } return { callback: function () {}, items: { getReference: { name: "查找引用", disabled: function () { return !me.currentCoeList || !me.currentCoeList[target.row]; }, icon: "fa-search", callback: function () { const coe = me.currentCoeList[target.row]; me.getReference(coe.ID); }, }, }, }; } else { return false; } }, }); }, referenceCheck: function (coeID, callback) { $.bootstrapLoading.start(); CommonAjax.post( "/rationRepository/api/getCoeReference", { rationRepId: pageOprObj.rationLibId, coeID }, function (info) { callback(info); $.bootstrapLoading.end(); }, function () { $.bootstrapLoading.end(); } ); }, getReference: function (coeID) { const $info = $("#info"); const $infoBody = $("#infoBody"); const me = this; me.referenceCheck(coeID, function (info) { let htmlArr = []; if (!info || !info.length) { htmlArr.push("