billsGuidance.js 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084
  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. await excelInstance.paintOnWorkBook();
  2267. } catch (error) {
  2268. console.log(error);
  2269. alert(error);
  2270. $("#excel-modal").modal('hide');
  2271. }
  2272. }
  2273. });
  2274. $('#export-excel-confirm').click(() => {
  2275. if (excelInstance) {
  2276. excelInstance.export();
  2277. }
  2278. })
  2279. $('#insert').click(function () {
  2280. insert([{ type: itemType.job, name: '', outputItemCharacter: true }], false);
  2281. });
  2282. $('#delConfirm').click(function () {
  2283. del();
  2284. $('#delAlert').modal('hide');
  2285. });
  2286. $('#delRationConfirm').click(function () {
  2287. delRations();
  2288. $('#delRationAlert').modal('hide');
  2289. });
  2290. $('#del').click(function () {
  2291. $('#delAlert').modal('show');
  2292. });
  2293. $('#upLevel').click(function () {
  2294. upLevel();
  2295. });
  2296. $('#downLevel').click(function () {
  2297. downLevel();
  2298. });
  2299. $('#upMove').click(function () {
  2300. upMove();
  2301. });
  2302. $('#downMove').click(function () {
  2303. downMove();
  2304. });
  2305. // 收起清单至第二层
  2306. $('#expandToSecond').click(function () {
  2307. if (!bills.tree || !bills.workBook) {
  2308. return;
  2309. }
  2310. bills.tree.roots.forEach(root => {
  2311. root.setExpanded(true);
  2312. root.children.forEach(item => {
  2313. item.setExpanded(false);
  2314. });
  2315. });
  2316. const billSheet = bills.workBook.getActiveSheet();
  2317. renderSheetFunc(billSheet, function () {
  2318. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billSheet, true);
  2319. });
  2320. })
  2321. //收起定额、展开全部
  2322. $('#expandContract').click(function () {
  2323. //目前状态时展开全部节点状态,点击则收起定额
  2324. let tree = bills.tree.selected.guidance.tree,
  2325. itemSheet = guideItem.workBook.getActiveSheet();
  2326. if (curExpandState === itemExpandState.expand) {
  2327. curExpandState = itemExpandState.contract;
  2328. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  2329. setNodesExpandState(tree.items, itemExpandState.contract);
  2330. } else {
  2331. curExpandState = itemExpandState.expand;
  2332. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  2333. setNodesExpandState(tree.items, itemExpandState.expand);
  2334. }
  2335. renderSheetFunc(itemSheet, function () {
  2336. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  2337. });
  2338. });
  2339. // 配置材料
  2340. $('#editMaterial').click(function () {
  2341. if (bills && bills.tree && bills.tree.selected) {
  2342. $('#bill-material-modal').modal('show');
  2343. }
  2344. });
  2345. // 插入选中定额
  2346. $('#insertRation').click(function () {
  2347. let checkedRows = getCheckedRationRows();
  2348. let insertDatas = getInsertRations(checkedRows);
  2349. if (insertDatas.length > 0) {
  2350. insert(insertDatas, false, function () {
  2351. //清空选择
  2352. clearCheckedRation(checkedRows);
  2353. });
  2354. }
  2355. else {
  2356. clearCheckedRation(checkedRows);
  2357. }
  2358. });
  2359. // 插入全部定额
  2360. $('#insertAll').click(function () {
  2361. let isAll = true;
  2362. let checkedRows = getCheckedRationRows(isAll);
  2363. let insertDatas = getInsertRations(checkedRows);
  2364. if (insertDatas.length > 0) {
  2365. insert(insertDatas, false);
  2366. }
  2367. });
  2368. // 搜索清单
  2369. $("#searchBillBtn").click(searchBills);
  2370. $('#searchBillText').keyup(function (e) {
  2371. delayKeyup(function () {
  2372. $('#searchBillBtn').click();
  2373. });
  2374. });
  2375. // 关闭搜索清单
  2376. $('#closeSearchBills').click(() => {
  2377. if (!bills.workBook) {
  2378. return;
  2379. }
  2380. const sheet = bills.workBook.getActiveSheet();
  2381. closeSearchBills(sheet);
  2382. })
  2383. //搜索定额
  2384. $('#searchBtn').click(function () {
  2385. let searchStr = $('#searchText').val();
  2386. if (!searchStr || searchStr === '') {
  2387. ration.cache = ration.datas;
  2388. }
  2389. else {
  2390. let reg = new RegExp(searchStr, 'i');
  2391. ration.cache = _.filter(ration.datas, function (data) {
  2392. return reg.test(data.code) || reg.test(data.name);
  2393. });
  2394. }
  2395. $('.top-content').hide();
  2396. $('#deResize').hide();
  2397. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  2398. $('#rationSearchResult').show();
  2399. autoFlashHeight();
  2400. ration.workBook.refresh();
  2401. let rationSheet = ration.workBook.getActiveSheet();
  2402. renderSheetFunc(rationSheet, function () {
  2403. clearCheckedRation(getCheckedRationRows());
  2404. showData(rationSheet, ration.headers, ration.cache);
  2405. })
  2406. });
  2407. //关闭搜索
  2408. $('#rationSearchResult a').click(function () {
  2409. $('.top-content').show();
  2410. $('#deResize').show();
  2411. $('#rationSearchResult').hide();
  2412. autoFlashHeight();
  2413. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  2414. clearCheckedRation(getCheckedRationRows());
  2415. });
  2416. section.workBook.refresh();
  2417. ration.workBook.refresh();
  2418. $('#searchText').val('');
  2419. //恢复章节树下的定额
  2420. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  2421. });
  2422. let keyupTime = 0,
  2423. delayTime = 500;
  2424. function delayKeyup(callback) {
  2425. let nowTime = Date.now();
  2426. keyupTime = nowTime;
  2427. setTimeout(function () {
  2428. if (nowTime - keyupTime == 0) {
  2429. callback();
  2430. }
  2431. }, delayTime);
  2432. }
  2433. //执行搜索
  2434. $('#searchText').keyup(function (e) {
  2435. delayKeyup(function () {
  2436. $('#searchBtn').click();
  2437. });
  2438. });
  2439. //编辑清单备注
  2440. $('.main-side-bottom').find('textarea').keyup(function () {
  2441. let me = this;
  2442. let node = bills.tree.selected;
  2443. let comment = $(me).val();
  2444. delayKeyup(function () {
  2445. if (node) {
  2446. let updateData = { lastOperator: userAccount, billsLibId: billsLibId, updateId: node.getID(), field: 'comment', data: comment };
  2447. updateBillsComment(updateData, function () {
  2448. node.data.comment = comment;
  2449. }, function () {
  2450. $(me).val(node.data.comment || '');
  2451. })
  2452. }
  2453. });
  2454. });
  2455. //编辑选项备注
  2456. $('.main-bottom-content').find('textarea').keyup(function () {
  2457. let me = this;
  2458. let node = bills.tree.selected.guidance.tree.selected;
  2459. let comment = $(me).val();
  2460. delayKeyup(function () {
  2461. if (node) {
  2462. let updateDatas = [{ updateType: updateType.update, findData: { ID: node.getID() }, updateData: { comment: comment } }];
  2463. updateGuideItems(updateDatas, function (rstData) {
  2464. node.data.comment = comment;
  2465. }, function () {
  2466. $(me).val(node.data.comment || '');
  2467. });
  2468. }
  2469. });
  2470. });
  2471. //定额高度拖动调整
  2472. let heightEleObj = {
  2473. module: moduleName,
  2474. resize: $('#deResize'),
  2475. top: $('#topContent'),
  2476. topSpread: $('#sectionSpread'),
  2477. bottom: $('#bottomContent'),
  2478. bottomSpread: $('#rationSpread')
  2479. },
  2480. heightLimit = {
  2481. min: 150,
  2482. max: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-150-10`,
  2483. notTopSpread: 0,
  2484. notBottomSpread: 0,
  2485. };
  2486. SlideResize.verticalSlide(heightEleObj, heightLimit, function () {
  2487. if (section.workBook) {
  2488. section.workBook.refresh();
  2489. }
  2490. if (ration.workBook) {
  2491. ration.workBook.refresh();
  2492. }
  2493. });
  2494. /*slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  2495. //autoFlashHeight();
  2496. if(section.workBook){
  2497. section.workBook.refresh();
  2498. }
  2499. if(ration.workBook){
  2500. ration.workBook.refresh();
  2501. }
  2502. });*/
  2503. //左右拖动
  2504. //清单表与项目指引表
  2505. let leftElesObj = {};
  2506. leftElesObj.module = moduleName;
  2507. leftElesObj.resize = $('#slideResizeLeft');
  2508. leftElesObj.parent = $('#dataRow');
  2509. leftElesObj.left = $('#leftContent');
  2510. leftElesObj.right = $('#midContent');
  2511. SlideResize.horizontalSlide(leftElesObj, { min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200` }, function () {
  2512. refreshALlWorkBook();
  2513. });
  2514. //人材机表与人材机组成物表
  2515. let rightElesObj = {};
  2516. rightElesObj.module = moduleName;
  2517. rightElesObj.resize = $('#slideResizeRight');
  2518. rightElesObj.parent = $('#dataRow');
  2519. rightElesObj.left = $('#midContent');
  2520. rightElesObj.right = $('#rightContent');
  2521. SlideResize.horizontalSlide(rightElesObj, { min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200` }, function () {
  2522. refreshALlWorkBook();
  2523. });
  2524. }
  2525. //刷新全部工作簿
  2526. //@return {void}
  2527. function refreshALlWorkBook() {
  2528. if (bills.workBook) {
  2529. bills.workBook.refresh();
  2530. }
  2531. if (guideItem.workBook) {
  2532. guideItem.workBook.refresh();
  2533. }
  2534. if (section.workBook) {
  2535. section.workBook.refresh();
  2536. }
  2537. if (ration.workBook) {
  2538. ration.workBook.refresh();
  2539. }
  2540. $('.main-side-bottom').find('textarea').height($('.main-side-bottom').height() - 20);
  2541. $('.main-side-bottom').find('textarea').width($('.main-side-bottom').width() - 25);
  2542. $('.main-bottom-content').find('textarea').height($('.main-bottom-content').height() - 20);
  2543. $('.main-bottom-content').find('textarea').width($('.main-bottom-content').width() - 25);
  2544. }
  2545. //读取拖动相关
  2546. //@return {void}
  2547. function initSlideSize() {
  2548. //定额表上下
  2549. let heightEleObj = {
  2550. module: moduleName,
  2551. top: $('#topContent'),
  2552. topSpread: $('#sectionSpread'),
  2553. bottom: $('#bottomContent'),
  2554. bottomSpread: $('#rationSpread')
  2555. };
  2556. if (!$('#rationSearchResult').is(':visible')) {
  2557. SlideResize.loadVerticalHeight(heightEleObj.module, heightEleObj,
  2558. {
  2559. totalHeight: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-10`,
  2560. notTopSpread: 0, notBottomSpread: 0
  2561. }, function () {
  2562. if (section.workBook) {
  2563. section.workBook.refresh();
  2564. }
  2565. if (ration.workBook) {
  2566. ration.workBook.refresh();
  2567. }
  2568. });
  2569. }
  2570. //水平
  2571. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft'), $('#slideResizeRight')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  2572. refreshALlWorkBook();
  2573. });
  2574. }
  2575. //初始化视图
  2576. //@param {void} @return {void}
  2577. function initViews() {
  2578. let modules = [bills, guideItem, section, ration, billMaterial, billMaterialHelper];
  2579. initWorkBooks(modules);
  2580. lockUtil.lockTools($(document.body), locked);
  2581. getLibWithBills(libID);
  2582. initDomEvents();
  2583. initContextMenu();
  2584. initRationContextMenu();
  2585. //initBillsContextMenu();
  2586. initSlideSize();
  2587. }
  2588. // 判断蓝色子项和孙子项是否打勾了必填
  2589. function hasRequireData(node) {
  2590. const requiredList = node.getPosterity().filter(subNode =>
  2591. subNode.data.required === true
  2592. );
  2593. if (requiredList.length) { return true }
  2594. return false;
  2595. }
  2596. // 这里判断有无无定额的情况,有的就返回true,没有就返回false
  2597. function isAllRationData(node) {
  2598. let isRequired = true;
  2599. if (node.children && node.children.length) {
  2600. node.children.forEach(subNode => {
  2601. if (!subNode.children || !subNode.children.length) {
  2602. isRequired = false;
  2603. }
  2604. })
  2605. }
  2606. //这里是兼容第一层直接是定额的白色节点
  2607. if (node.children && node.children.length) {
  2608. node.children.forEach(subNode => {
  2609. if (subNode.data.rationID) {
  2610. isRequired = true;
  2611. }
  2612. })
  2613. }
  2614. return isRequired;
  2615. }
  2616. // 获取选套定额
  2617. function getOptionalData(node, list = []) {
  2618. if (isProcessNode(node)) {
  2619. node.children.forEach(element => {
  2620. if (element.children && element.children.length) {
  2621. element.children.forEach(item => {
  2622. if (item.data.rationID) {
  2623. list.push(item.data.rationID);
  2624. } else if (isProcessNode(item)) {
  2625. getOptionalData(item, list)
  2626. }
  2627. })
  2628. }
  2629. });
  2630. } else {
  2631. node.children.forEach(element => {
  2632. if (element.data.rationID) {
  2633. list.push(element.data.rationID);
  2634. }
  2635. });
  2636. }
  2637. return list;
  2638. }
  2639. // 获取必填项下的ID和name的键值对
  2640. function getClassCodeStrData(nodes,data={classGroups:{},keyGroup:{}}){
  2641. nodes.forEach(node=>{
  2642. if (isProcessNode(node)&&node.data.required) {
  2643. node.children.forEach(subNode=>{
  2644. data.classGroups[subNode.data.ID]=subNode.data.name;
  2645. data.keyGroup[subNode.data.ID]=`${subNode.parent.data.name}:${subNode.data.name}`;
  2646. })
  2647. }
  2648. getClassCodeStrData(node.children,data);
  2649. })
  2650. return data;
  2651. }
  2652. //获取定额数据
  2653. // requireRationData必套定额对象
  2654. // optionalRationData 选逃定额对象
  2655. // classGroups classCode文字和id键值对
  2656. // classCodeList 各个classCode的pID和ID的关系
  2657. function getItemData(nodes, requireRationData = {}, optionalRationData = {}, classGroups = {}, prefixID = '', prefixSonID = '', IDData = {},keyGroup={}) {
  2658. const processNodes = nodes.filter(node => isProcessNode(node));
  2659. // const classGroups = []; // 同层必填选项的数组(二维数组)
  2660. processNodes.forEach(processNode => {
  2661. // 蓝色节点,必填
  2662. if (processNode.data.required) {
  2663. // 白色节点
  2664. const optionNodes = processNode.children.filter(node => isOptionNode(node));
  2665. optionNodes.forEach(optionNode => {
  2666. if (!requireRationData[optionNode.data.ID]) requireRationData[optionNode.data.ID] = [];
  2667. if (!optionalRationData[optionNode.data.ID]) optionalRationData[optionNode.data.ID] = [];
  2668. //白色节点下没有蓝色节点,就是到底了
  2669. if (!optionNode.children.some(subOptionNode => isProcessNode(subOptionNode))) {
  2670. // 是否必套定额
  2671. if (isAllRationData(optionNode)) {
  2672. optionNode.children.forEach(subOptionNode => {
  2673. requireRationData[optionNode.data.ID].push([subOptionNode.data.rationID]);
  2674. })
  2675. } else {
  2676. optionalRationData[optionNode.data.ID] = getOptionalData(optionNode);
  2677. }
  2678. const kV = {};
  2679. kV[optionNode.data.ID] = optionNode.data.name;
  2680. Object.assign(classGroups, kV);
  2681. const keyData={};
  2682. keyData[optionNode.data.ID] = `${optionNode.parent.data.name}:${optionNode.data.name}`;
  2683. Object.assign(keyGroup,keyData);
  2684. } else {
  2685. const kV = {};
  2686. kV[optionNode.data.ID] = optionNode.data.name;
  2687. Object.assign(classGroups, kV);
  2688. const keyData={};
  2689. keyData[optionNode.data.ID] = `${optionNode.parent.data.name}:${optionNode.data.name}`;
  2690. Object.assign(keyGroup,keyData);
  2691. // 后代项是否有必填
  2692. if (hasRequireData(optionNode)) {
  2693. //后代项有必填
  2694. prefixSonID = '';
  2695. getItemData(optionNode.children, requireRationData, optionalRationData, classGroups, optionNode.data.ID, prefixSonID, IDData,keyGroup);
  2696. } else {
  2697. //后代项无必填
  2698. optionNode.children.forEach(subOptionNode => {
  2699. // 是否必套定额
  2700. if (isAllRationData(optionNode)) {
  2701. if (!requireRationData[subOptionNode.parent.data.ID]) requireRationData[subOptionNode.parent.data.ID] = [];
  2702. requireRationData[subOptionNode.parent.data.ID].push(getOptionalData(subOptionNode));
  2703. } else {
  2704. if (!optionalRationData[subOptionNode.parent.data.ID]) optionalRationData[subOptionNode.parent.data.ID] = [];
  2705. optionalRationData[subOptionNode.parent.data.ID].push(...getOptionalData(subOptionNode));
  2706. }
  2707. })
  2708. }
  2709. }
  2710. })
  2711. } else {
  2712. // 蓝色节点,非必填
  2713. if (hasRequireData(processNode)) {
  2714. //后代项有必填
  2715. if (isProcessNode(processNode)) {
  2716. //蓝色
  2717. // 是否必套定额
  2718. if (isAllRationData(processNode)) {
  2719. processNode.children.forEach((subProcessNode) => {
  2720. subProcessNode.children.forEach((sSubProcessNode) => {
  2721. //这里是特殊处理,因为原来的逻辑是直接把定额绑到必填白色选项中下面的,每个蓝色的一组,但是这样是不对的,需要绑定在必填白色选项下的蓝色节点,所以这里就需要传入蓝色节点的id
  2722. const requireChildrenID = sSubProcessNode.parent.data.required ? prefixSonID : sSubProcessNode.data.ID;
  2723. IDData[sSubProcessNode.data.ID] = prefixID;
  2724. getItemData(
  2725. [sSubProcessNode],
  2726. requireRationData,
  2727. optionalRationData,
  2728. classGroups,
  2729. prefixID,
  2730. requireChildrenID,
  2731. IDData,
  2732. keyGroup
  2733. )
  2734. })
  2735. })
  2736. }else{
  2737. // 全部选套就不用走循环了,直接按照选套执行
  2738. let key = processNode.data.ID;
  2739. if (prefixID) key = prefixID;
  2740. if (prefixSonID) key = prefixSonID;
  2741. if (!optionalRationData[key]) optionalRationData[key] = [];
  2742. optionalRationData[key].push(...getOptionalData(processNode));
  2743. // 因为这里没有按照走整个流程,所以文字和ID的关系需要获取补充
  2744. if(hasRequireData(processNode)) {
  2745. const result =getClassCodeStrData(processNode.children)
  2746. Object.assign(classGroups,result.classGroups);
  2747. Object.assign(keyGroup,result.keyGroup);
  2748. } ;
  2749. }
  2750. }
  2751. } else {
  2752. let key = processNode.data.ID;
  2753. if (prefixID) key = prefixID;
  2754. if (prefixSonID) key = prefixSonID;
  2755. // 是否必套定额
  2756. if (isAllRationData(processNode)) {
  2757. if (!requireRationData[key]) requireRationData[key] = [];
  2758. requireRationData[key].push(getOptionalData(processNode));
  2759. } else {
  2760. if (!optionalRationData[key]) optionalRationData[key] = [];
  2761. optionalRationData[key].push(...getOptionalData(processNode));
  2762. }
  2763. }
  2764. }
  2765. })
  2766. return { requireRationData, optionalRationData, classGroups, IDData, keyGroup }
  2767. }
  2768. /* 生成特征分类: 前端测试使用,想要前端测试,需要在zhiyin.html中,将id=generate-classa的按钮放开 */
  2769. function getItemCharacterData(nodes, prefix, prefixID) {
  2770. const processNodes = nodes.filter(node => isProcessNode(node));
  2771. const classGroups = []; // 同层必填选项的数组(二维数组)
  2772. processNodes.forEach(processNode => {
  2773. const classItems = [];
  2774. const optionNodes = processNode.children.filter(node => isOptionNode(node));
  2775. optionNodes.forEach(optionNode => {
  2776. // const name = prefix ? `${prefix}@${optionNode.data.name}` : optionNode.data.name;
  2777. if (optionNode.parent && optionNode.parent.data.required && (!optionNode.children
  2778. || !optionNode.children.length
  2779. || (optionNode.children[0].data && optionNode.children[0].data.rationID)
  2780. || !optionNode.children.some(node => isProcessNode(node)))) {
  2781. // 必套定额
  2782. classItems.push({ name: optionNode.data.name, ID: optionNode.data.ID });
  2783. } else {
  2784. // classItems.push(...getItemCharacterData(optionNode.children, optionNode.parent && optionNode.parent.data.required ? optionNode.data.name : ''));
  2785. const childrenClassItem = getItemCharacterData(
  2786. optionNode.children,
  2787. optionNode.parent && optionNode.parent.data.required ? optionNode.data.name : '',
  2788. optionNode.parent && optionNode.parent.data.required ? optionNode.data.ID : ''
  2789. );
  2790. //如果返回的子项为空,但是父项又勾选了必填,则要把本身存入数组
  2791. if (optionNode.parent
  2792. && optionNode.parent.data.required
  2793. && childrenClassItem.length === 0
  2794. ) {
  2795. classItems.push({ name: optionNode.data.name, ID: optionNode.data.ID });
  2796. } else {
  2797. classItems.push(...childrenClassItem);
  2798. }
  2799. }
  2800. });
  2801. if (classItems.length) {
  2802. classGroups.push(classItems);
  2803. }
  2804. });
  2805. // 拼接上一文本
  2806. if (classGroups[0] && classGroups[0].length) {
  2807. // classGroups[0] = classGroups[0].map(name => prefix ? `${prefix}@${name}` : name);
  2808. classGroups[0] = classGroups[0].map(item => {
  2809. item.name = prefix ? `${prefix}@${item.name}` : item.name
  2810. item.ID = prefixID ? `${prefixID}@${item.ID}` : item.ID
  2811. return item;
  2812. });
  2813. }
  2814. // 二维数组内容排列组合
  2815. while (classGroups.length > 1) {
  2816. const prevClassItems = classGroups[0];
  2817. const nextClassItems = classGroups[1];
  2818. const mergedClassItems = [];
  2819. for (let i = 0; i < prevClassItems.length; i++) {
  2820. for (let j = 0; j < nextClassItems.length; j++) {
  2821. // 拼接文本
  2822. const mergedName = `${prevClassItems[i].name}@${nextClassItems[j].name}`;
  2823. const mergedID = `${prevClassItems[i].ID}@${nextClassItems[j].ID}`;
  2824. mergedClassItems.push({ name: mergedName, ID: mergedID });
  2825. }
  2826. }
  2827. classGroups.splice(0, 2, mergedClassItems);
  2828. }
  2829. // 去重(类别别名要唯一)
  2830. const items = classGroups[0] || [];
  2831. const nameMap = {};
  2832. const rst = [];
  2833. items.forEach(item => {
  2834. if (!nameMap[item.name]) {
  2835. rst.push(item);
  2836. }
  2837. nameMap[item.name] = true;
  2838. });
  2839. return rst;
  2840. }
  2841. // 获取选套定额:把所有分类数据的必套定额确定好了先。选套定额就是清单下所有定额除了必套的
  2842. function getOptionalRationIDs(optionalRationData) {
  2843. const optionalRationIDs = [];
  2844. Object.values(optionalRationData).forEach(optionalRation => {
  2845. if (optionalRation.length) optionalRationIDs.push(...optionalRation);
  2846. })
  2847. return [...new Set(optionalRationIDs)];
  2848. }
  2849. // 获取错套定额:清单下所有定额,除了分类对应的必套、选套定额
  2850. function getErrorRationIDs(requiredRationIDList, optionalRationIDs, guideNodes) {
  2851. const finRequireData = [];
  2852. requiredRationIDList.forEach(requiredRationIDs => {
  2853. finRequireData.push(...requiredRationIDs);
  2854. })
  2855. const errorRationIDs = [];
  2856. guideNodes.forEach(node => {
  2857. if (node.data.rationID && !finRequireData.includes(node.data.rationID) && !optionalRationIDs.includes(node.data.rationID)) {
  2858. errorRationIDs.push(node.data.rationID);
  2859. }
  2860. });
  2861. return [...new Set(errorRationIDs)];
  2862. }
  2863. //把classcode和必套选套定额结合在一起
  2864. function combineData(codeData, requireRationData, optionalRationData, classGroups, IDData,keyGroup) {
  2865. // 这里要记录下已经被绑定的选套定额,因为没有被用的定额需要绑定到各个classcode下
  2866. const matchRationList = [];
  2867. //这里需要把绑定在子节点的定额更新到必填的白色选项中(classcode的值)
  2868. const requireCombineData = {};
  2869. const optionCombineData = {};
  2870. Object.keys(IDData).forEach(key => {
  2871. if (!requireCombineData[IDData[key]]) requireCombineData[IDData[key]] = new Set();
  2872. if (!optionCombineData[IDData[key]]) optionCombineData[IDData[key]] = new Set();
  2873. if (requireRationData[key]) {
  2874. requireRationData[key].forEach(subData => {
  2875. subData.forEach(subItem => {
  2876. requireCombineData[IDData[key]].add(subItem);
  2877. })
  2878. })
  2879. }
  2880. if (optionalRationData[key]) {
  2881. optionalRationData[key].forEach(subData => {
  2882. optionCombineData[IDData[key]].add(subData);
  2883. })
  2884. }
  2885. })
  2886. const finData = codeData.map(classCodeData => {
  2887. const errorRationIDs = [];
  2888. const optionalRationIDs = [];
  2889. const requiredRationIDs = [];
  2890. let name = '';
  2891. let key = '';
  2892. const classCodeIDs = classCodeData.ID;
  2893. if (/@/.test(classCodeIDs)) {
  2894. classCodeIDs.split('@').forEach((classCodeID) => {
  2895. if (name) {
  2896. name = name + '@' + classGroups[classCodeID];
  2897. key += keyGroup[classCodeID];
  2898. } else {
  2899. name = classGroups[classCodeID];
  2900. key = keyGroup[classCodeID];
  2901. };
  2902. // 一组的必套定额,先去重
  2903. const unitRation = [];
  2904. // 这里是必填选项下绑定必套定额
  2905. if (requireRationData[classCodeID] && requireRationData[classCodeID].length) {
  2906. requireRationData[classCodeID].forEach(subItem => {
  2907. unitRation.push(...new Set(subItem));
  2908. })
  2909. requiredRationIDs.push(unitRation);
  2910. // 这里也要把用过的必套定额先存起来
  2911. matchRationList.push(...unitRation);
  2912. }
  2913. //这里是必填选项下绑定在蓝色节点下的必套定额
  2914. if (requireCombineData[classCodeID] && requireCombineData[classCodeID].size) {
  2915. requiredRationIDs.push([...requireCombineData[classCodeID]]);
  2916. // 这里也要把用过的必套定额先存起来
  2917. matchRationList.push(...requireCombineData[classCodeID]);
  2918. }
  2919. // 这里是必填选项下绑定选套定额
  2920. if (optionalRationData[classCodeID] && optionalRationData[classCodeID].length) {
  2921. optionalRationIDs.push(...optionalRationData[classCodeID]);
  2922. matchRationList.push(...optionalRationData[classCodeID]);
  2923. }
  2924. //这里是必填选项下绑定在蓝色节点下的选套定额,下同
  2925. if (optionCombineData[classCodeID] && optionCombineData[classCodeID].size) {
  2926. optionalRationIDs.push(...optionCombineData[classCodeID]);
  2927. matchRationList.push(...optionCombineData[classCodeID]);
  2928. }
  2929. })
  2930. return { name,key, requiredRationIDs, optionalRationIDs: [...new Set(optionalRationIDs)], errorRationIDs }
  2931. } else {
  2932. const unitRation = [];
  2933. name = classGroups[classCodeIDs];
  2934. key = keyGroup[classCodeIDs];
  2935. if (requireRationData[classCodeIDs] && requireRationData[classCodeIDs].length){
  2936. requireRationData[classCodeIDs].forEach(subItem => {
  2937. unitRation.push(...new Set(subItem));
  2938. })
  2939. requiredRationIDs.push(unitRation);
  2940. // 这里也要把用过的必套定额先存起来
  2941. matchRationList.push(...unitRation);
  2942. }
  2943. if (requireCombineData[classCodeIDs] && requireCombineData[classCodeIDs].size) {
  2944. requiredRationIDs.push([...requireCombineData[classCodeIDs]])
  2945. // 这里也要把用过的必套定额先存起来
  2946. matchRationList.push(...requireCombineData[classCodeIDs]);
  2947. };
  2948. if (optionalRationData[classCodeIDs] && optionalRationData[classCodeIDs].length) {
  2949. optionalRationIDs.push(...optionalRationData[classCodeIDs]);
  2950. matchRationList.push(...optionalRationData[classCodeIDs]);
  2951. }
  2952. if (optionCombineData[classCodeIDs] && optionCombineData[classCodeIDs].size) {
  2953. optionalRationIDs.push(...optionCombineData[classCodeIDs]);
  2954. matchRationList.push(...optionalRationData[classCodeIDs]);
  2955. }
  2956. return { name,key, requiredRationIDs, optionalRationIDs: [...new Set(optionalRationIDs)], errorRationIDs }
  2957. }
  2958. })
  2959. const unMatchRation = [];
  2960. Object.values(optionalRationData).forEach(data => {
  2961. data.forEach((rationID) => {
  2962. if (!matchRationList.includes(rationID)) {
  2963. unMatchRation.push(rationID);
  2964. }
  2965. })
  2966. })
  2967. // 这里把没有使用过的必套定额也丢到了选套里面
  2968. Object.values(requireRationData).forEach(data => {
  2969. data.forEach((rationData) => {
  2970. rationData.forEach(rationID=>{
  2971. if (!matchRationList.includes(rationID)) {
  2972. unMatchRation.push(rationID);
  2973. }
  2974. })
  2975. })
  2976. })
  2977. return { classData: finData, unMatchRation };
  2978. }
  2979. $('#generate-class').click(() => {
  2980. if (bills.tree.selected && bills.tree.selected.guidance.tree) {
  2981. const classCodeData = getItemCharacterData(bills.tree.selected.guidance.tree.roots);
  2982. const { requireRationData, optionalRationData, classGroups, IDData, keyGroup } = getItemData(bills.tree.selected.guidance.tree.roots);
  2983. // const noMatchOptionRation=[];
  2984. const { classData, unMatchRation } = combineData(classCodeData, requireRationData, optionalRationData, classGroups, IDData,keyGroup);
  2985. //因为所有的选套都是一样的,所以这里就直接赋值了
  2986. const optionalRationIDs = getOptionalRationIDs(optionalRationData);
  2987. classData.forEach(item => {
  2988. // 不在必填项下的选套都要绑定在每个classcode下
  2989. item.optionalRationIDs.push(...unMatchRation);
  2990. item.errorRationIDs = getErrorRationIDs(item.requiredRationIDs, item.optionalRationIDs, bills.tree.selected.guidance.tree.items);
  2991. })
  2992. console.log(optionalRationIDs);
  2993. console.log(classData);
  2994. }
  2995. });
  2996. return { initViews, initSlideSize, bills };
  2997. })();
  2998. $(document).ready(function () {
  2999. billsGuidance.initViews();
  3000. });