billsGuidance.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/6/1
  7. * @version
  8. */
  9. const billsGuidance = (function () {
  10. function _isDef(v) {
  11. return typeof v !== 'undefined' && v !== null;
  12. }
  13. //自执行函数全局变量定义
  14. const libID = getQueryString('libID');
  15. //总工作内容数据
  16. let stdBillsJobData = [];
  17. //总项目特征数据
  18. let stdBillsFeatureData = [];
  19. const bills = {
  20. dom: $('#billsSpread'),
  21. workBook: null,
  22. cache: [],
  23. tree: null,
  24. controller: null,
  25. treeSetting: {
  26. treeCol: 0,
  27. emptyRows: 0,
  28. headRows: 1,
  29. headRowHeight: [40],
  30. defaultRowHeight: 21,
  31. cols: [{
  32. width: 200,
  33. readOnly: true,
  34. showHint: true,
  35. head: {
  36. titleNames: ["项目编码"],
  37. spanCols: [1],
  38. spanRows: [1],
  39. vAlign: [1],
  40. hAlign: [1],
  41. font: ["Arial"]
  42. },
  43. data: {
  44. field: "code",
  45. vAlign: 1,
  46. hAlign: 0,
  47. font: "Arial"
  48. }
  49. }, {
  50. width: 200,
  51. readOnly: true,
  52. head: {
  53. titleNames: ["项目名称"],
  54. spanCols: [1],
  55. spanRows: [1],
  56. vAlign: [1],
  57. hAlign: [1],
  58. font: ["Arial"]
  59. },
  60. data: {
  61. field: "name",
  62. vAlign: 1,
  63. hAlign: 0,
  64. font: "Arial"
  65. }
  66. }]
  67. },
  68. headers: [
  69. {name: '项目编码', dataCode: 'code', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'},
  70. {name: '项目名称', dataCode: 'name', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'}
  71. ],
  72. events: {
  73. SelectionChanged: function (sender, info) {
  74. billsInitSel(info.newSelections[0].row);
  75. }
  76. }
  77. };
  78. //项目指引类型
  79. const itemType = {
  80. job: 0,
  81. ration: 1
  82. };
  83. //项目指引复制整块localStorage key
  84. const itemCopyBlockKey = 'guideItemCopyBlock';
  85. const updateType = {
  86. create: 'create',
  87. update: 'update',
  88. del: 'delete'
  89. };
  90. //项目指引节点状态:展开全部、收起定额
  91. const itemExpandState = {
  92. expand: 1,
  93. contract: 0
  94. };
  95. //项目指引当前节点展开收缩状态,默认展开全部
  96. let curExpandState = 1;
  97. const guideItem = {
  98. dom: $('#guideItemSpread'),
  99. workBook: null,
  100. tree: null,
  101. controller: null,
  102. treeSetting: {
  103. treeCol: 0,
  104. emptyRows: 0,
  105. headRows: 1,
  106. headRowHeight: [40],
  107. defaultRowHeight: 21,
  108. cols: [{
  109. width: 400,
  110. readOnly: false,
  111. head: {
  112. titleNames: ["项目指引"],
  113. spanCols: [1],
  114. spanRows: [1],
  115. vAlign: [1],
  116. hAlign: [1],
  117. font: ["Arial"]
  118. },
  119. data: {
  120. field: "name",
  121. vAlign: 1,
  122. hAlign: 0,
  123. font: "Arial"
  124. }
  125. }]
  126. },
  127. headers: [
  128. {name: '项目指引', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  129. ],
  130. events: {
  131. SelectionChanged: function (sender, info) {
  132. guideItemInitSel(info.newSelections[0].row)
  133. },
  134. EditEnded: function (sender, args) {
  135. edit(args.sheet, [{row: args.row, col: args.col}]);
  136. },
  137. RangeChanged: function (sender, args) {
  138. edit(args.sheet, args.changedCells);
  139. }
  140. }
  141. };
  142. //定额章节树
  143. const section = {
  144. dom: $('#sectionSpread'),
  145. workBook: null,
  146. cache: [],
  147. tree: null,
  148. controller: null,
  149. treeSetting: {
  150. treeCol: 0,
  151. emptyRows: 0,
  152. headRows: 1,
  153. headRowHeight: [40],
  154. defaultRowHeight: 21,
  155. cols: [{
  156. width: 400,
  157. readOnly: true,
  158. head: {
  159. titleNames: ["名称"],
  160. spanCols: [1],
  161. spanRows: [1],
  162. vAlign: [1],
  163. hAlign: [1],
  164. font: ["Arial"]
  165. },
  166. data: {
  167. field: "name",
  168. vAlign: 1,
  169. hAlign: 0,
  170. font: "Arial"
  171. }
  172. }]
  173. },
  174. headers: [
  175. {name: '名称', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  176. ],
  177. events: {
  178. SelectionChanged: function (sender, info) {
  179. sectionInitSel(info.newSelections[0].row)
  180. }
  181. }
  182. };
  183. const ration = {
  184. dom: $('#rationSpread'),
  185. workBook: null,
  186. datas: [],//所有的数据,搜索定额时,从所有数据中筛选
  187. cache: [],//显示在表格上的数据,添加定额可以有效根据行识别定额
  188. headers: [
  189. {name: '选择', dataCode: 'select', width: 50, vAlign: 'center', hAlign: 'center'},
  190. {name: '编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
  191. {name: '名称', dataCode: 'name', width: 250, vAlign: 'center', hAlign: 'left', formatter: '@'},
  192. {name: '单位', dataCode: 'unit', width: 100, vAlign: 'center', hAlign: 'left', formatter: '@'}
  193. ],
  194. events: {
  195. ButtonClicked: function (sender, args) {
  196. if(args.sheet.isEditing()){
  197. args.sheet.endEdit(true);
  198. }
  199. },
  200. CellDoubleClick: function (sender, args) {
  201. if(ration.headers[args.col].dataCode === 'name'){
  202. let insertDatas = getInsertRations([args.row]);
  203. if(insertDatas.length > 0){
  204. insert(insertDatas, false);
  205. }
  206. }
  207. }
  208. }
  209. };
  210. const options = {
  211. workBook: {
  212. tabStripVisible: false,
  213. allowContextMenu: false,
  214. allowCopyPasteExcelStyle : false,
  215. allowExtendPasteRange: false,
  216. allowUserDragDrop : false,
  217. allowUserDragFill: false,
  218. scrollbarMaxAlign : true
  219. },
  220. sheet: {
  221. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  222. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  223. }
  224. };
  225. //渲染时方法,停止渲染
  226. //@param {Object}sheet {Function}func @return {void}
  227. function renderSheetFunc(sheet, func){
  228. sheet.suspendEvent();
  229. sheet.suspendPaint();
  230. if(func){
  231. func();
  232. }
  233. sheet.resumeEvent();
  234. sheet.resumePaint();
  235. }
  236. //设置表选项
  237. //@param {Object}workBook {Object}opts @return {void}
  238. function setOptions (workBook, opts) {
  239. for(let opt in opts.workBook){
  240. workBook.options[opt] = opts.workBook[opt];
  241. }
  242. for(let opt in opts.sheet){
  243. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  244. }
  245. }
  246. //建表头
  247. //@param {Object}sheet {Array}headers @return {void}
  248. function buildHeader(sheet, headers) {
  249. let fuc = function () {
  250. sheet.setColumnCount(headers.length);
  251. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  252. for(let i = 0, len = headers.length; i < len; i++){
  253. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  254. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  255. if(headers[i].formatter){
  256. sheet.setFormatter(-1, i, headers[i].formatter);
  257. }
  258. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  259. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  260. }
  261. };
  262. renderSheetFunc(sheet, fuc);
  263. }
  264. //表监听事件
  265. //@param {Object}workBook @return {void}
  266. function bindEvent(workBook, events) {
  267. if(Object.keys(events).length === 0){
  268. return;
  269. }
  270. const Events = GC.Spread.Sheets.Events;
  271. let sheet = workBook.getActiveSheet();
  272. for(let event in events){
  273. workBook.bind(Events[event], events[event]);
  274. }
  275. }
  276. //建表
  277. //@param {Object}module @return {void}
  278. function buildSheet(module) {
  279. if(!module.workBook){
  280. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  281. let sheet = module.workBook.getActiveSheet();
  282. if(module === bills){
  283. sheet.name('stdBillsGuidance_bills');
  284. //默认初始可控制焦点在清单表中
  285. module.workBook.focus();
  286. sheet.options.isProtected = true;
  287. }
  288. else if(module === ration){
  289. sheet.options.isProtected = true;
  290. sheet.getRange(-1, 0, -1, 1).locked(false);
  291. sheet.getRange(-1, 1, -1, -1).locked(true);
  292. }
  293. else if(module === guideItem){
  294. sheetCommonObj.bindEscKey(module.workBook, [{sheet: sheet, editStarting: null, editEnded: module.events.EditEnded}]);
  295. }
  296. setOptions(module.workBook, options);
  297. buildHeader(module.workBook.getActiveSheet(), module.headers);
  298. bindEvent(module.workBook, module.events);
  299. }
  300. }
  301. //清空表数据
  302. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  303. function cleanData(sheet, headers, rowCount){
  304. renderSheetFunc(sheet, function () {
  305. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  306. if (rowCount >= 0) {
  307. sheet.setRowCount(rowCount);
  308. }
  309. });
  310. }
  311. //根据清单获取项目指引
  312. //@param {String}guidanceLibID {Number}billsID {Function}callback @return {void}
  313. function getItemsByBills(guidanceLibID, billsID, callback){
  314. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: guidanceLibID, billsID: billsID}, function (rstData) {
  315. if(callback){
  316. callback(rstData);
  317. }
  318. });
  319. }
  320. //清单表焦点控制
  321. //@param {Number}row @return {void}
  322. function billsInitSel(row){
  323. let guideSheet = guideItem.workBook.getActiveSheet();
  324. cleanData(guideSheet, guideItem.headers, -1);
  325. let node = bills.tree.items[row];
  326. if(!node){
  327. return;
  328. }
  329. bills.tree.selected = node;
  330. if(!node.guidance.tree){
  331. getItemsByBills(libID, node.data.ID, function (rstData) {
  332. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  333. setNodesExpandState(node.guidance.tree.items, curExpandState);
  334. renderSheetFunc(guideSheet, function () {
  335. TREE_SHEET_HELPER.refreshNodesVisible(node.guidance.tree.roots, guideSheet, true);
  336. });
  337. //设置底色
  338. setNodesColor(guideSheet, node.guidance.tree.items);
  339. //项目指引初始焦点
  340. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  341. });
  342. } else{
  343. setNodesExpandState(node.guidance.tree.items, curExpandState);
  344. node.guidance.controller.showTreeData();
  345. //设置底色
  346. setNodesColor(guideSheet, node.guidance.tree.items);
  347. //项目指引初始焦点
  348. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  349. }
  350. }
  351. //设置项目节点展开收起状态:展开全部、收起定额
  352. //@param {Array}nodes(当前清单下的所有项目指引节点) {Number}expandState(展开全部1或收起定额0).
  353. function setNodesExpandState(nodes, expandState) {
  354. if(expandState === itemExpandState.contract) {
  355. //找出所有定额的父节点
  356. let rations = _.filter(nodes, function (node) {
  357. return node.data.type === itemType.ration;
  358. });
  359. let rationParentIDs = [];
  360. for(let ration of rations){
  361. if(ration.data.ParentID != -1){
  362. rationParentIDs.push(ration.data.ParentID);
  363. }
  364. }
  365. rationParentIDs = Array.from(new Set(rationParentIDs));
  366. let rationParentNodes = _.filter(nodes, function (node) {
  367. return rationParentIDs.includes(node.data.ID);
  368. });
  369. //收起定额
  370. for(let node of rationParentNodes){
  371. node.setExpanded(false);
  372. }
  373. } else {
  374. for(let node of nodes){
  375. node.setExpanded(true);
  376. }
  377. }
  378. }
  379. //根据奇偶层级设置节点底色,奇数层为蓝色(树节点深度为偶数)
  380. //@param {Object}sheet {Array}nodes @return {void}
  381. function setNodesColor(sheet, nodes) {
  382. const color = '#DFE8F9';
  383. renderSheetFunc(sheet, function () {
  384. for(let node of nodes){
  385. let style = new GC.Spread.Sheets.Style();
  386. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  387. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  388. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  389. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  390. let nDepth = node.depth();
  391. style.backColor = nDepth % 2 == 0 && _isDef(node.data.type) && node.data.type === itemType.job ? color : 'White';
  392. sheet.setStyle(node.serialNo(), -1, style);
  393. }
  394. });
  395. }
  396. //选中的节点是否全是同层节点
  397. //@param {Object}sheet {Array}items @return {Boolean}
  398. function itemsSameDepth(sheet, items) {
  399. let sels = sheet.getSelections();
  400. if(sels.length === 0 || items.length === 0){
  401. return false;
  402. }
  403. let depths = [];
  404. for(let i = 0; i < sels[0].rowCount; i++){
  405. let row = sels[0].row + i;
  406. let node = items[row];
  407. if(node){
  408. depths.push(node.depth());
  409. }
  410. }
  411. }
  412. //节点子项是否全是工作内容
  413. //@param {Object}node @return {Boolean}
  414. function allJobChildren(node){
  415. for(let c of node.children){
  416. if(c.data.type === itemType.ration){
  417. return false;
  418. }
  419. }
  420. return true;
  421. }
  422. //节点子项是否全是定额
  423. //@param {Object}node @return {Boolean}
  424. function allRationChildren(node){
  425. for(let c of node.children){
  426. if(c.data.type === itemType.job){
  427. return false;
  428. }
  429. }
  430. return true;
  431. }
  432. //刷新按钮有效性
  433. //@param {Object}node @return {void}
  434. function refreshBtn(node){
  435. //全部设为无效
  436. $('.tools-btn').children().addClass('disabled');
  437. $('#insertRation').addClass('disabled');
  438. $('.main-bottom-content').find('textarea').attr('readonly', true);
  439. //插入
  440. if(bills.tree.selected && bills.tree.selected.guidance.tree){
  441. $('#insert').removeClass('disabled');
  442. if(node && node.data.type === itemType.ration){
  443. $('#insert').addClass('disabled');
  444. }
  445. }
  446. //删除
  447. if(node){
  448. $('#del').removeClass('disabled');
  449. }
  450. if(node && node.data.type === itemType.job){
  451. //升级
  452. if(node.parent){
  453. $('#upLevel').removeClass('disabled');
  454. if(node.nextSibling && node.children.length > 0 && !allJobChildren(node)){
  455. $('#upLevel').addClass('disabled');
  456. }
  457. }
  458. //降级
  459. if(node.preSibling){
  460. $('#downLevel').removeClass('disabled');
  461. if(node.preSibling.children.length > 0 && !allJobChildren(node.preSibling)){
  462. $('#downLevel').addClass('disabled');
  463. }
  464. }
  465. }
  466. //上移
  467. if(node && node.preSibling){
  468. $('#upMove').removeClass('disabled')
  469. }
  470. //下移
  471. if(node && node.nextSibling){
  472. $('#downMove').removeClass('disabled');
  473. }
  474. //收起定额、展开全部
  475. $('#expandContract').removeClass('disabled');
  476. //插入定额
  477. if(node && (node.children.length === 0 || allRationChildren(node))){
  478. $('#insertRation').removeClass('disabled');
  479. }
  480. //备注,奇数节点可用
  481. if(node && (node.depth() + 1) % 2 === 1 && node.data.type !== itemType.ration){
  482. $('.main-bottom-content').find('textarea').attr('readonly', false);
  483. }
  484. }
  485. //项目指引表焦点控制
  486. //@param {Number}row @return {void}
  487. function guideItemInitSel(row){
  488. let billsNode = bills.tree.selected;
  489. let node = null;
  490. if(billsNode && billsNode.guidance.tree){
  491. node = billsNode.guidance.tree.items[row];
  492. if(node){
  493. billsNode.guidance.tree.selected = node;
  494. //显示备注
  495. $('.main-bottom-content').find('textarea').val(node.data.comment ? node.data.comment : '');
  496. }
  497. }
  498. refreshBtn(node);
  499. }
  500. //初始化当前库名
  501. //@param {String} @return {void}
  502. function initLibName(libName) {
  503. $('#libName')[0].outerHTML = $('#libName')[0].outerHTML.replace("XXX清单指引", libName);
  504. }
  505. //初始化各工作表
  506. //@param {Array}modules @return {void}
  507. function initWorkBooks(modules){
  508. for(let module of modules){
  509. buildSheet(module);
  510. }
  511. }
  512. function tipDivCheck(){
  513. setTimeout(function () {
  514. let tips = $('#autoTip');
  515. if(ration.tipDiv == 'show'){
  516. return;
  517. } else if(ration.tipDiv == 'hide'&&tips){
  518. tips.hide();
  519. ration._toolTipElement = null;
  520. }
  521. },600)
  522. }
  523. //获取悬浮提示单元格
  524. //@param {Object}sheet @return {Object}
  525. function getTipCellType(sheet) {
  526. let setting = {};
  527. let TipCellType = function () {};
  528. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  529. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  530. return {
  531. x: x,
  532. y: y,
  533. row: context.row,
  534. col: context.col,
  535. cellStyle: cellStyle,
  536. cellRect: cellRect,
  537. sheet: context.sheet,
  538. sheetArea: context.sheetArea
  539. };
  540. };
  541. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  542. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  543. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  544. if(tag !== undefined && tag){
  545. text = tag;
  546. }
  547. if(sheet && sheet.getParent().qo){
  548. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  549. }
  550. if (setting.pos && text && text !== '') {
  551. //固定不显示的div,存储文本获取固定div宽度,toolTipElement由于显示和隐藏,获取宽度不正确
  552. if(!this._fixedTipElement){
  553. let div = $('#fixedTip1')[0];
  554. if (!div) {
  555. div = document.createElement("div");
  556. $(div).css("padding", 5)
  557. .attr("id", 'fixedTip');
  558. $(div).hide();
  559. document.body.insertBefore(div, null);
  560. }
  561. this._fixedTipElement = div;
  562. }
  563. $(this._fixedTipElement).width('');
  564. $(this._fixedTipElement).html(text);
  565. if (!this._toolTipElement) {
  566. let div = $('#autoTip1')[0];
  567. if (!div) {
  568. div = document.createElement("div");
  569. $(div).css("position", "absolute")
  570. .css("border", "1px #C0C0C0 solid")
  571. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  572. .css("font", "0.9rem Calibri")
  573. .css("background", "white")
  574. .css("padding", 5)
  575. .attr("id", 'autoTip1');
  576. $(div).hide();
  577. document.body.insertBefore(div, null);
  578. }
  579. this._toolTipElement = div;
  580. $(this._toolTipElement).width('');
  581. //实时读取位置信息
  582. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  583. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  584. }
  585. $(this._toolTipElement).html(text);
  586. //定额库定额特殊处理
  587. if($(hitinfo.sheet.getParent().qo).attr('id') === 'rationSpread'){
  588. let divWidth = $(this._fixedTipElement).width(),
  589. divHeight = $(this._fixedTipElement).height();
  590. if(divWidth > 600){
  591. divWidth = 590;
  592. $(this._toolTipElement).width(divWidth);
  593. }
  594. $(this._toolTipElement).css("top", setting.pos.y + hitinfo.y - divHeight).css("left", setting.pos.x - divWidth);
  595. }
  596. else{
  597. $(this._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  598. }
  599. //名称
  600. if(hitinfo.col === 2){
  601. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  602. zoom = hitinfo.sheet.zoom();
  603. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  604. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  605. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  606. if(textLength > cellWidth){
  607. $(this._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  608. $(this._toolTipElement).show("fast");
  609. ration.tipDiv = 'show';//做个标记
  610. }
  611. }
  612. else {
  613. $(this._toolTipElement).show("fast");
  614. ration.tipDiv = 'show';//做个标记
  615. }
  616. }
  617. }
  618. };
  619. TipCellType.prototype.processMouseLeave = function (hininfo) {
  620. ration.tipDiv = 'hide';
  621. if (this._toolTipElement) {
  622. $(this._toolTipElement).hide();
  623. this._toolTipElement = null;
  624. }
  625. tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  626. }
  627. return new TipCellType();
  628. }
  629. //输出表数据(定额表)
  630. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  631. function showData(sheet, headers, datas){
  632. let fuc = function () {
  633. sheet.setRowCount(datas.length);
  634. //复选框
  635. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  636. let tipCellType = getTipCellType(sheet);
  637. sheet.setCellType(-1, 0, checkBoxType);
  638. for(let col = 0, cLen = headers.length; col < cLen; col++){
  639. for(let row = 0, rLen = datas.length; row < rLen; row++){
  640. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  641. if(col === 1){
  642. sheet.setTag(row, col, datas[row]['hint']);
  643. }
  644. }
  645. }
  646. sheet.setCellType(-1, 1, tipCellType);
  647. sheet.setCellType(-1, 2, tipCellType);
  648. };
  649. renderSheetFunc(sheet, fuc);
  650. }
  651. //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
  652. //@param {Number}sectionId {Array}rations @return {Array}
  653. function getRationsBySectionId(sectionId, rations) {
  654. if(!sectionId || !rations){
  655. return [];
  656. }
  657. return _.filter(rations, {sectionId});
  658. }
  659. //定额章节树焦点控制
  660. //@param {Number}row @return {void}
  661. function sectionInitSel(row) {
  662. let rationSheet = ration.workBook.getActiveSheet();
  663. let sectionNode = section.tree ? section.tree.items[row] : null;
  664. if(sectionNode && sectionNode.children.length === 0){
  665. let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
  666. ration.cache = sectionRations;
  667. showData(rationSheet, ration.headers, sectionRations);
  668. }
  669. else {
  670. cleanData(rationSheet, ration.headers, 0);
  671. }
  672. }
  673. //初始化定额条目
  674. //@param {Number}rationLibId @return {void}
  675. function initRationItems(rationLibId){
  676. $.bootstrapLoading.start();
  677. //获取定额章节树
  678. let sectionSheet = section.workBook.getActiveSheet();
  679. CommonAjax.post('/rationRepository/api/getRationTree', {rationLibId: rationLibId}, function (sectionDatas) {
  680. //获取所有定额数据
  681. let reqEntity = {rationLibId: rationLibId, showHint: true, returnFields: '-_id code ID sectionId name unit basePrice rationGljList jobContent annotation'};
  682. CommonAjax.post('/rationRepository/api/getRationItemsByLib', reqEntity, function (rstData) {
  683. section.cache = sectionDatas;
  684. initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
  685. //初始焦点在第一行(切换库)
  686. sectionSheet.setActiveCell(0, 0);
  687. rstData.sort(function (a, b) {
  688. let rst = 0;
  689. if(a.code > b.code){
  690. rst = 1;
  691. }
  692. else if(a.code < b.code){
  693. rst = -1;
  694. }
  695. return rst;
  696. });
  697. ration.datas = rstData;
  698. sectionInitSel(0);
  699. $.bootstrapLoading.end();
  700. }, function () {
  701. $.bootstrapLoading.end();
  702. });
  703. }, function () {
  704. $.bootstrapLoading.end();
  705. });
  706. }
  707. //初始化定额库选择
  708. //@param {String}compilationId @return {void}
  709. function initRationLibs(compilationId){
  710. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
  711. $('#rationLibSel').empty();
  712. for(let rationLib of rstData){
  713. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  714. $('#rationLibSel').append(opt);
  715. }
  716. //初始选择
  717. initRationItems(parseInt($('#rationLibSel').select().val()));
  718. $('#rationLibSel').change(function () {
  719. let rationLibId = parseInt($(this).select().val());
  720. initRationItems(rationLibId);
  721. })
  722. });
  723. }
  724. //清单设置悬浮提示信息
  725. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  726. function setBillsHint(billsNodes, jobs, items) {
  727. let jobsMapping = {},
  728. itemsMapping = {};
  729. for(let job of jobs){
  730. jobsMapping[job.id] = job;
  731. }
  732. for(let item of items){
  733. itemsMapping[item.id] = item;
  734. }
  735. let tagInfo = [];
  736. for(let billsNode of billsNodes){
  737. let hintArr = [];
  738. let billsItems = billsNode.data.items;
  739. if(billsItems.length > 0){
  740. //项目特征
  741. hintArr.push('项目特征:');
  742. }
  743. let itemCount = 1,
  744. jobCount = 1;
  745. for(let billsItem of billsItems){
  746. let itemData = itemsMapping[billsItem.id];
  747. if(itemData){
  748. //特征值
  749. let eigens = [];
  750. for(let eigen of itemData.itemValue){
  751. eigens.push(eigen.value);
  752. }
  753. eigens = eigens.join(';');
  754. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  755. itemCount ++;
  756. }
  757. }
  758. //工作内容
  759. let billsJobs = billsNode.data.jobs;
  760. if(billsJobs.length > 0){
  761. hintArr.push('工作内容:');
  762. }
  763. for(let billsJob of billsJobs){
  764. let jobData = jobsMapping[billsJob.id];
  765. if(jobData){
  766. hintArr.push(`${jobCount}.${jobData.content}`);
  767. jobCount ++;
  768. }
  769. }
  770. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  771. hintArr.push('工程量计算规则:');
  772. hintArr.push(billsNode.data.ruleText);
  773. }
  774. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  775. hintArr.push('补注:');
  776. hintArr.push(billsNode.data.recharge);
  777. }*/
  778. if(hintArr.length > 0){
  779. tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
  780. }
  781. }
  782. let sheet = bills.workBook.getActiveSheet();
  783. renderSheetFunc(sheet, function () {
  784. for(let tagI of tagInfo){
  785. sheet.setTag(tagI.row, 0, tagI.value);
  786. }
  787. });
  788. }
  789. //初始化清单的工作内容和项目特征
  790. //@param {Number}billsLibId {Function}callback @return {void}
  791. function initJobAndCharacter(billsLibId, callback){
  792. CommonAjax.post('/stdBillsEditor/getJobContent', {billsLibId: billsLibId}, function (datas) {
  793. stdBillsJobData = datas;
  794. CommonAjax.post('/stdBillsEditor/getItemCharacter', {billsLibId: billsLibId}, function (datas) {
  795. stdBillsFeatureData = datas;
  796. if(callback){
  797. callback();
  798. }
  799. });
  800. });
  801. }
  802. //获取指引库信息及关联的清单
  803. //@param {Number}libID {Function}callback @return {Object}
  804. function getLibWithBills(libID, callback){
  805. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  806. initRationLibs(rstData.guidanceLib.compilationId);
  807. bills.cache = rstData.bills;
  808. initLibName(rstData.guidanceLib.name);
  809. /*initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  810. //每一棵项目指引树挂在清单节点上
  811. for(let node of bills.tree.items){
  812. node.guidance = {tree: null, controller: null};
  813. }
  814. //默认初始节点
  815. billsInitSel(0);
  816. if(callback){
  817. callback(rstData);
  818. }*/
  819. let initDataCallback = function () {
  820. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  821. //每一棵项目指引树挂在清单节点上
  822. for(let node of bills.tree.items){
  823. node.guidance = {tree: null, controller: null};
  824. }
  825. //默认初始节点
  826. billsInitSel(0);
  827. if(callback){
  828. callback(rstData);
  829. }
  830. };
  831. initJobAndCharacter(rstData.guidanceLib.billsLibId, initDataCallback);
  832. }, function (msg) {
  833. window.location.href = '/billsGuidance/main';
  834. });
  835. }
  836. //初始化并输出树
  837. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  838. function initTree(module, sheet, treeSetting, datas){
  839. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  840. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  841. module.tree.loadDatas(datas);
  842. module.controller.showTreeData();
  843. if(module === bills){
  844. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  845. }
  846. }
  847. //更新项目指引
  848. //@param {Array}updateDatas {Function}callback @return {void}
  849. function updateGuideItems(updateDatas, callback){
  850. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  851. if(callback){
  852. callback(rstData);
  853. }
  854. });
  855. }
  856. //项目指引编辑
  857. //@param {Object}sheet {Array}cells
  858. function edit(sheet, cells){
  859. let updateDatas = [];
  860. //同步节点数据
  861. let syncDatas = [];
  862. for(let cell of cells){
  863. let text = sheet.getValue(cell.row, cell.col);
  864. text = text ? text : '';
  865. let node = bills.tree.selected.guidance.tree.items[cell.row];
  866. if(node.data.name != text){
  867. syncDatas.push({node: node, text: text});
  868. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {name: text}});
  869. }
  870. }
  871. if(updateDatas.length > 0){
  872. updateGuideItems(updateDatas, function () {
  873. for(let syncData of syncDatas){
  874. syncData.node.data.name = syncData.text;
  875. }
  876. }, function () {
  877. //失败恢复
  878. renderSheetFunc(sheet, function () {
  879. for(let syncData of syncDatas){
  880. sheet.setValue(syncData.node.serialNo(), 0, syncData.node.data.name ? syncData.node.data.name : '');
  881. }
  882. });
  883. });
  884. }
  885. }
  886. //项目指引插入,支持一次插入多条数据
  887. //@param {Array}datas {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  888. function insert(datas, tobeChild, callback = null){
  889. $.bootstrapLoading.start();
  890. let sheet = guideItem.workBook.getActiveSheet();
  891. let controller = bills.tree.selected.guidance.controller;
  892. let selected = bills.tree.selected.guidance.tree.selected;
  893. let updateDatas = [];
  894. //建立数组下标索引
  895. let newDataIndex = {};
  896. for(let i = 0; i < datas.length; i++){
  897. let newNodeData = {
  898. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  899. billsID: bills.tree.selected.getID()
  900. };
  901. //定额类型插入当前工作内容焦点行,
  902. if(selected && ((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  903. newNodeData.ParentID = selected.getID();
  904. newNodeData.NextSiblingID = -1;
  905. }
  906. Object.assign(newNodeData, datas[i]);
  907. newDataIndex[i] = newNodeData;
  908. }
  909. for(let i = 0; i < datas.length; i++){
  910. //第一个节点
  911. if(i === 0){
  912. //非插入成子节点,更新选中节点NestSiblingID
  913. if(selected && !((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  914. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  915. }
  916. }
  917. //非最后一个节点
  918. if(i !== datas.length - 1){
  919. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  920. }
  921. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  922. }
  923. updateGuideItems(updateDatas, function () {
  924. for(let updateData of updateDatas){
  925. if(updateData.updateType === updateType.create){
  926. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  927. //同步data
  928. Object.assign(newNode.data, updateData.updateData);
  929. sheet.setValue(newNode.serialNo(), 0, newNode.data.name);
  930. refreshBtn(newNode);
  931. }
  932. }
  933. if(callback){
  934. callback();
  935. }
  936. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  937. guideItem.workBook.focus(true);
  938. $.bootstrapLoading.end();
  939. });
  940. }
  941. //项目指引删除操作
  942. //@return {void}
  943. function del(){
  944. $.bootstrapLoading.start();
  945. let controller = bills.tree.selected.guidance.controller;
  946. let selected = bills.tree.selected.guidance.tree.selected;
  947. let updateDatas = [];
  948. function getDelDatas(node){
  949. updateDatas.push({updateType: updateType.del, findData: {ID: node.getID()}, updateData: {deleted: true}});
  950. if(node.children.length > 0){
  951. for(let c of node.children){
  952. getDelDatas(c);
  953. }
  954. }
  955. }
  956. getDelDatas(selected);
  957. updateGuideItems(updateDatas, function () {
  958. controller.delete();
  959. refreshBtn(bills.tree.selected.guidance.tree.selected);
  960. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  961. $.bootstrapLoading.end();
  962. guideItem.workBook.focus(true)
  963. });
  964. }
  965. //项目指引升级
  966. //@return {void}
  967. function upLevel(){
  968. $.bootstrapLoading.start();
  969. let controller = bills.tree.selected.guidance.controller;
  970. let selected = bills.tree.selected.guidance.tree.selected;
  971. let updateDatas = [];
  972. //更新父节点
  973. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  974. //更新选中节点
  975. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()},
  976. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID()}});
  977. if(selected.nextSibling && selected.children.length > 0){
  978. //更新选中节点最末子节点
  979. let lastChild = selected.children[selected.children.length - 1];
  980. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: -1}});
  981. }
  982. //选中节点的所有后兄弟节点成为选中节点的子项
  983. let selectedNextIDs = [];
  984. let sNext = selected.nextSibling;
  985. while(sNext){
  986. selectedNextIDs.push(sNext.getID());
  987. sNext = sNext.nextSibling;
  988. }
  989. for(let sID of selectedNextIDs){
  990. updateDatas.push({updateType: updateType.update, findData: {ID: sID}, updateData: {ParentID: selected.getID()}});
  991. }
  992. updateGuideItems(updateDatas, function () {
  993. controller.upLevel();
  994. refreshBtn(bills.tree.selected.guidance.tree.selected);
  995. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  996. $.bootstrapLoading.end();
  997. guideItem.workBook.focus(true)//31574
  998. });
  999. }
  1000. //项目指引降级
  1001. //@return {void}
  1002. function downLevel(){
  1003. $.bootstrapLoading.start();
  1004. let controller = bills.tree.selected.guidance.controller;
  1005. let selected = bills.tree.selected.guidance.tree.selected;
  1006. let updateDatas = [];
  1007. //更新前兄弟节点
  1008. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1009. //更新前兄弟节点最末子节点
  1010. if(selected.preSibling.children.length > 0){
  1011. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  1012. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1013. }
  1014. //更新选中节点
  1015. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1}});
  1016. updateGuideItems(updateDatas, function () {
  1017. controller.downLevel();
  1018. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1019. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1020. $.bootstrapLoading.end();
  1021. guideItem.workBook.focus(true)
  1022. });
  1023. }
  1024. //项目指引上移
  1025. //@return {void}
  1026. function upMove(){
  1027. $.bootstrapLoading.start();
  1028. let controller = bills.tree.selected.guidance.controller;
  1029. let selected = bills.tree.selected.guidance.tree.selected;
  1030. let updateDatas = [];
  1031. //更新前节点
  1032. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1033. //更新前前节点
  1034. if(selected.preSibling.preSibling){
  1035. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1036. }
  1037. //更新选中节点
  1038. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  1039. updateGuideItems(updateDatas, function () {
  1040. controller.upMove();
  1041. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1042. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1043. $.bootstrapLoading.end();
  1044. guideItem.workBook.focus(true)
  1045. });
  1046. }
  1047. //项目指引下移
  1048. //@return {void}
  1049. function downMove(){
  1050. $.bootstrapLoading.start();
  1051. let controller = bills.tree.selected.guidance.controller;
  1052. let selected = bills.tree.selected.guidance.tree.selected;
  1053. let updateDatas = [];
  1054. //更新下节点
  1055. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  1056. //更新前节点
  1057. if(selected.preSibling){
  1058. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1059. }
  1060. //更新选中节点
  1061. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  1062. updateGuideItems(updateDatas, function () {
  1063. controller.downMove();
  1064. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1065. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1066. $.bootstrapLoading.end();
  1067. guideItem.workBook.focus(true)
  1068. });
  1069. }
  1070. //获取定额类型的项目指引名称,通过定额转换
  1071. //@param {Object}ration @return {String}
  1072. function getRationItemName(ration){
  1073. let arr = [];
  1074. arr.push(ration.code ? ration.code : '');
  1075. arr.push(ration.name ? ration.name : '');
  1076. arr.push(ration.basePrice ? ration.basePrice : '');
  1077. let rst = arr.join(' ');
  1078. rst += `/${ration.unit ? ration.unit : ''}`;
  1079. return rst;
  1080. }
  1081. //获取选中的定额表行
  1082. //@return {Array}
  1083. function getCheckedRationRows(){
  1084. let rst = [];
  1085. let sheet = ration.workBook.getActiveSheet();
  1086. for(let i = 0; i < sheet.getRowCount(); i++){
  1087. let checked = sheet.getValue(i, 0);
  1088. if(checked){
  1089. rst.push(i);
  1090. }
  1091. }
  1092. return rst;
  1093. }
  1094. //清空选中定额表行
  1095. //@param {Array}rows @return {void}
  1096. function clearCheckedRation(rows) {
  1097. let sheet = ration.workBook.getActiveSheet();
  1098. renderSheetFunc(sheet, function () {
  1099. for(let row of rows){
  1100. sheet.setValue(row, 0, 0);
  1101. }
  1102. });
  1103. }
  1104. //获取要插入的定额数据
  1105. //@param {Array}rows @return {Array}
  1106. function getInsertRations(rows){
  1107. let rst = [];
  1108. //当前已存在定额
  1109. let curRationIems = [];
  1110. let selected = bills.tree.selected.guidance.tree.selected;
  1111. if(selected){
  1112. if(selected.data.type === itemType.job){
  1113. curRationIems = selected.children;
  1114. }
  1115. else {
  1116. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  1117. }
  1118. }
  1119. for(let row of rows){
  1120. let selRation = ration.cache[row];
  1121. if(selRation){
  1122. //添加的定额是否已存在,不重复添加
  1123. let isExist = false;
  1124. for(let curRation of curRationIems){
  1125. if(curRation.data.rationID == selRation.ID){
  1126. isExist = true;
  1127. break;
  1128. }
  1129. }
  1130. if(!isExist){
  1131. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  1132. }
  1133. }
  1134. }
  1135. return rst;
  1136. }
  1137. //获取块节点父项不存在于选中节点中的节点
  1138. //@param {Array}nodes(选中的节点) @return {Array}
  1139. function getBlockNodes(nodes) {
  1140. let nodeMapping = {};
  1141. for(let node of nodes){
  1142. nodeMapping[node.data.ID] = node;
  1143. }
  1144. //块节点,父项不存在于选中节点中的节点
  1145. let blockNodes = [];
  1146. for(let node of nodes){
  1147. if(!nodeMapping[node.data.ParentID]){
  1148. blockNodes.push(node);
  1149. }
  1150. }
  1151. return blockNodes;
  1152. }
  1153. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1154. //@param {Array}nodes(块节点) @return {Boolean}
  1155. function canCopyBlock(nodes) {
  1156. if(!nodes || nodes.length === 0){
  1157. return false;
  1158. }
  1159. let pID = nodes[0].data.ParentID;
  1160. for(let node of nodes){
  1161. if(node.data.ParentID !== pID){
  1162. return false;
  1163. }
  1164. }
  1165. return true;
  1166. }
  1167. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1168. //@param {Object}node(粘贴到的节点)
  1169. function canPasteBlock(node) {
  1170. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1171. if(!pasteDatas || pasteDatas.length === 0){
  1172. return false;
  1173. }
  1174. if(!node){
  1175. return false;
  1176. }
  1177. //若粘贴到定额节点,则数据须全为定额
  1178. if(node.data.type === itemType.ration){
  1179. for(let data of pasteDatas){
  1180. if(data.type !== itemType.ration){
  1181. return false;
  1182. }
  1183. }
  1184. }
  1185. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1186. else {
  1187. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1188. for(let topData of topDatas){
  1189. if(topData.type === itemType.ration){
  1190. return false;
  1191. }
  1192. }
  1193. }
  1194. return true;
  1195. }
  1196. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1197. //@param {Array}nodes(块节点) @return {void}
  1198. function copyBlocks(nodes) {
  1199. nodes = _.cloneDeep(nodes);
  1200. //将块节点的ParentID暂时设置为-1
  1201. for(let topNode of nodes){
  1202. topNode.data.ParentID = -1;
  1203. }
  1204. let copyDatas = [];
  1205. let copyNodes = [];
  1206. //获取块节点包含的所有节点(包括自己)
  1207. function containNodes(nodes) {
  1208. for(let node of nodes){
  1209. copyNodes.push(node);
  1210. if(node.children.length > 0){
  1211. containNodes(node.children);
  1212. }
  1213. }
  1214. }
  1215. containNodes(nodes);
  1216. for(let node of copyNodes){
  1217. copyDatas.push(node.data);
  1218. }
  1219. console.log(`copyDatas`);
  1220. console.log(copyDatas);
  1221. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1222. }
  1223. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1224. //@param {Object}node(粘贴到的节点) @return {void}
  1225. function pasteBlock(node) {
  1226. let itemObj = bills.tree.selected.guidance;
  1227. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1228. //整理ID
  1229. let IDMapping = {};
  1230. for(let data of pasteDatas){
  1231. data.newID = uuid.v1();
  1232. IDMapping[data.ID] = data;
  1233. }
  1234. for(let data of pasteDatas){
  1235. let nextData = IDMapping[data.NextSiblingID];
  1236. data.NextSiblingID = nextData ? nextData.newID : -1;
  1237. let parentData = IDMapping[data.ParentID];
  1238. data.ParentID = parentData ? parentData.newID : -1;
  1239. }
  1240. for(let data of pasteDatas){
  1241. data.ID = data.newID;
  1242. delete data.newID;
  1243. }
  1244. let updateDatas = [];
  1245. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1246. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1247. for(let topData of topDatas){
  1248. topData.ParentID = node.getParentID();
  1249. }
  1250. //更新数据
  1251. //更新插入的最末顶层数据NextSiblingID
  1252. if(node.nextSibling){
  1253. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1254. }
  1255. //新建节点
  1256. for(let data of pasteDatas){
  1257. data.libID = libID;
  1258. data.billsID = node.data.billsID;
  1259. delete data._id;
  1260. updateDatas.push({updateType: updateType.create, updateData: data});
  1261. }
  1262. console.log(`node`);
  1263. console.log(node);
  1264. console.log(`pasteDatas`);
  1265. console.log(pasteDatas);
  1266. //更新粘贴到的节点的NextSiblingID
  1267. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1268. $.bootstrapLoading.start();
  1269. updateGuideItems(updateDatas, function (rstData) {
  1270. $.bootstrapLoading.end();
  1271. node.data.NextSiblingID = topDatas[0].ID;
  1272. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1273. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1274. itemObj.controller.showTreeData();
  1275. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1276. }, function () {
  1277. $.bootstrapLoading.end();
  1278. });
  1279. }
  1280. //初始化右键菜单
  1281. //@return {void}
  1282. function initContextMenu() {
  1283. $.contextMenu({
  1284. selector: '#guideItemSpread',
  1285. build: function($triggerElement, e){
  1286. //控制允许右键菜单在哪个位置出现
  1287. let sheet = guideItem.workBook.getSheet(0);
  1288. let offset = $("#guideItemSpread").offset(),
  1289. x = e.pageX - offset.left,
  1290. y = e.pageY - offset.top;
  1291. let target = sheet.hitTest(x, y);
  1292. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1293. let sel = sheet.getSelections()[0];
  1294. if(sel && sel.rowCount === 1){
  1295. sheet.setActiveCell(target.row, target.col);
  1296. }
  1297. sel = sheet.getSelections()[0];
  1298. let selNodes = [];
  1299. if(sel){
  1300. sel.row = sel.row === -1 ? 0 : sel.row;
  1301. for(let i = 0; i < sel.rowCount; i++){
  1302. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1303. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1304. }
  1305. }
  1306. }
  1307. //块节点
  1308. let blockNodes = getBlockNodes(selNodes);
  1309. //右键在多选内则不重设焦点
  1310. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1311. sheet.setActiveCell(target.row, target.col);
  1312. }
  1313. guideItemInitSel(target.row);
  1314. return {
  1315. callback: function(){},
  1316. items: {
  1317. "copy": {
  1318. name: "复制整块",
  1319. disabled: function () {
  1320. return !canCopyBlock(blockNodes);
  1321. },
  1322. icon: "fa-copy",
  1323. callback: function (key, opt) {
  1324. copyBlocks(blockNodes);
  1325. }},
  1326. "paste": {
  1327. name: "粘贴整块",
  1328. disabled: function () {
  1329. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1330. return !canPasteBlock(pasteNode);
  1331. },
  1332. icon: "fa-paste",
  1333. callback: function (key, opt) {
  1334. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1335. pasteBlock(pasteNode);
  1336. }},
  1337. "insertSibling": {
  1338. name: '插入行',
  1339. disabled: function () {
  1340. let node = bills.tree.selected.guidance.tree.items[target.row];
  1341. return !node || node.data.type !== itemType.job;
  1342. },
  1343. icon: "fa-arrow-left",
  1344. callback: function (key, opt) {
  1345. insert([{type: itemType.job, name: ''}], false);
  1346. }
  1347. },
  1348. "insertChild": {
  1349. name: '插入子项',
  1350. disabled: function () {
  1351. let node = bills.tree.selected.guidance.tree.items[target.row];
  1352. return !node || node.data.type !== itemType.job || !allJobChildren(node);
  1353. },
  1354. icon: 'fa-arrow-left',
  1355. callback: function (key, opt) {
  1356. insert([{type: itemType.job, name: ''}], true);
  1357. }
  1358. }
  1359. }
  1360. };
  1361. }
  1362. else{
  1363. return false;
  1364. }
  1365. }
  1366. });
  1367. }
  1368. //拖动相关
  1369. let mouseMoveCount = 0;
  1370. let rationLibResizeEles = {};
  1371. rationLibResizeEles.id = '#de';
  1372. rationLibResizeEles.resize = $('#deResize');
  1373. rationLibResizeEles.nearElement = $('#de').find('.top-content');
  1374. rationLibResizeEles.nearSpread = $('#sectionSpread');
  1375. rationLibResizeEles.farElement = $('#de').find('.bottom-content');
  1376. rationLibResizeEles.farSpread = $('#rationSpread');
  1377. rationLibResizeEles.nav = null;
  1378. function setDefaultSize(tag,eles,type) {
  1379. let o_nearSize = 5;
  1380. let o_farSize = 2;
  1381. if(type == 'height'){
  1382. let headerHeight = $(".header").height();
  1383. let toolsbarHeight = $(".sidebar-tools-bar").height();
  1384. let resizeHeight = 6;
  1385. let totalHeight = $(window).height() - headerHeight - toolsbarHeight - resizeHeight;
  1386. const navSize = eles.nav ? eles.nav[type]() + 4 : 0;
  1387. totalHeight = totalHeight - navSize;
  1388. let nearSize = (o_nearSize/(o_nearSize + o_farSize))* totalHeight;
  1389. eles.nearSpread[type](nearSize);
  1390. eles.nearElement[type](nearSize);
  1391. eles.farSpread[type](totalHeight - nearSize);
  1392. eles.farElement[type](totalHeight - nearSize);
  1393. }
  1394. }
  1395. function setSizeWithPercent(tag,eles,nearSize,farSize,type) {
  1396. nearSize = parseFloat(nearSize);
  1397. farSize = parseFloat(farSize);
  1398. if(type !== 'width') {
  1399. let headerHeight = $(".header").height();
  1400. let toolsbarHeight = $(".sidebar-tools-bar").height();
  1401. let resizeHeight = 6;
  1402. let totalHeight = $(window).height() - headerHeight - toolsbarHeight - resizeHeight;
  1403. const navSize = eles.nav ? eles.nav[type]() + 4 : 0;
  1404. totalHeight = totalHeight - navSize;
  1405. nearSize = (nearSize/(nearSize + farSize))* totalHeight;
  1406. eles.nearSpread[type](nearSize);
  1407. eles.nearElement[type](nearSize);
  1408. eles.farSpread[type](totalHeight - nearSize);
  1409. eles.farElement[type](totalHeight - nearSize);
  1410. }
  1411. }
  1412. /**
  1413. * 读取设置的高度
  1414. *
  1415. * @param {String} tag - 顶层div的id
  1416. * @param {function} callback - 回调函数
  1417. * @return {void}
  1418. */
  1419. function loadSize(eles, type, callback) {
  1420. let tag = eles.id;
  1421. if (tag === '') {
  1422. return;
  1423. }
  1424. if(type !== 'height' && type !== 'width'){
  1425. return;
  1426. }
  1427. let o_nearSize = eles.nearSpread[type]();
  1428. let o_farSize = eles.farSpread[type]();
  1429. let nearSize = getLocalCache(`near${type}:${tag}`);
  1430. let farSize = getLocalCache(`far${type}:${tag}`);
  1431. if (nearSize === null || farSize === null) {
  1432. setDefaultSize(tag,eles,type);
  1433. }else {
  1434. setSizeWithPercent(tag,eles,nearSize,farSize,type)//zhang 2018-06-04 改成按百分比设置
  1435. }
  1436. callback();
  1437. }
  1438. /**
  1439. * 拖动更改div大小
  1440. *
  1441. * @param {Object} eles - id:存储本地的标记 resize:拖动条 nearElement:左上外层div nearSpread:左上spread farElement:右下外层div evFixedSize:造价书左右拖动用
  1442. * @param {Object} limit - min/max
  1443. * @param {String} type - height/width
  1444. * @param {function} callback - 成功后执行
  1445. * @return {void}
  1446. */
  1447. function slideResize(eles, limit, type, callback) {
  1448. if(type !== 'height' && type !== 'width'){
  1449. return;
  1450. }
  1451. //nearElement:左上, farElement:右下
  1452. let startP = 0;
  1453. let drag = false;
  1454. const resizeElement = eles.resize;
  1455. const nElement = eles.nearElement;
  1456. const fElement = eles.farElement;
  1457. const navContentEle = eles.nav ? eles.nav : null;
  1458. let nEleSize = 0;
  1459. let fEleSize = 0;
  1460. let navSize = 0;
  1461. let nEleChangeSize = 0;
  1462. let fEleChangeSize = 0;
  1463. // 鼠标点下时
  1464. resizeElement.mousedown(function(e) {
  1465. drag = true;
  1466. startP = type === 'height' ? e.clientY : e.clientX;
  1467. // 获取左(上)部分的宽度(高度)
  1468. nEleSize = nElement[type]();
  1469. // 获取右(下)部分的宽度(高度)
  1470. fEleSize = fElement[type]();
  1471. // nav宽(高度)部分
  1472. if(navContentEle){
  1473. navSize = navContentEle[type]() + 4;
  1474. }
  1475. resizeElement.tooltip('hide');
  1476. });
  1477. // 鼠标移动
  1478. $("body").mousemove(function(e) {
  1479. if (drag) {
  1480. let moveSize = type === 'height' ? e.clientY - startP : e.clientX - startP;
  1481. // 判断拖动范围不能超出
  1482. nEleChangeSize = nEleSize + moveSize;
  1483. nEleChangeSize = nEleChangeSize < limit.min ? limit.min : nEleChangeSize;
  1484. nEleChangeSize = nEleChangeSize > limit.max ? limit.max + 9 : nEleChangeSize;
  1485. fEleChangeSize = fEleSize - moveSize;
  1486. fEleChangeSize = fEleChangeSize < limit.min ? limit.min : fEleChangeSize;
  1487. fEleChangeSize = fEleChangeSize > limit.max ? limit.max + 9 : fEleChangeSize;
  1488. if(type === 'width'){
  1489. let rePercent = getResizeWidthPercent(nEleChangeSize, fEleChangeSize);
  1490. eles.nearElement.css(type, rePercent.nearPercent);
  1491. eles.farElement.css(type, rePercent.farPercent);
  1492. }
  1493. else{
  1494. eles.nearSpread[type](nEleChangeSize);
  1495. eles.nearElement[type](nEleChangeSize);
  1496. eles.farSpread[type](fEleChangeSize - navSize);
  1497. eles.farElement[type](fEleChangeSize - navSize);
  1498. }
  1499. //实时刷新页面
  1500. mouseMoveCount+=Math.abs(moveSize);//取移动的决对值
  1501. if(mouseMoveCount >=5){//当累计移动超过5个像素时,才刷新,减少刷新次数
  1502. if(callback) callback();
  1503. mouseMoveCount = 0;
  1504. }
  1505. }
  1506. });
  1507. // 鼠标弹起
  1508. $("body").mouseup(function(e) {
  1509. if (drag) {
  1510. callback();
  1511. drag = false;
  1512. // 存入本地缓存
  1513. const id = eles.id;
  1514. nEleChangeSize = nEleChangeSize >= limit.max ? limit.max + 9 : nEleChangeSize;
  1515. fEleChangeSize = fEleChangeSize >= limit.max ? limit.max + 9 : fEleChangeSize;
  1516. setLocalCache(`near${type}:${id}`, nEleChangeSize);
  1517. setLocalCache(`far${type}:${id}`, fEleChangeSize);
  1518. }
  1519. });
  1520. }
  1521. /**
  1522. * 读取设置的高度
  1523. *
  1524. * @param {String} tag - 顶层div的id
  1525. * @param {function} callback - 回调函数
  1526. * @return {void}
  1527. */
  1528. function loadSize(eles, type, callback) {
  1529. let tag = eles.id;
  1530. if (tag === '') {
  1531. return;
  1532. }
  1533. if(type !== 'height' && type !== 'width'){
  1534. return;
  1535. }
  1536. let o_nearSize = eles.nearSpread[type]();
  1537. let o_farSize = eles.farSpread[type]();
  1538. let nearSize = getLocalCache(`near${type}:${tag}`);
  1539. let farSize = getLocalCache(`far${type}:${tag}`);
  1540. if (nearSize === null || farSize === null) {
  1541. setDefaultSize(tag,eles,type);//zhang 2018-05-21
  1542. /* eles.nearSpread[type](o_nearSize);
  1543. eles.farSpread[type](o_farSize);*/
  1544. }else {
  1545. setSizeWithPercent(tag,eles,nearSize,farSize,type)//zhang 2018-06-04 改成按百分比设置
  1546. }
  1547. if(type === 'width'){//使用百分比
  1548. let rePercent = getResizeWidthPercent(nearSize ? nearSize : o_nearSize, farSize ? farSize : o_farSize);
  1549. eles.nearElement.css(type, rePercent.nearPercent);
  1550. eles.farElement.css(type, rePercent.farPercent);
  1551. }
  1552. callback();
  1553. }
  1554. //初始化个按钮点击
  1555. //@return {void}
  1556. function initBtn(){
  1557. $('#insert').click(function () {
  1558. insert([{type: itemType.job, name: ''}], false);
  1559. });
  1560. $('#delConfirm').click(function () {
  1561. del();
  1562. $('#delAlert').modal('hide');
  1563. });
  1564. $('#del').click(function () {
  1565. $('#delAlert').modal('show');
  1566. });
  1567. $('#upLevel').click(function () {
  1568. upLevel();
  1569. });
  1570. $('#downLevel').click(function () {
  1571. downLevel();
  1572. });
  1573. $('#upMove').click(function () {
  1574. upMove();
  1575. });
  1576. $('#downMove').click(function () {
  1577. downMove();
  1578. });
  1579. //收起定额、展开全部
  1580. $('#expandContract').click(function () {
  1581. //目前状态时展开全部节点状态,点击则收起定额
  1582. let tree = bills.tree.selected.guidance.tree,
  1583. itemSheet = guideItem.workBook.getActiveSheet();
  1584. if(curExpandState === itemExpandState.expand){
  1585. curExpandState = itemExpandState.contract;
  1586. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  1587. setNodesExpandState(tree.items, itemExpandState.contract);
  1588. } else {
  1589. curExpandState = itemExpandState.expand;
  1590. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  1591. setNodesExpandState(tree.items, itemExpandState.expand);
  1592. }
  1593. renderSheetFunc(itemSheet, function () {
  1594. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  1595. });
  1596. });
  1597. $('#insertRation').click(function () {
  1598. let checkedRows = getCheckedRationRows();
  1599. let insertDatas = getInsertRations(checkedRows);
  1600. if(insertDatas.length > 0){
  1601. insert(insertDatas, false, function () {
  1602. //清空选择
  1603. clearCheckedRation(checkedRows);
  1604. });
  1605. }
  1606. else {
  1607. clearCheckedRation(checkedRows);
  1608. }
  1609. });
  1610. //搜索定额
  1611. $('#searchBtn').click(function () {
  1612. let searchStr = $('#searchText').val();
  1613. if(!searchStr || searchStr === ''){
  1614. ration.cache = ration.datas;
  1615. }
  1616. else{
  1617. let reg = new RegExp(searchStr, 'i');
  1618. ration.cache = _.filter(ration.datas, function (data) {
  1619. return reg.test(data.code) || reg.test(data.name);
  1620. });
  1621. }
  1622. $('.top-content').hide();
  1623. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  1624. $('#rationSearchResult').show();
  1625. autoFlashHeight();
  1626. ration.workBook.refresh();
  1627. let rationSheet = ration.workBook.getActiveSheet();
  1628. renderSheetFunc(rationSheet, function () {
  1629. clearCheckedRation(getCheckedRationRows());
  1630. showData(rationSheet, ration.headers, ration.cache);
  1631. })
  1632. });
  1633. //关闭搜索
  1634. $('#rationSearchResult a').click(function () {
  1635. $('.top-content').show();
  1636. $('#rationSearchResult').hide();
  1637. autoFlashHeight();
  1638. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  1639. clearCheckedRation(getCheckedRationRows());
  1640. });
  1641. section.workBook.refresh();
  1642. ration.workBook.refresh();
  1643. $('#searchText').val('');
  1644. //恢复章节树下的定额
  1645. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  1646. });
  1647. //执行搜索
  1648. $('#searchText').keyup(function (e) {
  1649. $('#searchBtn').click();
  1650. });
  1651. //编辑备注
  1652. $('.main-bottom-content').find('textarea').keyup(function () {
  1653. let node = bills.tree.selected.guidance.tree.selected;
  1654. if(node){
  1655. let comment = $(this).val();
  1656. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  1657. updateGuideItems(updateDatas, function (rstData) {
  1658. node.data.comment = comment;
  1659. });
  1660. }
  1661. });
  1662. //定额高度拖动调整
  1663. slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  1664. //autoFlashHeight();
  1665. if(section.workBook){
  1666. section.workBook.refresh();
  1667. }
  1668. if(ration.workBook){
  1669. ration.workBook.refresh();
  1670. }
  1671. });
  1672. }
  1673. //初始化视图
  1674. //@param {void} @return {void}
  1675. function initViews(){
  1676. let modules = [bills, guideItem, section, ration];
  1677. initWorkBooks(modules);
  1678. getLibWithBills(libID);
  1679. initBtn();
  1680. initContextMenu();
  1681. loadSize(rationLibResizeEles, 'height', function () {
  1682. if(section.workBook){
  1683. section.workBook.refresh();
  1684. }
  1685. if(ration.workBook){
  1686. ration.workBook.refresh();
  1687. }
  1688. });
  1689. }
  1690. return {initViews};
  1691. })();
  1692. $(document).ready(function () {
  1693. billsGuidance.initViews();
  1694. CommonAjax.post('/billsGuidance/api/testItems', {libID: getQueryString('libID')}, function (rstData) {
  1695. console.log(rstData);
  1696. });
  1697. });