billsGuidance.js 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  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: 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. "insertSibling": {
  1186. name: '插入行',
  1187. disabled: function () {
  1188. let node = bills.tree.selected.guidance.tree.items[target.row];
  1189. return !node || node.data.type !== itemType.job;
  1190. },
  1191. icon: "fa-arrow-left",
  1192. callback: function (key, opt) {
  1193. insert([{type: itemType.job, name: ''}], false);
  1194. }
  1195. },
  1196. "insertChild": {
  1197. name: '插入子项',
  1198. disabled: function () {
  1199. let node = bills.tree.selected.guidance.tree.items[target.row];
  1200. return !node || node.data.type !== itemType.job || !allJobChildren(node);
  1201. },
  1202. icon: 'fa-arrow-left',
  1203. callback: function (key, opt) {
  1204. insert([{type: itemType.job, name: ''}], true);
  1205. }
  1206. }
  1207. }
  1208. };
  1209. }
  1210. else{
  1211. return false;
  1212. }
  1213. }
  1214. });
  1215. }
  1216. //拖动相关
  1217. let mouseMoveCount = 0;
  1218. let rationLibResizeEles = {};
  1219. rationLibResizeEles.id = '#de';
  1220. rationLibResizeEles.resize = $('#deResize');
  1221. rationLibResizeEles.nearElement = $('#de').find('.top-content');
  1222. rationLibResizeEles.nearSpread = $('#sectionSpread');
  1223. rationLibResizeEles.farElement = $('#de').find('.bottom-content');
  1224. rationLibResizeEles.farSpread = $('#rationSpread');
  1225. rationLibResizeEles.nav = null;
  1226. function setDefaultSize(tag,eles,type) {
  1227. let o_nearSize = 5;
  1228. let o_farSize = 2;
  1229. if(type == 'height'){
  1230. let headerHeight = $(".header").height();
  1231. let toolsbarHeight = $(".sidebar-tools-bar").height();
  1232. let resizeHeight = 6;
  1233. let totalHeight = $(window).height() - headerHeight - toolsbarHeight - resizeHeight;
  1234. const navSize = eles.nav ? eles.nav[type]() + 4 : 0;
  1235. totalHeight = totalHeight - navSize;
  1236. let nearSize = (o_nearSize/(o_nearSize + o_farSize))* totalHeight;
  1237. eles.nearSpread[type](nearSize);
  1238. eles.nearElement[type](nearSize);
  1239. eles.farSpread[type](totalHeight - nearSize);
  1240. eles.farElement[type](totalHeight - nearSize);
  1241. }
  1242. }
  1243. function setSizeWithPercent(tag,eles,nearSize,farSize,type) {
  1244. nearSize = parseFloat(nearSize);
  1245. farSize = parseFloat(farSize);
  1246. if(type !== 'width') {
  1247. let headerHeight = $(".header").height();
  1248. let toolsbarHeight = $(".sidebar-tools-bar").height();
  1249. let resizeHeight = 6;
  1250. let totalHeight = $(window).height() - headerHeight - toolsbarHeight - resizeHeight;
  1251. const navSize = eles.nav ? eles.nav[type]() + 4 : 0;
  1252. totalHeight = totalHeight - navSize;
  1253. nearSize = (nearSize/(nearSize + farSize))* totalHeight;
  1254. eles.nearSpread[type](nearSize);
  1255. eles.nearElement[type](nearSize);
  1256. eles.farSpread[type](totalHeight - nearSize);
  1257. eles.farElement[type](totalHeight - nearSize);
  1258. }
  1259. }
  1260. /**
  1261. * 读取设置的高度
  1262. *
  1263. * @param {String} tag - 顶层div的id
  1264. * @param {function} callback - 回调函数
  1265. * @return {void}
  1266. */
  1267. function loadSize(eles, type, callback) {
  1268. let tag = eles.id;
  1269. if (tag === '') {
  1270. return;
  1271. }
  1272. if(type !== 'height' && type !== 'width'){
  1273. return;
  1274. }
  1275. let o_nearSize = eles.nearSpread[type]();
  1276. let o_farSize = eles.farSpread[type]();
  1277. let nearSize = getLocalCache(`near${type}:${tag}`);
  1278. let farSize = getLocalCache(`far${type}:${tag}`);
  1279. if (nearSize === null || farSize === null) {
  1280. setDefaultSize(tag,eles,type);
  1281. }else {
  1282. setSizeWithPercent(tag,eles,nearSize,farSize,type)//zhang 2018-06-04 改成按百分比设置
  1283. }
  1284. callback();
  1285. }
  1286. /**
  1287. * 拖动更改div大小
  1288. *
  1289. * @param {Object} eles - id:存储本地的标记 resize:拖动条 nearElement:左上外层div nearSpread:左上spread farElement:右下外层div evFixedSize:造价书左右拖动用
  1290. * @param {Object} limit - min/max
  1291. * @param {String} type - height/width
  1292. * @param {function} callback - 成功后执行
  1293. * @return {void}
  1294. */
  1295. function slideResize(eles, limit, type, callback) {
  1296. if(type !== 'height' && type !== 'width'){
  1297. return;
  1298. }
  1299. //nearElement:左上, farElement:右下
  1300. let startP = 0;
  1301. let drag = false;
  1302. const resizeElement = eles.resize;
  1303. const nElement = eles.nearElement;
  1304. const fElement = eles.farElement;
  1305. const navContentEle = eles.nav ? eles.nav : null;
  1306. let nEleSize = 0;
  1307. let fEleSize = 0;
  1308. let navSize = 0;
  1309. let nEleChangeSize = 0;
  1310. let fEleChangeSize = 0;
  1311. // 鼠标点下时
  1312. resizeElement.mousedown(function(e) {
  1313. drag = true;
  1314. startP = type === 'height' ? e.clientY : e.clientX;
  1315. // 获取左(上)部分的宽度(高度)
  1316. nEleSize = nElement[type]();
  1317. // 获取右(下)部分的宽度(高度)
  1318. fEleSize = fElement[type]();
  1319. // nav宽(高度)部分
  1320. if(navContentEle){
  1321. navSize = navContentEle[type]() + 4;
  1322. }
  1323. resizeElement.tooltip('hide');
  1324. });
  1325. // 鼠标移动
  1326. $("body").mousemove(function(e) {
  1327. if (drag) {
  1328. let moveSize = type === 'height' ? e.clientY - startP : e.clientX - startP;
  1329. // 判断拖动范围不能超出
  1330. nEleChangeSize = nEleSize + moveSize;
  1331. nEleChangeSize = nEleChangeSize < limit.min ? limit.min : nEleChangeSize;
  1332. nEleChangeSize = nEleChangeSize > limit.max ? limit.max + 9 : nEleChangeSize;
  1333. fEleChangeSize = fEleSize - moveSize;
  1334. fEleChangeSize = fEleChangeSize < limit.min ? limit.min : fEleChangeSize;
  1335. fEleChangeSize = fEleChangeSize > limit.max ? limit.max + 9 : fEleChangeSize;
  1336. if(type === 'width'){
  1337. let rePercent = getResizeWidthPercent(nEleChangeSize, fEleChangeSize);
  1338. eles.nearElement.css(type, rePercent.nearPercent);
  1339. eles.farElement.css(type, rePercent.farPercent);
  1340. }
  1341. else{
  1342. eles.nearSpread[type](nEleChangeSize);
  1343. eles.nearElement[type](nEleChangeSize);
  1344. eles.farSpread[type](fEleChangeSize - navSize);
  1345. eles.farElement[type](fEleChangeSize - navSize);
  1346. }
  1347. //实时刷新页面
  1348. mouseMoveCount+=Math.abs(moveSize);//取移动的决对值
  1349. if(mouseMoveCount >=5){//当累计移动超过5个像素时,才刷新,减少刷新次数
  1350. if(callback) callback();
  1351. mouseMoveCount = 0;
  1352. }
  1353. }
  1354. });
  1355. // 鼠标弹起
  1356. $("body").mouseup(function(e) {
  1357. if (drag) {
  1358. callback();
  1359. drag = false;
  1360. // 存入本地缓存
  1361. const id = eles.id;
  1362. nEleChangeSize = nEleChangeSize >= limit.max ? limit.max + 9 : nEleChangeSize;
  1363. fEleChangeSize = fEleChangeSize >= limit.max ? limit.max + 9 : fEleChangeSize;
  1364. setLocalCache(`near${type}:${id}`, nEleChangeSize);
  1365. setLocalCache(`far${type}:${id}`, fEleChangeSize);
  1366. }
  1367. });
  1368. }
  1369. /**
  1370. * 读取设置的高度
  1371. *
  1372. * @param {String} tag - 顶层div的id
  1373. * @param {function} callback - 回调函数
  1374. * @return {void}
  1375. */
  1376. function loadSize(eles, type, callback) {
  1377. let tag = eles.id;
  1378. if (tag === '') {
  1379. return;
  1380. }
  1381. if(type !== 'height' && type !== 'width'){
  1382. return;
  1383. }
  1384. let o_nearSize = eles.nearSpread[type]();
  1385. let o_farSize = eles.farSpread[type]();
  1386. let nearSize = getLocalCache(`near${type}:${tag}`);
  1387. let farSize = getLocalCache(`far${type}:${tag}`);
  1388. if (nearSize === null || farSize === null) {
  1389. setDefaultSize(tag,eles,type);//zhang 2018-05-21
  1390. /* eles.nearSpread[type](o_nearSize);
  1391. eles.farSpread[type](o_farSize);*/
  1392. }else {
  1393. setSizeWithPercent(tag,eles,nearSize,farSize,type)//zhang 2018-06-04 改成按百分比设置
  1394. }
  1395. if(type === 'width'){//使用百分比
  1396. let rePercent = getResizeWidthPercent(nearSize ? nearSize : o_nearSize, farSize ? farSize : o_farSize);
  1397. eles.nearElement.css(type, rePercent.nearPercent);
  1398. eles.farElement.css(type, rePercent.farPercent);
  1399. }
  1400. callback();
  1401. }
  1402. //初始化个按钮点击
  1403. //@return {void}
  1404. function initBtn(){
  1405. $('#insert').click(function () {
  1406. insert([{type: itemType.job, name: ''}], false);
  1407. });
  1408. $('#delConfirm').click(function () {
  1409. del();
  1410. $('#delAlert').modal('hide');
  1411. });
  1412. $('#del').click(function () {
  1413. $('#delAlert').modal('show');
  1414. });
  1415. $('#upLevel').click(function () {
  1416. upLevel();
  1417. });
  1418. $('#downLevel').click(function () {
  1419. downLevel();
  1420. });
  1421. $('#upMove').click(function () {
  1422. upMove();
  1423. });
  1424. $('#downMove').click(function () {
  1425. downMove();
  1426. });
  1427. $('#insertRation').click(function () {
  1428. let checkedRows = getCheckedRationRows();
  1429. let insertDatas = getInsertRations(checkedRows);
  1430. if(insertDatas.length > 0){
  1431. insert(insertDatas, false, function () {
  1432. //清空选择
  1433. clearCheckedRation(checkedRows);
  1434. });
  1435. }
  1436. else {
  1437. clearCheckedRation(checkedRows);
  1438. }
  1439. });
  1440. //搜索定额
  1441. $('#searchBtn').click(function () {
  1442. let searchStr = $('#searchText').val();
  1443. if(!searchStr || searchStr === ''){
  1444. ration.cache = ration.datas;
  1445. }
  1446. else{
  1447. let reg = new RegExp(searchStr, 'i');
  1448. ration.cache = _.filter(ration.datas, function (data) {
  1449. return reg.test(data.code) || reg.test(data.name);
  1450. });
  1451. }
  1452. $('.top-content').hide();
  1453. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  1454. $('#rationSearchResult').show();
  1455. autoFlashHeight();
  1456. ration.workBook.refresh();
  1457. let rationSheet = ration.workBook.getActiveSheet();
  1458. renderSheetFunc(rationSheet, function () {
  1459. clearCheckedRation(getCheckedRationRows());
  1460. showData(rationSheet, ration.headers, ration.cache);
  1461. })
  1462. });
  1463. //关闭搜索
  1464. $('#rationSearchResult a').click(function () {
  1465. $('.top-content').show();
  1466. $('#rationSearchResult').hide();
  1467. autoFlashHeight();
  1468. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  1469. clearCheckedRation(getCheckedRationRows());
  1470. });
  1471. section.workBook.refresh();
  1472. ration.workBook.refresh();
  1473. $('#searchText').val('');
  1474. //恢复章节树下的定额
  1475. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  1476. });
  1477. //执行搜索
  1478. $('#searchText').keyup(function (e) {
  1479. $('#searchBtn').click();
  1480. });
  1481. //编辑备注
  1482. $('.main-bottom-content').find('textarea').keyup(function () {
  1483. let node = bills.tree.selected.guidance.tree.selected;
  1484. if(node){
  1485. let comment = $(this).val();
  1486. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  1487. updateGuideItems(updateDatas, function (rstData) {
  1488. node.data.comment = comment;
  1489. });
  1490. }
  1491. });
  1492. //定额高度拖动调整
  1493. slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  1494. //autoFlashHeight();
  1495. if(section.workBook){
  1496. section.workBook.refresh();
  1497. }
  1498. if(ration.workBook){
  1499. ration.workBook.refresh();
  1500. }
  1501. });
  1502. }
  1503. //初始化视图
  1504. //@param {void} @return {void}
  1505. function initViews(){
  1506. let modules = [bills, guideItem, section, ration];
  1507. initWorkBooks(modules);
  1508. getLibWithBills(libID);
  1509. initBtn();
  1510. initContextMenu();
  1511. loadSize(rationLibResizeEles, 'height', function () {
  1512. if(section.workBook){
  1513. section.workBook.refresh();
  1514. }
  1515. if(ration.workBook){
  1516. ration.workBook.refresh();
  1517. }
  1518. });
  1519. }
  1520. return {initViews};
  1521. })();
  1522. $(document).ready(function () {
  1523. billsGuidance.initViews();
  1524. CommonAjax.post('/billsGuidance/api/testItems', {libID: getQueryString('libID')}, function (rstData) {
  1525. console.log(rstData);
  1526. });
  1527. });