billsGuidance.js 129 KB

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