12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409 |
- 'use strict';
- /**
- *
- *
- * @author Zhong
- * @date 2018/6/11
- * @version
- */
- //清单指引/精灵获取完清单数据后的回调函数
- let doAfterLoadGuidance = null;
- //选项单选多选状态(按住alt为多选) 单选:0 多选:1
- let billsGuidanceSelMode = 0;
- const billsGuidance = (function () {
- let currentLib = null;
- //库类型
- const libType = {'guidance': 1, 'elf': 2}; //清单指引、清单精灵
- const libTypeText = {1: '清单指引', 2: '清单精灵'};
- const libSel = $('#stdBillsGuidanceLibSelect');
- //工作内容
- let stdBillsJobData = [];
- //项目特征
- let stdBillsFeatureData = [];
- const bills = {
- dom: $('#billsGuidance_bills'),
- workBook: null,
- cache: [],
- tree: null,
- controller: null,
- treeSetting: {
- emptyRowHeader: true,
- rowHeaderWidth: 15,
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- cols: [{
- width: 140,
- 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: 190,
- readOnly: true,
- head: {
- titleNames: ["项目名称"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "name",
- vAlign: 1,
- hAlign: 0,
- font: "Arial"
- }
- },
- {
- width: 45,
- readOnly: true,
- head: {
- titleNames: ["计量单位"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "unit",
- vAlign: 1,
- hAlign: 1,
- font: "Arial"
- }
- }
- ]
- },
- headers: [
- {name: '项目编码', dataCode: 'code', width: 140, vAlign: 'center', hAlign: 'left', formatter: '@'},
- {name: '项目名称', dataCode: 'name', width: 190, vAlign: 'center', hAlign: 'left', formatter: '@'},
- {name: '单位', dataCode: 'unit', width: 45, vAlign: 'center', hAlign: 'center', formatter: '@'},
- ],
- rowHeaderWidth:25,
- events: {
- SelectionChanging: function (sender, info) {
- billsInitSel(info.newSelections[0].row);
- },
- CellDoubleClick: function (sender, args) {
- if(!bills.tree){
- return;
- }
- let node = bills.tree.items[args.row];
- if(!node){
- return;
- }
- if(node.children.length === 0){
- billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, node);
- }
- else {
- node.setExpanded(!node.expanded);
- //设置展开收起状态
- sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
- renderSheetFunc(args.sheet, function () {
- let iCount = node.posterityCount(), i, child;
- for (i = 0; i < iCount; i++) {
- child = bills.tree.items[args.row + i + 1];
- args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
- }
- args.sheet.invalidateLayout();
- });
- args.sheet.repaint();
- }
- }
- }
- };
- //项目指引类型
- const itemType = {
- job: 0,
- ration: 1
- };
- const guideItem = {
- dom: $('#billsGuidance_items'),
- workBook: null,
- tree: null,
- controller: null,
- treeSetting: {
- treeCol: 1,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- cols: [
- {
- width: 35,
- readOnly: false,
- head: {
- titleNames: ["选择"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "select",
- vAlign: 1,
- hAlign: 1,
- font: "Arial"
- }
- },
- {
- width: 420,
- readOnly: false,
- head: {
- titleNames: ["项目指引"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "name",
- vAlign: 1,
- hAlign: 0,
- font: "Arial"
- }
- }
- ]
- },
- headers: [
- {name: '选择', dataCode: 'select', width: 35, vAlign: 'center', hAlign: 'center', formatter: '@'},
- {name: '项目指引', dataCode: 'name', width: 300, vAlign: 'center', hAlign: 'left', formatter: '@'},
- ],
- rowHeaderWidth:25,
- events: {
- EditStarting: function (sender, args) {
- if(!bills.tree || guideItem.headers[args.col]['dataCode'] === 'name'){
- args.cancel = true;
- }
- },
- ButtonClicked: function (sender, args) {
- if(args.sheet.isEditing()){
- args.sheet.endEdit(true);
- }
- refreshInsertRation();
- },
- CellDoubleClick: function (sender, args) {
- if(!bills.tree || !bills.tree.selected){
- return;
- }
- let node = bills.tree.selected.guidance.tree.selected;
- if(!node){
- return;
- }
- if(node.children.length === 0){
- if(guideItem.headers[args.col]['dataCode'] === 'name'){
- insertRations(getInsertRationData([args.row]));
- }
- }
- else {
- node.setExpanded(!node.expanded);
- renderSheetFunc(args.sheet, function () {
- let iCount = node.posterityCount(), i, child;
- for (i = 0; i < iCount; i++) {
- child = bills.tree.selected.guidance.tree.items[args.row + i + 1];
- args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
- }
- args.sheet.invalidateLayout();
- });
- args.sheet.repaint();
- }
- }
- }
- };
- const elfItem = {
- dom: $('#billsGuidance_items'),
- workBook: null,
- tree: null,
- controller: null,
- treeSetting: {
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- cols: [
- {
- width: 250,
- readOnly: true,
- head: {
- titleNames: ["施工工序"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "name",
- vAlign: 1,
- hAlign: 0,
- font: "Arial"
- }
- },
- {
- width: 250,
- readOnly: false,
- head: {
- titleNames: ["选项"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "options",
- vAlign: 1,
- hAlign: 0,
- font: "Arial"
- }
- }
- ]
- },
- headers: [
- {name: '施工工序', dataCode: 'name', width: 250, rateWidth: 0.5, vAlign: 'center', hAlign: 'center', formatter: '@'},
- {name: '选项', dataCode: 'options', width: 250, rateWidth: 0.5, vAlign: 'center', hAlign: 'left', formatter: '@'},
- ],
- rowHeaderWidth:25,
- events: {
- CellClick: function (sender, args) {
- if(elfItem.headers[args.col]['dataCode'] === 'options' && args.sheetArea === 3){
- if(!args.sheet.getCell(args.row, args.col).locked() && !args.sheet.isEditing()){
- args.sheet.startEdit();
- }
- }
- },
- ClipboardPasting: function (sender, info) {
- info.cancel = true;
- }
- }
- };
- const options = {
- workBook: {
- tabStripVisible: false,
- allowContextMenu: false,
- allowCopyPasteExcelStyle : false,
- allowExtendPasteRange: false,
- allowUserDragDrop : false,
- allowUserDragFill: false,
- scrollbarMaxAlign : true
- },
- sheet: {
- protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
- clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
- }
- };
- //渲染时方法,停止渲染
- //@param {Object}sheet {Function}func @return {void}
- function renderSheetFunc(sheet, func){
- sheet.suspendEvent();
- sheet.suspendPaint();
- if(func){
- func();
- }
- sheet.resumeEvent();
- sheet.resumePaint();
- }
- //设置表选项
- //@param {Object}workBook {Object}opts @return {void}
- function setOptions (workBook, opts) {
- for(let opt in opts.workBook){
- workBook.options[opt] = opts.workBook[opt];
- }
- for(let opt in opts.sheet){
- workBook.getActiveSheet().options[opt] = opts.sheet[opt];
- }
- }
- //建表头
- //@param {Object}sheet {Array}headers @return {void}
- function buildHeader(sheet, headers) {
- let fuc = function () {
- sheet.setColumnCount(headers.length);
- sheet.setRowHeight(0, 30, GC.Spread.Sheets.SheetArea.colHeader);
- sheet.setColumnWidth(0, sheet.getParent() === bills.workBook ? 15 : 25, GC.Spread.Sheets.SheetArea.rowHeader);
- if(sheet.getParent() === elfItem.workBook || sheet.getParent() === guideItem.workBook){
- sheet.setRowHeight(0, 25, GC.Spread.Sheets.SheetArea.colHeader);
- }
- for(let i = 0, len = headers.length; i < len; i++){
- sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
- sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
- if(headers[i].formatter){
- sheet.setFormatter(-1, i, headers[i].formatter);
- }
- sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
- sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
- }
- };
- renderSheetFunc(sheet, fuc);
- }
- //表监听事件
- //@param {Object}workBook @return {void}
- function bindEvent(workBook, events) {
- if(Object.keys(events).length === 0){
- return;
- }
- const Events = GC.Spread.Sheets.Events;
- for(let event in events){
- workBook.bind(Events[event], events[event]);
- }
- }
- //根据宽度比例设置列宽
- //@param {Object}workBook {Number}workBookWidth {Array}headers @return {void}
- function setColumnWidthByRate(workBook, workBookWidth, headers) {
- if(workBook){
- const sheet = workBook.getActiveSheet();
- sheet.suspendEvent();
- sheet.suspendPaint();
- for(let col = 0; col < headers.length; col++){
- if(headers[col]['rateWidth'] !== undefined && headers[col]['rateWidth'] !== null && headers[col]['rateWidth'] !== ''){
- let width = workBookWidth * headers[col]['rateWidth'];
- if(headers[col]['dataCode'] === 'options'){
- width = width - 70;
- }
- sheet.setColumnWidth(col, width, GC.Spread.Sheets.SheetArea.colHeader)
- }
- else {
- if(headers[col]['headerWidth'] !== undefined && headers[col]['headerWidth'] !== null && headers[col]['headerWidth'] !== ''){
- sheet.setColumnWidth(col, headers[col]['headerWidth'], GC.Spread.Sheets.SheetArea.colHeader)
- }
- }
- }
- sheet.resumeEvent();
- sheet.resumePaint();
- }
- }
- //建表
- //@param {Object}module @return {void}
- function buildSheet(module) {
- if(!module.workBook){
- module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
- sheetCommonObj.spreadDefaultStyle(module.workBook);
- let sheet = module.workBook.getActiveSheet();
- if(module === bills){
- //默认初始可控制焦点在清单表中
- module.workBook.focus();
- sheet.options.isProtected = true;
- sheet.name('stdBillsGuidance_bills');
- //设置悬浮提示
- TREE_SHEET_HELPER.initSetting(bills.dom[0], bills.treeSetting);
- }
- if(module === guideItem){
- sheet.options.isProtected = true;
- sheet.getRange(-1, 0, -1, 1).locked(false);
- sheet.getRange(-1, 1, -1, 1).locked(true);
- }
- if(module === elfItem){
- sheet.options.isProtected = true;
- sheet.getRange(-1, 0, -1, 1).locked(true);
- sheet.getRange(-1, 1, -1, 1).locked(false);
- }
- if(module.rowHeaderWidth) sheet.setColumnWidth(0, module.rowHeaderWidth, GC.Spread.Sheets.SheetArea.rowHeader);
- setOptions(module.workBook, options);
- buildHeader(module.workBook.getActiveSheet(), module.headers);
- if(module === elfItem){
- setColumnWidthByRate(elfItem.workBook, $('#zy').width(), elfItem.headers)
- }
- bindEvent(module.workBook, module.events);
- }
- }
- //清空表数据
- //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
- function cleanData(sheet, headers, rowCount){
- renderSheetFunc(sheet, function () {
- sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
- if (rowCount > 0) {
- sheet.setRowCount(rowCount);
- }
- });
- }
- //初始化各工作表
- //@param {Array}modules @return {void}
- function initWorkBooks(modules){
- for(let module of modules){
- buildSheet(module);
- }
- }
- //初始化并输出树
- //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
- function initTree(module, sheet, treeSetting, datas){
- module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
- module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting, false);
- module.tree.loadDatas(datas);
- if(module === bills){
- initExpandStat();
- }
- module.controller.showTreeData();
- if(module === bills){
- setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
- }
- }
- //项目指引表焦点控制
- //@param {Number}row @return {void}
- function guideItemInitSel(row){
- let billsNode = bills.tree.selected;
- let node = null;
- if(billsNode && billsNode.guidance.tree){
- node = billsNode.guidance.tree.items[row];
- if(node){
- billsNode.guidance.tree.selected = node;
- }
- }
- }
- //清单精灵表焦点控制
- //@param {Number}row @return {void}
- function elfItemInitSel(row){
- let billsNode = bills.tree.selected;
- let node = null;
- if(billsNode && billsNode.elf.tree){
- node = billsNode.elf.tree.items[row];
- if(node){
- billsNode.elf.tree.selected = node;
- }
- }
- }
- //根据项目指引的类型设置单元格类型,定额类型的项目指引为复选框
- //@param {Array}nodes @return {void}
- function setItemCellType(nodes){
- //设置单元格类型
- const base = new GC.Spread.Sheets.CellTypes.Base();
- const checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
- const sheet = guideItem.workBook.getActiveSheet();
- renderSheetFunc(sheet, function(){
- for(let node of nodes){
- sheet.setCellType(node.serialNo(), 0, node.data.type === itemType.ration ? checkBox : base);
- }
- });
- }
- //清单表焦点控制
- //@param {Number}row @return {void}
- function billsInitSel(row){
- if(currentLib.type && currentLib.type === libType.elf){
- billsSelElf(row);
- }else {
- billsSelGuidance(row);
- }
- }
- //清单焦点变换-清单指引操作
- //@param {Number}row @return {void}
- function billsSelGuidance(row){
- let guideSheet = guideItem.workBook.getActiveSheet();
- cleanData(guideSheet, guideItem.headers, -1);
- if(!bills.tree){
- return;
- }
- let node = bills.tree.items[row];
- if(!node){
- return;
- }
- bills.tree.selected = node;
- refreshInsertRation();
- if(!node.guidance.tree){
- CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
- initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
- setItemCellType(node.guidance.tree.items);
- //项目指引初始焦点
- guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
- });
- }
- else{
- node.guidance.controller.showTreeData();
- setItemCellType(node.guidance.tree.items);
- //项目指引初始焦点
- guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
- }
- }
- //清单焦点变换-清单精灵操作
- //@param {Number}row @return {void}
- function billsSelElf(row) {
- let elfSheet = elfItem.workBook.getActiveSheet();
- cleanData(elfSheet, elfItem.headers, -1);
- if(!bills.tree){
- return;
- }
- let node = bills.tree.items[row];
- if(!node){
- return;
- }
- bills.tree.selected = node;
- if(!node.elf.tree){
- CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
- //定额数据删除编号信息
- for(let rData of rstData){
- if(rData.type === itemType.ration){
- let nameArr = rData.name.split(' ');
- if(nameArr.length > 0){
- nameArr.splice(0, 1);
- rData.name = nameArr.join(' ');
- }
- }
- }
- node.elf.datas = rstData;
- //第一层节点数据
- let firstLevelDatas = _.filter(rstData, function (data) {
- return data.ParentID == -1;
- });
- //第一层初始数据的选项显示
- for(let fData of firstLevelDatas){
- let options = getOptions(fData, rstData);
- fData.options = options.length > 0 ? options[0].name : '';
- //下挂的选项
- fData.optionsData = options && options.length > 0 ? _.cloneDeep(options) : [];
- fData.optionChecked = options && options.length > 0 ? [_.cloneDeep(options[0])] : [];
- }
- renderSheetFunc(elfSheet, function () {
- initTree(node.elf, elfSheet, elfItem.treeSetting, firstLevelDatas);
- //初始选择选项
- let initOptsOpr = [];
- for(let elfNode of node.elf.tree.items){
- if(elfNode.data.optionsData.length > 0){
- initOptsOpr.push({node: elfNode, data: elfNode.data.optionsData[0]});
- }
- }
- for(let opr of initOptsOpr){
- insertNodeByData(opr.node, opr.data);
- }
- TREE_SHEET_HELPER.refreshTreeNodeData(elfItem.treeSetting, elfSheet, node.elf.tree.items, false);
- setOptionsCellType(node.elf.tree.items);
- //项目指引初始焦点
- elfItemInitSel(elfSheet.getActiveRowIndex() ? elfSheet.getActiveRowIndex() : 0);
- refreshInsertRation();
- });
- });
- }
- else{
- renderSheetFunc(elfSheet, function () {
- node.elf.controller.showTreeData();
- setOptionsCellType(node.elf.tree.items);
- //项目指引初始焦点
- elfItemInitSel(elfSheet.getActiveRowIndex() ? elfSheet.getActiveRowIndex() : 0);
- refreshInsertRation();
- });
- }
- }
- //获取选项的深度
- //@param {Object}opt {Array}options(当前清单所有选项) @return {Array}
- function getOptionDepth(opt, options) {
- let parent = _.find(options, {ID: opt.ParentID});
- let depth = 0;
- while (parent){
- depth++;
- parent = _.find(options, {ID: parent.ParentID});
- }
- return depth;
- }
- //获取施工工序含有的选项(即当前施工工序的子项),获取的顺序按照NextSiblingID排序
- //@param {Object}process {Array}datas @return {Array}
- function getOptions(process, datas) {
- let rst = [];
- if(!process || !process.ID){
- return [];
- }
- let options = _.filter(datas, function (data) {
- return data.ParentID == process.ID;
- });
- if(options.length === 0){
- return [];
- }
- //根据NextSiblingID排序
- let IDMapping = {};
- for(let opt of options){
- IDMapping[opt.ID] = {self: opt, next: null, pre: null};
- }
- for(let opt of options){
- let next = IDMapping[opt.NextSiblingID] ? IDMapping[opt.NextSiblingID] : null;
- if(next){
- next.pre = IDMapping[opt.ID];
- IDMapping[opt.ID]['next'] = next;
- }
- }
- let first = null,
- rank = 0;
- for(let ID in IDMapping){
- let obj = IDMapping[ID];
- if(!obj.pre){
- first = obj;
- }
- }
- while(first){
- rank++;
- first.self.rank = rank;
- rst.push(first.self);
- first = first.next;
- }
- return rst;
- }
- //设置清单精灵选项单元格
- //@param {Array}nodes @return {void}
- function setOptionsCellType(nodes) {
- let elfSheet = elfItem.workBook.getActiveSheet();
- for(let node of nodes){
- if(node.data.optionsData && node.data.optionsData.length > 0){
- elfSheet.getCell(node.serialNo(), 1).locked(false).cellType(getOptionsCellType());
- }
- else {
- elfSheet.getCell(node.serialNo(), 1).locked(true).cellType(new GC.Spread.Sheets.CellTypes.Base());
- }
- }
- }
- //递归插入节点:原始项目指引数据奇数层为需要插入的节点,偶数层为下拉选项
- //@param {Object}node(当前操作的节点) {Object}data(选项) @return {void}
- function insertNodeByData(node, data) {
- let elfSheet = elfItem.workBook.getActiveSheet();
- let sameDepthNodes = node.children;
- let insertNextSiblingID = -1,
- insertParentID = node.data.ID;
- //当前操作节点的选项
- let nodeOpts = getOptions(node.data, bills.tree.selected.elf.datas);
- let subOpts = getOptions(data, bills.tree.selected.elf.datas);
- let dataDepth = getOptionDepth(data, bills.tree.selected.elf.datas);
- if(subOpts.length >0 && subOpts[0].type !== itemType.ration){
- if((dataDepth + 1) % 2 === 0){
- //排序后的数据
- let dataWithRank = _.find(nodeOpts, {ID: data.ID});
- //确定插入位置
- for(let subOpt of subOpts){
- for(let subNode of sameDepthNodes){
- //同层节点原本选项数据
- let subNodeOptData = _.find(bills.tree.selected.elf.datas, {ID: subNode.data.ID});
- //同层节点原本父选项数据
- let subNodeOptParent = _.find(bills.tree.selected.elf.datas, {ID: subNodeOptData.ParentID});
- let subNodeOptParentWithRank = _.find(nodeOpts, {ID: subNodeOptParent.ID});
- //父项顺序决定插入位置
- if(dataWithRank.rank < subNodeOptParentWithRank.rank){
- insertNextSiblingID = subNode.data.ID;
- break;
- }
- //父项顺序相同,根据子项顺序决定插入位置
- else if(dataWithRank.rank = subNodeOptParentWithRank.rank){
- if(subOpt.rank < subNode.data.rank){
- insertNextSiblingID = subNode.data.ID;
- break;
- }
- }
- }
- let sub2Opts = getOptions(subOpt, bills.tree.selected.elf.datas);
- subOpt.options = sub2Opts.length > 0 ? sub2Opts[0].name : '';
- let cloneOpt = _.cloneDeep(subOpt);//不改变原本的数据,比如ParentID
- cloneOpt.optionChecked = sub2Opts.length > 0 ? [_.cloneDeep(sub2Opts[0])] : [];
- cloneOpt.optionsData = sub2Opts.length > 0 ? _.cloneDeep(sub2Opts) : [];
- let newNode = node.tree.insertByData(cloneOpt, insertParentID, insertNextSiblingID);
- elfSheet.addRows(newNode.serialNo(), 1);
- node.tree.selected = newNode;
- elfSheet.setSelection(newNode.serialNo(), elfSheet.getSelections()[0].col, 1, 1);
- if(sub2Opts.length > 0 && sub2Opts[0].type !== itemType.ration){
- insertNodeByData(newNode, sub2Opts[0]);
- }
- }
- }
- else {
- insertNodeByData(node, subOpts[0]);
- }
- }
- }
- //获取选项下拉多选单元格
- //@param {void} @return {void}
- function getOptionsCellType() {
- let me = this;
- let elfSheet= elfItem.workBook.getActiveSheet();
- function OptionsCellType() {
- this.isEscKey=false;
- this.displayText='';
- }
- /* function getHtml(node, cellRect, cellStyle, top) {
- if(!node){
- return '';
- }
- let height = cellRect.height;
- top = top.replace('px', '');
- let htmlArr = [];
- let options = getOptions(node.data, bills.tree.selected.elf.datas);
- //let optionsTitle = node.data.options.split(';').join('\n');
- htmlArr.push(`<div style="height: ${height}px; background: ${cellStyle.backColor};overflow: hidden; white-space: nowrap; text-overflow: ellipsis">${node.data.options}</div><div id="optDiv" style="position: fixed; width: ${cellRect.width}px; top: ${top - (options.length - 2) * height - 5}px;background: ${cellStyle.backColor};border: 1px solid; overflow: auto; height: ${options.length > 6 ? height*6 : height*options.length+5}px; font-size: 0.9rem;">`);
- for(let opt of options){
- htmlArr.push(`<div title="${opt.name ? opt.name : ''}" class="elf-options" style="height: ${height}px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis">
- <input rank="${opt.rank}" value="${opt.ID}" style="margin-left: 5px; vertical-align: middle" type="checkbox"
- ${node.data.optionChecked && _.find(node.data.optionChecked, {ID: opt.ID}) ? 'checked' : ''}> ${opt.name ? opt.name : ''}</div>`);
- }
- htmlArr.push(`</div>`);
- return htmlArr.join('');
- }*/
- function setOptionsDiv($editor, node, cellRect, cellStyle, top) {
- if(!node){
- return '';
- }
- let height = cellRect.height;
- top = top.replace('px', '');
- let options = getOptions(node.data, bills.tree.selected.elf.datas);
- let $editInput = $(`<div style="height: ${height}px; background: ${cellStyle.backColor};overflow: hidden; white-space: nowrap; text-overflow: ellipsis">${node.data.options}</div>`),
- $optDiv = $(`<div style="position: fixed; width: ${cellRect.width}px; top: ${top - (options.length - 2) * height - 5}px;background: ${cellStyle.backColor};border: 1px solid; overflow: auto; height: ${options.length > 6 ? height*6 : height*options.length+5}px; font-size: 0.9rem;"></div>`);
- for(let opt of options){
- let $opt = $(`<div title="${opt.name ? opt.name : ''}" class="elf-options" style="height: ${height}px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis"></div>`),
- $optInput = $(`<input rank="${opt.rank}" value="${opt.ID}" style="margin-left: 5px; vertical-align: middle" type="checkbox"
- ${node.data.optionChecked && _.find(node.data.optionChecked, {ID: opt.ID}) ? 'checked' : ''}>`);
- $opt.text(`${opt.name ? opt.name : ''}`);
- $opt.prepend($optInput);
- $optDiv.append($opt);
- //选项复选框点击监听
- $optInput.click(function () {
- //单选
- if(billsGuidanceSelMode === 0){
- let $allInput = $optDiv.find('input');
- for(let input of $allInput){
- $(input).prop('checked', false);
- }
- $(this).prop('checked', 'checked');
- } else {//多选
- }
- });
- }
- $editor.append($editInput);
- $editor.append($optDiv);
- }
- //选择后处理
- function doAfterSel(node) {
- let checkedSels = $('.elf-options').find('input:checked');
- let checkedNameArr = [],
- optionChecked= [];
- for(let checkSel of checkedSels){
- let opt = _.cloneDeep(_.find(bills.tree.selected.elf.datas, {ID: $(checkSel).val()}));
- opt.rank = $(checkSel).attr('rank');
- checkedNameArr.push(opt.name);
- optionChecked.push(opt);
- }
- this.displayText = checkedNameArr.length > 0 ? checkedNameArr.join(';') : '';
- node.data.options = this.displayText;
- node.data.optionChecked = optionChecked;
- //删除节点
- let deleteNodes = getDeleteNodes(node, optionChecked);
- for(let dNode of deleteNodes){
- elfSheet.deleteRows(dNode.serialNo(), dNode.posterityCount() + 1);
- node.tree.delete(dNode);
- }
- //插入节点
- for(let perCheked of optionChecked){
- let exist = false;
- let subOpts = getOptions(perCheked, bills.tree.selected.elf.datas);
- for(let subNode of node.children){
- for(let subOpt of subOpts){
- if(subNode.data.ID === subOpt.ID){
- exist = true;
- break;
- }
- }
- }
- //不重复且不为定额时插入
- if(!exist && perCheked.type !== itemType.ration){
- insertNodeByData(node, perCheked);//这里递归,默认第一个
- }
- }
- TREE_SHEET_HELPER.refreshTreeNodeData(elfItem.treeSetting, elfSheet, node.tree.items, false);
- setOptionsCellType(node.tree.items);
- refreshInsertRation();
- }
- //获取删除节点
- function getDeleteNodes(node, optionChecked) {
- let rst = [];
- for(let subNode of node.children){
- let exist = false;
- for(let perChecked of optionChecked){
- let subOpts = getOptions(perChecked, bills.tree.selected.elf.datas);
- for(let subOpt of subOpts){
- if(subNode.data.ID === subOpt.ID){
- exist = true;
- break;
- }
- }
- }
- if(!exist){
- rst.push(subNode);
- }
- }
- return rst;
- }
- OptionsCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
- OptionsCellType.prototype.createEditorElement = function (context) {
- let element = document.createElement("div");//这里创建的,会自动销毁
- return element
- };
- OptionsCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
- if (editorContext) {
- let $editor = $(editorContext);
- $editor.css("position", "fixed");
- $editor.css("background", "white");
- $editor.css("width", cellRect.width);
- $editor.attr("gcUIElement", "gcEditingInput");
- let activeCellTop = $editor.parent().parent().css('top');
- let node = bills.tree.selected.elf.tree.items[elfSheet.getActiveRowIndex()];
- setOptionsDiv($editor, node, cellRect, cellStyle, activeCellTop);
- this.isEscKey = false;
- }
- }
- OptionsCellType.prototype.deactivateEditor = function (editorContext, context) {
- };
- OptionsCellType.prototype.setEditorValue = function (editor, value, context) {
- this.displayText = value;
- };
- OptionsCellType.prototype.getEditorValue = function (editor, context) {
- let me = this;
- let node = bills.tree.selected.elf.tree.items[elfSheet.getActiveRowIndex()];
- if(this.isEscKey !=true){
- renderSheetFunc(elfSheet, function () {
- doAfterSel.call(me, node);
- });
- }
- this.isEscKey = false;
- return this.displayText;
- };
- OptionsCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
- };
- OptionsCellType.prototype.isReservedKey = function (e, context) {
- //cell type handle tab key by itself
- this.isEscKey = e.keyCode === GC.Spread.Commands.Key.esc;
- return false;
- };
- /* OptionsCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- if(style.backColor){
- ctx.fillStyle = style.backColor;
- ctx.fillRect(x, y, w, h);
- ctx.save();
- }
- //边长
- const l = 7;
- let leftPointX = x + w - 15,
- rightPointX = leftPointX + l,
- middlePointX = (leftPointX + rightPointX)/2;
- const cos30 = Math.cos(2*Math.PI * 30 / 360);
- let hL = l * cos30;
- let beginY = y + h/2 - hL;
- ctx.beginPath();
- ctx.moveTo(leftPointX, beginY);
- ctx.lineTo(rightPointX, beginY);
- ctx.lineTo(middlePointX, beginY + hL);
- ctx.fillStyle = 'black';
- ctx.fill();
- ctx.save();
- };*/
- // override getHitInfo to allow cell type get mouse messages
- OptionsCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
- return {
- x: x,
- y: y,
- row: context.row,
- col: context.col,
- cellStyle: cellStyle,
- cellRect: cellRect,
- sheetArea: context.sheetArea
- };
- };
- return new OptionsCellType();
- }
- //初始化清单的工作内容和项目特征
- //@param {Number}billsLibId {Function}callback @return {void}
- function initJobAndCharacter(billsLibId, callback){
- CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: billsLibId}, function (datas) {
- stdBillsJobData = datas;
- CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: billsLibId}, function (datas) {
- stdBillsFeatureData = datas;
- if(callback){
- callback();
- }
- });
- });
- }
- //初始化清单展开收起状态
- //@return {void}
- function initExpandStat(){
- //读取展开收起状态
- let currentExpState = sessionStorage.getItem('stdBillsGuidanceExpState');
- if(currentExpState){
- bills.tree.setExpandedByState(bills.tree.items, currentExpState);
- }
- //非叶子节点默认收起
- else{
- bills.tree.setRootExpanded(bills.tree.roots, false);
- }
- }
- //设置tag以悬浮提示
- function setTagForHint(nodes){
- let sheet = bills.workBook.getActiveSheet();
- renderSheetFunc(sheet, function () {
- for(let node of nodes){
- sheet.setTag(node.serialNo(), 2, node.data.ruleText ? node.data.ruleText : '');
- }
- });
- }
- //根据编码定位至清单精灵库中
- //@param {String}code @return {void}
- function locateAtBills(code) {
- let nineCode = code.substring(0, 9);
- let items = bills.tree.items;
- let locateBills = _.find(items, function(item){
- return item.data.code === nineCode;
- });
- if(locateBills){
- expandSearchNodes([locateBills]);
- sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
- }
- let sheet = bills.workBook.getActiveSheet();
- let locateRow = locateBills ? locateBills.serialNo() : 0;
- sheet.setActiveCell(locateRow, 0);
- billsInitSel(locateRow);
- sheet.showRow(locateRow, GC.Spread.Sheets.VerticalPosition.center);
- }
- //清单设置悬浮提示信息
- //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
- function setBillsHint(billsNodes, jobs, items) {
- let jobsMapping = {},
- itemsMapping = {};
- for(let job of jobs){
- jobsMapping[job.id] = job;
- }
- for(let item of items){
- itemsMapping[item.id] = item;
- }
- let tagInfo = [];
- for(let billsNode of billsNodes){
- let hintArr = [];
- let billsItems = billsNode.data.items;
- if(billsItems.length > 0){
- //项目特征
- hintArr.push('项目特征:');
- }
- let itemCount = 1,
- jobCount = 1;
- for(let billsItem of billsItems){
- let itemData = itemsMapping[billsItem.id];
- if(itemData){
- //特征值
- let eigens = [];
- for(let eigen of itemData.itemValue){
- eigens.push(eigen.value);
- }
- eigens = eigens.join(';');
- hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
- itemCount ++;
- }
- }
- //工作内容
- let billsJobs = billsNode.data.jobs;
- if(billsJobs.length > 0){
- hintArr.push('工作内容:');
- }
- for(let billsJob of billsJobs){
- let jobData = jobsMapping[billsJob.id];
- if(jobData){
- hintArr.push(`${jobCount}.${jobData.content}`);
- jobCount ++;
- }
- }
- /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
- hintArr.push('工程量计算规则:');
- hintArr.push(billsNode.data.ruleText);
- }
- if(billsNode.data.recharge && billsNode.data.recharge !== ''){
- hintArr.push('补注:');
- hintArr.push(billsNode.data.recharge);
- }*/
- if(hintArr.length > 0){
- tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
- }
- }
- let sheet = bills.workBook.getActiveSheet();
- renderSheetFunc(sheet, function () {
- for(let tagI of tagInfo){
- sheet.setTag(tagI.row, 0, tagI.value);
- }
- });
- }
- //初始选择清单指引库
- //@param {Number}libID @return {void}
- function libInitSel(libID){
- //获取清单
- $.bootstrapLoading.start();
- CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function(rstData){
- currentLib = rstData.guidanceLib;
- if(guideItem.workBook){
- guideItem.workBook.destroy();
- guideItem.workBook = null;
- }
- if(elfItem.workBook){
- elfItem.workBook.destroy();
- elfItem.workBook = null;
- }
- initViews();
- let callback = function () {
- initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
- //清单精灵
- if(rstData.guidanceLib.type && rstData.guidanceLib.type == libType.elf){
- $('#stdBillsGuidanceTab').text('清单精灵');
- //每一个清单节点下挂载一棵清单精灵树
- for(let node of bills.tree.items){
- node.elf = {tree: null, controller: null, datas: []}; //挂载全部数据,数据不一定全成为树节点
- }
- }
- //清单指引
- else {
- $('#stdBillsGuidanceTab').text('清单指引');
- //每一棵项目指引树挂在清单节点上
- for(let node of bills.tree.items){
- node.guidance = {tree: null, controller: null};
- }
- }
- //setTagForHint(bills.tree.items);
- //默认初始节点
- billsInitSel(0);
- if(doAfterLoadGuidance){
- doAfterLoadGuidance();
- }
- $.bootstrapLoading.end();
- };
- //获取清单库中的工作内容和项目特征
- initJobAndCharacter(rstData.guidanceLib.billsLibId, callback);
- }, function () {
- $.bootstrapLoading.end();
- });
- }
- //初始化清单指引库
- //@param {Array}libDats @return {void}
- function initLibs(libDatas){
- libSel.empty();
- if(!libDatas){
- return;
- }
- let selectedLib = sessionStorage.getItem('stdBillsGuidance');
- for(let libData of libDatas){
- let opt = $('<option>').val(libData.id).text(libData.name);
- if(selectedLib && libData.id == selectedLib){
- opt.attr('selected', 'selected');
- }
- libSel.append(opt);
- }
- //初始默认选择
- libInitSel(libSel.select().val());
- }
- //初始化视图
- //@param {void} @return {void}
- function initViews(){
- //赋初始高度
- if($('#billsGuidance_bills').height() === 0 || $('#billsGuidance_items').height() === 0){
- let height = $(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-z").height();
- $('#billsGuidance_bills').height(height / 2);
- $('#billsGuidance_items').height(height / 2);
- }
- let modules = [bills];
- if(currentLib.type && currentLib.type === libType.elf){
- modules.push(elfItem);
- }
- else {
- modules.push(guideItem);
- }
- initWorkBooks(modules);
- }
- //获取选中的行
- //@return {Array}
- function getCheckedRows(){
- let rst = [];
- let itemSheet = guideItem.workBook.getActiveSheet();
- for(let row = 0; row < itemSheet.getRowCount(); row++){
- let rowV = itemSheet.getValue(row, 0);
- if(rowV){
- rst.push(row);
- }
- }
- return rst;
- }
- //获取清单精灵生成的定额数据
- //@return {Array}
- function getInsertElfRationData(){
- let rst = [];
- if(!bills.tree.selected){
- return [];
- }
- if(!bills.tree.selected.elf){
- return [];
- }
- let tree = bills.tree.selected.elf.tree;
- if(!tree){
- return [];
- }
- for(let node of tree.items){
- for(let perChecked of node.data.optionChecked){
- //选项直接是定额
- if(perChecked.type === itemType.ration){
- rst.push({itemQuery: {userID: userID, ID: perChecked.rationID}, rationType: rationType.ration});
- }
- //选项下子选项是定额
- else {
- let rationOpts = getOptions(perChecked, bills.tree.selected.elf.datas);
- for(let ration of rationOpts){
- if(ration.type === itemType.ration){
- rst.push({itemQuery: {userID: userID, ID: ration.rationID}, rationType: rationType.ration});
- }
- }
- }
- }
- }
- return rst;
- }
- //获取选中的定额数据
- //@param {Array}rows @return {Array}
- function getInsertRationData(rows){
- let rst = [];
- for(let row of rows){
- let node = bills.tree.selected.guidance.tree.items[row];
- if(node && node.data.type === itemType.ration){
- rst.push({itemQuery: {userID: userID, ID: node.data.rationID}, rationType: rationType.ration});
- }
- }
- return rst;
- }
- //插入定额
- //@return {void}
- function insertRations(addRationDatas){
- if(addRationDatas.length > 0){
- projectObj.project.Ration.addMultiRation(addRationDatas, function () {
- //恢复
- if(!currentLib.type || currentLib.type === libType.guidance){
- let sheet = guideItem.workBook.getActiveSheet();
- renderSheetFunc(sheet, function () {
- for(let row = 0; row < sheet.getRowCount(); row++){
- if(sheet.getValue(row, 0)){
- sheet.setValue(row, 0, false);
- }
- }
- });
- }
- refreshInsertRation();
- projectObj.setActiveCell('quantity', true);
- });
- }
- }
- //更新插入定额按钮有效性
- function refreshInsertRation(){
- if(currentLib.type && currentLib.type === libType.elf){
- if(getInsertElfRationData().length > 0){
- $('#guidanceInsertRation').removeClass('disabled');
- }
- else {
- $('#guidanceInsertRation').addClass('disabled');
- }
- }
- else {
- //勾选了定额,插入定额按钮才有效
- if(getCheckedRows().length > 0){
- $('#guidanceInsertRation').removeClass('disabled');
- }
- else {
- $('#guidanceInsertRation').addClass('disabled');
- }
- }
- }
- //展开至搜索出来点的节点
- //@param {Array}nodes @return {void}
- function expandSearchNodes(nodes){
- let that = this;
- let billsSheet = bills.workBook.getActiveSheet();
- renderSheetFunc(billsSheet, function () {
- function expParentNode(node){
- if(node.parent && !node.parent.expanded){
- node.parent.setExpanded(true);
- expParentNode(node.parent);
- }
- }
- for(let node of nodes){
- expParentNode(node);
- }
- TREE_SHEET_HELPER.refreshTreeNodeData(bills.treeSetting, billsSheet, bills.tree.roots, true);
- TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billsSheet, true);
- });
- }
- //各按钮监听事件
- //@return {void}
- function bindBtn(){
- //打开清单指引库
- $('#stdBillsGuidanceTab').click(function () {
- if(libSel.children().length === 0 && !projectReadOnly && !$(this).hasClass('disabled')){
- initLibs(projectInfoObj.projectInfo.engineeringInfo.billsGuidance_lib);
- }
- });
- //更改清单指引库
- $('#stdBillsGuidanceLibSelect').change(function () {
- //关闭搜索窗口
- $('#billsGuidanceSearchResult').hide();
- billsLibObj.clearHighLight(bills.workBook);
- libInitSel($(this).select().val());
- //记住选项
- sessionStorage.setItem('stdBillsGuidance', $(this).select().val());
- //清除展开收起状态sessionStorage
- sessionStorage.removeItem('stdBillsGuidanceExpState');
- });
- //插入定额
- $('#guidanceInsertRation').click(function () {
- let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
- insertRations(addRationDatas);
- });
- //插入清单
- $('#guidanceInsertBills').click(function () {
- //插入清单
- if(!bills.tree || !bills.tree.selected){
- return;
- }
- if(bills.tree.selected.children.length === 0){
- let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, bills.tree.selected);
- /*if(insert){
- //插入选中的定额
- let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
- insertRations(addRationDatas);
- }*/
- }
- });
- //插入清单和定额
- $('#guidanceInsertBillsAndRation').click(function () {
- //插入清单
- if(!bills.tree || !bills.tree.selected){
- return;
- }
- if(bills.tree.selected.children.length === 0){
- let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, bills.tree.selected);
- if(insert){
- //插入选中的定额
- let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
- insertRations(addRationDatas);
- }
- }
- });
- //搜索
- $('#stdBillsGuidanceSearch>div>button').click(function () {
- if(!bills.tree){
- return;
- }
- let billsSheet = bills.workBook.getActiveSheet();
- billsLibObj.clearHighLight(bills.workBook);
- let keyword = $('#stdBillsGuidanceSearch>input').val();
- if (!keyword || keyword === '') {
- $('#billsGuidanceSearchResult').hide();
- return;
- }
- let result = bills.tree.items.filter(function (item) {
- let codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
- let nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
- return codeIs || nameIs;
- });
- result.sort(function (x, y) {
- return x.serialNo() - y.serialNo();
- });
- if (result.length !== 0) {
- //展开搜索出来的节点
- expandSearchNodes(result);
- //设置记住展开
- sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
- let sel = billsSheet.getSelections();
- renderSheetFunc(billsSheet, function () {
- bills.controller.setTreeSelected(result[0]);
- billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
- billsInitSel(result[0].serialNo());
- for (let node of result) {
- billsSheet.getRange(node.serialNo(), -1, 1, -1).backColor('lemonChiffon');
- }
- });
- //搜索初始定位
- billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
- $('#nextBillsGuidance').show();
- $('#nextBillsGuidance').unbind('click');
- $('#nextBillsGuidance').bind('click', function () {
- let cur = bills.tree.selected, resultIndex = result.indexOf(cur), sel = billsSheet.getSelections();
- if (resultIndex === result.length - 1) {
- bills.controller.setTreeSelected(result[0]);
- billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
- billsInitSel(result[0].serialNo());
- billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
- } else {
- bills.controller.setTreeSelected(result[resultIndex + 1]);
- billsSheet.setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
- billsInitSel(result[resultIndex + 1].serialNo());
- billsSheet.showRow(result[resultIndex + 1].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
- }
- });
- } else {
- billsLibObj.clearHighLight(bills.workBook);
- $('#nextBillsGuidance').hide();
- }
- $('#billsGuidanceSearchResultCount').text('搜索结果:' + result.length);
- $('#billsGuidanceSearchResult').show();
- });
- //搜索框回车
- $('#stdBillsGuidanceSearch>input').bind('keypress', function (event) {
- if(event.keyCode === 13){
- $(this).blur();
- $('#stdBillsGuidanceSearch>div>button').click();
- }
- });
- // 关闭搜索结果
- $('#closeSearchBillsGuidance').click(function () {
- $('#billsGuidanceSearchResult').hide();
- billsLibObj.clearHighLight(bills.workBook);
- refreshWorkBook();
- });
- //监听alt建,确定选项单选多选状态
- $('#billsGuidance_items').keydown(function(e){
- if(e.keyCode === 18){
- billsGuidanceSelMode = 1;
- }
- });
- $('#billsGuidance_items').keyup(function(e){
- if(e.keyCode === 18){
- billsGuidanceSelMode = 0;
- }
- });
- }
- //刷新表
- //@return {void}
- function refreshWorkBook(){
- if(bills.workBook){
- bills.workBook.refresh();
- }
- if(guideItem.workBook){
- guideItem.workBook.refresh();
- }
- if(elfItem.workBook){
- elfItem.workBook.refresh();
- }
- }
- return {initViews, bindBtn, refreshWorkBook, refreshInsertRation, setColumnWidthByRate, locateAtBills, bills, elfItem};
- })();
- $(document).ready(function(){
- billsGuidance.bindBtn();
- });
|