billsGuidance.js 72 KB

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