std_billsGuidance_lib.js 28 KB

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