std_billsGuidance_lib.js 57 KB

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