std_billsGuidance_lib.js 59 KB

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