billsGuidance.js 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087
  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) {
  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) {
  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. //项目指引表焦点控制
  864. //@param {Number}row @return {void}
  865. function guideItemInitSel(row) {
  866. let billsNode = bills.tree.selected;
  867. let node = null;
  868. if (billsNode && billsNode.guidance.tree) {
  869. node = billsNode.guidance.tree.items[row];
  870. if (node) {
  871. billsNode.guidance.tree.selected = node;
  872. //显示备注
  873. $('.main-bottom-content').find('textarea').val(node.data.comment ? node.data.comment : '');
  874. }
  875. }
  876. refreshBtn(node);
  877. }
  878. //初始化当前库名
  879. //@param {String} @return {void}
  880. function initLibName(libName) {
  881. $('#libName')[0].outerHTML = $('#libName')[0].outerHTML.replace("XXX清单指引", libName);
  882. }
  883. //初始化各工作表
  884. //@param {Array}modules @return {void}
  885. function initWorkBooks(modules) {
  886. exportExcelWorkBook = new GC.Spread.Sheets.Workbook($('#excel-spread')[0], { sheetCount: 1 });
  887. for (let module of modules) {
  888. buildSheet(module);
  889. }
  890. }
  891. function tipDivCheck() {
  892. setTimeout(function () {
  893. let tips = $('#autoTip');
  894. if (ration.tipDiv == 'show') {
  895. return;
  896. } else if (ration.tipDiv == 'hide' && tips) {
  897. tips.hide();
  898. ration._toolTipElement = null;
  899. }
  900. }, 600)
  901. }
  902. //获取悬浮提示单元格
  903. //@param {Object}sheet @return {Object}
  904. function getTipCellType(sheet) {
  905. let setting = {};
  906. let TipCellType = function () { };
  907. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  908. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  909. return {
  910. x: x,
  911. y: y,
  912. row: context.row,
  913. col: context.col,
  914. cellStyle: cellStyle,
  915. cellRect: cellRect,
  916. sheet: context.sheet,
  917. sheetArea: context.sheetArea
  918. };
  919. };
  920. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  921. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  922. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  923. if (tag !== undefined && tag) {
  924. text = tag;
  925. }
  926. if (sheet && sheet.getParent().qo) {
  927. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  928. }
  929. let delayTimes = 500; //延时时间
  930. let now_timeStamp = +new Date();
  931. this.tipTimeStamp = now_timeStamp;
  932. let me = this;
  933. setTimeout(function () {
  934. if (now_timeStamp - me.tipTimeStamp == 0) {//鼠标停下的时候才显示
  935. if (setting.pos && text && text !== '') {
  936. //固定不显示的div,存储文本获取固定div宽度,toolTipElement由于显示和隐藏,获取宽度不正确
  937. if (!me._fixedTipElement) {
  938. let div = $('#fixedTip1')[0];
  939. if (!div) {
  940. div = document.createElement("div");
  941. $(div).css("padding", 5)
  942. .attr("id", 'fixedTip');
  943. $(div).hide();
  944. document.body.insertBefore(div, null);
  945. }
  946. me._fixedTipElement = div;
  947. }
  948. $(me._fixedTipElement).width('');
  949. $(me._fixedTipElement).html(text);
  950. if (!me._toolTipElement) {
  951. let div = $('#autoTip1')[0];
  952. if (!div) {
  953. div = document.createElement("div");
  954. $(div).css("position", "absolute")
  955. .css("border", "1px #C0C0C0 solid")
  956. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  957. .css("font", "0.9rem Calibri")
  958. .css("padding", 5)
  959. .css("background", '#303133')
  960. .css("color", '#fff')
  961. .attr("id", 'autoTip1');
  962. $(div).hide();
  963. document.body.insertBefore(div, null);
  964. }
  965. me._toolTipElement = div;
  966. $(me._toolTipElement).width('');
  967. //实时读取位置信息
  968. if (hitinfo.sheet && hitinfo.sheet.getParent().qo) {
  969. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  970. }
  971. $(me._toolTipElement).html(text);
  972. //定额库定额特殊处理
  973. if ($(hitinfo.sheet.getParent().qo).attr('id') === 'rationSpread') {
  974. let divWidth = $(me._fixedTipElement).width(),
  975. divHeight = $(me._fixedTipElement).height();
  976. if (divWidth > 600) {
  977. divWidth = 590;
  978. $(me._toolTipElement).width(divWidth);
  979. }
  980. let top = setting.pos.y + hitinfo.y - divHeight < 0 ? 0 : setting.pos.y + hitinfo.cellRect.y - divHeight;
  981. $(me._toolTipElement).css("top", top).css("left", setting.pos.x - divWidth);
  982. }
  983. else {
  984. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y + 15).css("left", setting.pos.x + hitinfo.x + 15);
  985. }
  986. //名称
  987. if (hitinfo.col === 2) {
  988. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  989. zoom = hitinfo.sheet.zoom();
  990. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  991. let textLength = me.getAutoFitWidth(value, text, acStyle, zoom, { sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport });
  992. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  993. if (textLength > cellWidth) {
  994. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y + 15).css("left", setting.pos.x + hitinfo.x + 15);
  995. $(me._toolTipElement).show("fast");
  996. ration.tipDiv = 'show';//做个标记
  997. }
  998. }
  999. else {
  1000. $(me._toolTipElement).show("fast");
  1001. ration.tipDiv = 'show';//做个标记
  1002. }
  1003. }
  1004. }
  1005. }
  1006. }, delayTimes);
  1007. };
  1008. TipCellType.prototype.processMouseLeave = function (hininfo) {
  1009. this.tipTimeStamp = +new Date();
  1010. ration.tipDiv = 'hide';
  1011. if (this._toolTipElement) {
  1012. $(this._toolTipElement).hide();
  1013. this._toolTipElement = null;
  1014. }
  1015. tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  1016. }
  1017. return new TipCellType();
  1018. }
  1019. //输出表数据(定额表)
  1020. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  1021. function showData(sheet, headers, datas) {
  1022. let fuc = function () {
  1023. sheet.setRowCount(datas.length);
  1024. //复选框
  1025. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  1026. let tipCellType = getTipCellType(sheet);
  1027. sheet.setCellType(-1, 0, checkBoxType);
  1028. for (let col = 0, cLen = headers.length; col < cLen; col++) {
  1029. for (let row = 0, rLen = datas.length; row < rLen; row++) {
  1030. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  1031. if (col === 1) {
  1032. sheet.setTag(row, col, datas[row]['hint']);
  1033. }
  1034. }
  1035. }
  1036. sheet.setCellType(-1, 1, tipCellType);
  1037. sheet.setCellType(-1, 2, tipCellType);
  1038. };
  1039. renderSheetFunc(sheet, fuc);
  1040. }
  1041. //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
  1042. //@param {Number}sectionId {Array}rations @return {Array}
  1043. function getRationsBySectionId(sectionId, rations) {
  1044. if (!sectionId || !rations) {
  1045. return [];
  1046. }
  1047. return _.filter(rations, { sectionId });
  1048. }
  1049. //定额章节树焦点控制
  1050. //@param {Number}row @return {void}
  1051. function sectionInitSel(row) {
  1052. let rationSheet = ration.workBook.getActiveSheet();
  1053. let sectionNode = section.tree ? section.tree.items[row] : null;
  1054. if (sectionNode && sectionNode.children.length === 0) {
  1055. let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
  1056. ration.cache = sectionRations;
  1057. showData(rationSheet, ration.headers, sectionRations);
  1058. }
  1059. else {
  1060. cleanData(rationSheet, ration.headers, 0);
  1061. }
  1062. }
  1063. //初始化定额条目
  1064. //@param {Number}rationLibId @return {void}
  1065. function initRationItems(rationLibId, successCb) {
  1066. $.bootstrapLoading.start();
  1067. //获取定额章节树
  1068. let sectionSheet = section.workBook.getActiveSheet();
  1069. CommonAjax.post('/rationRepository/api/getRationTree', { rationLibId: rationLibId }, function (sectionDatas) {
  1070. //获取所有定额数据
  1071. let reqEntity = { rationLibId: rationLibId, showHint: true, returnFields: '-_id code ID sectionId name unit basePrice rationGljList jobContent annotation' };
  1072. CommonAjax.post('/rationRepository/api/getRationItemsByLib', reqEntity, function (rstData) {
  1073. section.cache = sectionDatas;
  1074. initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
  1075. //初始焦点在第一行(切换库)
  1076. sectionSheet.setActiveCell(0, 0);
  1077. sortByCode(rstData);
  1078. /* rstData.sort(function (a, b) {
  1079. let rst = 0;
  1080. if(a.code > b.code){
  1081. rst = 1;
  1082. }
  1083. else if(a.code < b.code){
  1084. rst = -1;
  1085. }
  1086. return rst;
  1087. }); */
  1088. ration.datas = rstData;
  1089. sectionInitSel(0);
  1090. $.bootstrapLoading.end();
  1091. if (successCb) {
  1092. successCb();
  1093. }
  1094. }, function () {
  1095. $.bootstrapLoading.end();
  1096. });
  1097. }, function () {
  1098. $.bootstrapLoading.end();
  1099. });
  1100. }
  1101. // 可用的定额库ID
  1102. const rationLibIDs = [];
  1103. //初始化定额库选择
  1104. //@param {String}compilationId @return {void}
  1105. function initRationLibs(compilationId) {
  1106. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', { compilationId: compilationId }, function (rstData) {
  1107. $('#rationLibSel').empty();
  1108. for (let rationLib of rstData) {
  1109. rationLibIDs.push(+rationLib.ID);
  1110. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  1111. $('#rationLibSel').append(opt);
  1112. }
  1113. //初始选择
  1114. initRationItems(parseInt($('#rationLibSel').select().val()));
  1115. $('#rationLibSel').change(function () {
  1116. let rationLibId = parseInt($(this).select().val());
  1117. initRationItems(rationLibId);
  1118. })
  1119. });
  1120. }
  1121. // 变更定额库
  1122. function changeRationLib(libID, successCb) {
  1123. $('#rationLibSel').val(libID);
  1124. initRationItems(libID, successCb);
  1125. }
  1126. // 设置清单名称文本色
  1127. function setBillsForeColor(billsNodes) {
  1128. const sheet = bills.workBook.getActiveSheet();
  1129. renderSheetFunc(sheet, function () {
  1130. for (let bills of billsNodes) {
  1131. const row = bills.serialNo();
  1132. sheet.setStyle(row, 1, { foreColor: bills.data.hasGuide ? 'darkgreen' : 'black' });
  1133. }
  1134. });
  1135. }
  1136. //清单设置悬浮提示信息
  1137. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  1138. function setBillsHint(billsNodes, jobs, items) {
  1139. let jobsMapping = {},
  1140. itemsMapping = {};
  1141. for (let job of jobs) {
  1142. jobsMapping[job.id] = job;
  1143. }
  1144. for (let item of items) {
  1145. itemsMapping[item.id] = item;
  1146. }
  1147. let tagInfo = [];
  1148. for (let billsNode of billsNodes) {
  1149. let hintArr = [];
  1150. let billsItems = billsNode.data.items;
  1151. if (billsItems.length > 0) {
  1152. //项目特征
  1153. hintArr.push('项目特征:');
  1154. }
  1155. let itemCount = 1,
  1156. jobCount = 1;
  1157. for (let billsItem of billsItems) {
  1158. let itemData = itemsMapping[billsItem.id];
  1159. if (itemData) {
  1160. //特征值
  1161. let eigens = [];
  1162. for (let eigen of itemData.itemValue) {
  1163. eigens.push(eigen.value);
  1164. }
  1165. eigens = eigens.join(';');
  1166. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  1167. itemCount++;
  1168. }
  1169. }
  1170. //工作内容
  1171. let billsJobs = billsNode.data.jobs;
  1172. if (billsJobs.length > 0) {
  1173. hintArr.push('工作内容:');
  1174. }
  1175. for (let billsJob of billsJobs) {
  1176. let jobData = jobsMapping[billsJob.id];
  1177. if (jobData) {
  1178. hintArr.push(`${jobCount}.${jobData.content}`);
  1179. jobCount++;
  1180. }
  1181. }
  1182. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  1183. hintArr.push('工程量计算规则:');
  1184. hintArr.push(billsNode.data.ruleText);
  1185. }
  1186. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  1187. hintArr.push('补注:');
  1188. hintArr.push(billsNode.data.recharge);
  1189. }*/
  1190. if (hintArr.length > 0) {
  1191. tagInfo.push({ row: billsNode.serialNo(), value: hintArr.join('\n') });
  1192. }
  1193. }
  1194. let sheet = bills.workBook.getActiveSheet();
  1195. renderSheetFunc(sheet, function () {
  1196. for (let tagI of tagInfo) {
  1197. sheet.setTag(tagI.row, 0, tagI.value);
  1198. }
  1199. });
  1200. }
  1201. //初始化清单的工作内容和项目特征
  1202. //@param {Number}billsLibId {Function}callback @return {void}
  1203. function initJobAndCharacter(billsLibId, callback) {
  1204. CommonAjax.post('/stdBillsEditor/getJobContent', { billsLibId: billsLibId }, function (datas) {
  1205. stdBillsJobData = datas;
  1206. CommonAjax.post('/stdBillsEditor/getItemCharacter', { billsLibId: billsLibId }, function (datas) {
  1207. stdBillsFeatureData = datas;
  1208. if (callback) {
  1209. callback();
  1210. }
  1211. });
  1212. });
  1213. }
  1214. let billsLibId = 0;
  1215. //获取指引库信息及关联的清单
  1216. //@param {Number}libID {Function}callback @return {Object}
  1217. function getLibWithBills(libID, callback) {
  1218. CommonAjax.post('/billsGuidance/api/getLibWithBills', { libID: libID }, function (rstData) {
  1219. billsLibId = rstData.guidanceLib.billsLibId;
  1220. initRationLibs(rstData.guidanceLib.compilationId);
  1221. curCompilationID = rstData.guidanceLib.compilationId;
  1222. bills.cache = rstData.bills;
  1223. initLibName(rstData.guidanceLib.name);
  1224. /*initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  1225. //每一棵项目指引树挂在清单节点上
  1226. for(let node of bills.tree.items){
  1227. node.guidance = {tree: null, controller: null};
  1228. }
  1229. //默认初始节点
  1230. billsInitSel(0);
  1231. if(callback){
  1232. callback(rstData);
  1233. }*/
  1234. let initDataCallback = function () {
  1235. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  1236. //每一棵项目指引树挂在清单节点上
  1237. for (let node of bills.tree.items) {
  1238. node.guidance = { tree: null, controller: null };
  1239. }
  1240. //默认初始节点
  1241. billsInitSel(0);
  1242. if (callback) {
  1243. callback(rstData);
  1244. }
  1245. };
  1246. initJobAndCharacter(rstData.guidanceLib.billsLibId, initDataCallback);
  1247. }, function (msg) {
  1248. window.location.href = '/billsGuidance/main';
  1249. });
  1250. }
  1251. //初始化并输出树
  1252. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  1253. function initTree(module, sheet, treeSetting, datas) {
  1254. module.tree = idTree.createNew({ id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true });
  1255. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  1256. module.tree.loadDatas(datas);
  1257. if (module === bills) {
  1258. module.tree.roots.forEach(root => {
  1259. root.setExpanded(false);
  1260. })
  1261. }
  1262. module.controller.showTreeData();
  1263. if (module === bills) {
  1264. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  1265. setBillsForeColor(bills.tree.items);
  1266. }
  1267. }
  1268. //更新清单备注
  1269. function updateBillsComment(updateData, callback, errCB) {
  1270. CommonAjax.post('/stdBillsEditor/updateBills', updateData, function () {
  1271. if (callback) {
  1272. callback();
  1273. }
  1274. }, function () {
  1275. if (errCB) {
  1276. errCB();
  1277. }
  1278. });
  1279. }
  1280. //更新项目指引
  1281. //@param {Array}updateDatas {Function}callback @return {void}
  1282. function updateGuideItems(updateDatas, callback, errCB) {
  1283. CommonAjax.post('/billsGuidance/api/updateItems', { updateDatas: updateDatas }, function (rstData) {
  1284. if (callback) {
  1285. callback(rstData);
  1286. }
  1287. }, function () {
  1288. if (errCB) {
  1289. errCB();
  1290. }
  1291. $.bootstrapLoading.end();
  1292. });
  1293. }
  1294. //编辑后自动去除换行符回车符
  1295. const deESC = /[\n]/g;
  1296. //项目指引编辑
  1297. //@param {Object}sheet {Array}cells
  1298. function edit(sheet, cells) {
  1299. let updateDatas = [];
  1300. //同步节点数据
  1301. let syncDatas = [];
  1302. for (let cell of cells) {
  1303. const field = guideItem.headers[cell.col].dataCode;
  1304. let node = bills.tree.selected.guidance.tree.items[cell.row];
  1305. if (field === 'name' || field === 'unit' || field === 'interval') {
  1306. let text = sheet.getValue(cell.row, cell.col);
  1307. text = text ? text.toString() : '';
  1308. text = text.replace(deESC, '');
  1309. sheet.setValue(cell.row, cell.col, text);
  1310. if (node.data[field] != text) {
  1311. syncDatas.push({ node: node, text: text, field, cell });
  1312. updateDatas.push({ updateType: updateType.update, findData: { ID: node.getID() }, updateData: { [field]: text } });
  1313. }
  1314. } else if (field === 'outputItemCharacter' || field === 'required' || field === 'isMaterial' || field === 'isDefaultOption') {
  1315. const val = !sheet.getValue(cell.row, cell.col);
  1316. sheet.setValue(cell.row, cell.col, val);
  1317. syncDatas.push({ node: node, text: val, field, cell });
  1318. updateDatas.push({ updateType: updateType.update, findData: { ID: node.getID() }, updateData: { [field]: val } });
  1319. }
  1320. }
  1321. if (updateDatas.length > 0) {
  1322. updateGuideItems(updateDatas, function () {
  1323. for (let syncData of syncDatas) {
  1324. syncData.node.data[syncData.field] = syncData.text;
  1325. }
  1326. }, function () {
  1327. //失败恢复
  1328. renderSheetFunc(sheet, function () {
  1329. for (let syncData of syncDatas) {
  1330. sheet.setValue(syncData.node.serialNo(), syncData.cell.col, syncData.node.data[syncData.field] ? syncData.node.data[syncData.field] : '');
  1331. }
  1332. });
  1333. });
  1334. }
  1335. }
  1336. //项目指引插入,支持一次插入多条数据
  1337. //@param {Array}datas {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  1338. function insert(datas, tobeChild, callback = null) {
  1339. $.bootstrapLoading.start();
  1340. let sheet = guideItem.workBook.getActiveSheet();
  1341. let controller = bills.tree.selected.guidance.controller;
  1342. let selected = bills.tree.selected.guidance.tree.selected;
  1343. let updateDatas = [];
  1344. //建立数组下标索引
  1345. let newDataIndex = {};
  1346. for (let i = 0; i < datas.length; i++) {
  1347. let newNodeData = {
  1348. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  1349. billsID: bills.tree.selected.getID(),
  1350. outputItemCharacter: true,
  1351. };
  1352. //定额类型插入当前工作内容焦点行,
  1353. if (selected && ((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)) {
  1354. newNodeData.ParentID = selected.getID();
  1355. newNodeData.NextSiblingID = -1;
  1356. }
  1357. Object.assign(newNodeData, datas[i]);
  1358. newDataIndex[i] = newNodeData;
  1359. }
  1360. for (let i = 0; i < datas.length; i++) {
  1361. //第一个节点
  1362. if (i === 0) {
  1363. //非插入成子节点,更新选中节点NestSiblingID
  1364. if (selected && !((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)) {
  1365. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.getID() }, updateData: { NextSiblingID: newDataIndex[i].ID } });
  1366. }
  1367. }
  1368. //非最后一个节点
  1369. if (i !== datas.length - 1) {
  1370. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  1371. }
  1372. updateDatas.push({ updateType: updateType.create, updateData: newDataIndex[i] });
  1373. }
  1374. updateGuideItems(updateDatas, function () {
  1375. const outputItemCol = guideItem.headers.findIndex(item => item.dataCode === 'outputItemCharacter');
  1376. for (let updateData of updateDatas) {
  1377. if (updateData.updateType === updateType.create) {
  1378. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  1379. //同步data
  1380. Object.assign(newNode.data, updateData.updateData);
  1381. const row = newNode.serialNo();
  1382. sheet.setValue(row, 0, newNode.data.name);
  1383. if (newNode.data.outputItemCharacter !== undefined) {
  1384. sheet.setValue(row, outputItemCol, newNode.data.outputItemCharacter);
  1385. }
  1386. setProcessNodes(sheet, [newNode]);
  1387. refreshBtn(newNode);
  1388. }
  1389. }
  1390. if (!bills.tree.selected.data.hasGuide && bills.tree.selected.guidance.tree.items.length) {
  1391. bills.tree.selected.data.hasGuide = true;
  1392. setBillsForeColor([bills.tree.selected]);
  1393. }
  1394. if (callback) {
  1395. callback();
  1396. }
  1397. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1398. guideItem.workBook.focus(true);
  1399. $.bootstrapLoading.end();
  1400. });
  1401. }
  1402. // 删除定额(嵌套删除自身及后代定额)
  1403. function delRations() {
  1404. const selected = bills.tree.selected.guidance.tree.selected;
  1405. if (!selected) {
  1406. return;
  1407. }
  1408. if (selected.data.type === itemType.ration) {
  1409. del({ row: selected.serialNo(), col: 0, rowCount: 1, colCount: 1 });
  1410. return;
  1411. }
  1412. const rations = selected.getPosterity().filter(item => item.data.type === itemType.ration);
  1413. if (!rations.length) {
  1414. return;
  1415. }
  1416. const updateDatas = rations.map(item => ({ updateType: updateType.del, findData: { ID: item.data.ID } }));
  1417. const rationIDs = rations.map(r => r.data.ID);
  1418. $.bootstrapLoading.start();
  1419. updateGuideItems(updateDatas, function () {
  1420. const guideSheet = guideItem.workBook.getSheet(0);
  1421. const treeNodes = bills.tree.selected.guidance.tree.items.filter(item => !rationIDs.includes(item.data.ID));
  1422. const state = bills.tree.selected.guidance.tree.getExpState(treeNodes);
  1423. const treeData = treeNodes.map(item => item.data);
  1424. initTree(bills.tree.selected.guidance, guideSheet, guideItem.treeSetting, treeData);
  1425. bills.tree.selected.guidance.tree.setExpandedByState(bills.tree.selected.guidance.tree.items, state);
  1426. renderSheetFunc(guideSheet, function () {
  1427. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.selected.guidance.tree.roots, guideSheet, true);
  1428. });
  1429. //设置底色
  1430. setNodesColor(guideSheet, bills.tree.selected.guidance.tree.items);
  1431. //项目指引初始焦点
  1432. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  1433. $.bootstrapLoading.end();
  1434. guideItem.workBook.focus(true)
  1435. });
  1436. }
  1437. //项目指引删除操作
  1438. //@return {void}
  1439. function del(selArea = null) {
  1440. $.bootstrapLoading.start();
  1441. let controller = bills.tree.selected.guidance.controller;
  1442. let selNodes = [];
  1443. let sheet = guideItem.workBook.getSheet(0);
  1444. let sel = selArea ? selArea : sheet.getSelections()[0];
  1445. if (sel) {
  1446. sel.row = sel.row === -1 ? 0 : sel.row;
  1447. for (let i = 0; i < sel.rowCount; i++) {
  1448. if (bills.tree.selected.guidance.tree.items[sel.row + i]) {
  1449. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1450. }
  1451. }
  1452. }
  1453. //选中的块节点
  1454. let blockNodes = getBlockNodes(selNodes);
  1455. let updateDatas = [];
  1456. function getDelDatas(nodes) {
  1457. for (let node of nodes) {
  1458. updateDatas.push({ updateType: updateType.del, findData: { ID: node.getID() } });
  1459. if (node.children.length > 0) {
  1460. getDelDatas(node.children);
  1461. }
  1462. }
  1463. }
  1464. getDelDatas(blockNodes);
  1465. //更新相关的前节点
  1466. for (let node of blockNodes) {
  1467. if (node.preSibling && !blockNodes.includes(node.preSibling)) {
  1468. let next = node;
  1469. while (next.nextSibling && blockNodes.includes(next.nextSibling)) {
  1470. next = next.nextSibling;
  1471. }
  1472. updateDatas.push({ updateType: updateType.update, findData: { ID: node.preSibling.getID() }, updateData: { NextSiblingID: next.getNextSiblingID() } });
  1473. }
  1474. }
  1475. updateGuideItems(updateDatas, function () {
  1476. console.log(blockNodes);
  1477. controller.m_delete(blockNodes);
  1478. guideItemInitSel(sheet.getActiveRowIndex());
  1479. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1480. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1481. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1482. if (bills.tree.selected.data.hasGuide && !bills.tree.selected.guidance.tree.items.length) {
  1483. bills.tree.selected.data.hasGuide = false;
  1484. setBillsForeColor([bills.tree.selected]);
  1485. }
  1486. $.bootstrapLoading.end();
  1487. guideItem.workBook.focus(true)
  1488. });
  1489. }
  1490. //项目指引升级
  1491. //@return {void}
  1492. function upLevel() {
  1493. $.bootstrapLoading.start();
  1494. let controller = bills.tree.selected.guidance.controller;
  1495. let selected = bills.tree.selected.guidance.tree.selected;
  1496. let updateDatas = [];
  1497. //更新父节点
  1498. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.getParentID() }, updateData: { NextSiblingID: selected.getID() } });
  1499. //更新选中节点
  1500. updateDatas.push({
  1501. updateType: updateType.update, findData: { ID: selected.getID() },
  1502. updateData: { ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID(), unit: '', interval: '' }
  1503. });
  1504. if (selected.nextSibling && selected.children.length > 0) {
  1505. //更新选中节点最末子节点
  1506. let lastChild = selected.children[selected.children.length - 1];
  1507. updateDatas.push({ updateType: updateType.update, findData: { ID: lastChild.getID() }, updateData: { NextSiblingID: -1 } });
  1508. }
  1509. //选中节点的所有后兄弟节点成为选中节点的子项
  1510. let selectedNextIDs = [];
  1511. let sNext = selected.nextSibling;
  1512. while (sNext) {
  1513. selectedNextIDs.push(sNext.getID());
  1514. sNext = sNext.nextSibling;
  1515. }
  1516. for (let sID of selectedNextIDs) {
  1517. updateDatas.push({ updateType: updateType.update, findData: { ID: sID }, updateData: { ParentID: selected.getID() } });
  1518. }
  1519. updateGuideItems(updateDatas, function () {
  1520. controller.upLevel();
  1521. const sheet = guideItem.workBook.getActiveSheet();
  1522. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1523. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1524. setProcessNodes(sheet, bills.tree.selected.guidance.tree.items);
  1525. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  1526. const intervalCol = guideItem.headers.findIndex(item => item.dataCode === 'interval');
  1527. sheet.setValue(selected.serialNo(), unitCol, '');
  1528. sheet.setValue(selected.serialNo(), intervalCol, '');
  1529. $.bootstrapLoading.end();
  1530. guideItem.workBook.focus(true)//31574
  1531. });
  1532. }
  1533. //项目指引降级
  1534. //@return {void}
  1535. function downLevel() {
  1536. $.bootstrapLoading.start();
  1537. let controller = bills.tree.selected.guidance.controller;
  1538. let selected = bills.tree.selected.guidance.tree.selected;
  1539. let updateDatas = [];
  1540. //更新前兄弟节点
  1541. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.preSibling.getID() }, updateData: { NextSiblingID: selected.getNextSiblingID() } });
  1542. //更新前兄弟节点最末子节点
  1543. if (selected.preSibling.children.length > 0) {
  1544. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  1545. updateDatas.push({ updateType: updateType.update, findData: { ID: lastChild.getID() }, updateData: { NextSiblingID: selected.getID() } });
  1546. }
  1547. //更新选中节点
  1548. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.getID() }, updateData: { ParentID: selected.preSibling.getID(), NextSiblingID: -1, unit: '', interval: '' } });
  1549. updateGuideItems(updateDatas, function () {
  1550. controller.downLevel();
  1551. const sheet = guideItem.workBook.getActiveSheet();
  1552. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1553. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1554. setProcessNodes(sheet, bills.tree.selected.guidance.tree.items);
  1555. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  1556. const intervalCol = guideItem.headers.findIndex(item => item.dataCode === 'interval');
  1557. sheet.setValue(selected.serialNo(), unitCol, '');
  1558. sheet.setValue(selected.serialNo(), intervalCol, '');
  1559. $.bootstrapLoading.end();
  1560. guideItem.workBook.focus(true)
  1561. });
  1562. }
  1563. //项目指引上移
  1564. //@return {void}
  1565. function upMove() {
  1566. $.bootstrapLoading.start();
  1567. let controller = bills.tree.selected.guidance.controller;
  1568. let selected = bills.tree.selected.guidance.tree.selected;
  1569. let updateDatas = [];
  1570. //更新前节点
  1571. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.preSibling.getID() }, updateData: { NextSiblingID: selected.getNextSiblingID() } });
  1572. //更新前前节点
  1573. if (selected.preSibling.preSibling) {
  1574. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.preSibling.preSibling.getID() }, updateData: { NextSiblingID: selected.getID() } });
  1575. }
  1576. //更新选中节点
  1577. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.getID() }, updateData: { NextSiblingID: selected.preSibling.getID() } });
  1578. updateGuideItems(updateDatas, function () {
  1579. controller.upMove();
  1580. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1581. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1582. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1583. $.bootstrapLoading.end();
  1584. guideItem.workBook.focus(true)
  1585. });
  1586. }
  1587. //项目指引下移
  1588. //@return {void}
  1589. function downMove() {
  1590. $.bootstrapLoading.start();
  1591. let controller = bills.tree.selected.guidance.controller;
  1592. let selected = bills.tree.selected.guidance.tree.selected;
  1593. let updateDatas = [];
  1594. //更新下节点
  1595. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.getNextSiblingID() }, updateData: { NextSiblingID: selected.getID() } });
  1596. //更新前节点
  1597. if (selected.preSibling) {
  1598. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.preSibling.getID() }, updateData: { NextSiblingID: selected.getNextSiblingID() } });
  1599. }
  1600. //更新选中节点
  1601. updateDatas.push({ updateType: updateType.update, findData: { ID: selected.getID() }, updateData: { NextSiblingID: selected.nextSibling.getNextSiblingID() } });
  1602. updateGuideItems(updateDatas, function () {
  1603. controller.downMove();
  1604. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1605. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1606. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1607. $.bootstrapLoading.end();
  1608. guideItem.workBook.focus(true)
  1609. });
  1610. }
  1611. //获取定额类型的项目指引名称,通过定额转换
  1612. //@param {Object}ration @return {String}
  1613. function getRationItemName(ration) {
  1614. let arr = [];
  1615. arr.push(ration.code ? ration.code : '');
  1616. arr.push(ration.name ? ration.name : '');
  1617. arr.push(ration.basePrice ? ration.basePrice : '');
  1618. let rst = arr.join(' ');
  1619. rst += `/${ration.unit ? ration.unit : ''}`;
  1620. return rst;
  1621. }
  1622. //获取选中的定额表行
  1623. //@return {Array}
  1624. function getCheckedRationRows(all) {
  1625. let rst = [];
  1626. let sheet = ration.workBook.getActiveSheet();
  1627. for (let i = 0; i < sheet.getRowCount(); i++) {
  1628. // 全选
  1629. if (all) {
  1630. rst.push(i);
  1631. continue;
  1632. }
  1633. let checked = sheet.getValue(i, 0);
  1634. if (checked) {
  1635. rst.push(i);
  1636. }
  1637. }
  1638. return rst;
  1639. }
  1640. //清空选中定额表行
  1641. //@param {Array}rows @return {void}
  1642. function clearCheckedRation(rows) {
  1643. let sheet = ration.workBook.getActiveSheet();
  1644. renderSheetFunc(sheet, function () {
  1645. for (let row of rows) {
  1646. sheet.setValue(row, 0, 0);
  1647. }
  1648. });
  1649. }
  1650. //获取要插入的定额数据
  1651. //@param {Array}rows @return {Array}
  1652. function getInsertRations(rows) {
  1653. let rst = [];
  1654. //当前已存在定额
  1655. let curRationIems = [];
  1656. let selected = bills.tree.selected.guidance.tree.selected;
  1657. if (selected) {
  1658. if (selected.data.type === itemType.job) {
  1659. curRationIems = selected.children;
  1660. }
  1661. else {
  1662. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  1663. }
  1664. }
  1665. for (let row of rows) {
  1666. let selRation = ration.cache[row];
  1667. if (selRation) {
  1668. //添加的定额是否已存在,不重复添加
  1669. let isExist = false;
  1670. for (let curRation of curRationIems) {
  1671. if (curRation.data.rationID == selRation.ID) {
  1672. isExist = true;
  1673. break;
  1674. }
  1675. }
  1676. if (!isExist) {
  1677. rst.push({ type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID });
  1678. }
  1679. }
  1680. }
  1681. return rst;
  1682. }
  1683. //获取块节点父项不存在于选中节点中的节点
  1684. //@param {Array}nodes(选中的节点) @return {Array}
  1685. function getBlockNodes(nodes) {
  1686. let nodeMapping = {};
  1687. for (let node of nodes) {
  1688. nodeMapping[node.data.ID] = node;
  1689. }
  1690. //块节点,父项不存在于选中节点中的节点
  1691. let blockNodes = [];
  1692. for (let node of nodes) {
  1693. if (!nodeMapping[node.data.ParentID]) {
  1694. blockNodes.push(node);
  1695. }
  1696. }
  1697. return blockNodes;
  1698. }
  1699. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1700. //@param {Array}nodes(块节点) @return {Boolean}
  1701. function canCopyBlock(nodes) {
  1702. if (!nodes || nodes.length === 0) {
  1703. return false;
  1704. }
  1705. let pID = nodes[0].data.ParentID;
  1706. for (let node of nodes) {
  1707. if (node.data.ParentID !== pID) {
  1708. return false;
  1709. }
  1710. }
  1711. return true;
  1712. }
  1713. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1714. //@param {Object}node(粘贴到的节点)
  1715. function canPasteBlock(node) {
  1716. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1717. if (!pasteDatas || pasteDatas.length === 0) {
  1718. return false;
  1719. }
  1720. if (!node) {
  1721. return false;
  1722. }
  1723. //若粘贴到定额节点,则数据须全为定额
  1724. if (node.data.type === itemType.ration) {
  1725. for (let data of pasteDatas) {
  1726. if (data.type !== itemType.ration) {
  1727. return false;
  1728. }
  1729. }
  1730. }
  1731. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1732. else {
  1733. let topDatas = _.filter(pasteDatas, { ParentID: -1 });
  1734. for (let topData of topDatas) {
  1735. if (topData.type === itemType.ration) {
  1736. return false;
  1737. }
  1738. }
  1739. }
  1740. return true;
  1741. }
  1742. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1743. //@param {Array}nodes(块节点) @return {void}
  1744. function copyBlocks(nodes) {
  1745. nodes = _.cloneDeep(nodes);
  1746. //将块节点的ParentID暂时设置为-1
  1747. for (let topNode of nodes) {
  1748. topNode.data.ParentID = -1;
  1749. }
  1750. let copyDatas = [];
  1751. let copyNodes = [];
  1752. //获取块节点包含的所有节点(包括自己)
  1753. function containNodes(nodes) {
  1754. for (let node of nodes) {
  1755. copyNodes.push(node);
  1756. if (node.children.length > 0) {
  1757. containNodes(node.children);
  1758. }
  1759. }
  1760. }
  1761. containNodes(nodes);
  1762. for (let node of copyNodes) {
  1763. copyDatas.push(node.data);
  1764. }
  1765. console.log(`copyDatas`);
  1766. console.log(copyDatas);
  1767. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1768. }
  1769. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1770. //@param {Object}node(粘贴到的节点) @return {void}
  1771. function pasteBlock(node) {
  1772. let itemObj = bills.tree.selected.guidance;
  1773. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1774. //整理ID
  1775. let IDMapping = {};
  1776. for (let data of pasteDatas) {
  1777. data.newID = uuid.v1();
  1778. IDMapping[data.ID] = data;
  1779. }
  1780. for (let data of pasteDatas) {
  1781. let nextData = IDMapping[data.NextSiblingID];
  1782. data.NextSiblingID = nextData ? nextData.newID : -1;
  1783. let parentData = IDMapping[data.ParentID];
  1784. data.ParentID = parentData ? parentData.newID : -1;
  1785. }
  1786. for (let data of pasteDatas) {
  1787. data.ID = data.newID;
  1788. delete data.newID;
  1789. }
  1790. let updateDatas = [];
  1791. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1792. let topDatas = _.filter(pasteDatas, { ParentID: -1 });
  1793. for (let topData of topDatas) {
  1794. topData.ParentID = node.getParentID();
  1795. }
  1796. //更新数据
  1797. //更新插入的最末顶层数据NextSiblingID
  1798. if (node.nextSibling) {
  1799. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1800. }
  1801. //新建节点
  1802. for (let data of pasteDatas) {
  1803. data.libID = libID;
  1804. data.billsID = node.data.billsID;
  1805. delete data._id;
  1806. updateDatas.push({ updateType: updateType.create, updateData: data });
  1807. }
  1808. console.log(`pasteDatas`);
  1809. console.log(pasteDatas);
  1810. //更新粘贴到的节点的NextSiblingID
  1811. updateDatas.push({ updateType: updateType.update, findData: { ID: node.data.ID }, updateData: { NextSiblingID: topDatas[0].ID } })
  1812. $.bootstrapLoading.start();
  1813. updateGuideItems(updateDatas, function (rstData) {
  1814. $.bootstrapLoading.end();
  1815. node.data.NextSiblingID = topDatas[0].ID;
  1816. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1817. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1818. itemObj.controller.showTreeData();
  1819. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1820. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1821. }, function () {
  1822. $.bootstrapLoading.end();
  1823. });
  1824. }
  1825. // 双击定位定额
  1826. async function locateAtRation(row) {
  1827. const node = bills.tree.selected.guidance.tree.items[row];
  1828. if (!node || !node.data.rationID) {
  1829. return;
  1830. }
  1831. const rationItem = ration.datas.find(item => item.ID === node.data.rationID);
  1832. // 当前库没有找到,需要后端查找
  1833. if (!rationItem) {
  1834. const findedRation = await ajaxPost('/rationRepository/api/getRationByID', { ID: node.data.rationID });
  1835. if (!findedRation || !rationLibIDs.includes(findedRation.rationRepId)) {
  1836. alert('无法定位此定额,此定额已被删除');
  1837. return;
  1838. }
  1839. changeRationLib(findedRation.rationRepId, () => {
  1840. located(findedRation.ID, findedRation.sectionId);
  1841. })
  1842. } else {
  1843. located(rationItem.ID, rationItem.sectionId);
  1844. }
  1845. function located(rationID, sectionID) {
  1846. if (!section.tree) {
  1847. return;
  1848. }
  1849. const sectionNode = section.tree.nodes[section.tree.prefix + sectionID];
  1850. if (!sectionNode) {
  1851. return;
  1852. }
  1853. // 定位到对应章节树
  1854. const sectionSheet = section.workBook.getActiveSheet();
  1855. const sectionRow = sectionNode.serialNo();
  1856. expandSearchNodes(sectionSheet, [sectionNode], section.tree.roots);
  1857. sectionSheet.setSelection(sectionRow, 0, 1, 1);
  1858. sectionSheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.center);
  1859. sectionInitSel(sectionRow);
  1860. // 定位到对应定额
  1861. const locatedRationRow = ration.cache.findIndex(item => item.ID === rationID);
  1862. if (locatedRationRow !== -1) {
  1863. const rationSheet = ration.workBook.getActiveSheet();
  1864. rationSheet.setSelection(locatedRationRow, 1, 1, 1);
  1865. rationSheet.showRow(locatedRationRow, GC.Spread.Sheets.VerticalPosition.center);
  1866. }
  1867. }
  1868. }
  1869. //初始化右键菜单
  1870. //@return {void}
  1871. function initContextMenu() {
  1872. $.contextMenu({
  1873. selector: '#guideItemSpread',
  1874. build: function ($triggerElement, e) {
  1875. //控制允许右键菜单在哪个位置出现
  1876. let sheet = guideItem.workBook.getSheet(0);
  1877. let offset = $("#guideItemSpread").offset(),
  1878. x = e.pageX - offset.left,
  1879. y = e.pageY - offset.top;
  1880. let target = sheet.hitTest(x, y);
  1881. if (target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined') {//在表格内
  1882. let sel = sheet.getSelections()[0];
  1883. if (sel && sel.rowCount === 1) {
  1884. sheet.setActiveCell(target.row, target.col);
  1885. }
  1886. sel = sheet.getSelections()[0];
  1887. let selNodes = [];
  1888. if (sel) {
  1889. sel.row = sel.row === -1 ? 0 : sel.row;
  1890. for (let i = 0; i < sel.rowCount; i++) {
  1891. if (bills.tree.selected.guidance.tree.items[sel.row + i]) {
  1892. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1893. }
  1894. }
  1895. }
  1896. //块节点
  1897. let blockNodes = getBlockNodes(selNodes);
  1898. //右键在多选内则不重设焦点
  1899. if (!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)) {
  1900. sheet.setActiveCell(target.row, target.col);
  1901. }
  1902. guideItemInitSel(target.row);
  1903. return {
  1904. callback: function () { },
  1905. items: {
  1906. "copy": {
  1907. name: "复制整块",
  1908. disabled: function () {
  1909. return locked || !canCopyBlock(blockNodes);
  1910. },
  1911. icon: "fa-copy",
  1912. callback: function (key, opt) {
  1913. copyBlocks(blockNodes);
  1914. }
  1915. },
  1916. "paste": {
  1917. name: "粘贴整块",
  1918. disabled: function () {
  1919. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1920. return locked || !canPasteBlock(pasteNode);
  1921. },
  1922. icon: "fa-paste",
  1923. callback: function (key, opt) {
  1924. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1925. pasteBlock(pasteNode);
  1926. }
  1927. },
  1928. "delRations": {
  1929. name: '删除定额',
  1930. disabled: function () {
  1931. let node = bills.tree.selected.guidance.tree.items[target.row];
  1932. return locked || !node
  1933. },
  1934. icon: "fa-remove",
  1935. callback: function (key, opt) {
  1936. $('#delRationAlert').modal('show');
  1937. }
  1938. },
  1939. "del": {
  1940. name: '删除',
  1941. disabled: function () {
  1942. let node = bills.tree.selected.guidance.tree.items[target.row];
  1943. return locked || !node
  1944. },
  1945. icon: "fa-remove",
  1946. callback: function (key, opt) {
  1947. $('#delAlert').modal('show');
  1948. }
  1949. },
  1950. "insertSibling": {
  1951. name: '插入行',
  1952. disabled: function () {
  1953. let node = bills.tree.selected.guidance.tree.items[target.row];
  1954. return locked || !node || node.data.type !== itemType.job;
  1955. },
  1956. icon: "fa-arrow-left",
  1957. callback: function (key, opt) {
  1958. insert([{ type: itemType.job, name: '' }], false);
  1959. }
  1960. },
  1961. "insertChild": {
  1962. name: '插入子项',
  1963. disabled: function () {
  1964. let node = bills.tree.selected.guidance.tree.items[target.row];
  1965. return locked || !node || node.data.type !== itemType.job || !allJobChildren(node);
  1966. },
  1967. icon: 'fa-arrow-left',
  1968. callback: function (key, opt) {
  1969. insert([{ type: itemType.job, name: '' }], true);
  1970. }
  1971. }
  1972. }
  1973. };
  1974. }
  1975. else {
  1976. return false;
  1977. }
  1978. }
  1979. });
  1980. }
  1981. // 替换定额
  1982. function replaceRation(newRation, orgItem) {
  1983. if (newRation.ID === orgItem.data.rationID) {
  1984. return;
  1985. }
  1986. $.bootstrapLoading.start();
  1987. const updateAttrs = { name: getRationItemName(newRation), rationID: newRation.ID };
  1988. const updateData = [{ updateType: updateType.update, findData: { ID: orgItem.getID() }, updateData: updateAttrs }];
  1989. updateGuideItems(updateData, function () {
  1990. Object.assign(orgItem.data, updateAttrs);
  1991. const row = orgItem.serialNo();
  1992. guideItem.workBook.getSheet(0).setValue(row, 0, orgItem.data.name);
  1993. $.bootstrapLoading.end();
  1994. });
  1995. }
  1996. // 初始化清单右键菜单
  1997. function initRationContextMenu() {
  1998. $.contextMenu({
  1999. selector: '#rationSpread',
  2000. build: function ($triggerElement, e) {
  2001. //控制允许右键菜单在哪个位置出现
  2002. let sheet = ration.workBook.getActiveSheet();;
  2003. let offset = $("#rationSpread").offset(),
  2004. x = e.pageX - offset.left,
  2005. y = e.pageY - offset.top;
  2006. let target = sheet.hitTest(x, y);
  2007. if (target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined') {//在表格内
  2008. let sel = sheet.getSelections()[0];
  2009. if (sel && sel.rowCount === 1) {
  2010. sheet.setActiveCell(target.row, target.col);
  2011. }
  2012. sel = sheet.getSelections()[0];
  2013. if (sel) {
  2014. sel.row = sel.row === -1 ? 0 : sel.row;
  2015. }
  2016. //右键在多选内则不重设焦点
  2017. if (!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)) {
  2018. sheet.setActiveCell(target.row, target.col);
  2019. }
  2020. return {
  2021. callback: function () { },
  2022. items: {
  2023. "replace": {
  2024. name: "替换定额",
  2025. disabled: function () {
  2026. 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;
  2027. },
  2028. icon: "fa-copy",
  2029. callback: function (key, opt) {
  2030. const row = sheet.getActiveRowIndex();
  2031. if (!ration.cache[row]) {
  2032. return;
  2033. }
  2034. replaceRation(ration.cache[row], bills.tree.selected.guidance.tree.selected);
  2035. // copyBlocks(blockNodes);
  2036. }
  2037. },
  2038. }
  2039. };
  2040. }
  2041. else {
  2042. return false;
  2043. }
  2044. }
  2045. });
  2046. }
  2047. // 初始化定额右键菜单
  2048. function initBillsContextMenu() {
  2049. $.contextMenu({
  2050. selector: '#billsSpread',
  2051. build: function ($triggerElement, e) {
  2052. //控制允许右键菜单在哪个位置出现
  2053. let sheet = bills.workBook.getActiveSheet();;
  2054. let offset = $("#billsSpread").offset(),
  2055. x = e.pageX - offset.left,
  2056. y = e.pageY - offset.top;
  2057. let target = sheet.hitTest(x, y);
  2058. if (target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined') {//在表格内
  2059. let sel = sheet.getSelections()[0];
  2060. if (sel && sel.rowCount === 1) {
  2061. sheet.setActiveCell(target.row, target.col);
  2062. }
  2063. sel = sheet.getSelections()[0];
  2064. if (sel) {
  2065. sel.row = sel.row === -1 ? 0 : sel.row;
  2066. }
  2067. //右键在多选内则不重设焦点
  2068. if (!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)) {
  2069. sheet.setActiveCell(target.row, target.col);
  2070. }
  2071. billsInitSel(target.row, { row: bills.tree.selected.serialNo() });
  2072. return {
  2073. callback: function () { },
  2074. items: {
  2075. "replace": {
  2076. name: "配置材料",
  2077. disabled: function () {
  2078. return !bills.tree.selected;
  2079. },
  2080. icon: "fa-edit",
  2081. callback: function (key, opt) {
  2082. $('#bill-material-modal').modal('show');
  2083. }
  2084. },
  2085. }
  2086. };
  2087. }
  2088. else {
  2089. return false;
  2090. }
  2091. }
  2092. });
  2093. }
  2094. //展开至搜索出来点的节点
  2095. //@param {Array}nodes @return {void}
  2096. function expandSearchNodes(sheet, nodes, roots) {
  2097. renderSheetFunc(sheet, function () {
  2098. function expParentNode(node) {
  2099. if (node.parent) {
  2100. if (!node.parent.expanded) {
  2101. node.parent.setExpanded(true);
  2102. }
  2103. expParentNode(node.parent);
  2104. }
  2105. }
  2106. for (let node of nodes) {
  2107. expParentNode(node);
  2108. }
  2109. TREE_SHEET_HELPER.refreshNodesVisible(roots, sheet, true);
  2110. });
  2111. }
  2112. // 清空搜索高亮
  2113. function clearHighLight(sheet) {
  2114. renderSheetFunc(sheet, () => {
  2115. for (let i = 0; i < sheet.getRowCount(); i++) {
  2116. setBgColor(sheet, i, 'white')
  2117. }
  2118. });
  2119. }
  2120. // 清空搜索状态
  2121. // 关闭搜索清单结果
  2122. function closeSearchBills(sheet) {
  2123. if (!bills.tree) {
  2124. return;
  2125. }
  2126. $('#searchBillsResult').hide();
  2127. bills.tree.items.forEach(node => {
  2128. node.isSearch = false;
  2129. });
  2130. clearHighLight(sheet);
  2131. setBgColor(sheet, sheet.getActiveRowIndex(), selectedBgColor);
  2132. }
  2133. // 搜索清单
  2134. function searchBills() {
  2135. if (!bills.tree || !bills.workBook) {
  2136. return;
  2137. }
  2138. const sheet = bills.workBook.getActiveSheet();
  2139. const str = $('#searchBillText').val().trim();
  2140. // 空搜索字符,关闭搜索
  2141. if (!str) {
  2142. if ($('#searchBillsResult').is(':visible')) {
  2143. closeSearchBills(sheet);
  2144. }
  2145. return;
  2146. }
  2147. // 过滤清单
  2148. const result = bills.tree.items.filter(item => {
  2149. const codeIs = item.data.code ? item.data.code.indexOf(str) !== -1 : false;
  2150. const nameIs = item.data.name ? item.data.name.indexOf(str) !== -1 : false;
  2151. return codeIs || nameIs;
  2152. });
  2153. if (!result.length) {
  2154. closeSearchBills(sheet);
  2155. return;
  2156. }
  2157. // 显示搜索结果
  2158. $("#searchBillsResult").show();
  2159. $('#searchBillsCount').text(result.length);
  2160. //展开搜索出来的节点
  2161. expandSearchNodes(sheet, result, bills.tree.roots);
  2162. // 标黄结果
  2163. clearHighLight(sheet);
  2164. const col = sheet.getActiveColumnIndex();
  2165. renderSheetFunc(sheet, function () {
  2166. bills.controller.setTreeSelected(result[0]);
  2167. bills.tree.items.forEach(node => {
  2168. if (result.includes(node)) {
  2169. setBgColor(sheet, node.serialNo(), searchBgColor);
  2170. node.isSearch = true; // 标记为搜索结果,防止被焦点行变更恢复颜色
  2171. } else {
  2172. node.isSearch = false;
  2173. }
  2174. })
  2175. });
  2176. //搜索初始定位
  2177. const row = sheet.getActiveRowIndex();
  2178. sheet.setSelection(result[0].serialNo(), col, 1, 1);
  2179. billsInitSel(result[0].serialNo(), { row });
  2180. sheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  2181. let curIndex = 0;
  2182. // 上一条
  2183. $('#preBill').unbind('click');
  2184. $('#preBill').bind('click', () => {
  2185. const node = result[curIndex - 1];
  2186. if (!node) {
  2187. return;
  2188. }
  2189. curIndex -= 1;
  2190. const col = sheet.getActiveColumnIndex();
  2191. const row = node.serialNo();
  2192. const orgRow = sheet.getActiveRowIndex();
  2193. sheet.setSelection(row, col, 1, 1);
  2194. billsInitSel(row, { row: orgRow });
  2195. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  2196. });
  2197. // 下一条
  2198. $('#nextBills').unbind('click');
  2199. $('#nextBills').bind('click', () => {
  2200. const node = result[curIndex + 1];
  2201. if (!node) {
  2202. return;
  2203. }
  2204. curIndex += 1;
  2205. const col = sheet.getActiveColumnIndex();
  2206. const row = node.serialNo();
  2207. const orgRow = sheet.getActiveRowIndex();
  2208. sheet.setSelection(row, col, 1, 1);
  2209. billsInitSel(row, { row: orgRow });
  2210. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  2211. });
  2212. }
  2213. //初始化dom时间
  2214. //@return {void}
  2215. function initDomEvents() {
  2216. // $('#autoSetMaterialBtn').on("click",()=>{
  2217. // console.log(libID);
  2218. // console.log(bills.cache);
  2219. // const billIDList=[];
  2220. // for(let i=0;i<20;i++){
  2221. // billIDList.push(bills.cache[i].ID);
  2222. // }
  2223. // const rationItems = await billsGuideItemsModel.find({ libID, billsID: { $in: billIDList }, rationID: { $ne: null } }, '-_id rationID billsID').lean();
  2224. // // bills.cache.forEach((item,index)=>{
  2225. // // })
  2226. // const aa= {
  2227. // grid:'std_billsGuidance_materials',
  2228. // libID: 'cf851660-3534-11ec-9641-2da8021b8e4e',
  2229. // billID: '1d2fc566-0a9b-11ea-a33d-5388f9783b09'
  2230. // }
  2231. // })
  2232. // 清单材料窗口
  2233. $("#bill-material-modal").on('hidden.bs.modal', function () {
  2234. billMaterial.cache = [];
  2235. showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
  2236. });
  2237. $("#bill-material-modal").on('shown.bs.modal', function () {
  2238. if (billMaterial.workBook && billMaterialHelper.workBook) {
  2239. billMaterialHelper.workBook.refresh();
  2240. billMaterial.workBook.refresh();
  2241. getBillMaterials();
  2242. }
  2243. });
  2244. /* excel */
  2245. // 生成excel
  2246. $('#buildExcel').click(function () {
  2247. if (bills && bills.tree) {
  2248. $('#excel-modal').modal('show');
  2249. }
  2250. });
  2251. $("#excel-modal").on('hidden.bs.modal', function () {
  2252. $('#excel-info').text(`导出清单中:`);
  2253. $('#excel-spread').hide();
  2254. $('#export-excel-confirm').hide();
  2255. $('#excel-dialog').width('500px');
  2256. if (exportExcelWorkBook) {
  2257. exportExcelWorkBook.clearSheets();
  2258. exportExcelWorkBook.addSheet();
  2259. }
  2260. });
  2261. let excelInstance;
  2262. $("#excel-modal").on('shown.bs.modal', async function () {
  2263. exportExcelWorkBook.refresh();
  2264. if (bills.tree) {
  2265. excelInstance = new ExportExcel(exportExcelWorkBook, bills.tree, libID);
  2266. try {
  2267. await excelInstance.paintOnSheet();
  2268. } catch (error) {
  2269. console.log(error);
  2270. alert(error);
  2271. $("#excel-modal").modal('hide');
  2272. }
  2273. }
  2274. });
  2275. $('#export-excel-confirm').click(() => {
  2276. if (excelInstance) {
  2277. excelInstance.export();
  2278. }
  2279. })
  2280. $('#insert').click(function () {
  2281. insert([{ type: itemType.job, name: '', outputItemCharacter: true }], false);
  2282. });
  2283. $('#delConfirm').click(function () {
  2284. del();
  2285. $('#delAlert').modal('hide');
  2286. });
  2287. $('#delRationConfirm').click(function () {
  2288. delRations();
  2289. $('#delRationAlert').modal('hide');
  2290. });
  2291. $('#del').click(function () {
  2292. $('#delAlert').modal('show');
  2293. });
  2294. $('#upLevel').click(function () {
  2295. upLevel();
  2296. });
  2297. $('#downLevel').click(function () {
  2298. downLevel();
  2299. });
  2300. $('#upMove').click(function () {
  2301. upMove();
  2302. });
  2303. $('#downMove').click(function () {
  2304. downMove();
  2305. });
  2306. // 收起清单至第二层
  2307. $('#expandToSecond').click(function () {
  2308. if (!bills.tree || !bills.workBook) {
  2309. return;
  2310. }
  2311. bills.tree.roots.forEach(root => {
  2312. root.setExpanded(true);
  2313. root.children.forEach(item => {
  2314. item.setExpanded(false);
  2315. });
  2316. });
  2317. const billSheet = bills.workBook.getActiveSheet();
  2318. renderSheetFunc(billSheet, function () {
  2319. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billSheet, true);
  2320. });
  2321. })
  2322. //收起定额、展开全部
  2323. $('#expandContract').click(function () {
  2324. //目前状态时展开全部节点状态,点击则收起定额
  2325. let tree = bills.tree.selected.guidance.tree,
  2326. itemSheet = guideItem.workBook.getActiveSheet();
  2327. if (curExpandState === itemExpandState.expand) {
  2328. curExpandState = itemExpandState.contract;
  2329. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  2330. setNodesExpandState(tree.items, itemExpandState.contract);
  2331. } else {
  2332. curExpandState = itemExpandState.expand;
  2333. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  2334. setNodesExpandState(tree.items, itemExpandState.expand);
  2335. }
  2336. renderSheetFunc(itemSheet, function () {
  2337. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  2338. });
  2339. });
  2340. // 配置材料
  2341. $('#editMaterial').click(function () {
  2342. if (bills && bills.tree && bills.tree.selected) {
  2343. $('#bill-material-modal').modal('show');
  2344. }
  2345. });
  2346. // 插入选中定额
  2347. $('#insertRation').click(function () {
  2348. let checkedRows = getCheckedRationRows();
  2349. let insertDatas = getInsertRations(checkedRows);
  2350. if (insertDatas.length > 0) {
  2351. insert(insertDatas, false, function () {
  2352. //清空选择
  2353. clearCheckedRation(checkedRows);
  2354. });
  2355. }
  2356. else {
  2357. clearCheckedRation(checkedRows);
  2358. }
  2359. });
  2360. // 插入全部定额
  2361. $('#insertAll').click(function () {
  2362. let isAll = true;
  2363. let checkedRows = getCheckedRationRows(isAll);
  2364. let insertDatas = getInsertRations(checkedRows);
  2365. if (insertDatas.length > 0) {
  2366. insert(insertDatas, false);
  2367. }
  2368. });
  2369. // 搜索清单
  2370. $("#searchBillBtn").click(searchBills);
  2371. $('#searchBillText').keyup(function (e) {
  2372. delayKeyup(function () {
  2373. $('#searchBillBtn').click();
  2374. });
  2375. });
  2376. // 关闭搜索清单
  2377. $('#closeSearchBills').click(() => {
  2378. if (!bills.workBook) {
  2379. return;
  2380. }
  2381. const sheet = bills.workBook.getActiveSheet();
  2382. closeSearchBills(sheet);
  2383. })
  2384. //搜索定额
  2385. $('#searchBtn').click(function () {
  2386. let searchStr = $('#searchText').val();
  2387. if (!searchStr || searchStr === '') {
  2388. ration.cache = ration.datas;
  2389. }
  2390. else {
  2391. let reg = new RegExp(searchStr, 'i');
  2392. ration.cache = _.filter(ration.datas, function (data) {
  2393. return reg.test(data.code) || reg.test(data.name);
  2394. });
  2395. }
  2396. $('.top-content').hide();
  2397. $('#deResize').hide();
  2398. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  2399. $('#rationSearchResult').show();
  2400. autoFlashHeight();
  2401. ration.workBook.refresh();
  2402. let rationSheet = ration.workBook.getActiveSheet();
  2403. renderSheetFunc(rationSheet, function () {
  2404. clearCheckedRation(getCheckedRationRows());
  2405. showData(rationSheet, ration.headers, ration.cache);
  2406. })
  2407. });
  2408. //关闭搜索
  2409. $('#rationSearchResult a').click(function () {
  2410. $('.top-content').show();
  2411. $('#deResize').show();
  2412. $('#rationSearchResult').hide();
  2413. autoFlashHeight();
  2414. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  2415. clearCheckedRation(getCheckedRationRows());
  2416. });
  2417. section.workBook.refresh();
  2418. ration.workBook.refresh();
  2419. $('#searchText').val('');
  2420. //恢复章节树下的定额
  2421. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  2422. });
  2423. let keyupTime = 0,
  2424. delayTime = 500;
  2425. function delayKeyup(callback) {
  2426. let nowTime = Date.now();
  2427. keyupTime = nowTime;
  2428. setTimeout(function () {
  2429. if (nowTime - keyupTime == 0) {
  2430. callback();
  2431. }
  2432. }, delayTime);
  2433. }
  2434. //执行搜索
  2435. $('#searchText').keyup(function (e) {
  2436. delayKeyup(function () {
  2437. $('#searchBtn').click();
  2438. });
  2439. });
  2440. //编辑清单备注
  2441. $('.main-side-bottom').find('textarea').keyup(function () {
  2442. let me = this;
  2443. let node = bills.tree.selected;
  2444. let comment = $(me).val();
  2445. delayKeyup(function () {
  2446. if (node) {
  2447. let updateData = { lastOperator: userAccount, billsLibId: billsLibId, updateId: node.getID(), field: 'comment', data: comment };
  2448. updateBillsComment(updateData, function () {
  2449. node.data.comment = comment;
  2450. }, function () {
  2451. $(me).val(node.data.comment || '');
  2452. })
  2453. }
  2454. });
  2455. });
  2456. //编辑选项备注
  2457. $('.main-bottom-content').find('textarea').keyup(function () {
  2458. let me = this;
  2459. let node = bills.tree.selected.guidance.tree.selected;
  2460. let comment = $(me).val();
  2461. delayKeyup(function () {
  2462. if (node) {
  2463. let updateDatas = [{ updateType: updateType.update, findData: { ID: node.getID() }, updateData: { comment: comment } }];
  2464. updateGuideItems(updateDatas, function (rstData) {
  2465. node.data.comment = comment;
  2466. }, function () {
  2467. $(me).val(node.data.comment || '');
  2468. });
  2469. }
  2470. });
  2471. });
  2472. //定额高度拖动调整
  2473. let heightEleObj = {
  2474. module: moduleName,
  2475. resize: $('#deResize'),
  2476. top: $('#topContent'),
  2477. topSpread: $('#sectionSpread'),
  2478. bottom: $('#bottomContent'),
  2479. bottomSpread: $('#rationSpread')
  2480. },
  2481. heightLimit = {
  2482. min: 150,
  2483. max: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-150-10`,
  2484. notTopSpread: 0,
  2485. notBottomSpread: 0,
  2486. };
  2487. SlideResize.verticalSlide(heightEleObj, heightLimit, function () {
  2488. if (section.workBook) {
  2489. section.workBook.refresh();
  2490. }
  2491. if (ration.workBook) {
  2492. ration.workBook.refresh();
  2493. }
  2494. });
  2495. /*slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  2496. //autoFlashHeight();
  2497. if(section.workBook){
  2498. section.workBook.refresh();
  2499. }
  2500. if(ration.workBook){
  2501. ration.workBook.refresh();
  2502. }
  2503. });*/
  2504. //左右拖动
  2505. //清单表与项目指引表
  2506. let leftElesObj = {};
  2507. leftElesObj.module = moduleName;
  2508. leftElesObj.resize = $('#slideResizeLeft');
  2509. leftElesObj.parent = $('#dataRow');
  2510. leftElesObj.left = $('#leftContent');
  2511. leftElesObj.right = $('#midContent');
  2512. SlideResize.horizontalSlide(leftElesObj, { min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200` }, function () {
  2513. refreshALlWorkBook();
  2514. });
  2515. //人材机表与人材机组成物表
  2516. let rightElesObj = {};
  2517. rightElesObj.module = moduleName;
  2518. rightElesObj.resize = $('#slideResizeRight');
  2519. rightElesObj.parent = $('#dataRow');
  2520. rightElesObj.left = $('#midContent');
  2521. rightElesObj.right = $('#rightContent');
  2522. SlideResize.horizontalSlide(rightElesObj, { min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200` }, function () {
  2523. refreshALlWorkBook();
  2524. });
  2525. }
  2526. //刷新全部工作簿
  2527. //@return {void}
  2528. function refreshALlWorkBook() {
  2529. if (bills.workBook) {
  2530. bills.workBook.refresh();
  2531. }
  2532. if (guideItem.workBook) {
  2533. guideItem.workBook.refresh();
  2534. }
  2535. if (section.workBook) {
  2536. section.workBook.refresh();
  2537. }
  2538. if (ration.workBook) {
  2539. ration.workBook.refresh();
  2540. }
  2541. $('.main-side-bottom').find('textarea').height($('.main-side-bottom').height() - 20);
  2542. $('.main-side-bottom').find('textarea').width($('.main-side-bottom').width() - 25);
  2543. $('.main-bottom-content').find('textarea').height($('.main-bottom-content').height() - 20);
  2544. $('.main-bottom-content').find('textarea').width($('.main-bottom-content').width() - 25);
  2545. }
  2546. //读取拖动相关
  2547. //@return {void}
  2548. function initSlideSize() {
  2549. //定额表上下
  2550. let heightEleObj = {
  2551. module: moduleName,
  2552. top: $('#topContent'),
  2553. topSpread: $('#sectionSpread'),
  2554. bottom: $('#bottomContent'),
  2555. bottomSpread: $('#rationSpread')
  2556. };
  2557. if (!$('#rationSearchResult').is(':visible')) {
  2558. SlideResize.loadVerticalHeight(heightEleObj.module, heightEleObj,
  2559. {
  2560. totalHeight: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-10`,
  2561. notTopSpread: 0, notBottomSpread: 0
  2562. }, function () {
  2563. if (section.workBook) {
  2564. section.workBook.refresh();
  2565. }
  2566. if (ration.workBook) {
  2567. ration.workBook.refresh();
  2568. }
  2569. });
  2570. }
  2571. //水平
  2572. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft'), $('#slideResizeRight')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  2573. refreshALlWorkBook();
  2574. });
  2575. }
  2576. //初始化视图
  2577. //@param {void} @return {void}
  2578. function initViews() {
  2579. let modules = [bills, guideItem, section, ration, billMaterial, billMaterialHelper];
  2580. initWorkBooks(modules);
  2581. lockUtil.lockTools($(document.body), locked);
  2582. getLibWithBills(libID);
  2583. initDomEvents();
  2584. initContextMenu();
  2585. initRationContextMenu();
  2586. //initBillsContextMenu();
  2587. initSlideSize();
  2588. }
  2589. // 判断蓝色子项和孙子项是否打勾了必填
  2590. function hasRequireData(node) {
  2591. const requiredList = node.getPosterity().filter(subNode =>
  2592. subNode.data.required === true
  2593. );
  2594. if (requiredList.length) { return true }
  2595. return false;
  2596. }
  2597. // 这里判断有无无定额的情况,有的就返回true,没有就返回false
  2598. function isAllRationData(node) {
  2599. let isRequired = true;
  2600. if (node.children && node.children.length) {
  2601. node.children.forEach(subNode => {
  2602. if (!subNode.children || !subNode.children.length) {
  2603. isRequired = false;
  2604. }
  2605. })
  2606. }
  2607. //这里是兼容第一层直接是定额的白色节点
  2608. if (node.children && node.children.length) {
  2609. node.children.forEach(subNode => {
  2610. if (subNode.data.rationID) {
  2611. isRequired = true;
  2612. }
  2613. })
  2614. }
  2615. return isRequired;
  2616. }
  2617. // 获取选套定额
  2618. function getOptionalData(node, list = []) {
  2619. if (isProcessNode(node)) {
  2620. node.children.forEach(element => {
  2621. if (element.children && element.children.length) {
  2622. element.children.forEach(item => {
  2623. if (item.data.rationID) {
  2624. list.push(item.data.rationID);
  2625. } else if (isProcessNode(item)) {
  2626. getOptionalData(item, list)
  2627. }
  2628. })
  2629. }
  2630. });
  2631. } else {
  2632. node.children.forEach(element => {
  2633. if (element.data.rationID) {
  2634. list.push(element.data.rationID);
  2635. }
  2636. });
  2637. }
  2638. return list;
  2639. }
  2640. // 获取必填项下的ID和name的键值对
  2641. function getClassCodeStrData(nodes,data={classGroups:{},keyGroup:{}}){
  2642. nodes.forEach(node=>{
  2643. if (isProcessNode(node)&&node.data.required) {
  2644. node.children.forEach(subNode=>{
  2645. data.classGroups[subNode.data.ID]=subNode.data.name;
  2646. data.keyGroup[subNode.data.ID]=`${subNode.parent.data.name}:${subNode.data.name}`;
  2647. })
  2648. }
  2649. getClassCodeStrData(node.children,data);
  2650. })
  2651. return data;
  2652. }
  2653. //获取定额数据
  2654. // requireRationData必套定额对象
  2655. // optionalRationData 选逃定额对象
  2656. // classGroups classCode文字和id键值对
  2657. // classCodeList 各个classCode的pID和ID的关系
  2658. function getItemData(nodes, requireRationData = {}, optionalRationData = {}, classGroups = {}, prefixID = '', prefixSonID = '', IDData = {},keyGroup={}) {
  2659. const processNodes = nodes.filter(node => isProcessNode(node));
  2660. // const classGroups = []; // 同层必填选项的数组(二维数组)
  2661. processNodes.forEach(processNode => {
  2662. // 蓝色节点,必填
  2663. if (processNode.data.required) {
  2664. // 白色节点
  2665. const optionNodes = processNode.children.filter(node => isOptionNode(node));
  2666. optionNodes.forEach(optionNode => {
  2667. if (!requireRationData[optionNode.data.ID]) requireRationData[optionNode.data.ID] = [];
  2668. if (!optionalRationData[optionNode.data.ID]) optionalRationData[optionNode.data.ID] = [];
  2669. //白色节点下没有蓝色节点,就是到底了
  2670. if (!optionNode.children.some(subOptionNode => isProcessNode(subOptionNode))) {
  2671. // 是否必套定额
  2672. if (isAllRationData(optionNode)) {
  2673. optionNode.children.forEach(subOptionNode => {
  2674. requireRationData[optionNode.data.ID].push([subOptionNode.data.rationID]);
  2675. })
  2676. } else {
  2677. optionalRationData[optionNode.data.ID] = getOptionalData(optionNode);
  2678. }
  2679. const kV = {};
  2680. kV[optionNode.data.ID] = optionNode.data.name;
  2681. Object.assign(classGroups, kV);
  2682. const keyData={};
  2683. keyData[optionNode.data.ID] = `${optionNode.parent.data.name}:${optionNode.data.name}`;
  2684. Object.assign(keyGroup,keyData);
  2685. } else {
  2686. const kV = {};
  2687. kV[optionNode.data.ID] = optionNode.data.name;
  2688. Object.assign(classGroups, kV);
  2689. const keyData={};
  2690. keyData[optionNode.data.ID] = `${optionNode.parent.data.name}:${optionNode.data.name}`;
  2691. Object.assign(keyGroup,keyData);
  2692. // 后代项是否有必填
  2693. if (hasRequireData(optionNode)) {
  2694. //后代项有必填
  2695. prefixSonID = '';
  2696. getItemData(optionNode.children, requireRationData, optionalRationData, classGroups, optionNode.data.ID, prefixSonID, IDData,keyGroup);
  2697. } else {
  2698. //后代项无必填
  2699. optionNode.children.forEach(subOptionNode => {
  2700. // 是否必套定额
  2701. if (isAllRationData(optionNode)) {
  2702. if (!requireRationData[subOptionNode.parent.data.ID]) requireRationData[subOptionNode.parent.data.ID] = [];
  2703. requireRationData[subOptionNode.parent.data.ID].push(getOptionalData(subOptionNode));
  2704. } else {
  2705. if (!optionalRationData[subOptionNode.parent.data.ID]) optionalRationData[subOptionNode.parent.data.ID] = [];
  2706. optionalRationData[subOptionNode.parent.data.ID].push(...getOptionalData(subOptionNode));
  2707. }
  2708. })
  2709. }
  2710. }
  2711. })
  2712. } else {
  2713. // 蓝色节点,非必填
  2714. if (hasRequireData(processNode)) {
  2715. //后代项有必填
  2716. if (isProcessNode(processNode)) {
  2717. //蓝色
  2718. // 是否必套定额
  2719. if (isAllRationData(processNode)) {
  2720. processNode.children.forEach((subProcessNode) => {
  2721. subProcessNode.children.forEach((sSubProcessNode) => {
  2722. //这里是特殊处理,因为原来的逻辑是直接把定额绑到必填白色选项中下面的,每个蓝色的一组,但是这样是不对的,需要绑定在必填白色选项下的蓝色节点,所以这里就需要传入蓝色节点的id
  2723. const requireChildrenID = sSubProcessNode.parent.data.required ? prefixSonID : sSubProcessNode.data.ID;
  2724. IDData[sSubProcessNode.data.ID] = prefixID;
  2725. getItemData(
  2726. [sSubProcessNode],
  2727. requireRationData,
  2728. optionalRationData,
  2729. classGroups,
  2730. prefixID,
  2731. requireChildrenID,
  2732. IDData,
  2733. keyGroup
  2734. )
  2735. })
  2736. })
  2737. }else{
  2738. // 全部选套就不用走循环了,直接按照选套执行
  2739. let key = processNode.data.ID;
  2740. if (prefixID) key = prefixID;
  2741. if (prefixSonID) key = prefixSonID;
  2742. if (!optionalRationData[key]) optionalRationData[key] = [];
  2743. optionalRationData[key].push(...getOptionalData(processNode));
  2744. // 因为这里没有按照走整个流程,所以文字和ID的关系需要获取补充
  2745. if(hasRequireData(processNode)) {
  2746. const result =getClassCodeStrData(processNode.children)
  2747. Object.assign(classGroups,result.classGroups);
  2748. Object.assign(keyGroup,result.keyGroup);
  2749. } ;
  2750. }
  2751. }
  2752. } else {
  2753. let key = processNode.data.ID;
  2754. if (prefixID) key = prefixID;
  2755. if (prefixSonID) key = prefixSonID;
  2756. // 是否必套定额
  2757. if (isAllRationData(processNode)) {
  2758. if (!requireRationData[key]) requireRationData[key] = [];
  2759. requireRationData[key].push(getOptionalData(processNode));
  2760. } else {
  2761. if (!optionalRationData[key]) optionalRationData[key] = [];
  2762. optionalRationData[key].push(...getOptionalData(processNode));
  2763. }
  2764. }
  2765. }
  2766. })
  2767. return { requireRationData, optionalRationData, classGroups, IDData, keyGroup }
  2768. }
  2769. /* 生成特征分类: 前端测试使用,想要前端测试,需要在zhiyin.html中,将id=generate-classa的按钮放开 */
  2770. function getItemCharacterData(nodes, prefix, prefixID) {
  2771. const processNodes = nodes.filter(node => isProcessNode(node));
  2772. const classGroups = []; // 同层必填选项的数组(二维数组)
  2773. processNodes.forEach(processNode => {
  2774. const classItems = [];
  2775. const optionNodes = processNode.children.filter(node => isOptionNode(node));
  2776. optionNodes.forEach(optionNode => {
  2777. // const name = prefix ? `${prefix}@${optionNode.data.name}` : optionNode.data.name;
  2778. if (optionNode.parent && optionNode.parent.data.required && (!optionNode.children
  2779. || !optionNode.children.length
  2780. || (optionNode.children[0].data && optionNode.children[0].data.rationID)
  2781. || !optionNode.children.some(node => isProcessNode(node)))) {
  2782. // 必套定额
  2783. classItems.push({ name: optionNode.data.name, ID: optionNode.data.ID });
  2784. } else {
  2785. // classItems.push(...getItemCharacterData(optionNode.children, optionNode.parent && optionNode.parent.data.required ? optionNode.data.name : ''));
  2786. const childrenClassItem = getItemCharacterData(
  2787. optionNode.children,
  2788. optionNode.parent && optionNode.parent.data.required ? optionNode.data.name : '',
  2789. optionNode.parent && optionNode.parent.data.required ? optionNode.data.ID : ''
  2790. );
  2791. //如果返回的子项为空,但是父项又勾选了必填,则要把本身存入数组
  2792. if (optionNode.parent
  2793. && optionNode.parent.data.required
  2794. && childrenClassItem.length === 0
  2795. ) {
  2796. classItems.push({ name: optionNode.data.name, ID: optionNode.data.ID });
  2797. } else {
  2798. classItems.push(...childrenClassItem);
  2799. }
  2800. }
  2801. });
  2802. if (classItems.length) {
  2803. classGroups.push(classItems);
  2804. }
  2805. });
  2806. // 拼接上一文本
  2807. if (classGroups[0] && classGroups[0].length) {
  2808. // classGroups[0] = classGroups[0].map(name => prefix ? `${prefix}@${name}` : name);
  2809. classGroups[0] = classGroups[0].map(item => {
  2810. item.name = prefix ? `${prefix}@${item.name}` : item.name
  2811. item.ID = prefixID ? `${prefixID}@${item.ID}` : item.ID
  2812. return item;
  2813. });
  2814. }
  2815. // 二维数组内容排列组合
  2816. while (classGroups.length > 1) {
  2817. const prevClassItems = classGroups[0];
  2818. const nextClassItems = classGroups[1];
  2819. const mergedClassItems = [];
  2820. for (let i = 0; i < prevClassItems.length; i++) {
  2821. for (let j = 0; j < nextClassItems.length; j++) {
  2822. // 拼接文本
  2823. const mergedName = `${prevClassItems[i].name}@${nextClassItems[j].name}`;
  2824. const mergedID = `${prevClassItems[i].ID}@${nextClassItems[j].ID}`;
  2825. mergedClassItems.push({ name: mergedName, ID: mergedID });
  2826. }
  2827. }
  2828. classGroups.splice(0, 2, mergedClassItems);
  2829. }
  2830. // 去重(类别别名要唯一)
  2831. const items = classGroups[0] || [];
  2832. const nameMap = {};
  2833. const rst = [];
  2834. items.forEach(item => {
  2835. if (!nameMap[item.name]) {
  2836. rst.push(item);
  2837. }
  2838. nameMap[item.name] = true;
  2839. });
  2840. return rst;
  2841. }
  2842. // 获取选套定额:把所有分类数据的必套定额确定好了先。选套定额就是清单下所有定额除了必套的
  2843. function getOptionalRationIDs(optionalRationData) {
  2844. const optionalRationIDs = [];
  2845. Object.values(optionalRationData).forEach(optionalRation => {
  2846. if (optionalRation.length) optionalRationIDs.push(...optionalRation);
  2847. })
  2848. return [...new Set(optionalRationIDs)];
  2849. }
  2850. // 获取错套定额:清单下所有定额,除了分类对应的必套、选套定额
  2851. function getErrorRationIDs(requiredRationIDList, optionalRationIDs, guideNodes) {
  2852. const finRequireData = [];
  2853. requiredRationIDList.forEach(requiredRationIDs => {
  2854. finRequireData.push(...requiredRationIDs);
  2855. })
  2856. const errorRationIDs = [];
  2857. guideNodes.forEach(node => {
  2858. if (node.data.rationID && !finRequireData.includes(node.data.rationID) && !optionalRationIDs.includes(node.data.rationID)) {
  2859. errorRationIDs.push(node.data.rationID);
  2860. }
  2861. });
  2862. return [...new Set(errorRationIDs)];
  2863. }
  2864. //把classcode和必套选套定额结合在一起
  2865. function combineData(codeData, requireRationData, optionalRationData, classGroups, IDData,keyGroup) {
  2866. // 这里要记录下已经被绑定的选套定额,因为没有被用的定额需要绑定到各个classcode下
  2867. const matchRationList = [];
  2868. //这里需要把绑定在子节点的定额更新到必填的白色选项中(classcode的值)
  2869. const requireCombineData = {};
  2870. const optionCombineData = {};
  2871. Object.keys(IDData).forEach(key => {
  2872. if (!requireCombineData[IDData[key]]) requireCombineData[IDData[key]] = new Set();
  2873. if (!optionCombineData[IDData[key]]) optionCombineData[IDData[key]] = new Set();
  2874. if (requireRationData[key]) {
  2875. requireRationData[key].forEach(subData => {
  2876. subData.forEach(subItem => {
  2877. requireCombineData[IDData[key]].add(subItem);
  2878. })
  2879. })
  2880. }
  2881. if (optionalRationData[key]) {
  2882. optionalRationData[key].forEach(subData => {
  2883. optionCombineData[IDData[key]].add(subData);
  2884. })
  2885. }
  2886. })
  2887. const finData = codeData.map(classCodeData => {
  2888. const errorRationIDs = [];
  2889. const optionalRationIDs = [];
  2890. const requiredRationIDs = [];
  2891. let name = '';
  2892. let key = '';
  2893. const classCodeIDs = classCodeData.ID;
  2894. if (/@/.test(classCodeIDs)) {
  2895. classCodeIDs.split('@').forEach((classCodeID) => {
  2896. if (name) {
  2897. name = name + '@' + classGroups[classCodeID];
  2898. key += keyGroup[classCodeID];
  2899. } else {
  2900. name = classGroups[classCodeID];
  2901. key = keyGroup[classCodeID];
  2902. };
  2903. // 一组的必套定额,先去重
  2904. const unitRation = [];
  2905. // 这里是必填选项下绑定必套定额
  2906. if (requireRationData[classCodeID] && requireRationData[classCodeID].length) {
  2907. requireRationData[classCodeID].forEach(subItem => {
  2908. unitRation.push(...new Set(subItem));
  2909. })
  2910. requiredRationIDs.push(unitRation);
  2911. // 这里也要把用过的必套定额先存起来
  2912. matchRationList.push(...unitRation);
  2913. }
  2914. //这里是必填选项下绑定在蓝色节点下的必套定额
  2915. if (requireCombineData[classCodeID] && requireCombineData[classCodeID].size) {
  2916. requiredRationIDs.push([...requireCombineData[classCodeID]]);
  2917. // 这里也要把用过的必套定额先存起来
  2918. matchRationList.push(...requireCombineData[classCodeID]);
  2919. }
  2920. // 这里是必填选项下绑定选套定额
  2921. if (optionalRationData[classCodeID] && optionalRationData[classCodeID].length) {
  2922. optionalRationIDs.push(...optionalRationData[classCodeID]);
  2923. matchRationList.push(...optionalRationData[classCodeID]);
  2924. }
  2925. //这里是必填选项下绑定在蓝色节点下的选套定额,下同
  2926. if (optionCombineData[classCodeID] && optionCombineData[classCodeID].size) {
  2927. optionalRationIDs.push(...optionCombineData[classCodeID]);
  2928. matchRationList.push(...optionCombineData[classCodeID]);
  2929. }
  2930. })
  2931. return { name,key, requiredRationIDs, optionalRationIDs: [...new Set(optionalRationIDs)], errorRationIDs }
  2932. } else {
  2933. const unitRation = [];
  2934. name = classGroups[classCodeIDs];
  2935. key = keyGroup[classCodeIDs];
  2936. if (requireRationData[classCodeIDs] && requireRationData[classCodeIDs].length){
  2937. requireRationData[classCodeIDs].forEach(subItem => {
  2938. unitRation.push(...new Set(subItem));
  2939. })
  2940. requiredRationIDs.push(unitRation);
  2941. // 这里也要把用过的必套定额先存起来
  2942. matchRationList.push(...unitRation);
  2943. }
  2944. if (requireCombineData[classCodeIDs] && requireCombineData[classCodeIDs].size) {
  2945. requiredRationIDs.push([...requireCombineData[classCodeIDs]])
  2946. // 这里也要把用过的必套定额先存起来
  2947. matchRationList.push(...requireCombineData[classCodeIDs]);
  2948. };
  2949. if (optionalRationData[classCodeIDs] && optionalRationData[classCodeIDs].length) {
  2950. optionalRationIDs.push(...optionalRationData[classCodeIDs]);
  2951. matchRationList.push(...optionalRationData[classCodeIDs]);
  2952. }
  2953. if (optionCombineData[classCodeIDs] && optionCombineData[classCodeIDs].size) {
  2954. optionalRationIDs.push(...optionCombineData[classCodeIDs]);
  2955. matchRationList.push(...optionalRationData[classCodeIDs]);
  2956. }
  2957. return { name,key, requiredRationIDs, optionalRationIDs: [...new Set(optionalRationIDs)], errorRationIDs }
  2958. }
  2959. })
  2960. const unMatchRation = [];
  2961. Object.values(optionalRationData).forEach(data => {
  2962. data.forEach((rationID) => {
  2963. if (!matchRationList.includes(rationID)) {
  2964. unMatchRation.push(rationID);
  2965. }
  2966. })
  2967. })
  2968. // 这里把没有使用过的必套定额也丢到了选套里面
  2969. Object.values(requireRationData).forEach(data => {
  2970. data.forEach((rationData) => {
  2971. rationData.forEach(rationID=>{
  2972. if (!matchRationList.includes(rationID)) {
  2973. unMatchRation.push(rationID);
  2974. }
  2975. })
  2976. })
  2977. })
  2978. return { classData: finData, unMatchRation };
  2979. }
  2980. $('#generate-class').click(() => {
  2981. if (bills.tree.selected && bills.tree.selected.guidance.tree) {
  2982. const classCodeData = getItemCharacterData(bills.tree.selected.guidance.tree.roots);
  2983. const { requireRationData, optionalRationData, classGroups, IDData, keyGroup } = getItemData(bills.tree.selected.guidance.tree.roots);
  2984. // const noMatchOptionRation=[];
  2985. const { classData, unMatchRation } = combineData(classCodeData, requireRationData, optionalRationData, classGroups, IDData,keyGroup);
  2986. //因为所有的选套都是一样的,所以这里就直接赋值了
  2987. const optionalRationIDs = getOptionalRationIDs(optionalRationData);
  2988. classData.forEach(item => {
  2989. // 不在必填项下的选套都要绑定在每个classcode下
  2990. item.optionalRationIDs.push(...unMatchRation);
  2991. item.errorRationIDs = getErrorRationIDs(item.requiredRationIDs, item.optionalRationIDs, bills.tree.selected.guidance.tree.items);
  2992. })
  2993. console.log(optionalRationIDs);
  2994. console.log(classData);
  2995. }
  2996. });
  2997. return { initViews, initSlideSize };
  2998. })();
  2999. $(document).ready(function () {
  3000. billsGuidance.initViews();
  3001. });