12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259 |
- /**
- * 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("<li>无引用数据</li>");
- } else {
- htmlArr = info.map((ration) => {
- return `<li>
- <span>${ration.code}</span>
- <a data-dismiss="modal" href="javascript:;" onclick="sectionTreeObj.locateToSection('${ration.code}')">定位</a>
- </li>`;
- });
- }
- $infoBody.html(htmlArr.join(""));
- $info.modal("show");
- });
- },
- //粘贴的数据,编号唯一化,去除编号重复的项
- makeUniqItems: function (items) {
- let rst = [];
- for (let i = 0, len = items.length; i < len; i++) {
- if (typeof items[i].serialNo !== "undefined" && items[i].serialNo) {
- if (rst.length === 0) {
- rst.push(items[i]);
- } else {
- let isExist = false;
- for (let j = 0, jLen = rst.length; j < jLen; j++) {
- if (items[i].serialNo === rst[j].serialNo) {
- isExist = true;
- break;
- }
- }
- if (!isExist) {
- rst.push(items[i]);
- }
- }
- } else {
- rst.push(items[i]);
- }
- }
- return rst;
- },
- isInt: function (num) {
- return !isNaN(num) && num % 1 === 0;
- },
- hasTisNo: function (coeList, newSerialNo) {
- let rst = false;
- for (let i = 0, len = coeList.length; i < len; i++) {
- if (coeList[i].serialNo == newSerialNo) {
- rst = true;
- break;
- }
- }
- return rst;
- },
- updateCurrentCoeList: function (newCoeList) {
- let me = coeOprObj;
- if (newCoeList) {
- me.currentCoeList = me.currentCoeList.concat(newCoeList);
- }
- },
- sortCoeList: function (coeList) {
- coeList.sort(function (a, b) {
- let rst = 0;
- if (a.serialNo > b.serialNo) rst = 1;
- else if (a.serialNo < b.serialNo) rst = -1;
- return rst;
- });
- },
- getCoeList: function () {
- let me = coeOprObj;
- $.ajax({
- type: "post",
- url: "/rationRepository/api/getCoeList",
- data: { libID: pageOprObj.rationLibId },
- dataType: "json",
- timeout: 20000,
- success: function (result) {
- if (!result.error) {
- me.currentCoeList = result.data;
- me.sortCoeList(me.currentCoeList);
- // console.log(me.currentCoeList);
- me.currentMaxNo =
- me.currentCoeList.length > 0
- ? me.currentCoeList[me.currentCoeList.length - 1].serialNo
- : 0;
- pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
- me.workSheet.clearSelection();
- }
- },
- error: function (err) {
- alert("内部程序错误!");
- },
- });
- },
- save: function (addArr, updateArr, deleteArr, refresh, callback) {
- let me = coeOprObj;
- $.ajax({
- type: "POST",
- url: "api/saveCoeList",
- data: {
- data: JSON.stringify({
- addArr: addArr,
- updateArr: updateArr,
- deleteArr: deleteArr,
- }),
- },
- dataType: "json",
- timeout: 5000,
- success: function (result) {
- if (result.error) {
- alert(result.message);
- } else {
- if (callback) {
- if (result.message === "mixed") {
- for (let i = 0, len = result.data.length; i < len; i++) {
- if (result.data[i][0] === "addSc") {
- result.data = result.data[i][1];
- break;
- }
- }
- }
- callback(result.data);
- }
- if (refresh) {
- me.sortCoeList(me.currentCoeList);
- me.currentMaxNo =
- me.currentCoeList.length > 0
- ? me.currentCoeList[me.currentCoeList.length - 1].serialNo
- : 0;
- pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
- }
- }
- },
- error: function (err) {
- alert("内部程序错误!");
- },
- });
- },
- };
- // 验证数量的有效性:可以输入数值,也可以输入表达式,eg: [人材机编码]*1.5+1
- const validateAmount = (amountStr) => {
- if (!amountStr) {
- return true;
- }
- let str = amountStr.replace(/\s/g, "");
- if (!str) {
- return true;
- }
- try {
- str = amountStr.replace(/\s/g, "").replace(/\[\d+\]/g, "0");
- eval(str);
- } catch (error) {
- return false;
- }
- return true;
- };
- let gljAdjOprObj = {
- workBook: null,
- workSheet: null,
- currentGljAdjList: [],
- gljList: [], //只含编号和名称的总工料机列表
- setting: {
- header: [
- {
- headerName: "调整类型",
- headerWidth: 80,
- dataCode: "coeType",
- dataType: "String",
- hAlign: "center",
- vAlign: "center",
- readOnly: false,
- },
- {
- headerName: "人材机编码",
- headerWidth: 80,
- dataCode: "gljCode",
- dataType: "String",
- formatter: "@",
- hAlign: "center",
- vAlign: "center",
- readOnly: false,
- },
- // readOnly: true --> false,需要兼容粘贴列包含只读项
- {
- headerName: "名称",
- headerWidth: 100,
- dataCode: "gljName",
- dataType: "String",
- hAlign: "center",
- vAlign: "center",
- readOnly: false,
- },
- {
- headerName: "操作符",
- headerWidth: 60,
- dataCode: "operator",
- dataType: "String",
- hAlign: "center",
- vAlign: "center",
- readOnly: false,
- },
- {
- headerName: "数量",
- headerWidth: 80,
- dataCode: "amount",
- dataType: "String",
- hAlign: "center",
- vAlign: "center",
- readOnly: false,
- },
- {
- headerName: "替换为编码",
- headerWidth: 80,
- dataCode: "replaceCode",
- dataType: "String",
- formatter: "@",
- hAlign: "center",
- vAlign: "center",
- readOnly: false,
- },
- // readOnly: true --> false
- {
- headerName: "替换为名称",
- headerWidth: 100,
- dataCode: "replaceName",
- dataType: "String",
- hAlign: "center",
- vAlign: "center",
- readOnly: false,
- },
- ],
- comboItems: {
- //调整类型下拉菜单
- coeType: [
- "定额",
- "人工",
- "材料",
- "机械",
- "主材",
- "设备",
- "单个工料机",
- "替换人材机",
- "所选人材机",
- ],
- //操作符下拉菜单
- operator: ["+", "-", "*", "/", "=", "+*", "-*"],
- },
- },
- buildSheet: function (container) {
- let me = gljAdjOprObj;
- me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
- me.workSheet = me.workBook.getSheet(0);
- sheetCommonObj.bindEscKey(me.workBook, [
- {
- sheet: me.workBook.getSheet(0),
- editStarting: me.onEditStart,
- editEnded: me.onEditEnded,
- },
- ]);
- me.workSheet.options.isProtected = true;
- me.onDelOpr(me.workBook, me.setting);
- me.workSheet.clearSelection();
- me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStart);
- me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
- me.workSheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
- me.workSheet.bind(
- GC.Spread.Sheets.Events.ClipboardPasted,
- me.onClipboardPasted
- );
- },
- buildBaseCell: function (sheet) {
- let me = gljAdjOprObj;
- sheet.suspendPaint();
- sheet.suspendEvent();
- let baseCell = GC.Spread.Sheets.CellTypes.Base();
- sheet.getCell(-1, 0).cellType(baseCell);
- sheet.getCell(-1, 3).cellType(baseCell);
- sheet.resumePaint();
- sheet.resumeEvent();
- },
- buildDynamicComboBox: function (sheet) {
- let me = gljAdjOprObj;
- sheet.suspendPaint();
- sheet.suspendEvent();
- let dynamicCombo = sheetCommonObj.getDynamicCombo();
- dynamicCombo.items(me.setting.comboItems.coeType);
- let dynamicOprCombo = sheetCommonObj.getDynamicCombo();
- dynamicOprCombo.items(me.setting.comboItems.operator);
- sheet.getCell(-1, 0).cellType(dynamicCombo);
- sheet.getCell(-1, 3).cellType(dynamicOprCombo);
- sheet.resumePaint();
- sheet.resumeEvent();
- },
- onEnterCell: function (sender, args) {
- args.sheet.repaint();
- },
- onEditStart: function (sender, args) {
- let me = gljAdjOprObj;
- let dataCode = me.setting.header[args.col].dataCode;
- // 超出范围-没有选中的调整主项
- if (!coeOprObj.currentCoe) {
- args.cancel = true;
- return;
- }
- // 名称、替换为名称总是不可编辑(表头设置readOnly没有设置为true,因为需要粘贴)
- let alwaysNotEditable = ["gljName", "replaceName"];
- if (alwaysNotEditable.includes(dataCode)) {
- args.cancel = true;
- return;
- }
- // 新一行编辑时,除了总是可编辑的单元格:调整类型、操作符、数量,其他不可编辑
- let alwaysEditable = ["coeType", "operator", "amount"];
- if (
- args.row > me.currentGljAdjList.length - 1 &&
- !alwaysEditable.includes(dataCode)
- ) {
- args.cancel = true;
- return;
- }
- let curSubCoe = me.currentGljAdjList[args.row];
- if (!curSubCoe) {
- return;
- }
- // 调整类型不为“单个工料机”和“替换人材机”时,人材机编码不可编辑
- if (
- !["单个工料机", "替换人材机"].includes(curSubCoe.coeType) &&
- dataCode === "gljCode"
- ) {
- args.cancel = true;
- return;
- }
- // 调整类型不为“替换人材机”时,替换为编码不可编辑
- if (curSubCoe.coeType !== "替换人材机" && dataCode === "replaceCode") {
- args.cancel = true;
- return;
- }
- },
- onEditEnded: function (sender, args) {
- let me = gljAdjOprObj,
- isUpdate = false,
- dataCode = me.setting.header[args.col].dataCode;
- if (args.editingText && args.editingText.toString().trim().length > 0) {
- if (dataCode === "amount" && !validateAmount(args.editingText)) {
- alert("请输入数值或者表达式,如:[人材机编码]*0.3+1");
- args.sheet.setValue(
- args.row,
- args.col,
- typeof me.currentGljAdjList[args.row] !== "undefined" &&
- typeof me.currentGljAdjList[args.row][dataCode] !== "undefined"
- ? me.currentGljAdjList[args.row][dataCode] + ""
- : ""
- );
- } else {
- //update
- if (
- args.row < me.currentGljAdjList.length &&
- args.editingText.toString().trim() !==
- me.currentGljAdjList[args.row][dataCode]
- ) {
- let updateObj = me.currentGljAdjList[args.row];
- if (
- dataCode === "gljCode" &&
- typeof updateObj.coeType !== "undefined" &&
- (updateObj.coeType === "单个工料机" ||
- updateObj.coeType === "替换人材机")
- ) {
- let gljName = me.getGljName(args.editingText, me.gljList);
- if (gljName) {
- updateObj.gljCode = args.editingText;
- updateObj.gljName = gljName;
- isUpdate = true;
- } else {
- alert("不存在编号为" + args.editingText + "的工料机");
- }
- } else if (
- dataCode === "replaceCode" &&
- typeof updateObj.coeType !== "undefined" &&
- updateObj.coeType === "替换人材机"
- ) {
- let gljName = me.getGljName(args.editingText, me.gljList);
- if (gljName) {
- updateObj.replaceCode = args.editingText;
- updateObj.replaceName = gljName;
- isUpdate = true;
- } else {
- alert("不存在编号为" + args.editingText + "的工料机");
- }
- } else if (dataCode === "coeType") {
- isUpdate = true;
- updateObj[dataCode] = args.editingText;
- updateObj.gljCode = "";
- updateObj.gljName = "";
- updateObj.replaceCode = "";
- updateObj.replaceName = "";
- } else if (dataCode !== "gljCode") {
- isUpdate = true;
- updateObj[dataCode] = args.editingText;
- }
- }
- //insert
- else if (args.row >= me.currentGljAdjList.length) {
- isUpdate = true;
- let newAdjGlj = {};
- newAdjGlj[dataCode] = args.editingText;
- me.currentGljAdjList.push(newAdjGlj);
- }
- if (isUpdate) {
- coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
- console.log(me.currentGljAdjList);
- me.show(me.currentGljAdjList);
- });
- } else {
- args.sheet.setValue(
- args.row,
- args.col,
- typeof me.currentGljAdjList[args.row] !== "undefined" &&
- typeof me.currentGljAdjList[args.row][dataCode] !== "undefined"
- ? me.currentGljAdjList[args.row][dataCode] + ""
- : ""
- );
- }
- }
- }
- },
- getValidPasteData: function (pasteItems, info) {
- let me = gljAdjOprObj;
- function isDef(v) {
- return v !== undefined && v !== null;
- }
- // 粘贴项匹配处理
- let rules = {
- coeType: function (v, cur, tar) {
- if (v === "") {
- tar.coeType = v;
- tar.gljCode = v;
- tar.gljName = v;
- tar.replaceCode = v;
- tar.replaceName = v;
- } else if (me.setting.comboItems.coeType.includes(v)) {
- tar.coeType = v;
- }
- },
- gljCode: function (v, cur, tar) {
- if (v === "") {
- tar.gljCode = v;
- tar.gljName = v;
- } else if (
- ["单个工料机", "替换人材机"].includes(tar.coeType) ||
- (!isDef(tar.coeType) &&
- isDef(cur) &&
- ["单个工料机", "替换人材机"].includes(cur.coeType))
- ) {
- let gljName = me.getGljName(v, me.gljList);
- if (gljName) {
- tar.gljCode = v;
- tar.gljName = gljName;
- }
- }
- },
- amount: function (v, cur, tar) {
- /* if (!isNaN(v)) {
- tar.amount = v;
- } */
- if (validateAmount(v)) {
- tar.amount = v;
- }
- },
- operator: function (v, cur, tar) {
- if (v === "" || me.setting.comboItems.operator.includes(v)) {
- tar.operator = v;
- }
- },
- replaceCode: function (v, cur, tar) {
- if (v === "") {
- tar.replaceCode = v;
- tar.replaceName = v;
- } else if (
- tar.coeType === "替换人材机" ||
- (!isDef(tar.coeType) && isDef(cur) && cur.coeType === "替换人材机")
- ) {
- let replaceName = me.getGljName(v, me.gljList);
- if (replaceName) {
- tar.replaceCode = v;
- tar.replaceName = replaceName;
- }
- }
- },
- };
- let rst = [];
- for (let i = 0, len = pasteItems.length; i < len; i++) {
- let row = i + info.cellRange.row;
- let target = {},
- curObj = me.currentGljAdjList[row],
- pasteItem = pasteItems[i];
- if (row < me.currentGljAdjList.length) {
- target.index = row; //要有下标做为匹配的依据,不然在复制多行并且某个单元格是只读的情况下,这里返回的updateList个数会比选中的行数少,造成更新行和实际不匹配的情况
- }
- for (let pasteKey in pasteItem) {
- if (rules[pasteKey]) {
- rules[pasteKey](pasteItem[pasteKey], curObj, target);
- }
- }
- if (Object.keys(target).length > 0) {
- rst.push(target);
- }
- }
- return rst;
- },
- onClipboardPasted: function (sender, info) {
- let me = gljAdjOprObj,
- row;
- let items = sheetCommonObj.analyzePasteData(me.setting, info);
- let validData = me.getValidPasteData(items, info);
- for (let i = 0, len = validData.length; i < len; i++) {
- row = i + info.cellRange.row;
- //update
- if (
- row < me.currentGljAdjList.length &&
- typeof validData[i].index !== "undefined"
- ) {
- let updateObj = me.currentGljAdjList[validData[i].index]; //这里改成读取下标
- delete validData[i].index; //清除下标
- Object.assign(updateObj, validData[i]);
- }
- //insert
- else {
- me.currentGljAdjList.push(validData[i]);
- }
- }
- if (validData.length > 0) {
- coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
- me.show(me.currentGljAdjList);
- });
- } else {
- me.show(me.currentGljAdjList);
- }
- },
- onDelOpr: function (workBook, setting) {
- let me = gljAdjOprObj;
- workBook.commandManager().register("gljAdjDel", function () {
- let sheet = workBook.getSheet(0);
- let sels = sheet.getSelections();
- let isUpdate = false;
- for (let i = 0, len = sels.length; i < len; i++) {
- if (sels[i].colCount === setting.header.length) {
- //can del
- if (sels[i].row < me.currentGljAdjList.length) {
- isUpdate = true;
- me.currentGljAdjList.splice(sels[i].row, sels[i].rowCount);
- }
- }
- }
- if (isUpdate) {
- coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
- me.show(me.currentGljAdjList);
- });
- }
- });
- workBook
- .commandManager()
- .setShortcutKey(
- null,
- GC.Spread.Commands.Key.del,
- false,
- false,
- false,
- false
- );
- workBook
- .commandManager()
- .setShortcutKey(
- "gljAdjDel",
- GC.Spread.Commands.Key.del,
- false,
- false,
- false,
- false
- );
- },
- getGljName: function (gljCode, gljList, withSpecs) {
- //withSpecs 是否带上规格型号
- let rst = null;
- for (let i = 0, len = gljList.length; i < len; i++) {
- if (gljCode === gljList[i].code) {
- rst =
- withSpecs == true
- ? gljList[i].name + " - " + gljList[i].specs
- : gljList[i].name;
- break;
- }
- }
- return rst;
- },
- show: function (coes) {
- let me = gljAdjOprObj;
- pageObj.showData(me.workSheet, me.setting, coes);
- },
- getGljItemsOcc: function () {
- let me = gljAdjOprObj;
- $.ajax({
- type: "post",
- url: "/stdGljRepository/api/getGljItemsOccupied",
- data: { repId: pageOprObj.gljLibId, occupation: "-_id code name specs" },
- dataType: "json",
- timeout: 5000,
- success: function (result) {
- if (result.error) {
- alert(result.message);
- } else {
- me.gljList = result.data;
- }
- },
- error: function (err) {
- alert("内部程序错误!");
- },
- });
- },
- };
|