std_billsGuidance_lib.js 59 KB

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