billsGuidance.js 79 KB

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