billsGuidance.js 79 KB

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