123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299 |
- /**
- * Created by Zhong on 2017/8/14.
- */
- $(document).ready(function () {
- let moduleName = 'compleGLj';
- function refreshALlWorkBook() {
- if (gljClassTreeObj.workBook) {
- gljClassTreeObj.workBook.refresh();
- }
- if (repositoryGljObj.workBook) {
- repositoryGljObj.workBook.refresh();
- }
- if (gljComponentOprObj.workBook) {
- gljComponentOprObj.workBook.refresh();
- }
- }
- SlideResize.loadHorizonWidth(moduleName, [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
- refreshALlWorkBook();
- });
- //章节树与人材机表
- let leftElesObj = {};
- leftElesObj.resize = $('#leftResize');
- leftElesObj.parent = $('#dataRow');
- leftElesObj.left = $('#leftContent');
- leftElesObj.right = $('#midContent');
- SlideResize.horizontalSlide(moduleName, leftElesObj, {min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200`}, function () {
- refreshALlWorkBook();
- });
- //人材机表与人材机组成物表
- let rightElesObj = {};
- rightElesObj.resize = $('#rightResize');
- rightElesObj.parent = $('#dataRow');
- rightElesObj.left = $('#midContent');
- rightElesObj.right = $('#rightContent');
- SlideResize.horizontalSlide(moduleName, rightElesObj, {min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200`}, function () {
- refreshALlWorkBook();
- });
- });
- let pageOprObj = {
- gljLibName : null,
- stdGljLibId: null,
- userId: null,
- compilationId: null,
- initPage : function(container, containerComponent, containerC) {
- let me = pageOprObj;
- me.stdGljLibId = stdGljLibId;
- me.userId = userId;
- me.compilationId = compilationId;
- repositoryGljObj.buildSheet(container);
- gljComponentOprObj.buildSheet(containerComponent);
- componentOprObj.buildSheet(containerC);
- //获得定额库中引用此工料机库中的,所有被定额所套的工料机的ID
- //repositoryGljObj.getRationGljIds(gljLibId);
- repositoryGljObj.getGljDistType(function () {
- repositoryGljObj.currentRepositoryId = me.stdGljLibId;
- repositoryGljObj.getGljItems(me.stdGljLibId, function () {
- gljClassTreeObj.getGljClassTree(stdGljLibId);
- });
- });
- }
- };
- let repositoryGljObj = {
- treeObj : null,
- workBook: null,
- gljCurTypeId: -1,
- currentRepositoryId: -1,
- currentCache: null,
- parentNodeIds: {},
- gljList: [],
- stdGljList:[],
- complementaryGljList: [],
- machineModel: {textArr: ['特', '大', '中', '小'], comboItems: [{text: '特', value: 1}, {text: '大', value: 2},{text: '中', value: 3}, {text: '小', value: 4}]},
- machineModelIdx: {'1': '特', '2': '大', '3': '中', '4': '小'},
- distTypeTree: null,//add
- setting: {
- header:[
- {headerName:"编码",headerWidth:80,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
- {headerName:"名称",headerWidth:160,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
- {headerName:"规格型号",headerWidth:120,dataCode:"specs", dataType: "String", hAlign: "left", vAlign: "center"},
- {headerName:"单位",headerWidth:45,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
- {headerName:"定额价",headerWidth:80,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
- {headerName:"类型",headerWidth:90,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"},
- {headerName:"机型",headerWidth:60,dataCode:"model", dataType: "Number", hAlign: "center", vAlign: "center"},
- {headerName:"是否新增",headerWidth:60,dataCode:"isComplementary", hAlign: "center", vAlign: "center"}
- ],
- view:{
- comboBox:[
- {row:-1,col:3,rowCount:-1,colCount:1}
- ],
- lockedCells:[
- ]
- }
- },
- setUnitCombo: function (sheet, headers) {
- let me = this;
- sheet.suspendPaint();
- sheet.suspendEvent();
- let combo = sheetCommonObj.getDynamicCombo();
- combo.items(rationAndGljUnits).itemHeight(10).editable(true);
- for(let i = 0; i < headers.length; i++){
- if(headers[i].dataCode === 'unit'){
- sheet.getRange(-1, i, -1, 1).cellType(combo);
- break;
- }
- }
- sheet.resumePaint();
- sheet.resumeEvent();
- },
- getComboData: function (gljDistType) {
- let me = this;
- let distType;
- let distTypeTree = {
- prefix : 'gljType',
- distTypes: {},
- comboDatas: [],
- distTypesArr: []
- };
- gljDistType.forEach(function (typeData) {
- let typeObj = {
- data: typeData,
- children: [],
- parent: null
- };
- if(allowGljType.includes(typeData.ID)){
- distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
- distTypeTree.distTypesArr.push(typeObj);
- }
- });
- gljDistType.forEach(function (typeData) {
- if(allowGljType.includes(typeData.ID)){
- distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
- let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
- if(parent){
- distType.parent = parent;
- parent.children.push(distType);
- }
- }
- });
- distTypeTree.distTypesArr.forEach(function (distTypeObj) {
- if(distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械'){
- distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
- }
- });
- return distTypeTree;
- },
- getGljDistType: function (callback) {
- let me = this;
- CommonAjax.post('complementartGlj/api/getGljDistType', {}, function (rstData) {
- if(callback){
- me.distTypeTree = me.getComboData(rstData);
- console.log(me.distTypeTree);
- callback();
- }
- });
- },
- getGljTree: function(gljLibId, callback) {
- let me = this;
- CommonAjax.post('complementartGlj/api/getGljTree', {gljLibId: gljLibId}, function (rstData) {
- zTreeHelper.createTree(rstData, gljSetting, "repositoryTree", me);
- zTreeHelper.createTree(rstData, componentSetting, "componentTree", componentOprObj);
- if (rstData && rstData.length > 0) {
- me.gljCurTypeId = rstData[0].ID;
- } else {
- //重新创建库?
- // gljTypeTreeOprObj.addRootNode();
- }
- if(callback){
- callback();
- }
- });
- },
- getGljItems: function(stdGljLibId, callback) {
- let me = this;
- CommonAjax.post('complementartGlj/api/getGljItems', {stdGljLibId: stdGljLibId}, function (rstData) {
- me.stdGljList = rstData.stdGljs;
- //兼容多单价情况
- for(let sGlj of me.stdGljList){
- if(sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined') {
- sGlj.basePrice = sGlj.priceProperty.price1;
- }
- }
- me.complementaryGljList = rstData.complementaryGljs;
- me.workBook.getSheet(0).setRowCount(me.stdGljList.length);
- me.sortGlj(me.stdGljList);
- me.setProp('isStd', true, me.stdGljList);
- me.sortGlj(me.complementaryGljList);
- if(callback){
- callback();
- }
- /* let rootNode = me.treeObj.getNodes()[0];
- if(rootNode && rootNode.isParent && rootNode.isFirstNode){
- componentOprObj.rootNode = rootNode;
- me.treeObj.selectNode(rootNode);
- gljTypeTreeOprObj.onClick(null, 'repositoryTree', rootNode);
- }*/
- });
- },
- showGljItems: function(data, type) {
- let me = repositoryGljObj;
- let sheet = me.workBook.getActiveSheet();
- if (me.workBook) {
- let cacheSection = [];
- let pArr = me.parentNodeIds["_pNodeId_" + type];
- for (let i = 0; i < data.length; i++) {
- if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
- cacheSection.push(data[i]);
- } else if (type == data[i].gljClass) {
- cacheSection.push(data[i]);
- }
- }
- sheetOpr.cleanData(sheet, me.setting, -1);
- //清除是否新增复选框
- gljClassTreeObj.renderFunc(sheet, function () {
- let isComplementaryCol = 0;
- for(let colData of me.setting.header){
- if(colData.dataCode === 'isComplementary'){
- isComplementaryCol = me.setting.header.indexOf(colData);
- }
- }
- let baseCell = new GC.Spread.Sheets.CellTypes.Base();
- for(let row = 0; row < sheet.getRowCount(); row++){
- sheet.setCellType(row, isComplementaryCol, baseCell);
- }
- });
- sheetOpr.showData(sheet, me.setting, cacheSection, me.distTypeTree, me.machineModelIdx);
- sheetCommonObj.setDynamicCombo(sheet, 0, 5, sheet.getRowCount(), me.distTypeTree.comboDatas, false, 'text');
- sheetCommonObj.setDynamicCombo(sheet, 0, 6, sheet.getRowCount(), me.machineModel.comboItems, false, 'text');
- cacheSection = null;
- }
- },
- bindEnterKey: function () {
- let me = this;
- let sheet = me.workBook.getActiveSheet();
- me.workBook.commandManager().register("myEnter", function(){
- let orgRow = sheet.getActiveRowIndex();
- let orgCol = sheet.getActiveColumnIndex();
- if(sheet.isEditing()){
- sheet.endEdit();
- }
- let code = sheet.getValue(orgRow, 0);
- let newRow, newCol;
- if(!me.currentCache[orgRow] && code !== undefined && code !== null && orgCol !== me.setting.header.length - 1){
- newRow = orgRow;
- newCol = orgCol + 1;
- sheet.setActiveCell(newRow, newCol);
- }
- else{
- newRow = orgRow + 1;
- newCol = me.currentCache[orgRow + 1] ? orgCol : 0;
- sheet.setActiveCell(newRow, newCol);
- }
- //触发事件
- //me.onLeaveCell({type: 'LeaveCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: orgRow, col: orgCol});
- me.onEnterCell({type: 'EnterCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: newRow, col: newCol});
- let newSels = [{row: newRow, rowCount: 1, col: newCol, colCount: 1}];
- let oldSels = [{row: orgRow, rowCount: 1, col: orgRow, colCount: 1}];
- me.onSelectionChanged({type: 'SelectionChanged'}, {sheet: sheet, sheetName: sheet.name(), newSelections: newSels, oldSelections: oldSels});
- });
- me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.enter, false, false, false, false);
- me.workBook.commandManager().setShortcutKey("myEnter", GC.Spread.Commands.Key.enter, false, false, false, false);
- },
- buildSheet: function(container) {
- let me = repositoryGljObj;
- me.workBook = sheetOpr.buildSheet(container, me.setting, 30);
- sheetCommonObj.spreadDefaultStyle(me.workBook);
- me.repositoryGljDelOpr();
- me.onContextmenuOpr();
- me.bindEnterKey();
- me.setUnitCombo(me.workBook.getActiveSheet(), me.setting.header);
- me.workBook.getActiveSheet().bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
- me.workBook.getActiveSheet().bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
- 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.EnterCell, me.onEnterCell);
- me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
- me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
- },
- isDef: function (v) {
- return v !== undefined && v !== null;
- },
- //成为了组成物,暂时只需要判断主材的
- isComponent: function (gljId, gljList) {
- for(let i = 0, len = gljList.length; i < len; i++){
- let gljComponent = gljList[i].component;
- if(gljList[i].gljType === 4 && this.isDef(gljComponent) && gljComponent.length > 0){
- for(let j = 0, jLen = gljComponent.length; j < jLen; j++){
- if(gljComponent[j].ID === gljId){
- return true;
- }
- }
- }
- }
- return false;
- },
- getCurrentComponent: function (gljComponent) {
- let me = repositoryGljObj, rst = [];
- for(let i = 0; i < gljComponent.length; i++){
- let obj = {};
- for(let j = 0; j < me.complementaryGljList.length; j++){
- if(gljComponent[i].ID == me.complementaryGljList[j].ID){
- obj.isStd = false;
- obj.ID = me.complementaryGljList[j].ID;
- obj.code = me.complementaryGljList[j].code;
- obj.name = me.complementaryGljList[j].name;
- obj.unit = me.complementaryGljList[j].unit;
- obj.basePrice = me.complementaryGljList[j].basePrice;
- obj.consumeAmt = gljComponent[i].consumeAmt;
- rst.push(obj);
- }
- }
- for(let j = 0; j < me.stdGljList.length; j++){
- if(gljComponent[i].ID == me.stdGljList[j].ID){
- obj.isStd = true;
- obj.ID = me.stdGljList[j].ID;
- obj.code = me.stdGljList[j].code;
- obj.name = me.stdGljList[j].name;
- obj.unit = me.stdGljList[j].unit;
- obj.basePrice = me.stdGljList[j].basePrice;
- obj.consumeAmt = gljComponent[i].consumeAmt;
- rst.push(obj);
- }
- }
- }
- rst.sort(function (a, b) {
- let r = 0;
- if(a.code > b.code) r = 1;
- else if(a.code < b.code) r = -1;
- return r;
- });
- return rst;
- },
- //获得引用了组成物id为componentId的工料机,和重新变化组成物数组、重新计算单价
- getUpdateGljs: function (rObj, isDelete) {
- let me = repositoryGljObj, that = gljComponentOprObj,
- rst = {updateArr: [], updateBasePrcArr: []};
- //改变单价,以便reCalGljBasePrc方法可行
- if(!isDelete){
- for(let i = 0; i < me.complementaryGljList.length; i++){
- if(me.complementaryGljList[i].ID === rObj.ID){
- me.complementaryGljList[i].basePrice = rObj.basePrice;
- break;
- }
- }
- }
- for(let i = 0; i < me.complementaryGljList.length; i++){
- let thisComponent = me.complementaryGljList[i].component, isChange = false;
- for(let j = 0; j < thisComponent.length; j++){
- if(thisComponent[j].ID === rObj.ID){
- //删除
- isChange = true;
- if(isDelete){
- thisComponent.splice(j--, 1);
- }
- else {
- break;
- }
- }
- }
- if(isChange){//引用了此组成物
- let gljBasePrc = that.reCalGljBasePrc(me.getCurrentComponent(thisComponent));
- if(me.complementaryGljList[i].basePrice !== gljBasePrc){
- me.complementaryGljList[i].basePrice = gljBasePrc;
- rst.updateBasePrcArr.push({gljId: me.complementaryGljList[i].ID, gljType: me.complementaryGljList[i].gljType, basePrice: me.complementaryGljList[i].basePrice});
- }
- rst.updateArr.push(me.complementaryGljList[i]);
- }
- }
- return rst;
- },
- reshowGljBasePrc: function (glj) {
- let me = repositoryGljObj;
- let cacheSection = me.currentCache;
- for(let i = 0; i < cacheSection.length; i++){
- if(glj.ID === cacheSection[i].ID){
- cacheSection[i].basePrice = glj.basePrice;
- me.workBook.getSheet(0).setValue(i, 4, glj.basePrice);
- break;
- }
- }
- },
- onSelectionChanged: function (sender, info) {
- let me = repositoryGljObj, that = gljComponentOprObj;
- //混凝土202、砂浆203、配合比204、机械3
- if(typeof info.oldSelections || info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
- let row = info.newSelections[0].row;
- me.initSel(row);
- }
- },
- initSel: function (row) {
- let me = repositoryGljObj, that = gljComponentOprObj;
- sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, -1);
- me.workBook.focus(true);
- me.currentComponent = [];
- that.workBook.getSheet(0).setRowCount(5);
- if(row < me.currentCache.length){
- //标记当前工料机
- me.currentGlj = me.currentCache[row];
- if(allowComponent.includes(me.currentCache[row].gljType)){
- //展示数据
- if(me.currentGlj.component.length > 0){
- me.currentComponent = me.getCurrentComponent(me.currentGlj.component);
- if(me.currentComponent.length > 0){
- sheetOpr.showData(that.workBook.getSheet(0), that.setting, me.currentComponent);
- }
- }
- }
- }
- else{
- me.currentGlj = null;
- }
- },
- onEnterCell: function (sender, args) {
- let me = repositoryGljObj;
- args.sheet.repaint();
- me.cellRowIdx = args.row;
- let isHasData = false;
- if(me.addGljObj){
- for(let i=0; i<me.setting.header.length; i++){
- if(me.addGljObj[me.setting.header[i].dataCode]){
- isHasData = true;
- break;
- }
- }
- }
- if(isHasData){
- if(me.editingRowIdx !== me.cellRowIdx) {
- let isComple = true;
- let focusToCol;
- function getFocusToCol (me){
- if(!me.addGljObj[me.setting.header[0].dataCode]){
- $('#alertGljTxt').text('编号不能为空,继续增加人材机?');
- return 0;
- }
- else if(!me.addGljObj[me.setting.header[1].dataCode]){
- $('#alertGljTxt').text('名称不能为空,继续增加人材机?');
- return 1;
- }
- else if(!me.addGljObj[me.setting.header[3].dataCode]){
- $('#alertGljTxt').text('计量单位不能为空,继续增加人材机?');
- return 3;
- }
- else if(!me.addGljObj[me.setting.header[5].dataCode]){
- $('#alertGljTxt').text('类型不能为空,继续增加人材机?');
- return 5;
- }
- else {
- return -1;
- }
- }
- focusToCol = getFocusToCol(me);
- if(focusToCol === -1){
- }
- else {
- $('#gljAlertBtn').click();
- $('#aleConfBtn').unbind('click');
- $('#aleConfBtn').bind('click', function () {
- me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
- });
- $('#gljAleClose').unbind('click');
- $('#gljAleClose').bind('click', function () {
- me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
- });
- $('#aleCanceBtn').unbind('click');
- $('#aleCanceBtn').bind('click', function () {
- me.addGljObj = null;
- me.workBook.getSheet(0).suspendPaint();
- me.workBook.getSheet(0).suspendEvent();
- for(let col=0; col<me.setting.header.length; col++){
- if(col === 0){
- me.workBook.getSheet(0).getCell(me.editingRowIdx, 0).formatter("@");
- }
- me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
- }
- me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
- me.workBook.getSheet(0).resumePaint();
- me.workBook.getSheet(0).resumeEvent();
- });
- }
- }
- }
- },
- onButtonClicked: function (sender, args) {
- let me = repositoryGljObj;
- if(args.col === 6 && args.row < me.currentCache.length){
- args.sheet.setValue(args.row, args.col, true);
- }
- },
- onCellEditStart: function(sender, args) {
- let me = repositoryGljObj;
- let rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
- me.currentEditingGlj = rObj;
- me.orgCode = me.workBook.getSheet(0).getValue(args.row, 0);
- if(args.row < me.currentCache.length){
- me.currentGlj = me.currentCache[args.row];
- if(args.col === 0 || (args.col === 4 && allowComponent.includes(me.currentGlj.gljType) && me.currentGlj.component.length > 0)
- || (args.col === 6 && me.currentGlj.gljType !== 301) || args.col === 7){
- args.cancel = true;
- }
- else {
- rObj.ID = me.currentGlj.ID;
- rObj.gljClass = me.currentGlj.gljClass;
- }
- }
- else {
- me.currentGlj = null;
- }
- },
- onCellEditEnd: function(sender, args) {
- let me = repositoryGljObj, that = gljComponentOprObj,
- rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me),
- updateArr = [], addArr = [], updateBasePrcArr = [];
- me.editingRowIdx = args.row;
- rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
- //更新
- if (me.currentEditingGlj["ID"]) {
- rObj["ID"] = me.currentEditingGlj["ID"];
- rObj.gljClass = me.currentEditingGlj.gljClass;
- //for(let col =0; col< me.setting.header.length; col++){
- if(me.currentEditingGlj[me.setting.header[args.col].dataCode] !== rObj[me.setting.header[args.col].dataCode]){
- //me.addGljObj = rObj;
- //编码、名称、单位、类型不可为空
- if(rObj[me.setting.header[0].dataCode] && rObj[me.setting.header[1].dataCode] && rObj[me.setting.header[3].dataCode] && rObj[me.setting.header[5].dataCode]
- &&rObj[me.setting.header[0].dataCode].toString().trim().length !== 0 && rObj[me.setting.header[1].dataCode].toString().trim().length !== 0 && rObj[me.setting.header[3].dataCode].toString().trim().length !== 0&&
- rObj[me.setting.header[5].dataCode].toString().trim().length !== 0){
- if(rObj.gljType !== me.currentEditingGlj.gljType){//修改了工料机类型
- if(me.currentGlj){
- me.currentGlj.component = [];
- }
- /* if(me.allowComponent.indexOf(rObj.gljType) !== -1){
- rObj.basePrice = 0;
- }*/
- //工料机类型不为机械台班时,清空机型
- if(me.currentEditingGlj.gljType === 301 && rObj.gljType !== 301 && me.currentEditingGlj.model){
- rObj.model = null;
- }
- if(componentType.includes(me.currentEditingGlj.gljType) &&
- !(machineComponent.includes(me.currentEditingGlj.gljType) && machineComponent.includes(rObj.gljType))
- && !(materialComponent.includes(me.currentEditingGlj.gljType) && materialComponent.includes(rObj.gljType))){//修改了原本是组成物的工料机
- //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
- let updateGljs = me.getUpdateGljs(rObj, true);
- if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
- for(let i = 0; i < updateGljs.updateArr.length; i++){
- updateArr.push(updateGljs.updateArr[i]);
- }
- for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
- updateArr.push(updateGljs.updateBasePrcArr[i]);
- }
- }
- }
- sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, 5);
- }
- else if(rObj.basePrice !== me.currentEditingGlj.basePrice){//修改了单价,可修改单价的必为可成为组成物的
- //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
- if(isNaN(parseFloat(rObj.basePrice))){
- alert('单价只能为数值!');
- args.sheet.setValue(args.row, args.col, me.currentEditingGlj.basePrice ? me.currentEditingGlj.basePrice : 0);
- return;
- }
- rObj.basePrice = !isNaN(parseFloat(rObj.basePrice))? scMathUtil.roundTo(parseFloat(rObj.basePrice), -2) : me.currentEditingGlj.basePrice;
- let updateGljs = me.getUpdateGljs(rObj);
- if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
- for(let i = 0; i < updateGljs.updateArr.length; i++){
- updateArr.push(updateGljs.updateArr[i]);
- }
- for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
- updateArr.push(updateGljs.updateBasePrcArr[i]);
- }
- }
- //rObj.basePrice = !isNaN(parseFloat(rObj.basePrice)) && (rObj.basePrice && typeof rObj.basePrice !== 'undefined') ? that.round(parseFloat(rObj.basePrice), 2) : 0;
- }
- rObj.component = me.currentGlj.component;
- updateArr.push(rObj);
- }
- else{
- if(me.setting.header[args.col].dataCode === 'gljType'){
- let distTypeVal = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj[me.setting.header[args.col].dataCode]].data.fullName;
- args.sheet.setValue(args.row, args.col, distTypeVal);
- }
- else{
- args.sheet.setValue(args.row, args.col, me.currentEditingGlj[me.setting.header[args.col].dataCode]);
- }
- }
- }
- // }
- //--------------------------------------
- if(me.currentEditingGlj.basePrice !== rObj.basePrice){
- //update basePrice of ration when editting basePrice of glj
- let gljType = -1;
- let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
- if(gljTypeParent && gljTypeParent.data.ID <=3){
- gljType = gljTypeParent.data.ID;
- }
- if(!gljTypeParent && me.currentEditingGlj.gljType <= 3){
- gljType = me.currentEditingGlj.gljType;
- }
- let gljBasePrcObj = {gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: rObj.basePrice};
- if(gljBasePrcObj.gljType !== -1){
- updateBasePrcArr.push(gljBasePrcObj);
- me.updateRationBasePrcRq(updateBasePrcArr);
- }
- }
- //update basePrice of ration when editting gljType of glj
- if(me.currentEditingGlj.gljType !== rObj.gljType){
- let gljTypeObj = {gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: rObj.basePrice};
- updateBasePrcArr.push(gljTypeObj);
- me.updateRationBasePrcRq(updateBasePrcArr);
- }
- //-----------------------------------------------------------
- }
- //新增
- else {
- if(typeof rObj.code !== 'undefined'){
- me.addGljObj = rObj;
- let isCanSav = true;
- if(!rObj[me.setting.header[0].dataCode] || !rObj[me.setting.header[1].dataCode] || !rObj[me.setting.header[3].dataCode] || !rObj[me.setting.header[5].dataCode]){
- isCanSav = false;
- }
- if(isCanSav){
- me.addGljObj = null;
- rObj.component = [];
- //如果类型为混凝土、砂浆、配合比、机械台班时,添加时填写的单价清空
- /* if(me.allowComponent.indexOf(rObj.gljType) !== -1){
- rObj.basePrice = 0;
- }*/
- rObj.basePrice = !isNaN(parseFloat(rObj.basePrice)) && (rObj.basePrice && typeof rObj.basePrice !== 'undefined') ? parseFloat(rObj.basePrice) : 0;
- addArr.push(rObj);
- }
- }
- }
- if(!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
- rObj.gljClass = me.gljCurTypeId;
- }
- if(updateArr.length >0 || addArr.length >0){
- me.currentEditingGlj = null;
- me.mixUpdateRequest(updateArr, addArr, []);
- }
- },
- delGljs: function (sels) {
- let me = repositoryGljObj;
- let sheet = me.workBook.getSheet(0),
- updateArr = [], removeArr = [],
- tempRemoveArr= [],
- refGljCodes = [], //已被引用的工料机
- updateBasePrcArr = [],//删除基价单位后重新计算
- canUpdate = false,
- cacheSection = me.currentCache;
- if(sels.length > 0 && cacheSection.length > 0){
- for(let i = 0; i < sels.length; i++){
- if(sels[i].colCount === me.setting.header.length){
- for(let j = 0; j < sels[i].rowCount; j++){
- if(sels[i].row + j < cacheSection.length){
- //删除了已被引用成组成物的工料机,重新计算所有引用此组成物的工料机的单价、组成物数组
- let updateGljs = me.getUpdateGljs(cacheSection[sels[i].row + j], true);
- if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
- for(let i = 0; i < updateGljs.updateArr.length; i++){
- updateArr.push(updateGljs.updateArr[i]);
- }
- for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
- updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
- }
- }
- removeArr.push(cacheSection[sels[i].row + j].ID);
- //tempRemoveArr.push({ID: cacheSection[sels[i].row + j].ID, code: cacheSection[sels[i].row + j].code});
- //删除后重新计算引用了此工料机的定额单价
- updateBasePrcArr.push({gljId: cacheSection[sels[i].row + j].ID, gljType: cacheSection[sels[i].row + j].gljType, basePrice: 0, delete: 1});
- }
- }
- }
- else{
- let maxCol = sels[i].col + sels[i].colCount - 1;
- if(sels[i].col >= 2 && maxCol <= 4){
- for(let j = 0; j < sels[i].rowCount; j++){
- if(sels[i].row + j < cacheSection.length){
- let updateObj = cacheSection[sels[i].row + j];
- for(let col = sels[i].col; col <= maxCol; col++){
- if(me.setting.header[col].dataCode === 'basePrice'){
- //如果类型不为混凝土、砂浆、配合比、机械,才可删除单价 basePrice = 0
- if(!allowComponent.includes(updateObj.gljType)){
- canUpdate = true;
- updateObj[me.setting.header[col].dataCode] = 0;
- updateBasePrcArr.push({gljId: updateObj.ID, gljType: updateObj.gljType, basePrice: 0});
- }
- }
- else{
- canUpdate = true;
- updateObj[me.setting.header[col].dataCode] = '';
- }
- }
- if(canUpdate){
- updateArr.push(updateObj);
- }
- }
- }
- }
- //编号、名称、类型不可为空
- else{
- if(sels[i].row < cacheSection.length){
- let text = '', cantNullStr =['编码', '名称', '类型'];
- for(let col = sels[i].col; col <= sels[i].col + sels[i].colCount -1; col++){
- if(cantNullStr.indexOf(me.setting.header[col].headerName) !== -1){
- text += me.setting.header[col].headerName + " ";
- }
- }
- $('#alertText').text(text + "不可为空!");
- $('#codeAlertBtn').click();
- $('#codAleConfBtn').click(function () {
- });
- $('#codAleClose').click(function () {
- });
- }
- }
- }
- }
- if(removeArr.length > 0 || updateArr.length > 0){
- //删除警告
- $('#alertGljTxt').text('可能已有定额引用了当前工料机,导致定额查找不到此工料机。确定要删除吗?');
- $('#gljAlertBtn').click();
- //确认
- $('#aleConfBtn').unbind('click');
- $('#aleConfBtn').bind('click', function () {
- me.mixUpdateRequest(updateArr, [], removeArr);
- /*if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
- me.updateRationBasePrcRq(updateBasePrcArr);
- }*/
- });
- }
- }
- },
- repositoryGljDelOpr: function () {
- let me = repositoryGljObj;
- me.workBook.commandManager().register('repositoryGljDel', function () {
- let sels = me.workBook.getActiveSheet().getSelections();
- me.delGljs(sels);
- });
- me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
- me.workBook.commandManager().setShortcutKey('repositoryGljDel', GC.Spread.Commands.Key.del, false, false, false, false);
- },
- onContextmenuOpr: function () {
- let me = repositoryGljObj;
- $.contextMenu({
- selector: '#GLJListSheet',
- build: function($triggerElement, e){
- //控制允许右键菜单在哪个位置出现
- let sheet = me.workBook.getSheet(0);
- let offset = $("#GLJListSheet").offset(),
- x = e.pageX - offset.left,
- y = e.pageY - offset.top;
- let target = sheet.hitTest(x, y);
- let sel = sheet.getSelections()[0];
- if(sel.row === -1){
- sel.row = 0;
- }
- if(sel.col === -1){
- sel.col = 0;
- }
- if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
- me.initSel(target.row);
- if(sel.row > target.row || sel.row + sel.rowCount - 1 < target.row ||
- sel.col > target.col || sel.col + sel.colCount - 1 < target.col ){
- sheet.setActiveCell(target.row, target.col);
- }
- return {
- callback: function(){},
- items: {
- "delete": {
- name: "删除",
- disabled: function () {
- return !(me.currentCache && me.currentCache[target.row]);
- },
- icon: "fa-remove",
- callback: function (key, opt) {
- let curSel = _.cloneDeep(sheet.getSelections()[0]);
- curSel.colCount = me.setting.header.length;
- me.delGljs([curSel]);
- }}
- }
- };
- }
- else{
- return false;
- }
- }
- });
- },
- validUpdateObj: function (pasteObj, rowIdx) {
- let rst = {updateGlj: [], updateBasePrcArr: []}, backUpObj = {},
- me = repositoryGljObj,
- that = gljComponentOprObj,
- tempObj = me.currentCache[rowIdx],
- reCalBasePrc = false,
- isValid = true;
- //备份原始数据
- for(let atr in tempObj){
- backUpObj[atr] = tempObj[atr];
- }
- if(typeof pasteObj.code !== 'undefined'){
- if(pasteObj.code.trim().length !== 0){
- let isExist = false;
- for(let i = 0; i < me.stdGljList.length; i++){
- if(me.stdGljList[i].code === pasteObj.code){
- isExist = true;
- break;
- }
- }
- if(!isExist){
- for(let i = 0; i < me.complementaryGljList.length; i++){
- if(me.complementaryGljList[i].code === pasteObj.code){
- isExist = true;
- break;
- }
- }
- }
- if(!isExist){
- tempObj.code = pasteObj.code;
- }
- else isValid = false;
- }
- else isValid = false;
- }
- if(typeof pasteObj.name !== 'undefined'){
- if(pasteObj.name.trim().length === 0) isValid = false;
- else tempObj.name = pasteObj.name;
- }
- if(typeof pasteObj.specs !== 'undefined'){
- tempObj.specs = pasteObj.specs;
- }
- if(typeof pasteObj.unit !== 'undefined'){
- tempObj.unit = pasteObj.unit;
- }
- if(typeof pasteObj.gljType !== 'undefined'){
- let isExsit = false;
- for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
- if(pasteObj.gljType === me.distTypeTree.comboDatas[i].text){
- pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
- isExsit = true;
- reCalBasePrc = true;
- if(pasteObj.gljType !== 301 && tempObj.gljType === 301){
- tempObj.model = null;
- }
- if(componentType.includes(tempObj.gljType)&&
- !(machineComponent.includes(tempObj.gljType) && machineComponent.includes(pasteObj.gljType)) &&
- !(materialComponent.includes(tempObj.gljType) && materialComponent.includes(pasteObj.gljType))){//修改了原本是组成物的工料机
- //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
- let updateGljs = me.getUpdateGljs(tempObj, true);
- if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
- for(let i = 0; i < updateGljs.updateArr.length; i++){
- rst.updateGlj.push(updateGljs.updateArr[i]);
- }
- for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
- rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
- }
- }
- }
- tempObj.component = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.component : [];
- /*if(me.allowComponent.indexOf(tempObj.gljType) !== -1){
- tempObj.basePrice = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.basePrice : 0;
- }*/
- tempObj.gljType = me.distTypeTree.comboDatas[i].value;
- tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
- break;
- }
- }
- if(!isExsit) isValid = false;
- }
- //
- pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? scMathUtil.roundTo(parseFloat(pasteObj.basePrice), 2) :
- me.currentCache[rowIdx].basePrice;
- if(pasteObj.basePrice !== me.currentCache[rowIdx].basePrice){
- reCalBasePrc = true;
- tempObj.basePrice = pasteObj.basePrice;
- let updateGljs = me.getUpdateGljs(tempObj, false);
- if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
- for(let i = 0; i < updateGljs.updateArr.length; i++){
- rst.updateGlj.push(updateGljs.updateArr[i]);
- }
- for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
- rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
- }
- }
- }
- if(typeof pasteObj.model !== 'undefined'){
- if(!me.machineModel.textArr.includes(pasteObj.model)){
- isValid = false;
- }
- else {
- let existsModel = false;
- if((typeof pasteObj.gljType !== 'undefined' && pasteObj.gljType === 301) ||
- (tempObj.gljType && tempObj.gljType === 301)){
- me.machineModel.comboItems.forEach(function (item) {
- if(item.text === pasteObj.model){
- tempObj.model = item.value;
- existsModel = true;
- }
- });
- if(!existsModel){
- isValid = false;
- }
- }
- else {
- isValid = false;
- }
- }
- }
- if(isValid){
- rst.updateGlj.push(tempObj);
- if(reCalBasePrc){
- //重新计算定额基价对象
- //rst.updateBasePrc = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
- let newReObj = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
- rst.updateBasePrcArr.push(newReObj);
- }
- }
- else {
- for(let attr in backUpObj){
- tempObj[attr] = backUpObj[attr];
- }
- }
- return rst;
- },
- //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
- isValidObj: function(pasteObj) {
- let me = repositoryGljObj;
- if(!(pasteObj.code && typeof pasteObj.code !== 'undefined') || !(pasteObj.name && typeof pasteObj.name !== 'undefined') ||
- !(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined')){
- return false;
- }
- if(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined'){
- let isExist = false;
- for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
- if(me.distTypeTree.comboDatas[i].text === pasteObj.gljType){
- isExist = true;
- pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
- pasteObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + pasteObj.gljType].data.shortName;
- break;
- }
- }
- if(!isExist){
- return false;
- }
- }
- if(pasteObj.code && typeof pasteObj.code !== 'undefined'){
- for(let i = 0; i < me.stdGljList.length; i++){
- if(me.stdGljList[i].code === pasteObj.code){
- return false;
- }
- }
- for(let i = 0; i < me.complementaryGljList.length; i++){
- if(me.complementaryGljList[i].code === pasteObj.code){
- return false;
- }
- }
- }
- if(typeof pasteObj.model !== 'undefined' && pasteObj.model){
- if(!me.machineModel.textArr.includes(pasteObj.model) || pasteObj.gljType !== 301){
- return false;
- }
- me.machineModel.comboItems.forEach(function (item) {
- if(item.text === pasteObj.model){
- pasteObj.model = item.value;
- }
- });
- }
- pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
- if(!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
- pasteObj.gljClass = me.gljCurTypeId;
- }
- return true;
- },
- canPasted: function (info) {
- let rst = true;
- let me = repositoryGljObj;
- if(me.gljCurTypeId < 0){
- return false;
- }
- if(info.cellRange.col + info.cellRange.colCount - 1 > me.setting.header.length - 2){
- return false;
- }
- if(info.cellRange.row < me.currentCache.length){
- if(info.cellRange.col === 0){
- return false;
- }
- else if(info.cellRange.col <= 4 && info.cellRange.col + info.cellRange.colCount - 1 >= 4){
- for(let i = 0, len = info.cellRange.rowCount; i < len; i++){
- let row = i + info.cellRange.row;
- if(row < me.currentCache.length){
- if(allowComponent.includes(me.currentCache[row].gljType)){
- rst = false;
- }
- }
- else {
- break;
- }
- }
- }
- }
- return rst;
- },
- onClipboardPasting: function(sender, args) {
- let me = repositoryGljObj;
- let maxCol = args.cellRange.col + args.cellRange.colCount - 1;
- if (!me.canPasted(args)) {
- args.cancel = true;
- }
- },
- onClipboardPasted: function(e, info) {
- // if(info.pasteData.text.trim().length > 0){
- let me = repositoryGljObj;
- let updateArr = [], addArr = [];
- let items = sheetOpr.analyzePasteData(me.setting, info);
- let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,//复制的起始行数和结束行数
- maxRow = me.currentCache.length - 1,//当前数据最大行数
- updateBasePrcArr = [] ,
- updateCount, resumeArr = [];
- if(endRow <= maxRow){
- //updateItems = items;
- for(let i = 0; i < items.length; i++){
- let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
- if(updateObj && typeof updateObj.updateGlj !== 'undefined' && updateObj.updateGlj.length > 0){
- //updateArr = updateObj.updateGlj;
- updateArr = updateArr.concat(updateObj.updateGlj);
- if(typeof updateObj.updateBasePrcArr !== 'undefined'){
- updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
- }
- }
- }
- }
- else if(beginRow <= maxRow && endRow > maxRow){
- updateCount = maxRow - beginRow + 1;
- for(let i = 0; i < updateCount; i++){
- let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
- if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
- //updateArr = updateObj.updateGlj;
- updateArr = updateArr.concat(updateObj.updateGlj);
- if(typeof updateObj.updateBasePrcArr !== 'undefined'){
- updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
- }
- }
- }
- if(info.cellRange.colCount === me.setting.header.length -1){
- for(let i = updateCount ; i < items.length; i++){
- if(me.isValidObj(items[i])){
- items[i].component = [];
- //类型为混凝土、砂浆、配合比、机械时,基价只能组成物计算
- /* if(me.allowComponent.indexOf(items[i].gljType) !== -1){
- items[i].basePrice = 0;
- }*/
- addArr.push(items[i]);
- }
- }
- }
- }
- else{
- if(info.cellRange.colCount === me.setting.header.length -1){
- for(let i = 0; i < items.length; i++){
- if(me.isValidObj(items[i])){
- items[i].component = [];
- /*if(me.allowComponent.indexOf(items[i].gljType) !== -1){
- items[i].basePrice = 0;
- }*/
- addArr.push(items[i]);
- }
- }
- }
- }
- //repaint
- for(let i = 0; i < info.cellRange.rowCount; i++){
- resumeArr.push(info.cellRange.row + i);
- }
- if(resumeArr.length > 0){
- let sheet = me.workBook.getActiveSheet();
- sheet.suspendPaint();
- for(let i = 0; i < resumeArr.length ; i++){
- if(resumeArr[i] < me.currentCache.length){
- for(let col = 0; col < me.setting.header.length -1; col++){
- if(me.setting.header[col].dataCode === 'gljType'){
- let gljType = me.currentCache[resumeArr[i]][me.setting.header[col].dataCode];
- sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
- }
- else if(me.setting.header[col].dataCode === 'model'){
- sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode] ? me.machineModelIdx[me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]]: '');
- }
- else{
- sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]);
- }
- }
- }
- else{
- for(let col = 0; col < me.setting.header.length - 1; col++){
- sheet.setValue(resumeArr[i], col, '', GC.Spread.Sheets.SheetArea.viewport);
- }
- }
- }
- sheet.resumePaint();
- }
- if (updateArr.length > 0 || addArr.length > 0) {
- me.mixUpdateRequest(updateArr, addArr, []);
- }
- if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
- me.updateRationBasePrcRq(updateBasePrcArr);
- }
- // }
- },
- updateRationBasePrcRq: function (basePrcArr) {
- CommonAjax.post('complementartGlj/api/updateRationBasePrc', {basePrcArr: basePrcArr}, function (rstData) {
- });
- },
- /* getRationGljIds: function (repId) {
- let me = repositoryGljObj;
- $.ajax({
- type: 'post',
- url: 'api/getRationGljIds',
- data: {data: JSON.stringify({repId: repId})},
- dataType: 'json',
- success: function(result){
- if(!result.error){
- me.rationGljIds = result.data;
- }
- }
- });
- },*/
- mixUpdateRequest: function(updateArr, addArr, removeIds) {
- let me = repositoryGljObj;
- if(updateArr.length > 0){
- me.saveInString(updateArr);
- }
- if(addArr.length > 0){
- me.saveInString(addArr);
- }
- let url = 'complementartGlj/api/mixUpdateGljItems';
- let post = {updateItems: updateArr, addItems: addArr, removeIds: removeIds};
- let scCaller = function (rstData) {
- me.updateCache(addArr, updateArr, removeIds, rstData);
- me.sortGlj(me.complementaryGljList);
- if(me.currentOprParent === 1){
- me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
- }
- else{
- me.currentCache = me.getCache();
- }
- me.showGljItems(me.complementaryGljList, me.gljCurTypeId);
- //getCurrentGlj
- let row = me.workBook.getSheet(0).getSelections()[0].row;
- me.currentGlj = row < me.currentCache.length ? me.currentCache[row] : null;
- me.currentComponent = me.currentGlj ? me.getCurrentComponent(me.currentGlj.component) : [];
- sheetOpr.cleanData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, -1);
- sheetOpr.showData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, me.currentComponent);
- }
- let errCaller = function (err) {
- alert('保存失败');
- };
- CommonAjax.post(url, post, scCaller, errCaller);
- },
- saveInString: function (datas) {
- for(let i = 0, len = datas.length; i < len; i++){
- let data = datas[i];
- if(_exist(data, 'basePrice')){
- data['basePrice'] = data['basePrice'].toString();
- }
- if(_exist(data, 'component')){
- for(let j = 0, jLen = data['component'].length; j < jLen; j++){
- let comGljObj = data['component'][j];
- if(_exist(comGljObj, 'consumeAmt')){
- comGljObj['consumeAmt'] = comGljObj['consumeAmt'].toString();
- }
- }
- }
- }
- function _exist(data, attr){
- return data && data[attr] !== undefined && data[attr];
- }
- },
- getParentCache: function (nodes) {
- let me = repositoryGljObj, rst = [];
- for(let i = 0; i < me.complementaryGljList.length; i++){
- if(nodes.indexOf(me.complementaryGljList[i].gljClass) !== -1){
- rst.push(me.complementaryGljList[i]);
- }
- }
- rst.sort(function (a, b) {
- let rst = 0;
- if(a.code > b.code) rst = 1;
- else if(a.code < b.code)rst = -1;
- return rst;
- });
- return rst;
- },
- getCache: function() {
- let me = this, rst = [];
- for (let i = 0; i < me.complementaryGljList.length; i++) {
- if (me.complementaryGljList[i].gljClass == me.gljCurTypeId) {
- rst.push(me.complementaryGljList[i]);
- }
- }
- return rst;
- },
- updateCache: function(addArr, updateArr, removeIds, rstData) {
- let me = this, cacheSection = me.complementaryGljList;
- if (addArr.length > 0) {
- me.complementaryGljList = me.complementaryGljList.concat(addArr);
- cacheSection = me.complementaryGljList;
- }
- for (let i = removeIds.length - 1; i >= 0; i--) {
- for (let j = cacheSection.length - 1; j >= 0 ; j--) {
- if (cacheSection[j]["ID"] == removeIds[i]) {
- cacheSection.splice(j,1);
- }
- }
- }
- if (rstData && rstData.ops && rstData.ops.length > 0) {
- for (let i = 0; i < rstData.ops.length; i++) {
- for (let j = 0; j < cacheSection.length; j++) {
- if (cacheSection[j][me.setting.header[0].dataCode] == rstData.ops[i][me.setting.header[0].dataCode]) {
- cacheSection[j]["ID"] = rstData.ops[i]["ID"];
- }
- }
- }
- }
- 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"]) {
- cacheSection[j] = updateArr[i];
- }
- } else {
- if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
- cacheSection[j] = updateArr[i];
- }
- }
- }
- }
- //allgljs
- },
- updateParentNodeIds: function (nodes, caller) {
- let private_build_parentNodeIds = function(pNodeId, nodesArr){
- let rst = [];
- for (let i = 0; i < nodesArr.length; i++) {
- if (nodesArr[i].children.length > 0) {
- rst = rst.concat(private_build_parentNodeIds(nodesArr[i].data.ID, nodesArr[i].children));
- } else {
- rst.push(nodesArr[i].data.ID);
- }
- }
- if (pNodeId && rst.length > 0) {
- caller.parentNodeIds["_pNodeId_" + pNodeId] = rst;
- }
- return rst;
- };
- if (caller.parentNodeIds) {
- private_build_parentNodeIds(null, nodes);
- }
- },
- setProp: function (prop, value, gljList) {
- let me = this;
- for(let i = 0, len = gljList.length; i < len; i++){
- gljList[i][prop] = value;
- }
- },
- sortGlj: function(gljList) {
- let me = this;
- gljList.sort(function(a, b){
- let rst = 0;
- if (a.code > b.code) rst = 1
- else if (a.code < b.code) rst = -1;
- return rst;
- });
- }
- }
- let gljTypeTreeOprObj = {
- onClick: function(event,treeId,treeNode) {
- let me = repositoryGljObj,
- that = gljComponentOprObj,
- gljTypeId = treeNode.ID;
- me.gljCurTypeId = treeNode.ID;
- //消除新增到一半的数据
- me.addGljObj = null;
- //me.currentCache = me.getCache();
- sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, 5);
- if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
- me.currentOprParent = 1;
- me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
- me.workBook.getSheet(0).setRowCount(me.currentCache.length);
- } else {
- me.currentOprParent = 0;
- me.currentCache = me.getCache();
- }
- me.showGljItems(me.complementaryGljList, gljTypeId);
- }
- }
|