billsGuidance.js 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553
  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, false);
  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 {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  746. function insert(datas, tobeChild, 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) || tobeChild)){
  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) || tobeChild)){
  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: -1}});
  839. }
  840. //选中节点的所有后兄弟节点成为选中节点的子项
  841. let selectedNextIDs = [];
  842. let sNext = selected.nextSibling;
  843. while(sNext){
  844. selectedNextIDs.push(sNext.getID());
  845. sNext = sNext.nextSibling;
  846. }
  847. for(let sID of selectedNextIDs){
  848. updateDatas.push({updateType: updateType.update, findData: {ID: sID}, updateData: {ParentID: selected.getID()}});
  849. }
  850. updateGuideItems(updateDatas, function () {
  851. controller.upLevel();
  852. refreshBtn(bills.tree.selected.guidance.tree.selected);
  853. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  854. $.bootstrapLoading.end();
  855. guideItem.workBook.focus(true)//31574
  856. });
  857. }
  858. //项目指引降级
  859. //@return {void}
  860. function downLevel(){
  861. $.bootstrapLoading.start();
  862. let controller = bills.tree.selected.guidance.controller;
  863. let selected = bills.tree.selected.guidance.tree.selected;
  864. let updateDatas = [];
  865. //更新前兄弟节点
  866. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  867. //更新前兄弟节点最末子节点
  868. if(selected.preSibling.children.length > 0){
  869. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  870. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  871. }
  872. //更新选中节点
  873. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1}});
  874. updateGuideItems(updateDatas, function () {
  875. controller.downLevel();
  876. refreshBtn(bills.tree.selected.guidance.tree.selected);
  877. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  878. $.bootstrapLoading.end();
  879. guideItem.workBook.focus(true)
  880. });
  881. }
  882. //项目指引上移
  883. //@return {void}
  884. function upMove(){
  885. $.bootstrapLoading.start();
  886. let controller = bills.tree.selected.guidance.controller;
  887. let selected = bills.tree.selected.guidance.tree.selected;
  888. let updateDatas = [];
  889. //更新前节点
  890. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  891. //更新前前节点
  892. if(selected.preSibling.preSibling){
  893. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  894. }
  895. //更新选中节点
  896. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  897. updateGuideItems(updateDatas, function () {
  898. controller.upMove();
  899. refreshBtn(bills.tree.selected.guidance.tree.selected);
  900. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  901. $.bootstrapLoading.end();
  902. guideItem.workBook.focus(true)
  903. });
  904. }
  905. //项目指引下移
  906. //@return {void}
  907. function downMove(){
  908. $.bootstrapLoading.start();
  909. let controller = bills.tree.selected.guidance.controller;
  910. let selected = bills.tree.selected.guidance.tree.selected;
  911. let updateDatas = [];
  912. //更新下节点
  913. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  914. //更新前节点
  915. if(selected.preSibling){
  916. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  917. }
  918. //更新选中节点
  919. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  920. updateGuideItems(updateDatas, function () {
  921. controller.downMove();
  922. refreshBtn(bills.tree.selected.guidance.tree.selected);
  923. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  924. $.bootstrapLoading.end();
  925. guideItem.workBook.focus(true)
  926. });
  927. }
  928. //获取定额类型的项目指引名称,通过定额转换
  929. //@param {Object}ration @return {String}
  930. function getRationItemName(ration){
  931. let arr = [];
  932. arr.push(ration.code ? ration.code : '');
  933. arr.push(ration.name ? ration.name : '');
  934. arr.push(ration.basePrice ? ration.basePrice : '');
  935. let rst = arr.join(' ');
  936. rst += `/${ration.unit ? ration.unit : ''}`;
  937. return rst;
  938. }
  939. //获取选中的定额表行
  940. //@return {Array}
  941. function getCheckedRationRows(){
  942. let rst = [];
  943. let sheet = ration.workBook.getActiveSheet();
  944. for(let i = 0; i < sheet.getRowCount(); i++){
  945. let checked = sheet.getValue(i, 0);
  946. if(checked){
  947. rst.push(i);
  948. }
  949. }
  950. return rst;
  951. }
  952. //清空选中定额表行
  953. //@param {Array}rows @return {void}
  954. function clearCheckedRation(rows) {
  955. let sheet = ration.workBook.getActiveSheet();
  956. renderSheetFunc(sheet, function () {
  957. for(let row of rows){
  958. sheet.setValue(row, 0, 0);
  959. }
  960. });
  961. }
  962. //获取要插入的定额数据
  963. //@param {Array}rows @return {Array}
  964. function getInsertRations(rows){
  965. let rst = [];
  966. //当前已存在定额
  967. let curRationIems = [];
  968. let selected = bills.tree.selected.guidance.tree.selected;
  969. if(selected){
  970. if(selected.data.type === itemType.job){
  971. curRationIems = selected.children;
  972. }
  973. else {
  974. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  975. }
  976. }
  977. for(let row of rows){
  978. let selRation = ration.cache[row];
  979. if(selRation){
  980. //添加的定额是否已存在,不重复添加
  981. let isExist = false;
  982. for(let curRation of curRationIems){
  983. if(curRation.data.rationID == selRation.ID){
  984. isExist = true;
  985. break;
  986. }
  987. }
  988. if(!isExist){
  989. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  990. }
  991. }
  992. }
  993. return rst;
  994. }
  995. //获取块节点父项不存在于选中节点中的节点
  996. //@param {Array}nodes(选中的节点) @return {Array}
  997. function getBlockNodes(nodes) {
  998. let nodeMapping = {};
  999. for(let node of nodes){
  1000. nodeMapping[node.data.ID] = node;
  1001. }
  1002. //块节点,父项不存在于选中节点中的节点
  1003. let blockNodes = [];
  1004. for(let node of nodes){
  1005. if(!nodeMapping[node.data.ParentID]){
  1006. blockNodes.push(node);
  1007. }
  1008. }
  1009. return blockNodes;
  1010. }
  1011. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1012. //@param {Array}nodes(块节点) @return {Boolean}
  1013. function canCopyBlock(nodes) {
  1014. if(!nodes || nodes.length === 0){
  1015. return false;
  1016. }
  1017. let pID = nodes[0].data.ParentID;
  1018. for(let node of nodes){
  1019. if(node.data.ParentID !== pID){
  1020. return false;
  1021. }
  1022. }
  1023. return true;
  1024. }
  1025. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1026. //@param {Object}node(粘贴到的节点)
  1027. function canPasteBlock(node) {
  1028. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1029. if(!pasteDatas || pasteDatas.length === 0){
  1030. return false;
  1031. }
  1032. if(!node){
  1033. return false;
  1034. }
  1035. //若粘贴到定额节点,则数据须全为定额
  1036. if(node.data.type === itemType.ration){
  1037. for(let data of pasteDatas){
  1038. if(data.type !== itemType.ration){
  1039. return false;
  1040. }
  1041. }
  1042. }
  1043. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1044. else {
  1045. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1046. for(let topData of topDatas){
  1047. if(topData.type === itemType.ration){
  1048. return false;
  1049. }
  1050. }
  1051. }
  1052. return true;
  1053. }
  1054. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1055. //@param {Array}nodes(块节点) @return {void}
  1056. function copyBlocks(nodes) {
  1057. nodes = _.cloneDeep(nodes);
  1058. //将块节点的ParentID暂时设置为-1
  1059. for(let topNode of nodes){
  1060. topNode.data.ParentID = -1;
  1061. }
  1062. let copyDatas = [];
  1063. let copyNodes = [];
  1064. //获取块节点包含的所有节点(包括自己)
  1065. function containNodes(nodes) {
  1066. for(let node of nodes){
  1067. copyNodes.push(node);
  1068. if(node.children.length > 0){
  1069. containNodes(node.children);
  1070. }
  1071. }
  1072. }
  1073. containNodes(nodes);
  1074. for(let node of copyNodes){
  1075. copyDatas.push(node.data);
  1076. }
  1077. console.log(`copyDatas`);
  1078. console.log(copyDatas);
  1079. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1080. }
  1081. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1082. //@param {Object}node(粘贴到的节点) @return {void}
  1083. function pasteBlock(node) {
  1084. let itemObj = bills.tree.selected.guidance;
  1085. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1086. //整理ID
  1087. let IDMapping = {};
  1088. for(let data of pasteDatas){
  1089. data.newID = uuid.v1();
  1090. IDMapping[data.ID] = data;
  1091. }
  1092. for(let data of pasteDatas){
  1093. let nextData = IDMapping[data.NextSiblingID];
  1094. data.NextSiblingID = nextData ? nextData.newID : -1;
  1095. let parentData = IDMapping[data.ParentID];
  1096. data.ParentID = parentData ? parentData.newID : -1;
  1097. }
  1098. for(let data of pasteDatas){
  1099. data.ID = data.newID;
  1100. delete data.newID;
  1101. }
  1102. let updateDatas = [];
  1103. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1104. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1105. for(let topData of topDatas){
  1106. topData.ParentID = node.getParentID();
  1107. }
  1108. //更新数据
  1109. //更新插入的最末顶层数据NextSiblingID
  1110. if(node.nextSibling){
  1111. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1112. }
  1113. //新建节点
  1114. for(let data of pasteDatas){
  1115. data.libID = libID;
  1116. data.billsID = node.data.billsID;
  1117. delete data._id;
  1118. updateDatas.push({updateType: updateType.create, updateData: data});
  1119. }
  1120. console.log(`node`);
  1121. console.log(node);
  1122. console.log(`pasteDatas`);
  1123. console.log(pasteDatas);
  1124. //更新粘贴到的节点的NextSiblingID
  1125. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1126. $.bootstrapLoading.start();
  1127. updateGuideItems(updateDatas, function (rstData) {
  1128. $.bootstrapLoading.end();
  1129. node.data.NextSiblingID = topDatas[0].ID;
  1130. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1131. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1132. itemObj.controller.showTreeData();
  1133. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1134. }, function () {
  1135. $.bootstrapLoading.end();
  1136. });
  1137. }
  1138. //初始化右键菜单
  1139. //@return {void}
  1140. function initContextMenu() {
  1141. $.contextMenu({
  1142. selector: '#guideItemSpread',
  1143. build: function($triggerElement, e){
  1144. //控制允许右键菜单在哪个位置出现
  1145. let sheet = guideItem.workBook.getSheet(0);
  1146. let offset = $("#guideItemSpread").offset(),
  1147. x = e.pageX - offset.left,
  1148. y = e.pageY - offset.top;
  1149. let target = sheet.hitTest(x, y);
  1150. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1151. let sel = sheet.getSelections()[0];
  1152. if(sel && sel.rowCount === 1){
  1153. sheet.setActiveCell(target.row, target.col);
  1154. }
  1155. sel = sheet.getSelections()[0];
  1156. let selNodes = [];
  1157. if(sel){
  1158. sel.row = sel.row === -1 ? 0 : sel.row;
  1159. for(let i = 0; i < sel.rowCount; i++){
  1160. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1161. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1162. }
  1163. }
  1164. }
  1165. //块节点
  1166. let blockNodes = getBlockNodes(selNodes);
  1167. //右键在多选内则不重设焦点
  1168. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1169. sheet.setActiveCell(target.row, target.col);
  1170. }
  1171. guideItemInitSel(target.row);
  1172. return {
  1173. callback: function(){},
  1174. items: {
  1175. "copy": {
  1176. name: "复制整块",
  1177. disabled: function () {
  1178. return !canCopyBlock(blockNodes);
  1179. },
  1180. icon: "fa-copy",
  1181. callback: function (key, opt) {
  1182. copyBlocks(blockNodes);
  1183. }},
  1184. "paste": {
  1185. name: "粘贴整块",
  1186. disabled: function () {
  1187. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1188. return !canPasteBlock(pasteNode);
  1189. },
  1190. icon: "fa-paste",
  1191. callback: function (key, opt) {
  1192. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1193. pasteBlock(pasteNode);
  1194. }},
  1195. "insertSibling": {
  1196. name: '插入行',
  1197. disabled: function () {
  1198. let node = bills.tree.selected.guidance.tree.items[target.row];
  1199. return !node || node.data.type !== itemType.job;
  1200. },
  1201. icon: "fa-arrow-left",
  1202. callback: function (key, opt) {
  1203. insert([{type: itemType.job, name: ''}], false);
  1204. }
  1205. },
  1206. "insertChild": {
  1207. name: '插入子项',
  1208. disabled: function () {
  1209. let node = bills.tree.selected.guidance.tree.items[target.row];
  1210. return !node || node.data.type !== itemType.job || !allJobChildren(node);
  1211. },
  1212. icon: 'fa-arrow-left',
  1213. callback: function (key, opt) {
  1214. insert([{type: itemType.job, name: ''}], true);
  1215. }
  1216. }
  1217. }
  1218. };
  1219. }
  1220. else{
  1221. return false;
  1222. }
  1223. }
  1224. });
  1225. }
  1226. //拖动相关
  1227. let mouseMoveCount = 0;
  1228. let rationLibResizeEles = {};
  1229. rationLibResizeEles.id = '#de';
  1230. rationLibResizeEles.resize = $('#deResize');
  1231. rationLibResizeEles.nearElement = $('#de').find('.top-content');
  1232. rationLibResizeEles.nearSpread = $('#sectionSpread');
  1233. rationLibResizeEles.farElement = $('#de').find('.bottom-content');
  1234. rationLibResizeEles.farSpread = $('#rationSpread');
  1235. rationLibResizeEles.nav = null;
  1236. function setDefaultSize(tag,eles,type) {
  1237. let o_nearSize = 5;
  1238. let o_farSize = 2;
  1239. if(type == 'height'){
  1240. let headerHeight = $(".header").height();
  1241. let toolsbarHeight = $(".sidebar-tools-bar").height();
  1242. let resizeHeight = 6;
  1243. let totalHeight = $(window).height() - headerHeight - toolsbarHeight - resizeHeight;
  1244. const navSize = eles.nav ? eles.nav[type]() + 4 : 0;
  1245. totalHeight = totalHeight - navSize;
  1246. let nearSize = (o_nearSize/(o_nearSize + o_farSize))* totalHeight;
  1247. eles.nearSpread[type](nearSize);
  1248. eles.nearElement[type](nearSize);
  1249. eles.farSpread[type](totalHeight - nearSize);
  1250. eles.farElement[type](totalHeight - nearSize);
  1251. }
  1252. }
  1253. function setSizeWithPercent(tag,eles,nearSize,farSize,type) {
  1254. nearSize = parseFloat(nearSize);
  1255. farSize = parseFloat(farSize);
  1256. if(type !== 'width') {
  1257. let headerHeight = $(".header").height();
  1258. let toolsbarHeight = $(".sidebar-tools-bar").height();
  1259. let resizeHeight = 6;
  1260. let totalHeight = $(window).height() - headerHeight - toolsbarHeight - resizeHeight;
  1261. const navSize = eles.nav ? eles.nav[type]() + 4 : 0;
  1262. totalHeight = totalHeight - navSize;
  1263. nearSize = (nearSize/(nearSize + farSize))* totalHeight;
  1264. eles.nearSpread[type](nearSize);
  1265. eles.nearElement[type](nearSize);
  1266. eles.farSpread[type](totalHeight - nearSize);
  1267. eles.farElement[type](totalHeight - nearSize);
  1268. }
  1269. }
  1270. /**
  1271. * 读取设置的高度
  1272. *
  1273. * @param {String} tag - 顶层div的id
  1274. * @param {function} callback - 回调函数
  1275. * @return {void}
  1276. */
  1277. function loadSize(eles, type, callback) {
  1278. let tag = eles.id;
  1279. if (tag === '') {
  1280. return;
  1281. }
  1282. if(type !== 'height' && type !== 'width'){
  1283. return;
  1284. }
  1285. let o_nearSize = eles.nearSpread[type]();
  1286. let o_farSize = eles.farSpread[type]();
  1287. let nearSize = getLocalCache(`near${type}:${tag}`);
  1288. let farSize = getLocalCache(`far${type}:${tag}`);
  1289. if (nearSize === null || farSize === null) {
  1290. setDefaultSize(tag,eles,type);
  1291. }else {
  1292. setSizeWithPercent(tag,eles,nearSize,farSize,type)//zhang 2018-06-04 改成按百分比设置
  1293. }
  1294. callback();
  1295. }
  1296. /**
  1297. * 拖动更改div大小
  1298. *
  1299. * @param {Object} eles - id:存储本地的标记 resize:拖动条 nearElement:左上外层div nearSpread:左上spread farElement:右下外层div evFixedSize:造价书左右拖动用
  1300. * @param {Object} limit - min/max
  1301. * @param {String} type - height/width
  1302. * @param {function} callback - 成功后执行
  1303. * @return {void}
  1304. */
  1305. function slideResize(eles, limit, type, callback) {
  1306. if(type !== 'height' && type !== 'width'){
  1307. return;
  1308. }
  1309. //nearElement:左上, farElement:右下
  1310. let startP = 0;
  1311. let drag = false;
  1312. const resizeElement = eles.resize;
  1313. const nElement = eles.nearElement;
  1314. const fElement = eles.farElement;
  1315. const navContentEle = eles.nav ? eles.nav : null;
  1316. let nEleSize = 0;
  1317. let fEleSize = 0;
  1318. let navSize = 0;
  1319. let nEleChangeSize = 0;
  1320. let fEleChangeSize = 0;
  1321. // 鼠标点下时
  1322. resizeElement.mousedown(function(e) {
  1323. drag = true;
  1324. startP = type === 'height' ? e.clientY : e.clientX;
  1325. // 获取左(上)部分的宽度(高度)
  1326. nEleSize = nElement[type]();
  1327. // 获取右(下)部分的宽度(高度)
  1328. fEleSize = fElement[type]();
  1329. // nav宽(高度)部分
  1330. if(navContentEle){
  1331. navSize = navContentEle[type]() + 4;
  1332. }
  1333. resizeElement.tooltip('hide');
  1334. });
  1335. // 鼠标移动
  1336. $("body").mousemove(function(e) {
  1337. if (drag) {
  1338. let moveSize = type === 'height' ? e.clientY - startP : e.clientX - startP;
  1339. // 判断拖动范围不能超出
  1340. nEleChangeSize = nEleSize + moveSize;
  1341. nEleChangeSize = nEleChangeSize < limit.min ? limit.min : nEleChangeSize;
  1342. nEleChangeSize = nEleChangeSize > limit.max ? limit.max + 9 : nEleChangeSize;
  1343. fEleChangeSize = fEleSize - moveSize;
  1344. fEleChangeSize = fEleChangeSize < limit.min ? limit.min : fEleChangeSize;
  1345. fEleChangeSize = fEleChangeSize > limit.max ? limit.max + 9 : fEleChangeSize;
  1346. if(type === 'width'){
  1347. let rePercent = getResizeWidthPercent(nEleChangeSize, fEleChangeSize);
  1348. eles.nearElement.css(type, rePercent.nearPercent);
  1349. eles.farElement.css(type, rePercent.farPercent);
  1350. }
  1351. else{
  1352. eles.nearSpread[type](nEleChangeSize);
  1353. eles.nearElement[type](nEleChangeSize);
  1354. eles.farSpread[type](fEleChangeSize - navSize);
  1355. eles.farElement[type](fEleChangeSize - navSize);
  1356. }
  1357. //实时刷新页面
  1358. mouseMoveCount+=Math.abs(moveSize);//取移动的决对值
  1359. if(mouseMoveCount >=5){//当累计移动超过5个像素时,才刷新,减少刷新次数
  1360. if(callback) callback();
  1361. mouseMoveCount = 0;
  1362. }
  1363. }
  1364. });
  1365. // 鼠标弹起
  1366. $("body").mouseup(function(e) {
  1367. if (drag) {
  1368. callback();
  1369. drag = false;
  1370. // 存入本地缓存
  1371. const id = eles.id;
  1372. nEleChangeSize = nEleChangeSize >= limit.max ? limit.max + 9 : nEleChangeSize;
  1373. fEleChangeSize = fEleChangeSize >= limit.max ? limit.max + 9 : fEleChangeSize;
  1374. setLocalCache(`near${type}:${id}`, nEleChangeSize);
  1375. setLocalCache(`far${type}:${id}`, fEleChangeSize);
  1376. }
  1377. });
  1378. }
  1379. /**
  1380. * 读取设置的高度
  1381. *
  1382. * @param {String} tag - 顶层div的id
  1383. * @param {function} callback - 回调函数
  1384. * @return {void}
  1385. */
  1386. function loadSize(eles, type, callback) {
  1387. let tag = eles.id;
  1388. if (tag === '') {
  1389. return;
  1390. }
  1391. if(type !== 'height' && type !== 'width'){
  1392. return;
  1393. }
  1394. let o_nearSize = eles.nearSpread[type]();
  1395. let o_farSize = eles.farSpread[type]();
  1396. let nearSize = getLocalCache(`near${type}:${tag}`);
  1397. let farSize = getLocalCache(`far${type}:${tag}`);
  1398. if (nearSize === null || farSize === null) {
  1399. setDefaultSize(tag,eles,type);//zhang 2018-05-21
  1400. /* eles.nearSpread[type](o_nearSize);
  1401. eles.farSpread[type](o_farSize);*/
  1402. }else {
  1403. setSizeWithPercent(tag,eles,nearSize,farSize,type)//zhang 2018-06-04 改成按百分比设置
  1404. }
  1405. if(type === 'width'){//使用百分比
  1406. let rePercent = getResizeWidthPercent(nearSize ? nearSize : o_nearSize, farSize ? farSize : o_farSize);
  1407. eles.nearElement.css(type, rePercent.nearPercent);
  1408. eles.farElement.css(type, rePercent.farPercent);
  1409. }
  1410. callback();
  1411. }
  1412. //初始化个按钮点击
  1413. //@return {void}
  1414. function initBtn(){
  1415. $('#insert').click(function () {
  1416. insert([{type: itemType.job, name: ''}], false);
  1417. });
  1418. $('#delConfirm').click(function () {
  1419. del();
  1420. $('#delAlert').modal('hide');
  1421. });
  1422. $('#del').click(function () {
  1423. $('#delAlert').modal('show');
  1424. });
  1425. $('#upLevel').click(function () {
  1426. upLevel();
  1427. });
  1428. $('#downLevel').click(function () {
  1429. downLevel();
  1430. });
  1431. $('#upMove').click(function () {
  1432. upMove();
  1433. });
  1434. $('#downMove').click(function () {
  1435. downMove();
  1436. });
  1437. $('#insertRation').click(function () {
  1438. let checkedRows = getCheckedRationRows();
  1439. let insertDatas = getInsertRations(checkedRows);
  1440. if(insertDatas.length > 0){
  1441. insert(insertDatas, false, function () {
  1442. //清空选择
  1443. clearCheckedRation(checkedRows);
  1444. });
  1445. }
  1446. else {
  1447. clearCheckedRation(checkedRows);
  1448. }
  1449. });
  1450. //搜索定额
  1451. $('#searchBtn').click(function () {
  1452. let searchStr = $('#searchText').val();
  1453. if(!searchStr || searchStr === ''){
  1454. ration.cache = ration.datas;
  1455. }
  1456. else{
  1457. let reg = new RegExp(searchStr, 'i');
  1458. ration.cache = _.filter(ration.datas, function (data) {
  1459. return reg.test(data.code) || reg.test(data.name);
  1460. });
  1461. }
  1462. $('.top-content').hide();
  1463. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  1464. $('#rationSearchResult').show();
  1465. autoFlashHeight();
  1466. ration.workBook.refresh();
  1467. let rationSheet = ration.workBook.getActiveSheet();
  1468. renderSheetFunc(rationSheet, function () {
  1469. clearCheckedRation(getCheckedRationRows());
  1470. showData(rationSheet, ration.headers, ration.cache);
  1471. })
  1472. });
  1473. //关闭搜索
  1474. $('#rationSearchResult a').click(function () {
  1475. $('.top-content').show();
  1476. $('#rationSearchResult').hide();
  1477. autoFlashHeight();
  1478. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  1479. clearCheckedRation(getCheckedRationRows());
  1480. });
  1481. section.workBook.refresh();
  1482. ration.workBook.refresh();
  1483. $('#searchText').val('');
  1484. //恢复章节树下的定额
  1485. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  1486. });
  1487. //执行搜索
  1488. $('#searchText').keyup(function (e) {
  1489. $('#searchBtn').click();
  1490. });
  1491. //编辑备注
  1492. $('.main-bottom-content').find('textarea').keyup(function () {
  1493. let node = bills.tree.selected.guidance.tree.selected;
  1494. if(node){
  1495. let comment = $(this).val();
  1496. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  1497. updateGuideItems(updateDatas, function (rstData) {
  1498. node.data.comment = comment;
  1499. });
  1500. }
  1501. });
  1502. //定额高度拖动调整
  1503. slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  1504. //autoFlashHeight();
  1505. if(section.workBook){
  1506. section.workBook.refresh();
  1507. }
  1508. if(ration.workBook){
  1509. ration.workBook.refresh();
  1510. }
  1511. });
  1512. }
  1513. //初始化视图
  1514. //@param {void} @return {void}
  1515. function initViews(){
  1516. let modules = [bills, guideItem, section, ration];
  1517. initWorkBooks(modules);
  1518. getLibWithBills(libID);
  1519. initBtn();
  1520. initContextMenu();
  1521. loadSize(rationLibResizeEles, 'height', function () {
  1522. if(section.workBook){
  1523. section.workBook.refresh();
  1524. }
  1525. if(ration.workBook){
  1526. ration.workBook.refresh();
  1527. }
  1528. });
  1529. }
  1530. return {initViews};
  1531. })();
  1532. $(document).ready(function () {
  1533. billsGuidance.initViews();
  1534. CommonAjax.post('/billsGuidance/api/testItems', {libID: getQueryString('libID')}, function (rstData) {
  1535. console.log(rstData);
  1536. });
  1537. });