/** * Created by Zhong on 2017/12/18. */ let pageOprObj = { rationLibName : null, rationLibId : null, gljLibId: null, initPage : function() { let me = this, rationLibId = getQueryString("repository"); me.getRationLibInfo(rationLibId, function (rstData) { if(rstData.length > 0){ me.rationLibName = rstData[0].dispName; //let $rationName = $(``); let $rationName = $(``); $('.header-logo').after($rationName); me.gljLibId = rstData[0].gljLib; me.rationLibId = rationLibId; sectionTreeObj.getSectionTree(rationLibId); //job jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial); $('#addConBtn').click(jobContentOprObj.bindAddConBtn()); $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn()); jobContentOprObj.bindAllEvents($('#txtareaAll')); //fz annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial); $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn()); $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn()); annotationOprObj.bindAllEvents($('#fzTxtareaAll')); } gljSelOprObj.getGljClassTree(pageOprObj.gljLibId, function () { gljSelOprObj.getSelGljItems(pageOprObj.gljLibId); }); }); }, getRationLibInfo: function (rationLibId, callback) { CommonAjax.post('api/getRationLib', {rationRepId: rationLibId}, callback); }, //获取定额库列表 /*getRationLibs: function () { let scFunc = function (rstData) { $("#comple_ration_table").empty(); for(let i = 0; i < rstData.length; i++){ storageUtil.setSessionCache("RationGrp","repositoryID_" + rstData[i].ID, rstData[i].dispName); if(rstData[i].gljLib !== undefined && rstData[i].gljLib && rstData[i].gljLib != -1){ storageUtil.setSessionCache("gljLib","repositoryID_" + rstData[i].ID, rstData[i].gljLib); let id = rstData[i].ID; let libName = rstData[i].dispName; $("#comple_ration_table").append( "" + ""+libName+"" ); var newHref = "/complementaryRation/ration?repository="+id; $("#tempId td:first a").attr("href", newHref); $("#tempId").attr("id", id); } } }; let ration_lib = projectInfoObj.projectInfo.engineeringInfo.ration_lib; let ids = []; for(lib of ration_lib){ ids.push(parseInt(lib.id)); } CommonAjax.post('/complementaryRation/api/getRationLibs', {user_id: userID, ids: ids}, scFunc); }*/ }; let sectionTreeObj = { cache: null,//ref to tree.items tree: null, controller: null, workBook: null, sheet: null, updateType: {new: 'new', update: 'update'}, insertBtn: $('#tree_Insert'), removeBtn: $('#tree_remove'), type: {std: 'std', complementary: 'complementary'}, setting: { sheet: { cols:[ { head: { titleNames: ['名称'], spanCols: [1], spanRows: [2], vAlign: [1, 1], hAlign: [1, 1], font: 'Arial' }, data: { field: 'name', vAlign: 1, hAlign: 0, font: 'Arial' }, width: 400 } ], headRows: 1, headRowHeight: [47], emptyRows: 0, treeCol: 0 }, tree: { id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1 }, options: { allowContextMenu: false, tabStripVisible: false, allowCopyPasteExcelStyle : false, allowExtendPasteRange: false, allowUserDragDrop : false, allowUserDragFill: false, scrollbarMaxAlign : true } }, isDef: function (v) { return v !== undefined && v !== null; }, isFunc: function (v) { return this.isDef(v) && typeof v === 'function'; }, //sheet things setOptions: function (workbook, opts) { for(let opt in opts){ workbook.options[opt] = opts[opt]; } }, renderFunc: function (sheet, func) { sheet.suspendPaint(); sheet.suspendEvent(); if(this.isFunc(func)){ func(); } sheet.resumePaint(); sheet.resumeEvent(); }, buildSheet: function () { if(!this.isDef(this.workBook)){ this.workBook = new GC.Spread.Sheets.Workbook($('#sectionSpread')[0], {sheetCount: 1}); sheetCommonObj.bindEscKey(this.workBook, [{sheet: this.workBook.getSheet(0), editStarting: this.onEditStarting, editEnded: this.onEditEnded}]); this.sheet = this.workBook.getSheet(0); this.bindEvents(this.sheet); this.setOptions(this.workBook, this.setting.options); this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values; } }, bindEvents: function (sheet) { let me = sectionTreeObj; const Events = GC.Spread.Sheets.Events; sheet.bind(Events.SelectionChanging, me.onSelectionChanging); sheet.bind(Events.EditEnded, me.onEditEnded); sheet.bind(Events.EditStarting, me.onEditStarting); sheet.bind(Events.ClipboardPasting, me.onClipboardPasting); sheet.bind(Events.ClipboardPasted, me.onClipboardPasted); }, onSelectionChanging: function (sender, info) { let me = sectionTreeObj; if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){ let row = info.newSelections[0].row; let section = me.cache[row]; me.initSelection(section); } else { me.refreshBtn(null); } }, onEditStarting: function (sender, args) { let me = sectionTreeObj; let node = me.cache[args.row]; if(!me.isDef(node)){ args.cancel = true; return; } if(node.data.type === me.type.std){ args.cancel = true; } }, onEditEnded: function (sender, args) { let me = sectionTreeObj; let postData = []; let v = me.isDef(args.editingText) ? args.editingText.toString().trim() : ''; let node = me.cache[args.row]; if(me.isDef(node) && node.data.name !== v){ let updateObj = me.getUpdateObj(me.updateType.update, {ID: node.getID(), name: v}); postData.push(updateObj); //ajax //update me.sectionTreeAjax(postData, function (rstData) { node.data.name = v; }, function () { args.sheet.setValue(args.row, args.col, node.data.name ? node.data.name : ''); }); } }, onClipboardPasting: function (sender, info) { let me = sectionTreeObj; let hasStd = false; for(let row = info.cellRange.row, len = info.cellRange.row + info.cellRange.rowCount - 1; row < len; row ++){ if(me.isDef(me.cache[row]) && me.cache[row].data.type === me.type.std){ hasStd = true; } } if(hasStd){ info.cancel = true; } }, onClipboardPasted: function (sender, info) { let me = sectionTreeObj; let items = sheetCommonObj.analyzePasteData({header: [{dataCode: 'name'}]}, info); let postData = []; let frontData = []; for(let i = 0, len = items.length; i < len; i++){ let row = info.cellRange.row + i; let node = me.cache[row]; if(me.isDef(node) && me.isDef(items[i].name) && node.data.name !== items[i].name){ let updateObj = me.getUpdateObj(me.updateType.update, {ID: node.getID(), name: items[i].name}); postData.push(updateObj); frontData.push({row: row, name: items[i].name}); node.data.name = items[i].name; } } if(postData.length > 0){ //ajax me.sectionTreeAjax(postData, function (rstData) { for(let i = 0, len = frontData.length; i < len; i++){ let node = me.cache[frontData[i]['row']]; if(me.isDef(node)){ node.data.name = frontData[i]['name']; } } }, function () { for(let i = 0, len = frontData.length; i < len; i++){ let node = me.cache[frontData[i]['row']]; me.sheet.setValue(frontData[i]['row'], 0, me.isDef(node) ? node.data.name : ''); } }); } }, getSectionTree: function (repId) { let me = sectionTreeObj; let url = 'api/getRationTree'; let postData = {rationRepId: repId}; let sucFunc = function (rstData) { if(rstData.length > 0){ storageUtil.setSessionCache("RationGrp","repositoryID",rstData[0].rationRepId); } //init me.buildSheet(); me.initTree(rstData); me.cache = me.tree.items; me.bindBtn(); me.initController(me.tree, me.sheet, me.setting.sheet); me.controller.showTreeData(); me.setColor(me.cache); me.sheet.setFormatter(-1, 0, '@'); me.initSelection(me.tree.selected); explanatoryOprObj.bindEvents($('#explanationShow'), $('#ruleTextShow')); }; let errFunc = function () { }; CommonAjax.post(url, postData, sucFunc, errFunc); }, setColor: function (nodes) { let me = this; me.renderFunc(me.sheet, function () { for(let i = 0, len = nodes.length; i < len; i++){ if(nodes[i].data.type === me.type.complementary){ me.sheet.getCell(i, 0).foreColor('gray'); } } }); }, initTree: function (datas) { this.tree = idTree.createNew(this.setting.tree); this.tree.loadDatas(datas); this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null; }, initController: function (tree, sheet, setting) { this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting); }, refreshBtn: function (selected) { let me = this; me.insertBtn.removeClass('disabled'); me.removeBtn.removeClass('disabled'); if(!me.isDef(selected)){ me.removeBtn.addClass('disabled'); } else if(me.isDef(selected.data.type) && selected.data.type !== me.type.complementary){ me.removeBtn.addClass('disabled'); } }, bindBtn: function () { let me = this; me.insertBtn.click(function () { me.insert(); }); me.removeBtn.click(function () { me.remove(me.tree.selected); }); }, insert: function () { let me = this; me.insertBtn.addClass('disabled'); let postData = []; CommonAjax.post('api/getNewTreeID', {user_id: userID}, function (newID) { if(!me.isDef(newID)){ return; } me.tree.maxNodeID(newID - 1); let selected = me.tree.selected; let insertObj = me.getUpdateObj(me.updateType.new, {ID: newID, NextSiblingID: -1, ParentID: -1, name: ''}); if(me.isDef(selected)) { insertObj.updateData.ParentID = selected.getParentID(); //同级节点 let slNodes = []; slNodes = !me.isDef(selected.parent)? me.tree.roots : selected.parent.children; let updateNode = slNodes[slNodes.length - 1]; if(me.isDef(updateNode)){ me.controller.setTreeSelected(updateNode); if(updateNode.data.type === me.type.complementary){ let updateObj = me.getUpdateObj(me.updateType.update, {ID: updateNode.getID(), NextSiblingID: newID}); postData.push('updateObj'); postData.push(updateObj); } else { insertObj.updateData.isFirst = true; } } } postData.push(insertObj); if(postData.length > 0){ //ajax me.sectionTreeAjax(postData, function (rstData) { me.controller.insert(); me.sheet.getCell(me.sheet.getActiveRowIndex(), 0).foreColor('gray'); me.tree.selected.data = insertObj.updateData; me.tree.selected.data.type = me.type.complementary; me.refreshBtn(me.tree.selected); //fresh tools me.initTools(me.tree.selected); me.initSelection(me.tree.selected); }); } }); }, remove: function (selected) { let me = this; me.removeBtn.addClass('disabled'); let postData = [], IDs = []; let deleteObj = Object.create(null); deleteObj.deleted = true; deleteObj.deleteDateTime = new Date(); deleteObj.deleteBy = userID; if(!selected){ return; } getDelIds(selected); function getDelIds(node){ if(me.isDef(node)){ IDs.push(node.getID()); if(node.children.length > 0){ for(let i = 0, len = node.children.length; i < len; i++){ getDelIds(node.children[i]); } } } } if(me.isDef(selected.preSibling) && selected.preSibling.data.type === me.type.complementary){ let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null); postData.push(updateObj); } else if((!me.isDef(selected.preSibling) || (me.isDef(selected.preSibling) && selected.preSibling.data.type === me.type.std)) && me.isDef(selected.nextSibling)){ let updateNextObj = me.getUpdateObj(me.updateType.update, {ID: selected.nextSibling.getID(), isFirst: true}); postData.push(updateNextObj); } if(IDs.length > 0){ for(let i = 0, len = IDs.length; i < len; i++){ let delObj = me.getUpdateObj(me.updateType.update, {ID: IDs[i], deleteInfo: deleteObj}); postData.push(delObj); } } if(postData.length > 0){ //ajax me.sectionTreeAjax(postData, function (rstData) { me.controller.delete(); me.refreshBtn(me.tree.selected); me.initTools(me.tree.selected); me.initSelection(me.tree.selected); }); } }, getUpdateObj: function (updateType, updateData) { let updateObj = Object.create(null); updateObj.updateType = ''; updateObj.updateData = Object.create(null); updateObj.updateData.rationRepId = pageOprObj.rationLibId; if(this.isDef(updateType)){ updateObj.updateType = updateType; } if(this.isDef(updateData)){ for(let attr in updateData){ updateObj.updateData[attr] = updateData[attr]; } } return updateObj; }, sectionTreeAjax: function (postData, scFunc, errFunc) { CommonAjax.post('api/updateRationSection', {updateData: postData}, scFunc, errFunc); }, initTools: function (node) { if(this.isDef(node)){ explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText); explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow')); explanatoryOprObj.showText($('#explanationShow'), $('#ruleTextShow'), node.data.explanation, node.data.ruleText); //job jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.NONE; jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node); jobContentOprObj.clickUpdate($('#txtareaAll')); //fz annotationOprObj.currentSituation = typeof node.data.annotationSituation !== 'undefined'? node.data.annotationSituation : annotationOprObj.situations.NONE; annotationOprObj.clickUpdate($('#fzTxtareaAll')); } }, //模仿默认点击 initSelection: function (node) { let me = this; if(!me.isDef(node)){ sheetCommonObj.cleanSheet(rationOprObj.workBook.getActiveSheet(), rationOprObj.setting, -1); sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1); sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1); sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1); sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1); return; } me.workBook.getActiveSheet().setActiveCell(node.serialNo(), 0); me.initTools(node); me.refreshBtn(node); if(!me.isDef(node.children) || node.children.length === 0){ rationOprObj.canRations = true; rationOprObj.workBook.getSheet(0).clearSelection(); rationOprObj.getRationItems(node.data.ID); rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic'); } else { rationOprObj.canRations = false; rationOprObj.currentSectionId = node.data.ID; rationOprObj.workBook.getSheet(0).setRowCount(30); rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null); // jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios); jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial')); // annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios); annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial')); sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1); } sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1); sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1); sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1); sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1); //rationGLJOprObj.sheet.getParent().focus(false); me.workBook.focus(true); } };