billsGuidance.js 73 KB

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