std_billsGuidance_lib.js 57 KB

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