billsGuidance.js 130 KB

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