std_billsGuidance_lib.js 28 KB

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