stage.js 233 KB

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