billsGuidance.js 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642
  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. let curCompilationID = '';
  46. const locked = lockUtil.getLocked();
  47. let moduleName = 'stdBillsGuidance';
  48. //上下拖动的拖动条高度
  49. const verticalResize = 10;
  50. //自执行函数全局变量定义
  51. const libID = getQueryString('libID');
  52. //总工作内容数据
  53. let stdBillsJobData = [];
  54. //总项目特征数据
  55. let stdBillsFeatureData = [];
  56. const bills = {
  57. dom: $('#billsSpread'),
  58. workBook: null,
  59. cache: [],
  60. tree: null,
  61. controller: null,
  62. treeSetting: {
  63. treeCol: 0,
  64. emptyRows: 0,
  65. headRows: 1,
  66. headRowHeight: [40],
  67. defaultRowHeight: 21,
  68. cols: [{
  69. width: 200,
  70. readOnly: true,
  71. showHint: true,
  72. head: {
  73. titleNames: ["项目编码"],
  74. spanCols: [1],
  75. spanRows: [1],
  76. vAlign: [1],
  77. hAlign: [1],
  78. font: ["Arial"]
  79. },
  80. data: {
  81. field: "code",
  82. vAlign: 1,
  83. hAlign: 0,
  84. font: "Arial"
  85. }
  86. }, {
  87. width: 200,
  88. readOnly: true,
  89. head: {
  90. titleNames: ["项目名称"],
  91. spanCols: [1],
  92. spanRows: [1],
  93. vAlign: [1],
  94. hAlign: [1],
  95. font: ["Arial"]
  96. },
  97. data: {
  98. field: "name",
  99. vAlign: 1,
  100. hAlign: 0,
  101. font: "Arial"
  102. }
  103. }]
  104. },
  105. headers: [
  106. {name: '项目编码', dataCode: 'code', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'},
  107. {name: '项目名称', dataCode: 'name', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'}
  108. ],
  109. events: {
  110. SelectionChanged: function (sender, info) {
  111. billsInitSel(info.newSelections[0].row, info.oldSelections[0]);
  112. }
  113. }
  114. };
  115. const selectedBgColor = '#DFE8F9';
  116. const searchBgColor = 'lemonChiffon';
  117. //项目指引类型
  118. const itemType = {
  119. job: 0,
  120. ration: 1
  121. };
  122. //项目指引复制整块localStorage key
  123. const itemCopyBlockKey = 'guideItemCopyBlock';
  124. const updateType = {
  125. create: 'create',
  126. update: 'update',
  127. del: 'delete'
  128. };
  129. //项目指引节点状态:展开全部、收起定额
  130. const itemExpandState = {
  131. expand: 1,
  132. contract: 0
  133. };
  134. //项目指引当前节点展开收缩状态,默认展开全部
  135. let curExpandState = 1;
  136. const guideItem = {
  137. dom: $('#guideItemSpread'),
  138. workBook: null,
  139. tree: null,
  140. controller: null,
  141. treeSetting: {
  142. treeCol: 0,
  143. emptyRows: 0,
  144. headRows: 1,
  145. headRowHeight: [40],
  146. defaultRowHeight: 21,
  147. cols: [{
  148. width: 400,
  149. readOnly: locked,
  150. head: {
  151. titleNames: ["项目指引"],
  152. spanCols: [1],
  153. spanRows: [1],
  154. vAlign: [1],
  155. hAlign: [1],
  156. font: ["Arial"]
  157. },
  158. data: {
  159. field: "name",
  160. vAlign: 1,
  161. hAlign: 0,
  162. font: "Arial",
  163. formatter: "@"
  164. }
  165. },
  166. {
  167. width: 40,
  168. readOnly: true,
  169. head: {
  170. titleNames: ["输出特征"],
  171. spanCols: [1],
  172. spanRows: [1],
  173. vAlign: [1],
  174. hAlign: [1],
  175. font: ["Arial"]
  176. },
  177. data: {
  178. field: "outputItemCharacter",
  179. vAlign: 1,
  180. hAlign: 1,
  181. font: "Arial"
  182. }
  183. },
  184. {
  185. width: 30,
  186. readOnly: true,
  187. head: {
  188. titleNames: ["必填"],
  189. spanCols: [1],
  190. spanRows: [1],
  191. vAlign: [1],
  192. hAlign: [1],
  193. font: ["Arial"]
  194. },
  195. data: {
  196. field: "required",
  197. vAlign: 1,
  198. hAlign: 1,
  199. font: "Arial"
  200. }
  201. },
  202. {
  203. width: 30,
  204. readOnly: true,
  205. head: {
  206. titleNames: ["材料"],
  207. spanCols: [1],
  208. spanRows: [1],
  209. vAlign: [1],
  210. hAlign: [1],
  211. font: ["Arial"]
  212. },
  213. data: {
  214. field: "isMaterial",
  215. vAlign: 1,
  216. hAlign: 1,
  217. font: "Arial"
  218. }
  219. },
  220. {
  221. width: 30,
  222. readOnly: true,
  223. head: {
  224. titleNames: ["默认"],
  225. spanCols: [1],
  226. spanRows: [1],
  227. vAlign: [1],
  228. hAlign: [1],
  229. font: ["Arial"]
  230. },
  231. data: {
  232. field: "isDefaultOption",
  233. vAlign: 1,
  234. hAlign: 1,
  235. font: "Arial"
  236. }
  237. },
  238. {
  239. width: 40,
  240. readOnly: locked,
  241. head: {
  242. titleNames: ["单位"],
  243. spanCols: [1],
  244. spanRows: [1],
  245. vAlign: [1],
  246. hAlign: [1],
  247. font: ["Arial"]
  248. },
  249. data: {
  250. field: "unit",
  251. vAlign: 1,
  252. hAlign: 1,
  253. font: "Arial",
  254. formatter: "@"
  255. }
  256. },
  257. {
  258. width: 80,
  259. readOnly: locked,
  260. head: {
  261. titleNames: ["区间"],
  262. spanCols: [1],
  263. spanRows: [1],
  264. vAlign: [1],
  265. hAlign: [1],
  266. font: ["Arial"]
  267. },
  268. data: {
  269. field: "interval",
  270. vAlign: 1,
  271. hAlign: 1,
  272. font: "Arial",
  273. formatter: "@"
  274. }
  275. },
  276. ]
  277. },
  278. headers: [
  279. {name: '项目指引', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  280. {name: '输出特征', dataCode: 'outputItemCharacter', width: 40, vAlign: 'center', hAlign: 'center'},
  281. {name: '必填', dataCode: 'required', width: 30, vAlign: 'center', hAlign: 'center'},
  282. {name: '材料', dataCode: 'isMaterial', width: 30, vAlign: 'center', hAlign: 'center'},
  283. {name: '默认', dataCode: 'isDefaultOption', width: 30, vAlign: 'center', hAlign: 'center'},
  284. {name: '单位', dataCode: 'unit', width: 40, vAlign: 'center', hAlign: 'center', formatter: '@'},
  285. {name: '区间', dataCode: 'interval', width: 80, vAlign: 'center', hAlign: 'center', formatter: '@'},
  286. ],
  287. events: {
  288. SelectionChanged: function (sender, info) {
  289. guideItemInitSel(info.newSelections[0].row)
  290. },
  291. EditEnded: function (sender, args) {
  292. edit(args.sheet, [{row: args.row, col: args.col}]);
  293. },
  294. ButtonClicked: function (sender, args) {
  295. edit(args.sheet, [{row: args.row, col: args.col}]);
  296. },
  297. RangeChanged: function (sender, args) {
  298. edit(args.sheet, args.changedCells);
  299. },
  300. CellDoubleClick: function(sender, args) {
  301. locateAtRation(args.row);
  302. },
  303. EnterCell: function(sender, args) {
  304. console.log(args.row);
  305. }
  306. }
  307. };
  308. //定额章节树
  309. const section = {
  310. dom: $('#sectionSpread'),
  311. workBook: null,
  312. cache: [],
  313. tree: null,
  314. controller: null,
  315. treeSetting: {
  316. treeCol: 0,
  317. emptyRows: 0,
  318. headRows: 1,
  319. headRowHeight: [40],
  320. defaultRowHeight: 21,
  321. cols: [{
  322. width: 400,
  323. readOnly: true,
  324. head: {
  325. titleNames: ["名称"],
  326. spanCols: [1],
  327. spanRows: [1],
  328. vAlign: [1],
  329. hAlign: [1],
  330. font: ["Arial"]
  331. },
  332. data: {
  333. field: "name",
  334. vAlign: 1,
  335. hAlign: 0,
  336. font: "Arial"
  337. }
  338. }]
  339. },
  340. headers: [
  341. {name: '名称', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  342. ],
  343. events: {
  344. SelectionChanged: function (sender, info) {
  345. sectionInitSel(info.newSelections[0].row)
  346. }
  347. }
  348. };
  349. const ration = {
  350. dom: $('#rationSpread'),
  351. workBook: null,
  352. datas: [],//所有的数据,搜索定额时,从所有数据中筛选
  353. cache: [],//显示在表格上的数据,添加定额可以有效根据行识别定额
  354. headers: [
  355. {name: '选择', dataCode: 'select', width: 50, vAlign: 'center', hAlign: 'center'},
  356. {name: '编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
  357. {name: '名称', dataCode: 'name', width: 250, vAlign: 'center', hAlign: 'left', formatter: '@'},
  358. {name: '单位', dataCode: 'unit', width: 100, vAlign: 'center', hAlign: 'left', formatter: '@'}
  359. ],
  360. events: {
  361. ButtonClicked: function (sender, args) {
  362. if(args.sheet.isEditing()){
  363. args.sheet.endEdit(true);
  364. }
  365. },
  366. CellDoubleClick: function (sender, args) {
  367. if(ration.headers[args.col].dataCode === 'name'){
  368. let insertDatas = getInsertRations([args.row]);
  369. if(insertDatas.length > 0){
  370. insert(insertDatas, false);
  371. }
  372. }
  373. }
  374. }
  375. };
  376. const options = {
  377. workBook: {
  378. tabStripVisible: false,
  379. allowContextMenu: false,
  380. allowCopyPasteExcelStyle : false,
  381. allowExtendPasteRange: false,
  382. allowUserDragDrop : false,
  383. allowUserDragFill: false,
  384. scrollbarMaxAlign : true
  385. },
  386. sheet: {
  387. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  388. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  389. }
  390. };
  391. /* 清单材料表 */
  392. const billMaterial = {
  393. dom: $('#bill-material-spread'),
  394. workBook: null,
  395. cache: [],
  396. headers: [
  397. {name: '材料编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
  398. {name: '材料名称', dataCode: 'name', width: 150, vAlign: 'center', hAlign: 'left', formatter: '@'},
  399. {name: '规格', dataCode: 'specs', width: 150, vAlign: 'center', hAlign: 'left', formatter: '@'}
  400. ],
  401. events: {
  402. EditEnded: function (sender, args) {
  403. editMaterials(args.sheet, [{row: args.row, col: args.col}]);
  404. },
  405. RangeChanged: function (sender, args) {
  406. editMaterials(args.sheet, args.changedCells);
  407. },
  408. }
  409. }
  410. // 显示清单材料数据
  411. function showBillMaterialData(sheet, headers, datas, emptyRow = 0){
  412. let fuc = function () {
  413. const rowCount = datas.length + emptyRow;
  414. sheet.setRowCount(rowCount);
  415. for(let col = 0, cLen = headers.length; col < cLen; col++){
  416. for(let row = 0; row < rowCount; row++){
  417. if (datas[row]) {
  418. sheet.setValue(row, col, datas[row][headers[col]['dataCode']] || '');
  419. } else {
  420. sheet.setValue(row, col, '');
  421. }
  422. }
  423. }
  424. };
  425. renderSheetFunc(sheet, fuc);
  426. }
  427. // 获取清单材料数据
  428. async function getBillMaterials() {
  429. if (!bills.tree.selected) {
  430. return;
  431. }
  432. billMaterial.cache = [];
  433. try {
  434. $.bootstrapLoading.start();
  435. billMaterial.cache = await ajaxPost('/billsGuidance/api/getBillMaterials', { libID, billID: bills.tree.selected.data.ID });
  436. sortByCode(billMaterial.cache);
  437. } catch (error) {
  438. $('#alert-info').text(error.message);
  439. $('#alert').modal('show');
  440. } finally {
  441. showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
  442. billMaterial.workBook.getSheet(0).showRow(0, GC.Spread.Sheets.VerticalPosition.top);
  443. $.bootstrapLoading.end();
  444. }
  445. }
  446. function getText(sheet, row, col) {
  447. let text = sheet.getValue(row, col);
  448. text = text ? text.toString().trim() : '';
  449. return text;
  450. }
  451. // 编辑材料表
  452. async function editMaterials(sheet, cells){
  453. let isChanged = false;
  454. for(let cell of cells){
  455. const itemCode = billMaterial.cache[cell.row] && billMaterial.cache[cell.row].code || '';
  456. if (itemCode !== getText(sheet, cell.row, 0)) {
  457. isChanged = true;
  458. }
  459. }
  460. if (!isChanged) {
  461. return;
  462. }
  463. let gljCodes = new Set();
  464. const count = sheet.getRowCount();
  465. for (let row = 0; row < count; row++) {
  466. const code = getText(sheet, row, 0);
  467. if (code) {
  468. gljCodes.add(code);
  469. }
  470. }
  471. // 提交数据
  472. try {
  473. $.bootstrapLoading.start();
  474. billMaterial.cache = await ajaxPost('/billsGuidance/api/editBillMaterials', { libID, billID: bills.tree.selected.data.ID, gljCodes: [...gljCodes], compilationID: curCompilationID }, undefined, true);
  475. sortByCode(billMaterial.cache);
  476. } catch (error) {
  477. $('#alert-info').html(error);
  478. $('#alert').modal('show');
  479. } finally {
  480. showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
  481. $.bootstrapLoading.end();
  482. }
  483. }
  484. // 是否为工序行
  485. function isProcessNode(node) {
  486. return node && node.depth() % 2 === 0 && _isDef(node.data.type) && node.data.type === itemType.job
  487. }
  488. // 是否是选项行
  489. function isOptionNode(node) {
  490. return node && node.depth() % 2 === 1 && _isDef(node.data.type) && node.data.type === itemType.job
  491. }
  492. //渲染时方法,停止渲染
  493. //@param {Object}sheet {Function}func @return {void}
  494. function renderSheetFunc(sheet, func){
  495. sheet.suspendEvent();
  496. sheet.suspendPaint();
  497. if(func){
  498. func();
  499. }
  500. sheet.resumeEvent();
  501. sheet.resumePaint();
  502. }
  503. //设置表选项
  504. //@param {Object}workBook {Object}opts @return {void}
  505. function setOptions (workBook, opts) {
  506. for(let opt in opts.workBook){
  507. workBook.options[opt] = opts.workBook[opt];
  508. }
  509. for(let opt in opts.sheet){
  510. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  511. }
  512. }
  513. //建表头
  514. //@param {Object}sheet {Array}headers @return {void}
  515. function buildHeader(sheet, headers) {
  516. let fuc = function () {
  517. sheet.setColumnCount(headers.length);
  518. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  519. for(let i = 0, len = headers.length; i < len; i++){
  520. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  521. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  522. sheet.getCell(0, i, GC.Spread.Sheets.SheetArea.colHeader).wordWrap(true);
  523. if(headers[i].formatter){
  524. sheet.setFormatter(-1, i, headers[i].formatter);
  525. }
  526. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  527. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  528. }
  529. };
  530. renderSheetFunc(sheet, fuc);
  531. }
  532. //表监听事件
  533. //@param {Object}workBook @return {void}
  534. function bindEvent(workBook, events) {
  535. if(Object.keys(events).length === 0){
  536. return;
  537. }
  538. const Events = GC.Spread.Sheets.Events;
  539. for(let event in events){
  540. workBook.bind(Events[event], events[event]);
  541. }
  542. }
  543. //建表
  544. //@param {Object}module @return {void}
  545. function buildSheet(module) {
  546. if(!module.workBook){
  547. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  548. let sheet = module.workBook.getActiveSheet();
  549. if(module === bills){
  550. sheet.name('stdBillsGuidance_bills');
  551. //默认初始可控制焦点在清单表中
  552. module.workBook.focus();
  553. sheet.options.isProtected = true;
  554. }
  555. else if(module === ration){
  556. sheet.options.isProtected = true;
  557. sheet.getRange(-1, 0, -1, 1).locked(locked);
  558. sheet.getRange(-1, 1, -1, -1).locked(true);
  559. }
  560. else if(module === guideItem){
  561. sheet.name('stdBillsGuidance_guidance');
  562. sheetCommonObj.bindEscKey(module.workBook, [{sheet: sheet, editStarting: null, editEnded: module.events.EditEnded}]);
  563. }
  564. else if (module === billMaterial) {
  565. sheet.options.isProtected = true;
  566. sheet.getRange(-1, 0, -1, 1).locked(locked);
  567. sheet.getRange(-1, 1, -1, -1).locked(true);
  568. sheet.getRange(-1, 2, -1, -1).locked(true);
  569. }
  570. setOptions(module.workBook, options);
  571. buildHeader(module.workBook.getActiveSheet(), module.headers);
  572. bindEvent(module.workBook, module.events);
  573. }
  574. lockUtil.lockSpreads([module.workBook], locked);
  575. if (locked) {
  576. // 锁定表格后双击事件失效了,但是需要双击定位,因此重新绑定双击
  577. if (module === guideItem) {
  578. module.workBook.bind('CellDoubleClick', module.events.CellDoubleClick);
  579. }
  580. }
  581. }
  582. //清空表数据
  583. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  584. function cleanData(sheet, headers, rowCount){
  585. renderSheetFunc(sheet, function () {
  586. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  587. if (rowCount >= 0) {
  588. sheet.setRowCount(rowCount);
  589. }
  590. });
  591. }
  592. //根据清单获取项目指引
  593. //@param {String}guidanceLibID {Number}billsID {Function}callback @return {void}
  594. function getItemsByBills(guidanceLibID, billsID, callback){
  595. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: guidanceLibID, billsID: billsID}, function (rstData) {
  596. if(callback){
  597. callback(rstData);
  598. }
  599. });
  600. }
  601. //清单表焦点控制
  602. //@param {Number}row @return {void}
  603. function billsInitSel(row, oldSel){
  604. let guideSheet = guideItem.workBook.getActiveSheet();
  605. cleanData(guideSheet, guideItem.headers, -1);
  606. let node = bills.tree.items[row];
  607. if(!node){
  608. return;
  609. }
  610. const billSheet = bills.workBook.getActiveSheet();
  611. setBgColor(billSheet, row, selectedBgColor);
  612. if (oldSel && row !== oldSel.row) {
  613. const orgNode = bills.tree.items[oldSel.row]
  614. setBgColor(billSheet, oldSel.row, orgNode && orgNode.isSearch ? searchBgColor : 'white');
  615. }
  616. bills.tree.selected = node;
  617. //显示备注
  618. $('.main-side-bottom').find('textarea').val(node.data.comment ? node.data.comment : '');
  619. if(!node.guidance.tree){
  620. getItemsByBills(libID, node.data.ID, function (rstData) {
  621. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  622. setNodesExpandState(node.guidance.tree.items, curExpandState);
  623. setProcessNodes(guideSheet, node.guidance.tree.items);
  624. renderSheetFunc(guideSheet, function () {
  625. TREE_SHEET_HELPER.refreshNodesVisible(node.guidance.tree.roots, guideSheet, true);
  626. });
  627. //设置底色
  628. setNodesColor(guideSheet, node.guidance.tree.items);
  629. //项目指引初始焦点
  630. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  631. });
  632. } else{
  633. setNodesExpandState(node.guidance.tree.items, curExpandState);
  634. node.guidance.controller.showTreeData();
  635. setProcessNodes(guideSheet, node.guidance.tree.items);
  636. //设置底色
  637. setNodesColor(guideSheet, node.guidance.tree.items);
  638. //项目指引初始焦点
  639. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  640. }
  641. }
  642. function showCheckBox(sheet, nodes) {
  643. // const checkBoxType = locked ? sheetCommonObj.getReadOnlyCheckBox() : sheetCommonObj.getCheckBox();
  644. const checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  645. const baseType = new GC.Spread.Sheets.CellTypes.Base();
  646. const outputItemCol = guideItem.headers.findIndex(item => item.dataCode === 'outputItemCharacter');
  647. const requiredCol = guideItem.headers.findIndex(item => item.dataCode === 'required');
  648. const materialCol = guideItem.headers.findIndex(item => item.dataCode === 'isMaterial');
  649. const defaultOption = guideItem.headers.findIndex(item => item.dataCode === 'isDefaultOption');
  650. renderSheetFunc(sheet, function () {
  651. nodes.forEach(node => {
  652. const row = node.serialNo();
  653. if (isOptionNode(node)) {
  654. sheet.setCellType(row, defaultOption, checkBoxType);
  655. sheet.setValue(row, defaultOption, node.data.isDefaultOption || false);
  656. } else {
  657. sheet.setCellType(row, defaultOption, baseType);
  658. sheet.setValue(row, defaultOption, '');
  659. }
  660. if (isProcessNode(node)) {
  661. sheet.setCellType(row, outputItemCol, checkBoxType);
  662. sheet.setCellType(row, requiredCol, checkBoxType);
  663. sheet.setCellType(row, materialCol, checkBoxType);
  664. sheet.setValue(row, outputItemCol, node.data.outputItemCharacter || false);
  665. sheet.setValue(row, requiredCol, node.data.required || false);
  666. sheet.setValue(row, materialCol, node.data.isMaterial || false);
  667. } else {
  668. sheet.setCellType(row, outputItemCol, baseType);
  669. sheet.setCellType(row, requiredCol, baseType);
  670. sheet.setCellType(row, materialCol, baseType);
  671. sheet.setValue(row, outputItemCol, '');
  672. sheet.setValue(row, requiredCol, '');
  673. sheet.setValue(row, materialCol, '');
  674. }
  675. })
  676. });
  677. }
  678. function setReadOnly(sheet, nodes) {
  679. if (locked) {
  680. return;
  681. }
  682. // 单位仅特征/工序行可输入
  683. // 区间仅仅选项行可输入
  684. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  685. const intervalCol = guideItem.headers.findIndex(item => item.dataCode === 'interval');
  686. renderSheetFunc(sheet, function () {
  687. nodes.forEach(node => {
  688. const row = node.serialNo();
  689. sheet.getCell(row, unitCol).locked(!isProcessNode(node));
  690. sheet.getCell(row, intervalCol).locked(!isOptionNode(node));
  691. });
  692. });
  693. }
  694. // 设置选项行相关
  695. function setProcessNodes(sheet, nodes) {
  696. showCheckBox(sheet, nodes);
  697. setReadOnly(sheet, nodes);
  698. }
  699. //设置项目节点展开收起状态:展开全部、收起定额
  700. //@param {Array}nodes(当前清单下的所有项目指引节点) {Number}expandState(展开全部1或收起定额0).
  701. function setNodesExpandState(nodes, expandState) {
  702. if(expandState === itemExpandState.contract) {
  703. //找出所有定额的父节点
  704. let rations = _.filter(nodes, function (node) {
  705. return node.data.type === itemType.ration;
  706. });
  707. let rationParentIDs = [];
  708. for(let ration of rations){
  709. if(ration.data.ParentID != -1){
  710. rationParentIDs.push(ration.data.ParentID);
  711. }
  712. }
  713. rationParentIDs = Array.from(new Set(rationParentIDs));
  714. let rationParentNodes = _.filter(nodes, function (node) {
  715. return rationParentIDs.includes(node.data.ID);
  716. });
  717. //收起定额
  718. for(let node of rationParentNodes){
  719. node.setExpanded(false);
  720. }
  721. } else {
  722. for(let node of nodes){
  723. node.setExpanded(true);
  724. }
  725. }
  726. }
  727. // 设置行底色
  728. function setBgColor(sheet, row, color) {
  729. const style = new GC.Spread.Sheets.Style();
  730. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  731. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  732. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  733. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  734. style.backColor = color;
  735. sheet.setStyle(row, -1, style);
  736. }
  737. //根据奇偶层级设置节点底色,奇数层为蓝色(树节点深度为偶数)
  738. //@param {Object}sheet {Array}nodes @return {void}
  739. function setNodesColor(sheet, nodes) {
  740. renderSheetFunc(sheet, function () {
  741. for(let node of nodes){
  742. const color = isProcessNode(node) ? selectedBgColor : 'White';
  743. setBgColor(sheet, node.serialNo(), color);
  744. }
  745. });
  746. }
  747. //选中的节点是否全是同层节点
  748. //@param {Object}sheet {Array}items @return {Boolean}
  749. function itemsSameDepth(sheet, items) {
  750. let sels = sheet.getSelections();
  751. if(sels.length === 0 || items.length === 0){
  752. return false;
  753. }
  754. let depths = [];
  755. for(let i = 0; i < sels[0].rowCount; i++){
  756. let row = sels[0].row + i;
  757. let node = items[row];
  758. if(node){
  759. depths.push(node.depth());
  760. }
  761. }
  762. }
  763. //节点子项是否全是工作内容
  764. //@param {Object}node @return {Boolean}
  765. function allJobChildren(node){
  766. for(let c of node.children){
  767. if(c.data.type === itemType.ration){
  768. return false;
  769. }
  770. }
  771. return true;
  772. }
  773. //节点子项是否全是定额
  774. //@param {Object}node @return {Boolean}
  775. function allRationChildren(node){
  776. for(let c of node.children){
  777. if(c.data.type === itemType.job){
  778. return false;
  779. }
  780. }
  781. return true;
  782. }
  783. //刷新按钮有效性
  784. //@param {Object}node @return {void}
  785. function refreshBtn(node){
  786. if (locked) {
  787. return;
  788. }
  789. //全部设为无效
  790. $('.tools-btn').children().addClass('disabled');
  791. $('#generate-class').removeClass('disabled');
  792. $('#insertRation').addClass('disabled');
  793. $('#insertAll').addClass('disabled');
  794. $('.main-bottom-content').find('textarea').attr('readonly', true);
  795. //插入
  796. if(bills.tree.selected && bills.tree.selected.guidance.tree){
  797. $('#insert').removeClass('disabled');
  798. if(node && node.data.type === itemType.ration){
  799. $('#insert').addClass('disabled');
  800. }
  801. }
  802. //删除
  803. if(node){
  804. $('#del').removeClass('disabled');
  805. }
  806. if(node && node.data.type === itemType.job){
  807. //升级
  808. if(node.parent){
  809. $('#upLevel').removeClass('disabled');
  810. if(node.nextSibling && node.children.length > 0 && !allJobChildren(node)){
  811. $('#upLevel').addClass('disabled');
  812. }
  813. }
  814. //降级
  815. if(node.preSibling){
  816. $('#downLevel').removeClass('disabled');
  817. if(node.preSibling.children.length > 0 && !allJobChildren(node.preSibling)){
  818. $('#downLevel').addClass('disabled');
  819. }
  820. }
  821. }
  822. //上移
  823. if(node && node.preSibling){
  824. $('#upMove').removeClass('disabled')
  825. }
  826. //下移
  827. if(node && node.nextSibling){
  828. $('#downMove').removeClass('disabled');
  829. }
  830. //收起定额、展开全部
  831. $('#expandContract').removeClass('disabled');
  832. //插入定额
  833. if(node && (node.children.length === 0 || allRationChildren(node))){
  834. $('#insertRation').removeClass('disabled');
  835. $('#insertAll').removeClass('disabled');
  836. }
  837. //备注,奇数节点可用
  838. if(isProcessNode(node)){
  839. $('.main-bottom-content').find('textarea').attr('readonly', false);
  840. }
  841. }
  842. //项目指引表焦点控制
  843. //@param {Number}row @return {void}
  844. function guideItemInitSel(row){
  845. let billsNode = bills.tree.selected;
  846. let node = null;
  847. if(billsNode && billsNode.guidance.tree){
  848. node = billsNode.guidance.tree.items[row];
  849. if(node){
  850. billsNode.guidance.tree.selected = node;
  851. //显示备注
  852. $('.main-bottom-content').find('textarea').val(node.data.comment ? node.data.comment : '');
  853. }
  854. }
  855. refreshBtn(node);
  856. }
  857. //初始化当前库名
  858. //@param {String} @return {void}
  859. function initLibName(libName) {
  860. $('#libName')[0].outerHTML = $('#libName')[0].outerHTML.replace("XXX清单指引", libName);
  861. }
  862. //初始化各工作表
  863. //@param {Array}modules @return {void}
  864. function initWorkBooks(modules){
  865. for(let module of modules){
  866. buildSheet(module);
  867. }
  868. }
  869. function tipDivCheck(){
  870. setTimeout(function () {
  871. let tips = $('#autoTip');
  872. if(ration.tipDiv == 'show'){
  873. return;
  874. } else if(ration.tipDiv == 'hide'&&tips){
  875. tips.hide();
  876. ration._toolTipElement = null;
  877. }
  878. },600)
  879. }
  880. //获取悬浮提示单元格
  881. //@param {Object}sheet @return {Object}
  882. function getTipCellType(sheet) {
  883. let setting = {};
  884. let TipCellType = function () {};
  885. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  886. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  887. return {
  888. x: x,
  889. y: y,
  890. row: context.row,
  891. col: context.col,
  892. cellStyle: cellStyle,
  893. cellRect: cellRect,
  894. sheet: context.sheet,
  895. sheetArea: context.sheetArea
  896. };
  897. };
  898. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  899. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  900. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  901. if(tag !== undefined && tag){
  902. text = tag;
  903. }
  904. if(sheet && sheet.getParent().qo){
  905. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  906. }
  907. let delayTimes = 500; //延时时间
  908. let now_timeStamp = +new Date();
  909. this.tipTimeStamp = now_timeStamp;
  910. let me = this;
  911. setTimeout(function () {
  912. if(now_timeStamp - me.tipTimeStamp == 0){//鼠标停下的时候才显示
  913. if (setting.pos && text && text !== '') {
  914. //固定不显示的div,存储文本获取固定div宽度,toolTipElement由于显示和隐藏,获取宽度不正确
  915. if(!me._fixedTipElement){
  916. let div = $('#fixedTip1')[0];
  917. if (!div) {
  918. div = document.createElement("div");
  919. $(div).css("padding", 5)
  920. .attr("id", 'fixedTip');
  921. $(div).hide();
  922. document.body.insertBefore(div, null);
  923. }
  924. me._fixedTipElement = div;
  925. }
  926. $(me._fixedTipElement).width('');
  927. $(me._fixedTipElement).html(text);
  928. if (!me._toolTipElement) {
  929. let div = $('#autoTip1')[0];
  930. if (!div) {
  931. div = document.createElement("div");
  932. $(div).css("position", "absolute")
  933. .css("border", "1px #C0C0C0 solid")
  934. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  935. .css("font", "0.9rem Calibri")
  936. .css("padding", 5)
  937. .css("background", '#303133')
  938. .css("color", '#fff')
  939. .attr("id", 'autoTip1');
  940. $(div).hide();
  941. document.body.insertBefore(div, null);
  942. }
  943. me._toolTipElement = div;
  944. $(me._toolTipElement).width('');
  945. //实时读取位置信息
  946. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  947. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  948. }
  949. $(me._toolTipElement).html(text);
  950. //定额库定额特殊处理
  951. if($(hitinfo.sheet.getParent().qo).attr('id') === 'rationSpread'){
  952. let divWidth = $(me._fixedTipElement).width(),
  953. divHeight = $(me._fixedTipElement).height();
  954. if(divWidth > 600){
  955. divWidth = 590;
  956. $(me._toolTipElement).width(divWidth);
  957. }
  958. let top = setting.pos.y + hitinfo.y - divHeight < 0 ? 0 : setting.pos.y + hitinfo.cellRect.y - divHeight;
  959. $(me._toolTipElement).css("top", top).css("left", setting.pos.x - divWidth);
  960. }
  961. else{
  962. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  963. }
  964. //名称
  965. if(hitinfo.col === 2){
  966. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  967. zoom = hitinfo.sheet.zoom();
  968. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  969. let textLength = me.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  970. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  971. if(textLength > cellWidth){
  972. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  973. $(me._toolTipElement).show("fast");
  974. ration.tipDiv = 'show';//做个标记
  975. }
  976. }
  977. else {
  978. $(me._toolTipElement).show("fast");
  979. ration.tipDiv = 'show';//做个标记
  980. }
  981. }
  982. }
  983. }
  984. },delayTimes);
  985. };
  986. TipCellType.prototype.processMouseLeave = function (hininfo) {
  987. this.tipTimeStamp = +new Date();
  988. ration.tipDiv = 'hide';
  989. if (this._toolTipElement) {
  990. $(this._toolTipElement).hide();
  991. this._toolTipElement = null;
  992. }
  993. tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  994. }
  995. return new TipCellType();
  996. }
  997. //输出表数据(定额表)
  998. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  999. function showData(sheet, headers, datas){
  1000. let fuc = function () {
  1001. sheet.setRowCount(datas.length);
  1002. //复选框
  1003. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  1004. let tipCellType = getTipCellType(sheet);
  1005. sheet.setCellType(-1, 0, checkBoxType);
  1006. for(let col = 0, cLen = headers.length; col < cLen; col++){
  1007. for(let row = 0, rLen = datas.length; row < rLen; row++){
  1008. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  1009. if(col === 1){
  1010. sheet.setTag(row, col, datas[row]['hint']);
  1011. }
  1012. }
  1013. }
  1014. sheet.setCellType(-1, 1, tipCellType);
  1015. sheet.setCellType(-1, 2, tipCellType);
  1016. };
  1017. renderSheetFunc(sheet, fuc);
  1018. }
  1019. //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
  1020. //@param {Number}sectionId {Array}rations @return {Array}
  1021. function getRationsBySectionId(sectionId, rations) {
  1022. if(!sectionId || !rations){
  1023. return [];
  1024. }
  1025. return _.filter(rations, {sectionId});
  1026. }
  1027. //定额章节树焦点控制
  1028. //@param {Number}row @return {void}
  1029. function sectionInitSel(row) {
  1030. let rationSheet = ration.workBook.getActiveSheet();
  1031. let sectionNode = section.tree ? section.tree.items[row] : null;
  1032. if(sectionNode && sectionNode.children.length === 0){
  1033. let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
  1034. ration.cache = sectionRations;
  1035. showData(rationSheet, ration.headers, sectionRations);
  1036. }
  1037. else {
  1038. cleanData(rationSheet, ration.headers, 0);
  1039. }
  1040. }
  1041. //初始化定额条目
  1042. //@param {Number}rationLibId @return {void}
  1043. function initRationItems(rationLibId, successCb){
  1044. $.bootstrapLoading.start();
  1045. //获取定额章节树
  1046. let sectionSheet = section.workBook.getActiveSheet();
  1047. CommonAjax.post('/rationRepository/api/getRationTree', {rationLibId: rationLibId}, function (sectionDatas) {
  1048. //获取所有定额数据
  1049. let reqEntity = {rationLibId: rationLibId, showHint: true, returnFields: '-_id code ID sectionId name unit basePrice rationGljList jobContent annotation'};
  1050. CommonAjax.post('/rationRepository/api/getRationItemsByLib', reqEntity, function (rstData) {
  1051. section.cache = sectionDatas;
  1052. initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
  1053. //初始焦点在第一行(切换库)
  1054. sectionSheet.setActiveCell(0, 0);
  1055. sortByCode(rstData);
  1056. /* rstData.sort(function (a, b) {
  1057. let rst = 0;
  1058. if(a.code > b.code){
  1059. rst = 1;
  1060. }
  1061. else if(a.code < b.code){
  1062. rst = -1;
  1063. }
  1064. return rst;
  1065. }); */
  1066. ration.datas = rstData;
  1067. sectionInitSel(0);
  1068. $.bootstrapLoading.end();
  1069. if (successCb) {
  1070. successCb();
  1071. }
  1072. }, function () {
  1073. $.bootstrapLoading.end();
  1074. });
  1075. }, function () {
  1076. $.bootstrapLoading.end();
  1077. });
  1078. }
  1079. // 可用的定额库ID
  1080. const rationLibIDs = [];
  1081. //初始化定额库选择
  1082. //@param {String}compilationId @return {void}
  1083. function initRationLibs(compilationId){
  1084. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
  1085. $('#rationLibSel').empty();
  1086. for(let rationLib of rstData){
  1087. rationLibIDs.push(+rationLib.ID);
  1088. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  1089. $('#rationLibSel').append(opt);
  1090. }
  1091. //初始选择
  1092. initRationItems(parseInt($('#rationLibSel').select().val()));
  1093. $('#rationLibSel').change(function () {
  1094. let rationLibId = parseInt($(this).select().val());
  1095. initRationItems(rationLibId);
  1096. })
  1097. });
  1098. }
  1099. // 变更定额库
  1100. function changeRationLib(libID, successCb) {
  1101. $('#rationLibSel').val(libID);
  1102. initRationItems(libID, successCb);
  1103. }
  1104. // 设置清单名称文本色
  1105. function setBillsForeColor(billsNodes) {
  1106. const sheet = bills.workBook.getActiveSheet();
  1107. renderSheetFunc(sheet, function () {
  1108. for(let bills of billsNodes){
  1109. const row = bills.serialNo();
  1110. sheet.setStyle(row, 1, { foreColor: bills.data.hasGuide ? 'darkgreen' : 'black' });
  1111. }
  1112. });
  1113. }
  1114. //清单设置悬浮提示信息
  1115. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  1116. function setBillsHint(billsNodes, jobs, items) {
  1117. let jobsMapping = {},
  1118. itemsMapping = {};
  1119. for(let job of jobs){
  1120. jobsMapping[job.id] = job;
  1121. }
  1122. for(let item of items){
  1123. itemsMapping[item.id] = item;
  1124. }
  1125. let tagInfo = [];
  1126. for(let billsNode of billsNodes){
  1127. let hintArr = [];
  1128. let billsItems = billsNode.data.items;
  1129. if(billsItems.length > 0){
  1130. //项目特征
  1131. hintArr.push('项目特征:');
  1132. }
  1133. let itemCount = 1,
  1134. jobCount = 1;
  1135. for(let billsItem of billsItems){
  1136. let itemData = itemsMapping[billsItem.id];
  1137. if(itemData){
  1138. //特征值
  1139. let eigens = [];
  1140. for(let eigen of itemData.itemValue){
  1141. eigens.push(eigen.value);
  1142. }
  1143. eigens = eigens.join(';');
  1144. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  1145. itemCount ++;
  1146. }
  1147. }
  1148. //工作内容
  1149. let billsJobs = billsNode.data.jobs;
  1150. if(billsJobs.length > 0){
  1151. hintArr.push('工作内容:');
  1152. }
  1153. for(let billsJob of billsJobs){
  1154. let jobData = jobsMapping[billsJob.id];
  1155. if(jobData){
  1156. hintArr.push(`${jobCount}.${jobData.content}`);
  1157. jobCount ++;
  1158. }
  1159. }
  1160. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  1161. hintArr.push('工程量计算规则:');
  1162. hintArr.push(billsNode.data.ruleText);
  1163. }
  1164. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  1165. hintArr.push('补注:');
  1166. hintArr.push(billsNode.data.recharge);
  1167. }*/
  1168. if(hintArr.length > 0){
  1169. tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
  1170. }
  1171. }
  1172. let sheet = bills.workBook.getActiveSheet();
  1173. renderSheetFunc(sheet, function () {
  1174. for(let tagI of tagInfo){
  1175. sheet.setTag(tagI.row, 0, tagI.value);
  1176. }
  1177. });
  1178. }
  1179. //初始化清单的工作内容和项目特征
  1180. //@param {Number}billsLibId {Function}callback @return {void}
  1181. function initJobAndCharacter(billsLibId, callback){
  1182. CommonAjax.post('/stdBillsEditor/getJobContent', {billsLibId: billsLibId}, function (datas) {
  1183. stdBillsJobData = datas;
  1184. CommonAjax.post('/stdBillsEditor/getItemCharacter', {billsLibId: billsLibId}, function (datas) {
  1185. stdBillsFeatureData = datas;
  1186. if(callback){
  1187. callback();
  1188. }
  1189. });
  1190. });
  1191. }
  1192. let billsLibId = 0;
  1193. //获取指引库信息及关联的清单
  1194. //@param {Number}libID {Function}callback @return {Object}
  1195. function getLibWithBills(libID, callback){
  1196. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  1197. billsLibId = rstData.guidanceLib.billsLibId;
  1198. initRationLibs(rstData.guidanceLib.compilationId);
  1199. curCompilationID = rstData.guidanceLib.compilationId;
  1200. bills.cache = rstData.bills;
  1201. initLibName(rstData.guidanceLib.name);
  1202. /*initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  1203. //每一棵项目指引树挂在清单节点上
  1204. for(let node of bills.tree.items){
  1205. node.guidance = {tree: null, controller: null};
  1206. }
  1207. //默认初始节点
  1208. billsInitSel(0);
  1209. if(callback){
  1210. callback(rstData);
  1211. }*/
  1212. let initDataCallback = function () {
  1213. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  1214. //每一棵项目指引树挂在清单节点上
  1215. for(let node of bills.tree.items){
  1216. node.guidance = {tree: null, controller: null};
  1217. }
  1218. //默认初始节点
  1219. billsInitSel(0);
  1220. if(callback){
  1221. callback(rstData);
  1222. }
  1223. };
  1224. initJobAndCharacter(rstData.guidanceLib.billsLibId, initDataCallback);
  1225. }, function (msg) {
  1226. window.location.href = '/billsGuidance/main';
  1227. });
  1228. }
  1229. //初始化并输出树
  1230. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  1231. function initTree(module, sheet, treeSetting, datas){
  1232. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  1233. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  1234. module.tree.loadDatas(datas);
  1235. if(module === bills){
  1236. module.tree.roots.forEach(root => {
  1237. root.setExpanded(false);
  1238. })
  1239. }
  1240. module.controller.showTreeData();
  1241. if(module === bills){
  1242. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  1243. setBillsForeColor(bills.tree.items);
  1244. }
  1245. }
  1246. //更新清单备注
  1247. function updateBillsComment(updateData, callback, errCB) {
  1248. CommonAjax.post('/stdBillsEditor/updateBills', updateData, function () {
  1249. if (callback) {
  1250. callback();
  1251. }
  1252. }, function () {
  1253. if(errCB) {
  1254. errCB();
  1255. }
  1256. });
  1257. }
  1258. //更新项目指引
  1259. //@param {Array}updateDatas {Function}callback @return {void}
  1260. function updateGuideItems(updateDatas, callback, errCB){
  1261. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  1262. if(callback){
  1263. callback(rstData);
  1264. }
  1265. }, function () {
  1266. if(errCB) {
  1267. errCB();
  1268. }
  1269. $.bootstrapLoading.end();
  1270. });
  1271. }
  1272. //编辑后自动去除换行符回车符
  1273. const deESC = /[\n]/g;
  1274. //项目指引编辑
  1275. //@param {Object}sheet {Array}cells
  1276. function edit(sheet, cells){
  1277. let updateDatas = [];
  1278. //同步节点数据
  1279. let syncDatas = [];
  1280. for(let cell of cells){
  1281. const field = guideItem.headers[cell.col].dataCode;
  1282. let node = bills.tree.selected.guidance.tree.items[cell.row];
  1283. if (field === 'name' || field === 'unit' || field === 'interval') {
  1284. let text = sheet.getValue(cell.row, cell.col);
  1285. text = text ? text.toString() : '';
  1286. text = text.replace(deESC, '');
  1287. sheet.setValue(cell.row, cell.col, text);
  1288. if(node.data[field] != text){
  1289. syncDatas.push({node: node, text: text, field, cell});
  1290. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {[field]: text}});
  1291. }
  1292. } else if (field === 'outputItemCharacter' || field === 'required' || field === 'isMaterial' || field === 'isDefaultOption') {
  1293. const val = !sheet.getValue(cell.row, cell.col);
  1294. sheet.setValue(cell.row, cell.col, val);
  1295. syncDatas.push({node: node, text: val, field, cell });
  1296. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {[field]: val}});
  1297. }
  1298. }
  1299. if(updateDatas.length > 0){
  1300. updateGuideItems(updateDatas, function () {
  1301. for(let syncData of syncDatas){
  1302. syncData.node.data[syncData.field] = syncData.text;
  1303. }
  1304. }, function () {
  1305. //失败恢复
  1306. renderSheetFunc(sheet, function () {
  1307. for(let syncData of syncDatas){
  1308. sheet.setValue(syncData.node.serialNo(), syncData.cell.col, syncData.node.data[syncData.field] ? syncData.node.data[syncData.field] : '');
  1309. }
  1310. });
  1311. });
  1312. }
  1313. }
  1314. //项目指引插入,支持一次插入多条数据
  1315. //@param {Array}datas {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  1316. function insert(datas, tobeChild, callback = null){
  1317. $.bootstrapLoading.start();
  1318. let sheet = guideItem.workBook.getActiveSheet();
  1319. let controller = bills.tree.selected.guidance.controller;
  1320. let selected = bills.tree.selected.guidance.tree.selected;
  1321. let updateDatas = [];
  1322. //建立数组下标索引
  1323. let newDataIndex = {};
  1324. for(let i = 0; i < datas.length; i++){
  1325. let newNodeData = {
  1326. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  1327. billsID: bills.tree.selected.getID(),
  1328. outputItemCharacter: true,
  1329. };
  1330. //定额类型插入当前工作内容焦点行,
  1331. if(selected && ((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1332. newNodeData.ParentID = selected.getID();
  1333. newNodeData.NextSiblingID = -1;
  1334. }
  1335. Object.assign(newNodeData, datas[i]);
  1336. newDataIndex[i] = newNodeData;
  1337. }
  1338. for(let i = 0; i < datas.length; i++){
  1339. //第一个节点
  1340. if(i === 0){
  1341. //非插入成子节点,更新选中节点NestSiblingID
  1342. if(selected && !((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1343. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  1344. }
  1345. }
  1346. //非最后一个节点
  1347. if(i !== datas.length - 1){
  1348. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  1349. }
  1350. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  1351. }
  1352. updateGuideItems(updateDatas, function () {
  1353. const outputItemCol = guideItem.headers.findIndex(item => item.dataCode === 'outputItemCharacter');
  1354. for(let updateData of updateDatas){
  1355. if(updateData.updateType === updateType.create){
  1356. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  1357. //同步data
  1358. Object.assign(newNode.data, updateData.updateData);
  1359. const row = newNode.serialNo();
  1360. sheet.setValue(row, 0, newNode.data.name);
  1361. if (newNode.data.outputItemCharacter !== undefined) {
  1362. sheet.setValue(row, outputItemCol, newNode.data.outputItemCharacter);
  1363. }
  1364. setProcessNodes(sheet, [newNode]);
  1365. refreshBtn(newNode);
  1366. }
  1367. }
  1368. if (!bills.tree.selected.data.hasGuide && bills.tree.selected.guidance.tree.items.length) {
  1369. bills.tree.selected.data.hasGuide = true;
  1370. setBillsForeColor([bills.tree.selected]);
  1371. }
  1372. if(callback){
  1373. callback();
  1374. }
  1375. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1376. guideItem.workBook.focus(true);
  1377. $.bootstrapLoading.end();
  1378. });
  1379. }
  1380. // 删除定额(嵌套删除自身及后代定额)
  1381. function delRations() {
  1382. const selected = bills.tree.selected.guidance.tree.selected;
  1383. if (!selected) {
  1384. return;
  1385. }
  1386. if (selected.data.type === itemType.ration) {
  1387. del({ row: selected.serialNo(), col: 0, rowCount: 1, colCount: 1 });
  1388. return;
  1389. }
  1390. const rations = selected.getPosterity().filter(item => item.data.type === itemType.ration);
  1391. if (!rations.length) {
  1392. return;
  1393. }
  1394. const updateDatas = rations.map(item => ({ updateType: updateType.del, findData: { ID: item.data.ID } }));
  1395. const rationIDs = rations.map(r => r.data.ID);
  1396. $.bootstrapLoading.start();
  1397. updateGuideItems(updateDatas, function () {
  1398. const guideSheet = guideItem.workBook.getSheet(0);
  1399. const treeNodes = bills.tree.selected.guidance.tree.items.filter(item => !rationIDs.includes(item.data.ID));
  1400. const state = bills.tree.selected.guidance.tree.getExpState(treeNodes);
  1401. const treeData = treeNodes.map(item => item.data);
  1402. initTree(bills.tree.selected.guidance, guideSheet, guideItem.treeSetting, treeData);
  1403. bills.tree.selected.guidance.tree.setExpandedByState(bills.tree.selected.guidance.tree.items, state);
  1404. renderSheetFunc(guideSheet, function () {
  1405. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.selected.guidance.tree.roots, guideSheet, true);
  1406. });
  1407. //设置底色
  1408. setNodesColor(guideSheet, bills.tree.selected.guidance.tree.items);
  1409. //项目指引初始焦点
  1410. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  1411. $.bootstrapLoading.end();
  1412. guideItem.workBook.focus(true)
  1413. });
  1414. }
  1415. //项目指引删除操作
  1416. //@return {void}
  1417. function del(selArea = null){
  1418. $.bootstrapLoading.start();
  1419. let controller = bills.tree.selected.guidance.controller;
  1420. let selNodes = [];
  1421. let sheet = guideItem.workBook.getSheet(0);
  1422. let sel = selArea ? selArea : sheet.getSelections()[0];
  1423. if(sel){
  1424. sel.row = sel.row === -1 ? 0 : sel.row;
  1425. for(let i = 0; i < sel.rowCount; i++){
  1426. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1427. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1428. }
  1429. }
  1430. }
  1431. //选中的块节点
  1432. let blockNodes = getBlockNodes(selNodes);
  1433. let updateDatas = [];
  1434. function getDelDatas(nodes){
  1435. for (let node of nodes) {
  1436. updateDatas.push({updateType: updateType.del, findData: {ID: node.getID()}});
  1437. if (node.children.length > 0) {
  1438. getDelDatas(node.children);
  1439. }
  1440. }
  1441. }
  1442. getDelDatas(blockNodes);
  1443. //更新相关的前节点
  1444. for (let node of blockNodes) {
  1445. if (node.preSibling && !blockNodes.includes(node.preSibling)) {
  1446. let next = node;
  1447. while (next.nextSibling && blockNodes.includes(next.nextSibling)) {
  1448. next = next.nextSibling;
  1449. }
  1450. updateDatas.push({updateType: updateType.update, findData: {ID: node.preSibling.getID()}, updateData: {NextSiblingID: next.getNextSiblingID()}});
  1451. }
  1452. }
  1453. updateGuideItems(updateDatas, function () {
  1454. console.log(blockNodes);
  1455. controller.m_delete(blockNodes);
  1456. guideItemInitSel(sheet.getActiveRowIndex());
  1457. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1458. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1459. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1460. if (bills.tree.selected.data.hasGuide && !bills.tree.selected.guidance.tree.items.length) {
  1461. bills.tree.selected.data.hasGuide = false;
  1462. setBillsForeColor([bills.tree.selected]);
  1463. }
  1464. $.bootstrapLoading.end();
  1465. guideItem.workBook.focus(true)
  1466. });
  1467. }
  1468. //项目指引升级
  1469. //@return {void}
  1470. function upLevel(){
  1471. $.bootstrapLoading.start();
  1472. let controller = bills.tree.selected.guidance.controller;
  1473. let selected = bills.tree.selected.guidance.tree.selected;
  1474. let updateDatas = [];
  1475. //更新父节点
  1476. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  1477. //更新选中节点
  1478. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()},
  1479. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID(), unit: '', interval: ''}});
  1480. if(selected.nextSibling && selected.children.length > 0){
  1481. //更新选中节点最末子节点
  1482. let lastChild = selected.children[selected.children.length - 1];
  1483. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: -1}});
  1484. }
  1485. //选中节点的所有后兄弟节点成为选中节点的子项
  1486. let selectedNextIDs = [];
  1487. let sNext = selected.nextSibling;
  1488. while(sNext){
  1489. selectedNextIDs.push(sNext.getID());
  1490. sNext = sNext.nextSibling;
  1491. }
  1492. for(let sID of selectedNextIDs){
  1493. updateDatas.push({updateType: updateType.update, findData: {ID: sID}, updateData: {ParentID: selected.getID()}});
  1494. }
  1495. updateGuideItems(updateDatas, function () {
  1496. controller.upLevel();
  1497. const sheet = guideItem.workBook.getActiveSheet();
  1498. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1499. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1500. setProcessNodes(sheet, bills.tree.selected.guidance.tree.items);
  1501. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  1502. const intervalCol = guideItem.headers.findIndex(item => item.dataCode === 'interval');
  1503. sheet.setValue(selected.serialNo(), unitCol, '');
  1504. sheet.setValue(selected.serialNo(), intervalCol, '');
  1505. $.bootstrapLoading.end();
  1506. guideItem.workBook.focus(true)//31574
  1507. });
  1508. }
  1509. //项目指引降级
  1510. //@return {void}
  1511. function downLevel(){
  1512. $.bootstrapLoading.start();
  1513. let controller = bills.tree.selected.guidance.controller;
  1514. let selected = bills.tree.selected.guidance.tree.selected;
  1515. let updateDatas = [];
  1516. //更新前兄弟节点
  1517. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1518. //更新前兄弟节点最末子节点
  1519. if(selected.preSibling.children.length > 0){
  1520. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  1521. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1522. }
  1523. //更新选中节点
  1524. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1, unit: '', interval: ''}});
  1525. updateGuideItems(updateDatas, function () {
  1526. controller.downLevel();
  1527. const sheet = guideItem.workBook.getActiveSheet();
  1528. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1529. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1530. setProcessNodes(sheet, bills.tree.selected.guidance.tree.items);
  1531. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  1532. const intervalCol = guideItem.headers.findIndex(item => item.dataCode === 'interval');
  1533. sheet.setValue(selected.serialNo(), unitCol, '');
  1534. sheet.setValue(selected.serialNo(), intervalCol, '');
  1535. $.bootstrapLoading.end();
  1536. guideItem.workBook.focus(true)
  1537. });
  1538. }
  1539. //项目指引上移
  1540. //@return {void}
  1541. function upMove(){
  1542. $.bootstrapLoading.start();
  1543. let controller = bills.tree.selected.guidance.controller;
  1544. let selected = bills.tree.selected.guidance.tree.selected;
  1545. let updateDatas = [];
  1546. //更新前节点
  1547. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1548. //更新前前节点
  1549. if(selected.preSibling.preSibling){
  1550. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1551. }
  1552. //更新选中节点
  1553. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  1554. updateGuideItems(updateDatas, function () {
  1555. controller.upMove();
  1556. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1557. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1558. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1559. $.bootstrapLoading.end();
  1560. guideItem.workBook.focus(true)
  1561. });
  1562. }
  1563. //项目指引下移
  1564. //@return {void}
  1565. function downMove(){
  1566. $.bootstrapLoading.start();
  1567. let controller = bills.tree.selected.guidance.controller;
  1568. let selected = bills.tree.selected.guidance.tree.selected;
  1569. let updateDatas = [];
  1570. //更新下节点
  1571. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  1572. //更新前节点
  1573. if(selected.preSibling){
  1574. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1575. }
  1576. //更新选中节点
  1577. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  1578. updateGuideItems(updateDatas, function () {
  1579. controller.downMove();
  1580. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1581. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1582. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1583. $.bootstrapLoading.end();
  1584. guideItem.workBook.focus(true)
  1585. });
  1586. }
  1587. //获取定额类型的项目指引名称,通过定额转换
  1588. //@param {Object}ration @return {String}
  1589. function getRationItemName(ration){
  1590. let arr = [];
  1591. arr.push(ration.code ? ration.code : '');
  1592. arr.push(ration.name ? ration.name : '');
  1593. arr.push(ration.basePrice ? ration.basePrice : '');
  1594. let rst = arr.join(' ');
  1595. rst += `/${ration.unit ? ration.unit : ''}`;
  1596. return rst;
  1597. }
  1598. //获取选中的定额表行
  1599. //@return {Array}
  1600. function getCheckedRationRows(all){
  1601. let rst = [];
  1602. let sheet = ration.workBook.getActiveSheet();
  1603. for(let i = 0; i < sheet.getRowCount(); i++){
  1604. // 全选
  1605. if (all) {
  1606. rst.push(i);
  1607. continue;
  1608. }
  1609. let checked = sheet.getValue(i, 0);
  1610. if(checked){
  1611. rst.push(i);
  1612. }
  1613. }
  1614. return rst;
  1615. }
  1616. //清空选中定额表行
  1617. //@param {Array}rows @return {void}
  1618. function clearCheckedRation(rows) {
  1619. let sheet = ration.workBook.getActiveSheet();
  1620. renderSheetFunc(sheet, function () {
  1621. for(let row of rows){
  1622. sheet.setValue(row, 0, 0);
  1623. }
  1624. });
  1625. }
  1626. //获取要插入的定额数据
  1627. //@param {Array}rows @return {Array}
  1628. function getInsertRations(rows){
  1629. let rst = [];
  1630. //当前已存在定额
  1631. let curRationIems = [];
  1632. let selected = bills.tree.selected.guidance.tree.selected;
  1633. if(selected){
  1634. if(selected.data.type === itemType.job){
  1635. curRationIems = selected.children;
  1636. }
  1637. else {
  1638. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  1639. }
  1640. }
  1641. for(let row of rows){
  1642. let selRation = ration.cache[row];
  1643. if(selRation){
  1644. //添加的定额是否已存在,不重复添加
  1645. let isExist = false;
  1646. for(let curRation of curRationIems){
  1647. if(curRation.data.rationID == selRation.ID){
  1648. isExist = true;
  1649. break;
  1650. }
  1651. }
  1652. if(!isExist){
  1653. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  1654. }
  1655. }
  1656. }
  1657. return rst;
  1658. }
  1659. //获取块节点父项不存在于选中节点中的节点
  1660. //@param {Array}nodes(选中的节点) @return {Array}
  1661. function getBlockNodes(nodes) {
  1662. let nodeMapping = {};
  1663. for(let node of nodes){
  1664. nodeMapping[node.data.ID] = node;
  1665. }
  1666. //块节点,父项不存在于选中节点中的节点
  1667. let blockNodes = [];
  1668. for(let node of nodes){
  1669. if(!nodeMapping[node.data.ParentID]){
  1670. blockNodes.push(node);
  1671. }
  1672. }
  1673. return blockNodes;
  1674. }
  1675. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1676. //@param {Array}nodes(块节点) @return {Boolean}
  1677. function canCopyBlock(nodes) {
  1678. if(!nodes || nodes.length === 0){
  1679. return false;
  1680. }
  1681. let pID = nodes[0].data.ParentID;
  1682. for(let node of nodes){
  1683. if(node.data.ParentID !== pID){
  1684. return false;
  1685. }
  1686. }
  1687. return true;
  1688. }
  1689. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1690. //@param {Object}node(粘贴到的节点)
  1691. function canPasteBlock(node) {
  1692. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1693. if(!pasteDatas || pasteDatas.length === 0){
  1694. return false;
  1695. }
  1696. if(!node){
  1697. return false;
  1698. }
  1699. //若粘贴到定额节点,则数据须全为定额
  1700. if(node.data.type === itemType.ration){
  1701. for(let data of pasteDatas){
  1702. if(data.type !== itemType.ration){
  1703. return false;
  1704. }
  1705. }
  1706. }
  1707. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1708. else {
  1709. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1710. for(let topData of topDatas){
  1711. if(topData.type === itemType.ration){
  1712. return false;
  1713. }
  1714. }
  1715. }
  1716. return true;
  1717. }
  1718. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1719. //@param {Array}nodes(块节点) @return {void}
  1720. function copyBlocks(nodes) {
  1721. nodes = _.cloneDeep(nodes);
  1722. //将块节点的ParentID暂时设置为-1
  1723. for(let topNode of nodes){
  1724. topNode.data.ParentID = -1;
  1725. }
  1726. let copyDatas = [];
  1727. let copyNodes = [];
  1728. //获取块节点包含的所有节点(包括自己)
  1729. function containNodes(nodes) {
  1730. for(let node of nodes){
  1731. copyNodes.push(node);
  1732. if(node.children.length > 0){
  1733. containNodes(node.children);
  1734. }
  1735. }
  1736. }
  1737. containNodes(nodes);
  1738. for(let node of copyNodes){
  1739. copyDatas.push(node.data);
  1740. }
  1741. console.log(`copyDatas`);
  1742. console.log(copyDatas);
  1743. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1744. }
  1745. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1746. //@param {Object}node(粘贴到的节点) @return {void}
  1747. function pasteBlock(node) {
  1748. let itemObj = bills.tree.selected.guidance;
  1749. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1750. //整理ID
  1751. let IDMapping = {};
  1752. for(let data of pasteDatas){
  1753. data.newID = uuid.v1();
  1754. IDMapping[data.ID] = data;
  1755. }
  1756. for(let data of pasteDatas){
  1757. let nextData = IDMapping[data.NextSiblingID];
  1758. data.NextSiblingID = nextData ? nextData.newID : -1;
  1759. let parentData = IDMapping[data.ParentID];
  1760. data.ParentID = parentData ? parentData.newID : -1;
  1761. }
  1762. for(let data of pasteDatas){
  1763. data.ID = data.newID;
  1764. delete data.newID;
  1765. }
  1766. let updateDatas = [];
  1767. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1768. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1769. for(let topData of topDatas){
  1770. topData.ParentID = node.getParentID();
  1771. }
  1772. //更新数据
  1773. //更新插入的最末顶层数据NextSiblingID
  1774. if(node.nextSibling){
  1775. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1776. }
  1777. //新建节点
  1778. for(let data of pasteDatas){
  1779. data.libID = libID;
  1780. data.billsID = node.data.billsID;
  1781. delete data._id;
  1782. updateDatas.push({updateType: updateType.create, updateData: data});
  1783. }
  1784. console.log(`pasteDatas`);
  1785. console.log(pasteDatas);
  1786. //更新粘贴到的节点的NextSiblingID
  1787. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1788. $.bootstrapLoading.start();
  1789. updateGuideItems(updateDatas, function (rstData) {
  1790. $.bootstrapLoading.end();
  1791. node.data.NextSiblingID = topDatas[0].ID;
  1792. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1793. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1794. itemObj.controller.showTreeData();
  1795. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1796. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1797. }, function () {
  1798. $.bootstrapLoading.end();
  1799. });
  1800. }
  1801. // 双击定位定额
  1802. async function locateAtRation(row) {
  1803. const node = bills.tree.selected.guidance.tree.items[row];
  1804. if (!node || !node.data.rationID) {
  1805. return;
  1806. }
  1807. const rationItem = ration.datas.find(item => item.ID === node.data.rationID);
  1808. // 当前库没有找到,需要后端查找
  1809. if (!rationItem) {
  1810. const findedRation = await ajaxPost('/rationRepository/api/getRationByID',{ ID: node.data.rationID });
  1811. if (!findedRation || !rationLibIDs.includes(findedRation.rationRepId)) {
  1812. alert('无法定位此定额,此定额已被删除');
  1813. return;
  1814. }
  1815. changeRationLib(findedRation.rationRepId, () => {
  1816. located(findedRation.ID, findedRation.sectionId);
  1817. })
  1818. } else {
  1819. located(rationItem.ID, rationItem.sectionId);
  1820. }
  1821. function located(rationID, sectionID) {
  1822. if (!section.tree) {
  1823. return;
  1824. }
  1825. const sectionNode = section.tree.nodes[section.tree.prefix + sectionID];
  1826. if (!sectionNode) {
  1827. return;
  1828. }
  1829. // 定位到对应章节树
  1830. const sectionSheet = section.workBook.getActiveSheet();
  1831. const sectionRow = sectionNode.serialNo();
  1832. expandSearchNodes(sectionSheet, [sectionNode], section.tree.roots);
  1833. sectionSheet.setSelection(sectionRow, 0, 1, 1);
  1834. sectionSheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.center);
  1835. sectionInitSel(sectionRow);
  1836. // 定位到对应定额
  1837. const locatedRationRow = ration.cache.findIndex(item => item.ID === rationID);
  1838. if (locatedRationRow !== -1) {
  1839. const rationSheet = ration.workBook.getActiveSheet();
  1840. rationSheet.setSelection(locatedRationRow, 1, 1, 1);
  1841. rationSheet.showRow(locatedRationRow, GC.Spread.Sheets.VerticalPosition.center);
  1842. }
  1843. }
  1844. }
  1845. //初始化右键菜单
  1846. //@return {void}
  1847. function initContextMenu() {
  1848. $.contextMenu({
  1849. selector: '#guideItemSpread',
  1850. build: function($triggerElement, e){
  1851. //控制允许右键菜单在哪个位置出现
  1852. let sheet = guideItem.workBook.getSheet(0);
  1853. let offset = $("#guideItemSpread").offset(),
  1854. x = e.pageX - offset.left,
  1855. y = e.pageY - offset.top;
  1856. let target = sheet.hitTest(x, y);
  1857. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1858. let sel = sheet.getSelections()[0];
  1859. if(sel && sel.rowCount === 1){
  1860. sheet.setActiveCell(target.row, target.col);
  1861. }
  1862. sel = sheet.getSelections()[0];
  1863. let selNodes = [];
  1864. if(sel){
  1865. sel.row = sel.row === -1 ? 0 : sel.row;
  1866. for(let i = 0; i < sel.rowCount; i++){
  1867. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1868. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1869. }
  1870. }
  1871. }
  1872. //块节点
  1873. let blockNodes = getBlockNodes(selNodes);
  1874. //右键在多选内则不重设焦点
  1875. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1876. sheet.setActiveCell(target.row, target.col);
  1877. }
  1878. guideItemInitSel(target.row);
  1879. return {
  1880. callback: function(){},
  1881. items: {
  1882. "copy": {
  1883. name: "复制整块",
  1884. disabled: function () {
  1885. return locked || !canCopyBlock(blockNodes);
  1886. },
  1887. icon: "fa-copy",
  1888. callback: function (key, opt) {
  1889. copyBlocks(blockNodes);
  1890. }},
  1891. "paste": {
  1892. name: "粘贴整块",
  1893. disabled: function () {
  1894. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1895. return locked || !canPasteBlock(pasteNode);
  1896. },
  1897. icon: "fa-paste",
  1898. callback: function (key, opt) {
  1899. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1900. pasteBlock(pasteNode);
  1901. }},
  1902. "delRations": {
  1903. name: '删除定额',
  1904. disabled: function () {
  1905. let node = bills.tree.selected.guidance.tree.items[target.row];
  1906. return locked || !node
  1907. },
  1908. icon: "fa-remove",
  1909. callback: function (key, opt) {
  1910. $('#delRationAlert').modal('show');
  1911. }
  1912. },
  1913. "del": {
  1914. name: '删除',
  1915. disabled: function () {
  1916. let node = bills.tree.selected.guidance.tree.items[target.row];
  1917. return locked || !node
  1918. },
  1919. icon: "fa-remove",
  1920. callback: function (key, opt) {
  1921. $('#delAlert').modal('show');
  1922. }
  1923. },
  1924. "insertSibling": {
  1925. name: '插入行',
  1926. disabled: function () {
  1927. let node = bills.tree.selected.guidance.tree.items[target.row];
  1928. return locked || !node || node.data.type !== itemType.job;
  1929. },
  1930. icon: "fa-arrow-left",
  1931. callback: function (key, opt) {
  1932. insert([{type: itemType.job, name: ''}], false);
  1933. }
  1934. },
  1935. "insertChild": {
  1936. name: '插入子项',
  1937. disabled: function () {
  1938. let node = bills.tree.selected.guidance.tree.items[target.row];
  1939. return locked || !node || node.data.type !== itemType.job || !allJobChildren(node);
  1940. },
  1941. icon: 'fa-arrow-left',
  1942. callback: function (key, opt) {
  1943. insert([{type: itemType.job, name: ''}], true);
  1944. }
  1945. }
  1946. }
  1947. };
  1948. }
  1949. else{
  1950. return false;
  1951. }
  1952. }
  1953. });
  1954. }
  1955. // 替换定额
  1956. function replaceRation(newRation, orgItem) {
  1957. if (newRation.ID === orgItem.data.rationID) {
  1958. return;
  1959. }
  1960. $.bootstrapLoading.start();
  1961. const updateAttrs = {name: getRationItemName(newRation), rationID: newRation.ID};
  1962. const updateData = [{updateType: updateType.update, findData: {ID: orgItem.getID()}, updateData: updateAttrs }];
  1963. updateGuideItems(updateData, function () {
  1964. Object.assign(orgItem.data, updateAttrs);
  1965. const row = orgItem.serialNo();
  1966. guideItem.workBook.getSheet(0).setValue(row, 0, orgItem.data.name);
  1967. $.bootstrapLoading.end();
  1968. });
  1969. }
  1970. // 初始化清单右键菜单
  1971. function initRationContextMenu() {
  1972. $.contextMenu({
  1973. selector: '#rationSpread',
  1974. build: function($triggerElement, e){
  1975. //控制允许右键菜单在哪个位置出现
  1976. let sheet = ration.workBook.getActiveSheet();;
  1977. let offset = $("#rationSpread").offset(),
  1978. x = e.pageX - offset.left,
  1979. y = e.pageY - offset.top;
  1980. let target = sheet.hitTest(x, y);
  1981. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1982. let sel = sheet.getSelections()[0];
  1983. if(sel && sel.rowCount === 1){
  1984. sheet.setActiveCell(target.row, target.col);
  1985. }
  1986. sel = sheet.getSelections()[0];
  1987. if(sel){
  1988. sel.row = sel.row === -1 ? 0 : sel.row;
  1989. }
  1990. //右键在多选内则不重设焦点
  1991. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1992. sheet.setActiveCell(target.row, target.col);
  1993. }
  1994. return {
  1995. callback: function(){},
  1996. items: {
  1997. "replace": {
  1998. name: "替换定额",
  1999. disabled: function () {
  2000. return locked || !bills.tree.selected || !bills.tree.selected.guidance || !bills.tree.selected.guidance.tree || !bills.tree.selected.guidance.tree.selected || bills.tree.selected.guidance.tree.selected.data.type !== itemType.ration;
  2001. },
  2002. icon: "fa-copy",
  2003. callback: function (key, opt) {
  2004. const row = sheet.getActiveRowIndex();
  2005. if (!ration.cache[row]) {
  2006. return;
  2007. }
  2008. replaceRation(ration.cache[row], bills.tree.selected.guidance.tree.selected);
  2009. // copyBlocks(blockNodes);
  2010. }},
  2011. }
  2012. };
  2013. }
  2014. else{
  2015. return false;
  2016. }
  2017. }
  2018. });
  2019. }
  2020. // 初始化定额右键菜单
  2021. function initBillsContextMenu() {
  2022. $.contextMenu({
  2023. selector: '#billsSpread',
  2024. build: function($triggerElement, e){
  2025. //控制允许右键菜单在哪个位置出现
  2026. let sheet = bills.workBook.getActiveSheet();;
  2027. let offset = $("#billsSpread").offset(),
  2028. x = e.pageX - offset.left,
  2029. y = e.pageY - offset.top;
  2030. let target = sheet.hitTest(x, y);
  2031. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  2032. let sel = sheet.getSelections()[0];
  2033. if(sel && sel.rowCount === 1){
  2034. sheet.setActiveCell(target.row, target.col);
  2035. }
  2036. sel = sheet.getSelections()[0];
  2037. if(sel){
  2038. sel.row = sel.row === -1 ? 0 : sel.row;
  2039. }
  2040. //右键在多选内则不重设焦点
  2041. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  2042. sheet.setActiveCell(target.row, target.col);
  2043. }
  2044. billsInitSel(target.row, { row: bills.tree.selected.serialNo() });
  2045. return {
  2046. callback: function(){},
  2047. items: {
  2048. "replace": {
  2049. name: "配置材料",
  2050. disabled: function () {
  2051. return !bills.tree.selected;
  2052. },
  2053. icon: "fa-edit",
  2054. callback: function (key, opt) {
  2055. $('#bill-material-modal').modal('show');
  2056. }},
  2057. }
  2058. };
  2059. }
  2060. else{
  2061. return false;
  2062. }
  2063. }
  2064. });
  2065. }
  2066. //展开至搜索出来点的节点
  2067. //@param {Array}nodes @return {void}
  2068. function expandSearchNodes(sheet, nodes, roots){
  2069. renderSheetFunc(sheet, function () {
  2070. function expParentNode(node){
  2071. if(node.parent){
  2072. if (!node.parent.expanded) {
  2073. node.parent.setExpanded(true);
  2074. }
  2075. expParentNode(node.parent);
  2076. }
  2077. }
  2078. for(let node of nodes){
  2079. expParentNode(node);
  2080. }
  2081. TREE_SHEET_HELPER.refreshNodesVisible(roots, sheet, true);
  2082. });
  2083. }
  2084. // 清空搜索高亮
  2085. function clearHighLight(sheet) {
  2086. renderSheetFunc(sheet, () => {
  2087. for (let i = 0; i < sheet.getRowCount(); i++){
  2088. setBgColor(sheet, i, 'white')
  2089. }
  2090. });
  2091. }
  2092. // 清空搜索状态
  2093. // 关闭搜索清单结果
  2094. function closeSearchBills(sheet) {
  2095. if (!bills.tree) {
  2096. return;
  2097. }
  2098. $('#searchBillsResult').hide();
  2099. bills.tree.items.forEach(node => {
  2100. node.isSearch = false;
  2101. });
  2102. clearHighLight(sheet);
  2103. setBgColor(sheet, sheet.getActiveRowIndex(), selectedBgColor);
  2104. }
  2105. // 搜索清单
  2106. function searchBills() {
  2107. if (!bills.tree || !bills.workBook) {
  2108. return;
  2109. }
  2110. const sheet = bills.workBook.getActiveSheet();
  2111. const str = $('#searchBillText').val().trim();
  2112. // 空搜索字符,关闭搜索
  2113. if (!str) {
  2114. if ($('#searchBillsResult').is(':visible')) {
  2115. closeSearchBills(sheet);
  2116. }
  2117. return;
  2118. }
  2119. // 过滤清单
  2120. const result = bills.tree.items.filter(item => {
  2121. const codeIs = item.data.code ? item.data.code.indexOf(str) !== -1 : false;
  2122. const nameIs = item.data.name ? item.data.name.indexOf(str) !== -1 : false;
  2123. return codeIs || nameIs;
  2124. });
  2125. if (!result.length) {
  2126. closeSearchBills(sheet);
  2127. return;
  2128. }
  2129. // 显示搜索结果
  2130. $("#searchBillsResult").show();
  2131. $('#searchBillsCount').text(result.length);
  2132. //展开搜索出来的节点
  2133. expandSearchNodes(sheet, result, bills.tree.roots);
  2134. // 标黄结果
  2135. clearHighLight(sheet);
  2136. const col = sheet.getActiveColumnIndex();
  2137. renderSheetFunc(sheet, function () {
  2138. bills.controller.setTreeSelected(result[0]);
  2139. bills.tree.items.forEach(node => {
  2140. if (result.includes(node)) {
  2141. setBgColor(sheet, node.serialNo(), searchBgColor);
  2142. node.isSearch = true; // 标记为搜索结果,防止被焦点行变更恢复颜色
  2143. } else {
  2144. node.isSearch = false;
  2145. }
  2146. })
  2147. });
  2148. //搜索初始定位
  2149. const row = sheet.getActiveRowIndex();
  2150. sheet.setSelection(result[0].serialNo(), col, 1, 1);
  2151. billsInitSel(result[0].serialNo(), { row });
  2152. sheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  2153. let curIndex = 0;
  2154. // 上一条
  2155. $('#preBill').unbind('click');
  2156. $('#preBill').bind('click', () => {
  2157. const node = result[curIndex - 1];
  2158. if (!node) {
  2159. return;
  2160. }
  2161. curIndex -= 1;
  2162. const col = sheet.getActiveColumnIndex();
  2163. const row = node.serialNo();
  2164. const orgRow = sheet.getActiveRowIndex();
  2165. sheet.setSelection(row, col, 1, 1);
  2166. billsInitSel(row, { row: orgRow });
  2167. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  2168. });
  2169. // 下一条
  2170. $('#nextBills').unbind('click');
  2171. $('#nextBills').bind('click', () => {
  2172. const node = result[curIndex + 1];
  2173. if (!node) {
  2174. return;
  2175. }
  2176. curIndex += 1;
  2177. const col = sheet.getActiveColumnIndex();
  2178. const row = node.serialNo();
  2179. const orgRow = sheet.getActiveRowIndex();
  2180. sheet.setSelection(row, col, 1, 1);
  2181. billsInitSel(row, { row: orgRow });
  2182. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  2183. });
  2184. }
  2185. //初始化dom时间
  2186. //@return {void}
  2187. function initDomEvents(){
  2188. // 清单材料窗口
  2189. $("#bill-material-modal").on('hidden.bs.modal', function () {
  2190. billMaterial.cache = [];
  2191. showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
  2192. });
  2193. $("#bill-material-modal").on('shown.bs.modal', function () {
  2194. if (billMaterial.workBook) {
  2195. billMaterial.workBook.refresh();
  2196. getBillMaterials();
  2197. }
  2198. });
  2199. $('#insert').click(function () {
  2200. insert([{type: itemType.job, name: '', outputItemCharacter: true }], false);
  2201. });
  2202. $('#delConfirm').click(function () {
  2203. del();
  2204. $('#delAlert').modal('hide');
  2205. });
  2206. $('#delRationConfirm').click(function () {
  2207. delRations();
  2208. $('#delRationAlert').modal('hide');
  2209. });
  2210. $('#del').click(function () {
  2211. $('#delAlert').modal('show');
  2212. });
  2213. $('#upLevel').click(function () {
  2214. upLevel();
  2215. });
  2216. $('#downLevel').click(function () {
  2217. downLevel();
  2218. });
  2219. $('#upMove').click(function () {
  2220. upMove();
  2221. });
  2222. $('#downMove').click(function () {
  2223. downMove();
  2224. });
  2225. // 收起清单至第二层
  2226. $('#expandToSecond').click(function() {
  2227. if (!bills.tree || !bills.workBook) {
  2228. return;
  2229. }
  2230. bills.tree.roots.forEach(root => {
  2231. root.setExpanded(true);
  2232. root.children.forEach(item => {
  2233. item.setExpanded(false);
  2234. });
  2235. });
  2236. const billSheet = bills.workBook.getActiveSheet();
  2237. renderSheetFunc(billSheet, function () {
  2238. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billSheet, true);
  2239. });
  2240. })
  2241. //收起定额、展开全部
  2242. $('#expandContract').click(function () {
  2243. //目前状态时展开全部节点状态,点击则收起定额
  2244. let tree = bills.tree.selected.guidance.tree,
  2245. itemSheet = guideItem.workBook.getActiveSheet();
  2246. if(curExpandState === itemExpandState.expand){
  2247. curExpandState = itemExpandState.contract;
  2248. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  2249. setNodesExpandState(tree.items, itemExpandState.contract);
  2250. } else {
  2251. curExpandState = itemExpandState.expand;
  2252. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  2253. setNodesExpandState(tree.items, itemExpandState.expand);
  2254. }
  2255. renderSheetFunc(itemSheet, function () {
  2256. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  2257. });
  2258. });
  2259. // 插入选中定额
  2260. $('#insertRation').click(function () {
  2261. let checkedRows = getCheckedRationRows();
  2262. let insertDatas = getInsertRations(checkedRows);
  2263. if(insertDatas.length > 0){
  2264. insert(insertDatas, false, function () {
  2265. //清空选择
  2266. clearCheckedRation(checkedRows);
  2267. });
  2268. }
  2269. else {
  2270. clearCheckedRation(checkedRows);
  2271. }
  2272. });
  2273. // 插入全部定额
  2274. $('#insertAll').click(function () {
  2275. let isAll = true;
  2276. let checkedRows = getCheckedRationRows(isAll);
  2277. let insertDatas = getInsertRations(checkedRows);
  2278. if(insertDatas.length > 0){
  2279. insert(insertDatas, false);
  2280. }
  2281. });
  2282. // 搜索清单
  2283. $("#searchBillBtn").click(searchBills);
  2284. $('#searchBillText').keyup(function (e) {
  2285. delayKeyup(function () {
  2286. $('#searchBillBtn').click();
  2287. });
  2288. });
  2289. // 关闭搜索清单
  2290. $('#closeSearchBills').click(() => {
  2291. if (!bills.workBook) {
  2292. return;
  2293. }
  2294. const sheet = bills.workBook.getActiveSheet();
  2295. closeSearchBills(sheet);
  2296. })
  2297. //搜索定额
  2298. $('#searchBtn').click(function () {
  2299. let searchStr = $('#searchText').val();
  2300. if(!searchStr || searchStr === ''){
  2301. ration.cache = ration.datas;
  2302. }
  2303. else{
  2304. let reg = new RegExp(searchStr, 'i');
  2305. ration.cache = _.filter(ration.datas, function (data) {
  2306. return reg.test(data.code) || reg.test(data.name);
  2307. });
  2308. }
  2309. $('.top-content').hide();
  2310. $('#deResize').hide();
  2311. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  2312. $('#rationSearchResult').show();
  2313. autoFlashHeight();
  2314. ration.workBook.refresh();
  2315. let rationSheet = ration.workBook.getActiveSheet();
  2316. renderSheetFunc(rationSheet, function () {
  2317. clearCheckedRation(getCheckedRationRows());
  2318. showData(rationSheet, ration.headers, ration.cache);
  2319. })
  2320. });
  2321. //关闭搜索
  2322. $('#rationSearchResult a').click(function () {
  2323. $('.top-content').show();
  2324. $('#deResize').show();
  2325. $('#rationSearchResult').hide();
  2326. autoFlashHeight();
  2327. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  2328. clearCheckedRation(getCheckedRationRows());
  2329. });
  2330. section.workBook.refresh();
  2331. ration.workBook.refresh();
  2332. $('#searchText').val('');
  2333. //恢复章节树下的定额
  2334. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  2335. });
  2336. let keyupTime = 0,
  2337. delayTime = 500;
  2338. function delayKeyup(callback) {
  2339. let nowTime = Date.now();
  2340. keyupTime = nowTime;
  2341. setTimeout(function () {
  2342. if (nowTime - keyupTime == 0) {
  2343. callback();
  2344. }
  2345. }, delayTime);
  2346. }
  2347. //执行搜索
  2348. $('#searchText').keyup(function (e) {
  2349. delayKeyup(function () {
  2350. $('#searchBtn').click();
  2351. });
  2352. });
  2353. //编辑清单备注
  2354. $('.main-side-bottom').find('textarea').keyup(function () {
  2355. let me = this;
  2356. let node = bills.tree.selected;
  2357. let comment = $(me).val();
  2358. delayKeyup(function () {
  2359. if (node) {
  2360. let updateData = {lastOperator: userAccount, billsLibId: billsLibId, updateId: node.getID(), field: 'comment', data: comment};
  2361. updateBillsComment(updateData, function () {
  2362. node.data.comment = comment;
  2363. }, function() {
  2364. $(me).val(node.data.comment || '');
  2365. })
  2366. }
  2367. });
  2368. });
  2369. //编辑选项备注
  2370. $('.main-bottom-content').find('textarea').keyup(function () {
  2371. let me = this;
  2372. let node = bills.tree.selected.guidance.tree.selected;
  2373. let comment = $(me).val();
  2374. delayKeyup(function () {
  2375. if(node){
  2376. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  2377. updateGuideItems(updateDatas, function (rstData) {
  2378. node.data.comment = comment;
  2379. }, function() {
  2380. $(me).val(node.data.comment || '');
  2381. });
  2382. }
  2383. });
  2384. });
  2385. //定额高度拖动调整
  2386. let heightEleObj = {
  2387. module: moduleName,
  2388. resize: $('#deResize'),
  2389. top: $('#topContent'),
  2390. topSpread: $('#sectionSpread'),
  2391. bottom: $('#bottomContent'),
  2392. bottomSpread: $('#rationSpread')
  2393. },
  2394. heightLimit = {
  2395. min: 150,
  2396. max: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-150-10`,
  2397. notTopSpread: 0,
  2398. notBottomSpread: 0,
  2399. };
  2400. SlideResize.verticalSlide(heightEleObj, heightLimit, function () {
  2401. if(section.workBook){
  2402. section.workBook.refresh();
  2403. }
  2404. if(ration.workBook){
  2405. ration.workBook.refresh();
  2406. }
  2407. });
  2408. /*slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  2409. //autoFlashHeight();
  2410. if(section.workBook){
  2411. section.workBook.refresh();
  2412. }
  2413. if(ration.workBook){
  2414. ration.workBook.refresh();
  2415. }
  2416. });*/
  2417. //左右拖动
  2418. //清单表与项目指引表
  2419. let leftElesObj = {};
  2420. leftElesObj.module = moduleName;
  2421. leftElesObj.resize = $('#slideResizeLeft');
  2422. leftElesObj.parent = $('#dataRow');
  2423. leftElesObj.left = $('#leftContent');
  2424. leftElesObj.right = $('#midContent');
  2425. SlideResize.horizontalSlide(leftElesObj, {min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200`}, function () {
  2426. refreshALlWorkBook();
  2427. });
  2428. //人材机表与人材机组成物表
  2429. let rightElesObj = {};
  2430. rightElesObj.module = moduleName;
  2431. rightElesObj.resize = $('#slideResizeRight');
  2432. rightElesObj.parent = $('#dataRow');
  2433. rightElesObj.left = $('#midContent');
  2434. rightElesObj.right = $('#rightContent');
  2435. SlideResize.horizontalSlide(rightElesObj, {min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200`}, function () {
  2436. refreshALlWorkBook();
  2437. });
  2438. }
  2439. //刷新全部工作簿
  2440. //@return {void}
  2441. function refreshALlWorkBook() {
  2442. if (bills.workBook) {
  2443. bills.workBook.refresh();
  2444. }
  2445. if (guideItem.workBook) {
  2446. guideItem.workBook.refresh();
  2447. }
  2448. if (section.workBook) {
  2449. section.workBook.refresh();
  2450. }
  2451. if (ration.workBook) {
  2452. ration.workBook.refresh();
  2453. }
  2454. $('.main-side-bottom').find('textarea').height($('.main-side-bottom').height() - 20);
  2455. $('.main-side-bottom').find('textarea').width($('.main-side-bottom').width() - 25);
  2456. $('.main-bottom-content').find('textarea').height($('.main-bottom-content').height() - 20);
  2457. $('.main-bottom-content').find('textarea').width($('.main-bottom-content').width() - 25);
  2458. }
  2459. //读取拖动相关
  2460. //@return {void}
  2461. function initSlideSize() {
  2462. //定额表上下
  2463. let heightEleObj = {
  2464. module: moduleName,
  2465. top: $('#topContent'),
  2466. topSpread: $('#sectionSpread'),
  2467. bottom: $('#bottomContent'),
  2468. bottomSpread: $('#rationSpread')
  2469. };
  2470. if (!$('#rationSearchResult').is(':visible')) {
  2471. SlideResize.loadVerticalHeight(heightEleObj.module, heightEleObj,
  2472. {totalHeight: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-10`,
  2473. notTopSpread: 0, notBottomSpread: 0}, function () {
  2474. if(section.workBook){
  2475. section.workBook.refresh();
  2476. }
  2477. if(ration.workBook){
  2478. ration.workBook.refresh();
  2479. }
  2480. });
  2481. }
  2482. //水平
  2483. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft'), $('#slideResizeRight')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  2484. refreshALlWorkBook();
  2485. });
  2486. }
  2487. //初始化视图
  2488. //@param {void} @return {void}
  2489. function initViews(){
  2490. let modules = [bills, guideItem, section, ration, billMaterial];
  2491. initWorkBooks(modules);
  2492. lockUtil.lockTools($(document.body), locked);
  2493. getLibWithBills(libID);
  2494. initDomEvents();
  2495. initContextMenu();
  2496. initRationContextMenu();
  2497. initBillsContextMenu();
  2498. initSlideSize();
  2499. }
  2500. /* 生成特征分类: 测试使用 */
  2501. function getItemCharacterData(nodes, prefix) {
  2502. const processNodes = nodes.filter(node => isProcessNode(node));
  2503. const classGroups = []; // 同层必填选项的数组(二维数组)
  2504. processNodes.forEach(processNode => {
  2505. const classItems = [];
  2506. const optionNodes = processNode.children.filter(node => isOptionNode(node));
  2507. optionNodes.forEach(optionNode => {
  2508. // const name = prefix ? `${prefix}@${optionNode.data.name}` : optionNode.data.name;
  2509. if (optionNode.parent && optionNode.parent.data.required && (!optionNode.children
  2510. || !optionNode.children.length
  2511. || (optionNode.children[0].data && optionNode.children[0].data.rationID)
  2512. || !optionNode.children.some(node => isProcessNode(node)))) {
  2513. classItems.push(optionNode.data.name);
  2514. } else {
  2515. classItems.push(...getItemCharacterData(optionNode.children, optionNode.parent && optionNode.parent.data.required ? optionNode.data.name : ''));
  2516. }
  2517. });
  2518. if (classItems.length) {
  2519. classGroups.push(classItems);
  2520. }
  2521. });
  2522. // 拼接上一文本
  2523. if (classGroups[0] && classGroups[0].length) {
  2524. classGroups[0] = classGroups[0].map(name => prefix ? `${prefix}@${name}` : name);
  2525. }
  2526. // 二维数组内容排列组合
  2527. while (classGroups.length > 1) {
  2528. const prevClassItems = classGroups[0];
  2529. const nextClassItems = classGroups[1];
  2530. const mergedClassItems = [];
  2531. for (let i = 0; i < prevClassItems.length; i++) {
  2532. for (let j = 0; j < nextClassItems.length; j++) {
  2533. mergedClassItems.push(`${prevClassItems[i]}@${nextClassItems[j]}`);
  2534. }
  2535. }
  2536. classGroups.splice(0, 2, mergedClassItems);
  2537. }
  2538. return classGroups[0] ? [...new Set(classGroups[0])] : [];
  2539. }
  2540. /* function getItemCharacterData(nodes, prefix) {
  2541. debugger;
  2542. const processNodes = nodes.filter(node => isProcessNode(node) && node.data.required);
  2543. const classGroups = []; // 同层必填选项的数组(二维数组)
  2544. processNodes.forEach(processNode => {
  2545. const classItems = [];
  2546. const optionNodes = processNode.children.filter(node => isOptionNode(node));
  2547. optionNodes.forEach(optionNode => {
  2548. // const name = prefix ? `${prefix}@${optionNode.data.name}` : optionNode.data.name;
  2549. if (!optionNode.children
  2550. || !optionNode.children.length
  2551. || (optionNode.children[0].data && optionNode.children[0].data.rationID)
  2552. || !optionNode.children.some(node => isProcessNode(node) && node.data.required)) {
  2553. classItems.push(optionNode.data.name);
  2554. } else {
  2555. classItems.push(...getItemCharacterData(optionNode.children, optionNode.data.name));
  2556. }
  2557. });
  2558. classGroups.push(classItems);
  2559. });
  2560. // 拼接上一文本
  2561. if (classGroups[0] && classGroups[0].length) {
  2562. classGroups[0] = classGroups[0].map(name => prefix ? `${prefix}@${name}` : name);
  2563. }
  2564. // 二维数组内容排列组合
  2565. while (classGroups.length > 1) {
  2566. const prevClassItems = classGroups[0];
  2567. const nextClassItems = classGroups[1];
  2568. const mergedClassItems = [];
  2569. for (let i = 0; i < prevClassItems.length; i++) {
  2570. for (let j = 0; j < nextClassItems.length; j++) {
  2571. mergedClassItems.push(`${prevClassItems[i]}@${nextClassItems[j]}`);
  2572. }
  2573. }
  2574. classGroups.splice(0, 2, mergedClassItems);
  2575. }
  2576. return classGroups[0] || [];
  2577. } */
  2578. $('#generate-class').click(() => {
  2579. if (bills.tree.selected && bills.tree.selected.guidance.tree) {
  2580. const classData = getItemCharacterData(bills.tree.selected.guidance.tree.roots);
  2581. console.log(classData);
  2582. }
  2583. });
  2584. return {initViews, initSlideSize};
  2585. })();
  2586. $(document).ready(function () {
  2587. billsGuidance.initViews();
  2588. });