std_billsGuidance_lib.js 56 KB

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