std_billsGuidance_lib.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/6/11
  7. * @version
  8. */
  9. const billsGuidance = (function () {
  10. const libSel = $('#stdBillsGuidanceLibSelect');
  11. //工作内容
  12. let stdBillsJobData = [];
  13. //项目特征
  14. let stdBillsFeatureData = [];
  15. const bills = {
  16. dom: $('#billsGuidance_bills'),
  17. workBook: null,
  18. cache: [],
  19. tree: null,
  20. controller: null,
  21. treeSetting: {
  22. treeCol: 0,
  23. emptyRows: 0,
  24. headRows: 1,
  25. headRowHeight: [40],
  26. defaultRowHeight: 21,
  27. cols: [{
  28. width: 160,
  29. readOnly: true,
  30. head: {
  31. titleNames: ["项目编码"],
  32. spanCols: [1],
  33. spanRows: [1],
  34. vAlign: [1],
  35. hAlign: [1],
  36. font: ["Arial"]
  37. },
  38. data: {
  39. field: "code",
  40. vAlign: 1,
  41. hAlign: 0,
  42. font: "Arial"
  43. }
  44. }, {
  45. width: 220,
  46. readOnly: true,
  47. head: {
  48. titleNames: ["项目名称"],
  49. spanCols: [1],
  50. spanRows: [1],
  51. vAlign: [1],
  52. hAlign: [1],
  53. font: ["Arial"]
  54. },
  55. data: {
  56. field: "name",
  57. vAlign: 1,
  58. hAlign: 0,
  59. font: "Arial"
  60. }
  61. },
  62. {
  63. width: 45,
  64. readOnly: true,
  65. showHint: true,
  66. head: {
  67. titleNames: ["计量单位"],
  68. spanCols: [1],
  69. spanRows: [1],
  70. vAlign: [1],
  71. hAlign: [1],
  72. font: ["Arial"]
  73. },
  74. data: {
  75. field: "unit",
  76. vAlign: 1,
  77. hAlign: 1,
  78. font: "Arial"
  79. }
  80. }
  81. ]
  82. },
  83. headers: [
  84. {name: '项目编码', dataCode: 'code', width: 160, vAlign: 'center', hAlign: 'left', formatter: '@'},
  85. {name: '项目名称', dataCode: 'name', width: 220, vAlign: 'center', hAlign: 'left', formatter: '@'},
  86. {name: '单位', dataCode: 'unit', width: 45, vAlign: 'center', hAlign: 'center', formatter: '@'},
  87. ],
  88. events: {
  89. SelectionChanging: function (sender, info) {
  90. billsInitSel(info.newSelections[0].row);
  91. },
  92. CellDoubleClick: function (sender, args) {
  93. if(!bills.tree){
  94. return;
  95. }
  96. let node = bills.tree.items[args.row];
  97. if(!node){
  98. return;
  99. }
  100. if(node.children.length === 0){
  101. //插入清单
  102. let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, node);
  103. if(insert){
  104. //插入选中的定额
  105. let addRationDatas = getInsertRationData(getCheckedRows());
  106. insertRations(addRationDatas);
  107. }
  108. }
  109. else {
  110. node.setExpanded(!node.expanded);
  111. //设置展开收起状态
  112. sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
  113. renderSheetFunc(args.sheet, function () {
  114. let iCount = node.posterityCount(), i, child;
  115. for (i = 0; i < iCount; i++) {
  116. child = bills.tree.items[args.row + i + 1];
  117. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  118. }
  119. args.sheet.invalidateLayout();
  120. });
  121. args.sheet.repaint();
  122. }
  123. }
  124. }
  125. };
  126. //项目指引类型
  127. const itemType = {
  128. job: 0,
  129. ration: 1
  130. };
  131. const guideItem = {
  132. dom: $('#billsGuidance_items'),
  133. workBook: null,
  134. tree: null,
  135. controller: null,
  136. treeSetting: {
  137. treeCol: 1,
  138. emptyRows: 0,
  139. headRows: 1,
  140. headRowHeight: [40],
  141. defaultRowHeight: 21,
  142. cols: [
  143. {
  144. width: 35,
  145. readOnly: false,
  146. head: {
  147. titleNames: ["选择"],
  148. spanCols: [1],
  149. spanRows: [1],
  150. vAlign: [1],
  151. hAlign: [1],
  152. font: ["Arial"]
  153. },
  154. data: {
  155. field: "select",
  156. vAlign: 1,
  157. hAlign: 1,
  158. font: "Arial"
  159. }
  160. },
  161. {
  162. width: 420,
  163. readOnly: false,
  164. head: {
  165. titleNames: ["项目指引"],
  166. spanCols: [1],
  167. spanRows: [1],
  168. vAlign: [1],
  169. hAlign: [1],
  170. font: ["Arial"]
  171. },
  172. data: {
  173. field: "name",
  174. vAlign: 1,
  175. hAlign: 0,
  176. font: "Arial"
  177. }
  178. }
  179. ]
  180. },
  181. headers: [
  182. {name: '选择', dataCode: 'select', width: 35, vAlign: 'center', hAlign: 'center', formatter: '@'},
  183. {name: '项目指引', dataCode: 'name', width: 300, vAlign: 'center', hAlign: 'left', formatter: '@'},
  184. ],
  185. events: {
  186. EditStarting: function (sender, args) {
  187. if(!bills.tree || guideItem.headers[args.col]['dataCode'] === 'name'){
  188. args.cancel = true;
  189. }
  190. },
  191. ButtonClicked: function (sender, args) {
  192. if(args.sheet.isEditing()){
  193. args.sheet.endEdit(true);
  194. }
  195. refreshInsertRation();
  196. },
  197. CellDoubleClick: function (sender, args) {
  198. if(!bills.tree || !bills.tree.selected){
  199. return;
  200. }
  201. let node = bills.tree.selected.guidance.tree.selected;
  202. if(!node){
  203. return;
  204. }
  205. if(node.children.length === 0){
  206. if(guideItem.headers[args.col]['dataCode'] === 'name'){
  207. insertRations(getInsertRationData([args.row]));
  208. }
  209. }
  210. else {
  211. node.setExpanded(!node.expanded);
  212. renderSheetFunc(args.sheet, function () {
  213. let iCount = node.posterityCount(), i, child;
  214. for (i = 0; i < iCount; i++) {
  215. child = bills.tree.selected.guidance.tree.items[args.row + i + 1];
  216. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  217. }
  218. args.sheet.invalidateLayout();
  219. });
  220. args.sheet.repaint();
  221. }
  222. }
  223. }
  224. };
  225. const options = {
  226. workBook: {
  227. tabStripVisible: false,
  228. allowContextMenu: false,
  229. allowCopyPasteExcelStyle : false,
  230. allowExtendPasteRange: false,
  231. allowUserDragDrop : false,
  232. allowUserDragFill: false,
  233. scrollbarMaxAlign : true
  234. },
  235. sheet: {
  236. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  237. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  238. }
  239. };
  240. //渲染时方法,停止渲染
  241. //@param {Object}sheet {Function}func @return {void}
  242. function renderSheetFunc(sheet, func){
  243. sheet.suspendEvent();
  244. sheet.suspendPaint();
  245. if(func){
  246. func();
  247. }
  248. sheet.resumeEvent();
  249. sheet.resumePaint();
  250. }
  251. //设置表选项
  252. //@param {Object}workBook {Object}opts @return {void}
  253. function setOptions (workBook, opts) {
  254. for(let opt in opts.workBook){
  255. workBook.options[opt] = opts.workBook[opt];
  256. }
  257. for(let opt in opts.sheet){
  258. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  259. }
  260. }
  261. //建表头
  262. //@param {Object}sheet {Array}headers @return {void}
  263. function buildHeader(sheet, headers) {
  264. let fuc = function () {
  265. sheet.setColumnCount(headers.length);
  266. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  267. for(let i = 0, len = headers.length; i < len; i++){
  268. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  269. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  270. if(headers[i].formatter){
  271. sheet.setFormatter(-1, i, headers[i].formatter);
  272. }
  273. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  274. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  275. }
  276. };
  277. renderSheetFunc(sheet, fuc);
  278. }
  279. //表监听事件
  280. //@param {Object}workBook @return {void}
  281. function bindEvent(workBook, events) {
  282. if(Object.keys(events).length === 0){
  283. return;
  284. }
  285. const Events = GC.Spread.Sheets.Events;
  286. for(let event in events){
  287. workBook.bind(Events[event], events[event]);
  288. }
  289. }
  290. //建表
  291. //@param {Object}module @return {void}
  292. function buildSheet(module) {
  293. if(!module.workBook){
  294. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  295. let sheet = module.workBook.getActiveSheet();
  296. if(module === bills){
  297. //默认初始可控制焦点在清单表中
  298. module.workBook.focus();
  299. sheet.options.isProtected = true;
  300. sheet.name('stdBillsGuidance_bills');
  301. //设置悬浮提示
  302. TREE_SHEET_HELPER.initSetting(bills.dom[0], bills.treeSetting);
  303. }
  304. if(module === guideItem){
  305. sheet.options.isProtected = true;
  306. sheet.getRange(-1, 0, -1, 1).locked(false);
  307. sheet.getRange(-1, 1, -1, 1).locked(true);
  308. }
  309. setOptions(module.workBook, options);
  310. buildHeader(module.workBook.getActiveSheet(), module.headers);
  311. bindEvent(module.workBook, module.events);
  312. }
  313. }
  314. //清空表数据
  315. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  316. function cleanData(sheet, headers, rowCount){
  317. renderSheetFunc(sheet, function () {
  318. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  319. if (rowCount > 0) {
  320. sheet.setRowCount(rowCount);
  321. }
  322. });
  323. }
  324. //初始化各工作表
  325. //@param {Array}modules @return {void}
  326. function initWorkBooks(modules){
  327. for(let module of modules){
  328. buildSheet(module);
  329. }
  330. }
  331. //初始化并输出树
  332. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  333. function initTree(module, sheet, treeSetting, datas){
  334. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  335. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  336. module.tree.loadDatas(datas);
  337. if(module === bills){
  338. initExpandStat();
  339. }
  340. module.controller.showTreeData();
  341. }
  342. //项目指引表焦点控制
  343. //@param {Number}row @return {void}
  344. function guideItemInitSel(row){
  345. let billsNode = bills.tree.selected;
  346. let node = null;
  347. if(billsNode && billsNode.guidance.tree){
  348. node = billsNode.guidance.tree.items[row];
  349. if(node){
  350. billsNode.guidance.tree.selected = node;
  351. }
  352. }
  353. }
  354. //根据项目指引的类型设置单元格类型,定额类型的项目指引为复选框
  355. //@param {Array}nodes @return {void}
  356. function setItemCellType(nodes){
  357. //设置单元格类型
  358. const base = new GC.Spread.Sheets.CellTypes.Base();
  359. const checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  360. const sheet = guideItem.workBook.getActiveSheet();
  361. renderSheetFunc(sheet, function(){
  362. for(let node of nodes){
  363. sheet.setCellType(node.serialNo(), 0, node.data.type === itemType.ration ? checkBox : base);
  364. }
  365. });
  366. }
  367. //清单表焦点控制
  368. //@param {Number}row @return {void}
  369. function billsInitSel(row){
  370. let guideSheet = guideItem.workBook.getActiveSheet();
  371. cleanData(guideSheet, guideItem.headers, -1);
  372. refreshInsertRation();
  373. if(!bills.tree){
  374. return;
  375. }
  376. let node = bills.tree.items[row];
  377. if(!node){
  378. return;
  379. }
  380. bills.tree.selected = node;
  381. if(!node.guidance.tree){
  382. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
  383. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  384. setItemCellType(node.guidance.tree.items);
  385. //项目指引初始焦点
  386. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  387. });
  388. }
  389. else{
  390. node.guidance.controller.showTreeData();
  391. setItemCellType(node.guidance.tree.items);
  392. //项目指引初始焦点
  393. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  394. }
  395. }
  396. //初始化清单的工作内容和项目特征
  397. //@param {Number}billsLibId @return {void}
  398. function initJobAndCharacter(billsLibId){
  399. CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: billsLibId}, function (datas) {
  400. stdBillsJobData = datas;
  401. });
  402. CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: billsLibId}, function (datas) {
  403. stdBillsFeatureData = datas;
  404. });
  405. }
  406. //初始化清单展开收起状态
  407. //@return {void}
  408. function initExpandStat(){
  409. //读取展开收起状态
  410. let currentExpState = sessionStorage.getItem('stdBillsGuidanceExpState');
  411. if(currentExpState){
  412. bills.tree.setExpandedByState(bills.tree.items, currentExpState);
  413. }
  414. //非叶子节点默认收起
  415. else{
  416. bills.tree.setRootExpanded(bills.tree.roots, false);
  417. }
  418. }
  419. //设置tag以悬浮提示
  420. function setTagForHint(nodes){
  421. let sheet = bills.workBook.getActiveSheet();
  422. renderSheetFunc(sheet, function () {
  423. for(let node of nodes){
  424. sheet.setTag(node.serialNo(), 2, node.data.ruleText ? node.data.ruleText : '');
  425. }
  426. });
  427. }
  428. //初始选择清单指引库
  429. //@param {Number}libID @return {void}
  430. function libInitSel(libID){
  431. //获取清单
  432. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function(rstData){
  433. //获取清单库中的工作内容和项目特征
  434. initJobAndCharacter(rstData.guidanceLib.billsLibId);
  435. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
  436. //每一棵项目指引树挂在清单节点上
  437. for(let node of bills.tree.items){
  438. node.guidance = {tree: null, controller: null};
  439. }
  440. setTagForHint(bills.tree.items);
  441. //默认初始节点
  442. billsInitSel(0);
  443. });
  444. }
  445. //初始化清单指引库
  446. //@param {Array}libDats @return {void}
  447. function initLibs(libDatas){
  448. libSel.empty();
  449. if(!libDatas){
  450. return;
  451. }
  452. let selectedLib = sessionStorage.getItem('stdBillsGuidance');
  453. for(let libData of libDatas){
  454. let opt = $('<option>').val(libData.id).text(libData.name);
  455. if(selectedLib && libData.id == selectedLib){
  456. opt.attr('selected', 'selected');
  457. }
  458. libSel.append(opt);
  459. }
  460. //初始默认选择
  461. libInitSel(libSel.select().val());
  462. }
  463. //初始化视图
  464. //@param {void} @return {void}
  465. function initViews(){
  466. //赋初始高度
  467. if($('#billsGuidance_bills').height() === 0 || $('#billsGuidance_items').height() === 0){
  468. let height = $(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-z").height();
  469. $('#billsGuidance_bills').height(height / 2);
  470. $('#billsGuidance_items').height(height / 2);
  471. }
  472. let modules = [bills, guideItem];
  473. initWorkBooks(modules);
  474. }
  475. //获取选中的行
  476. //@return {Array}
  477. function getCheckedRows(){
  478. let rst = [];
  479. let itemSheet = guideItem.workBook.getActiveSheet();
  480. for(let row = 0; row < itemSheet.getRowCount(); row++){
  481. let rowV = itemSheet.getValue(row, 0);
  482. if(rowV){
  483. rst.push(row);
  484. }
  485. }
  486. return rst;
  487. }
  488. //获取选中的定额数据
  489. //@param {Array}rows @return {Array}
  490. function getInsertRationData(rows){
  491. let rst = [];
  492. for(let row of rows){
  493. let node = bills.tree.selected.guidance.tree.items[row];
  494. if(node && node.data.type === itemType.ration){
  495. rst.push({itemQuery: {userID: userID, ID: node.data.rationID}, rationType: rationType.ration});
  496. }
  497. }
  498. return rst;
  499. }
  500. //插入定额
  501. //@return {void}
  502. function insertRations(addRationDatas){
  503. if(addRationDatas.length > 0){
  504. projectObj.project.Ration.addMultiRation(addRationDatas, function () {
  505. //恢复
  506. let sheet = guideItem.workBook.getActiveSheet();
  507. renderSheetFunc(sheet, function () {
  508. for(let row = 0; row < sheet.getRowCount(); row++){
  509. if(sheet.getValue(row, 0)){
  510. sheet.setValue(row, 0, false);
  511. }
  512. }
  513. });
  514. refreshInsertRation();
  515. projectObj.setActiveCell('quantity', true);
  516. });
  517. }
  518. }
  519. //更新插入定额按钮有效性
  520. function refreshInsertRation(){
  521. //勾选了定额,插入定额按钮才有效
  522. if(getCheckedRows().length > 0){
  523. $('#guidanceInsertRation').removeClass('disabled');
  524. }
  525. else {
  526. $('#guidanceInsertRation').addClass('disabled');
  527. }
  528. }
  529. //展开至搜索出来点的节点
  530. //@param {Array}nodes @return {void}
  531. function expandSearchNodes(nodes){
  532. let that = this;
  533. let billsSheet = bills.workBook.getActiveSheet();
  534. renderSheetFunc(billsSheet, function () {
  535. function expParentNode(node){
  536. if(node.parent && !node.parent.expanded){
  537. node.parent.setExpanded(true);
  538. expParentNode(node.parent);
  539. }
  540. }
  541. for(let node of nodes){
  542. expParentNode(node);
  543. }
  544. TREE_SHEET_HELPER.refreshTreeNodeData(bills.treeSetting, billsSheet, bills.tree.roots, true);
  545. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billsSheet, true);
  546. });
  547. }
  548. //各按钮监听事件
  549. //@return {void}
  550. function bindBtn(){
  551. //打开清单指引库
  552. $('#stdBillsGuidanceTab').click(function () {
  553. if(libSel.children().length === 0 && !projectReadOnly && !$(this).hasClass('disabled')){
  554. initLibs(projectInfoObj.projectInfo.engineeringInfo.billsGuidance_lib);
  555. }
  556. });
  557. //更改清单指引库
  558. $('#stdBillsGuidanceLibSelect').change(function () {
  559. //关闭搜索窗口
  560. $('#billsGuidanceSearchResult').hide();
  561. billsLibObj.clearHighLight(bills.workBook);
  562. libInitSel($(this).select().val());
  563. //记住选项
  564. sessionStorage.setItem('stdBillsGuidance', $(this).select().val());
  565. //清除展开收起状态sessionStorage
  566. sessionStorage.removeItem('stdBillsGuidanceExpState');
  567. });
  568. //插入定额
  569. $('#guidanceInsertRation').click(function () {
  570. let addRationDatas = getInsertRationData(getCheckedRows());
  571. insertRations(addRationDatas);
  572. });
  573. //插入清单
  574. $('#guidanceInsertBills').click(function () {
  575. //插入清单
  576. if(!bills.tree || !bills.tree.selected){
  577. return;
  578. }
  579. if(bills.tree.selected.children.length === 0){
  580. let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, bills.tree.selected);
  581. if(insert){
  582. //插入选中的定额
  583. let addRationDatas = getInsertRationData(getCheckedRows());
  584. insertRations(addRationDatas);
  585. }
  586. }
  587. });
  588. //搜索
  589. $('#stdBillsGuidanceSearch>span>button').click(function () {
  590. if(!bills.tree){
  591. return;
  592. }
  593. let billsSheet = bills.workBook.getActiveSheet();
  594. billsLibObj.clearHighLight(bills.workBook);
  595. let keyword = $('#stdBillsGuidanceSearch>input').val();
  596. if (!keyword || keyword === '') {
  597. $('#billsGuidanceSearchResult').hide();
  598. return;
  599. }
  600. let result = bills.tree.items.filter(function (item) {
  601. let codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
  602. let nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
  603. return codeIs || nameIs;
  604. });
  605. result.sort(function (x, y) {
  606. return x.serialNo() - y.serialNo();
  607. });
  608. if (result.length !== 0) {
  609. //展开搜索出来的节点
  610. expandSearchNodes(result);
  611. //设置记住展开
  612. sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
  613. let sel = billsSheet.getSelections();
  614. renderSheetFunc(billsSheet, function () {
  615. bills.controller.setTreeSelected(result[0]);
  616. billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  617. billsInitSel(result[0].serialNo());
  618. for (let node of result) {
  619. billsSheet.getRange(node.serialNo(), -1, 1, -1).backColor('lemonChiffon');
  620. }
  621. });
  622. //搜索初始定位
  623. billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  624. $('#nextBillsGuidance').show();
  625. $('#nextBillsGuidance').unbind('click');
  626. $('#nextBillsGuidance').bind('click', function () {
  627. let cur = bills.tree.selected, resultIndex = result.indexOf(cur), sel = billsSheet.getSelections();
  628. if (resultIndex === result.length - 1) {
  629. bills.controller.setTreeSelected(result[0]);
  630. billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  631. billsInitSel(result[0].serialNo());
  632. billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  633. } else {
  634. bills.controller.setTreeSelected(result[resultIndex + 1]);
  635. billsSheet.setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
  636. billsInitSel(result[resultIndex + 1].serialNo());
  637. billsSheet.showRow(result[resultIndex + 1].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  638. }
  639. });
  640. } else {
  641. billsLibObj.clearHighLight(bills.workBook);
  642. $('#nextBillsGuidance').hide();
  643. }
  644. $('#billsGuidanceSearchResultCount').text('搜索结果:' + result.length);
  645. $('#billsGuidanceSearchResult').show();
  646. });
  647. //搜索框回车
  648. $('#stdBillsGuidanceSearch>input').bind('keypress', function (event) {
  649. if(event.keyCode === 13){
  650. $(this).blur();
  651. $('#stdBillsGuidanceSearch>span>button').click();
  652. }
  653. });
  654. // 关闭搜索结果
  655. $('#closeSearchBillsGuidance').click(function () {
  656. $('#billsGuidanceSearchResult').hide();
  657. billsLibObj.clearHighLight(bills.workBook);
  658. refreshWorkBook();
  659. });
  660. }
  661. //刷新表
  662. //@return {void}
  663. function refreshWorkBook(){
  664. if(bills.workBook){
  665. bills.workBook.refresh();
  666. }
  667. if(guideItem.workBook){
  668. guideItem.workBook.refresh();
  669. }
  670. }
  671. return {initViews, bindBtn, refreshWorkBook, refreshInsertRation, bills};
  672. })();
  673. $(document).ready(function(){
  674. billsGuidance.initViews();
  675. billsGuidance.bindBtn();
  676. });