123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- /**
- * Standard Ration Lib
- * Created by Mai on 2017/5/16.
- */
- /*var rationChapterSpread, sectionRationsSpread;*/
- var rationLibObj = {
- doAfterGetRationTree: null, //获取章节树回调
- doAfterLoadGetRations: null, //获取章节树下定额后回调
- rationChapterSpread: null,
- sectionRationsSpread: null,
- resultSpread: null,
- rationChapterTreeController: null,
- refreshSettingForHint: function () {
- TREE_SHEET_HELPER.initSetting($('#stdSectionRations')[0], rationLibObj.sectionRationsSetting);
- },
- checkSpread: function () {
- if (!this.rationChapterSpread) {
- this.rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
- sheetCommonObj.spreadDefaultStyle(this.rationChapterSpread);
- this.rationChapterSpread.getSheet(0).name('stdRationLib_chapter');
- this.rationChapterSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onChapterSpreadCellDoubleClick);
- }
- if (!this.sectionRationsSpread) {
- this.sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
- sheetCommonObj.spreadDefaultStyle(this.sectionRationsSpread);
- this.sectionRationsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRationSpreadCellDoubleClick);
- this.refreshSettingForHint();
- }
- },
- refreshSpread: function () {
- if (this.rationChapterSpread) {
- this.rationChapterSpread.refresh();
- }
- if (this.sectionRationsSpread) {
- this.sectionRationsSpread.refresh();
- }
- if(this.resultSpread){
- this.resultSpread.refresh();
- }
- },
- loadStdRationLibs: function () {
- let select = $('#stdRationLibSelect');
- select.empty();
- let ration_lib = projectInfoObj.projectInfo.engineeringInfo.ration_lib;
- let selectedRationLib = sessionStorage.getItem('stdRationLib');
- ration_lib.forEach(function (data) {
- let option = $('<option>').val(data.id).text(data.name);
- //select.append($('<option>').val(data.id).text(data.name));
- if(selectedRationLib){
- if(data.id == selectedRationLib){
- option.attr('selected', 'selected');
- }
- }else if(data.isDefault == true){
- option.attr('selected', 'selected');
- }
- select.append(option);
- });
- if (select[0].options.length !== 0) {
- rationLibObj.loadStdRation(select.val());
- }
- },
- loadStdRation: function (rationLibID) {
- $.bootstrapLoading.start();
- var that = this;
- var showRationChapterTree = function (datas) {
- var rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
- console.log(that);
- that.tree = rationChapterTree;
- var rationChapterTreeController = TREE_SHEET_CONTROLLER.createNew(rationChapterTree, that.rationChapterSpread.getActiveSheet(), that.rationChapterTreeSetting);
- rationChapterTree.loadDatas(datas);
- //读取展开收起状态
- let currentExpState = sessionStorage.getItem('stdRationLibExpState');
- if(currentExpState){
- that.tree.setExpandedByState(that.tree.items, currentExpState);
- }
- else {
- //展开至第二层
- for(let root of that.tree.roots){
- root.setExpanded(true);
- that.tree.setRootExpanded(root.children, false);
- }
- }
- rationChapterTreeController.showTreeData();
- rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
- rationLibObj.loadSectionRations(node && node.children.length === 0 ? node.getID() : null);
- });
- if (rationChapterTree.firstNode() && rationChapterTree.firstNode().length === 0) {
- rationLibObj.loadSectionRations(rationChapterTree.firstNode().getID());
- } else {
- rationLibObj.loadSectionRations();
- };
- };
- CommonAjax.post('/complementaryRation/api/getRationTree', {userId: userID, rationRepId: rationLibID}, function (datas) {
- showRationChapterTree(datas);
- if(that.doAfterGetRationTree){
- that.doAfterGetRationTree();
- }
- $.bootstrapLoading.end();
- }, function () {
- showRationChapterTree([]);
- $.bootstrapLoading.end();
- });
- },
- //双击隐藏显示
- onChapterSpreadCellDoubleClick: function (sender, args) {
- let me = rationLibObj;
- let node = me.tree.items[args.row];
- if (!node || node.children.length === 0)
- return;
- node.setExpanded(!node.expanded);
- sessionStorage.setItem('stdRationLibExpState', me.tree.getExpState(me.tree.items));
- TREE_SHEET_HELPER.massOperationSheet(args.sheet, function () {
- let iCount = node.posterityCount(), i, child;
- for (i = 0; i < iCount; i++) {
- child = me.tree.items[args.row + i + 1];
- args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
- }
- args.sheet.invalidateLayout();
- });
- args.sheet.repaint();
- },
- setTagForHint: function (sheet, datas) {
- sheet.suspendPaint();
- sheet.suspendEvent();
- for(let i = 0, len = sheet.getRowCount(); i < len; i++){
- sheet.setTag(i, 0, '');
- }
- for(let i = 0, len = datas.length; i < len; i++){
- if(datas[i].code === 'AA0032'){
- console.log(datas[i]);
- }
- sheet.setTag(i, 0, datas[i].hint ? datas[i].hint : '');
- }
- sheet.resumePaint();
- sheet.resumeEvent();
- },
- loadSectionRations: function (sectionID) {
- let me = this;
- var showDatas = function (datas, setting) {
- let rationSheet = rationLibObj.sectionRationsSpread.getActiveSheet();
- TREE_SHEET_HELPER.massOperationSheet(rationSheet, function () {
- rationSheet.setColumnWidth(0, 25, GC.Spread.Sheets.SheetArea.rowHeader);
- });
- SheetDataHelper.loadSheetHeader(setting, rationLibObj.sectionRationsSpread.getActiveSheet());
- SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
- rationLibObj.setTagForHint(rationSheet, datas);
- };
- if (sectionID) {
- CommonAjax.post('/complementaryRation/api/getRationGljItemsBySection', {user_Id: userID, sectionId: sectionID}, function (datas) {
- showDatas(datas, rationLibObj.sectionRationsSetting);
- if(me.doAfterLoadGetRations){
- me.doAfterLoadGetRations(datas);
- me.doAfterLoadGetRations = null;
- }
- }, function () {
- showDatas([], rationLibObj.sectionRationsSetting);
- });
- } else {
- showDatas([], rationLibObj.sectionRationsSetting);
- }
- },
- onRationSpreadCellDoubleClick: function (sender, args) {
- var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
- if (rationCode !== '') {
- projectObj.project.Ration.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration, function () {
- projectObj.setActiveCell('quantity', true);
- });
- }
- },
- loadStdRationContextMenu: function () {
- let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet(), rationModel = projectObj.project.Ration;;
- $.contextMenu({
- selector: '#stdSectionRations',
- build: function ($trigger, e) {
- let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
- return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
- },
- items: {
- "insertStdRation": {
- name: "插入定额",
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
- let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
- if (rationCode !== '') {
- rationModel.addNewRation({userID: userID, rationRepId: select.val(), code: rationCode},rationType.ration, function () {
- });
- }
- }
- },
- "replaceStdRation": {
- name: "替换定额",
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
- let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
- let mainTreeSelected = projectObj.project.mainTree.selected;
- if (rationCode !== ''&&mainTreeSelected&&mainTreeSelected.sourceType == rationModel.getSourceType()) {
- rationModel.updateRationCodes([{'node':mainTreeSelected,value:rationCode}]);
- }
- }
- },
- }
- });
- },
- expandSearchNodes: function(nodes){
- let that = rationLibObj;
- TREE_SHEET_HELPER.massOperationSheet(that.rationChapterSpread.getActiveSheet(), function () {
- function expParentNode(node){
- if(node.parent){
- expParentNode(node.parent);
- if(!node.parent.expanded){
- node.parent.setExpanded(true);
- }
- }
- }
- for(let node of nodes){
- expParentNode(node);
- }
- TREE_SHEET_HELPER.refreshTreeNodeData(that.rationChapterTreeSetting, that.rationChapterSpread.getActiveSheet(), that.tree.roots, true);
- TREE_SHEET_HELPER.refreshNodesVisible(that.tree.roots, that.rationChapterSpread.getActiveSheet(), true);
- });
- },
- initSel: function (row) {
- let me = this;
- let sheet = me.rationChapterSpread.getActiveSheet();
- sheet.setActiveCell(row, 0);
- sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
- let sectionNode = me.tree.items[row] || null;
- me.loadSectionRations(sectionNode && sectionNode.children.length === 0 ? sectionNode.data.ID : null);
- },
- locateAtRation: function(libID, code){
- let me = rationLibObj;
- //查找定额,以确定定额所在章节节点
- let firstLibID = projectInfoObj.projectInfo.engineeringInfo.ration_lib.length > 0 ?
- projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id : null;
- let locateRow = 0,
- locateSubRow = 0;
- CommonAjax.post('/complementaryRation/api/getRationItem', {rationRepIds: [libID], code: code}, function (ration) {
- if(ration && ration.sectionId){
- let sectionNode = me.tree.findNode(ration.sectionId);
- if(sectionNode){
- me.expandSearchNodes([sectionNode]);
- sessionStorage.setItem('stdRationLibExpState', me.tree.getExpState(me.tree.items));
- }
- locateRow = sectionNode.serialNo();
- me.doAfterLoadGetRations = function (rationItems) {
- let rationSheet = me.sectionRationsSpread.getActiveSheet();
- locateSubRow = _.findIndex(rationItems, {ID: ration.ID});
- rationSheet.setActiveCell(locateSubRow, 0);
- rationSheet.showRow(locateSubRow, GC.Spread.Sheets.VerticalPosition.center);
- };
- me.initSel(locateRow);
- }
- else {
- me.initSel(locateRow);
- }
- }, function () {
- me.initSel(locateRow);
- });
- },
- rationChapterTreeSetting: {
- "emptyRowHeader": true,
- "rowHeaderWidth": 15,
- "emptyRows":0,
- "headRows":1,
- "headRowHeight":[30],
- "defaultRowHeight": 21,
- "treeCol": 0,
- "cols":[{
- "width":400,
- "readOnly": true,
- "head":{
- "titleNames":["名称"],
- "spanCols":[1],
- "spanRows":[1],
- "vAlign":[1],
- "hAlign":[1],
- "font":["Arial"]
- },
- "data":{
- "field":"name",
- "vAlign":1,
- "hAlign":0,
- "font":"Arial"
- }
- }]
- },
- sectionRationsSetting: {
- "emptyRows":3,
- "headRows":1,
- "headRowHeight":[20],
- "defaultRowHeight": 21,
- "cols":[{
- "width":60,
- "readOnly": true,
- "showHint": true,
- "head":{
- "titleNames":["编码"],
- "spanCols":[1],
- "spanRows":[1],
- "vAlign":[1],
- "hAlign":[1],
- "font":["Arial"]
- },
- "data":{
- "field":"code",
- "vAlign":1,
- "hAlign":0,
- "font":"Arial"
- }
- }, {
- "width":220,
- "readOnly": true,
- "head":{
- "titleNames":["名称"],
- "spanCols":[1],
- "spanRows":[1],
- "vAlign":[1],
- "hAlign":[1],
- "font":["Arial"]
- },
- "data":{
- "field":"name",
- "vAlign":1,
- "hAlign":0,
- "font":"Arial"
- }
- }, {
- "width":55,
- "readOnly":true,
- "head":{
- "titleNames":["单位"],
- "spanCols":[1],
- "spanRows":[1],
- "vAlign":[1],
- "hAlign":[1],
- "font":["Arial"]
- },
- "data":{
- "field":"unit",
- "vAlign":1,
- "hAlign":1,
- "font":"Arial"
- }
- }, {
- "width":60,
- "readOnly":true,
- "head":{
- "titleNames":["基价"],
- "spanCols":[1],
- "spanRows":[1],
- "vAlign":[1],
- "hAlign":[1],
- "font":["Arial"]
- },
- "data":{
- "field":"basePrice",
- "vAlign":1,
- "hAlign":2,
- "font":"Arial"
- }
- }]
- },
- getStdRationLibIDs: function () {
- let ids = [];
- if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
- alert('当前项目无定额库,请添加定额库。');
- return null;
- }
- for(let rationLib of projectInfoObj.projectInfo.engineeringInfo.ration_lib){
- ids.push(rationLib.id);
- }
- return ids;
- },
- getCurrentStdRationLibID:function () {
- if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
- alert('当前项目无定额库,请添加定额库。');
- return null;
- }
- if($('#stdRationLibSelect').val()){
- return parseInt($('#stdRationLibSelect').val());
- }else {
- return projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
- }
- },
- getFirstStdRationLibID: function () {
- if(projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0){
- alert('当前项目无定额库,请添加定额库。');
- return null;
- }
- return parseInt(projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id);
- },
- getDefaultStdRationLibID:function(){
- let ration_lib = projectInfoObj.projectInfo.engineeringInfo.ration_lib;
- if(ration_lib.length === 0){
- alert('当前项目无定额库,请添加定额库。');
- return null;
- }
- let defaultLib = _.find(ration_lib,{'isDefault':true});
- let libID = defaultLib?defaultLib.id:ration_lib[0].id;
- return parseInt(libID);
- }
- };
- addEventOnResize(rationLibObj.refreshSettingForHint);
- //赋初始高度
- if($('#stdRationChapter').height() === 0 || $('#stdSectionRations').height() === 0){
- $('#stdRationChapter').height($(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-q").height()-312);
- $('#stdSectionRations').height(270);
- }
- $('#stdRationTab').bind('click', function () {
- if(!projectReadOnly){
- var select = $('#stdRationLibSelect');
- rationLibObj.checkSpread();
- if (select[0].options.length === 0) {
- rationLibObj.loadStdRationLibs();
- rationLibObj.loadStdRationContextMenu();
- };
- }
- });
- $('#stdRationLibSelect').change(function () {
- var select = $(this);
- if (this.children.length !== 0) {
- let rationLibId = select.val();
- sessionStorage.setItem('stdRationLib', rationLibId);
- sessionStorage.removeItem('stdRationLibExpState');
- rationLibObj.loadStdRation(rationLibId);
- }
- });
- //回车键搜索
- $('#rationSearchKeyword').bind('keypress', function (event) {
- if(event.keyCode === 13){
- $(this).blur();
- $('#rationSearch').click();
- }
- });
- $('#rationSearchKeyword').keyup(function () {
- let keyword = $('#rationSearchKeyword').val();
- if(keyword === ''){
- if($('#rationSearchResult').is(':visible')){
- $('#rationSearchResult').hide();
- $(".main-data-side-search", $('#rationSearchResult')).height(0);
- autoFlashHeight();
- rationLibObj.refreshSpread();
- }
- }
- });
- $('#rationSearch').click(function () {
- var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
- if(keyword === ''){
- if($('#rationSearchResult').is(':visible')){
- $('#rationSearchResult').hide();
- $(".main-data-side-search", $('#rationSearchResult')).height(0);
- autoFlashHeight();
- rationLibObj.refreshSpread();
- }
- return;
- }
- var getResultHtml = function (result) {
- var html = [], i, serialNo;
- html.push('<div class="d-flex justify-content-between">');
- html.push('<span>搜索结果:');
- html.push(result.length.toString());
- html.push('</span>');
- html.push('<a title="关闭搜索" class="btn btn-link btn-sm" href="javascript:void(0)"><i class="fa fa-remove" aria-hidden="true"></i></a>');
- html.push('</div>');
- html.push('<div class="w-100 main-data-side-search">');
- html.push('</div>');
- return html.join('');
- };
- let bindContextmenuOpr = function (sheet) {
- $.contextMenu({
- selector: '#rationSearchResult',
- build: function($triggerElement, e){
- //控制允许右键菜单在哪个位置出现
- let offset = $('.main-data-side-search').offset(),
- x = e.pageX - offset.left,
- y = e.pageY - offset.top;
- let target = sheet.hitTest(x, y);
- if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
- sheet.setActiveCell(target.row, target.col);
- return {
- callback: function(){},
- items: {
- "locate": {
- name: "定位至章节",
- disabled: function () {
- return target.row >= rationLibObj.resultCache.length;
- },
- icon: "fa-arrow-left",
- callback: function (key, opt) {
- let data = rationLibObj.resultCache[target.row];
- $('#rationSearchResult').hide();
- $(".main-data-side-search", $('#rationSearchResult')).height(0);
- autoFlashHeight();
- rationLibObj.refreshSpread();
- rationLibObj.locateAtRation(data.rationRepId, data.code);
- }}
- }
- };
- }
- else{
- return false;
- }
- }
- });
- };
- var showResult = function (result) {
- rationLibObj.resultCache = result;
- if(!rationLibObj.resultSpread){
- let resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
- rationLibObj.resultSpread = resultSpread;
- bindContextmenuOpr(resultSpread.getActiveSheet());
- SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
- resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
- }else {
- rationLibObj.resultSpread.refresh();
- }
- SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, rationLibObj.resultSpread.getActiveSheet(), result);
- rationLibObj.setTagForHint(rationLibObj.resultSpread.getActiveSheet(), result);
- };
- CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibID, 'keyword': keyword}, function (result) {
- //sort
- result.sort(function (a, b) {
- let rst = 0;
- if(a.code > b.code) rst = 1;
- else if(a.code < b.code) rst = -1;
- return rst;
- });
- var resultObj = $('#rationSearchResult');
- /*resultObj.empty();
- resultObj.append(getResultHtml(result));*/
- $('#rationSearchCount').text(`搜索结果:${result.length.toString()}`);
- $('a', result).unbind('click');
- $('a', resultObj).bind('click', function () {
- resultObj.hide();
- $(".main-data-side-search", resultObj).height(0);
- autoFlashHeight();
- rationLibObj.refreshSpread();
- });
- resultObj.show();
- $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
- showResult(result);
- });
- });
|