stage.js 229 KB

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