1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087 |
- /**
- * Created by Tony on 2017/4/28.
- */
- $(document).ready(function () {
- //定额表与下方子表上下拖动
- let rationSubResize = getRationSubResize();
- SlideResize.verticalSlide(
- rationSubResize.eleObj,
- rationSubResize.limit,
- function () {
- if (rationOprObj.workBook) {
- rationOprObj.workBook.refresh();
- }
- if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
- rationGLJOprObj.sheet.getParent().refresh();
- }
- }
- );
- SlideResize.loadVerticalHeight(
- rationSubResize.eleObj.module,
- rationSubResize.eleObj,
- rationSubResize.limit,
- function () {
- if (rationOprObj.workBook) {
- rationOprObj.workBook.refresh();
- }
- if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
- rationGLJOprObj.sheet.getParent().refresh();
- }
- }
- );
- });
- function getRationSubResize() {
- let rationSubResize = {};
- rationSubResize.eleObj = {
- module: moduleName,
- resize: $("#rationSubResize"),
- top: $("#rationItemsSheet"),
- topSpread: $("#rationItemsSheet"),
- bottom: $("#subContent"),
- bottomSpread: $("#rdSpread"),
- };
- rationSubResize.limit = {
- min: 150,
- max: `$(window).height()-$('.header').height()-$('.tools-bar').height()-150-verticalResize`,
- totalHeight: `$(window).height()-$('.header').height()-$('.tools-bar').height()-verticalResize`,
- notTopSpread: 0,
- notBottomSpread: $("#subContent ul").height(),
- };
- return rationSubResize;
- }
- function loadRationSubSize(resizeObj) {
- if (!resizeObj) {
- resizeObj = getRationSubResize();
- }
- SlideResize.loadVerticalHeight(
- resizeObj.eleObj.module,
- resizeObj.eleObj,
- resizeObj.limit,
- function () {
- if (rationOprObj.workBook) {
- rationOprObj.workBook.refresh();
- }
- if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
- rationGLJOprObj.sheet.getParent().refresh();
- }
- }
- );
- }
- const digital = {
- gljPrc: -3, //计算定额基价时单个工料机价格取三位
- rationBasePrc: -2,
- consumeAmt: -3,
- };
- let rationOprObj = {
- workBook: null,
- currentRations: {},
- currentEditingRation: null,
- currentSectionId: -1,
- rationsCodes: [],
- setting: {
- header: [
- {
- headerName: "编码",
- headerWidth: 70,
- dataCode: "code",
- dataType: "String",
- formatter: "@",
- },
- {
- headerName: "名称",
- headerWidth: 240,
- dataCode: "name",
- dataType: "String",
- },
- {
- headerName: "计量单位",
- headerWidth: 70,
- dataCode: "unit",
- dataType: "String",
- hAlign: "center",
- },
- /*{headerName:"人工费",headerWidth:80,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
- {headerName:"材料费",headerWidth:80,dataCode:"materialPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
- {headerName:"机械费",headerWidth:80,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},*/
- {
- headerName: "基价",
- headerWidth: 80,
- dataCode: "basePrice",
- dataType: "Number",
- hAlign: "right",
- },
- {
- headerName: "显示名称(以%s表示参数)",
- headerWidth: 240,
- dataCode: "caption",
- dataType: "String",
- },
- {
- headerName: "取费专业",
- headerWidth: 70,
- dataCode: "feeType",
- dataType: "String",
- hAlign: "center",
- formatter: "@",
- },
- {
- headerName: "油石比",
- headerWidth: 80,
- dataCode: "oilStoneRatio",
- dataType: "Number",
- hAlign: "right",
- },
- ],
- view: {
- comboBox: [{ row: -1, col: 2, rowCount: -1, colCount: 1 }],
- lockColumns: [3],
- },
- },
- buildSheet: function (container) {
- let rationRepId = getQueryString("repository");
- let me = rationOprObj;
- me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
- sheetCommonObj.bindEscKey(me.workBook, [
- {
- sheet: me.workBook.getSheet(0),
- editStarting: me.onCellEditStart,
- editEnded: me.onCellEditEnd,
- },
- ]);
- me.onContextmenuOpr();
- me.rationDelOpr();
- me.setCombo(me.workBook.getSheet(0), "dynamic");
- me.workBook
- .getSheet(0)
- .bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
- me.workBook
- .getSheet(0)
- .bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
- me.workBook
- .getSheet(0)
- .bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
- me.workBook
- .getSheet(0)
- .bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
- me.workBook
- .getSheet(0)
- .bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
- me.workBook
- .getSheet(0)
- .bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
- me.workBook
- .getSheet(0)
- .bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
- },
- setCombo: function (sheet, combo) {
- let me = rationOprObj;
- sheet.suspendPaint();
- sheet.suspendEvent();
- if (combo) {
- combo = sheetCommonObj.getDynamicCombo();
- combo.items(rationAndGljUnits).itemHeight(10).editable(true);
- }
- sheet.getRange(-1, me.setting.view.comboBox[0].col, -1, 1).cellType(combo);
- sheet.resumePaint();
- sheet.resumeEvent();
- },
- onSelectionChanged: function (sender, info) {
- if (
- (info.oldSelections.length === 0 && info.newSelections.length > 0) ||
- info.oldSelections[0].row !== info.newSelections[0].row
- ) {
- let row = info.newSelections[0].row;
- let me = rationOprObj;
- me.rationSelInit(row);
- }
- },
- //focusOnSection将工作簿焦点移到章节表上
- rationSelInit: function (row, focusOnSection = null) {
- let me = rationOprObj,
- sheetGLJ = rationGLJOprObj.sheet,
- settingGLJ = rationGLJOprObj.setting,
- sheetCoe = rationCoeOprObj.sheet,
- settingCoe = rationCoeOprObj.setting,
- sheetAss = rationAssistOprObj.sheet,
- settingAss = rationAssistOprObj.setting,
- sheetInst = rationInstObj.sheet,
- settingInst = rationInstObj.setting;
- sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
- sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
- sheetCommonObj.cleanData(sheetAss, settingAss, -1);
- sheetCommonObj.cleanData(sheetInst, settingInst, -1);
- let cacheSection = me.getCache();
- RationTemplate.rationInitSel(cacheSection[row]);
- if (cacheSection && row < cacheSection.length) {
- rationGLJOprObj.getGljItems(cacheSection[row], function () {
- if (focusOnSection) {
- sectionTreeObj.workBook.focus(true);
- } else {
- me.workBook.focus(true);
- }
- });
- rationCoeOprObj.getCoeItems(cacheSection[row], function () {
- if (focusOnSection) {
- sectionTreeObj.workBook.focus(true);
- } else {
- me.workBook.focus(true);
- }
- });
- rationAssistOprObj.getAssItems(cacheSection[row]);
- rationInstObj.getInstItems(cacheSection[row], function () {
- if (focusOnSection) {
- sectionTreeObj.workBook.focus(true);
- } else {
- me.workBook.focus(true);
- }
- });
- } else {
- rationGLJOprObj.currentRationItem = null;
- }
- if (!focusOnSection) {
- me.workBook.focus(true);
- }
- },
- isInt: function (num) {
- return !isNaN(num) && num % 1 === 0;
- },
- isDef: function (v) {
- return v !== undefined && v !== null;
- },
- getCache: function () {
- let me = this,
- rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
- if (!rst) {
- me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
- rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
- }
- return rst;
- },
- updateCache: function (addArr, updateArr, removeIds, result) {
- let me = this,
- cacheSection = me.getCache();
- if (addArr.length > 0) {
- me.currentRations["_SEC_ID_" + me.currentSectionId] =
- cacheSection.concat(addArr);
- cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
- }
- for (let i = removeIds.length - 1; i >= 0; i--) {
- for (let j = cacheSection.length - 1; j >= 0; j--) {
- if (cacheSection[j].rationTemplateList) {
- //清除模板关联
- _.remove(cacheSection[j].rationTemplateList, function (data) {
- return removeIds.includes(data.rationID);
- });
- }
- if (cacheSection[j]["ID"] == removeIds[i]) {
- cacheSection.splice(j, 1);
- }
- }
- }
- if (result && result.data.ops && result.data.ops.length > 0) {
- for (let i = 0; i < result.data.ops.length; i++) {
- for (let j = 0; j < cacheSection.length; j++) {
- if (
- cacheSection[j][me.setting.header[0].dataCode] ==
- result.data.ops[i][me.setting.header[0].dataCode]
- ) {
- cacheSection[j]["ID"] = result.data.ops[i]["ID"];
- cacheSection[j]["rationGljList"] =
- result.data.ops[i]["rationGljList"];
- cacheSection[j]["rationCoeList"] =
- result.data.ops[i]["rationCoeList"];
- cacheSection[j]["rationAssList"] =
- result.data.ops[i]["rationAssList"];
- cacheSection[j]["rationInstList"] =
- result.data.ops[i]["rationInstList"];
- }
- }
- }
- }
- for (let i = 0; i < updateArr.length; i++) {
- for (let j = 0; j < cacheSection.length; j++) {
- if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
- if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
- updateArr[i]["rationGljList"] = rationGLJOprObj.cache[
- "_GLJ_" + cacheSection[j]["ID"]
- ]
- ? rationGLJOprObj.cache["_GLJ_" + cacheSection[j]["ID"]]
- : cacheSection[j]["rationGljList"]
- ? cacheSection[j]["rationGljList"]
- : [];
- updateArr[i]["rationCoeList"] = cacheSection[j]["rationCoeList"]
- ? cacheSection[j]["rationCoeList"]
- : [];
- updateArr[i]["rationAssList"] = cacheSection[j]["rationAssList"];
- updateArr[i]["rationInstList"] = cacheSection[j]["rationInstList"];
- updateArr[i]["rationTemplateList"] =
- cacheSection[j]["rationTemplateList"];
- cacheSection[j] = updateArr[i];
- }
- } else {
- if (
- cacheSection[j][me.setting.header[0].dataCode] ==
- updateArr[i][me.setting.header[0].dataCode]
- ) {
- updateArr[i]["rationGljList"] = rationGLJOprObj.cache[
- "_GLJ_" + cacheSection[j]["ID"]
- ]
- ? rationGLJOprObj.cache["_GLJ_" + cacheSection[j]["ID"]]
- : cacheSection[j]["rationGljList"]
- ? cacheSection[j]["rationGljList"]
- : [];
- updateArr[i]["rationCoeList"] = cacheSection[j]["rationCoeList"]
- ? cacheSection[j]["rationCoeList"]
- : [];
- updateArr[i]["rationAssList"] = cacheSection[j]["rationAssList"];
- updateArr[i]["rationInstList"] = cacheSection[j]["rationInstList"];
- updateArr[i]["rationTemplateList"] =
- cacheSection[j]["rationTemplateList"];
- cacheSection[j] = updateArr[i];
- }
- }
- }
- }
- return cacheSection;
- },
- onContextmenuOpr: function () {
- //右键菜单
- let me = this;
- $.contextMenu({
- selector: "#rationItemsSheet",
- build: function ($triggerElement, e) {
- //控制允许右键菜单在哪个位置出现
- let target = SheetDataHelper.safeRightClickSelection(
- $triggerElement,
- e,
- me.workBook
- );
- let sheet = me.workBook.getSheet(0);
- let cacheSection = me.getCache();
- let ration = cacheSection[target.row];
- if (target.hitTestType === 3) {
- //在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
- if (typeof target.row !== "undefined") {
- //控制按钮是否可用
- sheet.setActiveCell(target.row, target.col);
- }
- return {
- callback: function () {},
- items: {
- delete: {
- name: "删除",
- disabled: function () {
- const inValidCell =
- !commonUtil.isDef(target.row) ||
- !commonUtil.isDef(target.col);
- const inValidData =
- !cacheSection || target.row >= cacheSection.length;
- return locked || inValidCell || inValidData;
- },
- icon: "fa-remove",
- callback: function (key, opt) {
- let removeInfo = `确定要删除定额 “${ration.code}” 及其下的所有数据吗?`;
- $("#delRationAlert").find(".modal-body h5").text(removeInfo);
- $("#delRationAlert").modal("show");
- $("#delRationConfirm").bind("click", function () {
- me.rationsCodes.splice(
- me.rationsCodes.indexOf(ration.code.toString()),
- 1
- );
- me.mixDel = 1;
- me.mixUpdateRequest([], [], [ration.ID]);
- $("#delRationConfirm").unbind("click");
- $("#delRationAlert").modal("hide");
- });
- },
- },
- },
- };
- } else {
- return false;
- }
- },
- });
- },
- rationDelOpr: function () {
- if (locked) {
- return;
- }
- let me = rationOprObj;
- me.workBook.commandManager().register("rationDelete", function () {
- let rationSheet = me.workBook.getActiveSheet();
- let sels = rationSheet.getSelections(),
- updateArr = [],
- removeArr = [],
- lockCols = me.setting.view.lockColumns;
- let removeCodes = [];
- let cacheSection = me.getCache();
- if (sels.length > 0) {
- for (let sel = 0; sel < sels.length; sel++) {
- if (sels[sel].colCount === me.setting.header.length) {
- if (cacheSection) {
- for (let i = 0; i < sels[sel].rowCount; i++) {
- if (sels[sel].row + i < cacheSection.length) {
- removeArr.push(cacheSection[sels[sel].row + i].ID);
- removeCodes.push(cacheSection[sels[sel].row + i].code);
- me.rationsCodes.splice(
- me.rationsCodes.indexOf(
- cacheSection[sels[sel].row + i].code.toString()
- ),
- 1
- );
- }
- }
- }
- } else {
- if (sels[sel].col === 0) {
- $("#alertText").text("编号不能为空,修改失败!");
- $("#alertModalBtn").click();
- $("#alertModalCls").click(function () {});
- $("#alertModalCof").click(function () {});
- } else if (
- sels[sel].col !== 0 &&
- !(sels[sel].col === 3 && sels.col + sels[sel].colCount - 1 === 6)
- ) {
- if (cacheSection) {
- for (
- let i = sels[sel].row === -1 ? 1 : 0;
- i < sels[sel].rowCount;
- i++
- ) {
- if (sels[sel].row + i < cacheSection.length) {
- for (
- let col = sels[sel].col;
- col <= sels[sel].col + sels[sel].colCount - 1;
- col++
- ) {
- if (lockCols.indexOf(col) === -1) {
- cacheSection[sels[sel].row + i][
- me.setting.header[col].dataCode
- ] = "";
- }
- }
- }
- if (
- cacheSection[sels[sel].row + i] &&
- typeof cacheSection[sels[sel].row + i] !== "undefined"
- ) {
- updateArr.push(cacheSection[sels[sel].row + i]);
- }
- }
- }
- }
- }
- }
- }
- /* if(updateArr.length > 0 || removeArr.length > 0){
- me.mixUpdate = 1;
- me.mixDel = removeArr.length > 0 ? 1 : 0;
- me.mixUpdateRequest(updateArr, [], removeArr);
- }*/
- if (updateArr.length > 0) {
- me.mixUpdate = 1;
- me.mixUpdateRequest(updateArr, [], []);
- }
- if (removeArr.length > 0) {
- let removeInfo = `确定要删除定额 “${removeCodes.join(
- ","
- )}” 及其下的所有数据吗?`;
- $("#delRationAlert").find(".modal-body h5").text(removeInfo);
- $("#delRationAlert").modal("show");
- $("#delRationConfirm").bind("click", function () {
- me.mixDel = 1;
- me.mixUpdateRequest([], [], removeArr);
- $("#delRationConfirm").unbind("click");
- $("#delRationAlert").modal("hide");
- });
- }
- });
- me.workBook
- .commandManager()
- .setShortcutKey(
- null,
- GC.Spread.Commands.Key.del,
- false,
- false,
- false,
- false
- );
- me.workBook
- .commandManager()
- .setShortcutKey(
- "rationDelete",
- GC.Spread.Commands.Key.del,
- false,
- false,
- false,
- false
- );
- },
- onLeaveCell: function (sender, args) {
- let me = rationOprObj;
- me.lastCol = me.setting.header[args.col];
- },
- onEnterCell: function (sender, args) {
- let me = rationOprObj;
- if (
- me.setting.header[args.col]["dataCode"] === "unit" ||
- me.lastCol.dataCode === "unit"
- ) {
- args.sheet.repaint();
- }
- me.cellRowIdx = args.row;
- let isHasData = false;
- if (me.addRationItem) {
- for (let i = 0; i < me.setting.header.length; i++) {
- if (me.addRationItem[me.setting.header[i].dataCode]) {
- isHasData = true;
- break;
- }
- }
- }
- if (isHasData) {
- if (me.editingRowIdx !== me.cellRowIdx) {
- let focusToCol = !me.addRationItem.code ? 0 : -1;
- if (focusToCol !== -1) {
- $("#rationAlertBtn").click();
- $("#rationAlertCac").click(function () {
- me.addRationItem = null;
- for (let col = 0; col < me.setting.header.length; col++) {
- me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value("");
- }
- });
- $("#rationAlertCls").click(function () {
- me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
- });
- $("#rationAlertCof").click(function () {
- me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
- });
- }
- }
- }
- },
- onCellEditStart: function (sender, args) {
- let me = rationOprObj;
- if (
- !me.canRations ||
- me.setting.view.lockColumns.indexOf(args.col) !== -1
- ) {
- args.cancel = true;
- } else {
- let rObj = sheetsOprObj.combineRationRowData(
- me.workBook.getSheet(0),
- me.setting,
- args.row
- );
- me.currentEditingRation = rObj;
- let cacheSection = me.getCache();
- if (cacheSection) {
- for (let j = 0; j < cacheSection.length; j++) {
- if (
- cacheSection[j][me.setting.header[0].dataCode] ==
- rObj[me.setting.header[0].dataCode]
- ) {
- rObj["ID"] = cacheSection[j]["ID"];
- break;
- }
- }
- }
- }
- },
- onCellEditEnd: function (sender, args) {
- let me = rationOprObj;
- // 输入编号、名称、单位时,如果输入回车符或粘贴回车符,提交时应转换为空格。
- let dataCode = me.setting.header[args.col].dataCode;
- let deESCFields = ["code", "name", "unit"];
- if (deESCFields.includes(dataCode)) {
- args.editingText = me.isDef(args.editingText)
- ? args.editingText.toString().replace(/[\r\n]/g, " ")
- : "";
- args.sheet.setValue(args.row, args.col, args.editingText);
- }
- let rObj = sheetsOprObj.combineRationRowData(
- me.workBook.getSheet(0),
- me.setting,
- args.row
- ),
- updateArr = [],
- addArr = [];
- me.editingRowIdx = args.row;
- if (me.currentEditingRation["ID"]) {
- if (
- (!args.editingText ||
- args.editingText.toString().trim().length === 0) &&
- args.col === 0
- ) {
- args.sheet.setValue(
- args.row,
- args.col,
- me.currentEditingRation[dataCode] + ""
- );
- } else {
- rObj["ID"] = me.currentEditingRation["ID"];
- if (me.currentEditingRation[dataCode] !== rObj[dataCode]) {
- me.addRationItem = rObj;
- if (dataCode === "code") {
- if (me.rationsCodes.indexOf(rObj.code.toString()) === -1) {
- me.rationsCodes.splice(
- me.rationsCodes.indexOf(rObj.code.toString()),
- 1
- );
- me.rationsCodes.push(rObj.code.toString());
- updateArr.push(rObj);
- } else {
- alert("编码已存在!");
- args.sheet.setValue(
- args.row,
- args.col,
- me.currentEditingRation[dataCode]
- );
- }
- } else {
- updateArr.push(rObj);
- }
- }
- }
- } else if (!me.currentEditingRation["ID"]) {
- if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
- //addArr.push(rObj);
- me.addRationItem = rObj;
- if (rObj.code && rObj.code.toString().trim().length > 0) {
- if (me.rationsCodes.indexOf(rObj.code.toString()) === -1) {
- //jobContent
- if (
- jobContentOprObj &&
- jobContentOprObj.currentSituation ===
- jobContentOprObj.situations.ALL
- ) {
- rObj.jobContent = jobContentOprObj.currentJobContent
- ? jobContentOprObj.currentJobContent
- : "";
- }
- if (
- annotationOprObj &&
- annotationOprObj.currentSituation ===
- annotationOprObj.situations.ALL
- ) {
- rObj.annotation = annotationOprObj.currentAnnotation
- ? annotationOprObj.currentAnnotation
- : "";
- }
- me.setInitPrc(rObj);
- addArr.push(rObj);
- me.rationsCodes.push(rObj.code.toString());
- me.addRationItem = null;
- } else {
- alert("编码已存在!");
- me.workBook.getSheet(0).setValue(args.row, args.col, "");
- }
- } else if (rObj.code && rObj.code.toString.trim().length === 0) {
- me.workBook.getSheet(0).setValue(args.row, args.col, "");
- }
- }
- }
- if (updateArr.length > 0 || addArr.length > 0) {
- me.currentEditingRation = null;
- me.mixUpdate = 1;
- me.mixUpdateRequest(updateArr, addArr, []);
- }
- },
- canPasted: function (beginCol, maxCol) {
- let me = rationOprObj;
- // 粘贴的列不可包含不可编辑的“基价”列
- // 粘贴的最大列不可超出表格的最大列
- if (
- me.canRations &&
- (maxCol < 3 || (beginCol > 3 && maxCol <= me.setting.header.length - 1))
- ) {
- return true;
- }
- return false;
- },
- onClipboardPasting: function (sender, args) {
- let me = rationOprObj;
- let maxCol = args.cellRange.col + args.cellRange.colCount - 1;
- if (!me.canPasted(args.cellRange.col, maxCol)) {
- args.cancel = true;
- }
- },
- onClipboardPasted: function (e, info) {
- let me = rationOprObj;
- let cacheSection = me.getCache();
- let updateArr = [],
- addArr = [];
- let items = sheetCommonObj.analyzePasteData(me.setting, info);
- for (let i = 0; i < items.length; i++) {
- let rowIdx = info.cellRange.row + i;
- if (cacheSection) {
- if (!cacheSection[rowIdx] && info.cellRange.col === 0) {
- if (me.rationsCodes.indexOf(items[i].code.toString()) === -1) {
- //jobConten
- if (
- jobContentOprObj &&
- jobContentOprObj.currentSituation ===
- jobContentOprObj.situations.ALL
- ) {
- items[i].jobContent = jobContentOprObj.currentJobContent
- ? jobContentOprObj.currentJobContent
- : "";
- }
- if (
- annotationOprObj &&
- annotationOprObj.currentSituation ===
- annotationOprObj.situations.ALL
- ) {
- items[i].annotation = annotationOprObj.currentAnnotation
- ? annotationOprObj.currentAnnotation
- : "";
- }
- me.setInitPrc(items[i]);
- addArr.push(items[i]);
- me.rationsCodes.push(items[i].code.toString());
- } else {
- me.workBook.getSheet(0).setValue(rowIdx, 0, "");
- }
- } else if (cacheSection[rowIdx]) {
- for (let col = 0; col < me.setting.header.length; col++) {
- if (
- !items[i][me.setting.header[col].dataCode] &&
- typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !==
- "undefined"
- ) {
- items[i][me.setting.header[col].dataCode] =
- cacheSection[rowIdx][me.setting.header[col].dataCode];
- }
- }
- if (info.cellRange.col === 0) {
- if (me.rationsCodes.indexOf(items[i].code.toString()) === -1) {
- items[i].ID = cacheSection[rowIdx].ID;
- updateArr.push(items[i]);
- } else {
- me.workBook
- .getSheet(0)
- .setValue(rowIdx, 0, cacheSection[rowIdx].code);
- }
- } else {
- items[i].ID = cacheSection[rowIdx].ID;
- updateArr.push(items[i]);
- }
- }
- } else {
- //add
- if (info.cellRange.col === 0) {
- //是否含有已存在的编号
- if (me.rationsCodes.indexOf(items[i].code.toString()) === -1) {
- //jobConten
- if (
- jobContentOprObj &&
- jobContentOprObj.currentSituation ===
- jobContentOprObj.situations.ALL
- ) {
- items[i].jobContent = jobContentOprObj.currentJobContent
- ? jobContentOprObj.currentJobContent
- : "";
- }
- if (
- annotationOprObj &&
- annotationOprObj.currentSituation ===
- annotationOprObj.situations.ALL
- ) {
- items[i].annotation = annotationOprObj.currentAnnotation
- ? annotationOprObj.currentAnnotation
- : "";
- }
- me.setInitPrc(items[i]);
- addArr.push(items[i]);
- }
- }
- }
- }
- if (updateArr.length > 0 || addArr.length > 0) {
- me.mixUpdate = 1;
- me.mixUpdateRequest(updateArr, addArr, []);
- } else {
- me.getRationItems(me.currentSectionId);
- }
- },
- setInitPrc: function (obj) {
- obj.labourPrice = 0;
- obj.materialPrice = 0;
- obj.machinePrice = 0;
- obj.basePrice = 0;
- },
- mixUpdateRequest: function (updateArr, addArr, removeIds, callback) {
- let me = rationOprObj;
- me.saveInString(updateArr);
- $.ajax({
- type: "POST",
- url: "api/mixUpdateRationItems",
- data: {
- rationLibId: getQueryString("repository"),
- lastOpr: userAccount,
- sectionID: me.currentSectionId,
- updateItems: JSON.stringify(updateArr),
- addItems: JSON.stringify(addArr),
- removeIds: JSON.stringify(removeIds),
- },
- dataType: "json",
- cache: false,
- timeout: 20000,
- success: function (result) {
- if (result.error) {
- alert("error");
- me.getRationItems(me.currentSectionId);
- } else {
- let cacheSection = me.updateCache(
- addArr,
- updateArr,
- removeIds,
- result
- );
- me.sortByCode(cacheSection);
- let curRow = me.workBook.getActiveSheet().getActiveRowIndex();
- me.rationSelInit(curRow);
- //jobContent
- if (jobContentOprObj) {
- jobContentOprObj.currentRationItems = cacheSection;
- jobContentOprObj.setRadiosDisabled(
- cacheSection.length > 0 ? false : true,
- jobContentOprObj.radios
- );
- if (cacheSection.length === 0) {
- jobContentOprObj.updateSituation(
- pageOprObj.rationLibId,
- me.currentSectionId,
- "NONE"
- );
- }
- jobContentOprObj.setRadiosChecked(
- jobContentOprObj.currentSituation,
- jobContentOprObj.radios
- );
- if (
- jobContentOprObj.currentSituation ===
- jobContentOprObj.situations.PARTIAL
- ) {
- jobContentOprObj.buildTablePartial(
- jobContentOprObj.tablePartial,
- jobContentOprObj.getGroup(cacheSection)
- );
- }
- }
- if (annotationOprObj) {
- annotationOprObj.setRadiosDisabled(
- cacheSection.length > 0 ? false : true,
- annotationOprObj.radios
- );
- if (cacheSection.length === 0) {
- annotationOprObj.updateAnnoSituation(
- pageOprObj.rationLibId,
- me.currentSectionId,
- "NONE"
- );
- }
- annotationOprObj.setRadiosChecked(
- annotationOprObj.currentSituation,
- annotationOprObj.radios
- );
- if (
- annotationOprObj.currentSituation ===
- annotationOprObj.situations.PARTIAL
- ) {
- annotationOprObj.buildTablePartial(
- annotationOprObj.fzTablePartial,
- annotationOprObj.getGroup(cacheSection)
- );
- }
- }
- me.showRationItems(me.currentSectionId);
- me.mixUpdate = 0;
- me.mixDel = 0;
- }
- me.workBook.focus(true);
- if (callback) callback();
- },
- error: function () {},
- });
- },
- doAfterGetRation: null,
- getRationItems: function (sectionID, callback = null) {
- if (sectionID != -1) {
- let me = rationOprObj;
- me.mixUpdate = 0;
- me.currentSectionId = sectionID;
- $.ajax({
- type: "POST",
- url: "api/getRationItems",
- data: { rationRepId: pageOprObj.rationLibId, sectionID: sectionID },
- dataType: "json",
- cache: false,
- timeout: 10000,
- success: function (result) {
- if (result) {
- me.currentRations["_SEC_ID_" + sectionID] = result.data;
- me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
- //job--
- jobContentOprObj.currentRationItems =
- me.currentRations["_SEC_ID_" + sectionID];
- jobContentOprObj.rationJobContentOpr(
- me.currentRations["_SEC_ID_" + sectionID]
- );
- //annotation
- annotationOprObj.rationAnnotationOpr(
- me.currentRations["_SEC_ID_" + sectionID]
- );
- me.showRationItems(sectionID);
- }
- if (!locked) {
- sectionTreeObj.removeBtn.removeClass("disabled");
- }
- if (callback) {
- callback(result.data);
- }
- },
- error: function (err) {
- sectionTreeObj.removeBtn.removeClass("disabled");
- alert(err);
- },
- });
- }
- },
- showRationItems: function (sectionID) {
- let me = rationOprObj,
- sheetGLJ = rationGLJOprObj.sheet,
- settingGLJ = rationGLJOprObj.setting,
- sheetCoe = rationCoeOprObj.sheet,
- settingCoe = rationCoeOprObj.setting,
- sheetAss = rationAssistOprObj.sheet,
- settingAss = rationAssistOprObj.setting,
- sheetInst = rationInstObj.sheet,
- settingInst = rationInstObj.setting;
- if (me.workBook) {
- sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
- if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID]) {
- let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
- sheetsOprObj.showData(
- me.workBook.getSheet(0),
- me.setting,
- cacheSection
- );
- if (me.mixDel === 1) {
- let row = me.workBook.getSheet(0).getSelections()[0].row;
- if (cacheSection && row < cacheSection.length) {
- sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
- sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
- sheetCommonObj.cleanData(sheetAss, settingAss, -1);
- sheetCommonObj.cleanData(sheetInst, settingInst, -1);
- rationGLJOprObj.getGljItems(cacheSection[row]);
- rationCoeOprObj.getCoeItems(cacheSection[row]);
- rationAssistOprObj.getAssItems(cacheSection[row]);
- rationInstObj.getInstItems(cacheSection[row]);
- } else {
- rationGLJOprObj.currentRationItem = null;
- sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
- sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
- sheetCommonObj.cleanData(sheetAss, settingAss, -1);
- sheetCommonObj.cleanData(sheetInst, settingInst, -1);
- sheetCommonObj.setDynamicCombo(
- sheetAss,
- 0,
- 5,
- sheetAss.getRowCount(),
- rationAssistOprObj.setting.comboItems,
- false,
- false
- );
- }
- }
- } else {
- sheetCommonObj.setDynamicCombo(
- sheetAss,
- 0,
- 5,
- sheetAss.getRowCount(),
- rationAssistOprObj.setting.comboItems,
- false,
- false
- );
- //清除ration数据及工料机数据
- rationGLJOprObj.currentRationItem = null;
- //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
- sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
- sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
- sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
- sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
- }
- }
- sectionTreeObj.workBook.focus(true);
- },
- sortByCode: function (arr) {
- function recurCompare(a, b, index) {
- if (a[index] && !b[index]) {
- return 1;
- } else if (!a[index] && b[index]) {
- return -1;
- } else if (a[index] && b[index]) {
- let aV = a[index],
- bV = b[index];
- if (!isNaN(aV) && !isNaN(bV)) {
- aV = parseFloat(a[index]);
- bV = parseFloat(b[index]);
- }
- if (aV > bV) {
- return 1;
- } else if (aV < bV) {
- return -1;
- } else {
- return recurCompare(a, b, index + 1);
- }
- }
- return 0;
- }
- arr.sort(function (a, b) {
- if (!commonUtil.isDef(a.code) || !commonUtil.isDef(b.code)) {
- return 0;
- }
- let aArr = a.code.split("-"),
- bArr = b.code.split("-");
- return recurCompare(aArr, bArr, 0);
- });
- },
- saveInString(datas) {
- for (let i = 0, len = datas.length; i < len; i++) {
- let data = datas[i];
- if (data.labourPrice !== undefined && data.labourPrice) {
- data.labourPrice = data.labourPrice.toString();
- }
- if (data.materialPrice !== undefined && data.materialPrice) {
- data.materialPrice = data.materialPrice.toString();
- }
- if (data.machinePrice !== undefined && data.machinePrice) {
- data.machinePrice = data.machinePrice.toString();
- }
- if (data.basePrice !== undefined && data.basePrice) {
- data.basePrice = data.basePrice.toString();
- }
- if (data.oilStoneRatio !== undefined && data.oilStoneRatio) {
- data.oilStoneRatio = scMathUtil.roundForObj(data.oilStoneRatio, 2);
- }
- if (
- data.rationGljList !== undefined &&
- data.rationGljList &&
- data.rationGljList.length > 0
- ) {
- for (let j = 0, jLen = data.rationGljList.length; j < jLen; j++) {
- let raGljObj = data.rationGljList[j];
- if (raGljObj.consumeAmt !== undefined && raGljObj.consumeAmt) {
- raGljObj.consumeAmt = raGljObj.consumeAmt.toString();
- }
- }
- }
- }
- },
- };
|