std_billsGuidance_lib.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. let sheet = module.workBook.getActiveSheet();
  332. if(module === bills){
  333. //默认初始可控制焦点在清单表中
  334. module.workBook.focus();
  335. sheet.options.isProtected = true;
  336. sheet.name('stdBillsGuidance_bills');
  337. //设置悬浮提示
  338. TREE_SHEET_HELPER.initSetting(bills.dom[0], bills.treeSetting);
  339. }
  340. if(module === guideItem){
  341. sheet.options.isProtected = true;
  342. sheet.getRange(-1, 0, -1, 1).locked(false);
  343. sheet.getRange(-1, 1, -1, 1).locked(true);
  344. }
  345. setOptions(module.workBook, options);
  346. buildHeader(module.workBook.getActiveSheet(), module.headers);
  347. bindEvent(module.workBook, module.events);
  348. }
  349. }
  350. //清空表数据
  351. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  352. function cleanData(sheet, headers, rowCount){
  353. renderSheetFunc(sheet, function () {
  354. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  355. if (rowCount > 0) {
  356. sheet.setRowCount(rowCount);
  357. }
  358. });
  359. }
  360. //初始化各工作表
  361. //@param {Array}modules @return {void}
  362. function initWorkBooks(modules){
  363. for(let module of modules){
  364. buildSheet(module);
  365. }
  366. }
  367. //初始化并输出树
  368. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  369. function initTree(module, sheet, treeSetting, datas){
  370. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  371. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  372. module.tree.loadDatas(datas);
  373. if(module === bills){
  374. initExpandStat();
  375. }
  376. module.controller.showTreeData();
  377. }
  378. //项目指引表焦点控制
  379. //@param {Number}row @return {void}
  380. function guideItemInitSel(row){
  381. let billsNode = bills.tree.selected;
  382. let node = null;
  383. if(billsNode && billsNode.guidance.tree){
  384. node = billsNode.guidance.tree.items[row];
  385. if(node){
  386. billsNode.guidance.tree.selected = node;
  387. }
  388. }
  389. }
  390. //根据项目指引的类型设置单元格类型,定额类型的项目指引为复选框
  391. //@param {Array}nodes @return {void}
  392. function setItemCellType(nodes){
  393. //设置单元格类型
  394. const base = new GC.Spread.Sheets.CellTypes.Base();
  395. const checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  396. const sheet = guideItem.workBook.getActiveSheet();
  397. renderSheetFunc(sheet, function(){
  398. for(let node of nodes){
  399. sheet.setCellType(node.serialNo(), 0, node.data.type === itemType.ration ? checkBox : base);
  400. }
  401. });
  402. }
  403. //清单表焦点控制
  404. //@param {Number}row @return {void}
  405. function billsInitSel(row){
  406. let guideSheet = guideItem.workBook.getActiveSheet();
  407. cleanData(guideSheet, guideItem.headers, -1);
  408. refreshInsertRation();
  409. if(!bills.tree){
  410. return;
  411. }
  412. let node = bills.tree.items[row];
  413. if(!node){
  414. return;
  415. }
  416. bills.tree.selected = node;
  417. if(!node.guidance.tree){
  418. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
  419. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  420. setItemCellType(node.guidance.tree.items);
  421. //项目指引初始焦点
  422. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  423. });
  424. }
  425. else{
  426. node.guidance.controller.showTreeData();
  427. setItemCellType(node.guidance.tree.items);
  428. //项目指引初始焦点
  429. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  430. }
  431. }
  432. //初始化清单的工作内容和项目特征
  433. //@param {Number}billsLibId @return {void}
  434. function initJobAndCharacter(billsLibId){
  435. CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: billsLibId}, function (datas) {
  436. stdBillsJobData = datas;
  437. });
  438. CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: billsLibId}, function (datas) {
  439. stdBillsFeatureData = datas;
  440. });
  441. }
  442. //初始化清单展开收起状态
  443. //@return {void}
  444. function initExpandStat(){
  445. //读取展开收起状态
  446. let currentExpState = sessionStorage.getItem('stdBillsGuidanceExpState');
  447. if(currentExpState){
  448. bills.tree.setExpandedByState(bills.tree.items, currentExpState);
  449. }
  450. //非叶子节点默认收起
  451. else{
  452. bills.tree.setRootExpanded(bills.tree.roots, false);
  453. }
  454. }
  455. //设置tag以悬浮提示
  456. function setTagForHint(nodes){
  457. let sheet = bills.workBook.getActiveSheet();
  458. renderSheetFunc(sheet, function () {
  459. for(let node of nodes){
  460. sheet.setTag(node.serialNo(), 2, node.data.ruleText ? node.data.ruleText : '');
  461. }
  462. });
  463. }
  464. //初始选择清单指引库
  465. //@param {Number}libID @return {void}
  466. function libInitSel(libID){
  467. //获取清单
  468. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function(rstData){
  469. //获取清单库中的工作内容和项目特征
  470. initJobAndCharacter(rstData.guidanceLib.billsLibId);
  471. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
  472. //每一棵项目指引树挂在清单节点上
  473. for(let node of bills.tree.items){
  474. node.guidance = {tree: null, controller: null};
  475. }
  476. setTagForHint(bills.tree.items);
  477. //默认初始节点
  478. billsInitSel(0);
  479. });
  480. }
  481. //初始化清单指引库
  482. //@param {Array}libDats @return {void}
  483. function initLibs(libDatas){
  484. libSel.empty();
  485. if(!libDatas){
  486. return;
  487. }
  488. let selectedLib = sessionStorage.getItem('stdBillsGuidance');
  489. for(let libData of libDatas){
  490. let opt = $('<option>').val(libData.id).text(libData.name);
  491. if(selectedLib && libData.id == selectedLib){
  492. opt.attr('selected', 'selected');
  493. }
  494. libSel.append(opt);
  495. }
  496. //初始默认选择
  497. libInitSel(libSel.select().val());
  498. }
  499. //初始化视图
  500. //@param {void} @return {void}
  501. function initViews(){
  502. //赋初始高度
  503. if($('#billsGuidance_bills').height() === 0 || $('#billsGuidance_items').height() === 0){
  504. let height = $(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-z").height();
  505. $('#billsGuidance_bills').height(height / 2);
  506. $('#billsGuidance_items').height(height / 2);
  507. }
  508. let modules = [bills, guideItem];
  509. initWorkBooks(modules);
  510. }
  511. //获取选中的行
  512. //@return {Array}
  513. function getCheckedRows(){
  514. let rst = [];
  515. let itemSheet = guideItem.workBook.getActiveSheet();
  516. for(let row = 0; row < itemSheet.getRowCount(); row++){
  517. let rowV = itemSheet.getValue(row, 0);
  518. if(rowV){
  519. rst.push(row);
  520. }
  521. }
  522. return rst;
  523. }
  524. //获取选中的定额数据
  525. //@param {Array}rows @return {Array}
  526. function getInsertRationData(rows){
  527. let rst = [];
  528. for(let row of rows){
  529. let node = bills.tree.selected.guidance.tree.items[row];
  530. if(node && node.data.type === itemType.ration){
  531. rst.push({itemQuery: {userID: userID, ID: node.data.rationID}, rationType: rationType.ration});
  532. }
  533. }
  534. return rst;
  535. }
  536. //插入定额
  537. //@return {void}
  538. function insertRations(addRationDatas){
  539. if(addRationDatas.length > 0){
  540. projectObj.project.Ration.addMultiRation(addRationDatas, function () {
  541. //恢复
  542. let sheet = guideItem.workBook.getActiveSheet();
  543. renderSheetFunc(sheet, function () {
  544. for(let row = 0; row < sheet.getRowCount(); row++){
  545. if(sheet.getValue(row, 0)){
  546. sheet.setValue(row, 0, false);
  547. }
  548. }
  549. });
  550. refreshInsertRation();
  551. projectObj.setActiveCell('quantity', true);
  552. });
  553. }
  554. }
  555. //更新插入定额按钮有效性
  556. function refreshInsertRation(){
  557. //勾选了定额,插入定额按钮才有效
  558. if(getCheckedRows().length > 0){
  559. $('#guidanceInsertRation').removeClass('disabled');
  560. }
  561. else {
  562. $('#guidanceInsertRation').addClass('disabled');
  563. }
  564. }
  565. //展开至搜索出来点的节点
  566. //@param {Array}nodes @return {void}
  567. function expandSearchNodes(nodes){
  568. let that = this;
  569. let billsSheet = bills.workBook.getActiveSheet();
  570. renderSheetFunc(billsSheet, function () {
  571. function expParentNode(node){
  572. if(node.parent && !node.parent.expanded){
  573. node.parent.setExpanded(true);
  574. expParentNode(node.parent);
  575. }
  576. }
  577. for(let node of nodes){
  578. expParentNode(node);
  579. }
  580. TREE_SHEET_HELPER.refreshTreeNodeData(bills.treeSetting, billsSheet, bills.tree.roots, true);
  581. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billsSheet, true);
  582. });
  583. }
  584. //各按钮监听事件
  585. //@return {void}
  586. function bindBtn(){
  587. //打开清单指引库
  588. $('#stdBillsGuidanceTab').click(function () {
  589. if(libSel.children().length === 0 && !projectReadOnly && !$(this).hasClass('disabled')){
  590. initLibs(projectInfoObj.projectInfo.engineeringInfo.billsGuidance_lib);
  591. }
  592. });
  593. //更改清单指引库
  594. $('#stdBillsGuidanceLibSelect').change(function () {
  595. //关闭搜索窗口
  596. $('#billsGuidanceSearchResult').hide();
  597. billsLibObj.clearHighLight(bills.workBook);
  598. libInitSel($(this).select().val());
  599. //记住选项
  600. sessionStorage.setItem('stdBillsGuidance', $(this).select().val());
  601. //清除展开收起状态sessionStorage
  602. sessionStorage.removeItem('stdBillsGuidanceExpState');
  603. });
  604. //插入定额
  605. $('#guidanceInsertRation').click(function () {
  606. let addRationDatas = getInsertRationData(getCheckedRows());
  607. insertRations(addRationDatas);
  608. });
  609. //插入清单
  610. $('#guidanceInsertBills').click(function () {
  611. //插入清单
  612. if(!bills.tree || !bills.tree.selected){
  613. return;
  614. }
  615. if(bills.tree.selected.children.length === 0){
  616. let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, bills.tree.selected);
  617. if(insert){
  618. //插入选中的定额
  619. let addRationDatas = getInsertRationData(getCheckedRows());
  620. insertRations(addRationDatas);
  621. }
  622. }
  623. });
  624. //搜索
  625. $('#stdBillsGuidanceSearch>span>button').click(function () {
  626. if(!bills.tree){
  627. return;
  628. }
  629. let billsSheet = bills.workBook.getActiveSheet();
  630. billsLibObj.clearHighLight(bills.workBook);
  631. let keyword = $('#stdBillsGuidanceSearch>input').val();
  632. if (!keyword || keyword === '') {
  633. $('#billsGuidanceSearchResult').hide();
  634. return;
  635. }
  636. let result = bills.tree.items.filter(function (item) {
  637. let codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
  638. let nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
  639. return codeIs || nameIs;
  640. });
  641. result.sort(function (x, y) {
  642. return x.serialNo() - y.serialNo();
  643. });
  644. if (result.length !== 0) {
  645. //展开搜索出来的节点
  646. expandSearchNodes(result);
  647. //设置记住展开
  648. sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
  649. let sel = billsSheet.getSelections();
  650. renderSheetFunc(billsSheet, function () {
  651. bills.controller.setTreeSelected(result[0]);
  652. billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  653. billsInitSel(result[0].serialNo());
  654. for (let node of result) {
  655. billsSheet.getRange(node.serialNo(), -1, 1, -1).backColor('lemonChiffon');
  656. }
  657. });
  658. //搜索初始定位
  659. billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  660. $('#nextBillsGuidance').show();
  661. $('#nextBillsGuidance').unbind('click');
  662. $('#nextBillsGuidance').bind('click', function () {
  663. let cur = bills.tree.selected, resultIndex = result.indexOf(cur), sel = billsSheet.getSelections();
  664. if (resultIndex === result.length - 1) {
  665. bills.controller.setTreeSelected(result[0]);
  666. billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  667. billsInitSel(result[0].serialNo());
  668. billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  669. } else {
  670. bills.controller.setTreeSelected(result[resultIndex + 1]);
  671. billsSheet.setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
  672. billsInitSel(result[resultIndex + 1].serialNo());
  673. billsSheet.showRow(result[resultIndex + 1].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  674. }
  675. });
  676. } else {
  677. billsLibObj.clearHighLight(bills.workBook);
  678. $('#nextBillsGuidance').hide();
  679. }
  680. $('#billsGuidanceSearchResultCount').text('搜索结果:' + result.length);
  681. $('#billsGuidanceSearchResult').show();
  682. });
  683. //搜索框回车
  684. $('#stdBillsGuidanceSearch>input').bind('keypress', function (event) {
  685. if(event.keyCode === 13){
  686. $(this).blur();
  687. $('#stdBillsGuidanceSearch>span>button').click();
  688. }
  689. });
  690. // 关闭搜索结果
  691. $('#closeSearchBillsGuidance').click(function () {
  692. $('#billsGuidanceSearchResult').hide();
  693. billsLibObj.clearHighLight(bills.workBook);
  694. refreshWorkBook();
  695. });
  696. }
  697. //刷新表
  698. //@return {void}
  699. function refreshWorkBook(){
  700. if(bills.workBook){
  701. bills.workBook.refresh();
  702. }
  703. if(guideItem.workBook){
  704. guideItem.workBook.refresh();
  705. }
  706. }
  707. return {initViews, bindBtn, refreshWorkBook, refreshInsertRation, bills};
  708. })();
  709. $(document).ready(function(){
  710. billsGuidance.initViews();
  711. billsGuidance.bindBtn();
  712. });