billsGuidance.js 76 KB

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