std_billsGuidance_lib.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  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. //点击清单名称后面的问号,弹出补注窗口并设置当前节点(或xxx父节点)的补注
  445. //@param {Number}row(当前焦点行) @return {void}
  446. function initRechargeModal(row) {
  447. let node = bills.tree.items[row];
  448. while (node && !node.data.recharge){
  449. node = node.parent;
  450. }
  451. let recharge = node && node.data.recharge ? node.data.recharge : '无内容';
  452. $('#billsQuestionContent').html(recharge);
  453. $('#billsQuestionModal').modal('show');
  454. }
  455. //初始化并输出树
  456. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  457. function initTree(module, sheet, treeSetting, datas){
  458. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  459. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting, false);
  460. module.tree.loadDatas(datas);
  461. if(module === bills){
  462. initExpandStat();
  463. }
  464. module.controller.showTreeData();
  465. if(module === bills){
  466. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  467. renderSheetFunc(sheet, function () {
  468. for(let i = 0; i < bills.tree.items.length; i++){
  469. sheet.setCellType(i, 1, TREE_SHEET_HELPER.getQuestionCellType(initRechargeModal));
  470. }
  471. });
  472. }
  473. }
  474. //项目指引表焦点控制
  475. //@param {Number}row @return {void}
  476. function guideItemInitSel(row){
  477. let billsNode = bills.tree.selected;
  478. let node = null;
  479. if(billsNode && billsNode.guidance.tree){
  480. node = billsNode.guidance.tree.items[row];
  481. if(node){
  482. billsNode.guidance.tree.selected = node;
  483. }
  484. }
  485. }
  486. //清单精灵表焦点控制
  487. //@param {Number}row @return {void}
  488. function elfItemInitSel(row){
  489. let billsNode = bills.tree.selected;
  490. let node = null;
  491. if(billsNode && billsNode.elf.tree){
  492. node = billsNode.elf.tree.items[row];
  493. if(node){
  494. billsNode.elf.tree.selected = node;
  495. }
  496. }
  497. }
  498. //根据项目指引的类型设置单元格类型,定额类型的项目指引为复选框
  499. //@param {Array}nodes @return {void}
  500. function setItemCellType(nodes){
  501. //设置单元格类型
  502. const base = new GC.Spread.Sheets.CellTypes.Base();
  503. const checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  504. const sheet = guideItem.workBook.getActiveSheet();
  505. renderSheetFunc(sheet, function(){
  506. for(let node of nodes){
  507. sheet.setCellType(node.serialNo(), 0, node.data.type === itemType.ration ? checkBox : base);
  508. }
  509. });
  510. }
  511. //清单表焦点控制
  512. //@param {Number}row @return {void}
  513. function billsInitSel(row){
  514. if(currentLib.type && currentLib.type === libType.elf){
  515. billsSelElf(row);
  516. }else {
  517. billsSelGuidance(row);
  518. }
  519. }
  520. //清单焦点变换-清单指引操作
  521. //@param {Number}row @return {void}
  522. function billsSelGuidance(row){
  523. let guideSheet = guideItem.workBook.getActiveSheet();
  524. cleanData(guideSheet, guideItem.headers, -1);
  525. if(!bills.tree){
  526. return;
  527. }
  528. let node = bills.tree.items[row];
  529. if(!node){
  530. return;
  531. }
  532. bills.tree.selected = node;
  533. refreshInsertRation();
  534. if(!node.guidance.tree){
  535. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
  536. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  537. setItemCellType(node.guidance.tree.items);
  538. //项目指引初始焦点
  539. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  540. });
  541. }
  542. else{
  543. node.guidance.controller.showTreeData();
  544. setItemCellType(node.guidance.tree.items);
  545. //项目指引初始焦点
  546. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  547. }
  548. }
  549. //清单焦点变换-清单精灵操作
  550. //@param {Number}row @return {void}
  551. function billsSelElf(row) {
  552. let elfSheet = elfItem.workBook.getActiveSheet();
  553. cleanData(elfSheet, elfItem.headers, -1);
  554. if(!bills.tree){
  555. return;
  556. }
  557. let node = bills.tree.items[row];
  558. if(!node){
  559. return;
  560. }
  561. bills.tree.selected = node;
  562. if(!node.elf.tree){
  563. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
  564. //定额数据删除编号信息
  565. for(let rData of rstData){
  566. if(rData.type === itemType.ration){
  567. let nameArr = rData.name.split(' ');
  568. if(nameArr.length > 0){
  569. nameArr.splice(0, 1);
  570. rData.name = nameArr.join(' ');
  571. }
  572. }
  573. }
  574. node.elf.datas = rstData;
  575. //第一层节点数据
  576. let firstLevelDatas = _.filter(rstData, function (data) {
  577. return data.ParentID == -1;
  578. });
  579. //第一层初始数据的选项显示
  580. for(let fData of firstLevelDatas){
  581. let options = getOptions(fData, rstData);
  582. fData.options = options.length > 0 ? options[0].name : '';
  583. //下挂的选项
  584. fData.optionsData = options && options.length > 0 ? _.cloneDeep(options) : [];
  585. fData.optionChecked = options && options.length > 0 ? [_.cloneDeep(options[0])] : [];
  586. }
  587. renderSheetFunc(elfSheet, function () {
  588. initTree(node.elf, elfSheet, elfItem.treeSetting, firstLevelDatas);
  589. //初始选择选项
  590. let initOptsOpr = [];
  591. for(let elfNode of node.elf.tree.items){
  592. if(elfNode.data.optionsData.length > 0){
  593. initOptsOpr.push({node: elfNode, data: elfNode.data.optionsData[0]});
  594. }
  595. }
  596. for(let opr of initOptsOpr){
  597. insertNodeByData(opr.node, opr.data);
  598. }
  599. TREE_SHEET_HELPER.refreshTreeNodeData(elfItem.treeSetting, elfSheet, node.elf.tree.items, false);
  600. setOptionsCellType(node.elf.tree.items);
  601. //项目指引初始焦点
  602. elfItemInitSel(elfSheet.getActiveRowIndex() ? elfSheet.getActiveRowIndex() : 0);
  603. refreshInsertRation();
  604. });
  605. });
  606. }
  607. else{
  608. renderSheetFunc(elfSheet, function () {
  609. node.elf.controller.showTreeData();
  610. setOptionsCellType(node.elf.tree.items);
  611. //项目指引初始焦点
  612. elfItemInitSel(elfSheet.getActiveRowIndex() ? elfSheet.getActiveRowIndex() : 0);
  613. refreshInsertRation();
  614. });
  615. }
  616. }
  617. //获取选项的深度
  618. //@param {Object}opt {Array}options(当前清单所有选项) @return {Array}
  619. function getOptionDepth(opt, options) {
  620. let parent = _.find(options, {ID: opt.ParentID});
  621. let depth = 0;
  622. while (parent){
  623. depth++;
  624. parent = _.find(options, {ID: parent.ParentID});
  625. }
  626. return depth;
  627. }
  628. //获取施工工序含有的选项(即当前施工工序的子项),获取的顺序按照NextSiblingID排序
  629. //@param {Object}process {Array}datas @return {Array}
  630. function getOptions(process, datas) {
  631. let rst = [];
  632. if(!process || !process.ID){
  633. return [];
  634. }
  635. let options = _.filter(datas, function (data) {
  636. return data.ParentID == process.ID;
  637. });
  638. if(options.length === 0){
  639. return [];
  640. }
  641. //根据NextSiblingID排序
  642. let IDMapping = {};
  643. for(let opt of options){
  644. IDMapping[opt.ID] = {self: opt, next: null, pre: null};
  645. }
  646. for(let opt of options){
  647. let next = IDMapping[opt.NextSiblingID] ? IDMapping[opt.NextSiblingID] : null;
  648. if(next){
  649. next.pre = IDMapping[opt.ID];
  650. IDMapping[opt.ID]['next'] = next;
  651. }
  652. }
  653. let first = null,
  654. rank = 0;
  655. for(let ID in IDMapping){
  656. let obj = IDMapping[ID];
  657. if(!obj.pre){
  658. first = obj;
  659. }
  660. }
  661. while(first){
  662. rank++;
  663. first.self.rank = rank;
  664. rst.push(first.self);
  665. first = first.next;
  666. }
  667. return rst;
  668. }
  669. //设置清单精灵选项单元格
  670. //@param {Array}nodes @return {void}
  671. function setOptionsCellType(nodes) {
  672. let elfSheet = elfItem.workBook.getActiveSheet();
  673. for(let node of nodes){
  674. if(node.data.optionsData && node.data.optionsData.length > 0){
  675. elfSheet.getCell(node.serialNo(), 1).locked(false).cellType(getOptionsCellType());
  676. }
  677. else {
  678. elfSheet.getCell(node.serialNo(), 1).locked(true).cellType(new GC.Spread.Sheets.CellTypes.Base());
  679. }
  680. }
  681. }
  682. //递归插入节点:原始项目指引数据奇数层为需要插入的节点,偶数层为下拉选项
  683. //@param {Object}node(当前操作的节点) {Object}data(选项) @return {void}
  684. function insertNodeByData(node, data) {
  685. let elfSheet = elfItem.workBook.getActiveSheet();
  686. let sameDepthNodes = node.children;
  687. let insertNextSiblingID = -1,
  688. insertParentID = node.data.ID;
  689. //当前操作节点的选项
  690. let nodeOpts = getOptions(node.data, bills.tree.selected.elf.datas);
  691. let subOpts = getOptions(data, bills.tree.selected.elf.datas);
  692. let dataDepth = getOptionDepth(data, bills.tree.selected.elf.datas);
  693. if(subOpts.length >0 && subOpts[0].type !== itemType.ration){
  694. if((dataDepth + 1) % 2 === 0){
  695. //排序后的数据
  696. let dataWithRank = _.find(nodeOpts, {ID: data.ID});
  697. //确定插入位置
  698. for(let subOpt of subOpts){
  699. for(let subNode of sameDepthNodes){
  700. //同层节点原本选项数据
  701. let subNodeOptData = _.find(bills.tree.selected.elf.datas, {ID: subNode.data.ID});
  702. //同层节点原本父选项数据
  703. let subNodeOptParent = _.find(bills.tree.selected.elf.datas, {ID: subNodeOptData.ParentID});
  704. let subNodeOptParentWithRank = _.find(nodeOpts, {ID: subNodeOptParent.ID});
  705. //父项顺序决定插入位置
  706. if(dataWithRank.rank < subNodeOptParentWithRank.rank){
  707. insertNextSiblingID = subNode.data.ID;
  708. break;
  709. }
  710. //父项顺序相同,根据子项顺序决定插入位置
  711. else if(dataWithRank.rank = subNodeOptParentWithRank.rank){
  712. if(subOpt.rank < subNode.data.rank){
  713. insertNextSiblingID = subNode.data.ID;
  714. break;
  715. }
  716. }
  717. }
  718. let sub2Opts = getOptions(subOpt, bills.tree.selected.elf.datas);
  719. subOpt.options = sub2Opts.length > 0 ? sub2Opts[0].name : '';
  720. let cloneOpt = _.cloneDeep(subOpt);//不改变原本的数据,比如ParentID
  721. cloneOpt.optionChecked = sub2Opts.length > 0 ? [_.cloneDeep(sub2Opts[0])] : [];
  722. cloneOpt.optionsData = sub2Opts.length > 0 ? _.cloneDeep(sub2Opts) : [];
  723. let newNode = node.tree.insertByData(cloneOpt, insertParentID, insertNextSiblingID);
  724. elfSheet.addRows(newNode.serialNo(), 1);
  725. node.tree.selected = newNode;
  726. elfSheet.setSelection(newNode.serialNo(), elfSheet.getSelections()[0].col, 1, 1);
  727. if(sub2Opts.length > 0 && sub2Opts[0].type !== itemType.ration){
  728. insertNodeByData(newNode, sub2Opts[0]);
  729. }
  730. }
  731. }
  732. else {
  733. insertNodeByData(node, subOpts[0]);
  734. }
  735. }
  736. }
  737. //获取选项下拉多选单元格
  738. //@param {void} @return {void}
  739. function getOptionsCellType() {
  740. let me = this;
  741. let elfSheet= elfItem.workBook.getActiveSheet();
  742. function OptionsCellType() {
  743. this.isEscKey=false;
  744. this.displayText='';
  745. }
  746. function setOptionsDiv($editor, node, cellRect, cellStyle, top) {
  747. if(!node){
  748. return '';
  749. }
  750. let height = cellRect.height;
  751. top = top.replace('px', '');
  752. let options = getOptions(node.data, bills.tree.selected.elf.datas);
  753. let $editInput = $(`<div style="height: ${height}px; background: ${cellStyle.backColor};overflow: hidden; white-space: nowrap; text-overflow: ellipsis">${node.data.options}</div>`),
  754. $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>`);
  755. for(let opt of options){
  756. let $opt = $(`<div title="${opt.name ? opt.name : ''}" class="elf-options" style="height: ${height}px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis"></div>`),
  757. $optInput = $(`<input rank="${opt.rank}" value="${opt.ID}" style="margin-left: 5px; vertical-align: middle" type="checkbox"
  758. ${node.data.optionChecked && _.find(node.data.optionChecked, {ID: opt.ID}) ? 'checked' : ''}>`);
  759. $opt.text(`${opt.name ? opt.name : ''}`);
  760. $opt.prepend($optInput);
  761. $optDiv.append($opt);
  762. //选项复选框点击监听
  763. $optInput.click(function () {
  764. //单选
  765. if(billsGuidanceSelMode === 0){
  766. let $allInput = $optDiv.find('input');
  767. for(let input of $allInput){
  768. $(input).prop('checked', false);
  769. }
  770. $(this).prop('checked', 'checked');
  771. elfItem.workBook.getSheet(0).endEdit();
  772. } else {//多选
  773. }
  774. });
  775. }
  776. $editor.append($editInput);
  777. $editor.append($optDiv);
  778. }
  779. //选择后处理
  780. function doAfterSel(node) {
  781. let checkedSels = $('.elf-options').find('input:checked');
  782. let checkedNameArr = [],
  783. optionChecked= [];
  784. for(let checkSel of checkedSels){
  785. let opt = _.cloneDeep(_.find(bills.tree.selected.elf.datas, {ID: $(checkSel).val()}));
  786. opt.rank = $(checkSel).attr('rank');
  787. checkedNameArr.push(opt.name);
  788. optionChecked.push(opt);
  789. }
  790. this.displayText = checkedNameArr.length > 0 ? checkedNameArr.join(';') : '';
  791. node.data.options = this.displayText;
  792. node.data.optionChecked = optionChecked;
  793. //删除节点
  794. let deleteNodes = getDeleteNodes(node, optionChecked);
  795. for(let dNode of deleteNodes){
  796. elfSheet.deleteRows(dNode.serialNo(), dNode.posterityCount() + 1);
  797. node.tree.delete(dNode);
  798. }
  799. //插入节点
  800. for(let perCheked of optionChecked){
  801. let exist = false;
  802. let subOpts = getOptions(perCheked, bills.tree.selected.elf.datas);
  803. for(let subNode of node.children){
  804. for(let subOpt of subOpts){
  805. if(subNode.data.ID === subOpt.ID){
  806. exist = true;
  807. break;
  808. }
  809. }
  810. }
  811. //不重复且不为定额时插入
  812. if(!exist && perCheked.type !== itemType.ration){
  813. insertNodeByData(node, perCheked);//这里递归,默认第一个
  814. }
  815. }
  816. TREE_SHEET_HELPER.refreshTreeNodeData(elfItem.treeSetting, elfSheet, node.tree.items, false);
  817. setOptionsCellType(node.tree.items);
  818. refreshInsertRation();
  819. }
  820. //获取删除节点
  821. function getDeleteNodes(node, optionChecked) {
  822. let rst = [];
  823. for(let subNode of node.children){
  824. let exist = false;
  825. for(let perChecked of optionChecked){
  826. let subOpts = getOptions(perChecked, bills.tree.selected.elf.datas);
  827. for(let subOpt of subOpts){
  828. if(subNode.data.ID === subOpt.ID){
  829. exist = true;
  830. break;
  831. }
  832. }
  833. }
  834. if(!exist){
  835. rst.push(subNode);
  836. }
  837. }
  838. return rst;
  839. }
  840. OptionsCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
  841. OptionsCellType.prototype.createEditorElement = function (context) {
  842. let element = document.createElement("div");//这里创建的,会自动销毁
  843. return element
  844. };
  845. OptionsCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
  846. if (editorContext) {
  847. let $editor = $(editorContext);
  848. $editor.css("position", "fixed");
  849. $editor.css("background", "white");
  850. $editor.css("width", cellRect.width);
  851. $editor.attr("gcUIElement", "gcEditingInput");
  852. let activeCellTop = $editor.parent().parent().css('top');
  853. let node = bills.tree.selected.elf.tree.items[elfSheet.getActiveRowIndex()];
  854. setOptionsDiv($editor, node, cellRect, cellStyle, activeCellTop);
  855. this.isEscKey = false;
  856. }
  857. }
  858. OptionsCellType.prototype.deactivateEditor = function (editorContext, context) {
  859. };
  860. OptionsCellType.prototype.setEditorValue = function (editor, value, context) {
  861. this.displayText = value;
  862. };
  863. OptionsCellType.prototype.getEditorValue = function (editor, context) {
  864. let me = this;
  865. let node = bills.tree.selected.elf.tree.items[elfSheet.getActiveRowIndex()];
  866. if(this.isEscKey !=true){
  867. renderSheetFunc(elfSheet, function () {
  868. doAfterSel.call(me, node);
  869. });
  870. }
  871. this.isEscKey = false;
  872. return this.displayText;
  873. };
  874. OptionsCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
  875. };
  876. OptionsCellType.prototype.isReservedKey = function (e, context) {
  877. //cell type handle tab key by itself
  878. this.isEscKey = e.keyCode === GC.Spread.Commands.Key.esc;
  879. return false;
  880. };
  881. /* OptionsCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  882. if(style.backColor){
  883. ctx.fillStyle = style.backColor;
  884. ctx.fillRect(x, y, w, h);
  885. ctx.save();
  886. }
  887. //边长
  888. const l = 7;
  889. let leftPointX = x + w - 15,
  890. rightPointX = leftPointX + l,
  891. middlePointX = (leftPointX + rightPointX)/2;
  892. const cos30 = Math.cos(2*Math.PI * 30 / 360);
  893. let hL = l * cos30;
  894. let beginY = y + h/2 - hL;
  895. ctx.beginPath();
  896. ctx.moveTo(leftPointX, beginY);
  897. ctx.lineTo(rightPointX, beginY);
  898. ctx.lineTo(middlePointX, beginY + hL);
  899. ctx.fillStyle = 'black';
  900. ctx.fill();
  901. ctx.save();
  902. };*/
  903. // override getHitInfo to allow cell type get mouse messages
  904. OptionsCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  905. return {
  906. x: x,
  907. y: y,
  908. row: context.row,
  909. col: context.col,
  910. cellStyle: cellStyle,
  911. cellRect: cellRect,
  912. sheetArea: context.sheetArea
  913. };
  914. };
  915. return new OptionsCellType();
  916. }
  917. //初始化清单的工作内容和项目特征
  918. //@param {Number}billsLibId {Function}callback @return {void}
  919. function initJobAndCharacter(billsLibId, callback){
  920. CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: billsLibId}, function (datas) {
  921. stdBillsJobData = datas;
  922. CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: billsLibId}, function (datas) {
  923. stdBillsFeatureData = datas;
  924. if(callback){
  925. callback();
  926. }
  927. });
  928. });
  929. }
  930. //初始化清单展开收起状态
  931. //@return {void}
  932. function initExpandStat(){
  933. //读取展开收起状态
  934. let currentExpState = sessionStorage.getItem('stdBillsGuidanceExpState');
  935. if(currentExpState){
  936. bills.tree.setExpandedByState(bills.tree.items, currentExpState);
  937. }
  938. //非叶子节点默认收起
  939. else{
  940. bills.tree.setRootExpanded(bills.tree.roots, false);
  941. }
  942. }
  943. //设置tag以悬浮提示
  944. function setTagForHint(nodes){
  945. let sheet = bills.workBook.getActiveSheet();
  946. renderSheetFunc(sheet, function () {
  947. for(let node of nodes){
  948. sheet.setTag(node.serialNo(), 2, node.data.ruleText ? node.data.ruleText : '');
  949. }
  950. });
  951. }
  952. //根据编码定位至清单精灵库中
  953. //@param {String}code @return {void}
  954. function locateAtBills(code) {
  955. let nineCode = code.substring(0, 9);
  956. let items = bills.tree.items;
  957. let locateBills = _.find(items, function(item){
  958. return item.data.code === nineCode;
  959. });
  960. if(locateBills){
  961. expandSearchNodes([locateBills]);
  962. sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
  963. }
  964. let sheet = bills.workBook.getActiveSheet();
  965. let locateRow = locateBills ? locateBills.serialNo() : 0;
  966. sheet.setActiveCell(locateRow, 0);
  967. billsInitSel(locateRow);
  968. sheet.showRow(locateRow, GC.Spread.Sheets.VerticalPosition.center);
  969. }
  970. //清单设置悬浮提示信息
  971. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  972. function setBillsHint(billsNodes, jobs, items) {
  973. let jobsMapping = {},
  974. itemsMapping = {};
  975. for(let job of jobs){
  976. jobsMapping[job.id] = job;
  977. }
  978. for(let item of items){
  979. itemsMapping[item.id] = item;
  980. }
  981. let tagInfo = [];
  982. for(let billsNode of billsNodes){
  983. let hintArr = [];
  984. let billsItems = billsNode.data.items;
  985. if(billsItems.length > 0){
  986. //项目特征
  987. hintArr.push('项目特征:');
  988. }
  989. let itemCount = 1,
  990. jobCount = 1;
  991. for(let billsItem of billsItems){
  992. let itemData = itemsMapping[billsItem.id];
  993. if(itemData){
  994. //特征值
  995. let eigens = [];
  996. for(let eigen of itemData.itemValue){
  997. eigens.push(eigen.value);
  998. }
  999. eigens = eigens.join(';');
  1000. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  1001. itemCount ++;
  1002. }
  1003. }
  1004. //工作内容
  1005. let billsJobs = billsNode.data.jobs;
  1006. if(billsJobs.length > 0){
  1007. hintArr.push('工作内容:');
  1008. }
  1009. for(let billsJob of billsJobs){
  1010. let jobData = jobsMapping[billsJob.id];
  1011. if(jobData){
  1012. hintArr.push(`${jobCount}.${jobData.content}`);
  1013. jobCount ++;
  1014. }
  1015. }
  1016. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  1017. hintArr.push('工程量计算规则:');
  1018. hintArr.push(billsNode.data.ruleText);
  1019. }
  1020. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  1021. hintArr.push('补注:');
  1022. hintArr.push(billsNode.data.recharge);
  1023. }*/
  1024. if(hintArr.length > 0){
  1025. tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
  1026. }
  1027. }
  1028. let sheet = bills.workBook.getActiveSheet();
  1029. renderSheetFunc(sheet, function () {
  1030. for(let tagI of tagInfo){
  1031. sheet.setTag(tagI.row, 0, tagI.value);
  1032. }
  1033. });
  1034. }
  1035. //初始选择清单指引库
  1036. //@param {Number}libID @return {void}
  1037. function libInitSel(libID){
  1038. //获取清单
  1039. $.bootstrapLoading.start();
  1040. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function(rstData){
  1041. currentLib = rstData.guidanceLib;
  1042. if(guideItem.workBook){
  1043. guideItem.workBook.destroy();
  1044. guideItem.workBook = null;
  1045. }
  1046. if(elfItem.workBook){
  1047. elfItem.workBook.destroy();
  1048. elfItem.workBook = null;
  1049. }
  1050. initViews();
  1051. let callback = function () {
  1052. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
  1053. //清单精灵
  1054. if(rstData.guidanceLib.type && rstData.guidanceLib.type == libType.elf){
  1055. $('#stdBillsGuidanceTab').text('清单精灵');
  1056. //每一个清单节点下挂载一棵清单精灵树
  1057. for(let node of bills.tree.items){
  1058. node.elf = {tree: null, controller: null, datas: []}; //挂载全部数据,数据不一定全成为树节点
  1059. }
  1060. }
  1061. //清单指引
  1062. else {
  1063. $('#stdBillsGuidanceTab').text('清单指引');
  1064. //每一棵项目指引树挂在清单节点上
  1065. for(let node of bills.tree.items){
  1066. node.guidance = {tree: null, controller: null};
  1067. }
  1068. }
  1069. //setTagForHint(bills.tree.items);
  1070. //默认初始节点
  1071. billsInitSel(0);
  1072. if(doAfterLoadGuidance){
  1073. doAfterLoadGuidance();
  1074. }
  1075. $.bootstrapLoading.end();
  1076. };
  1077. //获取清单库中的工作内容和项目特征
  1078. initJobAndCharacter(rstData.guidanceLib.billsLibId, callback);
  1079. }, function () {
  1080. $.bootstrapLoading.end();
  1081. });
  1082. }
  1083. //初始化清单指引库
  1084. //@param {Array}libDats @return {void}
  1085. function initLibs(libDatas){
  1086. libSel.empty();
  1087. if(!libDatas){
  1088. return;
  1089. }
  1090. let selectedLib = sessionStorage.getItem('stdBillsGuidance');
  1091. for(let libData of libDatas){
  1092. let opt = $('<option>').val(libData.id).text(libData.name);
  1093. if(selectedLib && libData.id == selectedLib){
  1094. opt.attr('selected', 'selected');
  1095. }
  1096. libSel.append(opt);
  1097. }
  1098. //初始默认选择
  1099. libInitSel(libSel.select().val());
  1100. }
  1101. //初始化视图
  1102. //@param {void} @return {void}
  1103. function initViews(){
  1104. //赋初始高度
  1105. if($('#billsGuidance_bills').height() === 0 || $('#billsGuidance_items').height() === 0){
  1106. let height = $(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-z").height();
  1107. $('#billsGuidance_bills').height(height / 2);
  1108. $('#billsGuidance_items').height(height / 2);
  1109. }
  1110. let modules = [bills];
  1111. if(currentLib.type && currentLib.type === libType.elf){
  1112. modules.push(elfItem);
  1113. }
  1114. else {
  1115. modules.push(guideItem);
  1116. }
  1117. initWorkBooks(modules);
  1118. }
  1119. //获取选中的行
  1120. //@return {Array}
  1121. function getCheckedRows(){
  1122. let rst = [];
  1123. let itemSheet = guideItem.workBook.getActiveSheet();
  1124. for(let row = 0; row < itemSheet.getRowCount(); row++){
  1125. let rowV = itemSheet.getValue(row, 0);
  1126. if(rowV){
  1127. rst.push(row);
  1128. }
  1129. }
  1130. return rst;
  1131. }
  1132. //获取清单精灵生成的定额数据
  1133. //@return {Array}
  1134. function getInsertElfRationData(){
  1135. let rst = [];
  1136. if(!bills.tree.selected){
  1137. return [];
  1138. }
  1139. if(!bills.tree.selected.elf){
  1140. return [];
  1141. }
  1142. let tree = bills.tree.selected.elf.tree;
  1143. if(!tree){
  1144. return [];
  1145. }
  1146. for(let node of tree.items){
  1147. for(let perChecked of node.data.optionChecked){
  1148. //选项直接是定额
  1149. if(perChecked.type === itemType.ration){
  1150. rst.push({itemQuery: {userID: userID, ID: perChecked.rationID}, rationType: rationType.ration});
  1151. }
  1152. //选项下子选项是定额
  1153. else {
  1154. let rationOpts = getOptions(perChecked, bills.tree.selected.elf.datas);
  1155. for(let ration of rationOpts){
  1156. if(ration.type === itemType.ration){
  1157. rst.push({itemQuery: {userID: userID, ID: ration.rationID}, rationType: rationType.ration});
  1158. }
  1159. }
  1160. }
  1161. }
  1162. }
  1163. return rst;
  1164. }
  1165. //获取选中的定额数据
  1166. //@param {Array}rows @return {Array}
  1167. function getInsertRationData(rows){
  1168. let rst = [];
  1169. for(let row of rows){
  1170. let node = bills.tree.selected.guidance.tree.items[row];
  1171. if(node && node.data.type === itemType.ration){
  1172. rst.push({itemQuery: {userID: userID, ID: node.data.rationID}, rationType: rationType.ration});
  1173. }
  1174. }
  1175. return rst;
  1176. }
  1177. //插入定额
  1178. //@return {void}
  1179. function insertRations(addRationDatas){
  1180. if(addRationDatas.length > 0){
  1181. projectObj.project.Ration.addMultiRation(addRationDatas, function () {
  1182. //恢复
  1183. if(!currentLib.type || currentLib.type === libType.guidance){
  1184. let sheet = guideItem.workBook.getActiveSheet();
  1185. renderSheetFunc(sheet, function () {
  1186. for(let row = 0; row < sheet.getRowCount(); row++){
  1187. if(sheet.getValue(row, 0)){
  1188. sheet.setValue(row, 0, false);
  1189. }
  1190. }
  1191. });
  1192. }
  1193. refreshInsertRation();
  1194. projectObj.setActiveCell('quantity', true);
  1195. });
  1196. }
  1197. }
  1198. //更新插入定额按钮有效性
  1199. function refreshInsertRation(){
  1200. if(currentLib.type && currentLib.type === libType.elf){
  1201. if(getInsertElfRationData().length > 0){
  1202. $('#guidanceInsertRation').removeClass('disabled');
  1203. }
  1204. else {
  1205. $('#guidanceInsertRation').addClass('disabled');
  1206. }
  1207. }
  1208. else {
  1209. //勾选了定额,插入定额按钮才有效
  1210. if(getCheckedRows().length > 0){
  1211. $('#guidanceInsertRation').removeClass('disabled');
  1212. }
  1213. else {
  1214. $('#guidanceInsertRation').addClass('disabled');
  1215. }
  1216. }
  1217. }
  1218. //展开至搜索出来点的节点
  1219. //@param {Array}nodes @return {void}
  1220. function expandSearchNodes(nodes){
  1221. let that = this;
  1222. let billsSheet = bills.workBook.getActiveSheet();
  1223. renderSheetFunc(billsSheet, function () {
  1224. function expParentNode(node){
  1225. if(node.parent && !node.parent.expanded){
  1226. node.parent.setExpanded(true);
  1227. expParentNode(node.parent);
  1228. }
  1229. }
  1230. for(let node of nodes){
  1231. expParentNode(node);
  1232. }
  1233. TREE_SHEET_HELPER.refreshTreeNodeData(bills.treeSetting, billsSheet, bills.tree.roots, true);
  1234. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billsSheet, true);
  1235. });
  1236. }
  1237. //各按钮监听事件
  1238. //@return {void}
  1239. function bindBtn(){
  1240. //打开清单指引库
  1241. $('#stdBillsGuidanceTab').click(function () {
  1242. if(libSel.children().length === 0 && !projectReadOnly && !$(this).hasClass('disabled')){
  1243. initLibs(projectInfoObj.projectInfo.engineeringInfo.billsGuidance_lib);
  1244. }
  1245. });
  1246. //更改清单指引库
  1247. $('#stdBillsGuidanceLibSelect').change(function () {
  1248. //关闭搜索窗口
  1249. $('#billsGuidanceSearchResult').hide();
  1250. billsLibObj.clearHighLight(bills.workBook);
  1251. libInitSel($(this).select().val());
  1252. //记住选项
  1253. sessionStorage.setItem('stdBillsGuidance', $(this).select().val());
  1254. //清除展开收起状态sessionStorage
  1255. sessionStorage.removeItem('stdBillsGuidanceExpState');
  1256. });
  1257. //插入定额
  1258. $('#guidanceInsertRation').click(function () {
  1259. let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
  1260. insertRations(addRationDatas);
  1261. });
  1262. //插入清单
  1263. $('#guidanceInsertBills').click(function () {
  1264. //插入清单
  1265. if(!bills.tree || !bills.tree.selected){
  1266. return;
  1267. }
  1268. if(bills.tree.selected.children.length === 0){
  1269. let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, bills.tree.selected);
  1270. /*if(insert){
  1271. //插入选中的定额
  1272. let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
  1273. insertRations(addRationDatas);
  1274. }*/
  1275. }
  1276. });
  1277. //插入清单和定额
  1278. $('#guidanceInsertBillsAndRation').click(function () {
  1279. //插入清单
  1280. if(!bills.tree || !bills.tree.selected){
  1281. return;
  1282. }
  1283. if(bills.tree.selected.children.length === 0){
  1284. let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, bills.tree.selected);
  1285. if(insert){
  1286. //插入选中的定额
  1287. let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
  1288. insertRations(addRationDatas);
  1289. }
  1290. }
  1291. });
  1292. //搜索
  1293. $('#stdBillsGuidanceSearch>div>button').click(function () {
  1294. if(!bills.tree){
  1295. return;
  1296. }
  1297. let billsSheet = bills.workBook.getActiveSheet();
  1298. billsLibObj.clearHighLight(bills.workBook);
  1299. let keyword = $('#stdBillsGuidanceSearch>input').val();
  1300. if (!keyword || keyword === '') {
  1301. $('#billsGuidanceSearchResult').hide();
  1302. return;
  1303. }
  1304. let result = bills.tree.items.filter(function (item) {
  1305. let codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
  1306. let nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
  1307. return codeIs || nameIs;
  1308. });
  1309. result.sort(function (x, y) {
  1310. return x.serialNo() - y.serialNo();
  1311. });
  1312. if (result.length !== 0) {
  1313. //展开搜索出来的节点
  1314. expandSearchNodes(result);
  1315. //设置记住展开
  1316. sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
  1317. let sel = billsSheet.getSelections();
  1318. renderSheetFunc(billsSheet, function () {
  1319. bills.controller.setTreeSelected(result[0]);
  1320. billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  1321. billsInitSel(result[0].serialNo());
  1322. for (let node of result) {
  1323. billsSheet.getRange(node.serialNo(), -1, 1, -1).backColor('lemonChiffon');
  1324. }
  1325. });
  1326. //搜索初始定位
  1327. billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  1328. $('#nextBillsGuidance').show();
  1329. $('#nextBillsGuidance').unbind('click');
  1330. $('#nextBillsGuidance').bind('click', function () {
  1331. let cur = bills.tree.selected, resultIndex = result.indexOf(cur), sel = billsSheet.getSelections();
  1332. if (resultIndex === result.length - 1) {
  1333. bills.controller.setTreeSelected(result[0]);
  1334. billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
  1335. billsInitSel(result[0].serialNo());
  1336. billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  1337. } else {
  1338. bills.controller.setTreeSelected(result[resultIndex + 1]);
  1339. billsSheet.setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
  1340. billsInitSel(result[resultIndex + 1].serialNo());
  1341. billsSheet.showRow(result[resultIndex + 1].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
  1342. }
  1343. });
  1344. } else {
  1345. billsLibObj.clearHighLight(bills.workBook);
  1346. $('#nextBillsGuidance').hide();
  1347. }
  1348. $('#billsGuidanceSearchResultCount').text('搜索结果:' + result.length);
  1349. $('#billsGuidanceSearchResult').show();
  1350. });
  1351. //搜索框回车
  1352. $('#stdBillsGuidanceSearch>input').bind('keypress', function (event) {
  1353. if(event.keyCode === 13){
  1354. $(this).blur();
  1355. $('#stdBillsGuidanceSearch>div>button').click();
  1356. }
  1357. });
  1358. // 关闭搜索结果
  1359. $('#closeSearchBillsGuidance').click(function () {
  1360. $('#billsGuidanceSearchResult').hide();
  1361. billsLibObj.clearHighLight(bills.workBook);
  1362. refreshWorkBook();
  1363. });
  1364. //监听alt建,确定选项单选多选状态
  1365. /* $('#billsGuidance_items').keydown(function(e){
  1366. if(e.keyCode === 18){
  1367. billsGuidanceSelMode = 1;
  1368. }
  1369. });
  1370. $('#billsGuidance_items').keyup(function(e){
  1371. if(e.keyCode === 18){
  1372. billsGuidanceSelMode = 0;
  1373. }
  1374. });*/
  1375. }
  1376. //刷新表
  1377. //@return {void}
  1378. function refreshWorkBook(){
  1379. if(bills.workBook){
  1380. bills.workBook.refresh();
  1381. }
  1382. if(guideItem.workBook){
  1383. guideItem.workBook.refresh();
  1384. }
  1385. if(elfItem.workBook){
  1386. elfItem.workBook.refresh();
  1387. }
  1388. }
  1389. return {initViews, bindBtn, refreshWorkBook, refreshInsertRation, setColumnWidthByRate, locateAtBills, bills, elfItem};
  1390. })();
  1391. $(document).ready(function(){
  1392. billsGuidance.bindBtn();
  1393. });