std_billsGuidance_lib.js 53 KB

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