billsGuidance.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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. const bills = {
  16. dom: $('#billsSpread'),
  17. workBook: null,
  18. cache: [],
  19. tree: null,
  20. controller: null,
  21. treeSetting: {
  22. treeCol: 0,
  23. emptyRows: 0,
  24. headRows: 1,
  25. headRowHeight: [40],
  26. defaultRowHeight: 21,
  27. cols: [{
  28. width: 200,
  29. readOnly: true,
  30. head: {
  31. titleNames: ["项目编码"],
  32. spanCols: [1],
  33. spanRows: [1],
  34. vAlign: [1],
  35. hAlign: [1],
  36. font: ["Arial"]
  37. },
  38. data: {
  39. field: "code",
  40. vAlign: 1,
  41. hAlign: 0,
  42. font: "Arial"
  43. }
  44. }, {
  45. width: 200,
  46. readOnly: true,
  47. head: {
  48. titleNames: ["项目名称"],
  49. spanCols: [1],
  50. spanRows: [1],
  51. vAlign: [1],
  52. hAlign: [1],
  53. font: ["Arial"]
  54. },
  55. data: {
  56. field: "name",
  57. vAlign: 1,
  58. hAlign: 0,
  59. font: "Arial"
  60. }
  61. }]
  62. },
  63. headers: [
  64. {name: '项目编码', dataCode: 'code', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'},
  65. {name: '项目名称', dataCode: 'name', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'}
  66. ],
  67. events: {
  68. SelectionChanged: function (sender, info) {
  69. billsInitSel(info.newSelections[0].row);
  70. }
  71. }
  72. };
  73. //项目指引类型
  74. const itemType = {
  75. job: 0,
  76. ration: 1
  77. };
  78. //项目指引复制整块localStorage key
  79. const itemCopyBlockKey = 'guideItemCopyBlock';
  80. const updateType = {
  81. create: 'create',
  82. update: 'update',
  83. del: 'delete'
  84. };
  85. const guideItem = {
  86. dom: $('#guideItemSpread'),
  87. workBook: null,
  88. tree: null,
  89. controller: null,
  90. treeSetting: {
  91. treeCol: 0,
  92. emptyRows: 0,
  93. headRows: 1,
  94. headRowHeight: [40],
  95. defaultRowHeight: 21,
  96. cols: [{
  97. width: 400,
  98. readOnly: false,
  99. head: {
  100. titleNames: ["项目指引"],
  101. spanCols: [1],
  102. spanRows: [1],
  103. vAlign: [1],
  104. hAlign: [1],
  105. font: ["Arial"]
  106. },
  107. data: {
  108. field: "name",
  109. vAlign: 1,
  110. hAlign: 0,
  111. font: "Arial"
  112. }
  113. }]
  114. },
  115. headers: [
  116. {name: '项目指引', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  117. ],
  118. events: {
  119. SelectionChanged: function (sender, info) {
  120. guideItemInitSel(info.newSelections[0].row)
  121. },
  122. EditEnded: function (sender, args) {
  123. edit(args.sheet, [{row: args.row, col: args.col}]);
  124. },
  125. RangeChanged: function (sender, args) {
  126. edit(args.sheet, args.changedCells);
  127. }
  128. }
  129. };
  130. //定额章节树
  131. const section = {
  132. dom: $('#sectionSpread'),
  133. workBook: null,
  134. cache: [],
  135. tree: null,
  136. controller: null,
  137. treeSetting: {
  138. treeCol: 0,
  139. emptyRows: 0,
  140. headRows: 1,
  141. headRowHeight: [40],
  142. defaultRowHeight: 21,
  143. cols: [{
  144. width: 400,
  145. readOnly: true,
  146. head: {
  147. titleNames: ["名称"],
  148. spanCols: [1],
  149. spanRows: [1],
  150. vAlign: [1],
  151. hAlign: [1],
  152. font: ["Arial"]
  153. },
  154. data: {
  155. field: "name",
  156. vAlign: 1,
  157. hAlign: 0,
  158. font: "Arial"
  159. }
  160. }]
  161. },
  162. headers: [
  163. {name: '名称', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  164. ],
  165. events: {
  166. SelectionChanged: function (sender, info) {
  167. sectionInitSel(info.newSelections[0].row)
  168. }
  169. }
  170. };
  171. const ration = {
  172. dom: $('#rationSpread'),
  173. workBook: null,
  174. datas: [],//所有的数据,搜索定额时,从所有数据中筛选
  175. cache: [],//显示在表格上的数据,添加定额可以有效根据行识别定额
  176. headers: [
  177. {name: '选择', dataCode: 'select', width: 50, vAlign: 'center', hAlign: 'center'},
  178. {name: '编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
  179. {name: '名称', dataCode: 'name', width: 250, vAlign: 'center', hAlign: 'left', formatter: '@'},
  180. {name: '单位', dataCode: 'unit', width: 100, vAlign: 'center', hAlign: 'left', formatter: '@'}
  181. ],
  182. events: {
  183. ButtonClicked: function (sender, args) {
  184. if(args.sheet.isEditing()){
  185. args.sheet.endEdit(true);
  186. }
  187. },
  188. CellDoubleClick: function (sender, args) {
  189. if(ration.headers[args.col].dataCode === 'name'){
  190. let insertDatas = getInsertRations([args.row]);
  191. if(insertDatas.length > 0){
  192. insert(insertDatas);
  193. }
  194. }
  195. }
  196. }
  197. };
  198. const options = {
  199. workBook: {
  200. tabStripVisible: false,
  201. allowContextMenu: false,
  202. allowCopyPasteExcelStyle : false,
  203. allowExtendPasteRange: false,
  204. allowUserDragDrop : false,
  205. allowUserDragFill: false,
  206. scrollbarMaxAlign : true
  207. },
  208. sheet: {
  209. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  210. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  211. }
  212. };
  213. //渲染时方法,停止渲染
  214. //@param {Object}sheet {Function}func @return {void}
  215. function renderSheetFunc(sheet, func){
  216. sheet.suspendEvent();
  217. sheet.suspendPaint();
  218. if(func){
  219. func();
  220. }
  221. sheet.resumeEvent();
  222. sheet.resumePaint();
  223. }
  224. //设置表选项
  225. //@param {Object}workBook {Object}opts @return {void}
  226. function setOptions (workBook, opts) {
  227. for(let opt in opts.workBook){
  228. workBook.options[opt] = opts.workBook[opt];
  229. }
  230. for(let opt in opts.sheet){
  231. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  232. }
  233. }
  234. //建表头
  235. //@param {Object}sheet {Array}headers @return {void}
  236. function buildHeader(sheet, headers) {
  237. let fuc = function () {
  238. sheet.setColumnCount(headers.length);
  239. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  240. for(let i = 0, len = headers.length; i < len; i++){
  241. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  242. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  243. if(headers[i].formatter){
  244. sheet.setFormatter(-1, i, headers[i].formatter);
  245. }
  246. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  247. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  248. }
  249. };
  250. renderSheetFunc(sheet, fuc);
  251. }
  252. //表监听事件
  253. //@param {Object}workBook @return {void}
  254. function bindEvent(workBook, events) {
  255. if(Object.keys(events).length === 0){
  256. return;
  257. }
  258. const Events = GC.Spread.Sheets.Events;
  259. let sheet = workBook.getActiveSheet();
  260. for(let event in events){
  261. workBook.bind(Events[event], events[event]);
  262. }
  263. }
  264. //建表
  265. //@param {Object}module @return {void}
  266. function buildSheet(module) {
  267. if(!module.workBook){
  268. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  269. let sheet = module.workBook.getActiveSheet();
  270. if(module === bills){
  271. //默认初始可控制焦点在清单表中
  272. module.workBook.focus();
  273. sheet.options.isProtected = true;
  274. }
  275. else if(module === ration){
  276. sheet.options.isProtected = true;
  277. sheet.getRange(-1, 0, -1, 1).locked(false);
  278. sheet.getRange(-1, 1, -1, -1).locked(true);
  279. }
  280. else if(module === guideItem){
  281. sheetCommonObj.bindEscKey(module.workBook, [{sheet: sheet, editStarting: null, editEnded: module.events.EditEnded}]);
  282. }
  283. setOptions(module.workBook, options);
  284. buildHeader(module.workBook.getActiveSheet(), module.headers);
  285. bindEvent(module.workBook, module.events);
  286. }
  287. }
  288. //清空表数据
  289. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  290. function cleanData(sheet, headers, rowCount){
  291. renderSheetFunc(sheet, function () {
  292. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  293. if (rowCount >= 0) {
  294. sheet.setRowCount(rowCount);
  295. }
  296. });
  297. }
  298. //根据清单获取项目指引
  299. //@param {String}guidanceLibID {Number}billsID {Function}callback @return {void}
  300. function getItemsByBills(guidanceLibID, billsID, callback){
  301. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: guidanceLibID, billsID: billsID}, function (rstData) {
  302. if(callback){
  303. callback(rstData);
  304. }
  305. });
  306. }
  307. //清单表焦点控制
  308. //@param {Number}row @return {void}
  309. function billsInitSel(row){
  310. let guideSheet = guideItem.workBook.getActiveSheet();
  311. cleanData(guideSheet, guideItem.headers, -1);
  312. let node = bills.tree.items[row];
  313. if(!node){
  314. return;
  315. }
  316. bills.tree.selected = node;
  317. if(!node.guidance.tree){
  318. getItemsByBills(libID, node.data.ID, function (rstData) {
  319. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  320. //设置底色
  321. setNodesColor(guideSheet, node.guidance.tree.items);
  322. //项目指引初始焦点
  323. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  324. });
  325. }
  326. else{
  327. node.guidance.controller.showTreeData();
  328. //设置底色
  329. setNodesColor(guideSheet, node.guidance.tree.items);
  330. //项目指引初始焦点
  331. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  332. }
  333. }
  334. //根据奇偶层级设置节点底色,奇数层为蓝色(树节点深度为偶数)
  335. function setNodesColor(sheet, nodes) {
  336. const color = '#DFE8F9';
  337. renderSheetFunc(sheet, function () {
  338. for(let node of nodes){
  339. let style = new GC.Spread.Sheets.Style();
  340. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  341. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  342. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  343. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  344. let nDepth = node.depth();
  345. style.backColor = nDepth % 2 == 0 && _isDef(node.data.type) && node.data.type === itemType.job ? color : 'White';
  346. sheet.setStyle(node.serialNo(), -1, style);
  347. }
  348. });
  349. }
  350. //选中的节点是否全是同层节点
  351. //@param {Object}sheet {Array}items @return {Boolean}
  352. function itemsSameDepth(sheet, items) {
  353. let sels = sheet.getSelections();
  354. if(sels.length === 0 || items.length === 0){
  355. return false;
  356. }
  357. let depths = [];
  358. for(let i = 0; i < sels[0].rowCount; i++){
  359. let row = sels[0].row + i;
  360. let node = items[row];
  361. if(node){
  362. depths.push(node.depth());
  363. }
  364. }
  365. }
  366. //节点子项是否全是工作内容
  367. //@param {Object}node @return {Boolean}
  368. function allJobChildren(node){
  369. for(let c of node.children){
  370. if(c.data.type === itemType.ration){
  371. return false;
  372. }
  373. }
  374. return true;
  375. }
  376. //节点子项是否全是定额
  377. //@param {Object}node @return {Boolean}
  378. function allRationChildren(node){
  379. for(let c of node.children){
  380. if(c.data.type === itemType.job){
  381. return false;
  382. }
  383. }
  384. return true;
  385. }
  386. //刷新按钮有效性
  387. //@param {Object}node @return {void}
  388. function refreshBtn(node){
  389. //全部设为无效
  390. $('.tools-btn').children().addClass('disabled');
  391. $('#insertRation').addClass('disabled');
  392. $('.main-bottom-content').find('textarea').attr('readonly', true);
  393. //插入
  394. if(bills.tree.selected && bills.tree.selected.guidance.tree){
  395. $('#insert').removeClass('disabled');
  396. if(node && node.data.type === itemType.ration){
  397. $('#insert').addClass('disabled');
  398. }
  399. }
  400. //删除
  401. if(node){
  402. $('#del').removeClass('disabled');
  403. }
  404. if(node && node.data.type === itemType.job){
  405. //升级
  406. if(node.parent){
  407. $('#upLevel').removeClass('disabled');
  408. if(node.nextSibling && node.children.length > 0 && !allJobChildren(node)){
  409. $('#upLevel').addClass('disabled');
  410. }
  411. }
  412. //降级
  413. if(node.preSibling){
  414. $('#downLevel').removeClass('disabled');
  415. if(node.preSibling.children.length > 0 && !allJobChildren(node.preSibling)){
  416. $('#downLevel').addClass('disabled');
  417. }
  418. }
  419. }
  420. //上移
  421. if(node && node.preSibling){
  422. $('#upMove').removeClass('disabled')
  423. }
  424. //下移
  425. if(node && node.nextSibling){
  426. $('#downMove').removeClass('disabled');
  427. }
  428. //插入定额
  429. if(node && (node.children.length === 0 || allRationChildren(node))){
  430. $('#insertRation').removeClass('disabled');
  431. }
  432. //备注,奇数节点可用
  433. if(node && (node.depth() + 1) % 2 === 1 && node.data.type !== itemType.ration){
  434. $('.main-bottom-content').find('textarea').attr('readonly', false);
  435. }
  436. }
  437. //项目指引表焦点控制
  438. //@param {Number}row @return {void}
  439. function guideItemInitSel(row){
  440. let billsNode = bills.tree.selected;
  441. let node = null;
  442. if(billsNode && billsNode.guidance.tree){
  443. node = billsNode.guidance.tree.items[row];
  444. if(node){
  445. billsNode.guidance.tree.selected = node;
  446. //显示备注
  447. $('.main-bottom-content').find('textarea').val(node.data.comment ? node.data.comment : '');
  448. }
  449. }
  450. refreshBtn(node);
  451. }
  452. //初始化当前库名
  453. //@param {String} @return {void}
  454. function initLibName(libName) {
  455. $('#libName')[0].outerHTML = $('#libName')[0].outerHTML.replace("XXX清单指引", libName);
  456. }
  457. //初始化各工作表
  458. //@param {Array}modules @return {void}
  459. function initWorkBooks(modules){
  460. for(let module of modules){
  461. buildSheet(module);
  462. }
  463. }
  464. function tipDivCheck(){
  465. setTimeout(function () {
  466. let tips = $('#autoTip');
  467. if(ration.tipDiv == 'show'){
  468. return;
  469. } else if(ration.tipDiv == 'hide'&&tips){
  470. tips.hide();
  471. ration._toolTipElement = null;
  472. }
  473. },600)
  474. }
  475. //获取悬浮提示单元格
  476. //@param {Object}sheet @return {Object}
  477. function getTipCellType(sheet) {
  478. let setting = {};
  479. let TipCellType = function () {};
  480. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  481. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  482. return {
  483. x: x,
  484. y: y,
  485. row: context.row,
  486. col: context.col,
  487. cellStyle: cellStyle,
  488. cellRect: cellRect,
  489. sheet: context.sheet,
  490. sheetArea: context.sheetArea
  491. };
  492. };
  493. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  494. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  495. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  496. if(tag !== undefined && tag){
  497. text = tag;
  498. }
  499. if(sheet && sheet.getParent().qo){
  500. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  501. }
  502. if (setting.pos && text && text !== '') {
  503. //固定不显示的div,存储文本获取固定div宽度,toolTipElement由于显示和隐藏,获取宽度不正确
  504. if(!this._fixedTipElement){
  505. let div = $('#fixedTip')[0];
  506. if (!div) {
  507. div = document.createElement("div");
  508. $(div).css("padding", 5)
  509. .attr("id", 'fixedTip');
  510. $(div).hide();
  511. document.body.insertBefore(div, null);
  512. }
  513. this._fixedTipElement = div;
  514. }
  515. $(this._fixedTipElement).width('');
  516. $(this._fixedTipElement).html(text);
  517. if (!this._toolTipElement) {
  518. let div = $('#autoTip')[0];
  519. if (!div) {
  520. div = document.createElement("div");
  521. $(div).css("position", "absolute")
  522. .css("border", "1px #C0C0C0 solid")
  523. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  524. .css("font", "0.9rem Calibri")
  525. .css("background", "white")
  526. .css("padding", 5)
  527. .attr("id", 'autoTip');
  528. $(div).hide();
  529. document.body.insertBefore(div, null);
  530. }
  531. this._toolTipElement = div;
  532. $(this._toolTipElement).width('');
  533. //实时读取位置信息
  534. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  535. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  536. }
  537. $(this._toolTipElement).html(text);
  538. //定额库定额特殊处理
  539. if($(hitinfo.sheet.getParent().qo).attr('id') === 'rationSpread'){
  540. let divWidth = $(this._fixedTipElement).width(),
  541. divHeight = $(this._fixedTipElement).height();
  542. if(divWidth > 600){
  543. divWidth = 590;
  544. $(this._toolTipElement).width(divWidth);
  545. }
  546. $(this._toolTipElement).css("top", setting.pos.y + hitinfo.y - divHeight).css("left", setting.pos.x - divWidth);
  547. }
  548. else{
  549. $(this._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  550. }
  551. //名称
  552. if(hitinfo.col === 2){
  553. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  554. zoom = hitinfo.sheet.zoom();
  555. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  556. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  557. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  558. if(textLength > cellWidth){
  559. $(this._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  560. $(this._toolTipElement).show("fast");
  561. ration.tipDiv = 'show';//做个标记
  562. }
  563. }
  564. else {
  565. $(this._toolTipElement).show("fast");
  566. ration.tipDiv = 'show';//做个标记
  567. }
  568. }
  569. }
  570. };
  571. TipCellType.prototype.processMouseLeave = function (hininfo) {
  572. ration.tipDiv = 'hide';
  573. if (this._toolTipElement) {
  574. $(this._toolTipElement).hide();
  575. this._toolTipElement = null;
  576. }
  577. tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  578. }
  579. return new TipCellType();
  580. }
  581. //输出表数据(定额表)
  582. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  583. function showData(sheet, headers, datas){
  584. let fuc = function () {
  585. sheet.setRowCount(datas.length);
  586. //复选框
  587. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  588. let tipCellType = getTipCellType(sheet);
  589. sheet.setCellType(-1, 0, checkBoxType);
  590. for(let col = 0, cLen = headers.length; col < cLen; col++){
  591. for(let row = 0, rLen = datas.length; row < rLen; row++){
  592. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  593. if(col === 1){
  594. sheet.setTag(row, col, datas[row]['hint']);
  595. }
  596. }
  597. }
  598. sheet.setCellType(-1, 1, tipCellType);
  599. sheet.setCellType(-1, 2, tipCellType);
  600. };
  601. renderSheetFunc(sheet, fuc);
  602. }
  603. //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
  604. //@param {Number}sectionId {Array}rations @return {Array}
  605. function getRationsBySectionId(sectionId, rations) {
  606. if(!sectionId || !rations){
  607. return [];
  608. }
  609. return _.filter(rations, {sectionId});
  610. }
  611. //定额章节树焦点控制
  612. //@param {Number}row @return {void}
  613. function sectionInitSel(row) {
  614. let rationSheet = ration.workBook.getActiveSheet();
  615. let sectionNode = section.tree ? section.tree.items[row] : null;
  616. if(sectionNode && sectionNode.children.length === 0){
  617. let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
  618. ration.cache = sectionRations;
  619. showData(rationSheet, ration.headers, sectionRations);
  620. }
  621. else {
  622. cleanData(rationSheet, ration.headers, 0);
  623. }
  624. }
  625. //初始化定额条目
  626. //@param {Number}rationLibId @return {void}
  627. function initRationItems(rationLibId){
  628. $.bootstrapLoading.start();
  629. //获取定额章节树
  630. let sectionSheet = section.workBook.getActiveSheet();
  631. CommonAjax.post('/rationRepository/api/getRationTree', {rationLibId: rationLibId}, function (sectionDatas) {
  632. //获取所有定额数据
  633. let reqEntity = {rationLibId: rationLibId, showHint: true, returnFields: '-_id code ID sectionId name unit basePrice rationGljList jobContent annotation'};
  634. CommonAjax.post('/rationRepository/api/getRationItemsByLib', reqEntity, function (rstData) {
  635. section.cache = sectionDatas;
  636. initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
  637. //初始焦点在第一行(切换库)
  638. sectionSheet.setActiveCell(0, 0);
  639. rstData.sort(function (a, b) {
  640. let rst = 0;
  641. if(a.code > b.code){
  642. rst = 1;
  643. }
  644. else if(a.code < b.code){
  645. rst = -1;
  646. }
  647. return rst;
  648. });
  649. ration.datas = rstData;
  650. sectionInitSel(0);
  651. $.bootstrapLoading.end();
  652. }, function () {
  653. $.bootstrapLoading.end();
  654. });
  655. }, function () {
  656. $.bootstrapLoading.end();
  657. });
  658. }
  659. //初始化定额库选择
  660. //@param {String}compilationId @return {void}
  661. function initRationLibs(compilationId){
  662. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
  663. $('#rationLibSel').empty();
  664. for(let rationLib of rstData){
  665. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  666. $('#rationLibSel').append(opt);
  667. }
  668. //初始选择
  669. initRationItems(parseInt($('#rationLibSel').select().val()));
  670. $('#rationLibSel').change(function () {
  671. let rationLibId = parseInt($(this).select().val());
  672. initRationItems(rationLibId);
  673. })
  674. });
  675. }
  676. //获取指引库信息及关联的清单
  677. //@param {Number}libID {Function}callback @return {Object}
  678. function getLibWithBills(libID, callback){
  679. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  680. initRationLibs(rstData.guidanceLib.compilationId);
  681. bills.cache = rstData.bills;
  682. initLibName(rstData.guidanceLib.name);
  683. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  684. //每一棵项目指引树挂在清单节点上
  685. for(let node of bills.tree.items){
  686. node.guidance = {tree: null, controller: null};
  687. }
  688. //默认初始节点
  689. billsInitSel(0);
  690. if(callback){
  691. callback(rstData);
  692. }
  693. }, function (msg) {
  694. window.location.href = '/billsGuidance/main';
  695. });
  696. }
  697. //初始化并输出树
  698. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  699. function initTree(module, sheet, treeSetting, datas){
  700. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  701. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  702. module.tree.loadDatas(datas);
  703. module.controller.showTreeData();
  704. }
  705. //更新项目指引
  706. //@param {Array}updateDatas {Function}callback @return {void}
  707. function updateGuideItems(updateDatas, callback){
  708. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  709. if(callback){
  710. callback(rstData);
  711. }
  712. });
  713. }
  714. //项目指引编辑
  715. //@param {Object}sheet {Array}cells
  716. function edit(sheet, cells){
  717. let updateDatas = [];
  718. //同步节点数据
  719. let syncDatas = [];
  720. for(let cell of cells){
  721. let text = sheet.getValue(cell.row, cell.col);
  722. text = text ? text : '';
  723. let node = bills.tree.selected.guidance.tree.items[cell.row];
  724. if(node.data.name != text){
  725. syncDatas.push({node: node, text: text});
  726. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {name: text}});
  727. }
  728. }
  729. if(updateDatas.length > 0){
  730. updateGuideItems(updateDatas, function () {
  731. for(let syncData of syncDatas){
  732. syncData.node.data.name = syncData.text;
  733. }
  734. }, function () {
  735. //失败恢复
  736. renderSheetFunc(sheet, function () {
  737. for(let syncData of syncDatas){
  738. sheet.setValue(syncData.node.serialNo(), 0, syncData.node.data.name ? syncData.node.data.name : '');
  739. }
  740. });
  741. });
  742. }
  743. }
  744. //项目指引插入,支持一次插入多条数据
  745. //@param {Array}datas {Function}callback @return {void}
  746. function insert(datas, callback = null){
  747. $.bootstrapLoading.start();
  748. let sheet = guideItem.workBook.getActiveSheet();
  749. let controller = bills.tree.selected.guidance.controller;
  750. let selected = bills.tree.selected.guidance.tree.selected;
  751. let updateDatas = [];
  752. //建立数组下标索引
  753. let newDataIndex = {};
  754. for(let i = 0; i < datas.length; i++){
  755. let newNodeData = {
  756. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  757. billsID: bills.tree.selected.getID()
  758. };
  759. //定额类型插入当前工作内容焦点行,
  760. if(selected && selected.data.type === itemType.job && datas[i].type === itemType.ration){
  761. newNodeData.ParentID = selected.getID();
  762. newNodeData.NextSiblingID = -1;
  763. }
  764. Object.assign(newNodeData, datas[i]);
  765. newDataIndex[i] = newNodeData;
  766. }
  767. for(let i = 0; i < datas.length; i++){
  768. //第一个节点
  769. if(i === 0){
  770. //非插入成子节点,更新选中节点NestSiblingID
  771. if(selected && !(selected.data.type === itemType.job && datas[i].type === itemType.ration)){
  772. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  773. }
  774. }
  775. //非最后一个节点
  776. if(i !== datas.length - 1){
  777. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  778. }
  779. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  780. }
  781. updateGuideItems(updateDatas, function () {
  782. for(let updateData of updateDatas){
  783. if(updateData.updateType === updateType.create){
  784. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  785. //同步data
  786. Object.assign(newNode.data, updateData.updateData);
  787. sheet.setValue(newNode.serialNo(), 0, newNode.data.name);
  788. refreshBtn(newNode);
  789. }
  790. }
  791. if(callback){
  792. callback();
  793. }
  794. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  795. guideItem.workBook.focus(true);
  796. $.bootstrapLoading.end();
  797. });
  798. }
  799. //项目指引删除操作
  800. //@return {void}
  801. function del(){
  802. $.bootstrapLoading.start();
  803. let controller = bills.tree.selected.guidance.controller;
  804. let selected = bills.tree.selected.guidance.tree.selected;
  805. let updateDatas = [];
  806. function getDelDatas(node){
  807. updateDatas.push({updateType: updateType.del, findData: {ID: node.getID()}, updateData: {deleted: true}});
  808. if(node.children.length > 0){
  809. for(let c of node.children){
  810. getDelDatas(c);
  811. }
  812. }
  813. }
  814. getDelDatas(selected);
  815. updateGuideItems(updateDatas, function () {
  816. controller.delete();
  817. refreshBtn(bills.tree.selected.guidance.tree.selected);
  818. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  819. $.bootstrapLoading.end();
  820. guideItem.workBook.focus(true)
  821. });
  822. }
  823. //项目指引升级
  824. //@return {void}
  825. function upLevel(){
  826. $.bootstrapLoading.start();
  827. let controller = bills.tree.selected.guidance.controller;
  828. let selected = bills.tree.selected.guidance.tree.selected;
  829. let updateDatas = [];
  830. //更新父节点
  831. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  832. //更新选中节点
  833. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()},
  834. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID()}});
  835. if(selected.nextSibling && selected.children.length > 0){
  836. //更新选中节点最末子节点
  837. let lastChild = selected.children[selected.children.length - 1];
  838. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  839. }
  840. updateGuideItems(updateDatas, function () {
  841. controller.upLevel();
  842. refreshBtn(bills.tree.selected.guidance.tree.selected);
  843. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  844. $.bootstrapLoading.end();
  845. guideItem.workBook.focus(true)
  846. });
  847. }
  848. //项目指引降级
  849. //@return {void}
  850. function downLevel(){
  851. $.bootstrapLoading.start();
  852. let controller = bills.tree.selected.guidance.controller;
  853. let selected = bills.tree.selected.guidance.tree.selected;
  854. let updateDatas = [];
  855. //更新前兄弟节点
  856. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  857. //更新前兄弟节点最末子节点
  858. if(selected.preSibling.children.length > 0){
  859. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  860. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  861. }
  862. //更新选中节点
  863. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1}});
  864. updateGuideItems(updateDatas, function () {
  865. controller.downLevel();
  866. refreshBtn(bills.tree.selected.guidance.tree.selected);
  867. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  868. $.bootstrapLoading.end();
  869. guideItem.workBook.focus(true)
  870. });
  871. }
  872. //项目指引上移
  873. //@return {void}
  874. function upMove(){
  875. $.bootstrapLoading.start();
  876. let controller = bills.tree.selected.guidance.controller;
  877. let selected = bills.tree.selected.guidance.tree.selected;
  878. let updateDatas = [];
  879. //更新前节点
  880. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  881. //更新前前节点
  882. if(selected.preSibling.preSibling){
  883. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  884. }
  885. //更新选中节点
  886. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  887. updateGuideItems(updateDatas, function () {
  888. controller.upMove();
  889. refreshBtn(bills.tree.selected.guidance.tree.selected);
  890. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  891. $.bootstrapLoading.end();
  892. guideItem.workBook.focus(true)
  893. });
  894. }
  895. //项目指引下移
  896. //@return {void}
  897. function downMove(){
  898. $.bootstrapLoading.start();
  899. let controller = bills.tree.selected.guidance.controller;
  900. let selected = bills.tree.selected.guidance.tree.selected;
  901. let updateDatas = [];
  902. //更新下节点
  903. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  904. //更新前节点
  905. if(selected.preSibling){
  906. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  907. }
  908. //更新选中节点
  909. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  910. updateGuideItems(updateDatas, function () {
  911. controller.downMove();
  912. refreshBtn(bills.tree.selected.guidance.tree.selected);
  913. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  914. $.bootstrapLoading.end();
  915. guideItem.workBook.focus(true)
  916. });
  917. }
  918. //获取定额类型的项目指引名称,通过定额转换
  919. //@param {Object}ration @return {String}
  920. function getRationItemName(ration){
  921. let arr = [];
  922. arr.push(ration.code ? ration.code : '');
  923. arr.push(ration.name ? ration.name : '');
  924. arr.push(ration.basePrice ? ration.basePrice : '');
  925. let rst = arr.join(' ');
  926. rst += `/${ration.unit ? ration.unit : ''}`;
  927. return rst;
  928. }
  929. //获取选中的定额表行
  930. //@return {Array}
  931. function getCheckedRationRows(){
  932. let rst = [];
  933. let sheet = ration.workBook.getActiveSheet();
  934. for(let i = 0; i < sheet.getRowCount(); i++){
  935. let checked = sheet.getValue(i, 0);
  936. if(checked){
  937. rst.push(i);
  938. }
  939. }
  940. return rst;
  941. }
  942. //清空选中定额表行
  943. //@param {Array}rows @return {void}
  944. function clearCheckedRation(rows) {
  945. let sheet = ration.workBook.getActiveSheet();
  946. renderSheetFunc(sheet, function () {
  947. for(let row of rows){
  948. sheet.setValue(row, 0, 0);
  949. }
  950. });
  951. }
  952. //获取要插入的定额数据
  953. //@param {Array}rows @return {Array}
  954. function getInsertRations(rows){
  955. let rst = [];
  956. //当前已存在定额
  957. let curRationIems = [];
  958. let selected = bills.tree.selected.guidance.tree.selected;
  959. if(selected){
  960. if(selected.data.type === itemType.job){
  961. curRationIems = selected.children;
  962. }
  963. else {
  964. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  965. }
  966. }
  967. for(let row of rows){
  968. let selRation = ration.cache[row];
  969. if(selRation){
  970. //添加的定额是否已存在,不重复添加
  971. let isExist = false;
  972. for(let curRation of curRationIems){
  973. if(curRation.data.rationID == selRation.ID){
  974. isExist = true;
  975. break;
  976. }
  977. }
  978. if(!isExist){
  979. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  980. }
  981. }
  982. }
  983. return rst;
  984. }
  985. //获取块节点父项不存在于选中节点中的节点
  986. //@param {Array}nodes(选中的节点) @return {Array}
  987. function getBlockNodes(nodes) {
  988. let nodeMapping = {};
  989. for(let node of nodes){
  990. nodeMapping[node.data.ID] = node;
  991. }
  992. //块节点,父项不存在于选中节点中的节点
  993. let blockNodes = [];
  994. for(let node of nodes){
  995. if(!nodeMapping[node.data.ParentID]){
  996. blockNodes.push(node);
  997. }
  998. }
  999. return blockNodes;
  1000. }
  1001. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1002. //@param {Array}nodes(块节点) @return {Boolean}
  1003. function canCopyBlock(nodes) {
  1004. if(!nodes || nodes.length === 0){
  1005. return false;
  1006. }
  1007. let pID = nodes[0].data.ParentID;
  1008. for(let node of nodes){
  1009. if(node.data.ParentID !== pID){
  1010. return false;
  1011. }
  1012. }
  1013. return true;
  1014. }
  1015. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1016. //@param {Object}node(粘贴到的节点)
  1017. function canPasteBlock(node) {
  1018. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1019. if(!pasteDatas || pasteDatas.length === 0){
  1020. return false;
  1021. }
  1022. if(!node){
  1023. return false;
  1024. }
  1025. //若粘贴到定额节点,则数据须全为定额
  1026. if(node.data.type === itemType.ration){
  1027. for(let data of pasteDatas){
  1028. if(data.type !== itemType.ration){
  1029. return false;
  1030. }
  1031. }
  1032. }
  1033. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1034. else {
  1035. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1036. for(let topData of topDatas){
  1037. if(topData.type === itemType.ration){
  1038. return false;
  1039. }
  1040. }
  1041. }
  1042. return true;
  1043. }
  1044. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1045. //@param {Array}nodes(块节点) @return {void}
  1046. function copyBlocks(nodes) {
  1047. nodes = _.cloneDeep(nodes);
  1048. //将块节点的ParentID暂时设置为-1
  1049. for(let topNode of nodes){
  1050. topNode.data.ParentID = -1;
  1051. }
  1052. let copyDatas = [];
  1053. let copyNodes = [];
  1054. //获取块节点包含的所有节点(包括自己)
  1055. function containNodes(nodes) {
  1056. for(let node of nodes){
  1057. copyNodes.push(node);
  1058. if(node.children.length > 0){
  1059. containNodes(node.children);
  1060. }
  1061. }
  1062. }
  1063. containNodes(nodes);
  1064. for(let node of copyNodes){
  1065. copyDatas.push(node.data);
  1066. }
  1067. console.log(`copyDatas`);
  1068. console.log(copyDatas);
  1069. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1070. }
  1071. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1072. //@param {Object}node(粘贴到的节点) @return {void}
  1073. function pasteBlock(node) {
  1074. let itemObj = bills.tree.selected.guidance;
  1075. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1076. //整理ID
  1077. let IDMapping = {};
  1078. for(let data of pasteDatas){
  1079. data.newID = uuid.v1();
  1080. IDMapping[data.ID] = data;
  1081. }
  1082. for(let data of pasteDatas){
  1083. let nextData = IDMapping[data.NextSiblingID];
  1084. data.NextSiblingID = nextData ? nextData.newID : -1;
  1085. let parentData = IDMapping[data.ParentID];
  1086. data.ParentID = parentData ? parentData.newID : -1;
  1087. }
  1088. for(let data of pasteDatas){
  1089. data.ID = data.newID;
  1090. delete data.newID;
  1091. }
  1092. let updateDatas = [];
  1093. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1094. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1095. for(let topData of topDatas){
  1096. topData.ParentID = node.getParentID();
  1097. }
  1098. //更新数据
  1099. //更新插入的最末顶层数据NextSiblingID
  1100. if(node.nextSibling){
  1101. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1102. }
  1103. //新建节点
  1104. for(let data of pasteDatas){
  1105. data.libID = libID;
  1106. data.billsID = node.data.billsID;
  1107. delete data._id;
  1108. updateDatas.push({updateType: updateType.create, updateData: data});
  1109. }
  1110. console.log(`node`);
  1111. console.log(node);
  1112. console.log(`pasteDatas`);
  1113. console.log(pasteDatas);
  1114. //更新粘贴到的节点的NextSiblingID
  1115. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1116. $.bootstrapLoading.start();
  1117. updateGuideItems(updateDatas, function (rstData) {
  1118. $.bootstrapLoading.end();
  1119. node.data.NextSiblingID = topDatas[0].ID;
  1120. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1121. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1122. itemObj.controller.showTreeData();
  1123. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1124. }, function () {
  1125. $.bootstrapLoading.end();
  1126. });
  1127. }
  1128. //初始化右键菜单
  1129. //@return {void}
  1130. function initContextMenu() {
  1131. $.contextMenu({
  1132. selector: '#guideItemSpread',
  1133. build: function($triggerElement, e){
  1134. //控制允许右键菜单在哪个位置出现
  1135. let sheet = guideItem.workBook.getSheet(0);
  1136. let offset = $("#guideItemSpread").offset(),
  1137. x = e.pageX - offset.left,
  1138. y = e.pageY - offset.top;
  1139. let target = sheet.hitTest(x, y);
  1140. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1141. let sel = sheet.getSelections()[0];
  1142. if(sel && sel.rowCount === 1){
  1143. sheet.setActiveCell(target.row, target.col);
  1144. }
  1145. sel = sheet.getSelections()[0];
  1146. let selNodes = [];
  1147. if(sel){
  1148. sel.row = sel.row === -1 ? 0 : sel.row;
  1149. for(let i = 0; i < sel.rowCount; i++){
  1150. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1151. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1152. }
  1153. }
  1154. }
  1155. //块节点
  1156. let blockNodes = getBlockNodes(selNodes);
  1157. //右键在多选内则不重设焦点
  1158. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1159. sheet.setActiveCell(target.row, target.col);
  1160. }
  1161. guideItemInitSel(target.row);
  1162. return {
  1163. callback: function(){},
  1164. items: {
  1165. "copy": {
  1166. name: "复制整块",
  1167. disabled: function () {
  1168. return !canCopyBlock(blockNodes);
  1169. },
  1170. icon: "fa-copy",
  1171. callback: function (key, opt) {
  1172. copyBlocks(blockNodes);
  1173. }},
  1174. "paste": {
  1175. name: "粘贴整块",
  1176. disabled: function () {
  1177. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1178. return !canPasteBlock(pasteNode);
  1179. },
  1180. icon: "fa-paste",
  1181. callback: function (key, opt) {
  1182. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1183. pasteBlock(pasteNode);
  1184. }},
  1185. }
  1186. };
  1187. }
  1188. else{
  1189. return false;
  1190. }
  1191. }
  1192. });
  1193. }
  1194. //初始化个按钮点击
  1195. //@return {void}
  1196. function initBtn(){
  1197. $('#insert').click(function () {
  1198. insert([{type: itemType.job, name: ''}]);
  1199. });
  1200. $('#delConfirm').click(function () {
  1201. del();
  1202. $('#delAlert').modal('hide');
  1203. });
  1204. $('#del').click(function () {
  1205. $('#delAlert').modal('show');
  1206. });
  1207. $('#upLevel').click(function () {
  1208. upLevel();
  1209. });
  1210. $('#downLevel').click(function () {
  1211. downLevel();
  1212. });
  1213. $('#upMove').click(function () {
  1214. upMove();
  1215. });
  1216. $('#downMove').click(function () {
  1217. downMove();
  1218. });
  1219. $('#insertRation').click(function () {
  1220. let checkedRows = getCheckedRationRows();
  1221. let insertDatas = getInsertRations(checkedRows);
  1222. if(insertDatas.length > 0){
  1223. insert(insertDatas, function () {
  1224. //清空选择
  1225. clearCheckedRation(checkedRows);
  1226. });
  1227. }
  1228. else {
  1229. clearCheckedRation(checkedRows);
  1230. }
  1231. });
  1232. //搜索定额
  1233. $('#searchBtn').click(function () {
  1234. let searchStr = $('#searchText').val();
  1235. if(!searchStr || searchStr === ''){
  1236. ration.cache = ration.datas;
  1237. }
  1238. else{
  1239. let reg = new RegExp(searchStr, 'i');
  1240. ration.cache = _.filter(ration.datas, function (data) {
  1241. return reg.test(data.code) || reg.test(data.name);
  1242. });
  1243. }
  1244. $('.top-content').hide();
  1245. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  1246. $('#rationSearchResult').show();
  1247. autoFlashHeight();
  1248. ration.workBook.refresh();
  1249. let rationSheet = ration.workBook.getActiveSheet();
  1250. renderSheetFunc(rationSheet, function () {
  1251. clearCheckedRation(getCheckedRationRows());
  1252. showData(rationSheet, ration.headers, ration.cache);
  1253. })
  1254. });
  1255. //关闭搜索
  1256. $('#rationSearchResult a').click(function () {
  1257. $('.top-content').show();
  1258. $('#rationSearchResult').hide();
  1259. autoFlashHeight();
  1260. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  1261. clearCheckedRation(getCheckedRationRows());
  1262. });
  1263. section.workBook.refresh();
  1264. ration.workBook.refresh();
  1265. $('#searchText').val('');
  1266. //恢复章节树下的定额
  1267. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  1268. });
  1269. //执行搜索
  1270. $('#searchText').keyup(function (e) {
  1271. $('#searchBtn').click();
  1272. });
  1273. //编辑备注
  1274. $('.main-bottom-content').find('textarea').keyup(function () {
  1275. let node = bills.tree.selected.guidance.tree.selected;
  1276. if(node){
  1277. let comment = $(this).val();
  1278. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  1279. updateGuideItems(updateDatas, function (rstData) {
  1280. node.data.comment = comment;
  1281. });
  1282. }
  1283. });
  1284. }
  1285. //初始化视图
  1286. //@param {void} @return {void}
  1287. function initViews(){
  1288. let modules = [bills, guideItem, section, ration];
  1289. initWorkBooks(modules);
  1290. getLibWithBills(libID);
  1291. initBtn();
  1292. initContextMenu();
  1293. }
  1294. return {initViews};
  1295. })();
  1296. $(document).ready(function () {
  1297. billsGuidance.initViews();
  1298. CommonAjax.post('/billsGuidance/api/testItems', {libID: getQueryString('libID')}, function (rstData) {
  1299. console.log(rstData);
  1300. });
  1301. });