stage.js 230 KB

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