change_revise.js 197 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  15. posXmj: ['code'],
  16. };
  17. function getExprInfo (field, converse = false) {
  18. const exprField = [
  19. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  20. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  21. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  22. ];
  23. return converse ? _.find(exprField, {expr: field}) : _.find(exprField, {qty: field});
  24. }
  25. function transExpr(expr) {
  26. return $.trim(expr).replace('\t', '').replace('=', '').replace(new RegExp('%', 'gm'), '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. const dskCompilation = 'zh.calc.dskCompilation';
  30. const checkOption = {
  31. sibling: { enable: 1 },
  32. empty_code: { enable: 1 },
  33. calc: {
  34. enable: 1,
  35. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  36. },
  37. zero: { enable: 1 },
  38. zeroPos: { enable: 1 },
  39. tp: {
  40. enable: 1,
  41. fields: [
  42. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  43. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  44. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  45. {qty: 'quantity', tp: 'total_price'},
  46. {qty: 'deal_qty', tp: 'deal_tp'},
  47. ],
  48. },
  49. same_code: { enable: 1 },
  50. same_bills: { enable: 1 },
  51. };
  52. $(document).ready(() => {
  53. let stdXmj, stdGcl, searchLedger;
  54. autoFlashHeight();
  55. billsSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', });
  56. if (!billsSpreadSetting.readOnly) {
  57. for (const col of billsSpreadSetting.cols) {
  58. if (!col.readOnly || col.readOnly === false)
  59. col.readOnly = 'readOnly.isChangeAdd';
  60. }
  61. }
  62. posSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', getValue: 'getValue.isChange' });
  63. if (!posSpreadSetting.readOnly) {
  64. for (const col of posSpreadSetting.cols) {
  65. if (!col.readOnly || col.readOnly === false)
  66. col.readOnly = 'readOnly.isChangeAdd';
  67. }
  68. }
  69. const billsCol = {
  70. readOnly: {
  71. isChangeAdd: function (data) {
  72. return !readOnly && !data.formc;
  73. },
  74. isChangeList: function (data) {
  75. if (!data) return true;
  76. let edit = !readOnly && !(data.is_leaf && data.b_code);
  77. if (!edit && data.id) {
  78. const lPos = pos.getLedgerPos(data.id);
  79. if (lPos && lPos.length > 0) {
  80. edit = true;
  81. }
  82. }
  83. return edit;
  84. }
  85. }
  86. };
  87. const posCol = {
  88. getValue: {
  89. isChange: function (data) {
  90. if (!data) return 0;
  91. if (!data.name) return 0;
  92. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  93. return cInfo ? 1 : 0;
  94. }
  95. },
  96. readOnly: {
  97. isChangeAdd: function (data) {
  98. return !readOnly && !data.formc && (data.settle_status && data.settle_status === settleStatus.finish);
  99. },
  100. isChangeList: function (data) {
  101. if (!data) return true;
  102. // console.log(data.name);
  103. return !readOnly && !data.name;
  104. }
  105. }
  106. };
  107. // 判断是否是已结算清单
  108. function checkIsSettle(data) {
  109. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  110. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  111. return true;
  112. }
  113. return false;
  114. }
  115. // 初始化spread
  116. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  117. const billsSheet = billsSpread.getActiveSheet();
  118. billsSpreadSetting.rowHeader = [
  119. {
  120. rowHeaderType: 'circle',
  121. setting: {
  122. size: 5,
  123. indent: 16,
  124. getColor: function (index, data) {
  125. if (!data) return;
  126. if(!data.formc && !data.cid) return;
  127. return '#dc3545';
  128. }
  129. },
  130. },
  131. ];
  132. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  133. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  134. return spreadColor.stage.settle;
  135. }
  136. if (data && data.is_change) {
  137. return '#c3e6cb';
  138. }
  139. return defaultColor;
  140. };
  141. billsSpreadSetting.localCache = {
  142. key: 'changes-ledger-spread',
  143. colWidth: true,
  144. };
  145. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  146. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  147. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  148. SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
  149. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  150. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  151. const posSheet = posSpread.getActiveSheet();
  152. posSpreadSetting.rowHeader = [
  153. {
  154. rowHeaderType: 'circle',
  155. setting: {
  156. size: 5,
  157. indent: 16,
  158. getColor: function (index, data) {
  159. if (!data) return;
  160. if(!data.formc) return;
  161. return '#dc3545';
  162. }
  163. },
  164. },
  165. ];
  166. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  167. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  168. return spreadColor.stage.settle;
  169. }
  170. return defaultColor;
  171. };
  172. posSpreadSetting.localCache = {
  173. key: 'changes-pos-spread',
  174. colWidth: true,
  175. };
  176. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  177. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  178. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  179. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  180. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  181. const errorList = $.cs_errorList({
  182. tabSelector: '#error-list-tab',
  183. selector: '#error-list',
  184. relaSpread: billsSpread,
  185. storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
  186. afterLocated: function () {
  187. posSpreadObj.loadCurPosData();
  188. },
  189. afterShow: function () {
  190. billsSpread.refresh();
  191. if (posSpread) posSpread.refresh();
  192. },
  193. });
  194. const checkList = $.ledger_checkList({
  195. id: 'check-list',
  196. tabSelector: '#check-list-tab',
  197. selector: '#check-list',
  198. relaSpread: billsSpread,
  199. storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
  200. checkType: getCheckType(checkOption),
  201. afterLocated: function () {
  202. posSpreadObj.loadCurPosData();
  203. },
  204. afterShow: function () {
  205. billsSpread.refresh();
  206. if (posSpread) posSpread.refresh();
  207. },
  208. });
  209. const sumLoadMiss = $.sumLoadMiss({
  210. tabSelector: '#sum-load-miss-tab',
  211. selector: '#sum-load-miss',
  212. relaSpread: billsSpread,
  213. storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
  214. id: 'revise-slm',
  215. afterLocated: function () {
  216. posSpreadObj.loadCurPosData();
  217. },
  218. afterShow: function () {
  219. billsSpread.refresh();
  220. if (posSpread) posSpread.refresh();
  221. },
  222. });
  223. // 初始化 节点树结构
  224. const treeSetting = {
  225. id: 'ledger_id',
  226. pid: 'ledger_pid',
  227. order: 'order',
  228. level: 'level',
  229. rootId: -1,
  230. keys: ['id', 'tender_id', 'ledger_id'],
  231. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  232. autoExpand: 3,
  233. markExpandKey: 'change-bills-expand',
  234. markExpandSubKey: window.location.pathname.split('/')[2],
  235. };
  236. if (!isTz) {
  237. treeSetting.calcFields.push('deal_tp');
  238. }
  239. treeSetting.calcFun = function (node) {
  240. if (node && node.b_code && isTz) {
  241. const posData = pos.getLedgerPos(node.id) || [];
  242. if (posData.length > 0) {
  243. let sgfh_qty = 0;
  244. let sjcl_qty = 0;
  245. let qtcl_qty = 0;
  246. for (const np of posData) {
  247. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  248. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  249. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  250. }
  251. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  252. node.sgfh_qty = sgfh_qty;
  253. node.sjcl_qty = sjcl_qty;
  254. node.qtcl_qty = qtcl_qty;
  255. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  256. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  257. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  258. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  259. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  260. }
  261. }
  262. }
  263. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  264. };
  265. const billsTree = createNewPathTree('revise', treeSetting);
  266. // 初始化 计量单元
  267. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  268. // 清单 相关方法&绑定spreadjs事件
  269. const billsTreeSpreadObj = {
  270. loadExprToInput(sheet) {
  271. const sel = sheet.getSelections()[0];
  272. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  273. if (col && col.type === 'Number') {
  274. const data = SpreadJsObj.getSelectObject(sheet);
  275. if (data) {
  276. const exprInfo = getExprInfo(col.field);
  277. if (exprInfo) {
  278. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  279. .attr('field', col.field).attr('org', data[col.field]);
  280. } else {
  281. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  282. }
  283. if (col.field.indexOf('dgn') >= 0) {
  284. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
  285. } else if (col.field === 'unit_price') {
  286. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
  287. } else {
  288. const nodePos = pos.getLedgerPos(data.id);
  289. if (nodePos && nodePos.length > 0) {
  290. $('#bills-expr').val('').attr('readOnly', true);
  291. $('#bills-expr').removeAttr('data-row');
  292. } else {
  293. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
  294. }
  295. }
  296. $('#bills-expr').attr('data-row', sel.row);
  297. } else {
  298. $('#bills-expr').val('').attr('readOnly', true);
  299. $('#bills-expr').removeAttr('data-row');
  300. }
  301. } else {
  302. $('#bills-expr').val('').attr('readOnly', true);
  303. $('#bills-expr').removeAttr('data-row');
  304. }
  305. },
  306. getDefaultSelectInfo: function (sheet) {
  307. const tree = sheet.zh_tree;
  308. if (!tree) return;
  309. const sel = sheet.getSelections()[0];
  310. const node = sheet.zh_tree.nodes[sel.row];
  311. if (!node) return;
  312. let count = 1;
  313. if (sel.rowCount > 1) {
  314. for (let r = 1; r < sel.rowCount; r++) {
  315. const rNode = sheet.zh_tree.nodes[sel.row + r];
  316. if (rNode.level > node.level) continue;
  317. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  318. toastr.warning('请选择同一节点下的节点,进行该操作');
  319. return;
  320. }
  321. count += 1;
  322. }
  323. }
  324. return [tree, node, count];
  325. },
  326. /**
  327. * 刷新顶部按钮是否可用
  328. * @param sheet
  329. * @param selections
  330. */
  331. refreshOperationValid: function (sheet, selection) {
  332. const setObjEnable = function (obj, enable) {
  333. if (enable) {
  334. obj.removeClass('disabled');
  335. } else {
  336. obj.addClass('disabled');
  337. }
  338. };
  339. const invalidAll = function () {
  340. setObjEnable($('a[name=base-opr][type=add]'), false);
  341. setObjEnable($('a[name=base-opr][type=delete]'), false);
  342. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  343. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  344. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  345. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  346. };
  347. const sel = selection ? selection[0] : sheet.getSelections()[0];
  348. const row = sel ? sel.row : -1;
  349. const tree = sheet.zh_tree;
  350. if (!tree) {
  351. invalidAll();
  352. return;
  353. }
  354. const first = sheet.zh_tree.nodes[row];
  355. if (!first) {
  356. invalidAll();
  357. return;
  358. }
  359. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  360. if (sel.rowCount > 1 && first) {
  361. for (let r = 1; r < sel.rowCount; r++) {
  362. const rNode = tree.nodes[sel.row + r];
  363. if (!rNode) {
  364. sameParent = false;
  365. break;
  366. }
  367. if (!rNode.formc) {
  368. sameParent = false;
  369. break;
  370. }
  371. nodeUsed = nodeUsed || rNode.used;
  372. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  373. if (rNode.level > first.level) continue;
  374. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  375. sameParent = false;
  376. break;
  377. }
  378. last = rNode;
  379. }
  380. }
  381. const preNode = tree.getPreSiblingNode(first);
  382. const siblings = tree.getChildren(tree.getParent(first));
  383. let upPower = true;
  384. for (let order = last.order; order < siblings.length - 1; order ++) {
  385. if (!siblings[order].formc) {
  386. upPower = false;
  387. break;
  388. }
  389. }
  390. const valid = !sheet.zh_setting.readOnly;
  391. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  392. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
  393. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
  394. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
  395. const posRange = last ? pos.getLedgerPos(last.id) : [];
  396. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  397. && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
  398. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  399. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  400. && first.level > 1 && preNode && (preNode.children.length > 0 || (preNode.children.length === 0 && preNode.formc && (!preNodePosRange || preNodePosRange.length === 0))) && !preNode.used && first.formc && preNode.settle_status !== settleStatus.finish);
  401. setObjEnable($('#cut'), valid);
  402. setObjEnable($('#paste'), valid);
  403. },
  404. /**
  405. *
  406. * @param sheet
  407. * @param data
  408. */
  409. refreshTree: function (sheet, data) {
  410. SpreadJsObj.massOperationSheet(sheet, function () {
  411. const tree = sheet.zh_tree;
  412. // 处理删除
  413. if (data.delete) {
  414. data.delete.sort(function (a, b) {
  415. return b.deleteIndex - a.deleteIndex;
  416. });
  417. for (const d of data.delete) {
  418. sheet.deleteRows(d.deleteIndex, 1);
  419. }
  420. }
  421. // 处理新增
  422. if (data.create) {
  423. const newNodes = data.create;
  424. if (newNodes) {
  425. newNodes.sort(function (a, b) {
  426. return a.index - b.index;
  427. });
  428. for (const node of newNodes) {
  429. sheet.addRows(node.index, 1);
  430. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  431. }
  432. }
  433. }
  434. // 处理更新
  435. if (data.update) {
  436. const rows = [];
  437. for (const u of data.update) {
  438. rows.push(tree.nodes.indexOf(u));
  439. }
  440. SpreadJsObj.reLoadRowsData(sheet, rows);
  441. }
  442. // 处理展开
  443. if (data.expand) {
  444. const expanded = [];
  445. for (const e of data.expand) {
  446. if (expanded.indexOf(e) === -1) {
  447. const posterity = tree.getPosterity(e);
  448. for (const p of posterity) {
  449. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  450. expanded.push(p);
  451. }
  452. }
  453. }
  454. }
  455. });
  456. },
  457. selectionChanged: function (e, info) {
  458. if (info.newSelections) {
  459. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  460. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  461. billsTreeSpreadObj.refreshPosData();
  462. }
  463. }
  464. billsTreeSpreadObj.loadExprToInput(info.sheet);
  465. },
  466. refreshPosData: function() {
  467. SpreadJsObj.resetTopAndSelect(posSheet);
  468. posSpreadObj.loadCurPosData();
  469. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  470. posSearch.search($('#pos-keyword').val());
  471. },
  472. /**
  473. * 新增节点
  474. * @param spread
  475. */
  476. baseOpr: function (sheet, type, addCount = 1) {
  477. const self = this;
  478. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  479. if (!tree || !node || !count) return;
  480. if (type === 'delete') {
  481. const parent = tree.getParent(node);
  482. const children = parent ? parent.children : tree.children;
  483. const index = children.indexOf(node);
  484. for (let i = 0; i < count; i++) {
  485. const child = children[i+index];
  486. if (tree.checkNodeUsed(child, pos)) {
  487. toastr.warning('选中的节点已计量,不可删除');
  488. return;
  489. }
  490. if (child.settle_status === settleStatus.finish) {
  491. toastr.warning('选中的节点已结算,不可删除');
  492. return;
  493. }
  494. }
  495. } else if (type === 'up-level') {
  496. const parent = tree.getParent(node);
  497. const children = parent ? parent.children : tree.children;
  498. const index = children.indexOf(node);
  499. const lastSelect = children[index + count - 1];
  500. if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  501. toastr.warning('选中的节点已计量,不可升级');
  502. return;
  503. }
  504. if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
  505. toastr.warning('选中的节点已结算,不可升级');
  506. return;
  507. }
  508. // for (let i = index; i < children.length; i++) {
  509. // const child = children[index];
  510. // if (tree.checkNodeUsed(child, pos)) {
  511. // if (i >= index + count) {
  512. // toastr.warning('其后节点已计量,选中的节点不可升级');
  513. // } else {
  514. // toastr.warning('选中的节点已计量,不可升级');
  515. // }
  516. // return;
  517. // }
  518. // }
  519. } else if (type === 'down-level') {
  520. const parent = tree.getParent(node);
  521. const children = parent ? parent.children : tree.children;
  522. const index = children.indexOf(node);
  523. if (index > 0 && children[index-1].used) {
  524. toastr.warning('其前节点已计量,选中的节点不可降级');
  525. return;
  526. }
  527. if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
  528. toastr.warning('其前节点已结算,选中的节点不可降级');
  529. return;
  530. }
  531. for (let i = index; i < count; i++) {
  532. const child = children[i+index];
  533. if (tree.checkNodeUsed(child, pos)) {
  534. toastr.warning('选中的节点已计量,不可降级');
  535. return;
  536. }
  537. if (tree.settle_status === settleStatus.finish) {
  538. toastr.warning('选中的节点已结算,不可降级');
  539. return;
  540. }
  541. }
  542. } else if (type === 'add') {
  543. if (node.settle_status === settleStatus.finish) {
  544. toastr.warning('选中的节点已结算,不可新增子项');
  545. return;
  546. }
  547. }
  548. if (type === 'delete') {
  549. deleteAfterHint(function () {
  550. postData(window.location.pathname + '/update', {
  551. postType: type,
  552. postData: {
  553. id: node.ledger_id,
  554. count: type === 'add' ? addCount : count,
  555. }
  556. }, function (result) {
  557. changeList = result.changeList;
  558. const refreshData = tree.loadPostData(result);
  559. self.refreshTree(sheet, refreshData);
  560. const sel = sheet.getSelections()[0];
  561. if (sel) {
  562. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  563. billsTreeSpreadObj.refreshPosData();
  564. }
  565. self.refreshOperationValid(sheet);
  566. });
  567. });
  568. } else {
  569. postData(window.location.pathname + '/update', {
  570. postType: type,
  571. postData: {
  572. id: node.ledger_id,
  573. count: type === 'add' ? addCount : count,
  574. }
  575. }, function (result) {
  576. changeList = result.changeList;
  577. const refreshData = tree.loadPostData(result);
  578. self.refreshTree(sheet, refreshData);
  579. if (['up-move', 'down-move'].indexOf(type) > -1) {
  580. const sel = sheet.getSelections()[0];
  581. if (sel) {
  582. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  583. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  584. }
  585. } else if (type === 'add') {
  586. const sel = sheet.getSelections()[0];
  587. if (sel) {
  588. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  589. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  590. billsTreeSpreadObj.refreshPosData();
  591. }
  592. }
  593. self.refreshOperationValid(sheet);
  594. });
  595. }
  596. },
  597. buttonClicked: function (e, info, v) {
  598. if (info.sheet.zh_setting) {
  599. const select = SpreadJsObj.getSelectObject(info.sheet);
  600. const col = info.sheet.zh_setting.cols[info.col];
  601. if (col.field === 'is_change') {
  602. if (billsCol.readOnly.isChangeList(select)) {
  603. return
  604. }
  605. if (info.sheet.isEditing()) {
  606. info.sheet.endEdit(true);
  607. }
  608. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  609. if (is_change) {
  610. makeGclGatherData();
  611. const gclInfo = _.find(gclGatherData, function (item) {
  612. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  613. });
  614. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  615. return item.gcl_id === select.id;
  616. });
  617. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  618. const data = {
  619. lid: gclInfo.leafXmjs[0].gcl_id || select.id,
  620. code: gclInfo.b_code,
  621. name: gclInfo.name || '',
  622. unit: gclInfo.unit || '',
  623. unit_price: gclInfo.unit_price,
  624. oamount: xmjInfo.quantity,
  625. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  626. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  627. xmj_code: xmjInfo.code || '',
  628. xmj_jldy: xmjInfo.jldy || '',
  629. xmj_dwgc: xmjInfo.dwgc || '',
  630. xmj_fbgc: xmjInfo.fbgc || '',
  631. xmj_fxgc: xmjInfo.fxgc || '',
  632. gcl_id: select.id,
  633. mx_id: '',
  634. };
  635. if (oldCInfo) {
  636. data.detail = oldCInfo.detail;
  637. data.camount = oldCInfo.camount;
  638. data.spamount = oldCInfo.spamount;
  639. data.is_valuation = oldCInfo.is_valuation;
  640. data.delimit = oldCInfo.delimit;
  641. }
  642. // 更新至服务器
  643. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  644. changeList = result.changeList;
  645. select.is_change = 1;
  646. }, function () {
  647. info.sheet.setValue(info.row, info.col, 0);
  648. });
  649. console.log(data);
  650. } else {
  651. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.id }) !== -1) {
  652. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  653. info.sheet.setValue(info.row, info.col, 1);
  654. return
  655. }
  656. const cInfo = _.find(changeList, { gcl_id: select.id });
  657. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  658. toastr.warning('该清单计量单元已被使用,无法取消勾选');
  659. info.sheet.setValue(info.row, info.col, 1);
  660. return
  661. } else if (checkIsSettle(cInfo)) {
  662. toastr.warning('该清单计量单元已结算,无法取消勾选');
  663. info.sheet.setValue(info.row, info.col, 1);
  664. return
  665. } else {
  666. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  667. changeList = result.changeList;
  668. select.is_change = 0;
  669. }, function () {
  670. info.sheet.setValue(info.row, info.col, 1);
  671. });
  672. }
  673. }
  674. }
  675. }
  676. },
  677. /**
  678. * 编辑单元格响应事件
  679. * @param {Object} e
  680. * @param {Object} info
  681. */
  682. editEnded: function (e, info) {
  683. if (info.sheet.zh_setting) {
  684. const col = info.sheet.zh_setting.cols[info.col];
  685. if (col.field === 'is_change') {
  686. return;
  687. }
  688. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  689. const node = sortData[info.row];
  690. const data = {
  691. id: node.id,
  692. tender_id: node.tender_id,
  693. ledger_id: node.ledger_id
  694. };
  695. // 未改变值则不提交
  696. const orgValue = node[col.field];
  697. const newValue = trimInvalidChar(info.editingText);
  698. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  699. return;
  700. }
  701. // 台账模式,检查计量单元相关
  702. if (isTz) {
  703. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  704. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  705. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  706. if (!node.children || node.children.length ===0) {
  707. const lPos = pos.getLedgerPos(node.id);
  708. if (lPos && lPos.length > 0) {
  709. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  710. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  711. return;
  712. }
  713. }
  714. }
  715. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  716. const lPos = pos.getLedgerPos(node.id);
  717. if (lPos && lPos.length > 0) {
  718. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  719. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  720. return;
  721. }
  722. }
  723. }
  724. // 获取更新数据
  725. const exprInfo = getExprInfo(col.field);
  726. if (info.editingText) {
  727. const text = newValue;
  728. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  729. toastr.error('节点已计量,请勿删除编号');
  730. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  731. return;
  732. }
  733. if (col.type === 'Number') {
  734. const num = _.toNumber(text);
  735. if (_.isFinite(num)) {
  736. data[col.field] = num;
  737. if (exprInfo) {
  738. data[exprInfo.expr] = '';
  739. }
  740. } else {
  741. try {
  742. data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
  743. if (exprInfo) {
  744. data[exprInfo.expr] = newValue;
  745. }
  746. } catch(err) {
  747. toastr.error('输入的表达式非法');
  748. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  749. return;
  750. }
  751. }
  752. } else {
  753. data[col.field] = text;
  754. }
  755. } else {
  756. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  757. toastr.error('节点已计量,请勿删除编号');
  758. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  759. return;
  760. }
  761. data[col.field] = null;
  762. if (exprInfo) {
  763. data[exprInfo.expr] = '';
  764. }
  765. }
  766. if (col.field === 'b_code' && newValue) {
  767. const ledgerData = _.filter(billsTree.nodes, function (item) {
  768. return item.b_code !== null && item.b_code !== '' && !item.formc;
  769. });
  770. const ledgerOneData = _.find(ledgerData, { b_code: newValue });
  771. if (ledgerOneData) {
  772. data.name = ledgerOneData.name;
  773. data.unit = ledgerOneData.unit;
  774. data.unit_price = ledgerOneData.unit_price;
  775. }
  776. }
  777. // 更新至服务器
  778. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  779. changeList = result.changeList;
  780. const refreshNode = billsTree.loadPostData(result);
  781. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  782. });
  783. }
  784. },
  785. clipboardPasting: function (e, info) {
  786. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  787. info.cancel = true;
  788. if (!setting || !tree) return;
  789. // const range = info.cellRange;
  790. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  791. // const node = tree.nodes[iRow];
  792. // if (tree.checkNodeUsed(node, pos)) {
  793. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  794. // return;
  795. // }
  796. // }
  797. const pasteData = info.pasteData.html
  798. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  799. : (info.pasteData.text === ''
  800. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  801. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  802. const hint = {
  803. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  804. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  805. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  806. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  807. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  808. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  809. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  810. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  811. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  812. settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
  813. };
  814. const datas = [], filterNodes = [];
  815. let pid, level, filterRow = 0;
  816. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  817. const curRow = info.cellRange.row + iRow;
  818. const node = tree.nodes[curRow];
  819. if (!node) continue;
  820. if (!pid) pid = node.ledger_pid;
  821. if (!level) level = node.level;
  822. // if (node.ledger_pid !== pid) {
  823. // toastMessageUniq(hint.sameParent);
  824. // filterRow+=1;
  825. // continue;
  826. // }
  827. if (node.level < level) break;
  828. let bPaste = false;
  829. const data = info.sheet.zh_tree.getNodeKeyData(node);
  830. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  831. const curCol = info.cellRange.col + iCol;
  832. const colSetting = info.sheet.zh_setting.cols[curCol];
  833. const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  834. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  835. toastMessageUniq(hint.parent);
  836. continue;
  837. }
  838. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  839. toastMessageUniq(hint.gcl);
  840. continue;
  841. }
  842. const lPos = pos.getLedgerPos(node.id);
  843. if (lPos && lPos.length > 0) {
  844. if (value === '' && colSetting.field === 'b_code') {
  845. toastMessageUniq(hint.posCode);
  846. continue;
  847. }
  848. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  849. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  850. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  851. toastMessageUniq(hint.posQty);
  852. continue;
  853. }
  854. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  855. toastMessageUniq(hint.posXmj);
  856. continue;
  857. }
  858. }
  859. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  860. toastMessageUniq (hint.usedUp);
  861. continue;
  862. }
  863. if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
  864. toastMessageUniq(hint.settle);
  865. continue;
  866. }
  867. if (colSetting.type === 'Number') {
  868. const num = _.toNumber(value);
  869. if (num) {
  870. data[colSetting.field] = num;
  871. } else {
  872. try {
  873. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  874. const exprInfo = getExprInfo(colSetting.field);
  875. if (exprInfo) {
  876. data[exprInfo.expr] = value;
  877. }
  878. bPaste = true;
  879. } catch (err) {
  880. toastMessageUniq(hint.invalidExpr);
  881. continue;
  882. }
  883. }
  884. } else {
  885. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  886. && data[colSetting.field] !== '' && value === '') {
  887. toastMessageUniq(hint.usedCode);
  888. continue;
  889. }
  890. data[colSetting.field] = value;
  891. }
  892. if (colSetting.field === 'b_code' && value) {
  893. const ledgerData = _.filter(billsTree.nodes, function (item) {
  894. return item.b_code !== null && item.b_code !== '' && !item.formc;
  895. });
  896. const ledgerOneData = _.find(ledgerData, { b_code: value });
  897. if (ledgerOneData) {
  898. data.name = ledgerOneData.name;
  899. data.unit = ledgerOneData.unit;
  900. data.unit_price = ledgerOneData.unit_price;
  901. }
  902. }
  903. bPaste = true;
  904. }
  905. if (bPaste) {
  906. datas.push(data);
  907. } else {
  908. filterNodes.push(node);
  909. }
  910. }
  911. if (datas.length > 0) {
  912. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  913. changeList = result.changeList;
  914. const refreshNode = tree.loadPostData(result);
  915. if (refreshNode.update) {
  916. refreshNode.update = refreshNode.update.concat(filterNodes);
  917. }
  918. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  919. }, function () {
  920. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  921. });
  922. } else {
  923. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  924. }
  925. },
  926. clipboardPasted: function (e, info) {
  927. const hint = {
  928. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  929. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  930. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  931. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  932. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  933. };
  934. const tree = info.sheet.zh_tree;
  935. if (!tree) { return; }
  936. const sortData = info.sheet.zh_tree.nodes;
  937. const datas = [], filterNodes = [];
  938. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  939. let bPaste = false;
  940. const curRow = info.cellRange.row + iRow;
  941. const node = sortData[curRow];
  942. if (node) {
  943. const data = info.sheet.zh_tree.getNodeKeyData(node);
  944. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  945. const curCol = info.cellRange.col + iCol;
  946. const colSetting = info.sheet.zh_setting.cols[curCol];
  947. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  948. const lPos = pos.getLedgerPos(node.id);
  949. if (lPos && lPos.length > 0) {
  950. if (value === '' && colSetting.field === 'b_code') {
  951. toastMessageUniq(hint.posCode);
  952. continue;
  953. }
  954. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  955. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  956. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  957. toastMessageUniq(hint.posQty);
  958. continue;
  959. }
  960. }
  961. if (node.used && colSetting.field === 'unit_price') {
  962. toastMessageUniq (hint.usedUp);
  963. continue;
  964. }
  965. if (colSetting.type === 'Number') {
  966. const num = _.toNumber(value);
  967. if (num) {
  968. data[colSetting.field] = num;
  969. } else {
  970. try {
  971. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  972. } catch (err) {
  973. toastMessageUniq(hint.invalidExpr);
  974. continue;
  975. }
  976. }
  977. } else {
  978. if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
  979. && data[colSetting.field] !== '' && value === '') {
  980. toastMessageUniq(hint.usedCode);
  981. continue;
  982. }
  983. data[colSetting.field] = value;
  984. }
  985. if (colSetting.field === 'b_code' && value) {
  986. const ledgerData = _.filter(billsTree.nodes, function (item) {
  987. return item.b_code !== null && item.b_code !== '' && !item.formc;
  988. });
  989. const ledgerOneData = _.find(ledgerData, { b_code: value });
  990. if (ledgerOneData) {
  991. data.name = ledgerOneData.name;
  992. data.unit = ledgerOneData.unit;
  993. data.unit_price = ledgerOneData.unit_price;
  994. }
  995. }
  996. bPaste = true;
  997. }
  998. if (bPaste) {
  999. datas.push(data);
  1000. } else {
  1001. filterNodes.push(node);
  1002. }
  1003. }
  1004. }
  1005. if (datas.length > 0) {
  1006. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1007. changeList = result.changeList;
  1008. const refreshNode = tree.loadPostData(result);
  1009. if (refreshNode.update) {
  1010. refreshNode.update = refreshNode.update.concat(filterNodes);
  1011. }
  1012. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1013. }, function () {
  1014. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1015. });
  1016. } else {
  1017. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1018. }
  1019. },
  1020. deletePress: function (sheet) {
  1021. if (!sheet.zh_setting) return;
  1022. const sel = sheet.getSelections()[0], datas = [];
  1023. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1024. let bDel = false;
  1025. const node = sheet.zh_tree.nodes[iRow];
  1026. const data = sheet.zh_tree.getNodeKeyData(node);
  1027. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1028. const col = sheet.zh_setting.cols[iCol];
  1029. const style = sheet.getStyle(iRow, iCol);
  1030. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  1031. if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
  1032. if (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  1033. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  1034. return;
  1035. }
  1036. data[col.field] = null;
  1037. const exprInfo = getExprInfo(col.field);
  1038. if (exprInfo) {
  1039. data[exprInfo.expr] = '';
  1040. }
  1041. bDel = true;
  1042. }
  1043. if (bDel) datas.push(data);
  1044. }
  1045. if (datas.length > 0) {
  1046. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1047. changeList = result.changeList;
  1048. const refreshNode = sheet.zh_tree.loadPostData(result);
  1049. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1050. billsTreeSpreadObj.loadExprToInput(sheet);
  1051. });
  1052. }
  1053. },
  1054. pasteBlock: function (spread, copyInfo) {
  1055. const self = this;
  1056. const sheet = spread.getActiveSheet();
  1057. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  1058. if (node.settle_status === settleStatus.finish) {
  1059. toastr.warning('选中的节点已结算,不可粘贴整块');
  1060. return;
  1061. }
  1062. postData(window.location.pathname + '/update', {
  1063. postType: 'paste-block',
  1064. postData: {
  1065. id: tree.getNodeKey(node),
  1066. tid: copyInfo.tid,
  1067. block: copyInfo.block,
  1068. }
  1069. }, function (data) {
  1070. changeList = data.changeList;
  1071. pos.updateDatas(data.pos);
  1072. const result = tree.loadPostData(data.ledger);
  1073. self.refreshTree(sheet, result);
  1074. const sel = sheet.getSelections()[0];
  1075. if (sel) {
  1076. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  1077. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  1078. }
  1079. self.refreshOperationValid(sheet);
  1080. removeLocalCache(copyBlockTag);
  1081. }, null, true);
  1082. },
  1083. topRowChanged: function (e, info) {
  1084. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1085. },
  1086. editStarting(e, info) {
  1087. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1088. const col = info.sheet.zh_setting.cols[info.col];
  1089. const node = info.sheet.zh_tree.nodes[info.row];
  1090. if (!node) {
  1091. info.cancel = true;
  1092. return;
  1093. }
  1094. const exprInfo = getExprInfo(col.field);
  1095. if (exprInfo) {
  1096. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1097. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1098. }
  1099. }
  1100. switch (col.field) {
  1101. case 'code':
  1102. const posRange = pos.getLedgerPos(node.id);
  1103. info.cancel = posRange && posRange.length > 0;
  1104. break;
  1105. case 'unit_price':
  1106. info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
  1107. break;
  1108. case 'sgfh_qty':
  1109. case 'sgfh_tp':
  1110. case 'sjcl_qty':
  1111. case 'sjcl_tp':
  1112. case 'qtcl_qty':
  1113. case 'qtcl_tp':
  1114. case 'deal_qty':
  1115. case 'deal_tp':
  1116. info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
  1117. break;
  1118. case 'dgn_qty1':
  1119. case 'dgn_qty2':
  1120. info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
  1121. break;
  1122. }
  1123. },
  1124. cut: function (sheet, sel, callback) {
  1125. if (!sheet || !sel) return;
  1126. if (sel.colCount >= sheet.zh_setting.cols.length) {
  1127. toastr.warning('请勿选中整行剪切');
  1128. return;
  1129. }
  1130. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  1131. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1132. const node = sortData[iRow];
  1133. if (node) {
  1134. const data = sheet.zh_tree.getNodeKeyData(node);
  1135. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1136. const col = sheet.zh_setting.cols[iCol];
  1137. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1138. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1139. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  1140. const lPos = pos.getLedgerPos(node.id);
  1141. if (lPos && lPos.length > 0) {
  1142. toastr.error('不可剪切');
  1143. return;
  1144. }
  1145. }
  1146. const style = sheet.getStyle(iRow, iCol);
  1147. if (style.locked) {
  1148. toastr.error('不可剪切');
  1149. return;
  1150. }
  1151. const colSetting = sheet.zh_setting.cols[iCol];
  1152. data[colSetting.field] = null;
  1153. const exprInfo = getExprInfo(colSetting.field);
  1154. if (exprInfo) {
  1155. data[exprInfo.expr] = '';
  1156. }
  1157. }
  1158. datas.push(data);
  1159. }
  1160. }
  1161. if (datas.length > 0) {
  1162. callback();
  1163. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1164. changeList = result.changeList;
  1165. const refreshNode = sheet.zh_tree.loadPostData(result);
  1166. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1167. });
  1168. }
  1169. },
  1170. sortCode: function (sheet) {
  1171. const tree = sheet.zh_tree;
  1172. if (!tree) return;
  1173. const select = SpreadJsObj.getSelectObject(sheet);
  1174. if (!select || !select.code || select.code === '') return;
  1175. const recursiveSortCode = function (data, parentCode, children) {
  1176. if (!children || children.length === 0) return;
  1177. for (const [i, child] of children.entries()) {
  1178. if (!child.b_code || child.b_code === '') {
  1179. const code = parentCode + '-' + (i + 1);
  1180. const cData = tree.getNodeKeyData(child);
  1181. cData.code = code;
  1182. data.push(cData);
  1183. if (!tree.isLeafXmj(child)) {
  1184. recursiveSortCode(data, code, child.children);
  1185. }
  1186. }
  1187. }
  1188. };
  1189. const data = [];
  1190. recursiveSortCode(data, select.code, select.children);
  1191. if (data.length > 0) {
  1192. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1193. changeList = result.changeList;
  1194. const refreshNode = tree.loadPostData(result);
  1195. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1196. })
  1197. }
  1198. }
  1199. };
  1200. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1201. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1202. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  1203. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  1204. if (!readOnly) {
  1205. // 增删上下移升降级
  1206. $('a[name="base-opr"]').click(function () {
  1207. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  1208. });
  1209. $('a[name=cpc]').click(function () {
  1210. billsSpread.commandManager().execute({
  1211. cmd: this.getAttribute('type'),
  1212. sheetName: billsSheet.name()
  1213. });
  1214. });
  1215. $('#bills-expr').bind('change onblur', function () {
  1216. if (this.readOnly) return;
  1217. const expr = $(this);
  1218. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1219. const select = billsTree.getItemsByIndex(row);
  1220. if (!select) return;
  1221. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1222. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1223. const data = {
  1224. id: select.id,
  1225. tender_id: select.tender_id,
  1226. ledger_id: select.ledger_id
  1227. };
  1228. const exprInfo = getExprInfo(field);
  1229. if (newValue !== '') {
  1230. const num = _.toNumber(newValue);
  1231. if (num) {
  1232. data[field] = num;
  1233. if (exprInfo) {
  1234. data[exprInfo.expr] = '';
  1235. }
  1236. } else {
  1237. try {
  1238. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  1239. if (exprInfo) {
  1240. data[exprInfo.expr] = newValue;
  1241. }
  1242. } catch (err) {
  1243. toastr.error('输入的表达式非法');
  1244. return;
  1245. }
  1246. }
  1247. } else {
  1248. data[field] = null;
  1249. if (exprInfo) {
  1250. data[exprInfo.expr] = '';
  1251. }
  1252. }
  1253. // 更新至服务器
  1254. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1255. changeList = result.changeList;
  1256. const refreshNode = billsTree.loadPostData(result);
  1257. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1258. });
  1259. });
  1260. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  1261. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  1262. billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
  1263. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  1264. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1265. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1266. SpreadJsObj.Clipboard.setCopyData(copyText);
  1267. });
  1268. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  1269. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  1270. }
  1271. // 右键菜单
  1272. let batchInsertObj;
  1273. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1274. const self = this;
  1275. if ($.isFunction(item.icon)) {
  1276. item._icon = item.icon.call(this, this, $t, key, item);
  1277. } else {
  1278. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1279. // to enable font awesome
  1280. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1281. } else {
  1282. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1283. }
  1284. }
  1285. this.addClass(item._icon);
  1286. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  1287. .appendTo(this);
  1288. const $input = $obj.find('input');
  1289. const event = () => {
  1290. if (self.hasClass('context-menu-disabled')) return;
  1291. item.batchInsert($input[0], root);
  1292. };
  1293. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1294. $input.click((e) => {e.stopPropagation();})
  1295. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1296. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1297. };
  1298. const billsContextMenuOptions = {
  1299. selector: '#bills-spread',
  1300. build: function ($trigger, e) {
  1301. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  1302. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1303. },
  1304. items: {}
  1305. };
  1306. if (!readOnly) {
  1307. billsContextMenuOptions.items.create = {
  1308. name: '新增',
  1309. icon: 'fa-sign-in',
  1310. callback: function (key, opt) {
  1311. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  1312. },
  1313. disabled: function (key, opt) {
  1314. const sheet = billsSheet;
  1315. const selection = sheet.getSelections();
  1316. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1317. const row = sel ? sel.row : -1;
  1318. const tree = sheet.zh_tree;
  1319. if (!tree) return true;
  1320. const first = sheet.zh_tree.nodes[row];
  1321. const valid = !sheet.zh_setting.readOnly;
  1322. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1323. }
  1324. };
  1325. billsContextMenuOptions.items.delete = {
  1326. name: '删除',
  1327. icon: 'fa-remove',
  1328. callback: function (key, opt) {
  1329. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  1330. },
  1331. disabled: function (key, opt) {
  1332. const sheet = billsSheet;
  1333. const selection = sheet.getSelections();
  1334. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1335. const row = sel ? sel.row : -1;
  1336. const tree = sheet.zh_tree;
  1337. if (!tree) return true;
  1338. const first = sheet.zh_tree.nodes[row];
  1339. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  1340. if (sel.rowCount > 1 && first) {
  1341. for (let r = 1; r < sel.rowCount; r++) {
  1342. const rNode = tree.nodes[sel.row + r];
  1343. if (!rNode) {
  1344. sameParent = false;
  1345. break;
  1346. }
  1347. if (!rNode.formc) {
  1348. return true;
  1349. }
  1350. nodeUsed = nodeUsed || rNode.used;
  1351. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  1352. if (rNode.level > first.level) continue;
  1353. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1354. sameParent = false;
  1355. break;
  1356. }
  1357. last = rNode;
  1358. }
  1359. }
  1360. const valid = !sheet.zh_setting.readOnly;
  1361. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  1362. }
  1363. };
  1364. billsContextMenuOptions.items.sprBase = '----';
  1365. }
  1366. billsContextMenuOptions.items.copyBlock = {
  1367. name: '复制整块',
  1368. icon: 'fa-files-o',
  1369. callback: function (key, opt) {
  1370. const copyBlockList = [];
  1371. const sheet = billsSheet;
  1372. const sel = sheet.getSelections()[0];
  1373. let iRow = sel.row;
  1374. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1375. while (iRow < sel.row + sel.rowCount) {
  1376. const node = sheet.zh_tree.nodes[iRow];
  1377. if (node.ledger_pid !== pid) {
  1378. toastr.error('仅可同时选中同层节点');
  1379. return;
  1380. }
  1381. const posterity = sheet.zh_tree.getPosterity(node);
  1382. iRow += posterity.length + 1;
  1383. posterity.unshift(node);
  1384. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1385. }
  1386. for (const cbl of copyBlockList) {
  1387. for (const b of cbl) {
  1388. const posRange = pos.getLedgerPos(b.id);
  1389. if (posRange && posRange.length > 0) b.pos = posRange;
  1390. }
  1391. }
  1392. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1393. },
  1394. visible: function (key, opt) {
  1395. const sheet = billsSheet;
  1396. const selection = sheet.getSelections();
  1397. const row = selection[0].row;
  1398. const select = billsTree.nodes[row];
  1399. return select;
  1400. },
  1401. disabled: function (key, opt) {
  1402. const sheet = billsSheet;
  1403. const selection = sheet.getSelections();
  1404. const row = selection[0].row;
  1405. const select = billsTree.nodes[row];
  1406. return select && select.level <= 1;
  1407. }
  1408. };
  1409. billsContextMenuOptions.items.copyBlockXmj = {
  1410. name: '复制整块(只复制项目节)',
  1411. icon: 'fa-files-o',
  1412. callback: function (key, opt) {
  1413. const copyBlockList = [];
  1414. const sheet = billsSheet;
  1415. const sel = sheet.getSelections()[0];
  1416. let iRow = sel.row;
  1417. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1418. while (iRow < sel.row + sel.rowCount) {
  1419. const node = sheet.zh_tree.nodes[iRow];
  1420. if (node.ledger_pid !== pid) {
  1421. toastr.error('仅可同时选中同层节点');
  1422. return;
  1423. }
  1424. const posterity = sheet.zh_tree.getPosterity(node);
  1425. iRow += posterity.length + 1;
  1426. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1427. copyPosterity.unshift(node);
  1428. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1429. for (const p of copyData) {
  1430. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1431. p.is_leaf = children.length === 0;
  1432. }
  1433. copyBlockList.push(copyData);
  1434. }
  1435. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1436. },
  1437. visible: function (key, opt) {
  1438. const sheet = billsSheet;
  1439. const selection = sheet.getSelections();
  1440. const row = selection[0].row;
  1441. const select = billsTree.nodes[row];
  1442. return select;
  1443. },
  1444. disabled: function (key, opt) {
  1445. const sheet = billsSheet;
  1446. const selection = sheet.getSelections();
  1447. const row = selection[0].row;
  1448. const select = billsTree.nodes[row];
  1449. return select && select.level <= 1;
  1450. }
  1451. };
  1452. if (!readOnly) {
  1453. billsContextMenuOptions.items.pasteBlock = {
  1454. name: '粘贴整块',
  1455. icon: 'fa-clipboard',
  1456. disabled: function (key, opt) {
  1457. //const block = treeOperationObj.block || [];
  1458. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1459. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1460. },
  1461. callback: function (key, opt) {
  1462. //const block = treeOperationObj.block || [];
  1463. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1464. if (copyInfo.block.length > 0) {
  1465. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  1466. } else {
  1467. document.execCommand('paste');
  1468. }
  1469. },
  1470. visible: function (key, opt) {
  1471. return !readOnly;
  1472. }
  1473. };
  1474. billsContextMenuOptions.items.sprBlock = '----';
  1475. }
  1476. if (!readOnly) {
  1477. billsContextMenuOptions.items.batchInsert = {
  1478. name: '批量插入',
  1479. type: 'batchInsert',
  1480. value: '2',
  1481. icon: 'fa-sign-in',
  1482. batchInsert: function (obj, root) {
  1483. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1484. obj.value = obj.max;
  1485. toastr.warning('批量插入不可多于' + obj.max);
  1486. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1487. obj.value = obj.min;
  1488. toastr.warning('批量插入不可少于' + obj.min);
  1489. } else {
  1490. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  1491. root.$menu.trigger('contextmenu:hide');
  1492. }
  1493. },
  1494. disabled: function (key, opt) {
  1495. const sheet = billsSheet;
  1496. const selection = sheet.getSelections();
  1497. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1498. const row = sel ? sel.row : -1;
  1499. const tree = sheet.zh_tree;
  1500. if (!tree) return true;
  1501. const first = sheet.zh_tree.nodes[row];
  1502. const valid = !sheet.zh_setting.readOnly;
  1503. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1504. }
  1505. };
  1506. billsContextMenuOptions.items.batchInsertBillsPos = {
  1507. name: '批量插入清单-计量单元',
  1508. icon: 'fa-sign-in',
  1509. visible: function (key, opt) {
  1510. return false;
  1511. },
  1512. disabled: function (key, opt) {
  1513. if (!isTz) return true;
  1514. const select = SpreadJsObj.getSelectObject(billsSheet);
  1515. if (select) {
  1516. if (select.code && select.code !== '') {
  1517. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  1518. } else {
  1519. const parent = billsTree.getParent(select);
  1520. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  1521. }
  1522. } else {
  1523. return false;
  1524. }
  1525. },
  1526. callback: function (key, opt) {
  1527. if (!batchInsertObj) {
  1528. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1529. } else {
  1530. batchInsertObj.initView();
  1531. }
  1532. $('#batch').modal('show');
  1533. }
  1534. };
  1535. }
  1536. billsContextMenuOptions.items.sprTag = '----';
  1537. billsContextMenuOptions.items.showLast = {
  1538. name: '显示至最底层',
  1539. callback: function (key, opt, menu, e) {
  1540. const node = SpreadJsObj.getSelectObject(billsSheet);
  1541. setTimeout(() => {
  1542. showWaitingView();
  1543. billsTree.expandByCustom(x => {
  1544. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1545. });
  1546. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  1547. closeWaitingView();
  1548. }, 100);
  1549. },
  1550. };
  1551. $.contextMenu(billsContextMenuOptions);
  1552. // 计量单元 相关方法&绑定spreadjs事件
  1553. const posSpreadObj = {
  1554. refreshOperationValid: function (sheet, selection) {
  1555. const setObjEnable = function (obj, enable) {
  1556. if (enable) {
  1557. obj.removeClass('disabled');
  1558. } else {
  1559. obj.addClass('disabled');
  1560. }
  1561. };
  1562. const invalidAll = function () {
  1563. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1564. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1565. };
  1566. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1567. const row = sel ? sel.row : -1;
  1568. const first = sheet.zh_data[row];
  1569. if (!first) {
  1570. invalidAll();
  1571. return;
  1572. }
  1573. let last = first;
  1574. if (sel.rowCount > 1 && first) {
  1575. for (let r = 1; r < sel.rowCount; r++) {
  1576. const rNode = sheet.zh_data[sel.row + r];
  1577. if (!rNode) break;
  1578. last = rNode;
  1579. }
  1580. }
  1581. const preNode = sheet.zh_data[row - 1];
  1582. const valid = !sheet.zh_setting.readOnly;
  1583. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  1584. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  1585. },
  1586. loadExprToInput: function () {
  1587. const sel = posSheet.getSelections()[0];
  1588. if (!sel) return;
  1589. const col = posSheet.zh_setting.cols[sel.col];
  1590. const cell = posSheet.getCell(sel.col, sel.col);
  1591. if (col && col.type === 'Number') {
  1592. const data = SpreadJsObj.getSelectObject(posSheet);
  1593. if (data) {
  1594. const exprInfo = getExprInfo(col.field);
  1595. const value = exprInfo
  1596. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1597. : data[col.field];
  1598. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1599. .attr('readOnly', readOnly || (!data.formc && cell.locked()) || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  1600. } else {
  1601. $('#pos-expr').val('').attr('readOnly', true);
  1602. $('#pos-expr').removeAttr('data-row');
  1603. }
  1604. } else {
  1605. $('#pos-expr').val('').attr('readOnly', true);
  1606. $('#pos-expr').removeAttr('data-row');
  1607. }
  1608. },
  1609. /**
  1610. * 加载计量单元 根据当前台账选择节点
  1611. */
  1612. loadCurPosData: function () {
  1613. const node = SpreadJsObj.getSelectObject(billsSheet);
  1614. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  1615. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  1616. if (node) {
  1617. const posData = pos.getLedgerPos(node.id) || [];
  1618. console.log(posData);
  1619. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  1620. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  1621. } else {
  1622. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  1623. posSheet.zh_setting.readOnly = true;
  1624. }
  1625. SpreadJsObj.massOperationSheet(posSheet, function () {
  1626. if (posSheet.zh_setting) {
  1627. posSheet.zh_setting.cols.forEach(function (col, i) {
  1628. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  1629. if (i !== 0) {
  1630. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  1631. } else {
  1632. let lock = false;
  1633. if (!posSheet.zh_data[iRow]) {
  1634. lock = true;
  1635. }
  1636. posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
  1637. }
  1638. }
  1639. });
  1640. }
  1641. });
  1642. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  1643. posSpreadObj.loadExprToInput();
  1644. posSpreadObj.refreshOperationValid(posSheet);
  1645. },
  1646. baseOpr: function (sheet, type) {
  1647. const data = {
  1648. postType: 'pos',
  1649. posPostType: type === 'delete' ? type : 'update',
  1650. postData: [],
  1651. };
  1652. const selection = sheet.getSelections();
  1653. const row = selection[0].row, count = selection[0].rowCount;
  1654. const first = sheet.zh_data[row];
  1655. if (type === 'delete') {
  1656. for (let iRow = 0; iRow < count; iRow++) {
  1657. const posData = sheet.zh_data[iRow + row];
  1658. if (posData) {
  1659. if (posData.used) {
  1660. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1661. return;
  1662. }
  1663. if (posData.settle_status) {
  1664. toastr.error('"' + posData.name + '"已结算,请勿删除');
  1665. return;
  1666. }
  1667. data.postData.push(sheet.zh_data[iRow + row].id);
  1668. }
  1669. }
  1670. } else if (type === 'up-move') {
  1671. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1672. for (let iRow = 0; iRow < count; iRow++) {
  1673. const posData = sheet.zh_data[iRow + row];
  1674. if (posData) {
  1675. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1676. preUpdate.porder = posData.porder;
  1677. }
  1678. }
  1679. data.postData.push(preUpdate);
  1680. } else if (type === 'down-move') {
  1681. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1682. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1683. const posData = sheet.zh_data[iRow + row];
  1684. if (posData) {
  1685. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1686. nextUpdate.porder = posData.porder;
  1687. }
  1688. }
  1689. data.postData.push(nextUpdate);
  1690. } else if (type === 'add') {
  1691. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1692. if (billsNode.settle_status === settleStatus.finish) {
  1693. toastr.warning('清单已结算,不可新增计量单元');
  1694. return;
  1695. }
  1696. }
  1697. if (data.postData.length > 0) {
  1698. postData(window.location.pathname + '/update', data, function (result) {
  1699. changeList = result.changeList;
  1700. if (type === 'delete') {
  1701. pos.removeDatas(result.pos);
  1702. sheet.deleteRows(row, count);
  1703. const loadResult = billsTree.loadPostData(result.ledger);
  1704. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1705. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1706. posSpreadObj.refreshOperationValid(posSheet);
  1707. } else {
  1708. pos.updateDatas(result.pos);
  1709. const sel = selection[0];
  1710. if (sel) {
  1711. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1712. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1713. }
  1714. posSpreadObj.loadCurPosData();
  1715. }
  1716. });
  1717. }
  1718. },
  1719. editStarting: function (e, info) {
  1720. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1721. const sel = info.sheet.getSelections();
  1722. if (!sel || !sel[0]) return;
  1723. const col = info.sheet.zh_setting.cols[sel[0].col];
  1724. const node = SpreadJsObj.getSelectObject(info.sheet);
  1725. const exprInfo = getExprInfo(col.field);
  1726. if (node && exprInfo) {
  1727. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1728. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1729. }
  1730. }
  1731. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  1732. info.cancel = true;
  1733. }
  1734. },
  1735. buttonClicked: function (e, info) {
  1736. if (info.sheet.zh_setting) {
  1737. const select = SpreadJsObj.getSelectObject(info.sheet);
  1738. const col = info.sheet.zh_setting.cols[info.col];
  1739. if (col.field === 'is_change') {
  1740. if (posCol.readOnly.isChangeList(select)) {
  1741. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  1742. return
  1743. }
  1744. if (info.sheet.isEditing()) {
  1745. info.sheet.endEdit(true);
  1746. }
  1747. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  1748. if (is_change) {
  1749. makeGclGatherData();
  1750. const gclInfo = _.find(gclGatherData, function (item) {
  1751. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  1752. });
  1753. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  1754. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  1755. const data = {
  1756. lid: select.lid,
  1757. code: gclInfo.b_code,
  1758. name: gclInfo.name || '',
  1759. unit: gclInfo.unit || '',
  1760. unit_price: gclInfo.unit_price,
  1761. oamount: xmjInfo.quantity,
  1762. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1763. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  1764. xmj_code: xmjInfo.code || '',
  1765. xmj_jldy: xmjInfo.jldy || '',
  1766. xmj_dwgc: xmjInfo.dwgc || '',
  1767. xmj_fbgc: xmjInfo.fbgc || '',
  1768. xmj_fxgc: xmjInfo.fxgc || '',
  1769. gcl_id: select.lid,
  1770. mx_id: select.id,
  1771. }
  1772. if (oldCInfo) {
  1773. data.detail = oldCInfo.detail;
  1774. data.camount = oldCInfo.camount;
  1775. data.spamount = oldCInfo.spamount;
  1776. data.is_valuation = oldCInfo.is_valuation;
  1777. data.delimit = oldCInfo.delimit;
  1778. }
  1779. // 更新至服务器
  1780. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  1781. changeList = result.changeList;
  1782. select.is_change = 1;
  1783. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  1784. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1785. billsNode.is_change = 1;
  1786. const loadResult = { update: [billsNode] };
  1787. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1788. }
  1789. }, function () {
  1790. info.sheet.setValue(info.row, info.col, 0);
  1791. });
  1792. } else {
  1793. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
  1794. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  1795. info.sheet.setValue(info.row, info.col, 1);
  1796. return
  1797. }
  1798. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  1799. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  1800. toastr.warning('该计量单元已被使用,无法取消变更');
  1801. info.sheet.setValue(info.row, info.col, 1);
  1802. return
  1803. } else if (checkIsSettle(cInfo)) {
  1804. toastr.warning('该计量单元已结算,无法取消变更');
  1805. info.sheet.setValue(info.row, info.col, 1);
  1806. return
  1807. } else {
  1808. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  1809. changeList = result.changeList;
  1810. select.is_change = 0;
  1811. // 判断是否只剩一个,并同步去勾
  1812. if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
  1813. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1814. billsNode.is_change = 0;
  1815. const loadResult = { update: [billsNode] };
  1816. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1817. }
  1818. }, function () {
  1819. info.sheet.setValue(info.row, info.col, 1);
  1820. });
  1821. }
  1822. }
  1823. }
  1824. }
  1825. },
  1826. /**
  1827. * 编辑单元格响应事件
  1828. * @param {Object} e
  1829. * @param {Object} info
  1830. */
  1831. editEnded: function (e, info) {
  1832. if (!info.sheet.zh_setting) {
  1833. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1834. return;
  1835. }
  1836. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1837. const col = info.sheet.zh_setting.cols[info.col];
  1838. if (col.field === 'is_change') {
  1839. return;
  1840. }
  1841. const orgText = posData ? posData[col.field] : null;
  1842. const newText = trimInvalidChar(info.editingText);
  1843. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  1844. const node = posSpreadObj.billsNode;
  1845. if (!node) {
  1846. toastr.error('数据错误,请选择台账节点后再试');
  1847. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1848. return;
  1849. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1850. toastr.error('父节点不可插入计量单元');
  1851. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1852. return;
  1853. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1854. toastr.error('项目节不可插入计量单元');
  1855. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1856. return;
  1857. }
  1858. const data = {postType: 'pos'};
  1859. if (col.field === 'name') {
  1860. if (newText === '' && posData) {
  1861. toastr.error('部位名称不可为空', 'error');
  1862. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1863. return;
  1864. } else if (!posData) {
  1865. if (newText && newText !== '') {
  1866. data.posPostType = 'add';
  1867. const sortData = info.sheet.zh_data;
  1868. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1869. data.postData = { name: newText, lid: node.id, porder: order};
  1870. if (node.settle_status === settleStatus.finish) {
  1871. toastr.error('已结算清单不可插入计量单元');
  1872. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1873. return;
  1874. }
  1875. } else {
  1876. return;
  1877. }
  1878. } else {
  1879. data.posPostType = 'update';
  1880. data.postData = {id: posData.id, name: newText};
  1881. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  1882. toastr.error('计量单元已结算,不可修改');
  1883. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1884. return;
  1885. }
  1886. }
  1887. } else if (!posData) {
  1888. toastr.warning('新增计量单元请先输入名称');
  1889. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1890. return;
  1891. } else {
  1892. data.posPostType = 'update';
  1893. data.postData = {id: posData.id};
  1894. if (col.type === 'Number') {
  1895. const exprInfo = getExprInfo(col.field);
  1896. const num = _.toNumber(newText);
  1897. if (_.isFinite(num)) {
  1898. data.postData[col.field] = num;
  1899. if (exprInfo) {
  1900. data.postData[exprInfo.expr] = '';
  1901. }
  1902. } else {
  1903. try {
  1904. data.postData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  1905. if (exprInfo) {
  1906. data.postData[exprInfo.expr] = newText;
  1907. }
  1908. } catch(err) {
  1909. toastr.error('输入的表达式非法');
  1910. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1911. return;
  1912. }
  1913. }
  1914. } else if (col.field.indexOf('_expr') > 0) {
  1915. const exprInfo = getExprInfo(col.field, true);
  1916. if (!exprInfo) return;
  1917. if (newText) {
  1918. try {
  1919. data.postData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  1920. data.postData[exprInfo.expr] = newText;
  1921. } catch(err) {
  1922. toastr.error('输入的表达式非法');
  1923. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1924. return;
  1925. }
  1926. } else {
  1927. data.postData[exprInfo.qty] = 0;
  1928. data.postData[exprInfo.expr] = '';
  1929. }
  1930. } else {
  1931. data.postData[col.field] = newText;
  1932. }
  1933. }
  1934. postData(window.location.pathname + '/update', data, function (result) {
  1935. changeList = result.changeList;
  1936. const updateRst = pos.updateDatas(result.pos);
  1937. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1938. if (updateRst.create.length > 0) {
  1939. posSpreadObj.loadCurPosData();
  1940. } else {
  1941. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1942. }
  1943. const loadResult = billsTree.loadPostData(result.ledger);
  1944. // 判断是否只剩一个,并同步去勾
  1945. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1946. billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  1947. if (loadResult.update) {
  1948. const r = _.find(loadResult.update, { id: billsNode.id });
  1949. r.is_change = billsNode.is_change;
  1950. } else {
  1951. loadResult.update = [billsNode];
  1952. }
  1953. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1954. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1955. }, function () {
  1956. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1957. });
  1958. },
  1959. /**
  1960. * 删除按钮响应事件
  1961. * @param sheet
  1962. */
  1963. deletePress: function (sheet) {
  1964. if (!sheet.zh_setting) return;
  1965. const sortData = sheet.zh_data;
  1966. const datas = [], posSelects = [];
  1967. const sel = sheet.getSelections()[0];
  1968. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1969. let bDel = false;
  1970. const node = sortData[iRow];
  1971. if (node) {
  1972. const data = {id: node.id};
  1973. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1974. const colSetting = sheet.zh_setting.cols[iCol];
  1975. if (colSetting.field === 'name') {
  1976. toastr.error('部位名称不能为空');
  1977. return;
  1978. }
  1979. const style = sheet.getStyle(iRow, iCol);
  1980. if (!style.locked) {
  1981. const colSetting = sheet.zh_setting.cols[iCol];
  1982. if (colSetting.field.indexOf('_expr') > 0) {
  1983. const exprInfo = getExprInfo(colSetting.field, true);
  1984. if (!exprInfo) continue;
  1985. data[exprInfo.expr] = '';
  1986. data[exprInfo.qty] = 0;
  1987. } else {
  1988. data[colSetting.field] = null;
  1989. const exprInfo = getExprInfo(colSetting.field);
  1990. if (exprInfo) data[exprInfo.expr] = '';
  1991. }
  1992. bDel = true;
  1993. }
  1994. }
  1995. if (bDel) {
  1996. datas.push(data);
  1997. posSelects.push(node);
  1998. }
  1999. }
  2000. }
  2001. if (datas.length > 0) {
  2002. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  2003. changeList = result.changeList;
  2004. pos.updateDatas(result.pos);
  2005. posSpreadObj.loadCurPosData();
  2006. const loadResult = billsTree.loadPostData(result.ledger);
  2007. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2008. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2009. }, function () {
  2010. posSpreadObj.loadCurPosData();
  2011. });
  2012. }
  2013. },
  2014. /**
  2015. * 删除 计量单元
  2016. * @param sheet
  2017. */
  2018. deletePos: function (sheet) {
  2019. const selection = sheet.getSelections();
  2020. const data = {
  2021. postType: 'pos',
  2022. posPostType: 'delete',
  2023. postData: [],
  2024. };
  2025. const row = selection[0].row, count = selection[0].rowCount;
  2026. const sortData = sheet.zh_data;
  2027. for (let iRow = 0; iRow < count; iRow++) {
  2028. const posData = sortData[iRow + row];
  2029. if (posData) {
  2030. if (posData.used) {
  2031. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2032. return;
  2033. }
  2034. if (posData.settle_status === settleStatus.finish) {
  2035. toastr.error(`"${posData.name}"已计量,请勿删除`);
  2036. return;
  2037. }
  2038. data.postData.push(sortData[iRow + row].id);
  2039. }
  2040. }
  2041. if (data.postData.length > 0) {
  2042. postData(window.location.pathname + '/update', data, function (result) {
  2043. changeList = result.changeList;
  2044. pos.removeDatas(result.pos);
  2045. sheet.deleteRows(row, count);
  2046. const loadResult = billsTree.loadPostData(result.ledger);
  2047. // 判断是否只剩一个,并同步去勾
  2048. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2049. billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  2050. if (loadResult.update) {
  2051. const r = _.find(loadResult.update, { id: billsNode.id });
  2052. r.is_change = billsNode.is_change;
  2053. } else {
  2054. loadResult.update = [billsNode];
  2055. }
  2056. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2057. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2058. });
  2059. }
  2060. },
  2061. /**
  2062. * 粘贴单元格响应事件
  2063. * @param e
  2064. * @param info
  2065. */
  2066. clipboardPasted: function (e, info) {
  2067. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2068. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2069. }
  2070. const node = SpreadJsObj.getSelectObject(billsSheet);
  2071. if (node.code && (node.code !== '')) {
  2072. toastr.error('项目节不可含有节点明细');
  2073. posSpreadObj.loadCurPosData();
  2074. return;
  2075. }
  2076. if (node.children && (node.children.length > 0)) {
  2077. toastr.error('仅节点子项可以含有计量单元');
  2078. posSpreadObj.loadCurPosData();
  2079. return;
  2080. }
  2081. if (node.settle_status === settleStatus.finish) {
  2082. toastr.error('清单已结算,请勿修改计量单元数据');
  2083. posSpread.loadCurPosData();
  2084. return;
  2085. }
  2086. if (!info.sheet.zh_setting) {
  2087. posSpreadObj.loadCurPosData();
  2088. return;
  2089. }
  2090. const data = [];
  2091. const sortData = info.sheet.zh_data || [];
  2092. const hint = {
  2093. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2094. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  2095. };
  2096. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  2097. const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
  2098. if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
  2099. toastr.warning('新增计量单元请先输入名称');
  2100. posSpreadObj.loadCurPosData();
  2101. return;
  2102. }
  2103. }
  2104. let bHint = false;
  2105. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2106. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2107. let bPaste = true;
  2108. const curRow = info.cellRange.row + iRow;
  2109. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  2110. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2111. const curCol = info.cellRange.col + iCol;
  2112. const colSetting = info.sheet.zh_setting.cols[curCol];
  2113. if (!colSetting) continue;
  2114. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2115. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  2116. bPaste = false;
  2117. toastMessageUniq(hint.settle);
  2118. continue;
  2119. }
  2120. if (colSetting.type === 'Number') {
  2121. const num = _.toNumber(posData[colSetting.field]);
  2122. if (num) {
  2123. posData[colSetting.field] = num;
  2124. } else {
  2125. try {
  2126. posData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(posData[colSetting.field]));
  2127. const exprInfo = getExprInfo(colSetting.field);
  2128. if (exprInfo) {
  2129. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2130. }
  2131. } catch (err) {
  2132. if (!bHint) {
  2133. toastr.warning('粘贴了非法表达式,已过滤');
  2134. bHint = true;
  2135. }
  2136. bPaste = false;
  2137. }
  2138. }
  2139. } else if (colSetting.field.indexOf('_expr') > 0) {
  2140. try {
  2141. const exprInfo = getExprInfo(colSetting.field, true);
  2142. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2143. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  2144. posData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(posData[exprInfo.expr]));
  2145. }
  2146. bPaste = true;
  2147. } catch (err) {
  2148. toastMessageUniq(hint.expr);
  2149. }
  2150. } else {
  2151. bPaste = true;
  2152. }
  2153. }
  2154. if (bPaste) {
  2155. data.push(posData);
  2156. }
  2157. }
  2158. if (data.length === 0) {
  2159. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2160. return;
  2161. }
  2162. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  2163. changeList = result.changeList;
  2164. pos.updateDatas(result.pos);
  2165. posSpreadObj.loadCurPosData();
  2166. const loadResult = billsTree.loadPostData(result.ledger);
  2167. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2168. posSpreadObj.loadCurPosData();
  2169. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2170. }, function () {
  2171. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2172. });
  2173. },
  2174. selectionChanged: function (e, info) {
  2175. posSpreadObj.loadExprToInput();
  2176. posSpreadObj.refreshOperationValid(posSheet);
  2177. },
  2178. addPegs: function (pegs) {
  2179. if (!pegs || pegs.length <= 0) return;
  2180. const node = SpreadJsObj.getSelectObject(billsSheet);
  2181. if (!node) return;
  2182. const sheet = posSpread.getActiveSheet();
  2183. const sortData = sheet.zh_data || [];
  2184. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2185. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2186. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  2187. changeList = result.changeList;
  2188. pos.updateDatas(result.pos);
  2189. posSpreadObj.loadCurPosData();
  2190. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2191. });
  2192. }
  2193. };
  2194. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  2195. if (!readOnly && isTz) {
  2196. $('a[name="pos-opr"]').click(function () {
  2197. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  2198. });
  2199. $('#pos-expr').bind('change onblur', function () {
  2200. if (this.readOnly) return;
  2201. const expr = $(this);
  2202. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2203. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2204. if (!select) return;
  2205. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  2206. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  2207. const data = {id: select.id};
  2208. const exprInfo = getExprInfo(field);
  2209. if (newValue !== '') {
  2210. const num = _.toNumber(newValue);
  2211. if (num) {
  2212. data[field] = num;
  2213. if (exprInfo) data[exprInfo.expr] = '';
  2214. } else {
  2215. try {
  2216. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2217. if (exprInfo) data[exprInfo.expr] = newValue;
  2218. } catch (err) {
  2219. toastr.error('输入的表达式非法');
  2220. return;
  2221. }
  2222. }
  2223. } else {
  2224. data[field] = null;
  2225. if (exprInfo) data[exprInfo.expr] = '';
  2226. }
  2227. // 更新至服务器
  2228. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  2229. changeList = result.changeList;
  2230. const updateRst = pos.updateDatas(result.pos);
  2231. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2232. SpreadJsObj.reLoadRowData(posSheet, row);
  2233. const loadResult = billsTree.loadPostData(result.ledger);
  2234. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2235. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2236. });
  2237. });
  2238. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  2239. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  2240. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  2241. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  2242. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  2243. $.contextMenu({
  2244. selector: '#pos-spread',
  2245. build: function ($trigger, e) {
  2246. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  2247. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2248. },
  2249. items: {
  2250. 'delete': {
  2251. name: '删除',
  2252. icon: 'fa-remove',
  2253. disabled: function (key, opt) {
  2254. if (posSheet.zh_data) {
  2255. const selection = posSheet.getSelections();
  2256. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2257. const row = sel ? sel.row : -1;
  2258. const rowCount = sel.rowCount;
  2259. let settleFinish = false;
  2260. for (let i = row; i < row + rowCount; i++) {
  2261. if (!posSheet.zh_data[i]) continue;
  2262. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  2263. }
  2264. return (posSheet.zh_data.length < selection[0].row + selection[0].rowCount) || (posSheet.zh_data[selection[0].row] && !posSheet.zh_data[selection[0].row].formc) || settleFinish;
  2265. } else {
  2266. return true;
  2267. }
  2268. },
  2269. callback: function (key, opt) {
  2270. posSpreadObj.deletePos(posSheet);
  2271. }
  2272. },
  2273. }
  2274. });
  2275. }
  2276. // 加载清单&计量单元数据
  2277. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  2278. let gclGatherData;
  2279. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  2280. for (const b of result.bills) {
  2281. if (!(b.is_leaf && b.b_code)) {
  2282. b.is_change = 0;
  2283. } else {
  2284. const cInfo = _.find(changeList, { gcl_id: b.id });
  2285. b.is_change = cInfo ? 1 : 0;
  2286. }
  2287. }
  2288. billsTree.loadDatas(result.bills);
  2289. pos.loadDatas(result.pos);
  2290. treeCalc.calculateAll(billsTree);
  2291. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  2292. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  2293. checkShowLast(result.bills.length);
  2294. posSpreadObj.loadCurPosData();
  2295. SpreadJsObj.resetTopAndSelect(posSheet);
  2296. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2297. billsTreeSpreadObj.loadExprToInput(billsSheet);
  2298. checkList.loadHisCheckData();
  2299. console.log(billsTree);
  2300. }, null);
  2301. $.divResizer({
  2302. select: '#revise-resize',
  2303. callback: function () {
  2304. billsSpread.refresh();
  2305. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2306. $(".sp-wrap").height(bcontent-30);
  2307. posSpread.refresh();
  2308. }
  2309. });
  2310. function makeGclGatherData() {
  2311. gclGatherModel.loadLedgerData(billsTree.datas);
  2312. gclGatherModel.loadPosData(pos.datas);
  2313. gclGatherData = gclGatherModel.gatherGclData();
  2314. gclGatherData = _.filter(gclGatherData, function (item) {
  2315. return item.leafXmjs && item.leafXmjs.length !== 0;
  2316. });
  2317. gclGatherData = gclGatherData.sort(sortByCode);
  2318. console.log(gclGatherData);
  2319. }
  2320. class DealBills {
  2321. constructor (selector, spreadSetting) {
  2322. const self = this;
  2323. this.loaded = false;
  2324. this.obj = $(selector)[0];
  2325. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2326. this.spreadSetting = spreadSetting;
  2327. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2328. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2329. if (!readOnly) {
  2330. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2331. const dealSheet = info.sheet;
  2332. const mainSheet = billsSheet;
  2333. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2334. if (!dealBills) { return; }
  2335. const mainTree = mainSheet.zh_tree;
  2336. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2337. if (!mainNode || !mainTree) { return; }
  2338. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2339. toastr.warning('非最底层项目下,不应添加节点');
  2340. return;
  2341. }
  2342. if (mainNode.settle_status === settleStatus.finish) {
  2343. toastr.warning('已结算节点下,不应添加签约清单');
  2344. return;
  2345. }
  2346. postData(window.location.pathname + '/update', {
  2347. postType: 'add-deal',
  2348. postData: {
  2349. id: mainNode.ledger_id,
  2350. type: mainNode.code ? 'child' : 'next',
  2351. dealBills: {
  2352. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2353. unit_price: dealBills.unit_price,
  2354. }
  2355. },
  2356. }, function (result) {
  2357. changeList = result.changeList;
  2358. const refreshData = mainTree.loadPostData(result);
  2359. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2360. const sel = mainSheet.getSelections()[0];
  2361. if (sel && refreshData.create[0]) {
  2362. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2363. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2364. }
  2365. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2366. billsSpread.focus();
  2367. posSpreadObj.loadCurPosData();
  2368. });
  2369. });
  2370. }
  2371. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2372. }
  2373. loadData (callback) {
  2374. if (this.loaded) {
  2375. if (callback) callback();
  2376. return;
  2377. }
  2378. const self = this;
  2379. postData(this.url+'/get-data', {}, function (data) {
  2380. self.data = data;
  2381. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2382. self.loaded = true;
  2383. if (callback) callback();
  2384. });
  2385. }
  2386. calculateData () {
  2387. if (this.data) {
  2388. for (const d of this.data) {
  2389. d.total_price = _.multiply(d.quantity, d.unit_price);
  2390. }
  2391. }
  2392. }
  2393. }
  2394. class BatchInsertBillsPosObj {
  2395. constructor (obj) {
  2396. const self = this;
  2397. this.obj = obj;
  2398. this.billsCount = 6;
  2399. this.posCount = 1000;
  2400. this.filter = getLocalCache('zh-calc-batch-filter');
  2401. if (!this.filter) {
  2402. this.filter = '1';
  2403. }
  2404. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2405. // 初始化 清单编号窗口 参数
  2406. this.qdSpreadSetting = {
  2407. cols: [
  2408. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2409. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2410. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2411. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2412. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2413. ],
  2414. emptyRows: this.billsCount,
  2415. headRows: 1,
  2416. headRowHeight: [32],
  2417. headerFont: '12px 微软雅黑',
  2418. font: '12px 微软雅黑',
  2419. };
  2420. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2421. // 初始化 部位数量复核表 参数
  2422. this.posSpreadSetting = {
  2423. cols: [
  2424. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2425. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2426. ],
  2427. emptyRows: this.posCount,
  2428. headRows: 1,
  2429. headRowHeight: [32],
  2430. headerFont: '12px 微软雅黑',
  2431. font: '12px 微软雅黑',
  2432. };
  2433. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2434. this.posSpreadSetting.cols.push(
  2435. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2436. )
  2437. }
  2438. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2439. // 初始化 签约节点 参数
  2440. this.dealSpreadSetting = {
  2441. cols: [
  2442. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2443. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2444. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2445. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2446. ],
  2447. emptyRows: 0,
  2448. headRows: 1,
  2449. headRowHeight: [32],
  2450. headerFont: '12px 微软雅黑',
  2451. font: '12px 微软雅黑',
  2452. };
  2453. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2454. // 初始化 清单编号、部位数量复核表 表格
  2455. this.initView();
  2456. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2457. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2458. // 拉取签约节点数据
  2459. dealBills.loadData(() => {
  2460. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2461. });
  2462. // 双击签约节点,自动添加到清单编号窗口
  2463. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  2464. const deal = info.sheet.zh_data[info.row];
  2465. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2466. const sel = qdSheet.getSelections()[0];
  2467. qdSheet.getCell(sel.row, 0).value(deal.code);
  2468. qdSheet.getCell(sel.row, 1).value(deal.name);
  2469. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2470. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2471. if (sel.row + 1 === qdSheet.getRowCount()) {
  2472. const count = sel.row + 2;
  2473. qdSheet.setRowCount(count);
  2474. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2475. const colCount = posSheet.getColumnCount() + 1;
  2476. posSheet.setColumnCount(colCount);
  2477. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2478. }
  2479. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2480. qdSheet.getParent().focus();
  2481. });
  2482. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2483. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  2484. const count = posSheet.getColumnCount() - 2;
  2485. if (billsCount > count) {
  2486. posSheet.setColumnCount(billsCount + 2);
  2487. for (let i = count + 1; i <= billsCount; i++) {
  2488. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2489. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2490. }
  2491. }
  2492. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  2493. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2494. if (dealBills && dealBills.length > 0) {
  2495. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2496. const curRow = iRow + info.cellRange.row;
  2497. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  2498. if (bills) {
  2499. info.sheet.getCell(curRow, 1).value(bills.name);
  2500. info.sheet.getCell(curRow, 2).value(bills.unit);
  2501. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  2502. }
  2503. }
  2504. }
  2505. }
  2506. });
  2507. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2508. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  2509. const count = qdSheet.getRowCount();
  2510. if (billsCount > count) {
  2511. qdSheet.setRowCount(billsCount);
  2512. for (let i = count + 1; i <= billsCount; i++) {
  2513. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2514. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2515. }
  2516. }
  2517. });
  2518. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2519. if (info.col === 0) {
  2520. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2521. if (dealBills && dealBills.length > 0) {
  2522. const bills = _.find(dealBills, {code: info.editingText});
  2523. if (bills) {
  2524. info.sheet.getCell(info.row, 1).value(bills.name);
  2525. info.sheet.getCell(info.row, 2).value(bills.unit);
  2526. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2527. }
  2528. }
  2529. }
  2530. });
  2531. this.obj.bind('shown.bs.modal', function () {
  2532. self.qdSpread.refresh();
  2533. self.posSpread.refresh();
  2534. self.dealSpread.refresh();
  2535. });
  2536. $('#batch-ok').click(function () {
  2537. const selection = billsSheet.getSelections();
  2538. const sel = selection[0];
  2539. const row = selection[0].row;
  2540. const select = billsTree.nodes[row];
  2541. if (select) {
  2542. const insertData = {};
  2543. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2544. insertData.id = select[billsTree.setting.id];
  2545. insertData.batchData = self.getBatchData();
  2546. if (insertData.batchData.length > 0) {
  2547. postData(window.location.pathname + '/update', {
  2548. postType: 'batch-insert',
  2549. postData: insertData
  2550. }, function (data) {
  2551. changeList = result.changeList;
  2552. pos.updateDatas(data.pos);
  2553. const result = billsTree.loadPostData(data.ledger);
  2554. billsTreeSpreadObj.refreshTree(billsSheet, result);
  2555. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2556. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  2557. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  2558. posSpreadObj.loadCurPosData();
  2559. self.obj.modal('hide');
  2560. }, null, true);
  2561. } else {
  2562. self.obj.modal('hide');
  2563. }
  2564. }
  2565. });
  2566. $('input[name=batch-filter]').change(function () {
  2567. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  2568. });
  2569. $.contextMenu({
  2570. selector: '.batch-l-t',
  2571. build: function ($trigger, e) {
  2572. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2573. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2574. },
  2575. items: {
  2576. 'create': {
  2577. name: '新增行',
  2578. icon: 'fa-sign-in',
  2579. callback: function (key, opt) {
  2580. const qdSheet = self.qdSpread.getActiveSheet();
  2581. const posSheet = self.posSpread.getActiveSheet();
  2582. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2583. const index = qdSheet.getRowCount();
  2584. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2585. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2586. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2587. },
  2588. },
  2589. 'delete': {
  2590. name: '删除行',
  2591. icon: 'fa-remove',
  2592. callback: function (key, opt) {
  2593. const qdSheet = self.qdSpread.getActiveSheet();
  2594. const posSheet = self.posSpread.getActiveSheet();
  2595. const sel = qdSheet.getSelections()[0];
  2596. qdSheet.deleteRows(sel.row, sel.rowCount);
  2597. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2598. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2599. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2600. }
  2601. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2602. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2603. }
  2604. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2605. },
  2606. },
  2607. }
  2608. });
  2609. }
  2610. // 初始化左侧表格
  2611. initView () {
  2612. // 初始化 清单编号
  2613. const qdSheet = this.qdSpread.getActiveSheet();
  2614. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2615. SpreadJsObj.refreshColumnAlign(qdSheet);
  2616. // 清理原有数据
  2617. SpreadJsObj.beginMassOperation(qdSheet);
  2618. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2619. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2620. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2621. }
  2622. qdSheet.setSelection(0, 0, 1 ,1);
  2623. SpreadJsObj.endMassOperation(qdSheet);
  2624. // 初始化 部位数量复核表
  2625. const posSheet = this.posSpread.getActiveSheet();
  2626. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2627. SpreadJsObj.refreshColumnAlign(posSheet);
  2628. // 清理原有数据
  2629. SpreadJsObj.beginMassOperation(posSheet);
  2630. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2631. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2632. posSheet.setSelection(0, 0, 1 ,1);
  2633. SpreadJsObj.endMassOperation(posSheet);
  2634. // 检查签约节点数据,以工具栏数据为准
  2635. if (dealBills) {
  2636. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2637. }
  2638. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2639. }
  2640. // 获取界面数据
  2641. getBatchData () {
  2642. const result = [];
  2643. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2644. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2645. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2646. const qd = {
  2647. b_code: qdSheet.getText(iRow, 0),
  2648. name: qdSheet.getText(iRow, 1),
  2649. unit: qdSheet.getText(iRow, 2),
  2650. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2651. pos: [],
  2652. };
  2653. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2654. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2655. if (value !== 0 && !isNaN(value)) {
  2656. qd.pos.push({
  2657. name: posSheet.getText(iPosRow, 0),
  2658. drawing_code: posSheet.getText(iPosRow, 1),
  2659. quantity: value, porder: qd.pos.length + 1,
  2660. });
  2661. }
  2662. }
  2663. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2664. }
  2665. return result;
  2666. }
  2667. }
  2668. const dealBills = new DealBills('#deal-bills-spread', {
  2669. cols: [
  2670. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2671. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2672. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2673. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2674. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2675. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2676. ],
  2677. emptyRows: 0,
  2678. headRows: 1,
  2679. headRowHeight: [32],
  2680. headColWidth: [30],
  2681. defaultRowHeight: 21,
  2682. headerFont: '12px 微软雅黑',
  2683. font: '12px 微软雅黑',
  2684. selectedBackColor: '#fffacd',
  2685. });
  2686. class Jlzf {
  2687. constructor (selector, spreadSetting) {
  2688. const self = this;
  2689. this.loaded = false;
  2690. this.obj = $(selector);
  2691. const relaSelect = {
  2692. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2693. searchText: `cb-${spreadSetting.stdType}-st`,
  2694. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2695. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2696. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2697. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2698. };
  2699. this.obj.html(
  2700. '<div class="sjs-bar d-flex">\n' +
  2701. ' <div class="ml-1">\n' +
  2702. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  2703. ' <div class="d-inline-block">\n' +
  2704. ' <div class="input-group input-group-sm mr-1">' +
  2705. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2706. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2707. ' <div class="input-group-append" >\n' +
  2708. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2709. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2710. ' </div>\n' +
  2711. ' </div>\n' +
  2712. ' </div>\n' +
  2713. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2714. ' </div>\n' +
  2715. ' </div>' +
  2716. '</div>\n' +
  2717. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2718. );
  2719. autoFlashHeight();
  2720. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2721. function getObjHeight(select) {
  2722. return select.length > 0 ? select.height() : 0;
  2723. }
  2724. const cHeader = getObjHeight($(".c-header"));
  2725. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2726. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2727. this.spreadSetting = spreadSetting;
  2728. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2729. const searchSheet = this.spread.getActiveSheet();
  2730. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2731. if (!readOnly) {
  2732. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2733. const dealSheet = info.sheet;
  2734. const mainSheet = billsSheet;
  2735. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2736. if (!dealBills) { return; }
  2737. const mainTree = mainSheet.zh_tree;
  2738. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2739. if (!mainNode || !mainTree) { return; }
  2740. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2741. toastr.warning('非最底层项目下,不应添加节点');
  2742. return;
  2743. }
  2744. if (mainNode.settle_status === settleStatus.finish) {
  2745. toastr.warning('已结算节点下,不应添加签约清单');
  2746. return;
  2747. }
  2748. postData(window.location.pathname + '/update', {
  2749. postType: 'add-deal',
  2750. postData: {
  2751. id: mainNode.ledger_id,
  2752. type: mainNode.code ? 'child' : 'next',
  2753. dealBills: {
  2754. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2755. unit_price: dealBills.unit_price,
  2756. }
  2757. },
  2758. }, function (result) {
  2759. changeList = result.changeList;
  2760. const refreshData = mainTree.loadPostData(result);
  2761. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2762. const sel = mainSheet.getSelections()[0];
  2763. if (sel && refreshData.create[0]) {
  2764. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2765. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2766. }
  2767. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2768. billsSpread.focus();
  2769. posSpreadObj.loadCurPosData();
  2770. });
  2771. });
  2772. }
  2773. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2774. const searchObj = {
  2775. result: [],
  2776. cur: 0,
  2777. searchStdNode: function() {
  2778. const keyword = $(`#${relaSelect.searchText}`).val();
  2779. const sortData = SpreadJsObj.getSortData(searchSheet);
  2780. searchObj.result = keyword ? sortData.filter(x => {
  2781. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  2782. }) : [];
  2783. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  2784. searchObj.cur = 0;
  2785. if (searchObj.result.length > 0) {
  2786. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2787. }
  2788. },
  2789. searchPre: function () {
  2790. if (searchObj.result.length === 0) return;
  2791. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  2792. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2793. },
  2794. searchNext: function () {
  2795. if (searchObj.result.length === 0) return;
  2796. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  2797. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2798. },
  2799. clear: function () {
  2800. $(`#${relaSelect.searchText}`).val('');
  2801. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  2802. searchObj.result = [];
  2803. searchObj.cur = 0;
  2804. }
  2805. };
  2806. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  2807. $(`#${relaSelect.searchPre}`).click(function (e) {
  2808. searchObj.searchPre();
  2809. e.stopPropagation();
  2810. });
  2811. $(`#${relaSelect.searchNext}`).click(function (e) {
  2812. searchObj.searchNext();
  2813. e.stopPropagation();
  2814. });
  2815. $(`#${relaSelect.searchClose}`).click(function (e) {
  2816. searchObj.clear();
  2817. e.stopPropagation();
  2818. });
  2819. };
  2820. loadData (callback) {
  2821. // if (this.loaded) {
  2822. // if (callback) callback();
  2823. // return;
  2824. // }
  2825. const self = this;
  2826. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  2827. const showDatas = [];
  2828. for (const d of datas) {
  2829. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  2830. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  2831. }
  2832. }
  2833. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  2834. // self.loaded = true;
  2835. if (callback) callback();
  2836. }
  2837. }
  2838. const jlzfBills = new Jlzf('#jlzf-spread', {
  2839. cols: [
  2840. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2841. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  2842. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2843. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2844. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2845. ],
  2846. emptyRows: 0,
  2847. headRows: 1,
  2848. headRowHeight: [32],
  2849. headColWidth: [30],
  2850. defaultRowHeight: 21,
  2851. headerFont: '12px 微软雅黑',
  2852. font: '12px 微软雅黑',
  2853. selectedBackColor: '#fffacd',
  2854. readOnly: true,
  2855. stdType: 'jlzf',
  2856. });
  2857. class Dsk {
  2858. constructor (selector, spreadSetting) {
  2859. const self = this;
  2860. this.loaded = false;
  2861. this.obj = $(selector);
  2862. const dskProjectHtml = spreadSetting.libs.map(l => {
  2863. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  2864. });
  2865. const relaSelect = {
  2866. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2867. searchText: `cb-${spreadSetting.stdType}-st`,
  2868. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2869. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2870. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2871. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2872. };
  2873. this.obj.html(
  2874. '<div class="sjs-bar d-flex">\n' +
  2875. ' <div class="dropdown mr-1">\n' +
  2876. ' <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2877. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  2878. ' </button>\n' +
  2879. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  2880. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  2881. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  2882. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  2883. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  2884. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  2885. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  2886. ' </div>\n' +
  2887. ' </div>' +
  2888. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project">${dskProjectHtml.join('')}</select></div>\n` +
  2889. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project-tree"></select></div>\n` +
  2890. ' <div class="ml-1">\n' +
  2891. ' <div class="dropdown">\n' +
  2892. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2893. ' <i class="fa fa-search"></i>\n' +
  2894. ' </button>\n' +
  2895. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  2896. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  2897. ' <div class="d-inline-block">\n' +
  2898. ' <div class="input-group input-group-sm mr-1">' +
  2899. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2900. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2901. ' <div class="input-group-append" >\n' +
  2902. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2903. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2904. ' </div>\n' +
  2905. ' </div>\n' +
  2906. ' </div>\n' +
  2907. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2908. ' </div>\n' +
  2909. ' </div>\n' +
  2910. ' </div>\n' +
  2911. ' </div>' +
  2912. '</div>\n' +
  2913. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2914. );
  2915. autoFlashHeight();
  2916. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2917. function getObjHeight(select) {
  2918. return select.length > 0 ? select.height() : 0;
  2919. }
  2920. const cHeader = getObjHeight($(".c-header"));
  2921. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2922. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2923. this.spreadSetting = spreadSetting;
  2924. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2925. const searchSheet = this.spread.getActiveSheet();
  2926. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2927. (function (select, sheet) {
  2928. $(select).click(function () {
  2929. if (!sheet.zh_tree) return;
  2930. const tag = $(this).attr('tag');
  2931. const tree = sheet.zh_tree;
  2932. setTimeout(() => {
  2933. switch (tag) {
  2934. case "1":
  2935. case "2":
  2936. case "3":
  2937. case "4":
  2938. case "5":
  2939. tree.expandByLevel(parseInt(tag));
  2940. SpreadJsObj.refreshTreeRowVisible(sheet);
  2941. break;
  2942. case "last":
  2943. tree.expandByCustom(() => { return true; });
  2944. SpreadJsObj.refreshTreeRowVisible(sheet);
  2945. break;
  2946. }
  2947. }, 100);
  2948. });
  2949. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  2950. if (!readOnly) {
  2951. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2952. const dealSheet = info.sheet;
  2953. const mainSheet = billsSheet;
  2954. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2955. if (!dealBills) { return; }
  2956. const mainTree = mainSheet.zh_tree;
  2957. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2958. if (!mainNode || !mainTree) { return; }
  2959. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2960. toastr.warning('非最底层项目下,不应添加节点');
  2961. return;
  2962. }
  2963. if (mainNode.settle_status === settleStatus.finish) {
  2964. toastr.warning('已结算节点下,不应添加签约清单');
  2965. return;
  2966. }
  2967. const is_bill = dealBills.kind === 4;
  2968. const oneBills = {
  2969. b_code: is_bill ? dealBills.code : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  2970. unit_price: is_bill ? dealBills.unitPrice : null, quantity: is_bill ? dealBills.quantity : null, total_price: is_bill ? dealBills.totalPrice : null,
  2971. sgfh_qty: is_bill ? dealBills.quantity : null, sgfh_tp: is_bill ? dealBills.totalPrice : null,
  2972. };
  2973. postData(window.location.pathname + '/update', {
  2974. postType: 'add-deal',
  2975. postData: {
  2976. id: mainNode.ledger_id,
  2977. type: mainNode.code ? 'child' : 'next',
  2978. dealBills: oneBills,
  2979. },
  2980. }, function (result) {
  2981. changeList = result.changeList;
  2982. const refreshData = mainTree.loadPostData(result);
  2983. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2984. const sel = mainSheet.getSelections()[0];
  2985. if (sel && refreshData.create[0]) {
  2986. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2987. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2988. }
  2989. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2990. billsSpread.focus();
  2991. posSpreadObj.loadCurPosData();
  2992. });
  2993. });
  2994. }
  2995. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2996. const searchObj = {
  2997. result: [],
  2998. cur: 0,
  2999. searchStdNode: function() {
  3000. const keyword = $(`#${relaSelect.searchText}`).val();
  3001. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  3002. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  3003. }) : [];
  3004. // searchObj.result = [];
  3005. // for (const x of pathTree.nodes) {
  3006. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  3007. // searchObj.result.push(x);
  3008. // }
  3009. // }
  3010. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  3011. searchObj.cur = 0;
  3012. if (searchObj.result.length > 0) {
  3013. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  3014. }
  3015. },
  3016. searchPre: function () {
  3017. if (searchObj.result.length === 0) return;
  3018. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  3019. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3020. },
  3021. searchNext: function () {
  3022. if (searchObj.result.length === 0) return;
  3023. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  3024. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3025. },
  3026. clear: function () {
  3027. $(`#${relaSelect.searchText}`).val('');
  3028. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  3029. searchObj.result = [];
  3030. searchObj.cur = 0;
  3031. }
  3032. };
  3033. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  3034. $(`#${relaSelect.searchPre}`).click(function (e) {
  3035. searchObj.searchPre();
  3036. e.stopPropagation();
  3037. });
  3038. $(`#${relaSelect.searchNext}`).click(function (e) {
  3039. searchObj.searchNext();
  3040. e.stopPropagation();
  3041. });
  3042. $(`#${relaSelect.searchClose}`).click(function (e) {
  3043. searchObj.clear();
  3044. e.stopPropagation();
  3045. });
  3046. };
  3047. loadData (callback) {
  3048. if (this.loaded) {
  3049. if (callback) callback();
  3050. return;
  3051. }
  3052. const self = this;
  3053. if (dskAccountData && dskAccountData.select_project) {
  3054. self.loaded = true;
  3055. changeDskProject(dskAccountData.select_project);
  3056. } else {
  3057. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  3058. self.loaded = true;
  3059. }
  3060. if (callback) callback();
  3061. }
  3062. }
  3063. $('body').on('change', '#change-dsk-project', function () {
  3064. const pid = $(this).val();
  3065. changeDskProject(pid);
  3066. });
  3067. $('body').on('change', '#change-dsk-project-tree', function () {
  3068. const treeId = $(this).val();
  3069. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  3070. changeDskProjectTree(projectInfo, treeId);
  3071. });
  3072. function setDskProjectTreeSelect(trees) {
  3073. let html = '';
  3074. for (const tree of trees) {
  3075. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  3076. }
  3077. $('#change-dsk-project-tree').html(html);
  3078. }
  3079. function changeDskProject(pid) {
  3080. const projectInfo = _.find(dskProjects, { pid });
  3081. if (!projectInfo) {
  3082. dskAccountData.select_project = null;
  3083. dskAccountData.select_tree = null;
  3084. const tree = dskProjectBills2Tree.convert([]);
  3085. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3086. return;
  3087. }
  3088. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  3089. const trees = _.filter(datas, x => x.type === 4);
  3090. dskAccountData.select_project = projectInfo.pid;
  3091. setDskProjectTreeSelect(trees);
  3092. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  3093. });
  3094. }
  3095. function changeDskProjectTree(projectInfo, treeId) {
  3096. dskAccountData.select_tree = treeId;
  3097. if (!treeId) {
  3098. const tree = dskProjectBills2Tree.convert([]);
  3099. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3100. return;
  3101. }
  3102. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  3103. const tree = dskProjectBills2Tree.convert(result);
  3104. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3105. });
  3106. }
  3107. const dskBills = new Dsk('#dsk-spread', {
  3108. cols: [
  3109. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  3110. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  3111. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3112. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  3113. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  3114. ],
  3115. emptyRows: 0,
  3116. headRows: 1,
  3117. headRowHeight: [32],
  3118. headColWidth: [30],
  3119. defaultRowHeight: 21,
  3120. headerFont: '12px 微软雅黑',
  3121. font: '12px 微软雅黑',
  3122. selectedBackColor: '#fffacd',
  3123. readOnly: true,
  3124. stdType: 'dsk',
  3125. libs: dskProjects,
  3126. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  3127. });
  3128. const dskProjectBills2Tree = (function () {
  3129. const treeSetting = {
  3130. id: 'dpb_id',
  3131. pid: 'dpb_pid',
  3132. order: 'seq',
  3133. level: 'level',
  3134. rootId: '-1',
  3135. fullPath: 'full_path',
  3136. };
  3137. const tenderTree = createNewPathTree('gather', treeSetting);
  3138. function setChildrenNode(node, dxs, files, tenders) {
  3139. const dxchildren = _.filter(dxs, { parentID: node.bid });
  3140. const children = _.filter(files, { parentID: node.bid });
  3141. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  3142. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  3143. for (const t of checkChildren) {
  3144. const child = {
  3145. bid: t.ID,
  3146. parentID: t.parentID,
  3147. name: t.name,
  3148. kind: t.kind,
  3149. code: t.code,
  3150. quantity: t.quantity,
  3151. quantity2: t.quantity2,
  3152. unit: t.unit,
  3153. unitPrice: t.unitPrice,
  3154. totalPrice: t.totalPrice,
  3155. formulaCode: t.formulaCode,
  3156. flag: t.flag,
  3157. remark: t.remark,
  3158. };
  3159. tenderTree.addNode(child, node);
  3160. setChildrenNode(child, dxs, files, tenders);
  3161. }
  3162. }
  3163. function convert (projects) {
  3164. tenderTree.clearDatas();
  3165. // 区分文件夹及项目
  3166. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  3167. const dxs = _.filter(projects, { kind: 1 });
  3168. const files = _.filter(projects, { kind: 4 });
  3169. const tenders = _.filter(projects, { kind: 8 });
  3170. for (const t of topLevel) {
  3171. const node = {
  3172. bid: t.ID,
  3173. parentID: t.parentID,
  3174. name: t.name,
  3175. kind: t.kind,
  3176. code: t.code,
  3177. quantity: t.quantity,
  3178. quantity2: t.quantity2,
  3179. unit: t.unit,
  3180. unitPrice: t.unitPrice,
  3181. totalPrice: t.totalPrice,
  3182. formulaCode: t.formulaCode,
  3183. flag: t.flag,
  3184. remark: t.remark,
  3185. };
  3186. tenderTree.addNode(node, null);
  3187. setChildrenNode(node, dxs, files, tenders);
  3188. }
  3189. tenderTree.sortTreeNode(true);
  3190. return tenderTree;
  3191. }
  3192. return { tenderTree, convert }
  3193. })();
  3194. $.divResizer({
  3195. select: '#revise-right-spr',
  3196. callback: function () {
  3197. billsSpread.refresh();
  3198. if (posSpread) posSpread.refresh();
  3199. if (stdXmj) stdXmj.spread.refresh();
  3200. if (stdGcl) stdGcl.spread.refresh();
  3201. if (dealBills) dealBills.spread.refresh();
  3202. if (searchLedger) searchLedger.spread.refresh();
  3203. if (errorList) errorList.spread.refresh();
  3204. if (checkList) checkList.spread.refresh();
  3205. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3206. if (jlzfBills) jlzfBills.spread.refresh();
  3207. if (dskBills) dskBills.spread.refresh();
  3208. }
  3209. });
  3210. $.subMenu({
  3211. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  3212. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  3213. key: 'menu.1.0.0',
  3214. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  3215. callback: function (info) {
  3216. if (info.mini) {
  3217. $('.panel-title').addClass('fluid');
  3218. $('#sub-menu').removeClass('panel-sidebar');
  3219. } else {
  3220. $('.panel-title').removeClass('fluid');
  3221. $('#sub-menu').addClass('panel-sidebar');
  3222. }
  3223. autoFlashHeight();
  3224. billsSpread.refresh();
  3225. if (posSpread) posSpread.refresh();
  3226. if (stdXmj) stdXmj.spread.refresh();
  3227. if (stdGcl) stdGcl.spread.refresh();
  3228. if (dealBills) dealBills.spread.refresh();
  3229. if (searchLedger) searchLedger.spread.refresh();
  3230. if (errorList) errorList.spread.refresh();
  3231. if (checkList) checkList.spread.refresh();
  3232. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3233. if (jlzfBills) jlzfBills.spread.refresh();
  3234. if (dskBills) dskBills.spread.refresh();
  3235. }
  3236. });
  3237. // showSideTools(true);
  3238. billsSpread.refresh();
  3239. if (posSpread) posSpread.refresh();
  3240. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  3241. const mainSheet = billsSheet;
  3242. if (!stdTree || !mainSheet.zh_tree) { return; }
  3243. const mainTree = mainSheet.zh_tree;
  3244. const sel = mainSheet.getSelections()[0];
  3245. const mainNode = mainTree.nodes[sel.row];
  3246. if (!stdNode) return;
  3247. if (updateData.postData.stdType === 'gcl') {
  3248. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3249. toastr.warning('非最底层项目下,不应添加节点');
  3250. return;
  3251. }
  3252. if (mainNode.settle_status === settleStatus.finish) {
  3253. toastr.warning('已结算节点下,不可添加工程量清单');
  3254. return;
  3255. }
  3256. } else {
  3257. const stdNodes = stdTree.getAllParents(stdNode);
  3258. for (const node of stdNodes) {
  3259. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  3260. if (parent && parent.settle_status === settleStatus.finish) {
  3261. toastr.warning('项目节父项已结算,不可添加节点');
  3262. return;
  3263. }
  3264. }
  3265. }
  3266. postData(window.location.pathname + '/update', {
  3267. postType: 'add-std',
  3268. postData: {
  3269. id: mainTree.getNodeKey(mainNode),
  3270. tender_id: mainNode.tender_id,
  3271. stdType: updateData.postData.stdType,
  3272. stdLibId: stdNode.list_id,
  3273. stdNode: stdTree.getNodeKey(stdNode)
  3274. }
  3275. }, function (result) {
  3276. changeList = result.changeList;
  3277. const refreshNode = mainTree.loadPostData(result);
  3278. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  3279. if (sel) {
  3280. if (refreshNode.create && refreshNode.create.length > 0) {
  3281. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  3282. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  3283. } else {
  3284. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  3285. if (node) {
  3286. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  3287. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  3288. }
  3289. }
  3290. }
  3291. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3292. billsSpread.focus();
  3293. posSpreadObj.loadCurPosData();
  3294. });
  3295. };
  3296. const stdXmjSetting = {
  3297. selector: '#std-xmj',
  3298. stdType: 'xmj',
  3299. libs: stdChapters,
  3300. treeSetting: {
  3301. id: 'chapter_id',
  3302. pid: 'pid',
  3303. order: 'order',
  3304. level: 'level',
  3305. rootId: -1,
  3306. keys: ['id', 'list_id', 'chapter_id'],
  3307. },
  3308. spreadSetting: {
  3309. cols: [
  3310. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3311. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3312. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3313. ],
  3314. treeCol: 0,
  3315. emptyRows: 0,
  3316. headRows: 1,
  3317. headRowHeight: [32],
  3318. defaultRowHeight: 21,
  3319. headerFont: '12px 微软雅黑',
  3320. font: '12px 微软雅黑',
  3321. headColWidth: [30],
  3322. selectedBackColor: '#fffacd',
  3323. },
  3324. cellDoubleClick: stdLibCellDoubleClick,
  3325. page: 'revise',
  3326. tid: window.location.pathname.split('/')[2],
  3327. };
  3328. const stdGclSetting = {
  3329. selector: '#std-gcl',
  3330. stdType: 'gcl',
  3331. libs: stdBills,
  3332. treeSetting: {
  3333. id: 'bill_id',
  3334. pid: 'pid',
  3335. order: 'order',
  3336. level: 'level',
  3337. rootId: -1,
  3338. keys: ['id', 'list_id', 'bill_id']
  3339. },
  3340. spreadSetting: {
  3341. cols: [
  3342. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3343. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3344. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3345. ],
  3346. treeCol: 0,
  3347. emptyRows: 0,
  3348. headRows: 1,
  3349. headRowHeight: [32],
  3350. defaultRowHeight: 21,
  3351. headerFont: '12px 微软雅黑',
  3352. font: '12px 微软雅黑',
  3353. headColWidth: [30],
  3354. selectedBackColor: '#fffacd',
  3355. },
  3356. cellDoubleClick: stdLibCellDoubleClick,
  3357. page: 'revise',
  3358. tid: window.location.pathname.split('/')[2],
  3359. };
  3360. // 展开收起标准节点
  3361. $('a', '#side-menu').bind('click', function (e) {
  3362. e.preventDefault();
  3363. const tab = $(this), tabPanel = $(tab.attr('content'));
  3364. // 展开工具栏、切换标签
  3365. if (!tab.hasClass('active')) {
  3366. const close = $('.active', '#side-menu').length === 0;
  3367. $('a', '#side-menu').removeClass('active');
  3368. tab.addClass('active');
  3369. $('.tab-content .tab-pane').removeClass('active');
  3370. tabPanel.addClass('active');
  3371. showSideTools(tab.hasClass('active'));
  3372. if (tab.attr('content') === '#std-xmj') {
  3373. if (!stdXmj) {
  3374. stdXmj = $.stdLib(stdXmjSetting);
  3375. }
  3376. stdXmj.spread.refresh();
  3377. } else if (tab.attr('content') === '#std-gcl') {
  3378. if (!stdGcl) {
  3379. stdGcl = $.stdLib(stdGclSetting);
  3380. }
  3381. stdGcl.spread.refresh();
  3382. } else if (tab.attr('content') === '#deal-bills') {
  3383. dealBills.loadData();
  3384. dealBills.spread.refresh();
  3385. } else if (tab.attr('content') === '#search') {
  3386. if (!searchLedger) {
  3387. searchLedger = $.billsSearch({
  3388. selector: '#search',
  3389. searchSpread: billsSpread,
  3390. searchOver: true,
  3391. searchEmpty: true,
  3392. resultSpreadSetting: {
  3393. cols: [
  3394. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3395. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3396. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3397. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3398. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3399. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3400. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  3401. ],
  3402. emptyRows: 0,
  3403. headRows: 1,
  3404. headRowHeight: [32],
  3405. headColWidth: [30],
  3406. defaultRowHeight: 21,
  3407. headerFont: '12px 微软雅黑',
  3408. font: '12px 微软雅黑',
  3409. selectedBackColor: '#fffacd',
  3410. readOnly: true,
  3411. },
  3412. afterLocated: function () {
  3413. posSpreadObj.loadCurPosData();
  3414. },
  3415. customSearch: [
  3416. {
  3417. key: 'revise', title: '新增部位', valid: true, parent: true,
  3418. check: function (node) {
  3419. if (node.formc || node.cid) {
  3420. return true;
  3421. } else {
  3422. return false;
  3423. }
  3424. }
  3425. }
  3426. ],
  3427. });
  3428. }
  3429. searchLedger.spread.refresh();
  3430. } else if (tab.attr('content') === '#error-list') {
  3431. errorList.spread.refresh();
  3432. } else if (tab.attr('content') === '#check-list') {
  3433. checkList.spread.refresh();
  3434. } else if (tab.attr('content') === '#sum-load-miss') {
  3435. sumLoadMiss.spread.refresh();
  3436. } else if (tab.attr('content') === '#dsk-list') {
  3437. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  3438. $(dskActiveTab).addClass('active');
  3439. if (dskActiveTab === '#jlzf-spread') {
  3440. $('#get-dsk-btn').hide();
  3441. $('#get-dsk-bills-btn').hide();
  3442. jlzfBills.loadData();
  3443. jlzfBills.spread.refresh();
  3444. } else if (dskActiveTab === '#dsk-spread') {
  3445. $('#get-dsk-btn').show();
  3446. $('#get-dsk-bills-btn').show();
  3447. dskBills.loadData();
  3448. dskBills.spread.refresh();
  3449. }
  3450. }
  3451. }
  3452. else {// 收起工具栏
  3453. tab.removeClass('active');
  3454. tabPanel.removeClass('active');
  3455. showSideTools(tab.hasClass('active'));
  3456. }
  3457. billsSpread.refresh();
  3458. if (posSpread) posSpread.refresh();
  3459. });
  3460. // 新增清单切换tab
  3461. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  3462. e.preventDefault();
  3463. const dskActiveTab = $(this).attr('href');
  3464. if (dskActiveTab === '#jlzf-spread') {
  3465. $('#get-dsk-btn').hide();
  3466. $('#get-dsk-bills-btn').hide();
  3467. jlzfBills.loadData();
  3468. jlzfBills.spread.refresh();
  3469. } else if (dskActiveTab === '#dsk-spread') {
  3470. $('#get-dsk-btn').show();
  3471. $('#get-dsk-bills-btn').show();
  3472. dskBills.loadData();
  3473. dskBills.spread.refresh();
  3474. }
  3475. });
  3476. // 显示层次
  3477. (function (select, sheet) {
  3478. $(select).click(function () {
  3479. if (!sheet.zh_tree) return;
  3480. const tag = $(this).attr('tag');
  3481. const tree = sheet.zh_tree;
  3482. setTimeout(() => {
  3483. showWaitingView();
  3484. switch (tag) {
  3485. case "1":
  3486. case "2":
  3487. case "3":
  3488. case "4":
  3489. case "5":
  3490. tree.expandByLevel(parseInt(tag));
  3491. SpreadJsObj.refreshTreeRowVisible(sheet);
  3492. break;
  3493. case "last":
  3494. tree.expandByCustom(() => { return true; });
  3495. SpreadJsObj.refreshTreeRowVisible(sheet);
  3496. break;
  3497. case "leafXmj":
  3498. tree.expandToLeafXmj();
  3499. SpreadJsObj.refreshTreeRowVisible(sheet);
  3500. break;
  3501. }
  3502. closeWaitingView();
  3503. }, 100);
  3504. });
  3505. })('a[name=showLevel]', billsSheet);
  3506. if (openRevise) {
  3507. const dataChecker = DataChecker({
  3508. checkUrl: window.location.pathname + '/check',
  3509. completeData: function (data) {
  3510. pos.updateDatas({update: data.source.pos});
  3511. const loadResult = billsTree.loadPostData({update: data.source.bills});
  3512. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3513. posSpreadObj.loadCurPosData();
  3514. for (const e of data.error) {
  3515. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  3516. }
  3517. },
  3518. errorList: errorList,
  3519. });
  3520. $('#ledger-check2').click(() => {
  3521. ledgerCheck2({
  3522. ledgerTree: billsTree,
  3523. ledgerPos: pos,
  3524. checkList: checkList,
  3525. decimal: decimal,
  3526. checkOption: checkOption,
  3527. }).then(result => {
  3528. check2Viewing({
  3529. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  3530. randomWait: true,
  3531. prefix: 'check2-',
  3532. checks: result,
  3533. checkList: checkList,
  3534. });
  3535. });
  3536. });
  3537. if (isYb) {
  3538. let compilationList = [];
  3539. $('#get-dsk-btn').click(function () {
  3540. // 判断是否已绑定dsk用户
  3541. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  3542. if (result === 1) {
  3543. $('#error-dsk .modal-body').find('h5').eq(0).show();
  3544. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  3545. $('#error-dsk').modal('show');
  3546. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  3547. } else if (result === 2) {
  3548. $('#error-dsk .modal-body').find('h5').eq(1).show();
  3549. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  3550. $('#error-dsk').modal('show');
  3551. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  3552. } else {
  3553. postData('/profile/dsk/api', {
  3554. type: 'compilation',
  3555. getProject: 1,
  3556. compilationId: getLocalCache(dskCompilation)
  3557. }, function (result) {
  3558. let html = '';
  3559. for (const data of result.compilation) {
  3560. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  3561. }
  3562. dskAccountData = result.dskAccountData;
  3563. compilationList = result.compilation;
  3564. console.log(compilationList);
  3565. $('#dsk-compilation-list').html(html);
  3566. $('#add-dsk').modal('show');
  3567. setLocalCache(dskCompilation, result.select_compilation);
  3568. makeDskProjectSjsHtml(result.project);
  3569. });
  3570. }
  3571. })
  3572. });
  3573. $('#get-dsk-bills-btn').click(function () {
  3574. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  3575. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  3576. });
  3577. $('body').on('change', '#dsk-compilation-list', function () {
  3578. const compilationId = $(this).val();
  3579. setLocalCache(dskCompilation, compilationId);
  3580. dskProjectSpreadObj.refreshSourceTree();
  3581. });
  3582. $('.hide-dsk-modal').click(function () {
  3583. $('#error-dsk').modal('hide');
  3584. });
  3585. let dp = false;
  3586. let gsObj = {
  3587. setting: null,
  3588. gsSheet: null,
  3589. grSheet: null,
  3590. tenderSourceTree: null,
  3591. grArray: dskProjects ? dskProjects : [],
  3592. orgSelect: null,
  3593. };
  3594. function makeDskProjectSjsHtml(datas) {
  3595. if (!dp) {
  3596. initDskProjectTree();
  3597. dp = true;
  3598. }
  3599. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  3600. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  3601. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  3602. if (datas.length === 0) {
  3603. $('#show-project-0').show();
  3604. } else {
  3605. $('#show-project-0').hide();
  3606. }
  3607. }
  3608. const dskProjectSpreadObj = {
  3609. _addTender: function (tender) {
  3610. const gr = gsObj.grArray.find(function (x) {
  3611. return x.pid === tender.pid;
  3612. });
  3613. const c_id = getLocalCache(dskCompilation);
  3614. const t = {
  3615. pid: tender.pid,
  3616. name: tender.name,
  3617. compilationId: c_id,
  3618. compilationName: _.find(compilationList, {ID: c_id}).name
  3619. };
  3620. if (!gr) gsObj.grArray.push(t);
  3621. return t;
  3622. },
  3623. _removeTender: function (tender) {
  3624. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  3625. return x.pid === tender.pid;
  3626. });
  3627. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  3628. },
  3629. reloadResultData: function () {
  3630. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  3631. },
  3632. refreshSourceTree: function () {
  3633. const c_id = getLocalCache(dskCompilation);
  3634. if (c_id) {
  3635. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  3636. makeDskProjectSjsHtml(result);
  3637. });
  3638. }
  3639. },
  3640. gsButtonClicked: function (e, info) {
  3641. if (!info.sheet.zh_setting) return;
  3642. const col = info.sheet.zh_setting.cols[info.col];
  3643. if (col.field !== 'selected') return;
  3644. const node = SpreadJsObj.getSelectObject(info.sheet);
  3645. node.selected = !node.selected;
  3646. if (node.children && node.children.length > 0) {
  3647. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  3648. for (const p of posterity) {
  3649. p.selected = node.selected;
  3650. if ((!p.children || p.children.length === 0) && p.type === 2) {
  3651. if (p.selected) {
  3652. dskProjectSpreadObj._addTender(p);
  3653. } else {
  3654. dskProjectSpreadObj._removeTender(p);
  3655. }
  3656. }
  3657. }
  3658. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  3659. } else if (node.type === 2) {
  3660. if (node.selected) {
  3661. dskProjectSpreadObj._addTender(node);
  3662. } else {
  3663. dskProjectSpreadObj._removeTender(node);
  3664. }
  3665. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  3666. }
  3667. dskProjectSpreadObj.reloadResultData();
  3668. },
  3669. deleteGr: function () {
  3670. if (gsObj.grArray.length === 0) return;
  3671. if (gsObj.grSheet.getSelections().length === 0) return;
  3672. const selections = gsObj.grSheet.getSelections();
  3673. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  3674. const row = sel && sel.row !== undefined ? sel.row : -1;
  3675. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3676. return false;
  3677. }
  3678. const delList = [];
  3679. for (let r = 0; r < sel.rowCount; r++) {
  3680. const select = gsObj.grArray[row + r];
  3681. delList.push(select);
  3682. }
  3683. _.pullAll(gsObj.grArray, delList);
  3684. dskProjectSpreadObj.reloadResultData();
  3685. dskProjectSpreadObj.refreshSourceTree();
  3686. },
  3687. };
  3688. const initDskProjectTree = function () {
  3689. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  3690. gsObj.gsSheet = gsSpread.getActiveSheet();
  3691. const gsSpreadSetting = {
  3692. cols: [
  3693. {
  3694. title: '选择',
  3695. field: 'selected',
  3696. hAlign: 1,
  3697. width: 40,
  3698. formatter: '@',
  3699. cellType: 'checkbox',
  3700. readOnly: true,
  3701. },
  3702. {
  3703. title: '名称',
  3704. field: 'name',
  3705. hAlign: 0,
  3706. width: 400,
  3707. formatter: '@',
  3708. readOnly: true,
  3709. folderCell: true,
  3710. cellType: 'tree'
  3711. },
  3712. ],
  3713. emptyRows: 0,
  3714. headRows: 1,
  3715. headRowHeight: [32],
  3716. defaultRowHeight: 21,
  3717. headerFont: '12px 微软雅黑',
  3718. font: '12px 微软雅黑',
  3719. headColWidth: [0],
  3720. selectedBackColor: '#fffacd',
  3721. };
  3722. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  3723. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  3724. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  3725. gsObj.grSheet = grSpread.getActiveSheet();
  3726. const grSpreadSetting = {
  3727. cols: [
  3728. {
  3729. title: '名称',
  3730. colSpan: '1',
  3731. rowSpan: '1',
  3732. field: 'name',
  3733. hAlign: 0,
  3734. width: 250,
  3735. formatter: '@',
  3736. readOnly: true,
  3737. cellType: 'ellipsisAutoTip',
  3738. scrollHeightClass: '.modal-height-500'
  3739. },
  3740. {
  3741. title: '所属编办',
  3742. colSpan: '1',
  3743. rowSpan: '1',
  3744. field: 'compilationName',
  3745. hAlign: 0,
  3746. width: 150,
  3747. formatter: '@',
  3748. readOnly: true
  3749. },
  3750. ],
  3751. emptyRows: 0,
  3752. headRows: 1,
  3753. headRowHeight: [32],
  3754. defaultRowHeight: 21,
  3755. headerFont: '12px 微软雅黑',
  3756. font: '12px 微软雅黑',
  3757. headColWidth: []
  3758. };
  3759. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  3760. // 右键删除已选项目
  3761. const gsContextMenuOptions = {
  3762. selector: '#dsk-project-result-spread',
  3763. build: function ($trigger, e) {
  3764. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  3765. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3766. },
  3767. items: {
  3768. delete: {
  3769. name: '删除',
  3770. icon: 'fa-remove',
  3771. callback: function (key, opt) {
  3772. dskProjectSpreadObj.deleteGr();
  3773. },
  3774. disabled: function (key, opt) {
  3775. const selection = gsObj.grSheet.getSelections();
  3776. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  3777. const row = sel && sel.row !== undefined ? sel.row : -1;
  3778. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3779. return true;
  3780. }
  3781. return false;
  3782. }
  3783. },
  3784. }
  3785. };
  3786. $.contextMenu(gsContextMenuOptions);
  3787. $('#add-dsk').bind('shown.bs.modal', function () {
  3788. if (gsSpread) gsSpread.refresh();
  3789. if (grSpread) grSpread.refresh();
  3790. });
  3791. };
  3792. const dskProject2Tree = (function () {
  3793. const treeSetting = {
  3794. id: 'tmt_id',
  3795. pid: 'tmt_pid',
  3796. order: 'seq',
  3797. level: 'level',
  3798. rootId: '-1',
  3799. fullPath: 'full_path',
  3800. };
  3801. const tenderTree = createNewPathTree('gather', treeSetting);
  3802. function setChildrenNode(node, files, tenders) {
  3803. const children = _.filter(files, {parentID: node.pid});
  3804. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  3805. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  3806. for (const c of checkChildren) {
  3807. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  3808. // // 判断文件夹下有无东西,没有就不插入
  3809. // continue;
  3810. // }
  3811. const child = {
  3812. pid: c.ID,
  3813. parentID: c.parentID,
  3814. name: c.name,
  3815. type: c.type,
  3816. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  3817. };
  3818. tenderTree.addNode(child, node);
  3819. if (c.type === 1) setChildrenNode(child, files, tenders);
  3820. }
  3821. }
  3822. function convert(projects) {
  3823. tenderTree.clearDatas();
  3824. const result = filterFolders(projects);
  3825. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  3826. const files = _.filter(result, {type: 1});
  3827. const tenders = _.filter(result, {type: 2});
  3828. for (const t of topLevel) {
  3829. const node = {
  3830. pid: t.ID,
  3831. parentID: t.parentID,
  3832. name: t.name,
  3833. type: t.type,
  3834. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  3835. };
  3836. tenderTree.addNode(node, null);
  3837. if (t.type === 1) setChildrenNode(node, files, tenders);
  3838. }
  3839. tenderTree.sortTreeNode(true);
  3840. return tenderTree;
  3841. }
  3842. return {tenderTree, convert}
  3843. })();
  3844. function filterFolders(data) {
  3845. // 构建ID到节点的映射
  3846. const idMap = data.reduce((map, node) => {
  3847. map[node.ID] = node;
  3848. return map;
  3849. }, {});
  3850. // 建立父子关系映射
  3851. const parentMap = data.reduce((map, node) => {
  3852. if (node.parentID !== '-1') {
  3853. if (!map[node.parentID]) {
  3854. map[node.parentID] = [];
  3855. }
  3856. map[node.parentID].push(node.ID);
  3857. }
  3858. return map;
  3859. }, {});
  3860. // 检查节点及其子节点是否包含清单(type=1)
  3861. const hasChecklist = (id) => {
  3862. const node = idMap[id];
  3863. if (node.type === 2) {
  3864. return true;
  3865. }
  3866. if (!parentMap[id]) {
  3867. return false;
  3868. }
  3869. return parentMap[id].some(childID => hasChecklist(childID));
  3870. };
  3871. // 过滤节点
  3872. const filteredIDs = new Set();
  3873. data.forEach(node => {
  3874. if (node.type === 2 || hasChecklist(node.ID)) {
  3875. let currentID = node.ID;
  3876. while (currentID !== '-1') {
  3877. filteredIDs.add(currentID);
  3878. currentID = idMap[currentID].parentID;
  3879. }
  3880. }
  3881. });
  3882. // 返回过滤后的数据
  3883. return data.filter(node => filteredIDs.has(node.ID));
  3884. }
  3885. $('#set-dsk-project').click(function () {
  3886. postData('/profile/dsk/api', {
  3887. type: 'save_projects',
  3888. tid: window.location.pathname.split('/')[2],
  3889. project_list: gsObj.grArray
  3890. }, function (result) {
  3891. // dskAccountData.select_project = result;
  3892. dskProjects = gsObj.grArray;
  3893. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  3894. dskAccountData.select_project = result;
  3895. changeDskProject(result);
  3896. dskBills.spread.refresh();
  3897. }
  3898. setDskProjectSelect(gsObj.grArray);
  3899. $('#add-dsk').modal('hide');
  3900. });
  3901. });
  3902. $('#add-dsk').on('hide.bs.modal', function () {
  3903. $('#autoTip').hide();
  3904. });
  3905. function setDskProjectSelect(projects) {
  3906. let html = '';
  3907. for (const project of projects) {
  3908. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  3909. }
  3910. $('#change-dsk-project').html(html);
  3911. }
  3912. // 选中所有新增部位/清单
  3913. $('#add-all-revise').click(function() {
  3914. const this_cid = window.location.pathname.split('/')[4];
  3915. makeGclGatherData();
  3916. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3917. type: 'get-revise-list',
  3918. }, function (result) {
  3919. const addDatas = [];
  3920. for (const ggd in gclGatherData) {
  3921. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  3922. let hadcid = 0;
  3923. for (const xmj of gclGatherData[ggd].leafXmjs) {
  3924. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  3925. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  3926. if (changeLedger || changePos) {
  3927. xmj.cid = 1;
  3928. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  3929. hadcid = 1;
  3930. }
  3931. }
  3932. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  3933. }
  3934. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  3935. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  3936. if (leafXmjs.length > 0) {
  3937. gclInfo.is_change = 1;
  3938. for (const xmj of leafXmjs) {
  3939. if (_.findIndex(changeList, function (item) {
  3940. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  3941. }) === -1) {
  3942. addDatas.push({
  3943. lid: xmj.gcl_id,
  3944. code: gclInfo.code,
  3945. name: gclInfo.name || '',
  3946. unit: gclInfo.unit || '',
  3947. unit_price: gclInfo.unit_price,
  3948. oamount: xmj.quantity,
  3949. oamount2: xmj.quantity,
  3950. bwmx: xmj.bwmx || xmj.jldy || '',
  3951. xmj_code: xmj.code || '',
  3952. xmj_jldy: xmj.jldy || '',
  3953. xmj_dwgc: xmj.dwgc || '',
  3954. xmj_fbgc: xmj.fbgc || '',
  3955. xmj_fxgc: xmj.fxgc || '',
  3956. gcl_id: xmj.gcl_id,
  3957. mx_id: xmj.mx_id || '',
  3958. });
  3959. }
  3960. }
  3961. }
  3962. }
  3963. console.log(addDatas);
  3964. if (addDatas.length > 0) {
  3965. // 更新至服务器
  3966. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3967. type: 'add-change-list',
  3968. postData: addDatas,
  3969. }, function (result) {
  3970. toastr.success('已新增当前变更令新增的所有部位/清单');
  3971. changeList = result.changeList;
  3972. const sortData = SpreadJsObj.getSortData(billsSheet);
  3973. const billsNodes = _.filter(sortData, function (item) {
  3974. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  3975. });
  3976. for (const billsNode of billsNodes) {
  3977. billsNode.is_change = 1;
  3978. }
  3979. const loadResult = { update: billsNodes };
  3980. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3981. posSpreadObj.loadCurPosData();
  3982. });
  3983. } else {
  3984. toastr.warning('未存在当前变更令新增的部位/清单');
  3985. }
  3986. });
  3987. });
  3988. }
  3989. }
  3990. });
  3991. // 编号排序,多重判断
  3992. function sortByCode(a, b, code = 'b_code') {
  3993. let code1 = a[code].split('-');
  3994. let code2 = b[code].split('-');
  3995. let code1length = code1.length;
  3996. let code2length = code2.length;
  3997. for (let i = 0; i < code1length; i ++) {
  3998. if (i+1 <= code2length) {
  3999. if (code1[i] != code2[i]) {
  4000. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  4001. return parseInt(code1[i]) - parseInt(code2[i]);
  4002. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  4003. return 1;
  4004. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  4005. return -1;
  4006. } else {
  4007. const str1length = code1[i].length;
  4008. const str2length = code2[i].length;
  4009. for (let j = 0; j < str1length; j++) {
  4010. if (j+1 <= str2length) {
  4011. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  4012. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  4013. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  4014. if (str1length == str2length) {
  4015. return 0;
  4016. } else {
  4017. return str1length - str2length;
  4018. }
  4019. }
  4020. } else {
  4021. if (j+1 >= str1length) {
  4022. return 1;
  4023. } else {
  4024. return -1;
  4025. }
  4026. }
  4027. }
  4028. }
  4029. } else if (i+1 == code1length && code1[i] == code2[i]) {
  4030. if (code1length == code2length) {
  4031. return 0;
  4032. } else {
  4033. return code1length - code2length;
  4034. }
  4035. }
  4036. } else {
  4037. if (i+1 >= code1length) {
  4038. return 1;
  4039. } else {
  4040. return -1;
  4041. }
  4042. }
  4043. }
  4044. }