123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- /**
- * Standard Ration Lib
- * Created by Mai on 2017/5/16.
- */
- /*var rationChapterSpread, sectionRationsSpread;*/
- var rationLibObj = {
- rationChapterSpread: null,
- sectionRationsSpread: null,
- rationChapterTreeController: null,
- refreshSettingForHint: function () {
- TREE_SHEET_HELPER.initSetting($('#stdSectionRations')[0], rationLibObj.sectionRationsSetting);
- },
- checkSpread: function () {
- if (!this.rationChapterSpread) {
- this.rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
- 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]);
- 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();
- }
- },
- 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 && data.id == selectedRationLib){
- option.attr('selected', 'selected');
- }
- select.append(option);
- });
- if (select[0].options.length !== 0) {
- rationLibObj.loadStdRation(select.val());
- }
- },
- loadStdRation: function (rationLibID) {
- var that = this;
- var showRationChapterTree = function (datas) {
- var rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
- 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 {
- //非叶子节点默认收起
- that.tree.setRootExpanded(that.tree.roots, false);
- }
- rationChapterTreeController.showTreeData();
- rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
- rationLibObj.loadSectionRations(node.getID());
- });
- if (rationChapterTree.firstNode()) {
- rationLibObj.loadSectionRations(rationChapterTree.firstNode().getID());
- } else {
- rationLibObj.loadSectionRations();
- };
- };
- CommonAjax.post('/complementaryRation/api/getRationTree', {userId: userID, rationRepId: rationLibID}, function (datas) {
- showRationChapterTree(datas);
- }, function () {
- showRationChapterTree([]);
- });
- },
- //双击隐藏显示
- 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 (datas) {
- let sheet = this.sectionRationsSpread.getActiveSheet();
- sheet.suspendPaint();
- sheet.suspendEvent();
- for(let i = 0, len = sheet.getRowCount(); i < len; i++){
- sheet.setTag(i, 1, '');
- }
- for(let i = 0, len = datas.length; i < len; i++){
- sheet.setTag(i, 1, datas[i].hint ? datas[i].hint : '');
- }
- sheet.resumePaint();
- sheet.resumeEvent();
- },
- loadSectionRations: function (sectionID) {
- var showDatas = function (datas, setting) {
- SheetDataHelper.loadSheetHeader(setting, rationLibObj.sectionRationsSpread.getActiveSheet());
- SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
- rationLibObj.setTagForHint(datas);
- };
- if (sectionID) {
- CommonAjax.post('/complementaryRation/api/getRationGljItemsBySection', {user_Id: userID, sectionId: sectionID}, function (datas) {
- showDatas(datas, rationLibObj.sectionRationsSetting);
- }, 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);
- }
- },
- 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);
- }
- }
- },
- "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}]);
- }
- }
- },
- }
- });
- },
- rationChapterTreeSetting: {
- "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,
- "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,
- "showHint": 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);
- }
- };
- 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 () {
- 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();
- }
- });
- $('#rationSearch').click(function () {
- var keyword = $('#rationSearchKeyword').val(), rationLibID = $('#stdRationLibSelect').val();
- 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('');
- };
- var showResult = function (result) {
- var resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
- SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
- SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet(), result);
- resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
- };
- 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'), resultSpread = null;
- resultObj.empty();
- resultObj.append(getResultHtml(result));
- $('a', resultObj).click(function () {
- resultObj.hide();
- $(".main-data-side-search", resultObj).height(0);
- autoFlashHeight();
- //$(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() - $(".tools-bar-height-d").height() - 202);
- rationLibObj.refreshSpread();
- });
- resultObj.show();
- $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
- showResult(result);
- });
- });
|