std_billsGuidance_lib.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/6/11
  7. * @version
  8. */
  9. const billsGuidance = (function () {
  10. let currentLib = null;
  11. //库类型
  12. const libType = {'guidance': 1, 'elf': 2}; //清单指引、清单精灵
  13. const libTypeText = {1: '清单指引', 2: '清单精灵'};
  14. const libSel = $('#stdBillsGuidanceLibSelect');
  15. //工作内容
  16. let stdBillsJobData = [];
  17. //项目特征
  18. let stdBillsFeatureData = [];
  19. const bills = {
  20. dom: $('#billsGuidance_bills'),
  21. workBook: null,
  22. cache: [],
  23. tree: null,
  24. controller: null,
  25. treeSetting: {
  26. emptyRowHeader: true,
  27. rowHeaderWidth: 15,
  28. treeCol: 0,
  29. emptyRows: 0,
  30. headRows: 1,
  31. headRowHeight: [40],
  32. defaultRowHeight: 21,
  33. cols: [{
  34. width: 160,
  35. readOnly: true,
  36. head: {
  37. titleNames: ["项目编码"],
  38. spanCols: [1],
  39. spanRows: [1],
  40. vAlign: [1],
  41. hAlign: [1],
  42. font: ["Arial"]
  43. },
  44. data: {
  45. field: "code",
  46. vAlign: 1,
  47. hAlign: 0,
  48. font: "Arial"
  49. }
  50. }, {
  51. width: 220,
  52. readOnly: true,
  53. head: {
  54. titleNames: ["项目名称"],
  55. spanCols: [1],
  56. spanRows: [1],
  57. vAlign: [1],
  58. hAlign: [1],
  59. font: ["Arial"]
  60. },
  61. data: {
  62. field: "name",
  63. vAlign: 1,
  64. hAlign: 0,
  65. font: "Arial"
  66. }
  67. },
  68. {
  69. width: 45,
  70. readOnly: true,
  71. showHint: true,
  72. head: {
  73. titleNames: ["计量单位"],
  74. spanCols: [1],
  75. spanRows: [1],
  76. vAlign: [1],
  77. hAlign: [1],
  78. font: ["Arial"]
  79. },
  80. data: {
  81. field: "unit",
  82. vAlign: 1,
  83. hAlign: 1,
  84. font: "Arial"
  85. }
  86. }
  87. ]
  88. },
  89. headers: [
  90. {name: '项目编码', dataCode: 'code', width: 160, vAlign: 'center', hAlign: 'left', formatter: '@'},
  91. {name: '项目名称', dataCode: 'name', width: 220, vAlign: 'center', hAlign: 'left', formatter: '@'},
  92. {name: '单位', dataCode: 'unit', width: 45, vAlign: 'center', hAlign: 'center', formatter: '@'},
  93. ],
  94. events: {
  95. SelectionChanging: function (sender, info) {
  96. billsInitSel(info.newSelections[0].row);
  97. },
  98. CellDoubleClick: function (sender, args) {
  99. if(!bills.tree){
  100. return;
  101. }
  102. let node = bills.tree.items[args.row];
  103. if(!node){
  104. return;
  105. }
  106. if(node.children.length === 0){
  107. //插入清单
  108. if (/\//.test(node.data.unit)) {
  109. let canAdd = true;
  110. $.bootstrapLoading.start();
  111. let existB = projectObj.project.Bills.sameStdCodeBillsData(node.data.code);
  112. if (existB) {
  113. let std = JSON.parse(JSON.stringify(node.data));
  114. std.unit = existB.unit;
  115. canAdd = ProjectController.addBills(projectObj.project, projectObj.mainController, std);
  116. if(canAdd !== null || canAdd !== false){
  117. //插入选中的定额
  118. let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
  119. insertRations(addRationDatas);
  120. }
  121. if(canAdd === false && $.bootstrapLoading.isLoading()){
  122. $.bootstrapLoading.end();
  123. }
  124. } else {
  125. ConfirmModal.stdBillsUnit.check(node.data, function (std) {
  126. canAdd = ProjectController.addBills(projectObj.project, projectObj.mainController, std);
  127. if(canAdd !== null || canAdd !== false){
  128. //插入选中的定额
  129. let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
  130. insertRations(addRationDatas);
  131. }
  132. if(canAdd === false && $.bootstrapLoading.isLoading()){
  133. $.bootstrapLoading.end();
  134. }
  135. }, function () {
  136. if($.bootstrapLoading.isLoading()){
  137. $.bootstrapLoading.end();
  138. }
  139. });
  140. }
  141. }
  142. else {
  143. let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, node);
  144. if(insert){
  145. //插入选中的定额
  146. let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
  147. insertRations(addRationDatas);
  148. }
  149. }
  150. }
  151. else {
  152. node.setExpanded(!node.expanded);
  153. //设置展开收起状态
  154. sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
  155. renderSheetFunc(args.sheet, function () {
  156. let iCount = node.posterityCount(), i, child;
  157. for (i = 0; i < iCount; i++) {
  158. child = bills.tree.items[args.row + i + 1];
  159. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  160. }
  161. args.sheet.invalidateLayout();
  162. });
  163. args.sheet.repaint();
  164. }
  165. }
  166. }
  167. };
  168. //项目指引类型
  169. const itemType = {
  170. job: 0,
  171. ration: 1
  172. };
  173. const guideItem = {
  174. dom: $('#billsGuidance_items'),
  175. workBook: null,
  176. tree: null,
  177. controller: null,
  178. treeSetting: {
  179. treeCol: 1,
  180. emptyRows: 0,
  181. headRows: 1,
  182. headRowHeight: [40],
  183. defaultRowHeight: 21,
  184. cols: [
  185. {
  186. width: 35,
  187. readOnly: false,
  188. head: {
  189. titleNames: ["选择"],
  190. spanCols: [1],
  191. spanRows: [1],
  192. vAlign: [1],
  193. hAlign: [1],
  194. font: ["Arial"]
  195. },
  196. data: {
  197. field: "select",
  198. vAlign: 1,
  199. hAlign: 1,
  200. font: "Arial"
  201. }
  202. },
  203. {
  204. width: 420,
  205. readOnly: false,
  206. head: {
  207. titleNames: ["项目指引"],
  208. spanCols: [1],
  209. spanRows: [1],
  210. vAlign: [1],
  211. hAlign: [1],
  212. font: ["Arial"]
  213. },
  214. data: {
  215. field: "name",
  216. vAlign: 1,
  217. hAlign: 0,
  218. font: "Arial"
  219. }
  220. }
  221. ]
  222. },
  223. headers: [
  224. {name: '选择', dataCode: 'select', width: 35, vAlign: 'center', hAlign: 'center', formatter: '@'},
  225. {name: '项目指引', dataCode: 'name', width: 300, vAlign: 'center', hAlign: 'left', formatter: '@'},
  226. ],
  227. events: {
  228. EditStarting: function (sender, args) {
  229. if(!bills.tree || guideItem.headers[args.col]['dataCode'] === 'name'){
  230. args.cancel = true;
  231. }
  232. },
  233. ButtonClicked: function (sender, args) {
  234. if(args.sheet.isEditing()){
  235. args.sheet.endEdit(true);
  236. }
  237. refreshInsertRation();
  238. },
  239. CellDoubleClick: function (sender, args) {
  240. if(!bills.tree || !bills.tree.selected){
  241. return;
  242. }
  243. let node = bills.tree.selected.guidance.tree.selected;
  244. if(!node){
  245. return;
  246. }
  247. if(node.children.length === 0){
  248. if(guideItem.headers[args.col]['dataCode'] === 'name'){
  249. insertRations(getInsertRationData([args.row]));
  250. }
  251. }
  252. else {
  253. node.setExpanded(!node.expanded);
  254. renderSheetFunc(args.sheet, function () {
  255. let iCount = node.posterityCount(), i, child;
  256. for (i = 0; i < iCount; i++) {
  257. child = bills.tree.selected.guidance.tree.items[args.row + i + 1];
  258. args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
  259. }
  260. args.sheet.invalidateLayout();
  261. });
  262. args.sheet.repaint();
  263. }
  264. }
  265. }
  266. };
  267. const elfItem = {
  268. dom: $('#billsGuidance_items'),
  269. workBook: null,
  270. tree: null,
  271. controller: null,
  272. treeSetting: {
  273. treeCol: 0,
  274. emptyRows: 0,
  275. headRows: 1,
  276. headRowHeight: [40],
  277. defaultRowHeight: 21,
  278. cols: [
  279. {
  280. width: 250,
  281. readOnly: true,
  282. head: {
  283. titleNames: ["施工工序"],
  284. spanCols: [1],
  285. spanRows: [1],
  286. vAlign: [1],
  287. hAlign: [1],
  288. font: ["Arial"]
  289. },
  290. data: {
  291. field: "name",
  292. vAlign: 1,
  293. hAlign: 0,
  294. font: "Arial"
  295. }
  296. },
  297. {
  298. width: 250,
  299. readOnly: false,
  300. head: {
  301. titleNames: ["选项"],
  302. spanCols: [1],
  303. spanRows: [1],
  304. vAlign: [1],
  305. hAlign: [1],
  306. font: ["Arial"]
  307. },
  308. data: {
  309. field: "options",
  310. vAlign: 1,
  311. hAlign: 0,
  312. font: "Arial"
  313. }
  314. }
  315. ]
  316. },
  317. headers: [
  318. {name: '施工工序', dataCode: 'name', width: 250, vAlign: 'center', hAlign: 'center', formatter: '@'},
  319. {name: '选项', dataCode: 'options', width: 250, vAlign: 'center', hAlign: 'left', formatter: '@'},
  320. ],
  321. events: {
  322. CellClick: function (sender, args) {
  323. if(elfItem.headers[args.col]['dataCode'] === 'options' && args.sheetArea === 3){
  324. if(!args.sheet.getCell(args.row, args.col).locked() && !args.sheet.isEditing()){
  325. args.sheet.startEdit();
  326. }
  327. }
  328. },
  329. ClipboardPasting: function (sender, info) {
  330. info.cancel = true;
  331. }
  332. }
  333. };
  334. const options = {
  335. workBook: {
  336. tabStripVisible: false,
  337. allowContextMenu: false,
  338. allowCopyPasteExcelStyle : false,
  339. allowExtendPasteRange: false,
  340. allowUserDragDrop : false,
  341. allowUserDragFill: false,
  342. scrollbarMaxAlign : true
  343. },
  344. sheet: {
  345. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  346. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  347. }
  348. };
  349. //渲染时方法,停止渲染
  350. //@param {Object}sheet {Function}func @return {void}
  351. function renderSheetFunc(sheet, func){
  352. sheet.suspendEvent();
  353. sheet.suspendPaint();
  354. if(func){
  355. func();
  356. }
  357. sheet.resumeEvent();
  358. sheet.resumePaint();
  359. }
  360. //设置表选项
  361. //@param {Object}workBook {Object}opts @return {void}
  362. function setOptions (workBook, opts) {
  363. for(let opt in opts.workBook){
  364. workBook.options[opt] = opts.workBook[opt];
  365. }
  366. for(let opt in opts.sheet){
  367. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  368. }
  369. }
  370. //建表头
  371. //@param {Object}sheet {Array}headers @return {void}
  372. function buildHeader(sheet, headers) {
  373. let fuc = function () {
  374. sheet.setColumnCount(headers.length);
  375. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  376. for(let i = 0, len = headers.length; i < len; i++){
  377. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  378. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  379. if(headers[i].formatter){
  380. sheet.setFormatter(-1, i, headers[i].formatter);
  381. }
  382. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  383. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  384. }
  385. };
  386. renderSheetFunc(sheet, fuc);
  387. }
  388. //表监听事件
  389. //@param {Object}workBook @return {void}
  390. function bindEvent(workBook, events) {
  391. if(Object.keys(events).length === 0){
  392. return;
  393. }
  394. const Events = GC.Spread.Sheets.Events;
  395. for(let event in events){
  396. workBook.bind(Events[event], events[event]);
  397. }
  398. }
  399. //建表
  400. //@param {Object}module @return {void}
  401. function buildSheet(module) {
  402. if(!module.workBook){
  403. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  404. sheetCommonObj.spreadDefaultStyle(module.workBook);
  405. let sheet = module.workBook.getActiveSheet();
  406. if(module === bills){
  407. //默认初始可控制焦点在清单表中
  408. module.workBook.focus();
  409. sheet.options.isProtected = true;
  410. sheet.name('stdBillsGuidance_bills');
  411. //设置悬浮提示
  412. TREE_SHEET_HELPER.initSetting(bills.dom[0], bills.treeSetting);
  413. }
  414. if(module === guideItem){
  415. sheet.options.isProtected = true;
  416. sheet.getRange(-1, 0, -1, 1).locked(false);
  417. sheet.getRange(-1, 1, -1, 1).locked(true);
  418. }
  419. if(module === elfItem){
  420. sheet.options.isProtected = true;
  421. sheet.getRange(-1, 0, -1, 1).locked(true);
  422. sheet.getRange(-1, 1, -1, 1).locked(false);
  423. }
  424. setOptions(module.workBook, options);
  425. buildHeader(module.workBook.getActiveSheet(), module.headers);
  426. bindEvent(module.workBook, module.events);
  427. }
  428. }
  429. //清空表数据
  430. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  431. function cleanData(sheet, headers, rowCount){
  432. renderSheetFunc(sheet, function () {
  433. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  434. if (rowCount > 0) {
  435. sheet.setRowCount(rowCount);
  436. }
  437. });
  438. }
  439. //初始化各工作表
  440. //@param {Array}modules @return {void}
  441. function initWorkBooks(modules){
  442. for(let module of modules){
  443. buildSheet(module);
  444. }
  445. }
  446. //初始化并输出树
  447. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  448. function initTree(module, sheet, treeSetting, datas){
  449. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  450. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  451. module.tree.loadDatas(datas);
  452. if(module === bills){
  453. initExpandStat();
  454. }
  455. module.controller.showTreeData();
  456. }
  457. //项目指引表焦点控制
  458. //@param {Number}row @return {void}
  459. function guideItemInitSel(row){
  460. let billsNode = bills.tree.selected;
  461. let node = null;
  462. if(billsNode && billsNode.guidance.tree){
  463. node = billsNode.guidance.tree.items[row];
  464. if(node){
  465. billsNode.guidance.tree.selected = node;
  466. }
  467. }
  468. }
  469. //清单精灵表焦点控制
  470. //@param {Number}row @return {void}
  471. function elfItemInitSel(row){
  472. let billsNode = bills.tree.selected;
  473. let node = null;
  474. if(billsNode && billsNode.elf.tree){
  475. node = billsNode.elf.tree.items[row];
  476. if(node){
  477. billsNode.elf.tree.selected = node;
  478. }
  479. }
  480. }
  481. //根据项目指引的类型设置单元格类型,定额类型的项目指引为复选框
  482. //@param {Array}nodes @return {void}
  483. function setItemCellType(nodes){
  484. //设置单元格类型
  485. const base = new GC.Spread.Sheets.CellTypes.Base();
  486. const checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  487. const sheet = guideItem.workBook.getActiveSheet();
  488. renderSheetFunc(sheet, function(){
  489. for(let node of nodes){
  490. sheet.setCellType(node.serialNo(), 0, node.data.type === itemType.ration ? checkBox : base);
  491. }
  492. });
  493. }
  494. //清单表焦点控制
  495. //@param {Number}row @return {void}
  496. function billsInitSel(row){
  497. if(currentLib.type && currentLib.type === libType.elf){
  498. billsSelElf(row);
  499. }else {
  500. billsSelGuidance(row);
  501. }
  502. }
  503. //清单焦点变换-清单指引操作
  504. //@param {Number}row @return {void}
  505. function billsSelGuidance(row){
  506. let guideSheet = guideItem.workBook.getActiveSheet();
  507. cleanData(guideSheet, guideItem.headers, -1);
  508. if(!bills.tree){
  509. return;
  510. }
  511. let node = bills.tree.items[row];
  512. if(!node){
  513. return;
  514. }
  515. bills.tree.selected = node;
  516. refreshInsertRation();
  517. if(!node.guidance.tree){
  518. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
  519. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  520. setItemCellType(node.guidance.tree.items);
  521. //项目指引初始焦点
  522. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  523. });
  524. }
  525. else{
  526. node.guidance.controller.showTreeData();
  527. setItemCellType(node.guidance.tree.items);
  528. //项目指引初始焦点
  529. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  530. }
  531. }
  532. //清单焦点变换-清单精灵操作
  533. //@param {Number}row @return {void}
  534. function billsSelElf(row) {
  535. let elfSheet = elfItem.workBook.getActiveSheet();
  536. cleanData(elfSheet, elfItem.headers, -1);
  537. if(!bills.tree){
  538. return;
  539. }
  540. let node = bills.tree.items[row];
  541. if(!node){
  542. return;
  543. }
  544. bills.tree.selected = node;
  545. if(!node.elf.tree){
  546. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
  547. //定额数据删除编号信息
  548. for(let rData of rstData){
  549. if(rData.type === itemType.ration){
  550. let nameArr = rData.name.split(' ');
  551. if(nameArr.length > 0){
  552. nameArr.splice(0, 1);
  553. rData.name = nameArr.join(' ');
  554. }
  555. }
  556. }
  557. node.elf.datas = rstData;
  558. //第一层节点数据
  559. let firstLevelDatas = _.filter(rstData, function (data) {
  560. return data.ParentID == -1;
  561. });
  562. //第一层初始数据的选项显示
  563. for(let fData of firstLevelDatas){
  564. let options = getOptions(fData, rstData);
  565. fData.options = options.length > 0 ? options[0].name : '';
  566. //下挂的选项
  567. fData.optionsData = options && options.length > 0 ? _.cloneDeep(options) : [];
  568. fData.optionChecked = options && options.length > 0 ? [_.cloneDeep(options[0])] : [];
  569. }
  570. renderSheetFunc(elfSheet, function () {
  571. initTree(node.elf, elfSheet, elfItem.treeSetting, firstLevelDatas);
  572. //初始选择选项
  573. let initOptsOpr = [];
  574. for(let elfNode of node.elf.tree.items){
  575. if(elfNode.data.optionsData.length > 0){
  576. initOptsOpr.push({node: elfNode, data: elfNode.data.optionsData[0]});
  577. }
  578. }
  579. for(let opr of initOptsOpr){
  580. insertNodeByData(opr.node, opr.data);
  581. }
  582. TREE_SHEET_HELPER.refreshTreeNodeData(elfItem.treeSetting, elfSheet, node.elf.tree.items, false);
  583. setOptionsCellType(node.elf.tree.items);
  584. //项目指引初始焦点
  585. elfItemInitSel(elfSheet.getActiveRowIndex() ? elfSheet.getActiveRowIndex() : 0);
  586. refreshInsertRation();
  587. });
  588. });
  589. }
  590. else{
  591. renderSheetFunc(elfSheet, function () {
  592. node.elf.controller.showTreeData();
  593. setOptionsCellType(node.elf.tree.items);
  594. //项目指引初始焦点
  595. elfItemInitSel(elfSheet.getActiveRowIndex() ? elfSheet.getActiveRowIndex() : 0);
  596. refreshInsertRation();
  597. });
  598. }
  599. }
  600. //获取选项的深度
  601. //@param {Object}opt {Array}options(当前清单所有选项) @return {Array}
  602. function getOptionDepth(opt, options) {
  603. let parent = _.find(options, {ID: opt.ParentID});
  604. let depth = 0;
  605. while (parent){
  606. depth++;
  607. parent = _.find(options, {ID: parent.ParentID});
  608. }
  609. return depth;
  610. }
  611. //获取施工工序含有的选项(即当前施工工序的子项),获取的顺序按照NextSiblingID排序
  612. //@param {Object}process {Array}datas @return {Array}
  613. function getOptions(process, datas) {
  614. let rst = [];
  615. if(!process || !process.ID){
  616. return [];
  617. }
  618. let options = _.filter(datas, function (data) {
  619. return data.ParentID == process.ID;
  620. });
  621. if(options.length === 0){
  622. return [];
  623. }
  624. //根据NextSiblingID排序
  625. let IDMapping = {};
  626. for(let opt of options){
  627. IDMapping[opt.ID] = {self: opt, next: null, pre: null};
  628. }
  629. for(let opt of options){
  630. let next = IDMapping[opt.NextSiblingID] ? IDMapping[opt.NextSiblingID] : null;
  631. if(next){
  632. next.pre = IDMapping[opt.ID];
  633. IDMapping[opt.ID]['next'] = next;
  634. }
  635. }
  636. let first = null,
  637. rank = 0;
  638. for(let ID in IDMapping){
  639. let obj = IDMapping[ID];
  640. if(!obj.pre){
  641. first = obj;
  642. }
  643. }
  644. while(first){
  645. rank++;
  646. first.self.rank = rank;
  647. rst.push(first.self);
  648. first = first.next;
  649. }
  650. return rst;
  651. }
  652. //设置清单精灵选项单元格
  653. //@param {Array}nodes @return {void}
  654. function setOptionsCellType(nodes) {
  655. let elfSheet = elfItem.workBook.getActiveSheet();
  656. for(let node of nodes){
  657. if(node.data.optionsData && node.data.optionsData.length > 0){
  658. elfSheet.getCell(node.serialNo(), 1).locked(false).cellType(getOptionsCellType());
  659. }
  660. else {
  661. elfSheet.getCell(node.serialNo(), 1).locked(true).cellType(new GC.Spread.Sheets.CellTypes.Base());
  662. }
  663. }
  664. }
  665. //递归插入节点:原始项目指引数据奇数层为需要插入的节点,偶数层为下拉选项
  666. //@param {Object}node(当前操作的节点) {Object}data(选项) @return {void}
  667. function insertNodeByData(node, data) {
  668. let elfSheet = elfItem.workBook.getActiveSheet();
  669. let sameDepthNodes = node.children;
  670. let insertNextSiblingID = -1,
  671. insertParentID = node.data.ID;
  672. //当前操作节点的选项
  673. let nodeOpts = getOptions(node.data, bills.tree.selected.elf.datas);
  674. let subOpts = getOptions(data, bills.tree.selected.elf.datas);
  675. let dataDepth = getOptionDepth(data, bills.tree.selected.elf.datas);
  676. if(subOpts.length >0 && subOpts[0].type !== itemType.ration){
  677. if((dataDepth + 1) % 2 === 0){
  678. //排序后的数据
  679. let dataWithRank = _.find(nodeOpts, {ID: data.ID});
  680. //确定插入位置
  681. for(let subOpt of subOpts){
  682. for(let subNode of sameDepthNodes){
  683. //同层节点原本选项数据
  684. let subNodeOptData = _.find(bills.tree.selected.elf.datas, {ID: subNode.data.ID});
  685. //同层节点原本父选项数据
  686. let subNodeOptParent = _.find(bills.tree.selected.elf.datas, {ID: subNodeOptData.ParentID});
  687. let subNodeOptParentWithRank = _.find(nodeOpts, {ID: subNodeOptParent.ID});
  688. //父项顺序决定插入位置
  689. if(dataWithRank.rank < subNodeOptParentWithRank.rank){
  690. insertNextSiblingID = subNode.data.ID;
  691. break;
  692. }
  693. //父项顺序相同,根据子项顺序决定插入位置
  694. else if(dataWithRank.rank = subNodeOptParentWithRank.rank){
  695. if(subOpt.rank < subNode.data.rank){
  696. insertNextSiblingID = subNode.data.ID;
  697. break;
  698. }
  699. }
  700. }
  701. let sub2Opts = getOptions(subOpt, bills.tree.selected.elf.datas);
  702. subOpt.options = sub2Opts.length > 0 ? sub2Opts[0].name : '';
  703. let cloneOpt = _.cloneDeep(subOpt);//不改变原本的数据,比如ParentID
  704. cloneOpt.optionChecked = sub2Opts.length > 0 ? [_.cloneDeep(sub2Opts[0])] : [];
  705. cloneOpt.optionsData = sub2Opts.length > 0 ? _.cloneDeep(sub2Opts) : [];
  706. let newNode = node.tree.insertByData(cloneOpt, insertParentID, insertNextSiblingID);
  707. elfSheet.addRows(newNode.serialNo(), 1);
  708. node.tree.selected = newNode;
  709. elfSheet.setSelection(newNode.serialNo(), elfSheet.getSelections()[0].col, 1, 1);
  710. if(sub2Opts.length > 0 && sub2Opts[0].type !== itemType.ration){
  711. insertNodeByData(newNode, sub2Opts[0]);
  712. }
  713. }
  714. }
  715. else {
  716. insertNodeByData(node, subOpts[0]);
  717. }
  718. }
  719. }
  720. //获取选项下拉多选单元格
  721. //@param {void} @return {void}
  722. function getOptionsCellType() {
  723. let me = this;
  724. let elfSheet= elfItem.workBook.getActiveSheet();
  725. function OptionsCellType() {
  726. this.isEscKey=false;
  727. this.displayText='';
  728. }
  729. function getHtml(node, cellRect, cellStyle) {
  730. if(!node){
  731. return '';
  732. }
  733. let height = cellRect.height;
  734. let htmlArr = [];
  735. let options = getOptions(node.data, bills.tree.selected.elf.datas);
  736. //let optionsTitle = node.data.options.split(';').join('\n');
  737. htmlArr.push(`<div style="height: ${height}px; background: ${cellStyle.backColor};overflow: hidden; white-space: nowrap; text-overflow: ellipsis">${node.data.options}</div><div style="background: ${cellStyle.backColor};border: 1px solid; overflow: auto; height: ${options.length > 6 ? height*6 : height*options.length+5}px; font-size: 0.9rem;">`);
  738. for(let opt of options){
  739. htmlArr.push(`<div title="${opt.name ? opt.name : ''}" class="elf-options" style="height: ${height}px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis">
  740. <input rank="${opt.rank}" value="${opt.ID}" style="margin-left: 5px; vertical-align: middle" type="checkbox"
  741. ${node.data.optionChecked && _.find(node.data.optionChecked, {ID: opt.ID}) ? 'checked' : ''}> ${opt.name ? opt.name : ''}</div>`);
  742. }
  743. htmlArr.push(`</div>`);
  744. return htmlArr.join('');
  745. }
  746. //选择后处理
  747. function doAfterSel(node) {
  748. let checkedSels = $('.elf-options').find('input:checked');
  749. let checkedNameArr = [],
  750. optionChecked= [];
  751. for(let checkSel of checkedSels){
  752. let opt = _.cloneDeep(_.find(bills.tree.selected.elf.datas, {ID: $(checkSel).val()}));
  753. opt.rank = $(checkSel).attr('rank');
  754. checkedNameArr.push(opt.name);
  755. optionChecked.push(opt);
  756. }
  757. this.displayText = checkedNameArr.length > 0 ? checkedNameArr.join(';') : '';
  758. node.data.options = this.displayText;
  759. node.data.optionChecked = optionChecked;
  760. //删除节点
  761. let deleteNodes = getDeleteNodes(node, optionChecked);
  762. for(let dNode of deleteNodes){
  763. elfSheet.deleteRows(dNode.serialNo(), dNode.posterityCount() + 1);
  764. node.tree.delete(dNode);
  765. }
  766. //插入节点
  767. for(let perCheked of optionChecked){
  768. let exist = false;
  769. let subOpts = getOptions(perCheked, bills.tree.selected.elf.datas);
  770. for(let subNode of node.children){
  771. for(let subOpt of subOpts){
  772. if(subNode.data.ID === subOpt.ID){
  773. exist = true;
  774. break;
  775. }
  776. }
  777. }
  778. //不重复且不为定额时插入
  779. if(!exist && perCheked.type !== itemType.ration){
  780. insertNodeByData(node, perCheked);//这里递归,默认第一个
  781. }
  782. }
  783. TREE_SHEET_HELPER.refreshTreeNodeData(elfItem.treeSetting, elfSheet, node.tree.items, false);
  784. setOptionsCellType(node.tree.items);
  785. refreshInsertRation();
  786. }
  787. //获取删除节点
  788. function getDeleteNodes(node, optionChecked) {
  789. let rst = [];
  790. for(let subNode of node.children){
  791. let exist = false;
  792. for(let perChecked of optionChecked){
  793. let subOpts = getOptions(perChecked, bills.tree.selected.elf.datas);
  794. for(let subOpt of subOpts){
  795. if(subNode.data.ID === subOpt.ID){
  796. exist = true;
  797. break;
  798. }
  799. }
  800. }
  801. if(!exist){
  802. rst.push(subNode);
  803. }
  804. }
  805. return rst;
  806. }
  807. OptionsCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
  808. OptionsCellType.prototype.createEditorElement = function (context) {
  809. let element = document.createElement("div");//这里创建的,会自动销毁
  810. return element
  811. };
  812. OptionsCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
  813. if (editorContext) {
  814. let $editor = $(editorContext);
  815. $editor.css("position", "fixed");
  816. $editor.css("background", "white");
  817. $editor.css("width", cellRect.width);
  818. $editor.attr("gcUIElement", "gcEditingInput");
  819. let node = bills.tree.selected.elf.tree.items[elfSheet.getActiveRowIndex()];
  820. $editor.html(getHtml(node, cellRect, cellStyle));
  821. }
  822. }
  823. OptionsCellType.prototype.deactivateEditor = function (editorContext, context) {
  824. };
  825. OptionsCellType.prototype.setEditorValue = function (editor, value, context) {
  826. this.displayText = value;
  827. };
  828. OptionsCellType.prototype.getEditorValue = function (editor, context) {
  829. let me = this;
  830. let node = bills.tree.selected.elf.tree.items[elfSheet.getActiveRowIndex()];
  831. if(this.isEscKey !=true){
  832. renderSheetFunc(elfSheet, function () {
  833. doAfterSel.call(me, node);
  834. });
  835. }
  836. this.isEscKey = false;
  837. return this.displayText;
  838. };
  839. OptionsCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
  840. };
  841. OptionsCellType.prototype.isReservedKey = function (e, context) {
  842. //cell type handle tab key by itself
  843. this.isEscKey = e.keyCode === GC.Spread.Commands.Key.esc;
  844. return false;
  845. };
  846. /* OptionsCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  847. if(style.backColor){
  848. ctx.fillStyle = style.backColor;
  849. ctx.fillRect(x, y, w, h);
  850. ctx.save();
  851. }
  852. //边长
  853. const l = 7;
  854. let leftPointX = x + w - 15,
  855. rightPointX = leftPointX + l,
  856. middlePointX = (leftPointX + rightPointX)/2;
  857. const cos30 = Math.cos(2*Math.PI * 30 / 360);
  858. let hL = l * cos30;
  859. let beginY = y + h/2 - hL;
  860. ctx.beginPath();
  861. ctx.moveTo(leftPointX, beginY);
  862. ctx.lineTo(rightPointX, beginY);
  863. ctx.lineTo(middlePointX, beginY + hL);
  864. ctx.fillStyle = 'black';
  865. ctx.fill();
  866. ctx.save();
  867. };*/
  868. // override getHitInfo to allow cell type get mouse messages
  869. OptionsCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  870. return {
  871. x: x,
  872. y: y,
  873. row: context.row,
  874. col: context.col,
  875. cellStyle: cellStyle,
  876. cellRect: cellRect,
  877. sheetArea: context.sheetArea
  878. };
  879. };
  880. return new OptionsCellType();
  881. }
  882. //初始化清单的工作内容和项目特征
  883. //@param {Number}billsLibId @return {void}
  884. function initJobAndCharacter(billsLibId){
  885. CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: billsLibId}, function (datas) {
  886. stdBillsJobData = datas;
  887. });
  888. CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: billsLibId}, function (datas) {
  889. stdBillsFeatureData = datas;
  890. });
  891. }
  892. //初始化清单展开收起状态
  893. //@return {void}
  894. function initExpandStat(){
  895. //读取展开收起状态
  896. let currentExpState = sessionStorage.getItem('stdBillsGuidanceExpState');
  897. if(currentExpState){
  898. bills.tree.setExpandedByState(bills.tree.items, currentExpState);
  899. }
  900. //非叶子节点默认收起
  901. else{
  902. bills.tree.setRootExpanded(bills.tree.roots, false);
  903. }
  904. }
  905. //设置tag以悬浮提示
  906. function setTagForHint(nodes){
  907. let sheet = bills.workBook.getActiveSheet();
  908. renderSheetFunc(sheet, function () {
  909. for(let node of nodes){
  910. sheet.setTag(node.serialNo(), 2, node.data.ruleText ? node.data.ruleText : '');
  911. }
  912. });
  913. }
  914. //初始选择清单指引库
  915. //@param {Number}libID @return {void}
  916. function libInitSel(libID){
  917. //获取清单
  918. $.bootstrapLoading.start();
  919. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function(rstData){
  920. currentLib = rstData.guidanceLib;
  921. if(guideItem.workBook){
  922. guideItem.workBook.destroy();
  923. guideItem.workBook = null;
  924. }
  925. if(elfItem.workBook){
  926. elfItem.workBook.destroy();
  927. elfItem.workBook = null;
  928. }
  929. initViews();
  930. //获取清单库中的工作内容和项目特征
  931. initJobAndCharacter(rstData.guidanceLib.billsLibId);
  932. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
  933. //清单精灵
  934. if(rstData.guidanceLib.type && rstData.guidanceLib.type == libType.elf){
  935. $('#stdBillsGuidanceTab').text('清单精灵');
  936. //每一个清单节点下挂载一棵清单精灵树
  937. for(let node of bills.tree.items){
  938. node.elf = {tree: null, controller: null, datas: []}; //挂载全部数据,数据不一定全成为树节点
  939. }
  940. }
  941. //清单指引
  942. else {
  943. $('#stdBillsGuidanceTab').text('清单指引');
  944. //每一棵项目指引树挂在清单节点上
  945. for(let node of bills.tree.items){
  946. node.guidance = {tree: null, controller: null};
  947. }
  948. }
  949. setTagForHint(bills.tree.items);
  950. //默认初始节点
  951. billsInitSel(0);
  952. $.bootstrapLoading.end();
  953. }, function () {
  954. $.bootstrapLoading.end();
  955. });
  956. }
  957. //初始化清单指引库
  958. //@param {Array}libDats @return {void}
  959. function initLibs(libDatas){
  960. libSel.empty();
  961. if(!libDatas){
  962. return;
  963. }
  964. let selectedLib = sessionStorage.getItem('stdBillsGuidance');
  965. for(let libData of libDatas){
  966. let opt = $('<option>').val(libData.id).text(libData.name);
  967. if(selectedLib && libData.id == selectedLib){
  968. opt.attr('selected', 'selected');
  969. }
  970. libSel.append(opt);
  971. }
  972. //初始默认选择
  973. libInitSel(libSel.select().val());
  974. }
  975. //初始化视图
  976. //@param {void} @return {void}
  977. function initViews(){
  978. //赋初始高度
  979. if($('#billsGuidance_bills').height() === 0 || $('#billsGuidance_items').height() === 0){
  980. let height = $(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-z").height();
  981. $('#billsGuidance_bills').height(height / 2);
  982. $('#billsGuidance_items').height(height / 2);
  983. }
  984. let modules = [bills];
  985. if(currentLib.type && currentLib.type === libType.elf){
  986. modules.push(elfItem);
  987. }
  988. else {
  989. modules.push(guideItem);
  990. }
  991. initWorkBooks(modules);
  992. }
  993. //获取选中的行
  994. //@return {Array}
  995. function getCheckedRows(){
  996. let rst = [];
  997. let itemSheet = guideItem.workBook.getActiveSheet();
  998. for(let row = 0; row < itemSheet.getRowCount(); row++){
  999. let rowV = itemSheet.getValue(row, 0);
  1000. if(rowV){
  1001. rst.push(row);
  1002. }
  1003. }
  1004. return rst;
  1005. }
  1006. //获取清单精灵生成的定额数据
  1007. //@return {Array}
  1008. function getInsertElfRationData(){
  1009. let rst = [];
  1010. if(!bills.tree.selected){
  1011. return [];
  1012. }
  1013. if(!bills.tree.selected.elf){
  1014. return [];
  1015. }
  1016. let tree = bills.tree.selected.elf.tree;
  1017. if(!tree){
  1018. return [];
  1019. }
  1020. for(let node of tree.items){
  1021. for(let perChecked of node.data.optionChecked){
  1022. //选项直接是定额
  1023. if(perChecked.type === itemType.ration){
  1024. rst.push({itemQuery: {userID: userID, ID: perChecked.rationID}, rationType: rationType.ration});
  1025. }
  1026. //选项下子选项是定额
  1027. else {
  1028. let rationOpts = getOptions(perChecked, bills.tree.selected.elf.datas);
  1029. for(let ration of rationOpts){
  1030. if(ration.type === itemType.ration){
  1031. rst.push({itemQuery: {userID: userID, ID: ration.rationID}, rationType: rationType.ration});
  1032. }
  1033. }
  1034. }
  1035. }
  1036. }
  1037. return rst;
  1038. }
  1039. //获取选中的定额数据
  1040. //@param {Array}rows @return {Array}
  1041. function getInsertRationData(rows){
  1042. let rst = [];
  1043. for(let row of rows){
  1044. let node = bills.tree.selected.guidance.tree.items[row];
  1045. if(node && node.data.type === itemType.ration){
  1046. rst.push({itemQuery: {userID: userID, ID: node.data.rationID}, rationType: rationType.ration});
  1047. }
  1048. }
  1049. return rst;
  1050. }
  1051. //插入定额
  1052. //@return {void}
  1053. function insertRations(addRationDatas){
  1054. if(addRationDatas.length > 0){
  1055. projectObj.project.Ration.addMultiRation(addRationDatas, function () {
  1056. //恢复
  1057. if(!currentLib.type || currentLib.type === libType.guidance){
  1058. let sheet = guideItem.workBook.getActiveSheet();
  1059. renderSheetFunc(sheet, function () {
  1060. for(let row = 0; row < sheet.getRowCount(); row++){
  1061. if(sheet.getValue(row, 0)){
  1062. sheet.setValue(row, 0, false);
  1063. }
  1064. }
  1065. });
  1066. }
  1067. refreshInsertRation();
  1068. projectObj.setActiveCell('quantity', true);
  1069. });
  1070. }
  1071. }
  1072. //更新插入定额按钮有效性
  1073. function refreshInsertRation(){
  1074. if(currentLib.type && currentLib.type === libType.elf){
  1075. if(getInsertElfRationData().length > 0){
  1076. $('#guidanceInsertRation').removeClass('disabled');
  1077. }
  1078. else {
  1079. $('#guidanceInsertRation').addClass('disabled');
  1080. }
  1081. }
  1082. else {
  1083. //勾选了定额,插入定额按钮才有效
  1084. if(getCheckedRows().length > 0){
  1085. $('#guidanceInsertRation').removeClass('disabled');
  1086. }
  1087. else {
  1088. $('#guidanceInsertRation').addClass('disabled');
  1089. }
  1090. }
  1091. }
  1092. //展开至搜索出来点的节点
  1093. //@param {Array}nodes @return {void}
  1094. function expandSearchNodes(nodes){
  1095. let that = this;
  1096. let billsSheet = bills.workBook.getActiveSheet();
  1097. renderSheetFunc(billsSheet, function () {
  1098. function expParentNode(node){
  1099. if(node.parent && !node.parent.expanded){
  1100. node.parent.setExpanded(true);
  1101. expParentNode(node.parent);
  1102. }
  1103. }
  1104. for(let node of nodes){
  1105. expParentNode(node);
  1106. }
  1107. TREE_SHEET_HELPER.refreshTreeNodeData(bills.treeSetting, billsSheet, bills.tree.roots, true);
  1108. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billsSheet, true);
  1109. });
  1110. }
  1111. //各按钮监听事件
  1112. //@return {void}
  1113. function bindBtn(){
  1114. //打开清单指引库
  1115. $('#stdBillsGuidanceTab').click(function () {
  1116. if(libSel.children().length === 0 && !projectReadOnly && !$(this).hasClass('disabled')){
  1117. initLibs(projectInfoObj.projectInfo.engineeringInfo.billsGuidance_lib);
  1118. }
  1119. });
  1120. //更改清单指引库
  1121. $('#stdBillsGuidanceLibSelect').change(function () {
  1122. //关闭搜索窗口
  1123. $('#billsGuidanceSearchResult').hide();
  1124. billsLibObj.clearHighLight(bills.workBook);
  1125. libInitSel($(this).select().val());
  1126. //记住选项
  1127. sessionStorage.setItem('stdBillsGuidance', $(this).select().val());
  1128. //清除展开收起状态sessionStorage
  1129. sessionStorage.removeItem('stdBillsGuidanceExpState');
  1130. });
  1131. //插入定额
  1132. $('#guidanceInsertRation').click(function () {
  1133. let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
  1134. insertRations(addRationDatas);
  1135. });
  1136. //插入清单
  1137. $('#guidanceInsertBills').click(function () {
  1138. //插入清单
  1139. if(!bills.tree || !bills.tree.selected){
  1140. return;
  1141. }
  1142. if(bills.tree.selected.children.length === 0){
  1143. let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, bills.tree.selected);
  1144. if(insert){
  1145. //插入选中的定额
  1146. let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
  1147. insertRations(addRationDatas);
  1148. }
  1149. }
  1150. });
  1151. //搜索
  1152. $('#stdBillsGuidanceSearch>div>button').click(function () {
  1153. if(!bills.tree){
  1154. return;
  1155. }
  1156. let billsSheet = bills.workBook.getActiveSheet();
  1157. billsLibObj.clearHighLight(bills.workBook);
  1158. let keyword = $('#stdBillsGuidanceSearch>input').val();
  1159. if (!keyword || keyword === '') {
  1160. $('#billsGuidanceSearchResult').hide();
  1161. return;
  1162. }
  1163. let result = bills.tree.items.filter(function (item) {
  1164. let codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
  1165. let nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
  1166. return codeIs || nameIs;
  1167. });
  1168. result.sort(function (x, y) {
  1169. return x.serialNo() - y.serialNo();
  1170. });
  1171. if (result.length !== 0) {
  1172. //展开搜索出来的节点
  1173. expandSearchNodes(result);
  1174. //设置记住展开
  1175. sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
  1176. let sel = billsSheet.getSelections();
  1177. renderSheetFunc(billsSheet, function () {
  1178. bills.controller.setTreeSelected(result[0]);
  1179. billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  1180. billsInitSel(result[0].serialNo());
  1181. for (let node of result) {
  1182. billsSheet.getRange(node.serialNo(), -1, 1, -1).backColor('lemonChiffon');
  1183. }
  1184. });
  1185. //搜索初始定位
  1186. billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  1187. $('#nextBillsGuidance').show();
  1188. $('#nextBillsGuidance').unbind('click');
  1189. $('#nextBillsGuidance').bind('click', function () {
  1190. let cur = bills.tree.selected, resultIndex = result.indexOf(cur), sel = billsSheet.getSelections();
  1191. if (resultIndex === result.length - 1) {
  1192. bills.controller.setTreeSelected(result[0]);
  1193. billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  1194. billsInitSel(result[0].serialNo());
  1195. billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  1196. } else {
  1197. bills.controller.setTreeSelected(result[resultIndex + 1]);
  1198. billsSheet.setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
  1199. billsInitSel(result[resultIndex + 1].serialNo());
  1200. billsSheet.showRow(result[resultIndex + 1].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  1201. }
  1202. });
  1203. } else {
  1204. billsLibObj.clearHighLight(bills.workBook);
  1205. $('#nextBillsGuidance').hide();
  1206. }
  1207. $('#billsGuidanceSearchResultCount').text('搜索结果:' + result.length);
  1208. $('#billsGuidanceSearchResult').show();
  1209. });
  1210. //搜索框回车
  1211. $('#stdBillsGuidanceSearch>input').bind('keypress', function (event) {
  1212. if(event.keyCode === 13){
  1213. $(this).blur();
  1214. $('#stdBillsGuidanceSearch>div>button').click();
  1215. }
  1216. });
  1217. // 关闭搜索结果
  1218. $('#closeSearchBillsGuidance').click(function () {
  1219. $('#billsGuidanceSearchResult').hide();
  1220. billsLibObj.clearHighLight(bills.workBook);
  1221. refreshWorkBook();
  1222. });
  1223. }
  1224. //刷新表
  1225. //@return {void}
  1226. function refreshWorkBook(){
  1227. if(bills.workBook){
  1228. bills.workBook.refresh();
  1229. }
  1230. if(guideItem.workBook){
  1231. guideItem.workBook.refresh();
  1232. }
  1233. if(elfItem.workBook){
  1234. elfItem.workBook.refresh();
  1235. }
  1236. }
  1237. return {initViews, bindBtn, refreshWorkBook, refreshInsertRation, bills};
  1238. })();
  1239. $(document).ready(function(){
  1240. billsGuidance.bindBtn();
  1241. });