stage.js 249 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. function getExprInfo (field) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. /**
  26. * 从cookie中读取缓存的列显示设置,没有则取默认
  27. * @returns {*[]}
  28. */
  29. function customColDisplay () {
  30. const defaultSetting = [
  31. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  32. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl', 'qc_minus_qty'], visible: true },
  33. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  34. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  35. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  36. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent', 'end_final_1_precent'], visible: true },
  37. { title: '本期批注', fields: ['postil'], visible: true },
  38. { title: '图册号', fields: ['drawing_code'], visible: true },
  39. { title: '备注', fields: ['memo'], visible: true },
  40. { title: '总额计量', fields: ['is_tp'], visible: true},
  41. ];
  42. if (!checkTzMeasureType()) {
  43. defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
  44. }
  45. const settingStr = Cookies.get(ckColSetting);
  46. if (settingStr) {
  47. const customSetting = JSON.parse(settingStr);
  48. for (const ds of defaultSetting) {
  49. const cs = customSetting.find(x => {return x.title === ds.title});
  50. if (cs) ds.visible = cs.visible;
  51. }
  52. }
  53. return defaultSetting;
  54. }
  55. /**
  56. * 根据列显示设置,调整setting中的列是否显示
  57. * @param setting
  58. * @param customDisplay
  59. */
  60. function customizeStageTreeSetting(setting, customDisplay) {
  61. for (const cd of customDisplay) {
  62. for (const c of setting.cols) {
  63. if (cd.fields.indexOf(c.field) !== -1) {
  64. c.visible = c.defaultVisible === undefined ? cd.visible : c.defaultVisible && cd.visible;
  65. }
  66. }
  67. }
  68. }
  69. /**
  70. * 初始化 树结构 列事件
  71. * @param setting
  72. */
  73. function initTreeColSettingEvents(setting) {
  74. const Events = {
  75. readOnly: {
  76. measureData: function (node) {
  77. return node.children && node.children.length > 0;
  78. },
  79. },
  80. };
  81. const getEvent = function (eventName) {
  82. const names = eventName.split('.');
  83. let event = Events;
  84. for (let name of names) {
  85. if (event[name]) {
  86. event = event[name];
  87. } else {
  88. return null;
  89. }
  90. }
  91. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  92. return null;
  93. } else {
  94. return event;
  95. }
  96. };
  97. for (const col of setting.cols) {
  98. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  99. col.readOnly = getEvent(col.readOnly);
  100. }
  101. }
  102. }
  103. // 生成所有附件列表
  104. function getAllList(currPageNum = 1) {
  105. // 每页最多几个附件
  106. const pageCount = 20;
  107. // 附件总数
  108. const total = attData.length;
  109. // 总页数
  110. const pageNum = Math.ceil(total/pageCount);
  111. $('#totalPage').text(pageNum);
  112. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  113. // 当前页附件内容
  114. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  115. currPageFileData = currPageAttData;
  116. let html = '';
  117. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  118. for(const att of currPageAttData) {
  119. html += `<tr>
  120. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  121. <td>
  122. <div class="d-flex">
  123. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  124. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  125. </div>
  126. </td><td>${att.username}</td></tr>`
  127. }
  128. $('#alllist-table').html(html);
  129. $('#alllist-table').on('click', 'tr', function() {
  130. $('#alllist-table tr').removeClass('bg-light')
  131. $(this).addClass('bg-light')
  132. })
  133. }
  134. // 生成当前节点列表
  135. function getNodeList(node) {
  136. let html = '';
  137. for(const att of attData) {
  138. if (node === att.lid) {
  139. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  140. html += `<tr>
  141. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  142. <td>
  143. <div class="d-flex">
  144. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  145. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  146. </div>
  147. </td><td>${att.username}</td></tr>`
  148. }
  149. }
  150. $('#nodelist-table').html(html);
  151. $('#nodelist-table').on('click', 'tr', function() {
  152. $('#nodelist-table tr').removeClass('bg-light');
  153. $(this).addClass('bg-light');
  154. })
  155. }
  156. function getGxbyText(data) {
  157. const def = thirdParty.gxby.find(function (x) {
  158. return x.value === data.gxby_status;
  159. });
  160. return def ? def.name : '';
  161. }
  162. function getDaglText(data) {
  163. const def = thirdParty.dagl.find(function (x) {
  164. return x.value === data.dagl_status;
  165. });
  166. return def ? def.name : '';
  167. }
  168. function getHintMsg () {
  169. return {
  170. invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
  171. disableChange: {type: 'error', msg: '不可修改此数据'},
  172. }
  173. }
  174. let ledgerData, posData = '';
  175. $(document).ready(() => {
  176. const exportExcelSetting = {
  177. cols: [
  178. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  179. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  180. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  181. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  182. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  183. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  184. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  185. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  186. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  187. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  188. {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  189. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  190. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  191. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  192. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  193. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  194. {title: '截止本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  195. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  196. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  197. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  198. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_final_1_percent', hAlign: 2, width: 80, type: 'Number'},
  199. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  200. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  201. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  202. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  203. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  204. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  205. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  206. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  207. ],
  208. headRows: 2,
  209. headRowHeight: [25, 25],
  210. defaultRowHeight: 21,
  211. headerFont: 'bold 10px 微软雅黑',
  212. font: '10px 微软雅黑'
  213. };
  214. let detail, searchLedger, checkedChanges;
  215. const checkOption = {
  216. sibling: { enable: 0 },
  217. empty_code: { enable: 0 },
  218. calc: {
  219. enable: 1,
  220. fields: ['contract_qty', 'qc_qty', 'qc_minus_qty'],
  221. },
  222. zero: { enable: 0 },
  223. tp: {
  224. enable: 1,
  225. fields: [
  226. {qty: 'contract_qty', tp: 'contract_tp'},
  227. {qty: 'qc_qty', tp: 'qc_tp'},
  228. ],
  229. filter: function (node) {
  230. return node.is_tp;
  231. }
  232. },
  233. over: { enable: 1, isTz: checkTzMeasureType(), },
  234. limit3f: { enable: 1, checkType: [], status: thirdParty, },
  235. minus_cb: { enable: hintMinusCb },
  236. };
  237. if (tender.s2b_gxby_check) checkOption.limit3f.checkType.push('gxby');
  238. if (tender.s2b_dagl_check) checkOption.limit3f.checkType.push('dagl');
  239. // 界面布局
  240. autoFlashHeight();
  241. // 初始化 台账树结构 数据结构
  242. removeLocalCache('bills-fold');
  243. const stageTreeSetting = {
  244. id: 'ledger_id',
  245. pid: 'ledger_pid',
  246. order: 'order',
  247. level: 'level',
  248. rootId: -1,
  249. keys: ['id', 'tender_id', 'ledger_id'],
  250. stageId: 'id',
  251. autoExpand: 3,
  252. // markFoldKey: 'bills-fold',
  253. // markFoldSubKey: window.location.pathname.split('/')[2],
  254. markExpandKey: 'stage-bills-expand',
  255. markExpandSubKey: window.location.pathname.split('/')[2],
  256. };
  257. // 台账树结构计算相关设置
  258. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty', 'postil', 'used', 'contract_expr'];
  259. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp',
  260. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp', 'final_1_tp', 'end_final_1_tp'];
  261. stageTreeSetting.calcFun = function (node) {
  262. if (!node.children || node.children.length === 0) {
  263. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  264. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  265. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  266. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  267. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  268. node.end_qc_minus_qty = ZhCalc.add(node.pre_qc_minus_qty, node.qc_minus_qty);
  269. node.final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.quantity);
  270. node.final_1_tp = ZhCalc.mul(node.final_1_qty, node.unit_price, tenderInfo.decimal.tp);
  271. node.deal_final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.deal_qty);
  272. node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty);
  273. }
  274. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  275. node.gather_tp = ZhCalc.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
  276. node.end_contract_tp = ZhCalc.sum([node.pre_contract_tp, node.contract_tp, node.contract_pc_tp]);
  277. node.end_qc_tp = ZhCalc.sum([node.pre_qc_tp, node.qc_tp, node.qc_pc_tp]);
  278. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  279. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  280. node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
  281. if (!node.children || node.children.length === 0) {
  282. if (node.end_contract_qty) {
  283. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  284. } else {
  285. node.end_correct_tp = node.end_gather_tp;
  286. }
  287. }
  288. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  289. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  290. node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
  291. node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2);
  292. node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2);
  293. };
  294. const stageTree = createNewPathTree('stage', stageTreeSetting);
  295. // 初始化 计量单元 数据结构
  296. const stagePosSetting = {
  297. id: 'id', ledgerId: 'lid',
  298. updateFields: ['contract_qty', 'qc_qty', 'qc_minus_qty', 'postil', 'contract_expr'],
  299. };
  300. stagePosSetting.calcFun = function (pos) {
  301. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  302. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  303. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  304. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  305. pos.end_qc_minus_qty = ZhCalc.add(pos.pre_qc_minus_qty, pos.qc_minus_qty);
  306. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  307. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  308. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  309. pos.estimate_qty = !checkZero(pos.real_qty)
  310. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  311. : null;
  312. pos.final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.quantity);
  313. pos.deal_final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.deal_qty);
  314. pos.end_final_1_qty = ZhCalc.add(pos.end_qc_qty, pos.final_1_qty);
  315. };
  316. const stagePos = new StagePosData(stagePosSetting);
  317. function checkUsed(tree, pos, node) {
  318. if (node.children && node.children.length > 0) {
  319. const posterity = tree.getPosterity(node);
  320. for (const p of posterity) {
  321. if (p.children && p.children.length > 0) continue;
  322. if (!checkZero(p.contract_qty) || !checkZero(p.contract_tp) ||
  323. !checkZero(p.qc_qty) || !checkZero(p.qc_tp) || !checkZero(p.qc_minus_qty))
  324. return true;
  325. const pPos = pos.getLedgerPos(p.id);
  326. if (!pPos || pPos.length === 0) continue;
  327. for (const pp of pPos) {
  328. if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
  329. }
  330. }
  331. return false;
  332. } else {
  333. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp) ||
  334. !checkZero(node.qc_qty) || !checkZero(node.qc_tp) || !checkZero(node.qc_minus_qty))
  335. return true;
  336. const pPos = pos.getLedgerPos(node.id);
  337. if (!pPos || pPos.length === 0) return false;
  338. for (const pp of pPos) {
  339. if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
  340. }
  341. }
  342. };
  343. class Changes {
  344. constructor(obj) {
  345. const self = this;
  346. this.obj = obj;
  347. // 初始化 清单编号窗口 参数
  348. this.spreadSetting = {
  349. cols: [
  350. {title: '已用', field: 'select', width: 45, formatter: '@', cellType: 'checkbox', hAlign: 1, indent: 14, getValue: function (data) {return data.uamount && !checkZero(data.uamount);}},
  351. {title: '变更令号', field: 'p_code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  352. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  353. {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
  354. {title: '批复数量', field: 'b_amount', width: 60, readOnly: true, hAlign: 2, },
  355. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, type: 'Number', getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  356. {title: '本期计量', field: 'uamount', width: 60, hAlign: 2, type: 'Number', },
  357. ],
  358. emptyRows: 0,
  359. headRows: 1,
  360. headRowHeight: [32],
  361. headerFont: '12px 微软雅黑',
  362. font: '12px 微软雅黑',
  363. getColor: function (sheet, data, row, col, defaultColor) {
  364. if (col.field === 'uamount') {
  365. if (data.bamount > 0) {
  366. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  367. return usedAmount < 0 || usedAmount > data.bamount ? spreadColor.stage.over : defaultColor;
  368. } else if (data.bamount < 0) {
  369. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  370. return usedAmount > 0 || usedAmount < data.bamount ? spreadColor.stage.over : defaultColor;
  371. } else {
  372. return data.uamount ? spreadColor.stage.over : defaultColor;
  373. }
  374. } else {
  375. return defaultColor;
  376. }
  377. }
  378. };
  379. this.curChangeId = '';
  380. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  381. this.firstView = true;
  382. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  383. // 初次显示,需刷新spread界面,保证界面绘制正确
  384. this.obj.bind('shown.bs.modal', function () {
  385. if (self.firstView) {
  386. self.firstView = false;
  387. self.spread.refresh();
  388. }
  389. });
  390. // 切换变更令,加载右侧明细数据
  391. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  392. const change = SpreadJsObj.getSelectObject(info.sheet);
  393. if(change) self._loadChangeDetail(change);
  394. });
  395. // 填写本期计量
  396. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  397. if (info.sheet.zh_setting) {
  398. const col = info.sheet.zh_setting.cols[info.col];
  399. if (col.cellType === 'checkbox') return;
  400. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  401. const node = sortData[info.row];
  402. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  403. // 刷新界面
  404. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  405. }
  406. });
  407. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  408. if (info.sheet.zh_setting) {
  409. const sortData = SpreadJsObj.getSortData(info.sheet);
  410. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  411. const curRow = iRow + info.cellRange.row;
  412. const curCol = info.cellRange.col;
  413. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  414. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  415. }
  416. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  417. }
  418. });
  419. this.spread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
  420. if (!info.sheet.zh_setting) return;
  421. const col = info.sheet.zh_setting.cols[info.col];
  422. if (col.cellType === 'checkbox') {
  423. if (info.sheet.isEditing()) {
  424. info.sheet.endEdit(true);
  425. }
  426. const select = info.sheet.zh_data[info.row];
  427. select.uamount = select.uamount ? 0 : select.vamount;
  428. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  429. }
  430. });
  431. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  432. if (sheet.zh_setting) {
  433. const sel = sheet.getSelections()[0];
  434. const sortData = SpreadJsObj.getSortData(sheet);
  435. // 仅本期计量可删除
  436. if (sel.col === 5 && sel.colCount === 1) {
  437. const col = sheet.zh_setting.cols[sel.col];
  438. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  439. const data = sortData[iRow];
  440. data[col.field] = null;
  441. }
  442. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  443. }
  444. }
  445. });
  446. // 过滤可变更数量为0
  447. $('#filterEmpty').click(function () {
  448. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  449. });
  450. // 匹配编号
  451. $('#matchPos').click(function () {
  452. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  453. });
  454. // 展开收起 变更令详细信息
  455. $('#show-bgl-detail').bind('click', function () {
  456. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  457. if (detail.hasClass('col-4')) {
  458. detail.attr('class', 'col').hide();
  459. bgl.attr('class', 'col-12');
  460. $('a', obj).attr('title', '展开侧栏');
  461. $('i', obj).attr('class', 'fa fa-chevron-left');
  462. self.spread.refresh();
  463. } else {
  464. detail.attr('class', 'col-4').show();
  465. bgl.attr('class', 'col-8');
  466. $('a', obj).attr('title', '收起侧栏');
  467. $('i', obj).attr('class', 'fa fa-chevron-right');
  468. self.spread.refresh();
  469. }
  470. });
  471. // 添加调用变更令
  472. $('#usg-bg-ok').click(function () {
  473. const data = { target: self.callData, change: [] };
  474. for (const c of self.displayChanges) {
  475. if (c.uamount) {
  476. if (c.bamount > 0) {
  477. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  478. if (usedAmount < 0 || usedAmount > c.bamount) {
  479. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  480. return;
  481. }
  482. } else if (c.bamount < 0) {
  483. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  484. if (usedAmount > 0 || usedAmount < c.bamount) {
  485. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  486. return;
  487. }
  488. } else {
  489. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  490. return;
  491. }
  492. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount, minus: c.bamount < 0 });
  493. }
  494. }
  495. // 提交数据到后端
  496. postData(window.location.pathname + '/use-change', data, function(result) {
  497. if (result.pos) {
  498. stagePos.loadCurStageData(result.pos.curStageData);
  499. }
  500. const nodes = stageTree.loadPostStageData(result.bills);
  501. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  502. stagePosSpreadObj.loadCurPosData();
  503. if (detail) {
  504. detail.loadStageChangeUpdateData(result, nodes);
  505. } else {
  506. stageIm.loadUpdateChangeData(result, nodes)
  507. }
  508. self.obj.modal('hide');
  509. });
  510. })
  511. }
  512. _calculateAmount() {
  513. for (const c of this.changes) {
  514. c.bamount = _.toNumber(c.b_amount);
  515. c.vamount = ZhCalc.sub(ZhCalc.sub(c.bamount, c.used_amount), c.stage_used_amount);
  516. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid, no_value: this.callData.noValue});
  517. if (uc) {
  518. c.org_uamount = uc.qty;
  519. c.uamount = uc.qty;
  520. c.vamount = ZhCalc.add(c.vamount, uc.qty);
  521. }
  522. c.pre_amount = ZhCalc.sub(ZhCalc.add(c.used_amount, c.stage_used_amount), c.uamount);
  523. }
  524. }
  525. _loadChangeDetail(change) {
  526. if (change) {
  527. if (change.cid === this.curChangeId) { return; }
  528. this.curChangeId = change.cid;
  529. const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
  530. for (const i of inputs) {
  531. const field = $(i).attr('name');
  532. const text = (field && change[field]) ? change[field] : '';
  533. $(i).val(text);
  534. }
  535. const textareas = $('textarea', this.obj);
  536. for (const ta of textareas) {
  537. const field = $(ta).attr('name');
  538. const text = (field && change[field]) ? change[field].replace(/<br><br>/g, '\r\n') : '';
  539. ta.textContent = text;
  540. }
  541. const html = [];
  542. for (const a of change.attachments) {
  543. html.push('<tr>');
  544. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  545. html.push('<td>', a.u_name, '</td>');
  546. html.push('</tr>');
  547. }
  548. // 变更类型
  549. if (change.type) {
  550. const cType = change.type.split(',');
  551. $('input[name="type"]').prop("checked", false);
  552. for (const c of cType) {
  553. $('input[name="type"][value='+ c +']').prop("checked", true);
  554. }
  555. }
  556. // 变更类别
  557. $('select[name=class]').val(change.class);
  558. // 变更性质
  559. $('select[name=quality]').val(change.quality);
  560. // 变更单位
  561. $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
  562. // 费用承担方
  563. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  564. // 附件
  565. $('#attachment').html(html.join(''));
  566. } else {
  567. const inputs = $('input', this.obj);
  568. for (const i of inputs) {
  569. $(i).val('');
  570. }
  571. const textareas = $('textarea', this.obj);
  572. for (const ta of textareas) {
  573. ta.innerText = '';
  574. }
  575. $('#attachment').html('');
  576. }
  577. }
  578. _viewChanges() {
  579. const sheet = this.spread.getActiveSheet();
  580. if (this.changes) {
  581. sheet.setSelection(0, 0, 1, 1);
  582. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  583. this._loadChangeDetail(this.displayChanges[0]);
  584. } else {
  585. toastr.error('查询变更令有误,请刷新页面后重试');
  586. }
  587. }
  588. _filterChange(filterEmpty, matchPosName) {
  589. this.displayChanges = [];
  590. for (const c of this.changes) {
  591. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  592. const matchVisible = matchPosName && this.callData.pos
  593. ? (c.gcl_id === this.callData.bills.id && c.b_bwmx === this.callData.pos.name)
  594. : true;
  595. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  596. this.displayChanges.push(c);
  597. }
  598. }
  599. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  600. this._loadChangeDetail(this.displayChanges[0]);
  601. }
  602. loadChanges(data) {
  603. this.callData = data;
  604. if (this.callData.pos) {
  605. $('#matchPos').parent().show();
  606. } else {
  607. $('#matchPos').parent().hide();
  608. }
  609. const self = this;
  610. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  611. postData(window.location.pathname + '/valid-change', data, function (result) {
  612. self.changes = result.changes;
  613. self.useChanges = result.useChanges;
  614. self._calculateAmount();
  615. self._viewChanges();
  616. self.obj.modal('show');
  617. });
  618. }
  619. }
  620. const changesObj = new Changes($('#use-bg'));
  621. // 初始化 台账 spread
  622. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  623. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  624. // 数量变更列,添加按钮
  625. const qcColShowImage = function (data) {
  626. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  627. return false;
  628. } else {
  629. const nodePos = stagePos.getLedgerPos(data.id);
  630. return !(nodePos && nodePos.length > 0);
  631. }
  632. };
  633. sjsSettingObj.setQcCols(ledgerSpreadSetting.cols, [
  634. {field: 'qc_qty', showImage: qcColShowImage},
  635. {field: 'qc_minus_qty', showImage: qcColShowImage},
  636. ]);
  637. sjsSettingObj.setOrgPriceCol(ledgerSpreadSetting.cols, [ {field: 'org_price'} ]);
  638. // const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_percent' || x.field === 'end_correct_percent'});
  639. // if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_percent' : 'end_gather_percent';
  640. const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'});
  641. if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
  642. ledgerSpreadSetting.imageClick = function (data, hitinfo) {
  643. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  644. switch (col.field) {
  645. case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
  646. case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
  647. case 'qc_qty':
  648. case 'qc_minus_qty':
  649. if (data.children && data.children.length > 0 || data.lock || data.is_import) return;
  650. const nodePos = stagePos.getLedgerPos(data.id);
  651. if (nodePos && nodePos.length > 0) return;
  652. const minus = col.field === 'qc_minus_qty' ? 1 : 0;
  653. changesObj.loadChanges({bills: data, minus, noValue: minus});
  654. break;
  655. default: return;
  656. }
  657. };
  658. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  659. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  660. if (data) {
  661. if (col.field === 'gxby') {
  662. const def = thirdParty.gxby.find(function (x) {
  663. return x.value === data.gxby_status;
  664. });
  665. if (def && def.color) return def.color;
  666. } else if (col.field === 'dagl') {
  667. const def = thirdParty.dagl.find(function (x) {
  668. return x.value === data.dagl_status;
  669. });
  670. if (def && def.color) return def.color;
  671. }
  672. return hintOver && checkUtils.billsOver(data, checkTzMeasureType(), stagePos) ? spreadColor.stage.over : defaultColor;
  673. } else {
  674. return defaultColor;
  675. }
  676. };
  677. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  678. sjsSettingObj.set3FCols(ledgerSpreadSetting.cols, [
  679. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  680. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  681. ]);
  682. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  683. ledgerSpreadSetting.headColWidth = [50];
  684. ledgerSpreadSetting.rowHeader = [
  685. {
  686. rowHeaderType: 'tag',
  687. setting: {
  688. indent: 14,
  689. tagSize: 0.8,
  690. tagFont: '8px 微软雅黑',
  691. getColor: function (index, data) {
  692. if (!data) return;
  693. return billsTag.getBillsTagsColor(data.id);
  694. },
  695. getTagHtml: function (index, data) {
  696. if (!data) return;
  697. const getHtml = function (list) {
  698. if (!list || list.length === 0) return '';
  699. const html = [];
  700. for (const l of list) {
  701. html.push('<div class="row mr-1">');
  702. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  703. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  704. html.push('</div>');
  705. }
  706. return html.join('');
  707. };
  708. return getHtml(billsTag.getBillsTagsInfo(data.id));
  709. }
  710. },
  711. },
  712. ];
  713. ledgerSpreadSetting.readOnly = function (data) {
  714. if (!data) return false;
  715. return data.lock || stageTreeSpreadObj.assistReadOnly;
  716. };
  717. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  718. //初始化所有附件列表
  719. getAllList();
  720. // 初始化 计量单元 Spread
  721. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  722. const posQcColShowImage = function (data) {
  723. return data !== undefined && data !== null;
  724. };
  725. sjsSettingObj.setQcCols(posSpreadSetting.cols, [
  726. { field: 'qc_qty', showImage: posQcColShowImage },
  727. { field: 'qc_minus_qty', showImage: posQcColShowImage }
  728. ]);
  729. posSpreadSetting.imageClick = function (data, hitinfo) {
  730. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  731. switch (col.field) {
  732. case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
  733. case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
  734. case 'qc_qty':
  735. case 'qc_minus_qty':
  736. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  737. if (node.lock) return;
  738. const minus = col.field === 'qc_minus_qty' ? 1 : 0;
  739. changesObj.loadChanges({bills: node, pos: data, minus, noValue: minus});
  740. break;
  741. default: return;
  742. }
  743. };
  744. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  745. if (data) {
  746. if (col.field === 'gxby') {
  747. const def = thirdParty.gxby.find(function (x) {
  748. return x.value === data.gxby_status;
  749. });
  750. if (def && def.color) return def.color;
  751. } else if (col.field === 'dagl') {
  752. const def = thirdParty.dagl.find(function (x) {
  753. return x.value === data.dagl_status;
  754. });
  755. if (def && def.color) return def.color;
  756. }
  757. }
  758. if (checkTzMeasureType()) {
  759. return hintOver && checkUtils.posOver(data) ? spreadColor.stage.over : defaultColor;
  760. }
  761. };
  762. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  763. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  764. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  765. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  766. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  767. ]);
  768. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  769. const billsTag = $.billsTag({
  770. selector: '#bills-tag',
  771. relaSpread: slSpread,
  772. updateUrl: window.location.pathname + '/tag',
  773. afterModify: function (nodes) {
  774. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  775. },
  776. afterLocated: function () {
  777. stagePosSpreadObj.loadCurPosData();
  778. },
  779. afterShow: function () {
  780. slSpread.refresh();
  781. if (spSpread) spSpread.refresh();
  782. },
  783. });
  784. const errorList = $.cs_errorList({
  785. tabSelector: '#error-list-tab',
  786. selector: '#error-list',
  787. relaSpread: slSpread,
  788. storeKey: 'stage-error-' + stage.id,
  789. afterLocated: function () {
  790. stagePosSpreadObj.loadCurPosData();
  791. },
  792. afterShow: function () {
  793. slSpread.refresh();
  794. if (spSpread) spSpread.refresh();
  795. },
  796. });
  797. const checkList = $.ledger_checkList({
  798. id: 'check-list',
  799. tabSelector: '#check-list-tab',
  800. selector: '#check-list',
  801. relaSpread: slSpread,
  802. storeKey: 'stage-check-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
  803. checkType: getCheckType(checkOption),
  804. afterLocated: function () {
  805. stagePosSpreadObj.loadCurPosData();
  806. },
  807. afterShow: function () {
  808. slSpread.refresh();
  809. if (spSpread) spSpread.refresh();
  810. },
  811. });
  812. const sumLoadMiss = $.sumLoadMiss({
  813. tabSelector: '#sum-load-miss-tab',
  814. selector: '#sum-load-miss',
  815. relaSpread: slSpread,
  816. storeKey: 'stage-slm-' + stage.id,
  817. id: 'stage-slm',
  818. type: 'stage',
  819. afterLocated: function () {
  820. stagePosSpreadObj.loadCurPosData();
  821. },
  822. afterShow: function () {
  823. slSpread.refresh();
  824. if (spSpread) spSpread.refresh();
  825. },
  826. });
  827. const stageTreeSpreadObj = {
  828. cut: function (sheet, sel, callback) {
  829. callback(true);
  830. },
  831. loadExprToInput(sheet) {
  832. const sel = sheet.getSelections()[0];
  833. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  834. if (col.type === 'Number') {
  835. const data = SpreadJsObj.getSelectObject(sheet);
  836. if (!data) {
  837. $('#bills-expr').val('').attr('readOnly', true);
  838. $('#bills-expr').removeAttr('data-row');
  839. return;
  840. }
  841. const nodePos = stagePos.getLedgerPos(data.id);
  842. if (nodePos && nodePos.length > 0) {
  843. $('#bills-expr').val('').attr('readOnly', true);
  844. } else {
  845. const exprInfo = getExprInfo(col.field);
  846. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  847. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  848. if (col.field.indexOf('tp') >= 0) {
  849. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
  850. } else {
  851. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
  852. }
  853. }
  854. $('#bills-expr').attr('data-row', sel.row);
  855. } else {
  856. $('#bills-expr').val('').attr('readOnly', true);
  857. $('#bills-expr').removeAttr('data-row');
  858. }
  859. },
  860. refreshTreeNodes: function (sheet, nodes) {
  861. const tree = sheet.zh_tree;
  862. if (!tree) { return }
  863. const rows = [];
  864. for (const node of nodes) {
  865. rows.push(tree.nodes.indexOf(node));
  866. }
  867. SpreadJsObj.reLoadRowsData(sheet, rows);
  868. },
  869. editEnded: function (e, info) {
  870. if (info.sheet.zh_setting) {
  871. const col = info.sheet.zh_setting.cols[info.col];
  872. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  873. const node = sortData[info.row], updateData = {};
  874. const orgValue = node[col.field];
  875. let newValue = trimInvalidChar(info.editingText);
  876. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  877. return;
  878. }
  879. if (col.type === 'Number' && newValue && newValue !== '') {
  880. const num = _.toNumber(newValue);
  881. if (_.isFinite(num)) {
  882. newValue = num;
  883. } else {
  884. try {
  885. newValue = math.evaluate(transExpr(newValue));
  886. } catch(err) {
  887. toastr.error('输入的表达式非法');
  888. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  889. return;
  890. }
  891. }
  892. }
  893. if (col.field.indexOf('_dgn_') > 0) {
  894. if (node.b_code && node.b_code !== '') {
  895. toastr.error('仅项目节可输入项目节数量');
  896. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  897. return;
  898. }
  899. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  900. if (node.children && node.children.length > 0) {
  901. toastr.error('清单父项不可计量');
  902. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  903. return;
  904. } else {
  905. const nodePos = stagePos.getLedgerPos(node.id);
  906. if (nodePos && nodePos.length > 0) {
  907. toastr.error('该清单有计量单元,请在计量单元处计量');
  908. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  909. return;
  910. }
  911. }
  912. }
  913. if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  914. updateData.main = {
  915. id: node.id
  916. };
  917. updateData.main[col.field] = newValue;
  918. } else if (col.field.indexOf('_dgn_') > 0) {
  919. updateData.dgn = {
  920. id: node.id
  921. };
  922. updateData.dgn[col.field] = newValue;
  923. } else if (col.field !== 'is_tp') {
  924. updateData.stage = {
  925. lid: node.id
  926. };
  927. updateData.stage[col.field] = newValue;
  928. const exprInfo = getExprInfo(col.field);
  929. if (exprInfo) {
  930. updateData.stage[exprInfo.expr] = info.editingText !== newValue+ '' ? trimInvalidChar(info.editingText) : '';
  931. }
  932. }
  933. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  934. // tag update
  935. const nodes = stageTree.loadPostStageData(data);
  936. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  937. if (detail) {
  938. detail.loadStageLedgerUpdateData(data, nodes);
  939. } else {
  940. stageIm.loadUpdateLedgerData(data, nodes);
  941. }
  942. }, function () {
  943. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  944. });
  945. }
  946. },
  947. loadRelaData: function () {
  948. const billsSheet = slSpread.getActiveSheet();
  949. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  950. const posSheet = spSpread.getActiveSheet();
  951. SpreadJsObj.resetTopAndSelect(posSheet);
  952. stagePosSpreadObj.loadCurPosData();
  953. if (posSearch) posSearch.search();
  954. },
  955. selectionChanged: function (e, info) {
  956. console.log(SpreadJsObj.getSelectObject(info.sheet));
  957. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  958. stageTreeSpreadObj.loadRelaData();
  959. // 全选去除
  960. $('#dqjiedian').find('.check-all-file').prop('checked', false);
  961. }
  962. stageTreeSpreadObj.loadExprToInput(info.sheet);
  963. },
  964. deletePress(sheet) {
  965. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  966. const tree = sheet.zh_tree;
  967. if (!tree) { return; }
  968. const sel = sheet.getSelections()[0];
  969. const validCols = [];
  970. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  971. const colSetting = sheet.zh_setting.cols[iCol];
  972. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  973. validCols.push(iCol);
  974. }
  975. }
  976. if (validCols.length === 0) { return; }
  977. const sortData = sheet.zh_tree.nodes;
  978. const datas = [], dgnDatas = [], mainDatas = [];
  979. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  980. const node = sortData[iRow];
  981. if (node && !node.lock) {
  982. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  983. let filter = true, filterDgn = true, filterMain = true;
  984. for (const iCol of validCols) {
  985. const colSetting = sheet.zh_setting.cols[iCol];
  986. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  987. if (node.b_code && node.b_code !== '') continue;
  988. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) < 0) {
  989. if (colSetting.field === 'contract_qty') {
  990. if (node.is_tp) continue;
  991. } else if (colSetting.field === 'contract_tp') {
  992. if (!node.is_tp) continue;
  993. }
  994. if (node.children && node.children.length > 0) {
  995. continue;
  996. }
  997. const nodePos = stagePos.getLedgerPos(node.id);
  998. if (nodePos && nodePos.length > 0) {
  999. continue;
  1000. }
  1001. }
  1002. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  1003. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  1004. dgnData[colSetting.field] = 0;
  1005. filterDgn = false;
  1006. }
  1007. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) >= 0) {
  1008. mainData[colSetting.field] = null;
  1009. filterMain = false;
  1010. } else {
  1011. data[colSetting.field] = null;
  1012. const exprInfo = getExprInfo(colSetting.field);
  1013. if (exprInfo) {
  1014. data[exprInfo.expr] = '';
  1015. }
  1016. filter = false;
  1017. }
  1018. }
  1019. if (!filter) datas.push(data);
  1020. if (!filterDgn) dgnDatas.push(dgnData);
  1021. if (!filterMain) mainDatas.push(mainData);
  1022. }
  1023. }
  1024. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1025. const bills = {};
  1026. if (datas.length > 0) bills.stage = datas;
  1027. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  1028. if (mainDatas.length > 0) bills.main = mainDatas;
  1029. postData(window.location.href + '/update', {bills: bills}, function (result) {
  1030. const nodes = stageTree.loadPostStageData(result);
  1031. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1032. if (detail) {
  1033. detail.loadStageLedgerUpdateData(result, nodes);
  1034. } else {
  1035. stageIm.loadUpdateLedgerData(result, nodes);
  1036. }
  1037. stageTreeSpreadObj.loadExprToInput(sheet);
  1038. });
  1039. }
  1040. }
  1041. },
  1042. clipboardPasting(e, info) {
  1043. if (info.sheet.zh_setting) {
  1044. const setting = info.sheet.zh_setting;
  1045. const range = info.cellRange;
  1046. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_minus_qty', 'postil'].concat(['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'], setting.dgnUpFields);
  1047. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1048. const col = info.sheet.zh_setting.cols[iCol];
  1049. if ((validField.indexOf(col.field) === -1)) {
  1050. toastr.error('不可修改此数据');
  1051. info.cancel = true;
  1052. return;
  1053. }
  1054. }
  1055. }
  1056. },
  1057. clipboardPasted(e, info) {
  1058. const pasteHint = getHintMsg();
  1059. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  1060. const sheet = info.sheet, setting = info.sheet.zh_setting;
  1061. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  1062. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1063. const curRow = iRow + info.cellRange.row;
  1064. const node = sheet.zh_tree.getItemsByIndex(curRow);
  1065. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  1066. let filter = true, filterDgn = true, filterMain = true;
  1067. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1068. const curCol = info.cellRange.col + iCol;
  1069. const col = info.sheet.zh_setting.cols[curCol];
  1070. if (col.field === 'contract_tp') {
  1071. if (!node.is_tp) continue;
  1072. } else if (col.field === 'contract_qty') {
  1073. if (node.is_tp) continue;
  1074. }
  1075. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1076. if (node.b_code && node.b_code !== '') continue;
  1077. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  1078. if (node.children && node.children.length > 0) continue;
  1079. const nodePos = stagePos.getLedgerPos(node.id);
  1080. if (nodePos && nodePos.length > 0) continue;
  1081. }
  1082. const text = trimInvalidChar(sheet.getText(curRow, curCol));
  1083. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1084. const num = _.toNumber(text);
  1085. if (num) {
  1086. dgnData[col.field] = num;
  1087. filterDgn = false;
  1088. } else {
  1089. try {
  1090. dgnData[col.field] = math.evaluate(transExpr(text));
  1091. filterDgn = false;
  1092. } catch(err) {
  1093. toastMessageUniq(pasteHint.invalidExpr);
  1094. }
  1095. }
  1096. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1097. mainData[col.field] = text;
  1098. filterMain = false;
  1099. } else {
  1100. if (col.type === 'Number') {
  1101. const exprInfo = getExprInfo(col.field);
  1102. if (text) {
  1103. const num = _.toNumber(text);
  1104. data[col.field] = num;
  1105. if (exprInfo) data[exprInfo.expr] = '';
  1106. if (_.isFinite(num)) {
  1107. filter = false;
  1108. } else {
  1109. try {
  1110. data[col.field] = math.evaluate(transExpr(text));
  1111. if (exprInfo) data[exprInfo.expr] = text;
  1112. filter = false;
  1113. } catch(err) {
  1114. toastMessageUniq(pasteHint.invalidExpr);
  1115. }
  1116. }
  1117. } else {
  1118. data[col.field] = null;
  1119. if (exprInfo) data[exprInfo.expr] = '';
  1120. filter = false;
  1121. }
  1122. } else {
  1123. data[col.field] = text;
  1124. }
  1125. }
  1126. }
  1127. if (filter && filterDgn && filterMain) {
  1128. filterNodes.push(node);
  1129. } else {
  1130. if (!filter) datas.push(data);
  1131. if (!filterDgn) dgnDatas.push(dgnData);
  1132. if (!filterMain) mainDatas.push(mainData);
  1133. }
  1134. }
  1135. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1136. const updateData = {};
  1137. if (datas.length > 0) updateData.stage = datas;
  1138. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  1139. if (mainDatas.length > 0) updateData.main = mainDatas;
  1140. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  1141. const nodes = stageTree.loadPostStageData(data);
  1142. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  1143. if (detail) {
  1144. detail.loadStageLedgerUpdateData(data, nodes);
  1145. } else {
  1146. stageIm.loadUpdateLedgerData(data, nodes);
  1147. }
  1148. stageTreeSpreadObj.loadExprToInput(sheet);
  1149. }, function () {
  1150. // todo
  1151. //stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1152. });
  1153. } else {
  1154. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1155. }
  1156. }
  1157. },
  1158. measureAllPosInNode(node, ratio = 1) {
  1159. const posterity = stageTree.getPosterity(node);
  1160. const data = {updateType: 'update', updateData: []};
  1161. for (const p of posterity) {
  1162. if (p.children && p.children.length > 0) continue;
  1163. const posRange = stagePos.getLedgerPos(p.id);
  1164. if (posRange && posRange.length > 0) {
  1165. for (const pr of posRange) {
  1166. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  1167. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  1168. if (validValue <= 0) continue;
  1169. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  1170. const pData = {
  1171. pid: pr.id,
  1172. lid: pr.lid,
  1173. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  1174. };
  1175. data.updateData.push(pData);
  1176. }
  1177. }
  1178. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  1179. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  1180. break;
  1181. }
  1182. }
  1183. if (data.updateData.length === 0) {
  1184. toastr.info('其下全部计量单元均已计量');
  1185. return;
  1186. }
  1187. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1188. if (result.pos) {
  1189. stagePos.updateDatas(result.pos.pos);
  1190. stagePos.loadCurStageData(result.pos.curStageData);
  1191. }
  1192. const nodes = stageTree.loadPostStageData(result.ledger);
  1193. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1194. stagePosSpreadObj.loadCurPosData();
  1195. if (detail) {
  1196. detail.loadStagePosUpdateData(result, nodes);
  1197. } else {
  1198. stageIm.loadUpdatePosData(result, nodes);
  1199. }
  1200. toastr.success('已计量' + data.updateData.length + '条');
  1201. }, function () {
  1202. stagePosSpreadObj.loadCurPosData();
  1203. });
  1204. },
  1205. topRowChanged(e, info) {
  1206. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1207. },
  1208. editStarting(e, info) {
  1209. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1210. const col = info.sheet.zh_setting.cols[info.col];
  1211. const node = info.sheet.zh_tree.nodes[info.row];
  1212. const exprInfo = getExprInfo(col.field);
  1213. if (exprInfo) {
  1214. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1215. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1216. }
  1217. }
  1218. switch (col.field) {
  1219. case 'contract_qty':
  1220. case 'qc_qty':
  1221. case 'qc_minus_qty':
  1222. info.cancel = node.is_tp;
  1223. break;
  1224. case 'contract_tp':
  1225. info.cancel = !node.is_tp;
  1226. break;
  1227. case 'is_tp':
  1228. info.cancel = true;
  1229. break;
  1230. }
  1231. },
  1232. buttonClicked: function (e, info) {
  1233. if (info.sheet.zh_setting) {
  1234. const node = SpreadJsObj.getSelectObject(info.sheet);
  1235. const col = info.sheet.zh_setting.cols[info.col];
  1236. const posRange = stagePos.getLedgerPos(node.id);
  1237. const tpUnit = ['总额', '元', '台', '个', '处', '月', '棵', '套', '组', '辆'];
  1238. if (node.pre_used === 1 ||
  1239. (node.children && node.children.length > 0) ||
  1240. (tpUnit.indexOf(node.unit) < 0) ||
  1241. (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  1242. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1243. return;
  1244. }
  1245. const postIsTp = function () {
  1246. const data = { calcType: {id: node.id} };
  1247. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  1248. // 更新至服务器
  1249. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  1250. const nodes = stageTree.loadPostStageData(result);
  1251. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1252. if (detail) {
  1253. detail.loadStageLedgerUpdateData(result, nodes);
  1254. } else {
  1255. stageIm.loadUpdateLedgerData(result, nodes);
  1256. }
  1257. });
  1258. };
  1259. if (col.field === 'is_tp') {
  1260. if (info.sheet.isEditing()) {
  1261. info.sheet.endEdit(true);
  1262. }
  1263. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp)) {
  1264. $.msgBox({
  1265. id: 'calc-type',
  1266. title: '提示',
  1267. message: '切换计量模式,已计量数据会被清空。',
  1268. ok: {
  1269. caption: '确定',
  1270. callback: postIsTp,
  1271. },
  1272. cancel: {
  1273. caption: '取消',
  1274. callback: function () {
  1275. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1276. }
  1277. }
  1278. });
  1279. } else {
  1280. postIsTp();
  1281. }
  1282. }
  1283. }
  1284. },
  1285. measureByBatch: function (posNames, ratio, apply2sibling) {
  1286. if (posNames.length <= 0) return;
  1287. if (ratio <= 0) return;
  1288. const fRatio = ZhCalc.div(ratio, 100);
  1289. const sheet = slSpread.getActiveSheet();
  1290. const node = SpreadJsObj.getSelectObject(sheet);
  1291. const parent = stageTree.getParent(node);
  1292. const nodes = apply2sibling === true ? (parent ? parent.children : stageTree.children) : [node];
  1293. const data = {updateType: 'batchUpdate', updateData: []};
  1294. for (const node of nodes) {
  1295. const posRange = stagePos.getLedgerPos(node.id);
  1296. if (!posRange || posRange <= 0) continue;
  1297. for (const p of posRange) {
  1298. if (posNames.indexOf(p.name) < 0) continue;
  1299. data.updateData.push({
  1300. pid: p.id, lid: p.lid,
  1301. contract_qty: ZhCalc.mul(p.quantity, fRatio),
  1302. contract_expr: `${p.quantity}*${ratio}%`,
  1303. });
  1304. }
  1305. }
  1306. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1307. if (result.pos) {
  1308. stagePos.updateDatas(result.pos.pos);
  1309. stagePos.loadCurStageData(result.pos.curStageData);
  1310. }
  1311. const nodes = stageTree.loadPostStageData(result.ledger);
  1312. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1313. stagePosSpreadObj.loadCurPosData();
  1314. if (detail) {
  1315. detail.loadStagePosUpdateData(result, nodes);
  1316. } else {
  1317. stageIm.loadUpdatePosData(result, nodes);
  1318. }
  1319. $('#calc-by-ratio').modal('hide');
  1320. }, function () {
  1321. stagePosSpreadObj.loadCurPosData();
  1322. $('#calc-by-ratio').modal('hide');
  1323. });
  1324. },
  1325. exportExcel: function (filename, nodes) {
  1326. const exportNodesData = function (data, nodes) {
  1327. for (const node of nodes) {
  1328. data.push({
  1329. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  1330. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  1331. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  1332. qc_qty: node.qc_qty, qc_tp: node.qc_tp,
  1333. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  1334. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  1335. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp,
  1336. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_final_1_percent: node.end_final_1_percent,
  1337. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  1338. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  1339. final_dgn_price: node.final_dgn_price,
  1340. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  1341. });
  1342. if (node.children && node.children.length > 0) {
  1343. exportNodesData(data, node.children);
  1344. } else {
  1345. const posRange = stagePos.getLedgerPos(node.id);
  1346. if (posRange && posRange.length > 0) {
  1347. for (const [i, p] of posRange.entries()) {
  1348. data.push({
  1349. pos_code: (i + 1) + '', name: p.name,
  1350. quantity: p.quantity,
  1351. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  1352. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  1353. drawing_code: p.drawing_code, memo: p.memo, postil: p.postil,
  1354. });
  1355. }
  1356. }
  1357. }
  1358. }
  1359. };
  1360. const data = [];
  1361. exportNodesData(data, nodes ? nodes : stageTree.children);
  1362. SpreadExcelObj.exportSimpleXlsxSheet(exportExcelSetting, data, filename);
  1363. }
  1364. };
  1365. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1366. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1367. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1368. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1369. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1370. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1371. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1372. SpreadJsObj.addCutEvents(slSpread, stageTreeSpreadObj.cut);
  1373. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1374. if (!readOnly) {
  1375. $('#bills-expr').bind('change onblur', function () {
  1376. if (this.readOnly) return;
  1377. const expr = $(this);
  1378. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1379. const select = stageTree.getItemsByIndex(row);
  1380. if (!select) return;
  1381. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1382. let newValue = expr.val();
  1383. const num = _.toNumber(newValue);
  1384. if (_.isFinite(num)) {
  1385. newValue = num;
  1386. } else {
  1387. try {
  1388. newValue = math.evaluate(transExpr(newValue));
  1389. } catch(err) {
  1390. toastr.error('输入的表达式非法');
  1391. return;
  1392. }
  1393. }
  1394. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1395. if (field.indexOf('_dgn_') > 0) {
  1396. updateData.dgn = {
  1397. id: select.id
  1398. };
  1399. updateData.dgn[field] = newValue;
  1400. } else {
  1401. updateData.stage = {
  1402. lid: select.id
  1403. };
  1404. updateData.stage[field] = newValue;
  1405. const exprInfo = getExprInfo(field);
  1406. if (exprInfo) {
  1407. updateData.stage[exprInfo.expr] = expr.val();
  1408. }
  1409. }
  1410. // 更新至服务器
  1411. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1412. const nodes = stageTree.loadPostStageData(result);
  1413. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1414. if (detail) {
  1415. detail.loadStageLedgerUpdateData(result, nodes);
  1416. } else {
  1417. stageIm.loadUpdateLedgerData(result, nodes);
  1418. }
  1419. });
  1420. });
  1421. }
  1422. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1423. const addTag = newTag({ledgerSheet: slSpread.getActiveSheet(), billsTag});
  1424. const tenderSelect = TenderSelect({
  1425. type: 'stage',
  1426. afterLoad: function (result, select) {
  1427. const nodes = stageTree.loadPostStageData(result);
  1428. const posterity = stageTree.getPosterity(select);
  1429. for (const p of posterity) {
  1430. p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
  1431. }
  1432. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1433. if (detail) {
  1434. detail.loadStageLedgerUpdateData(result, nodes);
  1435. } else {
  1436. stageIm.loadUpdateLedgerData(result, nodes);
  1437. }
  1438. if (result.sumLoadHis.errors.length > 0) {
  1439. sumLoadMiss.loadMissData(result.sumLoadHis.errors);
  1440. sumLoadMiss.show();
  1441. } else {
  1442. sumLoadMiss.clearMissData();
  1443. }
  1444. // todo 优化,仅加载需要刷新的变更令
  1445. if (checkedChanges) checkedChanges.reloadChangeData();
  1446. }
  1447. });
  1448. const batchImport = BatchImportStageGcl({
  1449. stageTree,
  1450. afterLoad: function (result, select) {
  1451. const nodes = stageTree.loadPostStageData(result);
  1452. const posterity = stageTree.getPosterity(select);
  1453. for (const p of posterity) {
  1454. p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
  1455. }
  1456. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1457. if (detail) {
  1458. detail.loadStageLedgerUpdateData(result, nodes);
  1459. } else {
  1460. stageIm.loadUpdateLedgerData(result, nodes);
  1461. }
  1462. if (checkedChanges) checkedChanges.reloadChangeData();
  1463. }
  1464. });
  1465. $.contextMenu({
  1466. selector: '#stage-ledger',
  1467. build: function ($trigger, e) {
  1468. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1469. stageTreeSpreadObj.loadRelaData();
  1470. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1471. },
  1472. items: {
  1473. 'locateZjjl': {
  1474. name: '定位至中间计量',
  1475. icon: 'fa-sign-in',
  1476. callback: function (key, opt) {
  1477. if (!detail) {
  1478. detail = new Detail($('#detail-spread'));
  1479. }
  1480. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1481. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1482. if (leafUsedBills) {
  1483. if (!$('#zhongjian').hasClass('active')) {
  1484. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  1485. $('a', '.side-menu').removeClass('active');
  1486. $('.tab-content .tab-select-show').removeClass('active');
  1487. tab.addClass('active');
  1488. tabPanel.addClass('active');
  1489. showSideTools(tab.hasClass('active'));
  1490. slSpread.refresh();
  1491. spSpread.refresh();
  1492. }
  1493. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1494. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1495. SpreadJsObj.locateData(detail.sheet, im);
  1496. detail.spread.refresh();
  1497. $('#zhongjian .sjs-bottom').height('400px');
  1498. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1499. detail.reLoadDetailData();
  1500. } else {
  1501. toastr.error('无可定位中间计量');
  1502. }
  1503. },
  1504. disabled: function (key, opt) {
  1505. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1506. return !node;
  1507. }
  1508. },
  1509. tagSpr: '----',
  1510. tag: {
  1511. name: '书签',
  1512. callback: function (key, opt, menu, e) {
  1513. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1514. addTag.do(node);
  1515. },
  1516. disabled: function (key, opt) {
  1517. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1518. return !node;
  1519. }
  1520. },
  1521. showSpr: '----',
  1522. showLast: {
  1523. name: '显示至最底层',
  1524. callback: function (key, opt, menu, e) {
  1525. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1526. setTimeout(() => {
  1527. showWaitingView();
  1528. stageTree.expandByCustom(x => {
  1529. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1530. });
  1531. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  1532. closeWaitingView();
  1533. }, 100);
  1534. },
  1535. disabled: function (key, opt) {
  1536. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1537. return !node;
  1538. }
  1539. },
  1540. exportSpr: '----',
  1541. exportSelectNodeXlsx: {
  1542. name: '导出选中节点至Excel',
  1543. callback: function (key, opt, menu, e) {
  1544. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1545. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  1546. },
  1547. disabled: function (key, opt) {
  1548. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1549. return !node;
  1550. }
  1551. },
  1552. importSpr: '---',
  1553. importStageGcl: {
  1554. name: '导入(其他标段)工程量清单计量数据',
  1555. icon: 'fa-link',
  1556. disabled: function (key, opt) {
  1557. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1558. return readOnly || !node || !stageTree.isLeafXmj(node);
  1559. },
  1560. callback: function (key, opt) {
  1561. tenderSelect.showSelect(SpreadJsObj.getSelectObject(slSpread.getActiveSheet()));
  1562. }
  1563. },
  1564. batchImportStageGcl: {
  1565. name: '批量导入(其他标段)工程量清单计量数据',
  1566. icon: 'fa-link',
  1567. disabled: function (key, opt) {
  1568. return readOnly;
  1569. },
  1570. callback: function (key, opt){
  1571. batchImport.show();
  1572. }
  1573. },
  1574. shoufangdanSpr: '---',
  1575. shoufangdan: {
  1576. name: '生成收方单',
  1577. visible: function(key, opt) {
  1578. if (cur_uid === stage.user_id) return true;
  1579. },
  1580. disabled: function (key, opt) {
  1581. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1582. if (!node || !node.b_code || !node.is_leaf || cur_uid !== stage.user_id) return true;
  1583. },
  1584. callback: function (key, opt) {
  1585. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1586. $('#shoufang-lid').val(node.id);
  1587. $('#shoufang-pid').val('');
  1588. $('#shoufang-ledger').text('清单:' + node.b_code);
  1589. $('#shoufang-pos').text('').hide();
  1590. $('#addshoufang').modal('show');
  1591. }
  1592. },
  1593. lockedSpr: '----',
  1594. lockedHint: {
  1595. name: '检查审批状态',
  1596. visible: function (key, opt) {
  1597. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1598. return node.locked;
  1599. },
  1600. callback: function (key, opt) {
  1601. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1602. const lockedInfo = stageTree.getLockedInfo(node);
  1603. toastr.warning(`审批人 ${lockedInfo.map(x => { return x.name; }).join(',')} 审批通过,如需修改,请联系审批人重新审批`);
  1604. }
  1605. },
  1606. }
  1607. });
  1608. const stagePosSpreadObj = {
  1609. loadExprToInput(sheet) {
  1610. const sel = sheet.getSelections()[0];
  1611. if (!sel) return;
  1612. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1613. if (col && col.type === 'Number') {
  1614. const data = SpreadJsObj.getSelectObject(sheet);
  1615. if (data) {
  1616. const exprInfo = getExprInfo(col.field);
  1617. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1618. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1619. .attr('readOnly', readOnly || cell.locked());
  1620. $('#pos-expr').attr('data-row', sel.row);
  1621. } else {
  1622. $('#pos-expr').val('').attr('readOnly', true);
  1623. $('#pos-expr').removeAttr('data-row');
  1624. }
  1625. } else {
  1626. $('#pos-expr').val('').attr('readOnly', true);
  1627. $('#pos-expr').removeAttr('data-row');
  1628. }
  1629. },
  1630. /**
  1631. * 加载计量单元 根据当前台账选择节点
  1632. */
  1633. loadCurPosData: function () {
  1634. const sheet = slSpread.getActiveSheet();
  1635. const node = SpreadJsObj.getSelectObject(sheet);
  1636. if (node) {
  1637. const posReadOnly = node.lock || (node.children && node.children.length > 0) || !node.b_code;
  1638. spSpread.getActiveSheet().zh_setting.readOnly = posReadOnly;
  1639. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1640. const posMeasure = $('#pos-measure')[0].checked;
  1641. posData.forEach(x => {
  1642. x.visible = !posMeasure || (!!x.contract_qty || !!x.qc_qty || !!x.qc_minus_qty);
  1643. });
  1644. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData, posReadOnly);
  1645. getNodeList(node.id);
  1646. } else {
  1647. spSpread.getActiveSheet().zh_setting.readOnly = true;
  1648. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', [], true);
  1649. }
  1650. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1651. },
  1652. editEnded: function (e, info) {
  1653. if (info.sheet.zh_setting) {
  1654. // 未改变过,则直接跳过
  1655. const sortData = info.sheet.zh_data;
  1656. const posData = sortData ? sortData[info.row] : null;
  1657. const col = info.sheet.zh_setting.cols[info.col];
  1658. const orgText = posData ? posData[col.field] : null;
  1659. const newText = trimInvalidChar(info.editingText);
  1660. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1661. return;
  1662. }
  1663. // 台账模式下,不可新增
  1664. if (checkTzMeasureType() && !posData) {
  1665. toastr.error('台账模式不可新增计量单元数据');
  1666. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1667. return ;
  1668. }
  1669. // 不同节点下,计量单元检查输入
  1670. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1671. const node = stagePosSpreadObj.stageTreeNode;
  1672. if (!node) {
  1673. toastr.warning('数据错误, 请刷新页面后再试');
  1674. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1675. return;
  1676. } else if (newText !== '' && node.children && node.children.length > 0) {
  1677. toastr.error('父节点不可插入计量单元');
  1678. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1679. return;
  1680. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1681. toastr.error('项目节不可插入计量单元');
  1682. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1683. return;
  1684. }
  1685. // 生成提交数据
  1686. const data = {};
  1687. if (col.field === 'name') {
  1688. if ((!newText || newText === '') && posData) {
  1689. toastr.error('部位名称不可为空');
  1690. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1691. return;
  1692. } else if (!posData) {
  1693. if (newText !== '') {
  1694. data.updateType = 'add';
  1695. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1696. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1697. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1698. return;
  1699. }
  1700. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1701. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1702. } else {
  1703. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1704. return;
  1705. }
  1706. } else {
  1707. data.updateType = 'update';
  1708. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1709. }
  1710. } else if (!posData) {
  1711. toastr.warning('新增计量单元请先输入名称');
  1712. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1713. data.updateType = 'update';
  1714. data.updateData = {pid: posData.id, lid: posData.lid};
  1715. data.updateData[col.field] = newText;
  1716. } else {
  1717. data.updateType = 'update';
  1718. data.updateData = {pid: posData.id, lid: posData.lid};
  1719. if (col.type === 'Number') {
  1720. const exprInfo = getExprInfo(col.field);
  1721. const num = _.toNumber(newText);
  1722. if (_.isFinite(num)) {
  1723. data.updateData[col.field] = num;
  1724. if (exprInfo) {
  1725. data.updateData[exprInfo.expr] = '';
  1726. }
  1727. } else {
  1728. try {
  1729. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1730. if (exprInfo) {
  1731. data.updateData[exprInfo.expr] = newText;
  1732. }
  1733. } catch(err) {
  1734. toastr.error('输入的表达式非法');
  1735. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1736. return;
  1737. }
  1738. }
  1739. } else {
  1740. data.updateData[col.field] = newText;
  1741. }
  1742. }
  1743. // 提交数据到服务器
  1744. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1745. if (result.pos) {
  1746. stagePos.updateDatas(result.pos.pos);
  1747. stagePos.loadCurStageData(result.pos.curStageData);
  1748. }
  1749. const refreshData = stageTree.loadPostStageData(result.ledger);
  1750. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1751. stagePosSpreadObj.loadCurPosData();
  1752. if (detail) {
  1753. detail.loadStagePosUpdateData(result, refreshData);
  1754. } else {
  1755. stageIm.loadUpdatePosData(result, refreshData);
  1756. }
  1757. }, function () {
  1758. stagePosSpreadObj.loadCurPosData();
  1759. });
  1760. }
  1761. },
  1762. editStarting: function (e, info) {
  1763. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1764. const sel = info.sheet.getSelections();
  1765. if (!sel || !sel[0]) return;
  1766. const col = info.sheet.zh_setting.cols[sel[0].col];
  1767. const node = SpreadJsObj.getSelectObject(info.sheet);
  1768. const exprInfo = getExprInfo(col.field);
  1769. if (exprInfo && node) {
  1770. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1771. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1772. }
  1773. }
  1774. },
  1775. clipboardPasting: function (e, info) {
  1776. if (info.sheet.zh_setting) {
  1777. const sortData = info.sheet.zh_data;
  1778. const range = info.cellRange;
  1779. const validField = ['contract_qty', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3'];
  1780. if (!checkTzMeasureType()) {
  1781. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1782. }
  1783. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1784. const col = info.sheet.zh_setting.cols[iCol];
  1785. if (validField.indexOf(col.field) === -1) {
  1786. if (checkTzMeasureType()) {
  1787. toastr.error('不可修改此数据');
  1788. info.cancel = true;
  1789. return;
  1790. } else {
  1791. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1792. const pos = sortData(iRow);
  1793. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1794. toastr.error('不可修改此数据');
  1795. info.cancel = true;
  1796. return;
  1797. }
  1798. }
  1799. }
  1800. }
  1801. }
  1802. }
  1803. },
  1804. clipboardPasted: function (e, info) {
  1805. if (info.sheet.zh_setting) {
  1806. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1807. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1808. }
  1809. const data = { updateType: '', updateData: [], };
  1810. const sortData = info.sheet.zh_data;
  1811. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1812. if (node.children && node.children.length > 0) return;
  1813. if (sortData && (info.cellRange.row >= sortData.length)) {
  1814. data.updateType = 'add';
  1815. if (info.cellRange.col !== 0) {
  1816. toastr.warning('新增计量单元请先输入名称');
  1817. stagePosSpreadObj.loadCurPosData();
  1818. return;
  1819. }
  1820. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1821. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1822. stagePosSpreadObj.loadCurPosData();
  1823. return;
  1824. }
  1825. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1826. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1827. const curRow = info.cellRange.row + iRow;
  1828. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1829. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1830. const curCol = info.cellRange.col + iCol;
  1831. const colSetting = info.sheet.zh_setting.cols[curCol];
  1832. if (!colSetting) continue;
  1833. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1834. if (colSetting.type === 'Number') {
  1835. const exprInfo = getExprInfo(colSetting.field);
  1836. if (newValue) {
  1837. const num = _.toNumber(newValue);
  1838. if (num) {
  1839. newData[colSetting.field] = num;
  1840. if (exprInfo) {
  1841. newData[exprInfo.expr] = '';
  1842. }
  1843. } else {
  1844. try {
  1845. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1846. if (exprInfo) {
  1847. newData[exprInfo.expr] = newValue;
  1848. }
  1849. } catch(err) {
  1850. toastr.error('输入的表达式非法');
  1851. stagePosSpreadObj.loadCurPosData();
  1852. return;
  1853. }
  1854. }
  1855. } else {
  1856. newData[colSetting.field] = null;
  1857. if (exprInfo) newData[exprInfo.expr] = '';
  1858. }
  1859. } else {
  1860. newData[colSetting.field] = newValue;
  1861. }
  1862. }
  1863. data.updateData.push(newData);
  1864. }
  1865. } else {
  1866. data.updateType = 'update';
  1867. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1868. const curRow = info.cellRange.row + iRow;
  1869. const curPos = sortData[curRow];
  1870. if (curPos) {
  1871. const newData = {pid: curPos.id, lid: curPos.lid};
  1872. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1873. const curCol = info.cellRange.col + iCol;
  1874. const colSetting = info.sheet.zh_setting.cols[curCol];
  1875. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1876. if (colSetting.type === 'Number') {
  1877. const exprInfo = getExprInfo(colSetting.field);
  1878. if (!newValue) {
  1879. newData[colSetting.field] = newValue;
  1880. if (exprInfo) newData[exprInfo.expr] = '';
  1881. continue;
  1882. }
  1883. const num = _.toNumber(newValue);
  1884. if (num) {
  1885. newData[colSetting.field] = num;
  1886. if (exprInfo) newData[exprInfo.expr] = '';
  1887. } else {
  1888. try {
  1889. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1890. const exprInfo = getExprInfo(colSetting.field);
  1891. if (exprInfo) newData[exprInfo.expr] = newValue;
  1892. } catch(err) {
  1893. toastr.error('输入的表达式非法');
  1894. stagePosSpreadObj.loadCurPosData();
  1895. return;
  1896. }
  1897. }
  1898. } else {
  1899. newData[colSetting.field] = newValue;
  1900. }
  1901. }
  1902. data.updateData.push(newData);
  1903. }
  1904. }
  1905. }
  1906. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1907. if (result.pos) {
  1908. stagePos.updateDatas(result.pos.pos);
  1909. stagePos.loadCurStageData(result.pos.curStageData);
  1910. }
  1911. const nodes = stageTree.loadPostStageData(result.ledger);
  1912. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1913. stagePosSpreadObj.loadCurPosData();
  1914. if (detail) {
  1915. detail.loadStagePosUpdateData(result, nodes);
  1916. } else {
  1917. stageIm.loadUpdatePosData(result, nodes);
  1918. }
  1919. }, function () {
  1920. stagePosSpreadObj.loadCurPosData();
  1921. });
  1922. }
  1923. },
  1924. deletePress: function (sheet) {
  1925. if (sheet.zh_setting.readOnly) return;
  1926. if (sheet.zh_setting && sheet.zh_data) {
  1927. const sortData = sheet.zh_data;
  1928. if (!sortData || sortData.length === 0) { return; }
  1929. const sel = sheet.getSelections()[0];
  1930. const validCols = [];
  1931. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1932. const colSetting = sheet.zh_setting.cols[iCol];
  1933. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  1934. validCols.push(iCol);
  1935. }
  1936. }
  1937. if (validCols.length === 0) { return; }
  1938. const datas = [], posSelects = [];
  1939. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1940. const node = sortData[iRow];
  1941. if (node) {
  1942. const data = {pid: node.id, lid: node.lid};
  1943. for (const iCol of validCols) {
  1944. const colSetting = sheet.zh_setting.cols[iCol];
  1945. if (colSetting.field === 'name') {
  1946. toastr.error('部位名称不能为空');
  1947. return;
  1948. }
  1949. data[colSetting.field] = null;
  1950. const exprInfo = getExprInfo(colSetting.field);
  1951. if (exprInfo) {
  1952. data[exprInfo.expr] = '';
  1953. }
  1954. }
  1955. datas.push(data);
  1956. posSelects.push(node);
  1957. }
  1958. }
  1959. if (datas.length > 0) {
  1960. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1961. if (result.pos) {
  1962. stagePos.updateDatas(result.pos.pos);
  1963. stagePos.loadCurStageData(result.pos.curStageData);
  1964. }
  1965. const nodes = stageTree.loadPostStageData(result.ledger);
  1966. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1967. if (detail) {
  1968. detail.loadStagePosUpdateData(result, nodes);
  1969. } else {
  1970. stageIm.loadUpdatePosData(result, nodes);
  1971. }
  1972. // todo 只加载改变项
  1973. stagePosSpreadObj.loadCurPosData();
  1974. });
  1975. }
  1976. }
  1977. },
  1978. deletePos: function (sheet) {
  1979. const sels = sheet.getSelections();
  1980. const sel = sels ? sels[0] : null;
  1981. if (sheet.zh_data && sel) {
  1982. const data = {updateType: 'delete', updateData: []};
  1983. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1984. const posData = sheet.zh_data[sel.row + iRow];
  1985. if (posData) {
  1986. data.updateData.push(posData.id);
  1987. }
  1988. }
  1989. if (data.updateData.length > 0) {
  1990. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1991. stagePos.removeDatas(result.pos.pos);
  1992. const refreshData = stageTree.loadPostStageData(result.ledger);
  1993. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1994. stagePosSpreadObj.loadCurPosData();
  1995. if (detail) {
  1996. detail.loadStagePosUpdateData(result, refreshData);
  1997. } else {
  1998. stageIm.loadUpdatePosData(result, refreshData);
  1999. }
  2000. });
  2001. }
  2002. }
  2003. },
  2004. selectionChanged: function (e, info) {
  2005. stagePosSpreadObj.loadExprToInput(info.sheet);
  2006. },
  2007. addPegs: function (pegs) {
  2008. if (!pegs || pegs.length <= 0) return;
  2009. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2010. if (!node) return;
  2011. const sheet = spSpread.getActiveSheet();
  2012. const sortData = sheet.zh_data || [];
  2013. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2014. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2015. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  2016. if (result.pos) {
  2017. stagePos.updateDatas(result.pos.pos);
  2018. }
  2019. stagePosSpreadObj.loadCurPosData();
  2020. });
  2021. }
  2022. };
  2023. $('#pos-measure').click(stagePosSpreadObj.loadCurPosData);
  2024. // 加载上下窗口resizer
  2025. $.divResizer({
  2026. select: '#main-resize',
  2027. callback: function () {
  2028. slSpread.refresh();
  2029. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2030. $(".sp-wrap").height(bcontent-30);
  2031. spSpread.refresh();
  2032. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2033. }
  2034. });
  2035. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  2036. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;import_change;tag;' }, function (result) {
  2037. // 加载树结构
  2038. stageTree.loadDatas(result.ledgerData, result.locked);
  2039. if (stage.assist) stageTree.loadFilter(stage.assist.ass_ledger_id);
  2040. // 加载部位明细
  2041. stagePos.loadDatas(result.posData);
  2042. checkShowLast(result.ledgerData.length);
  2043. treeCalc.calculateAll(stageTree);
  2044. for (const t of result.tags) {
  2045. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  2046. }
  2047. billsTag.loadDatas(result.tags);
  2048. stagePos.calculateAll();
  2049. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  2050. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  2051. stagePosSpreadObj.loadCurPosData();
  2052. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  2053. // 加载中间计量
  2054. stageIm.init(stage, imType, tenderInfo.decimal, stage.assist ? stage.assist.ass_ledger_id : '');
  2055. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData, result.import_change, result.detailAtt);
  2056. errorList.loadHisErrorData();
  2057. checkList.loadHisCheckData();
  2058. sumLoadMiss.loadHisMissData();
  2059. // 收方单赋值
  2060. ledgerData = result.ledgerData;
  2061. posData = result.posData;
  2062. makeShouFang();
  2063. }, null, true);
  2064. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2065. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2066. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2067. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2068. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2069. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2070. if (!readOnly) {
  2071. $('#pos-expr').bind('change onblur', function () {
  2072. if (this.readOnly) return;
  2073. const expr = $(this);
  2074. const posSheet = spSpread.getActiveSheet();
  2075. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2076. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2077. if (!select) return;
  2078. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2079. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2080. const data = {pid: select.id, lid: select.lid};
  2081. const exprInfo = getExprInfo(field);
  2082. if (newValue !== '') {
  2083. const num = _.toNumber(newValue);
  2084. if (num) {
  2085. data[field] = num;
  2086. if (exprInfo) data[exprInfo.expr] = '';
  2087. } else {
  2088. try {
  2089. data[field] = math.evaluate(transExpr(newValue));
  2090. if (exprInfo) data[exprInfo.expr] = newValue;
  2091. } catch (err) {
  2092. toastr.error('输入的表达式非法');
  2093. return;
  2094. }
  2095. }
  2096. } else {
  2097. data[field] = null;
  2098. if (exprInfo) data[exprInfo.expr] = '';
  2099. }
  2100. // 提交数据到服务器
  2101. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2102. if (result.pos) {
  2103. stagePos.updateDatas(result.pos.pos);
  2104. stagePos.loadCurStageData(result.pos.curStageData);
  2105. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2106. }
  2107. const refreshData = stageTree.loadPostStageData(result.ledger);
  2108. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2109. if (detail) {
  2110. detail.loadStagePosUpdateData(result, refreshData);
  2111. } else {
  2112. stageIm.loadUpdatePosData(result, refreshData);
  2113. }
  2114. });
  2115. });
  2116. }
  2117. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2118. $.contextMenu({
  2119. selector: '#stage-pos',
  2120. build: function ($trigger, e) {
  2121. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2122. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2123. },
  2124. items: {
  2125. 'del': {
  2126. name: '删除',
  2127. icon: 'fa-remove',
  2128. visible: function (key, opt) {
  2129. return !checkTzMeasureType();
  2130. },
  2131. disabled: function (key, opt) {
  2132. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2133. if (!node || node.lock) return true;
  2134. const sheet = spSpread.getActiveSheet();
  2135. if (sheet.zh_data && !readOnly) {
  2136. const selection = sheet.getSelections();
  2137. if (selection && selection[0]) {
  2138. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2139. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2140. const posData = sheet.zh_data[selection[0].row + iRow];
  2141. if (posData) {
  2142. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2143. valid = true;
  2144. break;
  2145. }
  2146. } else {
  2147. valid = true;
  2148. break;
  2149. }
  2150. }
  2151. return valid;
  2152. } else {
  2153. return true;
  2154. }
  2155. } else {
  2156. return true;
  2157. }
  2158. },
  2159. callback: function (key, opt) {
  2160. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2161. }
  2162. },
  2163. 'sort': {
  2164. name: '排序',
  2165. items: {
  2166. "addStageReverse": {
  2167. name: '按新增期倒序',
  2168. icon: 'fa-sort-amount-desc',
  2169. callback: function (key, opt) {
  2170. stagePos.sort = [['add_stage_order', 'desc'], ['porder', 'asc']];
  2171. const spSheet = spSpread.getActiveSheet();
  2172. if (spSheet.zh_data) {
  2173. spSheet.zh_data.sort((x, y) => { return y.add_stage_order - x.add_stage_order || x.porder - y.porder; });
  2174. SpreadJsObj.reLoadSheetData(spSheet);
  2175. }
  2176. }
  2177. }
  2178. }
  2179. },
  2180. 'merge-peg': {
  2181. name: '合并起讫桩号',
  2182. visible: function (key, opt) {
  2183. return !checkTzMeasureType();
  2184. },
  2185. disabled: function (key, opt) {
  2186. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2187. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2188. },
  2189. callback: function (key, opt) {
  2190. mergePeg.show();
  2191. }
  2192. },
  2193. 'calcByRatio': {
  2194. name: '按比例计量',
  2195. visible: function (key, opt) {
  2196. const data = spSpread.getActiveSheet().zh_data;
  2197. return checkTzMeasureType() && data && data.length > 0;
  2198. },
  2199. disabled: function (key, opt) {
  2200. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2201. return node.lock;
  2202. },
  2203. callback: function (key, opt) {
  2204. $('#cbr-ratio').val('');
  2205. $('#apply2sibling')[0].checked = false;
  2206. $('#cbr-check-all')[0].checked = false;
  2207. const html = [];
  2208. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2209. html.push('<tr>');
  2210. html.push('<td>', i+1, '</td>');
  2211. html.push('<td>', p.name, '</td>');
  2212. html.push('<td>', p.quantity, '</td>');
  2213. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2214. html.push('</tr>');
  2215. }
  2216. $('#cbr-pos-list').html(html.join(''));
  2217. $('#calc-by-ratio').modal('show');
  2218. }
  2219. },
  2220. 'remainCur': {
  2221. name: '填剩余量(选中行)',
  2222. disabled: function (key, opt) {
  2223. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2224. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2225. return readOnly || node.lock || !curPos;
  2226. },
  2227. callback: function (key, opt) {
  2228. const sheet = spSpread.getActiveSheet();
  2229. const sels = sheet.getSelections();
  2230. if (!sels || !sels[0]) return;
  2231. const data = { updateType: 'update', updateData: [] };
  2232. for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
  2233. const curRow = iRow + sels[0].row;
  2234. const curPos = SpreadJsObj.getRowObject(sheet, curRow);
  2235. if (!curPos) continue;
  2236. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2237. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2238. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2239. }
  2240. if (data.updateData.length > 0) {
  2241. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2242. if (result.pos) {
  2243. stagePos.updateDatas(result.pos.pos);
  2244. stagePos.loadCurStageData(result.pos.curStageData);
  2245. }
  2246. const nodes = stageTree.loadPostStageData(result.ledger);
  2247. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2248. stagePosSpreadObj.loadCurPosData();
  2249. if (detail) {
  2250. detail.loadStagePosUpdateData(result, nodes);
  2251. } else {
  2252. stageIm.loadUpdatePosData(result, nodes);
  2253. }
  2254. });
  2255. }
  2256. },
  2257. visible: function(key, opt) {
  2258. return checkTzMeasureType();
  2259. },
  2260. },
  2261. 'remainAll': {
  2262. name: '填剩余量(全部行)',
  2263. disabled: function (key, opt) {
  2264. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2265. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2266. return readOnly || node.lock || !curPos;
  2267. },
  2268. callback: function (key, opt) {
  2269. const sheet = spSpread.getActiveSheet();
  2270. if (!sheet.zh_data || sheet.zh_data.length === 0) return;
  2271. const data = { updateType: 'update', updateData: [] };
  2272. for (const curPos of sheet.zh_data) {
  2273. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2274. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2275. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2276. }
  2277. if (data.updateData.length > 0) {
  2278. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2279. if (result.pos) {
  2280. stagePos.updateDatas(result.pos.pos);
  2281. stagePos.loadCurStageData(result.pos.curStageData);
  2282. }
  2283. const nodes = stageTree.loadPostStageData(result.ledger);
  2284. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2285. stagePosSpreadObj.loadCurPosData();
  2286. if (detail) {
  2287. detail.loadStagePosUpdateData(result, nodes);
  2288. } else {
  2289. stageIm.loadUpdatePosData(result, nodes);
  2290. }
  2291. });
  2292. }
  2293. },
  2294. visible: function(key, opt) {
  2295. return checkTzMeasureType();
  2296. },
  2297. },
  2298. 'shoufangdan': {
  2299. name: '生成收方单',
  2300. visible: function(key, opt) {
  2301. if (cur_uid === stage.user_id) return true;
  2302. },
  2303. disabled: function (key, opt) {
  2304. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2305. if (!node || cur_uid !== stage.user_id) return true;
  2306. },
  2307. callback: function (key, opt) {
  2308. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2309. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2310. $('#shoufang-lid').val(node.lid);
  2311. $('#shoufang-pid').val(node.id);
  2312. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2313. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2314. $('#addshoufang').modal('show');
  2315. }
  2316. }
  2317. }
  2318. });
  2319. $.subMenu({
  2320. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2321. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2322. key: 'menu.1.0.0',
  2323. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2324. callback: function (info) {
  2325. if (info.mini) {
  2326. $('.panel-title').addClass('fluid');
  2327. $('#sub-menu').removeClass('panel-sidebar');
  2328. } else {
  2329. $('.panel-title').removeClass('fluid');
  2330. $('#sub-menu').addClass('panel-sidebar');
  2331. }
  2332. autoFlashHeight();
  2333. slSpread.refresh();
  2334. spSpread.refresh();
  2335. if (searchLedger) searchLedger.spread.refresh();
  2336. if (detail) detail.spread.refresh();
  2337. if (checkedChanges) checkedChanges.refresh();
  2338. if (errorList && errorList.spread) errorList.spread.refresh();
  2339. if (checkList) checkList.spread.refresh();
  2340. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2341. }
  2342. });
  2343. $('#row-view').on('show.bs.modal', function () {
  2344. const html = [], customDisplay = customColDisplay();
  2345. for (const cd of customDisplay) {
  2346. html.push('<tr>');
  2347. html.push('<td>', cd.title, '</td>');
  2348. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2349. html.push('</tr>');
  2350. }
  2351. $('#row-view-list').html(html.join(''));
  2352. });
  2353. $('#row-view-ok').click(function () {
  2354. const customDisplay = customColDisplay();
  2355. const cvl = $('#row-view-list').children();
  2356. for (const cv of cvl) {
  2357. const title = $(cv).children()[0].innerHTML;
  2358. const check = $('input', cv)[0].checked;
  2359. const cd = customDisplay.find(function (c) {
  2360. return c.title === title;
  2361. });
  2362. cd.visible = check;
  2363. }
  2364. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2365. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2366. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2367. $('#row-view').modal('hide');
  2368. });
  2369. const posSearch = (function () {
  2370. let resultArr = [];
  2371. const search = function () {
  2372. resultArr = [];
  2373. const keyword = $('#pos-search-keyword').val();
  2374. const checkOver = $('#pos-over-search')[0].checked;
  2375. const checkEmpty = $('#pos-empty-search')[0].checked;
  2376. const sortData = spSpread.getActiveSheet().zh_data;
  2377. if (checkOver || checkEmpty) {
  2378. if (sortData) {
  2379. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2380. const sd = sortData[i];
  2381. let match = false;
  2382. if (checkOver) {
  2383. if (sd.end_gather_qty) {
  2384. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2385. }
  2386. }
  2387. if (checkEmpty) {
  2388. if (sd.quantity) {
  2389. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2390. }
  2391. }
  2392. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2393. if (match) {
  2394. resultArr.push({index: i, data: sd});
  2395. }
  2396. }
  2397. }
  2398. } else if (keyword && keyword !== '') {
  2399. if (sortData) {
  2400. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2401. const sd = sortData[i];
  2402. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2403. resultArr.push({index: i, data: sd});
  2404. }
  2405. }
  2406. }
  2407. }
  2408. $('#pos-search-result').html('结果:' + resultArr.length);
  2409. };
  2410. const searchAndLocate = function () {
  2411. search();
  2412. if (resultArr.length > 0) {
  2413. const sheet = spSpread.getActiveSheet();
  2414. const sel = sheet.getSelections()[0];
  2415. const curRow = sel ? sel.row : 0;
  2416. const pos = resultArr[0];
  2417. if (pos.index !== curRow) {
  2418. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2419. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2420. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2421. }
  2422. }
  2423. };
  2424. const locateNext = function () {
  2425. if (resultArr.length > 0) {
  2426. const sheet = spSpread.getActiveSheet();
  2427. const sel = sheet.getSelections()[0];
  2428. const curRow = sel ? sel.row : 0;
  2429. let next = _.find(resultArr, function (d) {
  2430. return d.index > curRow;
  2431. });
  2432. if (!next) next = resultArr[0];
  2433. if (next.index !== curRow) {
  2434. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2435. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2436. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2437. }
  2438. }
  2439. };
  2440. const locatePre = function () {
  2441. if (resultArr.length > 0) {
  2442. const sheet = spSpread.getActiveSheet();
  2443. const sel = sheet.getSelections()[0];
  2444. const curRow = sel ? sel.row : 0;
  2445. let next = _.findLast(resultArr, function (d) {
  2446. return d.index < curRow;
  2447. });
  2448. if (!next) next = resultArr[resultArr.length - 1];
  2449. if (next.index !== curRow) {
  2450. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2451. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2452. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2453. }
  2454. }
  2455. };
  2456. return {search, searchAndLocate, locateNext, locatePre};
  2457. })();
  2458. $('#pos-search-keyword').bind('keydown', function(e){
  2459. if (e.keyCode == 13) posSearch.searchAndLocate();
  2460. });
  2461. $('#pos-empty-search').click(function () {
  2462. if (this.checked) {
  2463. $('[for=' + this.id +']').addClass('text-warning');
  2464. } else {
  2465. $('[for=' + this.id +']').removeClass('text-warning');
  2466. }
  2467. if (this.checked) {
  2468. if ($('#pos-over-search')[0].checked) {
  2469. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2470. } else {
  2471. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2472. }
  2473. } else {
  2474. if ($('#pos-over-search')[0].checked) {
  2475. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2476. } else {
  2477. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2478. }
  2479. }
  2480. posSearch.searchAndLocate();
  2481. });
  2482. $('#pos-over-search').click(function () {
  2483. if (this.checked) {
  2484. $('[for=' + this.id +']').addClass('text-danger');
  2485. } else {
  2486. $('[for=' + this.id +']').removeClass('text-danger');
  2487. }
  2488. if (this.checked) {
  2489. if ($('#pos-empty-search')[0].checked) {
  2490. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2491. } else {
  2492. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2493. }
  2494. } else {
  2495. if ($('#pos-empty-search')[0].checked) {
  2496. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2497. } else {
  2498. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2499. }
  2500. }
  2501. posSearch.searchAndLocate();
  2502. });
  2503. $('#pos-search-next').click(() => {posSearch.locateNext()});
  2504. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  2505. $.divResizer({
  2506. select: '#right-spr',
  2507. callback: function () {
  2508. slSpread.refresh();
  2509. spSpread.refresh();
  2510. if (searchLedger) {
  2511. searchLedger.spread.refresh();
  2512. }
  2513. if (detail) {
  2514. detail.spread.refresh();
  2515. }
  2516. if (checkedChanges) checkedChanges.refresh();
  2517. if (errorList && errorList.spread) errorList.spread.refresh();
  2518. if (checkList) checkList.spread.refresh();
  2519. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2520. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2521. }
  2522. });
  2523. // 中间计量加载上下窗口resizer
  2524. $.divResizer({
  2525. select: '#zhongjian-spr',
  2526. callback: function () {
  2527. if (detail) {
  2528. detail.spread.refresh();
  2529. }
  2530. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2531. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2532. }
  2533. });
  2534. // 附件加载上下窗口resizer
  2535. $.divResizer({
  2536. select: '#file-spr',
  2537. callback: function () {
  2538. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2539. }
  2540. });
  2541. // 变更令加载上下窗口resizer
  2542. $.divResizer({
  2543. select: '#change-spr',
  2544. callback: function () {
  2545. if (checkedChanges) checkedChanges.refresh();
  2546. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2547. }
  2548. });
  2549. class Detail {
  2550. constructor (obj) {
  2551. const self = this;
  2552. this.spreadSetting = {
  2553. cols: [
  2554. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2555. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2556. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  2557. {
  2558. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  2559. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  2560. },
  2561. {
  2562. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  2563. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  2564. return data.attachment ? data.attachment.length : 0;
  2565. }
  2566. },
  2567. ],
  2568. headRows: 1,
  2569. emptyRows: 0,
  2570. headRowHeight: [32],
  2571. headColWidth: [30],
  2572. defaultRowHeight: 21,
  2573. headerFont: '12px 微软雅黑',
  2574. font: '12px 微软雅黑',
  2575. readOnly: readOnly,
  2576. selectedBackColor: '#fffacd',
  2577. imageClick: function (data) {
  2578. self.makeAttTable(data);
  2579. $('#im-file').modal('show');
  2580. }
  2581. };
  2582. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  2583. this.sheet = this.spread.getActiveSheet();
  2584. this.spread.options.allowUserDragFill = true;
  2585. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  2586. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2587. this.detailObj = {
  2588. selectionChanged: function (e, info) {
  2589. self.reLoadDetailData();
  2590. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  2591. self.loadLocateInfo();
  2592. }
  2593. },
  2594. editEnded: function(e, info) {
  2595. if (info.sheet.zh_setting) {
  2596. const col = info.sheet.zh_setting.cols[info.col];
  2597. if (col.field !== 'doc_code') {
  2598. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2599. return;
  2600. }
  2601. const data = SpreadJsObj.getSelectObject(info.sheet);
  2602. if (data) {
  2603. const updateData = {lid: data.lid, pid: data.pid};
  2604. if (data.uuid) {
  2605. updateData.uuid = data.uuid;
  2606. } else {
  2607. updateData.code = data.code;
  2608. updateData.name = data.name;
  2609. updateData.unit = data.unit;
  2610. updateData.unit_price = data.unit_price;
  2611. updateData.pid = data.pid;
  2612. updateData.pos_name = data.pos_name;
  2613. updateData.im_type = data.im_type;
  2614. }
  2615. if (data.custom_define.indexOf('doc_code') === -1) {
  2616. updateData.custom_define = data.custom_define;
  2617. updateData.custom_define.push('doc_code');
  2618. updateData.custom_define = updateData.custom_define.join(',');
  2619. }
  2620. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  2621. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2622. stageIm.loadUpdateDetailData(result);
  2623. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2624. }, function () {
  2625. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2626. });
  2627. } else {
  2628. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2629. }
  2630. }
  2631. },
  2632. clipboardPasted: function (e, info) {
  2633. if (info.sheet.zh_setting && info.sheet.zh_data) {
  2634. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  2635. if (info.cellRange.colCount > 1) {
  2636. toastr.warning('请勿同时复制粘贴多列数据');
  2637. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2638. return;
  2639. }
  2640. if (col.field !== 'doc_code') {
  2641. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2642. return;
  2643. }
  2644. const datas = [];
  2645. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2646. const curRow = info.cellRange.row + iRow;
  2647. const data = info.sheet.zh_data[curRow];
  2648. if (data) {
  2649. const updateData = {lid: data.lid, pid: data.pid};
  2650. if (data.uuid) {
  2651. updateData.uuid = data.uuid;
  2652. } else {
  2653. updateData.code = data.code;
  2654. updateData.name = data.name;
  2655. updateData.unit = data.unit;
  2656. updateData.unit_price = data.unit_price;
  2657. updateData.pid = data.pid;
  2658. updateData.pos_name = data.pos_name;
  2659. updateData.im_type = data.im_type;
  2660. }
  2661. if (data.custom_define.indexOf('doc_code') === -1) {
  2662. updateData.custom_define = data.custom_define;
  2663. updateData.custom_define.push('doc_code');
  2664. updateData.custom_define = updateData.custom_define.join(',');
  2665. }
  2666. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  2667. datas.push(updateData);
  2668. }
  2669. }
  2670. if (datas.length > 0) {
  2671. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2672. stageIm.loadUpdateDetailData(result);
  2673. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2674. }, function () {
  2675. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2676. })
  2677. }
  2678. }
  2679. },
  2680. deletePress: function (sheet) {
  2681. if (sheet.zh_setting) {
  2682. const datas = [];
  2683. const sel = sheet.getSelections()[0];
  2684. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2685. const col = sheet.zh_setting.cols[iCol];
  2686. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2687. const data = sheet.zh_data[iRow];
  2688. if (col.field === 'doc_code') {
  2689. const updateData = {lid: data.lid};
  2690. if (data.uuid) {
  2691. updateData.uuid = data.uuid;
  2692. updateData.doc_code = '';
  2693. datas.push(updateData);
  2694. }
  2695. }
  2696. }
  2697. }
  2698. if (datas.length > 0) {
  2699. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2700. stageIm.loadUpdateDetailData(result);
  2701. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2702. }, function () {
  2703. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2704. });
  2705. }
  2706. }
  2707. },
  2708. dragFillBlock: function (e, info) {
  2709. info.cancel = true;
  2710. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2711. const sel = info.sheet.getSelections()[0];
  2712. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2713. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2714. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2715. if (text === '') return;
  2716. const regRst = /(\d+)$/g.exec(text), datas = [];
  2717. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2718. const curRow = info.fillRange.row + iRow;
  2719. const data = info.sheet.zh_data[curRow];
  2720. if (data) {
  2721. const updateData = {lid: data.lid};
  2722. if (data.uuid) {
  2723. updateData.uuid = data.uuid;
  2724. } else {
  2725. updateData.code = data.code;
  2726. updateData.name = data.name;
  2727. updateData.unit = data.unit;
  2728. updateData.unit_price = data.unit_price;
  2729. updateData.pid = data.pid;
  2730. updateData.pos_name = data.pos_name;
  2731. updateData.im_type = data.im_type;
  2732. }
  2733. if (regRst) {
  2734. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2735. } else {
  2736. updateData.doc_code = text.replace('\n', '');
  2737. }
  2738. if (data.custom_define.indexOf('doc_code') === -1) {
  2739. updateData.custom_define = data.custom_define;
  2740. updateData.custom_define.push('doc_code');
  2741. updateData.custom_define = updateData.custom_define.join(',');
  2742. }
  2743. datas.push(updateData);
  2744. }
  2745. }
  2746. if (datas.length > 0) {
  2747. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2748. stageIm.loadUpdateDetailData(result);
  2749. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2750. }, function () {
  2751. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2752. })
  2753. }
  2754. },
  2755. };
  2756. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2757. if (!readOnly) {
  2758. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2759. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2760. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2761. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2762. }
  2763. this._initImTypeSetRela();
  2764. this._initModifyDetail();
  2765. this._initLocateRela();
  2766. this._initAttRela();
  2767. // 草图相关
  2768. this._initImageRela();
  2769. this.reBuildImData();
  2770. }
  2771. makeAttTable (data) {
  2772. let html = [];
  2773. if (data.attachment) {
  2774. for (const att of data.attachment) {
  2775. const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked))
  2776. ? '<a class="delete-att text-danger ml-1" href="javascript:void(0);" data-imid="'+ data.att_uuid +'" data-attid="'+ att.file_id +'" title="删除"><i class="fa fa-remove "></i></a>'
  2777. : '';
  2778. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  2779. const downloadHtml = '<a href="'+ window.location.pathname + '/im-file/download?im_id='+ data.att_uuid +'&file_id='+ att.file_id +'" title="下载"><i class="fa fa-download "></i></a>';
  2780. html.push(`<tr><td><input type="checkbox" name="sia-check" fid="${att.file_id}"></td><td style="width: 200px">` + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
  2781. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  2782. }
  2783. }
  2784. $('#im-attList').html(html.join(''));
  2785. }
  2786. _initAttRela() {
  2787. // 上传附件
  2788. const self = this;
  2789. $('#upload-im-file').change(function () {
  2790. const files = this.files;
  2791. const sels = self.sheet.getSelections();
  2792. const select = SpreadJsObj.getSelectObject(self.sheet);
  2793. if (!select) return;
  2794. const formData = new FormData();
  2795. const baseInfo = {};
  2796. if (select.att_uuid) {
  2797. baseInfo.uuid = select.att_uuid;
  2798. } else {
  2799. baseInfo.im_type = select.im_type;
  2800. baseInfo.lid = select.lid;
  2801. baseInfo.pid = select.pid;
  2802. baseInfo.code = select.code;
  2803. baseInfo.name = select.name;
  2804. baseInfo.unit = select.unit;
  2805. baseInfo.unit_price = select.unit_price;
  2806. baseInfo.pos_name = select.pos_name;
  2807. }
  2808. formData.append('base', JSON.stringify(baseInfo));
  2809. for (const file of files) {
  2810. if (file === undefined) {
  2811. toast('未选择上传文件!', 'error');
  2812. return false;
  2813. }
  2814. const filesize = file.size;
  2815. if (filesize > 30 * 1024 * 1024) {
  2816. toast('存在上传文件大小过大!', 'error');
  2817. return false;
  2818. }
  2819. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2820. if (whiteList.indexOf(fileext) === -1) {
  2821. toast('只能上传指定格式的附件!', 'error');
  2822. return false;
  2823. }
  2824. formData.append('size', filesize);
  2825. formData.append('file[]', file);
  2826. }
  2827. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  2828. stageIm.loadUpdateDetailAtt(data);
  2829. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  2830. self.makeAttTable(select);
  2831. $('#upload-im-file').val('');
  2832. });
  2833. });
  2834. // 删除附件
  2835. $('body').on('click', '.delete-att' ,function () {
  2836. const sels = self.sheet.getSelections();
  2837. const select = SpreadJsObj.getSelectObject(self.sheet);
  2838. if (!select) return;
  2839. const uuid = $(this).attr('data-imid');
  2840. const file_id = $(this).attr('data-attid');
  2841. const att = select.attachment.find(x => {
  2842. return x.file_id === file_id;
  2843. });
  2844. deleteAfterHint(function () {
  2845. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  2846. stageIm.loadUpdateDetailAtt(result);
  2847. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  2848. self.makeAttTable(select);
  2849. });
  2850. }, `确认删除附件「${att.filename}」?`);
  2851. });
  2852. // 预览附件
  2853. $('body').on('click', '.preview-att', function () {
  2854. const uuid = $(this).attr('data-imid');
  2855. const file_id = $(this).attr('data-attid');
  2856. postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
  2857. const { filepath } = result;
  2858. $('#load-file').attr('href', filepath);
  2859. $('#load-file')[0].click();
  2860. });
  2861. });
  2862. $('#batch-download-im-file').click(function() {
  2863. const select = $('[name=sia-check]:checked');
  2864. if (select.length === 0) {
  2865. toastr.warning('请选择需要批量下载的文件');
  2866. return;
  2867. }
  2868. const files = [];
  2869. const curIm = SpreadJsObj.getSelectObject(self.sheet);
  2870. for (const s of select) {
  2871. const att = curIm.attachment.find(x => { return x.file_id === s.getAttribute('fid')});
  2872. if (att) files.push(att);
  2873. }
  2874. if (files.length === 0) return;
  2875. AliOss.zipFiles(files, `中间计量[${curIm.code}].zip`, (fails) => {
  2876. $(self).removeAttr('disabled');
  2877. if (fails.length === 0) {
  2878. toastr.success('下载成功');
  2879. } else {
  2880. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  2881. }
  2882. }, () => {
  2883. $(self).removeAttr('disabled');
  2884. toastr.error('批量下载失败');
  2885. });
  2886. });
  2887. }
  2888. _initImTypeSetRela() {
  2889. const self = this;
  2890. const gatherConfirmPopover = {
  2891. reBind: function (obj, eventName, fun) {
  2892. obj.unbind(eventName);
  2893. obj.bind(eventName, fun);
  2894. },
  2895. check: function (pos, hint, okCallback) {
  2896. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2897. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2898. this.reBind(cancelObj, 'click', function () {
  2899. confirmObj.hide();
  2900. });
  2901. this.reBind(okObj, 'click', function () {
  2902. okCallback();
  2903. confirmObj.hide();
  2904. });
  2905. hintObj.text(hint);
  2906. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2907. }
  2908. };
  2909. this.gsTree = stageIm.getGsTree();
  2910. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2911. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2912. jlCol.title = '本期计量金额';
  2913. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2914. $('[name=type-title-contract]').text('本期合同计量金额');
  2915. $('[name=type-title-qc]').text('本期变更计量金额');
  2916. if ($('#show-qc-minus-jl').length > 0) {
  2917. $('#show-qc-minus-jl').parent().hide();
  2918. $('#qc-minus-jl').parent().hide();
  2919. }
  2920. } else {
  2921. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2922. jlCol.title = '本期计量数量';
  2923. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2924. $('[name=type-title-contract]').text('本期合同计量数量');
  2925. $('[name=type-title-qc]').text('本期变更计量数量');
  2926. if ($('#show-qc-minus-jl').length > 0) {
  2927. $('#show-qc-minus-jl').parent().show();
  2928. $('#qc-minus-jl').parent().show();
  2929. }
  2930. }
  2931. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2932. $('#show-jldy').parent().show();
  2933. $('#jldy').parent().show();
  2934. $('#show-xm-name').parent().hide();
  2935. $('#xm-name').parent().hide();
  2936. } else {
  2937. $('#show-jldy').parent().hide();
  2938. $('#jldy').parent().hide();
  2939. $('#show-xm-name').parent().show();
  2940. $('#xm-name').parent().show();
  2941. }
  2942. // 选择中间计量模式
  2943. $('div[name="im-type"]').click(function () {
  2944. function chooseType(obj) {
  2945. obj.style.cursor = 'default';
  2946. $(obj).children().addClass('text-primary');
  2947. $(obj).addClass('border-primary');
  2948. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2949. }
  2950. function validType(obj) {
  2951. obj.style.cursor = 'pointer';
  2952. $(obj).children().removeClass('text-primary');
  2953. $(obj).removeClass('border-primary');
  2954. $('i', obj).remove();
  2955. }
  2956. if (this.style.cursor === 'pointer') {
  2957. const typeArr = $('div[name="im-type"]');
  2958. for (const t of typeArr) {
  2959. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2960. chooseType(t);
  2961. } else {
  2962. validType(t)
  2963. }
  2964. }
  2965. }
  2966. });
  2967. $('#choose').on('show.bs.modal', function () {
  2968. function chooseType(obj) {
  2969. obj.style.cursor = 'default';
  2970. $(obj).children().addClass('text-primary');
  2971. $('i', obj).remove();
  2972. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2973. }
  2974. function validType(obj) {
  2975. obj.style.cursor = 'pointer';
  2976. $(obj).children().removeClass('text-primary');
  2977. $('i', obj).remove();
  2978. }
  2979. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2980. $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
  2981. const typeArr = $('div[name="im-type"]');
  2982. for (const t of typeArr) {
  2983. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2984. chooseType(t);
  2985. } else {
  2986. validType(t)
  2987. }
  2988. }
  2989. });
  2990. // 提交 中间计量模式
  2991. $('#choose-ok').click(() => {
  2992. let startNum;
  2993. try {
  2994. startNum = parseInt($('#im-start-num').val());
  2995. if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
  2996. } catch (err) {
  2997. toastr.error("起始编号请输入正整数");
  2998. return;
  2999. }
  3000. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  3001. return it.style.cursor !== 'pointer';
  3002. });
  3003. const data = {
  3004. im_type: parseInt($(chooseType).attr('im-type')),
  3005. im_pre: $('#im-pre').val(),
  3006. im_start_num: startNum,
  3007. };
  3008. postData(window.location.pathname + '/detail/build', data, function (result) {
  3009. stage.im_type = data.im_type;
  3010. stage.im_pre = data.im_pre;
  3011. stage.im_start_num = data.im_start_num;
  3012. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3013. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3014. jlCol.title = '本期计量金额';
  3015. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3016. $('[name=type-title-contract]').text('本期合同计量金额');
  3017. $('[name=type-title-qc]').text('本期变更计量金额');
  3018. if ($('#show-qc-minus-jl').length > 0) {
  3019. $('#show-qc-minus-jl').parent().hide();
  3020. $('#qc-minus-jl').parent().hide();
  3021. }
  3022. } else {
  3023. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3024. jlCol.title = '本期计量数量';
  3025. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3026. $('[name=type-title-contract]').text('本期合同计量数量');
  3027. $('[name=type-title-qc]').text('本期变更计量数量');
  3028. if ($('#show-qc-minus-jl').length > 0) {
  3029. $('#show-qc-minus-jl').parent().show();
  3030. $('#qc-minus-jl').parent().show();
  3031. }
  3032. }
  3033. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3034. $('#show-jldy').parent().show();
  3035. $('#jldy').parent().show();
  3036. $('#show-xm-name').parent().hide();
  3037. $('#xm-name').parent().hide();
  3038. } else {
  3039. $('#show-jldy').parent().hide();
  3040. $('#jldy').parent().hide();
  3041. $('#show-xm-name').parent().show();
  3042. $('#xm-name').parent().show();
  3043. }
  3044. // 加载生成数据
  3045. self.reBuildImData();
  3046. $('#choose').modal('hide');
  3047. });
  3048. });
  3049. // 显示树结构信息
  3050. $('#choose2').on('shown.bs.modal', function () {
  3051. if (!self.gsSpread) {
  3052. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  3053. const setting = {
  3054. cols: [
  3055. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  3056. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  3057. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3058. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  3059. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  3060. ],
  3061. headRows: 1,
  3062. emptyRows: 0,
  3063. headRowHeight: [32],
  3064. defaultRowHeight: 21,
  3065. headerFont: '12px 微软雅黑',
  3066. font: '12px 微软雅黑',
  3067. };
  3068. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  3069. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  3070. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  3071. function checkParent(node) {
  3072. const parent = self.gsTree.getParent(node);
  3073. if (parent) {
  3074. return parent.check ? parent.check : checkParent(parent);
  3075. } else {
  3076. return false;
  3077. }
  3078. }
  3079. function checkChildren(node) {
  3080. for (const child of node.children) {
  3081. if (child.check) {
  3082. return true;
  3083. } else if (checkChildren(child)) {
  3084. return true;
  3085. }
  3086. }
  3087. return false;
  3088. }
  3089. if (!$('#im-gather-check')[0].checked) { return; }
  3090. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  3091. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  3092. if (sheet.isEditing()) {
  3093. sheet.endEdit(true);
  3094. }
  3095. }
  3096. if (info.sheet.zh_setting) {
  3097. const col = info.sheet.zh_setting.cols[info.col];
  3098. if (col.field !== 'check') {
  3099. return;
  3100. }
  3101. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  3102. const node = sortData[info.row];
  3103. if (!node.check) {
  3104. if (checkParent(node)) {
  3105. const rect = info.sheet.getCellRect(info.row, info.col);
  3106. gatherConfirmPopover.check({
  3107. x: rect.x + rect.width / 2 + 25,
  3108. y: rect.y + rect.height / 2 + 3,
  3109. }, '父项已勾选,继续将取消父项勾选。', function () {
  3110. node.check = true;
  3111. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  3112. const rows = [self.gsTree.nodes.indexOf(node)];
  3113. for (const p of parents) {
  3114. if (p.check) {
  3115. p.check = false;
  3116. rows.push(self.gsTree.nodes.indexOf(p));
  3117. }
  3118. }
  3119. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3120. });
  3121. } else if (checkChildren(node)) {
  3122. const rect = info.sheet.getCellRect(info.row, info.col);
  3123. gatherConfirmPopover.check({
  3124. x: rect.x + rect.width / 2 + 25,
  3125. y: rect.y + rect.height / 2 + 3,
  3126. }, '子项已勾选,继续将取消子项勾选。', function () {
  3127. node.check = true;
  3128. const posterity = self.gsTree.getPosterity(node);
  3129. const rows = [self.gsTree.nodes.indexOf(node)];
  3130. for (const p of posterity) {
  3131. if (p.check) {
  3132. rows.push(self.gsTree.nodes.indexOf(p));
  3133. p.check = false;
  3134. }
  3135. }
  3136. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3137. });
  3138. } else {
  3139. node.check = true;
  3140. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3141. }
  3142. } else {
  3143. node.check = false;
  3144. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3145. }
  3146. }
  3147. });
  3148. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3149. for (const node of self.gsTree.datas) {
  3150. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3151. }
  3152. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  3153. self.gsTree.expandByLevel(4);
  3154. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  3155. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  3156. } else {
  3157. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3158. for (const node of self.gsTree.datas) {
  3159. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3160. }
  3161. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  3162. }
  3163. });
  3164. // 提交 高级设置
  3165. $('#choose2-ok').click(() => {
  3166. if (!self.gsTree) { return; }
  3167. const nodes = [];
  3168. for (const node of self.gsTree.datas) {
  3169. if (node.check) {
  3170. nodes.push(node.id);
  3171. }
  3172. }
  3173. const data = {
  3174. im_gather: $('#im-gather-check')[0].checked,
  3175. im_gather_node: nodes.join(','),
  3176. };
  3177. postData(window.location.pathname + '/detail/adv', data, function (result) {
  3178. stage.im_gather = data.im_gather;
  3179. stage.im_gather_node = data.im_gather_node;
  3180. $('#choose2').modal('hide');
  3181. });
  3182. });
  3183. }
  3184. _initLocateRela() {
  3185. const self = this;
  3186. $('#im-locate2bills').click(function () {
  3187. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3188. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3189. if (select && select.source) {
  3190. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  3191. stagePosSpreadObj.loadCurPosData();
  3192. }
  3193. });
  3194. $('#im-locate-pre').click(function () {
  3195. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3196. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3197. if (select && select.source) {
  3198. const targetIndex = Math.max(curIndex-1, 1);
  3199. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3200. stagePosSpreadObj.loadCurPosData();
  3201. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3202. }
  3203. });
  3204. $('#im-locate-next').click(function () {
  3205. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3206. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3207. if (select && select.source) {
  3208. const targetIndex = Math.min(curIndex+1, select.source.length);
  3209. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3210. stagePosSpreadObj.loadCurPosData();
  3211. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3212. }
  3213. });
  3214. }
  3215. _initModifyDetail() {
  3216. const self = this;
  3217. // 重置
  3218. $('#reset-detail-ok').click(function () {
  3219. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3220. if (!data.uuid) return;
  3221. const updateData = {
  3222. lid: data.lid, pid: data.pid,
  3223. uuid: data.uuid,
  3224. custom_define: [],
  3225. };
  3226. for (const f of data.custom_define) {
  3227. if (stageIm.resetFields.indexOf(f) >= 0) {
  3228. updateData[f] = null;
  3229. } else {
  3230. updateData.custom_define.push(f);
  3231. }
  3232. }
  3233. updateData.custom_define = updateData.custom_define.join(',');
  3234. $('#reset-detail-modal').modal('hide');
  3235. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3236. stageIm.loadUpdateDetailData(result);
  3237. self.reLoadDetailData();
  3238. });
  3239. });
  3240. // 编辑
  3241. $('#edit-detail').click(function () {
  3242. $(this).hide();
  3243. $('#save-detail').show();
  3244. $('#cancel-detail').show();
  3245. $('#detail-show').hide();
  3246. $('#detail-edit').show();
  3247. self.updateImageData = null;
  3248. });
  3249. // 保存
  3250. $('#save-detail').click(() => {
  3251. function check(field, obj, org, update) {
  3252. const newValue = obj.val();
  3253. if (!org[field]) {
  3254. if (newValue !== '') {
  3255. update[field] = newValue;
  3256. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3257. return true;
  3258. }
  3259. } else if (newValue !== org[field]){
  3260. update[field] = newValue;
  3261. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3262. return true;
  3263. }
  3264. return false;
  3265. }
  3266. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3267. const updateData = {lid: data.lid, pid: data.pid};
  3268. if (data.uuid) {
  3269. updateData.uuid = data.uuid;
  3270. updateData.custom_define = data.custom_define;
  3271. } else {
  3272. updateData.code = data.code;
  3273. updateData.name = data.name;
  3274. updateData.unit = data.unit;
  3275. updateData.unit_price = data.unit_price;
  3276. updateData.pid = data.pid;
  3277. updateData.pos_name = data.pos_name;
  3278. updateData.im_type = data.im_type;
  3279. updateData.custom_define = [];
  3280. }
  3281. let infoUpdate = false;
  3282. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  3283. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  3284. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  3285. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  3286. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  3287. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  3288. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  3289. updateData.custom_define = updateData.custom_define.join(',');
  3290. if (infoUpdate) {
  3291. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3292. stageIm.loadUpdateDetailData(result);
  3293. self.reLoadDetailData();
  3294. if (!self.updateImageData) return;
  3295. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  3296. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3297. stageIm.loadUpdateDetailData(result);
  3298. self.reLoadDetailData();
  3299. });
  3300. });
  3301. } else if (self.updateImageData) {
  3302. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3303. stageIm.loadUpdateDetailData(result);
  3304. self.reLoadDetailData();
  3305. });
  3306. } else {
  3307. self.reLoadDetailData();
  3308. }
  3309. });
  3310. // 取消
  3311. $('#cancel-detail').click(() => {
  3312. self.reLoadDetailData();
  3313. });
  3314. }
  3315. _initImageRela() {
  3316. const self = this;
  3317. $('#edit-detail').click(function () {
  3318. loadImageItem();
  3319. });
  3320. function setdraggrable(){
  3321. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3322. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3323. stop: function( event, ui ) {
  3324. }
  3325. });
  3326. }
  3327. function upload(formData) {
  3328. if (formData.length < 1) {
  3329. return;
  3330. }
  3331. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3332. const html = [];
  3333. html.push('<div class="img-item">');
  3334. html.push('<div class="img-bar">');
  3335. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3336. html.push('</div>');
  3337. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3338. html.push('</div>');
  3339. $('.img-view').append(html.join(''));
  3340. $('.img-bar').click(removeImageItem);
  3341. setdraggrable();
  3342. $('#upload-img-file').val('');
  3343. });
  3344. }
  3345. function dragFile(e) {
  3346. var file = null,
  3347. data = e.dataTransfer.types;
  3348. for (var i = 0; i < data.length; i += 1) {
  3349. if (data[i] === 'Files') {
  3350. file = e.dataTransfer.files; //获取文件
  3351. break;
  3352. }
  3353. }
  3354. if (file && file[0].type.indexOf('image') !== -1) {
  3355. var formData = new FormData();
  3356. formData.append('file', file[0]); //上传单个文件的添加方式
  3357. upload(formData); //upload 异步上传
  3358. }
  3359. }
  3360. // 移动图片
  3361. const moveImageItem = function (ev) {
  3362. const item = this;
  3363. const view = $('.img-view')[0];
  3364. let oEvent = ev;
  3365. // 浏览器有一些图片的默认事件,这里要阻止
  3366. oEvent.preventDefault();
  3367. let disX = oEvent.clientX - item.offsetLeft;
  3368. let disY = oEvent.clientY - item.offsetTop;
  3369. view.onmousemove = function (ev) {
  3370. oEvent = ev;
  3371. oEvent.preventDefault();
  3372. let x = oEvent.clientX -disX;
  3373. let y = oEvent.clientY -disY;
  3374. // 图形移动的边界判断
  3375. x = x <= 0 ? 0 : x;
  3376. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  3377. y = y <= 0 ? 0 : y;
  3378. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  3379. item.style.left = x + 'px';
  3380. item.style.top = y + 'px';
  3381. };
  3382. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  3383. view.onmouseleave = function () {
  3384. view.onmousemove = null;
  3385. view.onmouseup = null;
  3386. };
  3387. // 鼠标弹起后停止移动
  3388. view.onmouseup=function() {
  3389. view.onmousemove = null;
  3390. view.onmouseup = null;
  3391. };
  3392. };
  3393. const removeImageItem = function () {
  3394. $(this).parent().remove();
  3395. };
  3396. // 加载草图组成
  3397. const loadImageItem = function () {
  3398. self.updateImageData = null;
  3399. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3400. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3401. const html = [];
  3402. for (const item of items) {
  3403. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3404. html.push('<div class="img-item" style="' + itemStyle + '">');
  3405. html.push('<div class="img-bar">');
  3406. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3407. html.push('</div>');
  3408. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3409. html.push('</div>');
  3410. }
  3411. $('.img-view').html(html.join(''));
  3412. $('.img-bar').click(removeImageItem);
  3413. setdraggrable();
  3414. };
  3415. // 上传图片
  3416. $('#upload-img').click(function () {
  3417. $('#upload-img-file').trigger('click');
  3418. });
  3419. // 拖拽上传
  3420. //拖拽上传文件
  3421. const dragbox = document.querySelector('#upload-img');
  3422. dragbox.addEventListener('dragover', function(e) {
  3423. e.preventDefault(); // 必须阻止默认事件
  3424. }, false);
  3425. dragbox.addEventListener('drop', function(e) {
  3426. e.preventDefault(); // 阻止默认事件
  3427. dragFile(e);
  3428. }, false);
  3429. //拖拽上传文件
  3430. const dragbox2 = document.querySelector('.img-view');
  3431. dragbox2.addEventListener('dragover', function(e) {
  3432. e.preventDefault(); // 必须阻止默认事件
  3433. }, false);
  3434. dragbox2.addEventListener('drop', function(e) {
  3435. e.preventDefault(); // 阻止默认事件
  3436. dragFile(e);
  3437. }, false);
  3438. // 粘贴上传
  3439. $(".img-view").on('paste', function(ev) {
  3440. let file = null;
  3441. const data = (event.clipboardData || window.clipboardData).items;
  3442. for (let i = 0; i < data.length; i += 1) {
  3443. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3444. file = data[i].getAsFile(); //读取图片文件
  3445. break;
  3446. }
  3447. }
  3448. if (file) {
  3449. const formData = new FormData();
  3450. formData.append('file', file); //上传单个文件的添加方式
  3451. upload(formData); //异步上传文件
  3452. }
  3453. });
  3454. $('#upload-img-file').change(function () {
  3455. const file = this.files[0];
  3456. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  3457. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  3458. if (!imgStr.test(ext)) {
  3459. toastr.error('请上传正确的图片格式文件');
  3460. return
  3461. }
  3462. if ($(this).val()) {
  3463. const formData = new FormData();
  3464. formData.append('file', this.files[0]);
  3465. upload(formData);
  3466. }
  3467. });
  3468. // 保存草图修改结果
  3469. $('#edit-img-ok').click(function () {
  3470. // 记录上传的图片的信息
  3471. const items = $('.img-item');
  3472. const img_remark = $('#text-edit').val();
  3473. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3474. // 生成上传数据
  3475. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  3476. if (data.uuid) {
  3477. updateData.uuid = data.uuid;
  3478. } else {
  3479. updateData.code = data.code;
  3480. updateData.name = data.name;
  3481. updateData.unit = data.unit;
  3482. updateData.unit_price = data.unit_price;
  3483. updateData.pid = data.pid;
  3484. updateData.pos_name = data.pos_name;
  3485. updateData.im_type = data.im_type;
  3486. }
  3487. if (items.length > 0) {
  3488. const itemInfo = [];
  3489. for (const item of items) {
  3490. const itemData = {
  3491. src: $('img', item).attr('src'),
  3492. left: item.style.left,
  3493. top: item.style.top,
  3494. width: item.style.width,
  3495. height: item.style.height,
  3496. };
  3497. itemInfo.push(itemData);
  3498. }
  3499. // 获取合并好的图片数据
  3500. const canvas = document.createElement('canvas');
  3501. const view = $('.img-view')[0];
  3502. canvas.height = view.clientHeight;
  3503. canvas.width = view.clientWidth;
  3504. const ctx = canvas.getContext('2d');
  3505. ctx.fillStyle = '#ffffff';
  3506. ctx.fillRect(0, 0, canvas.width, canvas.height);
  3507. for (const b of $('.img-item')) {
  3508. const pos = $(b).position();
  3509. const img = $('img', b)[0];
  3510. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  3511. }
  3512. updateData.img = canvas.toDataURL('image/png');
  3513. updateData.imgInfo = itemInfo;
  3514. self.updateImageData = updateData;
  3515. $('#calc-img').attr('src', updateData.img);
  3516. $('#calc-remark').html(img_remark);
  3517. $('#view-calc-img').attr('src', updateData.img);
  3518. $('#show-calc-img').attr('src', updateData.img);
  3519. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  3520. $('#view-calc-remark').text(img_remark);
  3521. $('#edit-img').modal('hide');
  3522. // });
  3523. } else if (data.calc_img) {
  3524. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  3525. $('#show-calc-img').attr('src', '');
  3526. $('#show-calc-remark').html('');
  3527. $('#calc-img').attr('src', '');
  3528. $('#calc-remark').html(img_remark);
  3529. $('#view-calc-img').attr('src', '');
  3530. $('#view-calc-remark').val(img_remark);
  3531. $('#text-edit').val(img_remark);
  3532. $('#edit-img').modal('hide');
  3533. } else {
  3534. self.updateImageData = updateData;
  3535. $('#show-calc-img').attr('src', '');
  3536. $('#show-calc-remark').html('');
  3537. $('#calc-img').attr('src', '');
  3538. $('#calc-remark').html(img_remark);
  3539. $('#view-calc-img').attr('src', '');
  3540. $('#view-calc-remark').val(img_remark);
  3541. $('#text-edit').val(img_remark);
  3542. $('#edit-img').modal('hide');
  3543. }
  3544. });
  3545. }
  3546. reBuildImData() {
  3547. const imData = stageIm.buildImData();
  3548. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3549. this.reLoadDetailData();
  3550. this.loadLocateInfo();
  3551. }
  3552. loadStageLedgerUpdateData(data, nodes) {
  3553. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  3554. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3555. this.reLoadDetailData();
  3556. }
  3557. loadStagePosUpdateData(data, nodes) {
  3558. const imData = stageIm.loadUpdatePosData(data, nodes);
  3559. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3560. this.reLoadDetailData();
  3561. }
  3562. loadStageChangeUpdateData(data, nodes) {
  3563. const imData = stageIm.loadUpdateChangeData(data, nodes);
  3564. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3565. this.reLoadDetailData();
  3566. }
  3567. loadLocateInfo() {
  3568. const select = SpreadJsObj.getSelectObject(this.sheet);
  3569. if (select && select.source.length > 1) {
  3570. $('#im-locate2bills').next().show();
  3571. } else {
  3572. $('#im-locate2bills').next().hide();
  3573. }
  3574. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  3575. }
  3576. reLoadDetailData() {
  3577. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  3578. $('#reset-detail').hide();
  3579. if (data) {
  3580. for (const f of data.custom_define) {
  3581. if (stageIm.resetFields.indexOf(f) >= 0) {
  3582. $('#reset-detail').show();
  3583. break;
  3584. }
  3585. }
  3586. $('#edit-detail').show();
  3587. $('#modify-img').show();
  3588. } else {
  3589. $('#edit-detail').hide();
  3590. $('#modify-img').hide();
  3591. }
  3592. $('#save-detail').hide();
  3593. $('#cancel-detail').hide();
  3594. $('#detail-show').show();
  3595. $('#detail-edit').hide();
  3596. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  3597. $('#show-contract-jl').text(contractJl);
  3598. $('#contract-jl').val(contractJl);
  3599. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  3600. $('#show-qc-jl').text(qcJl);
  3601. $('#qc-jl').val(qcJl);
  3602. const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
  3603. $('#show-qc-minus-jl').text(qcMinusJl);
  3604. $('#qc-minus-jl').val(qcMinusJl);
  3605. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  3606. $('#show-bgl-code').text(bglCode);
  3607. $('#bgl-code').val(bglCode);
  3608. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  3609. $('#show-bgl-drawing-code').text(bglDrawingCode);
  3610. $('#bgl-drawing-code').val(bglDrawingCode);
  3611. const bwName = data && data.bw ? data.bw : '';
  3612. $('#show-bw-name').text(bwName);
  3613. $('#bw-name').val(bwName);
  3614. const position = data && data.position ? data.position : '';
  3615. $('#show-position').text(position);
  3616. $('#position').val(position);
  3617. const peg = data && data.peg ? data.peg : '';
  3618. $('#show-peg').text(peg);
  3619. $('#peg').val(peg);
  3620. const xmName = data && data.xm ? data.xm: '';
  3621. $('#show-xm-name').text(xmName);
  3622. $('#xm-name').val(xmName);
  3623. const jldy = data && data.jldy ? data.jldy: '';
  3624. $('#show-jldy').text(jldy);
  3625. $('#jldy').val(jldy);
  3626. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  3627. $('#show-drawing-code').text(drawingCode);
  3628. $('#drawing-code').val(drawingCode);
  3629. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  3630. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  3631. $('#calc-memo').val(calcMemo);
  3632. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3633. $('#show-calc-img').attr('src', calcImgSrc);
  3634. $('#calc-img').attr('src', calcImgSrc);
  3635. $('#view-calc-img').attr('src', calcImgSrc);
  3636. const calcImgRemark = data && data.calc_img_remark || '';
  3637. $('#view-calc-remark').val(calcImgRemark);
  3638. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  3639. $('#calc-remark').html(calcImgRemark);
  3640. $("#view-calc-remark").attr('readonly', true);
  3641. // 处理 编辑 -> 添加草图中textarea多余的空格
  3642. $('#text-edit').val(calcImgRemark)
  3643. }
  3644. }
  3645. class CheckedChange {
  3646. constructor (setting) {
  3647. const self = this;
  3648. this.changeSpreadSetting = {
  3649. cols: [
  3650. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: function (x) { return x.t_name ? `所属标段:${x.t_name}` : ''; }},
  3651. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  3652. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3653. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  3654. ],
  3655. emptyRows: 0,
  3656. headRows: 1,
  3657. headRowHeight: [32],
  3658. headColWidth: [30],
  3659. defaultRowHeight: 21,
  3660. headerFont: '12px 微软雅黑',
  3661. font: '12px 微软雅黑',
  3662. readOnly: true,
  3663. getColor: function (sheet, data, row, col, defaultColor) {
  3664. if (data && data.is_import) {
  3665. return '#eee';
  3666. } else {
  3667. return defaultColor;
  3668. }
  3669. }
  3670. };
  3671. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  3672. this.changeSheet = this.changeSpread.getActiveSheet();
  3673. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  3674. const getTipText = function (data) {
  3675. if (!data) return '';
  3676. const tips = [];
  3677. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  3678. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  3679. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  3680. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  3681. return tips.join('-');
  3682. };
  3683. this.changeBillsSpreadSetting = {
  3684. cols: [
  3685. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  3686. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, cellType: 'delayTip', getTip: getTipText},
  3687. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3688. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  3689. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  3690. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  3691. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  3692. ],
  3693. emptyRows: 0,
  3694. headRows: 1,
  3695. headRowHeight: [32],
  3696. defaultRowHeight: 21,
  3697. headerFont: '12px 微软雅黑',
  3698. font: '12px 微软雅黑',
  3699. readOnly: true
  3700. };
  3701. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  3702. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  3703. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  3704. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  3705. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3706. self.refreshChangeDetailData(change);
  3707. });
  3708. this.changes = null;
  3709. this.reloadChangeData();
  3710. setting.reloadObj.click(function() {
  3711. self.reloadChangeData();
  3712. });
  3713. $.contextMenu({
  3714. selector: '#' + setting.changeBillsObj.attr('id'),
  3715. build: function ($trigger, e) {
  3716. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  3717. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3718. },
  3719. items: {
  3720. 'locateZjjl': {
  3721. name: '定位至台账',
  3722. icon: 'fa-sign-in',
  3723. callback: function (key, opt) {
  3724. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3725. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3726. if (change.is_import) {
  3727. if (changeBills.pos && changeBills.pos.length > 0) {
  3728. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), changeBills.pos[0].ledger_id, true);
  3729. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  3730. stagePosSpreadObj.loadCurPosData();
  3731. }
  3732. } else if (changeBills.gcl_id) {
  3733. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  3734. if (!node) return;
  3735. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id, true);
  3736. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  3737. stagePosSpreadObj.loadCurPosData();
  3738. const posData = spSpread.getActiveSheet().zh_data;
  3739. if (!posData || posData.length === 0) return;
  3740. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  3741. if (changePos) SpreadJsObj.locateData(spSpread.getActiveSheet(), changePos);
  3742. } else {
  3743. const cb = {
  3744. b_code: changeBills.code || '',
  3745. name: changeBills.name || '',
  3746. unit: changeBills.unit || '',
  3747. unit_price: changeBills.unit_price || 0,
  3748. };
  3749. for (const node of stageTree.nodes) {
  3750. if (node.children && node.children.length > 0) continue;
  3751. const b = {
  3752. b_code: node.b_code || '',
  3753. name: node.name || '',
  3754. unit: node.unit || '',
  3755. unit_price: node.unit_price || 0,
  3756. };
  3757. if (_.isMatch(cb, b)) {
  3758. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3759. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  3760. stagePosSpreadObj.loadCurPosData();
  3761. return;
  3762. }
  3763. }
  3764. }
  3765. },
  3766. disabled: function (key, opt) {
  3767. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3768. return !changeBills;
  3769. }
  3770. },
  3771. 'autoUse': {
  3772. name: '调用',
  3773. icon: 'fa-play',
  3774. callback: function (key, opt) {
  3775. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3776. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3777. const billsPos = self.findBillsPos(curChange, changeBills);
  3778. if (!billsPos) {
  3779. toastr.warning('无可调用的清单或计量单元');
  3780. return;
  3781. }
  3782. const data = { autoType: 'bills', bills: [{ ...billsPos, cid: changeBills.cid, cbid: changeBills.id }] };
  3783. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  3784. if (result.pos) {
  3785. stagePos.loadCurStageData(result.pos.curStageData);
  3786. }
  3787. const nodes = stageTree.loadPostStageData(result.bills);
  3788. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  3789. stagePosSpreadObj.loadCurPosData();
  3790. if (detail) {
  3791. detail.loadStageChangeUpdateData(result, nodes);
  3792. } else {
  3793. stageIm.loadUpdateChangeData(result, nodes)
  3794. }
  3795. });
  3796. },
  3797. disable: function (key, opt) {
  3798. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3799. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3800. return !changeBills || curChange.is_import;
  3801. },
  3802. visible: function (key, opt) {
  3803. return is_debug && stage.status === 1;
  3804. }
  3805. },
  3806. }
  3807. });
  3808. $.contextMenu({
  3809. selector: '#' + setting.changeObj.attr('id'),
  3810. build: function ($trigger, e) {
  3811. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeSpread);
  3812. const change = self.changes[target.cellTypeHitInfo.row];
  3813. self.refreshChangeDetailData(change);
  3814. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3815. },
  3816. items: {
  3817. 'autoUseCur': {
  3818. name: '自动调用',
  3819. icon: 'fa-play',
  3820. callback: function (key, opt) {
  3821. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3822. const changeBills = self.changeBillsSheet.zh_data;
  3823. const data = { bills: [], autoType: 'bills' };
  3824. for (const cb of changeBills) {
  3825. const billsPos = self.findBillsPos(curChange, cb);
  3826. if (billsPos) data.bills.push({ ...billsPos, cid: cb.cid, cbid: cb.id })
  3827. }
  3828. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  3829. if (result.pos) {
  3830. stagePos.loadCurStageData(result.pos.curStageData);
  3831. }
  3832. const nodes = stageTree.loadPostStageData(result.bills);
  3833. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  3834. stagePosSpreadObj.loadCurPosData();
  3835. if (detail) {
  3836. detail.loadStageChangeUpdateData(result, nodes);
  3837. } else {
  3838. stageIm.loadUpdateChangeData(result, nodes)
  3839. }
  3840. });
  3841. },
  3842. disable: function (key, opt) {
  3843. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3844. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3845. return !changeBills || curChange.is_import;
  3846. },
  3847. visible: function (key, opt) {
  3848. return is_debug && stage.status === 1;
  3849. }
  3850. },
  3851. 'autoUseAll': {
  3852. name: '自动调用(全部变更令)',
  3853. icon: 'fa-play',
  3854. callback: function (key, opt) {
  3855. postData(window.location.pathname + '/auto-use-change', { autoType: 'all' }, function(result) {
  3856. window.location.reload();
  3857. });
  3858. },
  3859. disable: function (key, opt) {
  3860. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3861. return !curChange || curChange.is_import;
  3862. },
  3863. visible: function (key, opt) {
  3864. return is_debug && stage.status === 1;
  3865. }
  3866. }
  3867. }
  3868. });
  3869. }
  3870. refreshChangeDetailData(data) {
  3871. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  3872. if (change.cid === this.curChangeId) return;
  3873. this.curChangeId = change.cid;
  3874. const self = this;
  3875. if (change.detail) {
  3876. self.loadChangeDetailData();
  3877. } else {
  3878. postData(window.location.pathname + '/change/detail', {cid: change.cid, is_import: change.is_import}, function (result) {
  3879. change.detail = result;
  3880. self.analyzeChange(change);
  3881. self.loadChangeDetailData();
  3882. });
  3883. }
  3884. }
  3885. loadChangeDetailData(data) {
  3886. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  3887. if (change) {
  3888. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  3889. } else {
  3890. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  3891. }
  3892. }
  3893. refresh() {
  3894. this.changeSpread.refresh();
  3895. this.changeBillsSpread.refresh();
  3896. }
  3897. reloadChangeData() {
  3898. const self = this;
  3899. postData(window.location.pathname + '/change/data', null, function (result) {
  3900. self.changes = [];
  3901. result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
  3902. result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; self.changes.push(x); });
  3903. if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
  3904. if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
  3905. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  3906. self.changeSheet.setSelection(0, 0, 1, 1);
  3907. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  3908. self.loadChangeDetailData();
  3909. });
  3910. }
  3911. _analyzeCommon(change) {
  3912. for (const b of change.bills) {
  3913. const eub = change.detail.endUsedBills.find(function (x) {
  3914. return x.cbid === b.id;
  3915. });
  3916. if (eub) b.used_qty = eub.qty;
  3917. b.qty = _.toNumber(b.samount);
  3918. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  3919. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3920. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  3921. b.cur_qty = 0;
  3922. for (const p of b.pos) {
  3923. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  3924. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  3925. }
  3926. }
  3927. }
  3928. _analyzeImport(change) {
  3929. for (const b of change.bills) {
  3930. const eub = change.detail.endUsedBills.find(function (x) {
  3931. return x.rela_cbid === b.id;
  3932. });
  3933. if (eub) b.used_qty = eub.rela_qty;
  3934. b.qty = _.toNumber(b.samount);
  3935. delete b.unit_price;
  3936. // b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3937. b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
  3938. b.cur_qty = 0;
  3939. for (const p of b.pos) {
  3940. p.qty = p.rela_qty;
  3941. const node = stageTree.datas.find(x => { return x.id === p.lid; });
  3942. p.ledger_id = node.ledger_id;
  3943. p.f_qty = node.quantity;
  3944. b.cur_qty = ZhCalc.add(b.cur_qty, p.rela_qty);
  3945. }
  3946. }
  3947. }
  3948. analyzeChange(change) {
  3949. change.bills = change.detail.bills;
  3950. if (change.is_import) {
  3951. this._analyzeImport(change);
  3952. } else {
  3953. this._analyzeCommon(change);
  3954. }
  3955. }
  3956. findBillsPos(change, changeBills) {
  3957. if (change.is_import) {
  3958. return null;
  3959. } else if (changeBills.gcl_id) {
  3960. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  3961. posData = stagePos.getLedgerPos(node.id) || [];
  3962. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  3963. return { lid: node.id, pid: changePos ? changePos.id : (posData.length > 0 ? posData[0].id : '-1') };
  3964. } else {
  3965. const cb = {
  3966. b_code: changeBills.code || '',
  3967. name: changeBills.name || '',
  3968. unit: changeBills.unit || '',
  3969. unit_price: changeBills.unit_price || 0,
  3970. };
  3971. for (const node of stageTree.nodes) {
  3972. if (node.children && node.children.length > 0) continue;
  3973. const b = {
  3974. b_code: node.b_code || '',
  3975. name: node.name || '',
  3976. unit: node.unit || '',
  3977. unit_price: node.unit_price || 0,
  3978. };
  3979. if (_.isMatch(cb, b)) {
  3980. posData = stagePos.getLedgerPos(node.id) || [];
  3981. return { lid: node.id, pid: posData.length > 0 ? posData[0].id : '-1' };
  3982. }
  3983. }
  3984. return null;
  3985. }
  3986. }
  3987. }
  3988. // 展开收起附件
  3989. $('a', '.right-nav').bind('click', function () {
  3990. //const main = $('#main-view'), tool = $('#tools-view');
  3991. const tab = $(this), tabPanel = $(tab.attr('content'));
  3992. if (!tab.hasClass('active')) {
  3993. $('a', '.side-menu').removeClass('active');
  3994. $('.tab-content .tab-select-show').removeClass('active');
  3995. tab.addClass('active');
  3996. tabPanel.addClass('active');
  3997. showSideTools(tab.hasClass('active'));
  3998. if (tab.attr('content') === '#search' && !searchLedger) {
  3999. searchLedger = $.billsSearch({
  4000. selector: '#search',
  4001. searchSpread: slSpread,
  4002. searchOver: true,
  4003. searchEmpty: true,
  4004. resultSpreadSetting: {
  4005. cols: [
  4006. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4007. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4008. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4009. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4010. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4011. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4012. {title: '完成率(%)', field: 'end_gather_percent', hAlign: 2, width: 70},
  4013. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4014. ],
  4015. emptyRows: 0,
  4016. headRows: 1,
  4017. headRowHeight: [32],
  4018. headColWidth: [30],
  4019. defaultRowHeight: 21,
  4020. headerFont: '12px 微软雅黑',
  4021. font: '12px 微软雅黑',
  4022. selectedBackColor: '#fffacd',
  4023. },
  4024. afterLocated: function () {
  4025. stagePosSpreadObj.loadCurPosData();
  4026. },
  4027. customSearch: [
  4028. {
  4029. key: 'less', title: '漏计', valid: true,
  4030. check: function (node) {
  4031. if (node.quantity) {
  4032. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  4033. } else if (node.total_price) {
  4034. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  4035. }
  4036. }
  4037. }, {
  4038. key: 'over', title: '超计', valid: true,
  4039. check: function (node) {
  4040. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  4041. }
  4042. }, {
  4043. key: 'empty', title: '漏计', valid: false,
  4044. check: function (node) {
  4045. if (node.quantity) {
  4046. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  4047. } else if (node.total_price) {
  4048. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  4049. }
  4050. }
  4051. }, {
  4052. key: 'estimate', title: '预计变更', valid: true,
  4053. check: function (node) {
  4054. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  4055. if (posRange.length > 0) {
  4056. for (const p of posRange) {
  4057. if (!checkZero(p.estimate_qty)) return true;
  4058. }
  4059. return false;
  4060. } else {
  4061. return false;
  4062. }
  4063. }
  4064. }
  4065. ],
  4066. });
  4067. searchLedger.spread.refresh();
  4068. }
  4069. if (tab.attr('content') === '#fujian') {
  4070. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4071. node && getNodeList(node.id);
  4072. }
  4073. if (tab.attr('content') === '#zhongjian') {
  4074. if (!detail) {
  4075. detail = new Detail($('#detail-spread'));
  4076. detail.spread.refresh();
  4077. $('#zhongjian .sjs-bottom').height('400px');
  4078. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  4079. } else {
  4080. detail.spread.refresh();
  4081. }
  4082. }
  4083. if (tab.attr('content') === '#checked-change') {
  4084. if (!checkedChanges) {
  4085. checkedChanges = new CheckedChange({
  4086. changeObj: $('#cc-spread'),
  4087. changeBillsObj: $('#ccb-spread'),
  4088. reloadObj: $('#refresh-cc'),
  4089. });
  4090. checkedChanges.refresh();
  4091. } else {
  4092. $('#ccb-spread').height('400px');
  4093. checkedChanges.refresh();
  4094. }
  4095. }
  4096. if (tab.attr('content') === '#error-list') {
  4097. errorList.spread.refresh();
  4098. }
  4099. if (tab.attr('content') === '#check-list') {
  4100. checkList.spread.refresh();
  4101. }
  4102. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  4103. } else {
  4104. tab.removeClass('active');
  4105. tabPanel.removeClass('active');
  4106. showSideTools(tab.hasClass('active'));
  4107. }
  4108. slSpread.refresh();
  4109. spSpread.refresh();
  4110. });
  4111. // 切换附件里节点和所有附件
  4112. $('#fujian .nav-link').on('click', function () {
  4113. const tabPanel = $(this).attr('fujian-content');
  4114. if (tabPanel !== 'syfujian') {
  4115. $('#showPage').hide();
  4116. $('#bach-download').prop('type', 'curr');
  4117. } else {
  4118. $('#showPage').show();
  4119. $('#bach-download').prop('type', 'all')
  4120. }
  4121. $('#showAttachment').hide();
  4122. });
  4123. // 上传附件
  4124. $('#upload-file-btn').click(function () {
  4125. // if (curAuditor && curAuditor.aid !== cur_uid) {
  4126. // return toastr.error('当前操作没有权限!');
  4127. // }
  4128. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4129. if (!node) return
  4130. const files = $('#upload-file')[0].files;
  4131. const formData = new FormData();
  4132. formData.append('lid', node.id);
  4133. for (const file of files) {
  4134. if (file === undefined) {
  4135. toastr.error('未选择上传文件!');
  4136. return false;
  4137. }
  4138. const filesize = file.size;
  4139. if (filesize > 30 * 1024 * 1024) {
  4140. toastr.error('存在上传文件大小过大!');
  4141. return false;
  4142. }
  4143. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  4144. if (whiteList.indexOf(fileext) === -1) {
  4145. toastr.error('只能上传指定格式的附件!');
  4146. return false;
  4147. }
  4148. formData.append('size', filesize);
  4149. formData.append('file[]', file);
  4150. }
  4151. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  4152. $('#upload').modal('hide');
  4153. // 插入到attData中
  4154. attData = data.concat(attData);
  4155. // 重新生成List
  4156. getAllList();
  4157. getNodeList(node.id);
  4158. }, function () {
  4159. toastr.error('附件上传失败');
  4160. });
  4161. $('#upload-file').val('');
  4162. });
  4163. // 获取附件信息
  4164. $('.list-table').on('click', '.att-file-name', function () {
  4165. const fid = $(this).attr('file-id');
  4166. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  4167. return;
  4168. }
  4169. const att = attData.find(function (item) {
  4170. return item.id === parseInt(fid);
  4171. });
  4172. $('#edit-att').hide();
  4173. $('#show-att').show();
  4174. if (att !== undefined) {
  4175. // 进来先把编辑功能隐藏
  4176. $('#btn-att a').eq(3).hide()
  4177. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  4178. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4179. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  4180. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  4181. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  4182. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  4183. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  4184. $('#show-att tr').eq(3).children('td').text(att.remark);
  4185. // 附件uid等于当前用户id, 附件上传本人
  4186. if (parseInt(cur_uid) === att.uid) {
  4187. $('#btn-att').show();
  4188. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  4189. // if (!curAuditor) {
  4190. // stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  4191. // stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  4192. // stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  4193. // } else {
  4194. // curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  4195. // }
  4196. if (showDel) $('#btn-att a').eq(3).show();
  4197. // $('#btn-att a').eq(3).show();
  4198. $('#btn-att a').eq(2).hide();
  4199. $('#btn-att a').eq(4).hide();
  4200. $('#btn-att a').eq(5).hide();
  4201. } else {
  4202. $('#btn-att').hide();
  4203. $('#btn-att a').eq(3).hide();
  4204. $('#btn-att a').eq(2).hide();
  4205. $('#btn-att a').eq(4).hide();
  4206. $('#btn-att a').eq(5).hide();
  4207. }
  4208. $('#showAttachment').attr('file-id', fid);
  4209. $('#showAttachment').show();
  4210. } else {
  4211. $('#showAttachment').hide();
  4212. $('#showAttachment').attr('file-id', '');
  4213. toastr.error('附件信息获取失败');
  4214. }
  4215. });
  4216. // $('body').on('click', '.alllist-table a', handleFileList);
  4217. $('body').on('click', '#btn-att a', function () {
  4218. const content = $(this).attr('content');
  4219. const fid = $('#showAttachment').attr('file-id');
  4220. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4221. if (content === 'edit') {
  4222. $('#btn-att a').eq(3).hide();
  4223. $('#btn-att a').eq(2).show();
  4224. $('#btn-att a').eq(4).show();
  4225. $('#btn-att a').eq(5).show();
  4226. $('#show-att').hide();
  4227. $('#edit-att').show();
  4228. const att = attData.find(function (item) {
  4229. return item.id === parseInt(fid);
  4230. });
  4231. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  4232. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  4233. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4234. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  4235. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  4236. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  4237. } else if (content === 'cancel') {
  4238. $('#show-att').show();
  4239. $('#edit-att').hide();
  4240. $('#btn-att a').eq(3).show();
  4241. $('#btn-att a').eq(2).hide();
  4242. $('#btn-att a').eq(4).hide();
  4243. $('#btn-att a').eq(5).hide();
  4244. } else if (content === 'save') {
  4245. const formData = new FormData();
  4246. formData.append('id', fid);
  4247. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  4248. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  4249. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  4250. const file = $('#change-att-btn')[0];
  4251. if (file.files[0] !== undefined) {
  4252. const filesize = file.files[0].size;
  4253. formData.append('size', filesize);
  4254. formData.append('file', file.files[0]);
  4255. }
  4256. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  4257. // 替换到attData中
  4258. const att_index = attData.findIndex(function (item) {
  4259. return item.id === parseInt(fid);
  4260. });
  4261. attData.splice(att_index, 1, data);
  4262. // 重新生成List
  4263. getAllList(parseInt($('#currentPage').text()));
  4264. getNodeList(node.id);
  4265. $('#show-att').show();
  4266. $('#edit-att').hide();
  4267. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4268. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4269. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4270. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  4271. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  4272. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  4273. $('#show-att tr').eq(4).children('td').text(data.remark);
  4274. $('#btn-att a').eq(3).show();
  4275. $('#btn-att a').eq(2).hide();
  4276. $('#btn-att a').eq(4).hide();
  4277. $('#btn-att a').eq(5).hide();
  4278. }, function () {
  4279. toastr.error('附件上传失败');
  4280. });
  4281. $('#change-att-btn').val('');
  4282. } else if (content === 'del') {
  4283. const data = {id: fid};
  4284. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  4285. // 删除到attData中
  4286. const att_index = attData.findIndex(function (item) {
  4287. return item.id === parseInt(fid);
  4288. });
  4289. attData.splice(att_index, 1);
  4290. // 重新生成List
  4291. if ($('#alllist-table tr').length === 1) {
  4292. getAllList(parseInt($('#currentPage').text()) - 1);
  4293. } else {
  4294. getAllList(parseInt($('#currentPage').text()));
  4295. }
  4296. getNodeList(node.id);
  4297. $('#showAttachment').hide();
  4298. $('#showAttachment').attr('file-id', '');
  4299. });
  4300. } else if (content === 'view') {
  4301. const data = {id: fid};
  4302. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  4303. const { filepath } = result
  4304. $('#load-file').attr('href', filepath);
  4305. $('#load-file')[0].click();
  4306. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  4307. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  4308. });
  4309. } else if (content === 'location') {
  4310. const att = attData.find(item => item.id === parseInt(fid));
  4311. if (Object.keys(att).length) {
  4312. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  4313. stagePosSpreadObj.loadCurPosData();
  4314. }
  4315. }
  4316. });
  4317. // 替换附件
  4318. $('#change-att-btn').on('change', function () {
  4319. const file = $('#change-att-btn')[0].files[0];
  4320. const name = file.name;
  4321. const filename = name.substring(0, name.lastIndexOf("."));
  4322. const fileext = name.substr(name.indexOf("."));
  4323. const filesize = file.size;
  4324. if (filesize > 30 * 1024 * 1024) {
  4325. toastr.error('文件大小过大!');
  4326. $('#change-att-btn').val('');
  4327. return false;
  4328. }
  4329. if (whiteList.indexOf(fileext) === -1) {
  4330. toastr.error('只能上传指定格式的附件!');
  4331. $('#change-att-btn').val('');
  4332. return false;
  4333. }
  4334. $('#edit-att .form-group').eq(0).find('input').val(filename);
  4335. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  4336. });
  4337. // 切换页数
  4338. $('.page-select').on('click', function () {
  4339. const totalPageNum = parseInt($('#totalPage').text());
  4340. const lastPageNum = parseInt($('#currentPage').text());
  4341. const status = $(this).attr('content');
  4342. if (status === 'pre' && lastPageNum > 1) {
  4343. getAllList(lastPageNum-1);
  4344. $('#showAttachment').hide();
  4345. $('#syfujian .check-all-file').prop('checked', false)
  4346. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4347. getAllList(lastPageNum+1);
  4348. $('#showAttachment').hide();
  4349. $('#syfujian .check-all-file').prop('checked', false)
  4350. }
  4351. });
  4352. // 批量下载
  4353. $('#bach-download').click(function() {
  4354. const fileIds = [];
  4355. const type = $(this).attr('type');
  4356. let node = ''
  4357. if (type === 'curr') {
  4358. node = '#nodelist-table .check-file:checked'
  4359. } else {
  4360. node = '#alllist-table .check-file:checked'
  4361. }
  4362. $(node).each(function() {
  4363. const fileId = $(this).attr('file-id');
  4364. fileId && fileIds.push(fileId);
  4365. });
  4366. if (fileIds.length) {
  4367. if (fileIds.length > 20) {
  4368. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  4369. }
  4370. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  4371. $(this).attr('disabled', "true")
  4372. const btn = $(this);
  4373. const fileArr = [];
  4374. for (const id of fileIds) {
  4375. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  4376. fileArr.push({
  4377. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  4378. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  4379. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  4380. });
  4381. }
  4382. const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
  4383. try {
  4384. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  4385. } catch (e) {
  4386. btn.removeAttr('disabled');
  4387. toastr.clear();
  4388. toastr.error('批量下载失败');
  4389. }
  4390. // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  4391. // toastr.clear()
  4392. // toastr.success('压缩文件成功')
  4393. // btn.removeAttr('disabled')
  4394. // const href = window.URL.createObjectURL(result)
  4395. // $('#zipDown').attr('href', href);
  4396. // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  4397. // $("#zipDown")[0].click();
  4398. // }, () => {
  4399. // btn.removeAttr('disabled')
  4400. // toastr.clear()
  4401. // toastr.error('批量下载失败')
  4402. // });
  4403. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  4404. // $('#zipDown').attr('href', url);
  4405. // $("#zipDown")[0].click();
  4406. }
  4407. });
  4408. // 监听附件check是否选中
  4409. $('.list-table').on('click', '.check-file', function() {
  4410. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  4411. const childs = $(this).parents('.list-table').children().length;
  4412. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  4413. if (checkedList.length === childs) {
  4414. checkBox.prop("checked", true);
  4415. } else {
  4416. checkBox.prop("checked", false);
  4417. }
  4418. });
  4419. $('.check-all-file').click(function() {
  4420. const isCheck = $(this).is(':checked');
  4421. $(this).parents('table').find('.list-table').each(function() {
  4422. $(this).find('input:checkbox').prop("checked", isCheck);
  4423. })
  4424. });
  4425. // 显示层次
  4426. (function (select, sheet) {
  4427. $(select).click(function () {
  4428. if (!sheet.zh_tree) return;
  4429. const tag = $(this).attr('tag');
  4430. const tree = sheet.zh_tree;
  4431. setTimeout(() => {
  4432. showWaitingView();
  4433. switch (tag) {
  4434. case "1":
  4435. case "2":
  4436. case "3":
  4437. case "4":
  4438. case "5":
  4439. tree.expandByLevel(parseInt(tag));
  4440. SpreadJsObj.refreshTreeRowVisible(sheet);
  4441. break;
  4442. case "last":
  4443. tree.expandByCustom(() => { return true; });
  4444. SpreadJsObj.refreshTreeRowVisible(sheet);
  4445. break;
  4446. case "leafXmj":
  4447. tree.expandToLeafXmj();
  4448. SpreadJsObj.refreshTreeRowVisible(sheet);
  4449. break;
  4450. case "curMeasure":
  4451. tree.expandByCustom(function (node) {
  4452. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  4453. if (node[field]) {
  4454. return true;
  4455. }
  4456. }
  4457. return false;
  4458. });
  4459. SpreadJsObj.refreshTreeRowVisible(sheet);
  4460. break;
  4461. case "endMeasure":
  4462. tree.expandByCustom(function (node) {
  4463. for (const field of ['contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp']) {
  4464. if (node[field]) {
  4465. return true;
  4466. }
  4467. }
  4468. return false;
  4469. });
  4470. SpreadJsObj.refreshTreeRowVisible(sheet);
  4471. break;
  4472. }
  4473. closeWaitingView();
  4474. }, 100);
  4475. });
  4476. })('a[name=showLevel]', slSpread.getActiveSheet());
  4477. const stageCheckerSetting = {
  4478. ledgerTree: stageTree,
  4479. ledgerPos: stagePos,
  4480. checkList: checkList,
  4481. decimal: tenderInfo.decimal,
  4482. checkOption: checkOption,
  4483. };
  4484. if (!checkTzMeasureType()) {
  4485. stageCheckerSetting.checkOption.tp.fields.push(
  4486. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  4487. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  4488. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  4489. {qty: 'quantity', tp: 'total_price'},
  4490. );
  4491. }
  4492. $('#ledger-check2').click(() => {
  4493. ledgerCheck2(stageCheckerSetting).then(result => {
  4494. check2Viewing({
  4495. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  4496. randomWait: true,
  4497. prefix: 'check2-',
  4498. checks: result,
  4499. checkList: checkList,
  4500. });
  4501. });
  4502. });
  4503. const dataChecker = DataChecker({
  4504. checkUrl: window.location.pathname + '/check',
  4505. completeData: function (data) {
  4506. stagePos.updateDatas({pos: data.source.pos});
  4507. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  4508. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  4509. stagePosSpreadObj.loadCurPosData();
  4510. for (const e of data.error) {
  4511. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  4512. }
  4513. },
  4514. errorList: errorList,
  4515. });
  4516. $('[name=stage-start]').submit(function (e) {
  4517. if (checkAuditorFrom()) {
  4518. // 再检查多人协同确认情况
  4519. const list = stage.relaAssists.find(x => {return !x.confirm });
  4520. if(list) {
  4521. toastr.error('请检查多人协同确认情况再上报');
  4522. $('#hide-all').hide();
  4523. return false;
  4524. }
  4525. $(this).parent().parent().parent().modal('hide');
  4526. dataChecker.checkAndPost(this.action, {});
  4527. $('#hide-all').hide();
  4528. }
  4529. return false;
  4530. });
  4531. $('#audit-check0').submit(function (e) {
  4532. // 再检查多人协同确认情况
  4533. const list = stage.relaAssists.find(x => {return !x.confirm && stageAssistRela.checkAssistPartUsed(x) });
  4534. if(list) {
  4535. toastr.error('请检查多人协同确认情况再审批通过');
  4536. $('#hide-all').hide();
  4537. return false;
  4538. }
  4539. const checkType = parseInt($('[name=checkType]').val());
  4540. const noUsed = stage.relaAssists.filter(x => {return !stageAssistRela.checkAssistPartUsed(x) });
  4541. const data = {
  4542. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4543. coop_noUsed: noUsed && noUsed.length > 0 ? noUsed.map(x => { return x.ass_ledger_id; }) : [],
  4544. checkType,
  4545. };
  4546. $('#sp-done').modal('hide');
  4547. checkType && dataChecker.checkAndPost(this.action, data);
  4548. $('#hide-all').hide();
  4549. return false;
  4550. });
  4551. $('#audit-check1').submit(function (e) {
  4552. const checkType = parseInt($('[name=checkType]:checked').val());
  4553. const confirm = stage.relaAssists.filter(x => { return x.confirm });
  4554. const data = {
  4555. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4556. coop_checked: confirm && confirm.length > 0 ? confirm.map(x => { return x.id; }) : [],
  4557. checkType,
  4558. };
  4559. if ($('#warning-text').length) $('#warning-text').remove();
  4560. if (!checkType && !$('#warning-text').length) {
  4561. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  4562. return false
  4563. }
  4564. $('#sp-back').modal('hide');
  4565. checkType && dataChecker.checkAndPost(this.action, data);
  4566. $('#hide-all').hide();
  4567. return false;
  4568. });
  4569. $('#exportExcel').click(function () {
  4570. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  4571. });
  4572. $('#cbr-check-all').click(function () {
  4573. if (this.checked) {
  4574. $('input', '#cbr-pos-list').attr('checked', 'checked');
  4575. } else {
  4576. $('input', '#cbr-pos-list').removeAttr('checked');
  4577. }
  4578. });
  4579. $('#cbr-ok').click(() => {
  4580. const ratio = parseInt($('#cbr-ratio').val());
  4581. if (!ratio) {
  4582. toastr.warning('请输入计量比例');
  4583. return;
  4584. } else if (ratio < 1) {
  4585. toastr.warning('计量比例不可小于1');
  4586. return;
  4587. } else if (ratio > 100) {
  4588. toastr.warning('计量比例不可大于100');
  4589. return;
  4590. }
  4591. const apply2sibling = $('#apply2sibling')[0].checked;
  4592. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  4593. if (posName.length === 0) {
  4594. toastr.warning('请勾选需要按计量比例的计量单元');
  4595. return;
  4596. }
  4597. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  4598. });
  4599. // 收方单生成
  4600. $('#setshoufang').click(function () {
  4601. const lid = $('#shoufang-lid').val();
  4602. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  4603. // 修改线上
  4604. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  4605. // 收方单tab打开并显示在最新
  4606. if (!$('#shoufang-tab').hasClass('active')) {
  4607. $('#shoufang-tab').click();
  4608. }
  4609. const data = makeOneShouFang(result);
  4610. data.filenum = 0;
  4611. sfData = _.concat(data, sfData);
  4612. getShouFangList();
  4613. });
  4614. });
  4615. $('body').on('click', '.del-shoufang', function () {
  4616. const id = $(this).attr('data-id');
  4617. $('#del-shoufang-id').val(id);
  4618. const name = $(this).parents('tr').children('td').eq(0).text();
  4619. const ledger_code = name.split(' / ')[0];
  4620. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  4621. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  4622. if (pos_name) {
  4623. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  4624. } else {
  4625. $('#del-shoufang-pos').text('').hide();
  4626. }
  4627. });
  4628. // 收方单删除
  4629. $('#delshoufang').click(function () {
  4630. const sfid = $('#del-shoufang-id').val();
  4631. // 修改线上
  4632. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  4633. // 删除到sfData中
  4634. const att_index = sfData.findIndex(function (item) {
  4635. return item.id === parseInt(sfid);
  4636. });
  4637. sfData.splice(att_index, 1);
  4638. // 重新生成List
  4639. if ($('#shoufang-table tr').length === 1) {
  4640. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  4641. } else {
  4642. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  4643. }
  4644. $('#shoufangdelete').modal('hide');
  4645. });
  4646. });
  4647. // 切换页数
  4648. $('.shoufang-page-select').on('click', function () {
  4649. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  4650. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  4651. const status = $(this).attr('content');
  4652. if (status === 'pre' && lastPageNum > 1) {
  4653. getShouFangList(lastPageNum-1);
  4654. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4655. getShouFangList(lastPageNum+1);
  4656. }
  4657. });
  4658. // 获取单个收方单附件列表
  4659. $('body').on('click', '.show-shoufang-att', function () {
  4660. const id = parseInt($(this).attr('data-id'));
  4661. let html = '';
  4662. $('#shoufang-flie-list').html(html);
  4663. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  4664. for (const att of result) {
  4665. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  4666. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  4667. `<a href="${att.filepath}" target="_blank"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a>` + makeViewHtml(att.viewpath) + makeDelHtml(att.id, att.extra_upload) +`</td></tr>`;
  4668. }
  4669. $('#shoufang-flie-list').html(html);
  4670. $('[data-toggle="tooltip"]').tooltip()
  4671. });
  4672. function makeViewHtml(viewpath) {
  4673. return viewpath ? `<a href="${viewpath}" target="_blank" class="ml-1"><i data-toggle="tooltip" data-placement="left" data-original-title="预览" class="fa fa-eye"></i></a>` : '';
  4674. }
  4675. function makeDelHtml(fid, extra_upload) {
  4676. return sfAttDelPower &&
  4677. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4678. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
  4679. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4680. }
  4681. });
  4682. function makeEditHtml(fid, filename, fileext, extra_upload) {
  4683. return sfAttDelPower &&
  4684. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4685. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  4686. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  4687. }
  4688. // 修改收方单附件文件名
  4689. $('body').on('click', '.edit-shoufang-att', function () {
  4690. $(this).children('i').tooltip('hide');
  4691. const fid = $(this).data('id');
  4692. const filename = $(this).data('filename');
  4693. const fileext = $(this).data('fileext');
  4694. const html = `<div class="input-group input-group-sm">
  4695. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  4696. <div class="input-group-append" id="button-${fid}">
  4697. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  4698. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  4699. </div>
  4700. </div>`;
  4701. $(this).parents('td').html(html);
  4702. });
  4703. // 确认修改文件名
  4704. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  4705. const validText = $.trim($(this).parents('td').find('input').val());
  4706. const orgValue = $.trim($(this).data('filename'));
  4707. const fileext = $(this).data('fileext');
  4708. const fid = $(this).data('fid');
  4709. if (!validText) {
  4710. toastr.error('文件名不能为空');
  4711. return;
  4712. }
  4713. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  4714. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  4715. toastr.error('文件名中不能包含.字符和空格');
  4716. return;
  4717. }
  4718. if(validText == orgValue) {
  4719. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  4720. $(this).parents('td').html(html);
  4721. return;
  4722. }
  4723. const data = {
  4724. id: fid,
  4725. filename: validText,
  4726. };
  4727. const _self = $(this);
  4728. postData('/wap/shoufang/editfile', data, function (result) {
  4729. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  4730. _self.parents('td').html(html);
  4731. });
  4732. });
  4733. // 取消修改文件名
  4734. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  4735. const fid = $(this).data('fid');
  4736. const filename = $(this).data('filename');
  4737. const fileext = $(this).data('fileext');
  4738. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  4739. $(this).parents('td').html(html);
  4740. });
  4741. // 删除收方单附件
  4742. $('body').on('click', '.del-shoufang-att', function () {
  4743. const id = $(this).data('id');
  4744. const _self = $(this);
  4745. const data = { id };
  4746. const sfid = $(this).data('sfid');
  4747. postData('/wap/shoufang/delfile', data, function (result) {
  4748. _self.parents('tr').remove();
  4749. // 附件个数更新
  4750. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  4751. const sfInfo = _.find(sfData, { id: sfid });
  4752. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  4753. });
  4754. });
  4755. // 定位到对应的清单或计量单元
  4756. $('body').on('click', '.show-shoufang-node', function () {
  4757. const id = parseInt($(this).attr('data-id'));
  4758. const sfInfo = _.find(sfData, { id });
  4759. if (sfInfo) {
  4760. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4761. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  4762. stagePosSpreadObj.loadCurPosData();
  4763. if (sfInfo.pid) {
  4764. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  4765. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  4766. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  4767. }
  4768. }
  4769. });
  4770. // 定位到对应的清单或计量单元
  4771. $('body').on('click', '.show-shoufang-report', function () {
  4772. const id = parseInt($(this).attr('data-id'));
  4773. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  4774. sessionStorage.qrCodePath = qrCodePath;
  4775. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  4776. sessionStorage.req_params = JSON.stringify(req_params);
  4777. sessionStorage.rpt_name = rpt_name;
  4778. window.open('/individualReport/A4');
  4779. });
  4780. $('#importExcel').click(() => {
  4781. importExcel.doImport({
  4782. template: {
  4783. hint: '计量台账',
  4784. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/导入计量台账Excel格式.xlsx',
  4785. },
  4786. callback: function (sheet) {
  4787. postDataCompress(window.location.pathname + '/importStageSheet', {sheet}, function (result) {
  4788. window.location.reload();
  4789. }, null);
  4790. }
  4791. });
  4792. });
  4793. const stageAssistRela = {
  4794. refreshAssConfirmBtn: function () {
  4795. if (stage.assist) {
  4796. const caption = stage.assist.user_id === stage.user_id
  4797. ? (stage.assist.confirm ? '撤销上报' : '确认上报')
  4798. : (stage.assist.confirm ? '重新审批' : '审批通过');
  4799. if (!stage.readOnly || stage.assist.locked) $('#ass-confirm-btn').show().html(caption);
  4800. } else {
  4801. $('#ass-confirm-btn').hide();
  4802. }
  4803. },
  4804. checkAssistPartUsed(assist) {
  4805. const ass_lid = assist.ass_ledger_id.split(',');
  4806. for (const lid of ass_lid) {
  4807. const node = stageTree.getItems(lid);
  4808. if (!node) continue;
  4809. if (checkUsed(stageTree, stagePos, node)) return true;
  4810. }
  4811. return false;
  4812. },
  4813. refreshAssistTable: function () {
  4814. const html = [];
  4815. for (const ra of stage.relaAssists) {
  4816. const used = this.checkAssistPartUsed(ra);
  4817. const hint = used
  4818. ? (ra.confirm ? `<td class="text-success">${moment(ra.update_time).format('YYYY-MM-DD HH:mm')}</td>` : '<td class="text-warning">待确认</td>')
  4819. : '<td>本期未计量</td>';
  4820. html.push(`<tr><td>${ra.name}</td><td>${ra.company}</td>${hint}</tr>`);
  4821. }
  4822. return $('#assistList').html(html.join(''));
  4823. },
  4824. refreshAssists: function () {
  4825. if (stage.relaAssists.length > 0) {
  4826. $('#assistCount').html(stage.relaAssists.length || '').parent().show();
  4827. } else {
  4828. $('#assistCount').parent().hide();
  4829. }
  4830. },
  4831. refreshReadOnly(){
  4832. stageTreeSpreadObj.assistReadOnly = stage.readOnly || stage.revising || (!!stage.assist && !!stage.assist.confirm);
  4833. SpreadJsObj.refreshSheetReadOnly(slSpread.getActiveSheet());
  4834. stagePosSpreadObj.loadCurPosData();
  4835. },
  4836. init: function() {
  4837. this.refreshAssConfirmBtn();
  4838. this.refreshReadOnly();
  4839. this.refreshAssists();
  4840. },
  4841. };
  4842. stageAssistRela.init();
  4843. $('#ass-confirm-btn').click(() => {
  4844. const data = { user_id: stage.assist.user_id, ass_user_id: stage.assist.ass_user_id, confirm: !stage.assist.confirm, type: 'stage' };
  4845. postData(window.location.pathname + '/ass-confirm', data, function(result) {
  4846. window.location.reload();
  4847. // stage.assist = result;
  4848. // stageAssistRela.refreshAssConfirmBtn();
  4849. // stageAssistRela.refreshReadOnly();
  4850. });
  4851. });
  4852. $('#assists').on('show.bs.modal', function(){
  4853. postData(window.location.pathname + '/ass', { user_id: userID, type: 'stage' }, function (result) {
  4854. stage.relaAssists = result;
  4855. stageAssistRela.refreshAssistTable();
  4856. });
  4857. });
  4858. });
  4859. function makeOneShouFang(sf) {
  4860. const lData = _.find(ledgerData, { id: sf.lid });
  4861. sf.name = lData.b_code;
  4862. if (sf.pid) {
  4863. const pData = _.find(posData, { id: sf.pid });
  4864. sf.name = lData.b_code + ' / ' + pData.name;
  4865. }
  4866. return sf;
  4867. }
  4868. function makeShouFang() {
  4869. for (const sf of sfData) {
  4870. makeOneShouFang(sf);
  4871. }
  4872. getShouFangList();
  4873. }
  4874. // 生成收方单列表
  4875. function getShouFangList(currPageNum = 1) {
  4876. // 每页最多几个附件
  4877. const pageCount = 20;
  4878. // 附件总数
  4879. const total = sfData.length;
  4880. // 总页数
  4881. const pageNum = Math.ceil(total/pageCount);
  4882. $('#shoufang-totalPage').text(pageNum);
  4883. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  4884. // 当前页附件内容
  4885. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  4886. let html = '';
  4887. for(const att of currPageAttData) {
  4888. html += '<tr><td>' + att.name + '</td>' +
  4889. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  4890. '<td width="100">' +
  4891. '<a href="javascript:void(0);" data-id="'+ att.id +'" class="show-shoufang-node mr-1" data-toggle="tooltip" data-placement="left" data-original-title="定位"><i class="fa fa-crosshairs"></i></a> ' +
  4892. '<a href="javascript:void(0);" data-id="'+ att.id +'" class="show-shoufang-report mr-1"><i data-toggle="tooltip" data-placement="left" data-original-title="预览" class="fa fa-eye"></i></a> ' +
  4893. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  4894. makeDelHtml(att.id, att.extra_upload) +
  4895. '</td></tr>';
  4896. }
  4897. function makeDelHtml(id, extra_upload) {
  4898. return cur_uid === stage.user_id &&
  4899. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4900. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  4901. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4902. }
  4903. $('#shoufang-table').html(html);
  4904. $('[data-toggle="tooltip"]').tooltip();
  4905. }
  4906. function makeReportData(sfid) {
  4907. const sfInfo = _.find(sfData, { id: sfid });
  4908. const ledger_code = sfInfo.name.split(' / ')[0];
  4909. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  4910. const replace_key_params = {
  4911. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  4912. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  4913. 'KEY_合同段': tenderInfo.deal_info.dealName,
  4914. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  4915. 'KEY_编号': '',
  4916. 'KEY_设计工程数量': 0,
  4917. };
  4918. // if (sfInfo.pid) {
  4919. // const pData = _.find(posData, { id: sfInfo.pid });
  4920. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  4921. // } else {
  4922. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4923. // }
  4924. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  4925. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  4926. const req_params = {
  4927. rpt_tpl_id: window.location.host === '127.0.0.1:7002' || window.location.host === 'jlqa.smartcost.com.cn:7002' ? 1784 : (window.location.host === 'jluat.smartcost.com.cn' ? 315 : 2138), // 1784(qa的,外网是2138)
  4928. pageSize: 'A4',
  4929. project_id: tender.project_id,
  4930. tender_id: tender.id,
  4931. stage_id: stage.id,
  4932. };
  4933. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  4934. const qrCodePath = sfInfo.qrcode;
  4935. return [qrCodePath, replace_key_params, req_params, rpt_name];
  4936. }