stage.js 231 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791
  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 || data.is_import) 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, select) {
  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. // todo 优化,仅加载需要刷新的变更令
  1430. if (checkedChanges) checkedChanges.reloadChangeData();
  1431. }
  1432. });
  1433. $.contextMenu({
  1434. selector: '#stage-ledger',
  1435. build: function ($trigger, e) {
  1436. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1437. stageTreeSpreadObj.loadRelaData();
  1438. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1439. },
  1440. items: {
  1441. 'locateZjjl': {
  1442. name: '定位至中间计量',
  1443. icon: 'fa-sign-in',
  1444. callback: function (key, opt) {
  1445. if (!detail) {
  1446. detail = new Detail($('#detail-spread'));
  1447. }
  1448. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1449. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1450. if (leafUsedBills) {
  1451. if (!$('#zhongjian').hasClass('active')) {
  1452. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  1453. $('a', '.side-menu').removeClass('active');
  1454. $('.tab-content .tab-select-show').removeClass('active');
  1455. tab.addClass('active');
  1456. tabPanel.addClass('active');
  1457. showSideTools(tab.hasClass('active'));
  1458. slSpread.refresh();
  1459. spSpread.refresh();
  1460. }
  1461. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1462. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1463. SpreadJsObj.locateData(detail.sheet, im);
  1464. detail.spread.refresh();
  1465. $('#zhongjian .sjs-bottom').height('400px');
  1466. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1467. detail.reLoadDetailData();
  1468. } else {
  1469. toastr.error('无可定位中间计量');
  1470. }
  1471. },
  1472. disabled: function (key, opt) {
  1473. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1474. return !node;
  1475. }
  1476. },
  1477. tagSpr: '----',
  1478. tag: {
  1479. name: '书签',
  1480. callback: function (key, opt, menu, e) {
  1481. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1482. addTag.do(node);
  1483. },
  1484. disabled: function (key, opt) {
  1485. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1486. return !node;
  1487. }
  1488. },
  1489. showSpr: '----',
  1490. showLast: {
  1491. name: '显示至最底层',
  1492. callback: function (key, opt, menu, e) {
  1493. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1494. setTimeout(() => {
  1495. showWaitingView();
  1496. stageTree.expandByCustom(x => {
  1497. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1498. });
  1499. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  1500. closeWaitingView();
  1501. }, 100);
  1502. },
  1503. disabled: function (key, opt) {
  1504. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1505. return !node;
  1506. }
  1507. },
  1508. exportSpr: '----',
  1509. exportSelectNodeXlsx: {
  1510. name: '导出选中节点至Excel',
  1511. callback: function (key, opt, menu, e) {
  1512. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1513. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  1514. },
  1515. disabled: function (key, opt) {
  1516. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1517. return !node;
  1518. }
  1519. },
  1520. importSpr: '---',
  1521. importStageGcl: {
  1522. name: '导入(其他标段)工程量清单计量数据',
  1523. icon: 'fa-link',
  1524. disabled: function (key, opt) {
  1525. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1526. return readOnly || !node || !stageTree.isLeafXmj(node);
  1527. },
  1528. callback: function (key, opt) {
  1529. tenderSelect.showSelect(SpreadJsObj.getSelectObject(slSpread.getActiveSheet()));
  1530. }
  1531. },
  1532. shoufangdanSpr: '---',
  1533. shoufangdan: {
  1534. name: '生成收方单',
  1535. visible: function(key, opt) {
  1536. if (cur_uid === stage.user_id) return true;
  1537. },
  1538. disabled: function (key, opt) {
  1539. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1540. if (!node || !node.b_code || !node.is_leaf || cur_uid !== stage.user_id) return true;
  1541. },
  1542. callback: function (key, opt) {
  1543. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1544. $('#shoufang-lid').val(node.id);
  1545. $('#shoufang-pid').val('');
  1546. $('#shoufang-ledger').text('清单:' + node.b_code);
  1547. $('#shoufang-pos').text('').hide();
  1548. $('#addshoufang').modal('show');
  1549. }
  1550. }
  1551. }
  1552. });
  1553. const stagePosSpreadObj = {
  1554. loadExprToInput(sheet) {
  1555. const sel = sheet.getSelections()[0];
  1556. if (!sel) return;
  1557. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1558. if (col && col.type === 'Number') {
  1559. const data = SpreadJsObj.getSelectObject(sheet);
  1560. if (data) {
  1561. const exprInfo = getExprInfo(col.field);
  1562. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1563. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1564. .attr('readOnly', readOnly || cell.locked());
  1565. $('#pos-expr').attr('data-row', sel.row);
  1566. } else {
  1567. $('#pos-expr').val('').attr('readOnly', true);
  1568. $('#pos-expr').removeAttr('data-row');
  1569. }
  1570. } else {
  1571. $('#pos-expr').val('').attr('readOnly', true);
  1572. $('#pos-expr').removeAttr('data-row');
  1573. }
  1574. },
  1575. /**
  1576. * 加载计量单元 根据当前台账选择节点
  1577. */
  1578. loadCurPosData: function () {
  1579. const sheet = slSpread.getActiveSheet();
  1580. const node = SpreadJsObj.getSelectObject(sheet);
  1581. if (node) {
  1582. const posReadOnly = node.lock || (node.children && node.children.length > 0) || !node.b_code;
  1583. spSpread.getActiveSheet().zh_setting.readOnly = posReadOnly;
  1584. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1585. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData, posReadOnly);
  1586. getNodeList(node.id);
  1587. } else {
  1588. spSpread.getActiveSheet().zh_setting.readOnly = true;
  1589. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', [], true);
  1590. }
  1591. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1592. },
  1593. editEnded: function (e, info) {
  1594. if (info.sheet.zh_setting) {
  1595. // 未改变过,则直接跳过
  1596. const sortData = info.sheet.zh_data;
  1597. const posData = sortData ? sortData[info.row] : null;
  1598. const col = info.sheet.zh_setting.cols[info.col];
  1599. const orgText = posData ? posData[col.field] : null;
  1600. const newText = trimInvalidChar(info.editingText);
  1601. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1602. return;
  1603. }
  1604. // 台账模式下,不可新增
  1605. if (checkTzMeasureType() && !posData) {
  1606. toastr.error('台账模式不可新增计量单元数据');
  1607. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1608. return ;
  1609. }
  1610. // 不同节点下,计量单元检查输入
  1611. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1612. const node = stagePosSpreadObj.stageTreeNode;
  1613. if (!node) {
  1614. toastr.warning('数据错误, 请刷新页面后再试');
  1615. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1616. return;
  1617. } else if (newText !== '' && node.children && node.children.length > 0) {
  1618. toastr.error('父节点不可插入计量单元');
  1619. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1620. return;
  1621. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1622. toastr.error('项目节不可插入计量单元');
  1623. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1624. return;
  1625. }
  1626. // 生成提交数据
  1627. const data = {};
  1628. if (col.field === 'name') {
  1629. if ((!newText || newText === '') && posData) {
  1630. toastr.error('部位名称不可为空');
  1631. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1632. return;
  1633. } else if (!posData) {
  1634. if (newText !== '') {
  1635. data.updateType = 'add';
  1636. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1637. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1638. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1639. return;
  1640. }
  1641. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1642. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1643. } else {
  1644. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1645. return;
  1646. }
  1647. } else {
  1648. data.updateType = 'update';
  1649. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1650. }
  1651. } else if (!posData) {
  1652. toastr.warning('新增计量单元请先输入名称');
  1653. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1654. data.updateType = 'update';
  1655. data.updateData = {pid: posData.id, lid: posData.lid};
  1656. data.updateData[col.field] = newText;
  1657. } else {
  1658. data.updateType = 'update';
  1659. data.updateData = {pid: posData.id, lid: posData.lid};
  1660. if (col.type === 'Number') {
  1661. const exprInfo = getExprInfo(col.field);
  1662. const num = _.toNumber(newText);
  1663. if (_.isFinite(num)) {
  1664. data.updateData[col.field] = num;
  1665. if (exprInfo) {
  1666. data.updateData[exprInfo.expr] = '';
  1667. }
  1668. } else {
  1669. try {
  1670. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1671. if (exprInfo) {
  1672. data.updateData[exprInfo.expr] = newText;
  1673. }
  1674. } catch(err) {
  1675. toastr.error('输入的表达式非法');
  1676. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1677. return;
  1678. }
  1679. }
  1680. } else {
  1681. data.updateData[col.field] = newText;
  1682. }
  1683. }
  1684. // 提交数据到服务器
  1685. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1686. if (result.pos) {
  1687. stagePos.updateDatas(result.pos.pos);
  1688. stagePos.loadCurStageData(result.pos.curStageData);
  1689. }
  1690. const refreshData = stageTree.loadPostStageData(result.ledger);
  1691. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1692. stagePosSpreadObj.loadCurPosData();
  1693. if (detail) {
  1694. detail.loadStagePosUpdateData(result, refreshData);
  1695. } else {
  1696. stageIm.loadUpdatePosData(result, refreshData);
  1697. }
  1698. }, function () {
  1699. stagePosSpreadObj.loadCurPosData();
  1700. });
  1701. }
  1702. },
  1703. editStarting: function (e, info) {
  1704. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1705. const sel = info.sheet.getSelections();
  1706. if (!sel || !sel[0]) return;
  1707. const col = info.sheet.zh_setting.cols[sel[0].col];
  1708. const node = SpreadJsObj.getSelectObject(info.sheet);
  1709. const exprInfo = getExprInfo(col.field);
  1710. if (exprInfo && node) {
  1711. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1712. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1713. }
  1714. }
  1715. },
  1716. clipboardPasting: function (e, info) {
  1717. if (info.sheet.zh_setting) {
  1718. const sortData = info.sheet.zh_data;
  1719. const range = info.cellRange;
  1720. const validField = ['contract_qty', 'qc_qty', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3'];
  1721. if (!checkTzMeasureType()) {
  1722. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1723. }
  1724. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1725. const col = info.sheet.zh_setting.cols[iCol];
  1726. if (validField.indexOf(col.field) === -1) {
  1727. if (checkTzMeasureType()) {
  1728. toastr.error('不可修改此数据');
  1729. info.cancel = true;
  1730. return;
  1731. } else {
  1732. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1733. const pos = sortData(iRow);
  1734. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1735. toastr.error('不可修改此数据');
  1736. info.cancel = true;
  1737. return;
  1738. }
  1739. }
  1740. }
  1741. }
  1742. }
  1743. }
  1744. },
  1745. clipboardPasted: function (e, info) {
  1746. if (info.sheet.zh_setting) {
  1747. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1748. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1749. }
  1750. const data = { updateType: '', updateData: [], };
  1751. const sortData = info.sheet.zh_data;
  1752. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1753. if (node.children && node.children.length > 0) return;
  1754. if (sortData && (info.cellRange.row >= sortData.length)) {
  1755. data.updateType = 'add';
  1756. if (info.cellRange.col !== 0) {
  1757. toastr.warning('新增计量单元请先输入名称');
  1758. stagePosSpreadObj.loadCurPosData();
  1759. return;
  1760. }
  1761. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1762. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1763. stagePosSpreadObj.loadCurPosData();
  1764. return;
  1765. }
  1766. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1767. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1768. const curRow = info.cellRange.row + iRow;
  1769. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1770. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1771. const curCol = info.cellRange.col + iCol;
  1772. const colSetting = info.sheet.zh_setting.cols[curCol];
  1773. if (!colSetting) continue;
  1774. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1775. if (colSetting.type === 'Number') {
  1776. const exprInfo = getExprInfo(colSetting.field);
  1777. if (newValue) {
  1778. const num = _.toNumber(newValue);
  1779. if (num) {
  1780. newData[colSetting.field] = num;
  1781. if (exprInfo) {
  1782. newData[exprInfo.expr] = '';
  1783. }
  1784. } else {
  1785. try {
  1786. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1787. if (exprInfo) {
  1788. newData[exprInfo.expr] = newValue;
  1789. }
  1790. } catch(err) {
  1791. toastr.error('输入的表达式非法');
  1792. stagePosSpreadObj.loadCurPosData();
  1793. return;
  1794. }
  1795. }
  1796. } else {
  1797. newData[colSetting.field] = null;
  1798. if (exprInfo) newData[exprInfo.expr] = '';
  1799. }
  1800. } else {
  1801. newData[colSetting.field] = newValue;
  1802. }
  1803. }
  1804. data.updateData.push(newData);
  1805. }
  1806. } else {
  1807. data.updateType = 'update';
  1808. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1809. const curRow = info.cellRange.row + iRow;
  1810. const curPos = sortData[curRow];
  1811. if (curPos) {
  1812. const newData = {pid: curPos.id, lid: curPos.lid};
  1813. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1814. const curCol = info.cellRange.col + iCol;
  1815. const colSetting = info.sheet.zh_setting.cols[curCol];
  1816. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1817. if (colSetting.type === 'Number') {
  1818. const exprInfo = getExprInfo(colSetting.field);
  1819. if (!newValue) {
  1820. newData[colSetting.field] = newValue;
  1821. if (exprInfo) newData[exprInfo.expr] = '';
  1822. continue;
  1823. }
  1824. const num = _.toNumber(newValue);
  1825. if (num) {
  1826. newData[colSetting.field] = num;
  1827. if (exprInfo) newData[exprInfo.expr] = '';
  1828. } else {
  1829. try {
  1830. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1831. const exprInfo = getExprInfo(colSetting.field);
  1832. if (exprInfo) newData[exprInfo.expr] = newValue;
  1833. } catch(err) {
  1834. toastr.error('输入的表达式非法');
  1835. stagePosSpreadObj.loadCurPosData();
  1836. return;
  1837. }
  1838. }
  1839. } else {
  1840. newData[colSetting.field] = newValue;
  1841. }
  1842. }
  1843. data.updateData.push(newData);
  1844. }
  1845. }
  1846. }
  1847. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1848. if (result.pos) {
  1849. stagePos.updateDatas(result.pos.pos);
  1850. stagePos.loadCurStageData(result.pos.curStageData);
  1851. }
  1852. const nodes = stageTree.loadPostStageData(result.ledger);
  1853. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1854. stagePosSpreadObj.loadCurPosData();
  1855. if (detail) {
  1856. detail.loadStagePosUpdateData(result, nodes);
  1857. } else {
  1858. stageIm.loadUpdatePosData(result, nodes);
  1859. }
  1860. }, function () {
  1861. stagePosSpreadObj.loadCurPosData();
  1862. });
  1863. }
  1864. },
  1865. deletePress: function (sheet) {
  1866. if (sheet.zh_setting.readOnly) return;
  1867. if (sheet.zh_setting && sheet.zh_data) {
  1868. const sortData = sheet.zh_data;
  1869. if (!sortData || sortData.length === 0) { return; }
  1870. const sel = sheet.getSelections()[0];
  1871. const validCols = [];
  1872. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1873. const colSetting = sheet.zh_setting.cols[iCol];
  1874. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1875. validCols.push(iCol);
  1876. }
  1877. }
  1878. if (validCols.length === 0) { return; }
  1879. const datas = [], posSelects = [];
  1880. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1881. const node = sortData[iRow];
  1882. if (node) {
  1883. const data = {pid: node.id, lid: node.lid};
  1884. for (const iCol of validCols) {
  1885. const colSetting = sheet.zh_setting.cols[iCol];
  1886. if (colSetting.field === 'name') {
  1887. toastr.error('部位名称不能为空');
  1888. return;
  1889. }
  1890. data[colSetting.field] = null;
  1891. const exprInfo = getExprInfo(colSetting.field);
  1892. if (exprInfo) {
  1893. data[exprInfo.expr] = '';
  1894. }
  1895. }
  1896. datas.push(data);
  1897. posSelects.push(node);
  1898. }
  1899. }
  1900. if (datas.length > 0) {
  1901. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1902. if (result.pos) {
  1903. stagePos.updateDatas(result.pos.pos);
  1904. stagePos.loadCurStageData(result.pos.curStageData);
  1905. }
  1906. const nodes = stageTree.loadPostStageData(result.ledger);
  1907. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1908. if (detail) {
  1909. detail.loadStagePosUpdateData(result, nodes);
  1910. } else {
  1911. stageIm.loadUpdatePosData(result, nodes);
  1912. }
  1913. // todo 只加载改变项
  1914. stagePosSpreadObj.loadCurPosData();
  1915. });
  1916. }
  1917. }
  1918. },
  1919. deletePos: function (sheet) {
  1920. const sels = sheet.getSelections();
  1921. const sel = sels ? sels[0] : null;
  1922. if (sheet.zh_data && sel) {
  1923. const data = {updateType: 'delete', updateData: []};
  1924. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1925. const posData = sheet.zh_data[sel.row + iRow];
  1926. if (posData) {
  1927. data.updateData.push(posData.id);
  1928. }
  1929. }
  1930. if (data.updateData.length > 0) {
  1931. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1932. stagePos.removeDatas(result.pos.pos);
  1933. const refreshData = stageTree.loadPostStageData(result.ledger);
  1934. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1935. stagePosSpreadObj.loadCurPosData();
  1936. if (detail) {
  1937. detail.loadStagePosUpdateData(result, refreshData);
  1938. } else {
  1939. stageIm.loadUpdatePosData(result, refreshData);
  1940. }
  1941. });
  1942. }
  1943. }
  1944. },
  1945. selectionChanged: function (e, info) {
  1946. stagePosSpreadObj.loadExprToInput(info.sheet);
  1947. },
  1948. addPegs: function (pegs) {
  1949. if (!pegs || pegs.length <= 0) return;
  1950. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1951. if (!node) return;
  1952. const sheet = spSpread.getActiveSheet();
  1953. const sortData = sheet.zh_data || [];
  1954. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1955. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1956. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1957. if (result.pos) {
  1958. stagePos.updateDatas(result.pos.pos);
  1959. }
  1960. stagePosSpreadObj.loadCurPosData();
  1961. });
  1962. }
  1963. };
  1964. // 加载上下窗口resizer
  1965. $.divResizer({
  1966. select: '#main-resize',
  1967. callback: function () {
  1968. slSpread.refresh();
  1969. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1970. $(".sp-wrap").height(bcontent-30);
  1971. spSpread.refresh();
  1972. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1973. }
  1974. });
  1975. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1976. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;cooperation' }, function (result) {
  1977. // 加载树结构
  1978. stageTree.loadDatas(result.ledgerData);
  1979. checkShowLast(result.ledgerData.length);
  1980. treeCalc.calculateAll(stageTree);
  1981. // 加载解锁相关
  1982. if (result.cooperation) {
  1983. stageTree.loadPwd(result.cooperation, 'bills-p-' + userID + '-' + window.location.pathname.split('/')[2], result.cooperationConfirm);
  1984. $('#cooperationCount').html(stageTree.pwd.length || '');
  1985. if (stageTree.pwd.length > 0) $('#cooperationCount').parent().show();
  1986. setCooperationSelectHtml();
  1987. reloadCooperationHtml();
  1988. }
  1989. for (const t of result.tags) {
  1990. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  1991. }
  1992. billsTag.loadDatas(result.tags);
  1993. // 加载部位明细
  1994. stagePos.loadDatas(result.posData);
  1995. stagePos.calculateAll();
  1996. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1997. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1998. stagePosSpreadObj.loadCurPosData();
  1999. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  2000. // 加载中间计量
  2001. stageIm.init(stage, imType, tenderInfo.decimal);
  2002. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData, result.detailAtt);
  2003. errorList.loadHisErrorData();
  2004. checkList.loadHisCheckData();
  2005. sumLoadMiss.loadHisMissData();
  2006. // 收方单赋值
  2007. ledgerData = result.ledgerData;
  2008. posData = result.posData;
  2009. makeShouFang();
  2010. }, null, true);
  2011. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2012. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2013. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2014. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2015. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2016. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2017. if (!readOnly) {
  2018. $('#pos-expr').bind('change onblur', function () {
  2019. if (this.readOnly) return;
  2020. const expr = $(this);
  2021. const posSheet = spSpread.getActiveSheet();
  2022. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2023. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2024. if (!select) return;
  2025. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2026. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2027. const data = {pid: select.id, lid: select.lid};
  2028. const exprInfo = getExprInfo(field);
  2029. if (newValue !== '') {
  2030. const num = _.toNumber(newValue);
  2031. if (num) {
  2032. data[field] = num;
  2033. if (exprInfo) data[exprInfo.expr] = '';
  2034. } else {
  2035. try {
  2036. data[field] = math.evaluate(transExpr(newValue));
  2037. if (exprInfo) data[exprInfo.expr] = newValue;
  2038. } catch (err) {
  2039. toastr.error('输入的表达式非法');
  2040. return;
  2041. }
  2042. }
  2043. } else {
  2044. data[field] = null;
  2045. if (exprInfo) data[exprInfo.expr] = '';
  2046. }
  2047. // 提交数据到服务器
  2048. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2049. if (result.pos) {
  2050. stagePos.updateDatas(result.pos.pos);
  2051. stagePos.loadCurStageData(result.pos.curStageData);
  2052. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2053. }
  2054. const refreshData = stageTree.loadPostStageData(result.ledger);
  2055. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2056. if (detail) {
  2057. detail.loadStagePosUpdateData(result, refreshData);
  2058. } else {
  2059. stageIm.loadUpdatePosData(result, refreshData);
  2060. }
  2061. });
  2062. });
  2063. }
  2064. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2065. $.contextMenu({
  2066. selector: '#stage-pos',
  2067. build: function ($trigger, e) {
  2068. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2069. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2070. },
  2071. items: {
  2072. 'del': {
  2073. name: '删除',
  2074. icon: 'fa-remove',
  2075. visible: function (key, opt) {
  2076. return !checkTzMeasureType();
  2077. },
  2078. disabled: function (key, opt) {
  2079. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2080. if (!node || node.lock) return true;
  2081. const sheet = spSpread.getActiveSheet();
  2082. if (sheet.zh_data && !readOnly) {
  2083. const selection = sheet.getSelections();
  2084. if (selection && selection[0]) {
  2085. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2086. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2087. const posData = sheet.zh_data[selection[0].row + iRow];
  2088. if (posData) {
  2089. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2090. valid = true;
  2091. break;
  2092. }
  2093. } else {
  2094. valid = true;
  2095. break;
  2096. }
  2097. }
  2098. return valid;
  2099. } else {
  2100. return true;
  2101. }
  2102. } else {
  2103. return true;
  2104. }
  2105. },
  2106. callback: function (key, opt) {
  2107. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2108. }
  2109. },
  2110. 'merge-peg': {
  2111. name: '合并起讫桩号',
  2112. visible: function (key, opt) {
  2113. return !checkTzMeasureType();
  2114. },
  2115. disabled: function (key, opt) {
  2116. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2117. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2118. },
  2119. callback: function (key, opt) {
  2120. mergePeg.show();
  2121. }
  2122. },
  2123. 'calcByRatio': {
  2124. name: '按比例计量',
  2125. visible: function (key, opt) {
  2126. const data = spSpread.getActiveSheet().zh_data;
  2127. return checkTzMeasureType() && data && data.length > 0;
  2128. },
  2129. disabled: function (key, opt) {
  2130. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2131. return node.lock;
  2132. },
  2133. callback: function (key, opt) {
  2134. $('#cbr-ratio').val('');
  2135. $('#apply2sibling')[0].checked = false;
  2136. $('#cbr-check-all')[0].checked = false;
  2137. const html = [];
  2138. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2139. html.push('<tr>');
  2140. html.push('<td>', i+1, '</td>');
  2141. html.push('<td>', p.name, '</td>');
  2142. html.push('<td>', p.quantity, '</td>');
  2143. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2144. html.push('</tr>');
  2145. }
  2146. $('#cbr-pos-list').html(html.join(''));
  2147. $('#calc-by-ratio').modal('show');
  2148. }
  2149. },
  2150. 'remainCur': {
  2151. name: '填剩余量(选中行)',
  2152. disabled: function (key, opt) {
  2153. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2154. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2155. return readOnly || node.lock || !curPos;
  2156. },
  2157. callback: function (key, opt) {
  2158. const sheet = spSpread.getActiveSheet();
  2159. const sels = sheet.getSelections();
  2160. if (!sels || !sels[0]) return;
  2161. const data = { updateType: 'update', updateData: [] };
  2162. for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
  2163. const curRow = iRow + sels[0].row;
  2164. const curPos = SpreadJsObj.getRowObject(sheet, curRow);
  2165. if (!curPos) continue;
  2166. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2167. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2168. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2169. }
  2170. if (data.updateData.length > 0) {
  2171. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2172. if (result.pos) {
  2173. stagePos.updateDatas(result.pos.pos);
  2174. stagePos.loadCurStageData(result.pos.curStageData);
  2175. }
  2176. const nodes = stageTree.loadPostStageData(result.ledger);
  2177. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2178. stagePosSpreadObj.loadCurPosData();
  2179. if (detail) {
  2180. detail.loadStagePosUpdateData(result, nodes);
  2181. } else {
  2182. stageIm.loadUpdatePosData(result, nodes);
  2183. }
  2184. });
  2185. }
  2186. },
  2187. visible: function(key, opt) {
  2188. return checkTzMeasureType();
  2189. },
  2190. },
  2191. 'remainAll': {
  2192. name: '填剩余量(全部行)',
  2193. disabled: function (key, opt) {
  2194. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2195. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2196. return readOnly || node.lock || !curPos;
  2197. },
  2198. callback: function (key, opt) {
  2199. const sheet = spSpread.getActiveSheet();
  2200. if (!sheet.zh_data || sheet.zh_data.length === 0) return;
  2201. const data = { updateType: 'update', updateData: [] };
  2202. for (const curPos of sheet.zh_data) {
  2203. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2204. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2205. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2206. }
  2207. if (data.updateData.length > 0) {
  2208. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2209. if (result.pos) {
  2210. stagePos.updateDatas(result.pos.pos);
  2211. stagePos.loadCurStageData(result.pos.curStageData);
  2212. }
  2213. const nodes = stageTree.loadPostStageData(result.ledger);
  2214. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2215. stagePosSpreadObj.loadCurPosData();
  2216. if (detail) {
  2217. detail.loadStagePosUpdateData(result, nodes);
  2218. } else {
  2219. stageIm.loadUpdatePosData(result, nodes);
  2220. }
  2221. });
  2222. }
  2223. },
  2224. visible: function(key, opt) {
  2225. return checkTzMeasureType();
  2226. },
  2227. },
  2228. 'shoufangdan': {
  2229. name: '生成收方单',
  2230. visible: function(key, opt) {
  2231. if (cur_uid === stage.user_id) return true;
  2232. },
  2233. disabled: function (key, opt) {
  2234. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2235. if (!node || cur_uid !== stage.user_id) return true;
  2236. },
  2237. callback: function (key, opt) {
  2238. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2239. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2240. $('#shoufang-lid').val(node.lid);
  2241. $('#shoufang-pid').val(node.id);
  2242. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2243. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2244. $('#addshoufang').modal('show');
  2245. }
  2246. }
  2247. }
  2248. });
  2249. $.subMenu({
  2250. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2251. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2252. key: 'menu.1.0.0',
  2253. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2254. callback: function (info) {
  2255. if (info.mini) {
  2256. $('.panel-title').addClass('fluid');
  2257. $('#sub-menu').removeClass('panel-sidebar');
  2258. } else {
  2259. $('.panel-title').removeClass('fluid');
  2260. $('#sub-menu').addClass('panel-sidebar');
  2261. }
  2262. autoFlashHeight();
  2263. slSpread.refresh();
  2264. spSpread.refresh();
  2265. if (searchLedger) searchLedger.spread.refresh();
  2266. if (detail) detail.spread.refresh();
  2267. if (checkedChanges) checkedChanges.refresh();
  2268. if (errorList && errorList.spread) errorList.spread.refresh();
  2269. if (checkList) checkList.spread.refresh();
  2270. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2271. }
  2272. });
  2273. $('#row-view').on('show.bs.modal', function () {
  2274. const html = [], customDisplay = customColDisplay();
  2275. for (const cd of customDisplay) {
  2276. html.push('<tr>');
  2277. html.push('<td>', cd.title, '</td>');
  2278. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2279. html.push('</tr>');
  2280. }
  2281. $('#row-view-list').html(html.join(''));
  2282. });
  2283. $('#row-view-ok').click(function () {
  2284. const customDisplay = customColDisplay();
  2285. const cvl = $('#row-view-list').children();
  2286. for (const cv of cvl) {
  2287. const title = $(cv).children()[0].innerHTML;
  2288. const check = $('input', cv)[0].checked;
  2289. const cd = customDisplay.find(function (c) {
  2290. return c.title === title;
  2291. });
  2292. cd.visible = check;
  2293. }
  2294. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2295. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2296. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2297. $('#row-view').modal('hide');
  2298. });
  2299. const posSearch = (function () {
  2300. let resultArr = [];
  2301. const search = function () {
  2302. resultArr = [];
  2303. const keyword = $('#pos-search-keyword').val();
  2304. const checkOver = $('#pos-over-search')[0].checked;
  2305. const checkEmpty = $('#pos-empty-search')[0].checked;
  2306. const sortData = spSpread.getActiveSheet().zh_data;
  2307. if (checkOver || checkEmpty) {
  2308. if (sortData) {
  2309. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2310. const sd = sortData[i];
  2311. let match = false;
  2312. if (checkOver) {
  2313. if (sd.end_gather_qty) {
  2314. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2315. }
  2316. }
  2317. if (checkEmpty) {
  2318. if (sd.quantity) {
  2319. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2320. }
  2321. }
  2322. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2323. if (match) {
  2324. resultArr.push({index: i, data: sd});
  2325. }
  2326. }
  2327. }
  2328. } else if (keyword && keyword !== '') {
  2329. if (sortData) {
  2330. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2331. const sd = sortData[i];
  2332. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2333. resultArr.push({index: i, data: sd});
  2334. }
  2335. }
  2336. }
  2337. }
  2338. $('#pos-search-result').html('结果:' + resultArr.length);
  2339. };
  2340. const searchAndLocate = function () {
  2341. search();
  2342. if (resultArr.length > 0) {
  2343. const sheet = spSpread.getActiveSheet();
  2344. const sel = sheet.getSelections()[0];
  2345. const curRow = sel ? sel.row : 0;
  2346. const pos = resultArr[0];
  2347. if (pos.index !== curRow) {
  2348. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2349. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2350. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2351. }
  2352. }
  2353. };
  2354. const locateNext = function () {
  2355. if (resultArr.length > 0) {
  2356. const sheet = spSpread.getActiveSheet();
  2357. const sel = sheet.getSelections()[0];
  2358. const curRow = sel ? sel.row : 0;
  2359. let next = _.find(resultArr, function (d) {
  2360. return d.index > curRow;
  2361. });
  2362. if (!next) next = resultArr[0];
  2363. if (next.index !== curRow) {
  2364. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2365. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2366. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2367. }
  2368. }
  2369. };
  2370. const locatePre = function () {
  2371. if (resultArr.length > 0) {
  2372. const sheet = spSpread.getActiveSheet();
  2373. const sel = sheet.getSelections()[0];
  2374. const curRow = sel ? sel.row : 0;
  2375. let next = _.findLast(resultArr, function (d) {
  2376. return d.index < curRow;
  2377. });
  2378. if (!next) next = resultArr[resultArr.length - 1];
  2379. if (next.index !== curRow) {
  2380. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2381. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2382. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2383. }
  2384. }
  2385. };
  2386. return {search, searchAndLocate, locateNext, locatePre};
  2387. })();
  2388. $('#pos-search-keyword').bind('keydown', function(e){
  2389. if (e.keyCode == 13) posSearch.searchAndLocate();
  2390. });
  2391. $('#pos-empty-search').click(function () {
  2392. if (this.checked) {
  2393. $('[for=' + this.id +']').addClass('text-warning');
  2394. } else {
  2395. $('[for=' + this.id +']').removeClass('text-warning');
  2396. }
  2397. if (this.checked) {
  2398. if ($('#pos-over-search')[0].checked) {
  2399. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2400. } else {
  2401. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2402. }
  2403. } else {
  2404. if ($('#pos-over-search')[0].checked) {
  2405. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2406. } else {
  2407. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2408. }
  2409. }
  2410. posSearch.searchAndLocate();
  2411. });
  2412. $('#pos-over-search').click(function () {
  2413. if (this.checked) {
  2414. $('[for=' + this.id +']').addClass('text-danger');
  2415. } else {
  2416. $('[for=' + this.id +']').removeClass('text-danger');
  2417. }
  2418. if (this.checked) {
  2419. if ($('#pos-empty-search')[0].checked) {
  2420. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2421. } else {
  2422. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2423. }
  2424. } else {
  2425. if ($('#pos-empty-search')[0].checked) {
  2426. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2427. } else {
  2428. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2429. }
  2430. }
  2431. posSearch.searchAndLocate();
  2432. });
  2433. $('#pos-search-next').click(() => {posSearch.locateNext()});
  2434. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  2435. $.divResizer({
  2436. select: '#right-spr',
  2437. callback: function () {
  2438. slSpread.refresh();
  2439. spSpread.refresh();
  2440. if (searchLedger) {
  2441. searchLedger.spread.refresh();
  2442. }
  2443. if (detail) {
  2444. detail.spread.refresh();
  2445. }
  2446. if (checkedChanges) checkedChanges.refresh();
  2447. if (errorList && errorList.spread) errorList.spread.refresh();
  2448. if (checkList) checkList.spread.refresh();
  2449. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2450. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2451. }
  2452. });
  2453. // 中间计量加载上下窗口resizer
  2454. $.divResizer({
  2455. select: '#zhongjian-spr',
  2456. callback: function () {
  2457. if (detail) {
  2458. detail.spread.refresh();
  2459. }
  2460. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2461. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2462. }
  2463. });
  2464. // 附件加载上下窗口resizer
  2465. $.divResizer({
  2466. select: '#file-spr',
  2467. callback: function () {
  2468. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2469. }
  2470. });
  2471. // 变更令加载上下窗口resizer
  2472. $.divResizer({
  2473. select: '#change-spr',
  2474. callback: function () {
  2475. if (checkedChanges) checkedChanges.refresh();
  2476. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2477. }
  2478. });
  2479. class Detail {
  2480. constructor (obj) {
  2481. const self = this;
  2482. this.spreadSetting = {
  2483. cols: [
  2484. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2485. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2486. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  2487. {
  2488. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  2489. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  2490. },
  2491. {
  2492. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  2493. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  2494. return data.attachment ? data.attachment.length : 0;
  2495. }
  2496. },
  2497. ],
  2498. headRows: 1,
  2499. emptyRows: 0,
  2500. headRowHeight: [32],
  2501. headColWidth: [30],
  2502. defaultRowHeight: 21,
  2503. headerFont: '12px 微软雅黑',
  2504. font: '12px 微软雅黑',
  2505. readOnly: readOnly,
  2506. selectedBackColor: '#fffacd',
  2507. imageClick: function (data) {
  2508. self.makeAttTable(data);
  2509. $('#im-file').modal('show');
  2510. }
  2511. };
  2512. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  2513. this.sheet = this.spread.getActiveSheet();
  2514. this.spread.options.allowUserDragFill = true;
  2515. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  2516. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2517. this.detailObj = {
  2518. selectionChanged: function (e, info) {
  2519. self.reLoadDetailData();
  2520. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  2521. self.loadLocateInfo();
  2522. }
  2523. },
  2524. editEnded: function(e, info) {
  2525. if (info.sheet.zh_setting) {
  2526. const col = info.sheet.zh_setting.cols[info.col];
  2527. if (col.field !== 'doc_code') {
  2528. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2529. return;
  2530. }
  2531. const data = SpreadJsObj.getSelectObject(info.sheet);
  2532. if (data) {
  2533. const updateData = {lid: data.lid, pid: data.pid};
  2534. if (data.uuid) {
  2535. updateData.uuid = data.uuid;
  2536. } else {
  2537. updateData.code = data.code;
  2538. updateData.name = data.name;
  2539. updateData.unit = data.unit;
  2540. updateData.unit_price = data.unit_price;
  2541. updateData.pid = data.pid;
  2542. updateData.pos_name = data.pos_name;
  2543. updateData.im_type = data.im_type;
  2544. }
  2545. if (data.custom_define.indexOf('doc_code') === -1) {
  2546. updateData.custom_define = data.custom_define;
  2547. updateData.custom_define.push('doc_code');
  2548. updateData.custom_define = updateData.custom_define.join(',');
  2549. }
  2550. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  2551. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2552. stageIm.loadUpdateDetailData(result);
  2553. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2554. }, function () {
  2555. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2556. });
  2557. } else {
  2558. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2559. }
  2560. }
  2561. },
  2562. clipboardPasted: function (e, info) {
  2563. if (info.sheet.zh_setting && info.sheet.zh_data) {
  2564. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  2565. if (info.cellRange.colCount > 1) {
  2566. toastr.warning('请勿同时复制粘贴多列数据');
  2567. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2568. return;
  2569. }
  2570. if (col.field !== 'doc_code') {
  2571. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2572. return;
  2573. }
  2574. const datas = [];
  2575. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2576. const curRow = info.cellRange.row + iRow;
  2577. const data = info.sheet.zh_data[curRow];
  2578. if (data) {
  2579. const updateData = {lid: data.lid, pid: data.pid};
  2580. if (data.uuid) {
  2581. updateData.uuid = data.uuid;
  2582. } else {
  2583. updateData.code = data.code;
  2584. updateData.name = data.name;
  2585. updateData.unit = data.unit;
  2586. updateData.unit_price = data.unit_price;
  2587. updateData.pid = data.pid;
  2588. updateData.pos_name = data.pos_name;
  2589. updateData.im_type = data.im_type;
  2590. }
  2591. if (data.custom_define.indexOf('doc_code') === -1) {
  2592. updateData.custom_define = data.custom_define;
  2593. updateData.custom_define.push('doc_code');
  2594. updateData.custom_define = updateData.custom_define.join(',');
  2595. }
  2596. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  2597. datas.push(updateData);
  2598. }
  2599. }
  2600. if (datas.length > 0) {
  2601. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2602. stageIm.loadUpdateDetailData(result);
  2603. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2604. }, function () {
  2605. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2606. })
  2607. }
  2608. }
  2609. },
  2610. deletePress: function (sheet) {
  2611. if (sheet.zh_setting) {
  2612. const datas = [];
  2613. const sel = sheet.getSelections()[0];
  2614. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2615. const col = sheet.zh_setting.cols[iCol];
  2616. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2617. const data = sheet.zh_data[iRow];
  2618. if (col.field === 'doc_code') {
  2619. const updateData = {lid: data.lid};
  2620. if (data.uuid) {
  2621. updateData.uuid = data.uuid;
  2622. updateData.doc_code = '';
  2623. datas.push(updateData);
  2624. }
  2625. }
  2626. }
  2627. }
  2628. if (datas.length > 0) {
  2629. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2630. stageIm.loadUpdateDetailData(result);
  2631. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2632. }, function () {
  2633. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2634. });
  2635. }
  2636. }
  2637. },
  2638. dragFillBlock: function (e, info) {
  2639. info.cancel = true;
  2640. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2641. const sel = info.sheet.getSelections()[0];
  2642. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2643. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2644. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2645. if (text === '') return;
  2646. const regRst = /(\d+)$/g.exec(text), datas = [];
  2647. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2648. const curRow = info.fillRange.row + iRow;
  2649. const data = info.sheet.zh_data[curRow];
  2650. if (data) {
  2651. const updateData = {lid: data.lid};
  2652. if (data.uuid) {
  2653. updateData.uuid = data.uuid;
  2654. } else {
  2655. updateData.code = data.code;
  2656. updateData.name = data.name;
  2657. updateData.unit = data.unit;
  2658. updateData.unit_price = data.unit_price;
  2659. updateData.pid = data.pid;
  2660. updateData.pos_name = data.pos_name;
  2661. updateData.im_type = data.im_type;
  2662. }
  2663. if (regRst) {
  2664. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2665. } else {
  2666. updateData.doc_code = text.replace('\n', '');
  2667. }
  2668. if (data.custom_define.indexOf('doc_code') === -1) {
  2669. updateData.custom_define = data.custom_define;
  2670. updateData.custom_define.push('doc_code');
  2671. updateData.custom_define = updateData.custom_define.join(',');
  2672. }
  2673. datas.push(updateData);
  2674. }
  2675. }
  2676. if (datas.length > 0) {
  2677. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2678. stageIm.loadUpdateDetailData(result);
  2679. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2680. }, function () {
  2681. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2682. })
  2683. }
  2684. },
  2685. };
  2686. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2687. if (!readOnly) {
  2688. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2689. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2690. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2691. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2692. }
  2693. this._initImTypeSetRela();
  2694. this._initModifyDetail();
  2695. this._initLocateRela();
  2696. this._initAttRela();
  2697. // 草图相关
  2698. this._initImageRela();
  2699. this.reBuildImData();
  2700. }
  2701. makeAttTable (data) {
  2702. let html = [];
  2703. if (data.attachment) {
  2704. for (const att of data.attachment) {
  2705. const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked))
  2706. ? '<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>'
  2707. : '';
  2708. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  2709. 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>';
  2710. html.push('<tr><td style="width: 200px">' + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
  2711. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  2712. }
  2713. }
  2714. $('#im-attList').html(html.join(''));
  2715. }
  2716. _initAttRela() {
  2717. // 上传附件
  2718. const self = this;
  2719. $('#upload-im-file').change(function () {
  2720. const files = this.files;
  2721. const sels = self.sheet.getSelections();
  2722. const select = SpreadJsObj.getSelectObject(self.sheet);
  2723. if (!select) return;
  2724. const formData = new FormData();
  2725. const baseInfo = {};
  2726. if (select.att_uuid) {
  2727. baseInfo.uuid = select.att_uuid;
  2728. } else {
  2729. baseInfo.im_type = select.im_type;
  2730. baseInfo.lid = select.lid;
  2731. baseInfo.pid = select.pid;
  2732. baseInfo.code = select.code;
  2733. baseInfo.name = select.name;
  2734. baseInfo.unit = select.unit;
  2735. baseInfo.unit_price = select.unit_price;
  2736. baseInfo.pos_name = select.pos_name;
  2737. }
  2738. formData.append('base', JSON.stringify(baseInfo));
  2739. for (const file of files) {
  2740. if (file === undefined) {
  2741. toast('未选择上传文件!', 'error');
  2742. return false;
  2743. }
  2744. const filesize = file.size;
  2745. if (filesize > 30 * 1024 * 1024) {
  2746. toast('存在上传文件大小过大!', 'error');
  2747. return false;
  2748. }
  2749. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2750. if (whiteList.indexOf(fileext) === -1) {
  2751. toast('只能上传指定格式的附件!', 'error');
  2752. return false;
  2753. }
  2754. formData.append('size', filesize);
  2755. formData.append('file[]', file);
  2756. }
  2757. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  2758. stageIm.loadUpdateDetailAtt(data);
  2759. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  2760. self.makeAttTable(select);
  2761. $('#upload-im-file').val('');
  2762. });
  2763. });
  2764. // 删除附件
  2765. $('body').on('click', '.delete-att' ,function () {
  2766. const sels = self.sheet.getSelections();
  2767. const select = SpreadJsObj.getSelectObject(self.sheet);
  2768. if (!select) return;
  2769. const uuid = $(this).attr('data-imid');
  2770. const file_id = $(this).attr('data-attid');
  2771. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  2772. stageIm.loadUpdateDetailAtt(result);
  2773. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  2774. self.makeAttTable(select);
  2775. });
  2776. });
  2777. // 预览附件
  2778. $('body').on('click', '.preview-att', function () {
  2779. const uuid = $(this).attr('data-imid');
  2780. const file_id = $(this).attr('data-attid');
  2781. postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
  2782. const { filepath } = result;
  2783. $('#load-file').attr('href', filepath);
  2784. $('#load-file')[0].click();
  2785. });
  2786. })
  2787. }
  2788. _initImTypeSetRela() {
  2789. const self = this;
  2790. const gatherConfirmPopover = {
  2791. reBind: function (obj, eventName, fun) {
  2792. obj.unbind(eventName);
  2793. obj.bind(eventName, fun);
  2794. },
  2795. check: function (pos, hint, okCallback) {
  2796. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2797. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2798. this.reBind(cancelObj, 'click', function () {
  2799. confirmObj.hide();
  2800. });
  2801. this.reBind(okObj, 'click', function () {
  2802. okCallback();
  2803. confirmObj.hide();
  2804. });
  2805. hintObj.text(hint);
  2806. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2807. }
  2808. };
  2809. this.gsTree = stageIm.getGsTree();
  2810. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2811. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2812. jlCol.title = '本期计量金额';
  2813. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2814. $('[name=type-title-contract]').text('本期合同计量金额');
  2815. $('[name=type-title-qc]').text('本期变更计量金额');
  2816. } else {
  2817. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2818. jlCol.title = '本期计量数量';
  2819. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2820. $('[name=type-title-contract]').text('本期合同计量数量');
  2821. $('[name=type-title-qc]').text('本期变更计量数量');
  2822. }
  2823. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2824. $('#show-jldy').parent().show();
  2825. $('#jldy').parent().show();
  2826. $('#show-xm-name').parent().hide();
  2827. $('#xm-name').parent().hide();
  2828. } else {
  2829. $('#show-jldy').parent().hide();
  2830. $('#jldy').parent().hide();
  2831. $('#show-xm-name').parent().show();
  2832. $('#xm-name').parent().show();
  2833. }
  2834. // 选择中间计量模式
  2835. $('div[name="im-type"]').click(function () {
  2836. function chooseType(obj) {
  2837. obj.style.cursor = 'default';
  2838. $(obj).children().addClass('text-primary');
  2839. $(obj).addClass('border-primary');
  2840. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2841. }
  2842. function validType(obj) {
  2843. obj.style.cursor = 'pointer';
  2844. $(obj).children().removeClass('text-primary');
  2845. $(obj).removeClass('border-primary');
  2846. $('i', obj).remove();
  2847. }
  2848. if (this.style.cursor === 'pointer') {
  2849. const typeArr = $('div[name="im-type"]');
  2850. for (const t of typeArr) {
  2851. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2852. chooseType(t);
  2853. } else {
  2854. validType(t)
  2855. }
  2856. }
  2857. }
  2858. });
  2859. $('#choose').on('show.bs.modal', function () {
  2860. function chooseType(obj) {
  2861. obj.style.cursor = 'default';
  2862. $(obj).children().addClass('text-primary');
  2863. $('i', obj).remove();
  2864. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2865. }
  2866. function validType(obj) {
  2867. obj.style.cursor = 'pointer';
  2868. $(obj).children().removeClass('text-primary');
  2869. $('i', obj).remove();
  2870. }
  2871. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2872. $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
  2873. const typeArr = $('div[name="im-type"]');
  2874. for (const t of typeArr) {
  2875. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2876. chooseType(t);
  2877. } else {
  2878. validType(t)
  2879. }
  2880. }
  2881. });
  2882. // 提交 中间计量模式
  2883. $('#choose-ok').click(() => {
  2884. let startNum;
  2885. try {
  2886. startNum = parseInt($('#im-start-num').val());
  2887. if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
  2888. } catch (err) {
  2889. toastr.error("起始编号请输入正整数");
  2890. return;
  2891. }
  2892. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2893. return it.style.cursor !== 'pointer';
  2894. });
  2895. const data = {
  2896. im_type: parseInt($(chooseType).attr('im-type')),
  2897. im_pre: $('#im-pre').val(),
  2898. im_start_num: startNum,
  2899. };
  2900. postData(window.location.pathname + '/detail/build', data, function (result) {
  2901. stage.im_type = data.im_type;
  2902. stage.im_pre = data.im_pre;
  2903. stage.im_start_num = data.im_start_num;
  2904. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2905. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2906. jlCol.title = '本期计量金额';
  2907. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2908. $('[name=type-title-contract]').text('本期合同计量金额');
  2909. $('[name=type-title-qc]').text('本期变更计量金额');
  2910. } else {
  2911. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2912. jlCol.title = '本期计量数量';
  2913. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2914. $('[name=type-title-contract]').text('本期合同计量数量');
  2915. $('[name=type-title-qc]').text('本期变更计量数量');
  2916. }
  2917. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2918. $('#show-jldy').parent().show();
  2919. $('#jldy').parent().show();
  2920. $('#show-xm-name').parent().hide();
  2921. $('#xm-name').parent().hide();
  2922. } else {
  2923. $('#show-jldy').parent().hide();
  2924. $('#jldy').parent().hide();
  2925. $('#show-xm-name').parent().show();
  2926. $('#xm-name').parent().show();
  2927. }
  2928. // 加载生成数据
  2929. self.reBuildImData();
  2930. $('#choose').modal('hide');
  2931. });
  2932. });
  2933. // 显示树结构信息
  2934. $('#choose2').on('shown.bs.modal', function () {
  2935. if (!self.gsSpread) {
  2936. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2937. const setting = {
  2938. cols: [
  2939. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2940. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2941. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2942. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2943. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2944. ],
  2945. headRows: 1,
  2946. emptyRows: 0,
  2947. headRowHeight: [32],
  2948. defaultRowHeight: 21,
  2949. headerFont: '12px 微软雅黑',
  2950. font: '12px 微软雅黑',
  2951. };
  2952. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2953. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2954. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2955. function checkParent(node) {
  2956. const parent = self.gsTree.getParent(node);
  2957. if (parent) {
  2958. return parent.check ? parent.check : checkParent(parent);
  2959. } else {
  2960. return false;
  2961. }
  2962. }
  2963. function checkChildren(node) {
  2964. for (const child of node.children) {
  2965. if (child.check) {
  2966. return true;
  2967. } else if (checkChildren(child)) {
  2968. return true;
  2969. }
  2970. }
  2971. return false;
  2972. }
  2973. if (!$('#im-gather-check')[0].checked) { return; }
  2974. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2975. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2976. if (sheet.isEditing()) {
  2977. sheet.endEdit(true);
  2978. }
  2979. }
  2980. if (info.sheet.zh_setting) {
  2981. const col = info.sheet.zh_setting.cols[info.col];
  2982. if (col.field !== 'check') {
  2983. return;
  2984. }
  2985. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2986. const node = sortData[info.row];
  2987. if (!node.check) {
  2988. if (checkParent(node)) {
  2989. const rect = info.sheet.getCellRect(info.row, info.col);
  2990. gatherConfirmPopover.check({
  2991. x: rect.x + rect.width / 2 + 25,
  2992. y: rect.y + rect.height / 2 + 3,
  2993. }, '父项已勾选,继续将取消父项勾选。', function () {
  2994. node.check = true;
  2995. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2996. const rows = [self.gsTree.nodes.indexOf(node)];
  2997. for (const p of parents) {
  2998. if (p.check) {
  2999. p.check = false;
  3000. rows.push(self.gsTree.nodes.indexOf(p));
  3001. }
  3002. }
  3003. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3004. });
  3005. } else if (checkChildren(node)) {
  3006. const rect = info.sheet.getCellRect(info.row, info.col);
  3007. gatherConfirmPopover.check({
  3008. x: rect.x + rect.width / 2 + 25,
  3009. y: rect.y + rect.height / 2 + 3,
  3010. }, '子项已勾选,继续将取消子项勾选。', function () {
  3011. node.check = true;
  3012. const posterity = self.gsTree.getPosterity(node);
  3013. const rows = [self.gsTree.nodes.indexOf(node)];
  3014. for (const p of posterity) {
  3015. if (p.check) {
  3016. rows.push(self.gsTree.nodes.indexOf(p));
  3017. p.check = false;
  3018. }
  3019. }
  3020. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3021. });
  3022. } else {
  3023. node.check = true;
  3024. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3025. }
  3026. } else {
  3027. node.check = false;
  3028. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3029. }
  3030. }
  3031. });
  3032. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3033. for (const node of self.gsTree.datas) {
  3034. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3035. }
  3036. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  3037. self.gsTree.expandByLevel(4);
  3038. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  3039. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  3040. } else {
  3041. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3042. for (const node of self.gsTree.datas) {
  3043. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3044. }
  3045. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  3046. }
  3047. });
  3048. // 提交 高级设置
  3049. $('#choose2-ok').click(() => {
  3050. if (!self.gsTree) { return; }
  3051. const nodes = [];
  3052. for (const node of self.gsTree.datas) {
  3053. if (node.check) {
  3054. nodes.push(node.id);
  3055. }
  3056. }
  3057. const data = {
  3058. im_gather: $('#im-gather-check')[0].checked,
  3059. im_gather_node: nodes.join(','),
  3060. };
  3061. postData(window.location.pathname + '/detail/adv', data, function (result) {
  3062. stage.im_gather = data.im_gather;
  3063. stage.im_gather_node = data.im_gather_node;
  3064. $('#choose2').modal('hide');
  3065. });
  3066. });
  3067. }
  3068. _initLocateRela() {
  3069. const self = this;
  3070. $('#im-locate2bills').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. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  3075. stagePosSpreadObj.loadCurPosData();
  3076. }
  3077. });
  3078. $('#im-locate-pre').click(function () {
  3079. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3080. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3081. if (select && select.source) {
  3082. const targetIndex = Math.max(curIndex-1, 1);
  3083. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3084. stagePosSpreadObj.loadCurPosData();
  3085. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3086. }
  3087. });
  3088. $('#im-locate-next').click(function () {
  3089. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3090. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3091. if (select && select.source) {
  3092. const targetIndex = Math.min(curIndex+1, select.source.length);
  3093. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3094. stagePosSpreadObj.loadCurPosData();
  3095. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3096. }
  3097. });
  3098. }
  3099. _initModifyDetail() {
  3100. const self = this;
  3101. // 重置
  3102. $('#reset-detail-ok').click(function () {
  3103. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3104. if (!data.uuid) return;
  3105. const updateData = {
  3106. lid: data.lid, pid: data.pid,
  3107. uuid: data.uuid,
  3108. custom_define: [],
  3109. };
  3110. for (const f of data.custom_define) {
  3111. if (stageIm.resetFields.indexOf(f) >= 0) {
  3112. updateData[f] = null;
  3113. } else {
  3114. updateData.custom_define.push(f);
  3115. }
  3116. }
  3117. updateData.custom_define = updateData.custom_define.join(',');
  3118. $('#reset-detail-modal').modal('hide');
  3119. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3120. stageIm.loadUpdateDetailData(result);
  3121. self.reLoadDetailData();
  3122. });
  3123. });
  3124. // 编辑
  3125. $('#edit-detail').click(function () {
  3126. $(this).hide();
  3127. $('#save-detail').show();
  3128. $('#cancel-detail').show();
  3129. $('#detail-show').hide();
  3130. $('#detail-edit').show();
  3131. self.updateImageData = null;
  3132. });
  3133. // 保存
  3134. $('#save-detail').click(() => {
  3135. function check(field, obj, org, update) {
  3136. const newValue = obj.val();
  3137. if (!org[field]) {
  3138. if (newValue !== '') {
  3139. update[field] = newValue;
  3140. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3141. return true;
  3142. }
  3143. } else if (newValue !== org[field]){
  3144. update[field] = newValue;
  3145. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3146. return true;
  3147. }
  3148. return false;
  3149. }
  3150. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3151. const updateData = {lid: data.lid, pid: data.pid};
  3152. if (data.uuid) {
  3153. updateData.uuid = data.uuid;
  3154. updateData.custom_define = data.custom_define;
  3155. } else {
  3156. updateData.code = data.code;
  3157. updateData.name = data.name;
  3158. updateData.unit = data.unit;
  3159. updateData.unit_price = data.unit_price;
  3160. updateData.pid = data.pid;
  3161. updateData.pos_name = data.pos_name;
  3162. updateData.im_type = data.im_type;
  3163. updateData.custom_define = [];
  3164. }
  3165. let infoUpdate = false;
  3166. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  3167. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  3168. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  3169. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  3170. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  3171. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  3172. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  3173. updateData.custom_define = updateData.custom_define.join(',');
  3174. if (infoUpdate) {
  3175. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3176. stageIm.loadUpdateDetailData(result);
  3177. self.reLoadDetailData();
  3178. if (!self.updateImageData) return;
  3179. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  3180. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3181. stageIm.loadUpdateDetailData(result);
  3182. self.reLoadDetailData();
  3183. });
  3184. });
  3185. } else if (self.updateImageData) {
  3186. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3187. stageIm.loadUpdateDetailData(result);
  3188. self.reLoadDetailData();
  3189. });
  3190. } else {
  3191. self.reLoadDetailData();
  3192. }
  3193. });
  3194. // 取消
  3195. $('#cancel-detail').click(() => {
  3196. self.reLoadDetailData();
  3197. });
  3198. }
  3199. _initImageRela() {
  3200. const self = this;
  3201. $('#edit-detail').click(function () {
  3202. loadImageItem();
  3203. });
  3204. function setdraggrable(){
  3205. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3206. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3207. stop: function( event, ui ) {
  3208. }
  3209. });
  3210. }
  3211. function upload(formData) {
  3212. if (formData.length < 1) {
  3213. return;
  3214. }
  3215. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3216. const html = [];
  3217. html.push('<div class="img-item">');
  3218. html.push('<div class="img-bar">');
  3219. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3220. html.push('</div>');
  3221. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3222. html.push('</div>');
  3223. $('.img-view').append(html.join(''));
  3224. $('.img-bar').click(removeImageItem);
  3225. setdraggrable();
  3226. $('#upload-img-file').val('');
  3227. });
  3228. }
  3229. function dragFile(e) {
  3230. var file = null,
  3231. data = e.dataTransfer.types;
  3232. for (var i = 0; i < data.length; i += 1) {
  3233. if (data[i] === 'Files') {
  3234. file = e.dataTransfer.files; //获取文件
  3235. break;
  3236. }
  3237. }
  3238. if (file && file[0].type.indexOf('image') !== -1) {
  3239. var formData = new FormData();
  3240. formData.append('file', file[0]); //上传单个文件的添加方式
  3241. upload(formData); //upload 异步上传
  3242. }
  3243. }
  3244. // 移动图片
  3245. const moveImageItem = function (ev) {
  3246. const item = this;
  3247. const view = $('.img-view')[0];
  3248. let oEvent = ev;
  3249. // 浏览器有一些图片的默认事件,这里要阻止
  3250. oEvent.preventDefault();
  3251. let disX = oEvent.clientX - item.offsetLeft;
  3252. let disY = oEvent.clientY - item.offsetTop;
  3253. view.onmousemove = function (ev) {
  3254. oEvent = ev;
  3255. oEvent.preventDefault();
  3256. let x = oEvent.clientX -disX;
  3257. let y = oEvent.clientY -disY;
  3258. // 图形移动的边界判断
  3259. x = x <= 0 ? 0 : x;
  3260. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  3261. y = y <= 0 ? 0 : y;
  3262. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  3263. item.style.left = x + 'px';
  3264. item.style.top = y + 'px';
  3265. };
  3266. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  3267. view.onmouseleave = function () {
  3268. view.onmousemove = null;
  3269. view.onmouseup = null;
  3270. };
  3271. // 鼠标弹起后停止移动
  3272. view.onmouseup=function() {
  3273. view.onmousemove = null;
  3274. view.onmouseup = null;
  3275. };
  3276. };
  3277. const removeImageItem = function () {
  3278. $(this).parent().remove();
  3279. };
  3280. // 加载草图组成
  3281. const loadImageItem = function () {
  3282. self.updateImageData = null;
  3283. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3284. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3285. const html = [];
  3286. for (const item of items) {
  3287. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3288. html.push('<div class="img-item" style="' + itemStyle + '">');
  3289. html.push('<div class="img-bar">');
  3290. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3291. html.push('</div>');
  3292. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3293. html.push('</div>');
  3294. }
  3295. $('.img-view').html(html.join(''));
  3296. $('.img-bar').click(removeImageItem);
  3297. setdraggrable();
  3298. };
  3299. // 上传图片
  3300. $('#upload-img').click(function () {
  3301. $('#upload-img-file').trigger('click');
  3302. });
  3303. // 拖拽上传
  3304. //拖拽上传文件
  3305. const dragbox = document.querySelector('#upload-img');
  3306. dragbox.addEventListener('dragover', function(e) {
  3307. e.preventDefault(); // 必须阻止默认事件
  3308. }, false);
  3309. dragbox.addEventListener('drop', function(e) {
  3310. e.preventDefault(); // 阻止默认事件
  3311. dragFile(e);
  3312. }, false);
  3313. //拖拽上传文件
  3314. const dragbox2 = document.querySelector('.img-view');
  3315. dragbox2.addEventListener('dragover', function(e) {
  3316. e.preventDefault(); // 必须阻止默认事件
  3317. }, false);
  3318. dragbox2.addEventListener('drop', function(e) {
  3319. e.preventDefault(); // 阻止默认事件
  3320. dragFile(e);
  3321. }, false);
  3322. // 粘贴上传
  3323. $(".img-view").on('paste', function(ev) {
  3324. let file = null;
  3325. const data = (event.clipboardData || window.clipboardData).items;
  3326. for (let i = 0; i < data.length; i += 1) {
  3327. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3328. file = data[i].getAsFile(); //读取图片文件
  3329. break;
  3330. }
  3331. }
  3332. if (file) {
  3333. const formData = new FormData();
  3334. formData.append('file', file); //上传单个文件的添加方式
  3335. upload(formData); //异步上传文件
  3336. }
  3337. });
  3338. $('#upload-img-file').change(function () {
  3339. const file = this.files[0];
  3340. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  3341. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  3342. if (!imgStr.test(ext)) {
  3343. toastr.error('请上传正确的图片格式文件');
  3344. return
  3345. }
  3346. if ($(this).val()) {
  3347. const formData = new FormData();
  3348. formData.append('file', this.files[0]);
  3349. upload(formData);
  3350. }
  3351. });
  3352. // 保存草图修改结果
  3353. $('#edit-img-ok').click(function () {
  3354. // 记录上传的图片的信息
  3355. const items = $('.img-item');
  3356. const img_remark = $('#text-edit').val();
  3357. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3358. // 生成上传数据
  3359. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  3360. if (data.uuid) {
  3361. updateData.uuid = data.uuid;
  3362. } else {
  3363. updateData.code = data.code;
  3364. updateData.name = data.name;
  3365. updateData.unit = data.unit;
  3366. updateData.unit_price = data.unit_price;
  3367. updateData.pid = data.pid;
  3368. updateData.pos_name = data.pos_name;
  3369. updateData.im_type = data.im_type;
  3370. }
  3371. if (items.length > 0) {
  3372. const itemInfo = [];
  3373. for (const item of items) {
  3374. const itemData = {
  3375. src: $('img', item).attr('src'),
  3376. left: item.style.left,
  3377. top: item.style.top,
  3378. width: item.style.width,
  3379. height: item.style.height,
  3380. };
  3381. itemInfo.push(itemData);
  3382. }
  3383. // 获取合并好的图片数据
  3384. const canvas = document.createElement('canvas');
  3385. const view = $('.img-view')[0];
  3386. canvas.height = view.clientHeight;
  3387. canvas.width = view.clientWidth;
  3388. const ctx = canvas.getContext('2d');
  3389. ctx.fillStyle = '#ffffff';
  3390. ctx.fillRect(0, 0, canvas.width, canvas.height);
  3391. for (const b of $('.img-item')) {
  3392. const pos = $(b).position();
  3393. const img = $('img', b)[0];
  3394. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  3395. }
  3396. updateData.img = canvas.toDataURL('image/png');
  3397. updateData.imgInfo = itemInfo;
  3398. self.updateImageData = updateData;
  3399. $('#calc-img').attr('src', updateData.img);
  3400. $('#calc-remark').html(img_remark);
  3401. $('#view-calc-img').attr('src', updateData.img);
  3402. $('#show-calc-img').attr('src', updateData.img);
  3403. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  3404. $('#view-calc-remark').text(img_remark);
  3405. $('#edit-img').modal('hide');
  3406. // });
  3407. } else if (data.calc_img) {
  3408. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  3409. $('#show-calc-img').attr('src', '');
  3410. $('#show-calc-remark').html('');
  3411. $('#calc-img').attr('src', '');
  3412. $('#calc-remark').html(img_remark);
  3413. $('#view-calc-img').attr('src', '');
  3414. $('#view-calc-remark').val(img_remark);
  3415. $('#text-edit').val(img_remark);
  3416. $('#edit-img').modal('hide');
  3417. } else {
  3418. self.updateImageData = updateData;
  3419. $('#show-calc-img').attr('src', '');
  3420. $('#show-calc-remark').html('');
  3421. $('#calc-img').attr('src', '');
  3422. $('#calc-remark').html(img_remark);
  3423. $('#view-calc-img').attr('src', '');
  3424. $('#view-calc-remark').val(img_remark);
  3425. $('#text-edit').val(img_remark);
  3426. $('#edit-img').modal('hide');
  3427. }
  3428. });
  3429. }
  3430. reBuildImData() {
  3431. const imData = stageIm.buildImData();
  3432. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3433. this.reLoadDetailData();
  3434. this.loadLocateInfo();
  3435. }
  3436. loadStageLedgerUpdateData(data, nodes) {
  3437. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  3438. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3439. this.reLoadDetailData();
  3440. }
  3441. loadStagePosUpdateData(data, nodes) {
  3442. const imData = stageIm.loadUpdatePosData(data, nodes);
  3443. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3444. this.reLoadDetailData();
  3445. }
  3446. loadStageChangeUpdateData(data, nodes) {
  3447. const imData = stageIm.loadUpdateChangeData(data, nodes);
  3448. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3449. this.reLoadDetailData();
  3450. }
  3451. loadLocateInfo() {
  3452. const select = SpreadJsObj.getSelectObject(this.sheet);
  3453. if (select && select.source.length > 1) {
  3454. $('#im-locate2bills').next().show();
  3455. } else {
  3456. $('#im-locate2bills').next().hide();
  3457. }
  3458. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  3459. }
  3460. reLoadDetailData() {
  3461. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  3462. $('#reset-detail').hide();
  3463. if (data) {
  3464. for (const f of data.custom_define) {
  3465. if (stageIm.resetFields.indexOf(f) >= 0) {
  3466. $('#reset-detail').show();
  3467. break;
  3468. }
  3469. }
  3470. $('#edit-detail').show();
  3471. $('#modify-img').show();
  3472. } else {
  3473. $('#edit-detail').hide();
  3474. $('#modify-img').hide();
  3475. }
  3476. $('#save-detail').hide();
  3477. $('#cancel-detail').hide();
  3478. $('#detail-show').show();
  3479. $('#detail-edit').hide();
  3480. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  3481. $('#show-contract-jl').text(contractJl);
  3482. $('#contract-jl').val(contractJl);
  3483. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  3484. $('#show-qc-jl').text(qcJl);
  3485. $('#qc-jl').val(qcJl);
  3486. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  3487. $('#show-bgl-code').text(bglCode);
  3488. $('#bgl-code').val(bglCode);
  3489. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  3490. $('#show-bgl-drawing-code').text(bglDrawingCode);
  3491. $('#bgl-drawing-code').val(bglDrawingCode);
  3492. const bwName = data && data.bw ? data.bw : '';
  3493. $('#show-bw-name').text(bwName);
  3494. $('#bw-name').val(bwName);
  3495. const position = data && data.position ? data.position : '';
  3496. $('#show-position').text(position);
  3497. $('#position').val(position);
  3498. const peg = data && data.peg ? data.peg : '';
  3499. $('#show-peg').text(peg);
  3500. $('#peg').val(peg);
  3501. const xmName = data && data.xm ? data.xm: '';
  3502. $('#show-xm-name').text(xmName);
  3503. $('#xm-name').val(xmName);
  3504. const jldy = data && data.jldy ? data.jldy: '';
  3505. $('#show-jldy').text(jldy);
  3506. $('#jldy').val(jldy);
  3507. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  3508. $('#show-drawing-code').text(drawingCode);
  3509. $('#drawing-code').val(drawingCode);
  3510. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  3511. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  3512. $('#calc-memo').val(calcMemo);
  3513. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3514. $('#show-calc-img').attr('src', calcImgSrc);
  3515. $('#calc-img').attr('src', calcImgSrc);
  3516. $('#view-calc-img').attr('src', calcImgSrc);
  3517. const calcImgRemark = data && data.calc_img_remark || '';
  3518. $('#view-calc-remark').val(calcImgRemark);
  3519. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  3520. $('#calc-remark').html(calcImgRemark);
  3521. $("#view-calc-remark").attr('readonly', true);
  3522. // 处理 编辑 -> 添加草图中textarea多余的空格
  3523. $('#text-edit').val(calcImgRemark)
  3524. }
  3525. }
  3526. class CheckedChange {
  3527. constructor (setting) {
  3528. const self = this;
  3529. this.changeSpreadSetting = {
  3530. cols: [
  3531. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: function (x) { return x.t_name ? `所属标段:${x.t_name}` : ''; }},
  3532. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  3533. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3534. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  3535. ],
  3536. emptyRows: 0,
  3537. headRows: 1,
  3538. headRowHeight: [32],
  3539. headColWidth: [30],
  3540. defaultRowHeight: 21,
  3541. headerFont: '12px 微软雅黑',
  3542. font: '12px 微软雅黑',
  3543. readOnly: true,
  3544. getColor: function (sheet, data, row, col, defaultColor) {
  3545. if (data && data.is_import) {
  3546. return '#eee';
  3547. } else {
  3548. return defaultColor;
  3549. }
  3550. }
  3551. };
  3552. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  3553. this.changeSheet = this.changeSpread.getActiveSheet();
  3554. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  3555. const getTipText = function (data) {
  3556. if (!data) return '';
  3557. const tips = [];
  3558. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  3559. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  3560. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  3561. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  3562. return tips.join('-');
  3563. };
  3564. this.changeBillsSpreadSetting = {
  3565. cols: [
  3566. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', cellType: 'tip', getTip: getTipText},
  3567. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number', cellType: 'tip', getTip: getTipText},
  3568. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'tip', getTip: getTipText},
  3569. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', cellType: 'tip', getTip: getTipText},
  3570. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3571. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3572. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: getTipText},
  3573. ],
  3574. emptyRows: 0,
  3575. headRows: 1,
  3576. headRowHeight: [32],
  3577. defaultRowHeight: 21,
  3578. headerFont: '12px 微软雅黑',
  3579. font: '12px 微软雅黑',
  3580. readOnly: true
  3581. };
  3582. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  3583. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  3584. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  3585. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  3586. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3587. if (change.cid === self.curChangeId) { return; }
  3588. self.curChangeId = change.cid;
  3589. if (change.detail) {
  3590. self.loadChangeDetailData();
  3591. } else {
  3592. postData(window.location.pathname + '/change/detail', {cid: change.cid, is_import: change.is_import}, function (result) {
  3593. change.detail = result;
  3594. self.analyzeChange(change);
  3595. self.loadChangeDetailData();
  3596. });
  3597. }
  3598. });
  3599. this.changes = null;
  3600. this.reloadChangeData();
  3601. setting.reloadObj.click(function() {
  3602. self.reloadChangeData();
  3603. });
  3604. $.contextMenu({
  3605. selector: '#' + setting.changeBillsObj.attr('id'),
  3606. build: function ($trigger, e) {
  3607. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  3608. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3609. },
  3610. items: {
  3611. 'locateZjjl': {
  3612. name: '定位至台账',
  3613. icon: 'fa-sign-in',
  3614. callback: function (key, opt) {
  3615. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3616. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3617. if (change.is_import) {
  3618. if (changeBills.pos && changeBills.pos.length > 0) {
  3619. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), changeBills.pos[0].ledger_id, true);
  3620. stagePosSpreadObj.loadCurPosData();
  3621. }
  3622. } else 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 = [];
  3673. result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
  3674. result.import_changes.forEach(x => { x.is_import = 1; self.changes.push(x); });
  3675. if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
  3676. if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
  3677. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  3678. self.changeSheet.setSelection(0, 0, 1, 1);
  3679. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  3680. self.loadChangeDetailData();
  3681. });
  3682. }
  3683. _analyzeCommon(change) {
  3684. for (const b of change.bills) {
  3685. const eub = change.detail.endUsedBills.find(function (x) {
  3686. return x.cbid === b.id;
  3687. });
  3688. if (eub) b.used_qty = eub.qty;
  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. _analyzeImport(change) {
  3701. for (const b of change.bills) {
  3702. const eub = change.detail.endUsedBills.find(function (x) {
  3703. return x.rela_cbid === b.id;
  3704. });
  3705. if (eub) b.used_qty = eub.rela_qty;
  3706. b.qty = _.toNumber(b.samount);
  3707. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  3708. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3709. b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
  3710. b.cur_qty = 0;
  3711. for (const p of b.pos) {
  3712. b.qty = b.rela_qty;
  3713. const node = stageTree.datas.find(x => { return x.id === p.lid; });
  3714. p.ledger_id = node.ledger_id;
  3715. p.f_qty = node.quantity;
  3716. b.cur_qty = ZhCalc.add(b.cur_qty, p.rela_qty);
  3717. }
  3718. }
  3719. }
  3720. analyzeChange(change) {
  3721. change.bills = change.detail.bills;
  3722. if (change.is_import) {
  3723. this._analyzeImport(change);
  3724. } else {
  3725. this._analyzeCommon(change);
  3726. }
  3727. }
  3728. }
  3729. // 展开收起附件
  3730. $('a', '.right-nav').bind('click', function () {
  3731. //const main = $('#main-view'), tool = $('#tools-view');
  3732. const tab = $(this), tabPanel = $(tab.attr('content'));
  3733. if (!tab.hasClass('active')) {
  3734. $('a', '.side-menu').removeClass('active');
  3735. $('.tab-content .tab-select-show').removeClass('active');
  3736. tab.addClass('active');
  3737. tabPanel.addClass('active');
  3738. showSideTools(tab.hasClass('active'));
  3739. if (tab.attr('content') === '#search' && !searchLedger) {
  3740. searchLedger = $.billsSearch({
  3741. selector: '#search',
  3742. searchSpread: slSpread,
  3743. searchOver: true,
  3744. searchEmpty: true,
  3745. resultSpreadSetting: {
  3746. cols: [
  3747. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3748. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3749. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3750. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3751. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3752. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3753. {title: '完成率(%)', field: 'end_gather_percent', hAlign: 2, width: 70},
  3754. ],
  3755. emptyRows: 0,
  3756. headRows: 1,
  3757. headRowHeight: [32],
  3758. headColWidth: [30],
  3759. defaultRowHeight: 21,
  3760. headerFont: '12px 微软雅黑',
  3761. font: '12px 微软雅黑',
  3762. selectedBackColor: '#fffacd',
  3763. },
  3764. afterLocated: function () {
  3765. stagePosSpreadObj.loadCurPosData();
  3766. },
  3767. customSearch: [
  3768. {
  3769. key: 'less', title: '漏计', valid: true,
  3770. check: function (node) {
  3771. if (node.quantity) {
  3772. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  3773. } else if (node.total_price) {
  3774. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  3775. }
  3776. }
  3777. }, {
  3778. key: 'over', title: '超计', valid: true,
  3779. check: function (node) {
  3780. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  3781. }
  3782. }, {
  3783. key: 'empty', title: '漏计', valid: false,
  3784. check: function (node) {
  3785. if (node.quantity) {
  3786. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  3787. } else if (node.total_price) {
  3788. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  3789. }
  3790. }
  3791. }, {
  3792. key: 'estimate', title: '预计变更', valid: true,
  3793. check: function (node) {
  3794. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  3795. if (posRange.length > 0) {
  3796. for (const p of posRange) {
  3797. if (!checkZero(p.estimate_qty)) return true;
  3798. }
  3799. return false;
  3800. } else {
  3801. return false;
  3802. }
  3803. }
  3804. }
  3805. ],
  3806. });
  3807. searchLedger.spread.refresh();
  3808. }
  3809. if (tab.attr('content') === '#fujian') {
  3810. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3811. node && getNodeList(node.id);
  3812. }
  3813. if (tab.attr('content') === '#zhongjian') {
  3814. if (!detail) {
  3815. detail = new Detail($('#detail-spread'));
  3816. detail.spread.refresh();
  3817. $('#zhongjian .sjs-bottom').height('400px');
  3818. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3819. } else {
  3820. detail.spread.refresh();
  3821. }
  3822. }
  3823. if (tab.attr('content') === '#checked-change') {
  3824. if (!checkedChanges) {
  3825. checkedChanges = new CheckedChange({
  3826. changeObj: $('#cc-spread'),
  3827. changeBillsObj: $('#ccb-spread'),
  3828. reloadObj: $('#refresh-cc'),
  3829. });
  3830. checkedChanges.refresh();
  3831. } else {
  3832. $('#ccb-spread').height('400px');
  3833. checkedChanges.refresh();
  3834. }
  3835. }
  3836. if (tab.attr('content') === '#error-list') {
  3837. errorList.spread.refresh();
  3838. }
  3839. if (tab.attr('content') === '#check-list') {
  3840. checkList.spread.refresh();
  3841. }
  3842. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  3843. } else {
  3844. tab.removeClass('active');
  3845. tabPanel.removeClass('active');
  3846. showSideTools(tab.hasClass('active'));
  3847. }
  3848. slSpread.refresh();
  3849. spSpread.refresh();
  3850. });
  3851. // 切换附件里节点和所有附件
  3852. $('#fujian .nav-link').on('click', function () {
  3853. const tabPanel = $(this).attr('fujian-content');
  3854. if (tabPanel !== 'syfujian') {
  3855. $('#showPage').hide();
  3856. $('#bach-download').prop('type', 'curr');
  3857. } else {
  3858. $('#showPage').show();
  3859. $('#bach-download').prop('type', 'all')
  3860. }
  3861. $('#showAttachment').hide();
  3862. });
  3863. // 上传附件
  3864. $('#upload-file-btn').click(function () {
  3865. // if (curAuditor && curAuditor.aid !== cur_uid) {
  3866. // return toastr.error('当前操作没有权限!');
  3867. // }
  3868. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3869. if (!node) return
  3870. const files = $('#upload-file')[0].files;
  3871. const formData = new FormData();
  3872. formData.append('lid', node.id);
  3873. for (const file of files) {
  3874. if (file === undefined) {
  3875. toastr.error('未选择上传文件!');
  3876. return false;
  3877. }
  3878. const filesize = file.size;
  3879. if (filesize > 30 * 1024 * 1024) {
  3880. toastr.error('存在上传文件大小过大!');
  3881. return false;
  3882. }
  3883. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3884. if (whiteList.indexOf(fileext) === -1) {
  3885. toastr.error('只能上传指定格式的附件!');
  3886. return false;
  3887. }
  3888. formData.append('size', filesize);
  3889. formData.append('file[]', file);
  3890. }
  3891. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  3892. $('#upload').modal('hide');
  3893. // 插入到attData中
  3894. attData = data.concat(attData);
  3895. // 重新生成List
  3896. getAllList();
  3897. getNodeList(node.id);
  3898. }, function () {
  3899. toastr.error('附件上传失败');
  3900. });
  3901. $('#upload-file').val('');
  3902. });
  3903. // 获取附件信息
  3904. $('.list-table').on('click', '.att-file-name', function () {
  3905. const fid = $(this).attr('file-id');
  3906. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3907. return;
  3908. }
  3909. const att = attData.find(function (item) {
  3910. return item.id === parseInt(fid);
  3911. });
  3912. $('#edit-att').hide();
  3913. $('#show-att').show();
  3914. if (att !== undefined) {
  3915. // 进来先把编辑功能隐藏
  3916. $('#btn-att a').eq(3).hide()
  3917. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3918. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3919. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3920. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3921. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3922. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3923. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3924. $('#show-att tr').eq(3).children('td').text(att.remark);
  3925. // 附件uid等于当前用户id, 附件上传本人
  3926. if (parseInt(cur_uid) === att.uid) {
  3927. $('#btn-att').show();
  3928. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  3929. // if (!curAuditor) {
  3930. // stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  3931. // stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3932. // stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3933. // } else {
  3934. // curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  3935. // }
  3936. if (showDel) $('#btn-att a').eq(3).show();
  3937. // $('#btn-att a').eq(3).show();
  3938. $('#btn-att a').eq(2).hide();
  3939. $('#btn-att a').eq(4).hide();
  3940. $('#btn-att a').eq(5).hide();
  3941. } else {
  3942. $('#btn-att').hide();
  3943. $('#btn-att a').eq(3).hide();
  3944. $('#btn-att a').eq(2).hide();
  3945. $('#btn-att a').eq(4).hide();
  3946. $('#btn-att a').eq(5).hide();
  3947. }
  3948. $('#showAttachment').attr('file-id', fid);
  3949. $('#showAttachment').show();
  3950. } else {
  3951. $('#showAttachment').hide();
  3952. $('#showAttachment').attr('file-id', '');
  3953. toastr.error('附件信息获取失败');
  3954. }
  3955. });
  3956. // $('body').on('click', '.alllist-table a', handleFileList);
  3957. $('body').on('click', '#btn-att a', function () {
  3958. const content = $(this).attr('content');
  3959. const fid = $('#showAttachment').attr('file-id');
  3960. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3961. if (content === 'edit') {
  3962. $('#btn-att a').eq(3).hide();
  3963. $('#btn-att a').eq(2).show();
  3964. $('#btn-att a').eq(4).show();
  3965. $('#btn-att a').eq(5).show();
  3966. $('#show-att').hide();
  3967. $('#edit-att').show();
  3968. const att = attData.find(function (item) {
  3969. return item.id === parseInt(fid);
  3970. });
  3971. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3972. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3973. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3974. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3975. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3976. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3977. } else if (content === 'cancel') {
  3978. $('#show-att').show();
  3979. $('#edit-att').hide();
  3980. $('#btn-att a').eq(3).show();
  3981. $('#btn-att a').eq(2).hide();
  3982. $('#btn-att a').eq(4).hide();
  3983. $('#btn-att a').eq(5).hide();
  3984. } else if (content === 'save') {
  3985. const formData = new FormData();
  3986. formData.append('id', fid);
  3987. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3988. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3989. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3990. const file = $('#change-att-btn')[0];
  3991. if (file.files[0] !== undefined) {
  3992. const filesize = file.files[0].size;
  3993. formData.append('size', filesize);
  3994. formData.append('file', file.files[0]);
  3995. }
  3996. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3997. // 替换到attData中
  3998. const att_index = attData.findIndex(function (item) {
  3999. return item.id === parseInt(fid);
  4000. });
  4001. attData.splice(att_index, 1, data);
  4002. // 重新生成List
  4003. getAllList(parseInt($('#currentPage').text()));
  4004. getNodeList(node.id);
  4005. $('#show-att').show();
  4006. $('#edit-att').hide();
  4007. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4008. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4009. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4010. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  4011. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  4012. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  4013. $('#show-att tr').eq(4).children('td').text(data.remark);
  4014. $('#btn-att a').eq(3).show();
  4015. $('#btn-att a').eq(2).hide();
  4016. $('#btn-att a').eq(4).hide();
  4017. $('#btn-att a').eq(5).hide();
  4018. }, function () {
  4019. toastr.error('附件上传失败');
  4020. });
  4021. $('#change-att-btn').val('');
  4022. } else if (content === 'del') {
  4023. const data = {id: fid};
  4024. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  4025. // 删除到attData中
  4026. const att_index = attData.findIndex(function (item) {
  4027. return item.id === parseInt(fid);
  4028. });
  4029. attData.splice(att_index, 1);
  4030. // 重新生成List
  4031. if ($('#alllist-table tr').length === 1) {
  4032. getAllList(parseInt($('#currentPage').text()) - 1);
  4033. } else {
  4034. getAllList(parseInt($('#currentPage').text()));
  4035. }
  4036. getNodeList(node.id);
  4037. $('#showAttachment').hide();
  4038. $('#showAttachment').attr('file-id', '');
  4039. });
  4040. } else if (content === 'view') {
  4041. const data = {id: fid};
  4042. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  4043. const { filepath } = result
  4044. $('#load-file').attr('href', filepath);
  4045. $('#load-file')[0].click();
  4046. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  4047. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  4048. });
  4049. } else if (content === 'location') {
  4050. const att = attData.find(item => item.id === parseInt(fid));
  4051. if (Object.keys(att).length) {
  4052. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  4053. stagePosSpreadObj.loadCurPosData();
  4054. }
  4055. }
  4056. });
  4057. // 替换附件
  4058. $('#change-att-btn').on('change', function () {
  4059. const file = $('#change-att-btn')[0].files[0];
  4060. const name = file.name;
  4061. const filename = name.substring(0, name.lastIndexOf("."));
  4062. const fileext = name.substr(name.indexOf("."));
  4063. const filesize = file.size;
  4064. if (filesize > 30 * 1024 * 1024) {
  4065. toastr.error('文件大小过大!');
  4066. $('#change-att-btn').val('');
  4067. return false;
  4068. }
  4069. if (whiteList.indexOf(fileext) === -1) {
  4070. toastr.error('只能上传指定格式的附件!');
  4071. $('#change-att-btn').val('');
  4072. return false;
  4073. }
  4074. $('#edit-att .form-group').eq(0).find('input').val(filename);
  4075. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  4076. });
  4077. // 切换页数
  4078. $('.page-select').on('click', function () {
  4079. const totalPageNum = parseInt($('#totalPage').text());
  4080. const lastPageNum = parseInt($('#currentPage').text());
  4081. const status = $(this).attr('content');
  4082. if (status === 'pre' && lastPageNum > 1) {
  4083. getAllList(lastPageNum-1);
  4084. $('#showAttachment').hide();
  4085. $('#syfujian .check-all-file').prop('checked', false)
  4086. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4087. getAllList(lastPageNum+1);
  4088. $('#showAttachment').hide();
  4089. $('#syfujian .check-all-file').prop('checked', false)
  4090. }
  4091. });
  4092. // 批量下载
  4093. $('#bach-download').click(function() {
  4094. const fileIds = [];
  4095. const type = $(this).attr('type');
  4096. let node = ''
  4097. if (type === 'curr') {
  4098. node = '#nodelist-table .check-file:checked'
  4099. } else {
  4100. node = '#alllist-table .check-file:checked'
  4101. }
  4102. $(node).each(function() {
  4103. const fileId = $(this).attr('file-id');
  4104. fileId && fileIds.push(fileId);
  4105. });
  4106. if (fileIds.length) {
  4107. if (fileIds.length > 20) {
  4108. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  4109. }
  4110. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  4111. $(this).attr('disabled', "true")
  4112. const btn = $(this);
  4113. const fileArr = [];
  4114. for (const id of fileIds) {
  4115. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  4116. fileArr.push({
  4117. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  4118. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  4119. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  4120. });
  4121. }
  4122. const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
  4123. try {
  4124. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  4125. } catch (e) {
  4126. btn.removeAttr('disabled');
  4127. toastr.clear();
  4128. toastr.error('批量下载失败');
  4129. }
  4130. // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  4131. // toastr.clear()
  4132. // toastr.success('压缩文件成功')
  4133. // btn.removeAttr('disabled')
  4134. // const href = window.URL.createObjectURL(result)
  4135. // $('#zipDown').attr('href', href);
  4136. // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  4137. // $("#zipDown")[0].click();
  4138. // }, () => {
  4139. // btn.removeAttr('disabled')
  4140. // toastr.clear()
  4141. // toastr.error('批量下载失败')
  4142. // });
  4143. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  4144. // $('#zipDown').attr('href', url);
  4145. // $("#zipDown")[0].click();
  4146. }
  4147. });
  4148. // 监听附件check是否选中
  4149. $('.list-table').on('click', '.check-file', function() {
  4150. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  4151. const childs = $(this).parents('.list-table').children().length;
  4152. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  4153. if (checkedList.length === childs) {
  4154. checkBox.prop("checked", true);
  4155. } else {
  4156. checkBox.prop("checked", false);
  4157. }
  4158. });
  4159. $('.check-all-file').click(function() {
  4160. const isCheck = $(this).is(':checked');
  4161. $(this).parents('table').find('.list-table').each(function() {
  4162. $(this).find('input:checkbox').prop("checked", isCheck);
  4163. })
  4164. });
  4165. // 显示层次
  4166. (function (select, sheet) {
  4167. $(select).click(function () {
  4168. if (!sheet.zh_tree) return;
  4169. const tag = $(this).attr('tag');
  4170. const tree = sheet.zh_tree;
  4171. setTimeout(() => {
  4172. showWaitingView();
  4173. switch (tag) {
  4174. case "1":
  4175. case "2":
  4176. case "3":
  4177. case "4":
  4178. case "5":
  4179. tree.expandByLevel(parseInt(tag));
  4180. SpreadJsObj.refreshTreeRowVisible(sheet);
  4181. break;
  4182. case "last":
  4183. tree.expandByCustom(() => { return true; });
  4184. SpreadJsObj.refreshTreeRowVisible(sheet);
  4185. break;
  4186. case "leafXmj":
  4187. tree.expandToLeafXmj();
  4188. SpreadJsObj.refreshTreeRowVisible(sheet);
  4189. break;
  4190. case "curMeasure":
  4191. tree.expandByCustom(function (node) {
  4192. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  4193. if (node[field]) {
  4194. return true;
  4195. }
  4196. }
  4197. return false;
  4198. });
  4199. SpreadJsObj.refreshTreeRowVisible(sheet);
  4200. break;
  4201. }
  4202. closeWaitingView();
  4203. }, 100);
  4204. });
  4205. })('a[name=showLevel]', slSpread.getActiveSheet());
  4206. const stageCheckerSetting = {
  4207. ledgerTree: stageTree,
  4208. ledgerPos: stagePos,
  4209. checkList: checkList,
  4210. decimal: tenderInfo.decimal,
  4211. checkOption: checkOption,
  4212. };
  4213. if (!checkTzMeasureType()) {
  4214. stageCheckerSetting.checkOption.tp.fields.push(
  4215. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  4216. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  4217. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  4218. {qty: 'quantity', tp: 'total_price'},
  4219. );
  4220. }
  4221. $('#ledger-check2').click(() => {
  4222. const result = ledgerCheck2(stageCheckerSetting);
  4223. check2Viewing({
  4224. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  4225. randomWait: true,
  4226. prefix: 'check2-',
  4227. checks: result,
  4228. checkList: checkList,
  4229. })
  4230. });
  4231. const dataChecker = DataChecker({
  4232. checkUrl: window.location.pathname + '/check',
  4233. completeData: function (data) {
  4234. stagePos.updateDatas({pos: data.source.pos});
  4235. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  4236. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  4237. stagePosSpreadObj.loadCurPosData();
  4238. for (const e of data.error) {
  4239. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  4240. }
  4241. },
  4242. errorList: errorList,
  4243. });
  4244. $('[name=stage-start]').submit(function (e) {
  4245. if (checkAuditorFrom()) {
  4246. // 再检查多人协同确认情况
  4247. const list = stageTree.pwd.find(x => {return !x.confirm });
  4248. if(list) {
  4249. toastr.error('请检查多人协同确认情况再上报');
  4250. $('#hide-all').hide();
  4251. return false;
  4252. }
  4253. $(this).parent().parent().parent().modal('hide');
  4254. dataChecker.checkAndPost(this.action, {});
  4255. $('#hide-all').hide();
  4256. }
  4257. return false;
  4258. });
  4259. $('#audit-check0').submit(function (e) {
  4260. // 再检查多人协同确认情况
  4261. const list = stageTree.pwd.find(x => {return !x.confirm });
  4262. if(list) {
  4263. toastr.error('请检查多人协同确认情况再审批通过');
  4264. $('#hide-all').hide();
  4265. return false;
  4266. }
  4267. const checkType = parseInt($('[name=checkType]').val());
  4268. const data = {
  4269. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4270. checkType,
  4271. };
  4272. $('#sp-done').modal('hide');
  4273. checkType && dataChecker.checkAndPost(this.action, data);
  4274. $('#hide-all').hide();
  4275. return false;
  4276. });
  4277. $('#audit-check1').submit(function (e) {
  4278. const checkType = parseInt($('[name=checkType]:checked').val());
  4279. const data = {
  4280. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4281. checkType,
  4282. };
  4283. if ($('#warning-text').length) $('#warning-text').remove()
  4284. if (!checkType && !$('#warning-text').length) {
  4285. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  4286. return false
  4287. }
  4288. $('#sp-back').modal('hide');
  4289. checkType && dataChecker.checkAndPost(this.action, data);
  4290. $('#hide-all').hide();
  4291. return false;
  4292. });
  4293. $('#exportExcel').click(function () {
  4294. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  4295. });
  4296. $('#cbr-check-all').click(function () {
  4297. if (this.checked) {
  4298. $('input', '#cbr-pos-list').attr('checked', 'checked');
  4299. } else {
  4300. $('input', '#cbr-pos-list').removeAttr('checked');
  4301. }
  4302. });
  4303. $('#cbr-ok').click(() => {
  4304. const ratio = parseInt($('#cbr-ratio').val());
  4305. if (!ratio) {
  4306. toastr.warning('请输入计量比例');
  4307. return;
  4308. } else if (ratio < 1) {
  4309. toastr.warning('计量比例不可小于1');
  4310. return;
  4311. } else if (ratio > 100) {
  4312. toastr.warning('计量比例不可大于100');
  4313. return;
  4314. }
  4315. const apply2sibling = $('#apply2sibling')[0].checked;
  4316. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  4317. if (posName.length === 0) {
  4318. toastr.warning('请勾选需要按计量比例的计量单元');
  4319. return;
  4320. }
  4321. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  4322. });
  4323. $('body').on('click', '[name=ledger-unlock]', function() {
  4324. $('#cooperation').modal('hide');
  4325. const lid = this.getAttribute('lid');
  4326. if (!lid) return;
  4327. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4328. if (!p) return;
  4329. $('#unlock-info').html(`${p.node.code} ${p.node.name} 解锁密码<b class="text-danger">*</b>`);
  4330. $('#unlock-pwd').val('').removeClass('is-invalid');
  4331. $('.invalid-feedback', '#unlock').hide();
  4332. $('.alert-warning', '#unlock').hide();
  4333. $('#unlock-ok').attr('lid', lid);
  4334. $('#unlock').modal('show');
  4335. });
  4336. $('#unlock-ok').click(function () {
  4337. const lid = this.getAttribute('lid');
  4338. if (!lid) return;
  4339. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4340. if (!p) return;
  4341. if (p.pwd === $('#unlock-pwd').val()) {
  4342. const refresh = stageTree.lockNode(p, false);
  4343. // 修改线上
  4344. SpreadJsObj.reloadRowsReadonly(slSpread.getActiveSheet(), refresh);
  4345. stagePosSpreadObj.loadCurPosData();
  4346. $('#unlock').modal('hide');
  4347. reloadCooperationHtml();
  4348. } else {
  4349. $('#unlock-pwd').addClass('is-invalid');
  4350. $('.invalid-feedback', '#unlock').show();
  4351. $('.alert-warning', '#unlock').show();
  4352. }
  4353. });
  4354. $('#cooperationSelect').change(function () {
  4355. reloadCooperationHtml();
  4356. });
  4357. // 确认
  4358. $('body').on('click', '[name=ledger-confirm]', function() {
  4359. const lid = this.getAttribute('lid');
  4360. if (!lid) return;
  4361. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4362. if (!p) return;
  4363. // 修改线上
  4364. postData(window.location.pathname + '/save/cooperation', { type: 'save-confirm', postData: { ledger_id: lid } }, function (result) {
  4365. p.confirm = true;
  4366. p.confirm_time = new Date();
  4367. stageTree.confirmList = result.cooperationConfirm;
  4368. reloadCooperationHtml();
  4369. });
  4370. });
  4371. // 确认
  4372. $('body').on('click', '[name=ledger-unconfirm]', function() {
  4373. const lid = this.getAttribute('lid');
  4374. if (!lid) return;
  4375. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4376. if (!p) return;
  4377. // 修改线上
  4378. postData(window.location.pathname + '/save/cooperation', { type: 'del-confirm', postData: { ledger_id: lid } }, function (result) {
  4379. p.confirm = false;
  4380. p.confirm_time = null;
  4381. stageTree.confirmList = result.cooperationConfirm;
  4382. reloadCooperationHtml();
  4383. });
  4384. });
  4385. // 收方单生成
  4386. $('#setshoufang').click(function () {
  4387. const lid = $('#shoufang-lid').val();
  4388. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  4389. // 修改线上
  4390. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  4391. // 收方单tab打开并显示在最新
  4392. if (!$('#shoufang-tab').hasClass('active')) {
  4393. $('#shoufang-tab').click();
  4394. }
  4395. const data = makeOneShouFang(result);
  4396. data.filenum = 0;
  4397. sfData = _.concat(data, sfData);
  4398. getShouFangList();
  4399. });
  4400. });
  4401. $('body').on('click', '.del-shoufang', function () {
  4402. const id = $(this).attr('data-id');
  4403. $('#del-shoufang-id').val(id);
  4404. const name = $(this).parents('tr').children('td').eq(0).text();
  4405. const ledger_code = name.split(' / ')[0];
  4406. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  4407. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  4408. if (pos_name) {
  4409. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  4410. } else {
  4411. $('#del-shoufang-pos').text('').hide();
  4412. }
  4413. });
  4414. // 收方单删除
  4415. $('#delshoufang').click(function () {
  4416. const sfid = $('#del-shoufang-id').val();
  4417. // 修改线上
  4418. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  4419. // 删除到sfData中
  4420. const att_index = sfData.findIndex(function (item) {
  4421. return item.id === parseInt(sfid);
  4422. });
  4423. sfData.splice(att_index, 1);
  4424. // 重新生成List
  4425. if ($('#shoufang-table tr').length === 1) {
  4426. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  4427. } else {
  4428. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  4429. }
  4430. $('#shoufangdelete').modal('hide');
  4431. });
  4432. });
  4433. // 切换页数
  4434. $('.shoufang-page-select').on('click', function () {
  4435. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  4436. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  4437. const status = $(this).attr('content');
  4438. if (status === 'pre' && lastPageNum > 1) {
  4439. getShouFangList(lastPageNum-1);
  4440. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4441. getShouFangList(lastPageNum+1);
  4442. }
  4443. });
  4444. // 获取单个收方单附件列表
  4445. $('body').on('click', '.show-shoufang-att', function () {
  4446. const id = parseInt($(this).attr('data-id'));
  4447. let html = '';
  4448. $('#shoufang-flie-list').html(html);
  4449. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  4450. for (const att of result) {
  4451. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  4452. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  4453. `<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>`;
  4454. }
  4455. $('#shoufang-flie-list').html(html);
  4456. $('[data-toggle="tooltip"]').tooltip()
  4457. });
  4458. function makeViewHtml(viewpath) {
  4459. 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>` : '';
  4460. }
  4461. function makeDelHtml(fid, extra_upload) {
  4462. return sfAttDelPower &&
  4463. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4464. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
  4465. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4466. }
  4467. });
  4468. function makeEditHtml(fid, filename, fileext, extra_upload) {
  4469. return sfAttDelPower &&
  4470. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4471. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  4472. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  4473. }
  4474. // 修改收方单附件文件名
  4475. $('body').on('click', '.edit-shoufang-att', function () {
  4476. $(this).children('i').tooltip('hide');
  4477. const fid = $(this).data('id');
  4478. const filename = $(this).data('filename');
  4479. const fileext = $(this).data('fileext');
  4480. const html = `<div class="input-group input-group-sm">
  4481. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  4482. <div class="input-group-append" id="button-${fid}">
  4483. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  4484. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  4485. </div>
  4486. </div>`;
  4487. $(this).parents('td').html(html);
  4488. });
  4489. // 确认修改文件名
  4490. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  4491. const validText = $.trim($(this).parents('td').find('input').val());
  4492. const orgValue = $.trim($(this).data('filename'));
  4493. const fileext = $(this).data('fileext');
  4494. const fid = $(this).data('fid');
  4495. if (!validText) {
  4496. toastr.error('文件名不能为空');
  4497. return;
  4498. }
  4499. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  4500. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  4501. toastr.error('文件名中不能包含.字符和空格');
  4502. return;
  4503. }
  4504. if(validText == orgValue) {
  4505. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  4506. $(this).parents('td').html(html);
  4507. return;
  4508. }
  4509. const data = {
  4510. id: fid,
  4511. filename: validText,
  4512. };
  4513. const _self = $(this);
  4514. postData('/wap/shoufang/editfile', data, function (result) {
  4515. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  4516. _self.parents('td').html(html);
  4517. });
  4518. });
  4519. // 取消修改文件名
  4520. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  4521. const fid = $(this).data('fid');
  4522. const filename = $(this).data('filename');
  4523. const fileext = $(this).data('fileext');
  4524. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  4525. $(this).parents('td').html(html);
  4526. });
  4527. // 删除收方单附件
  4528. $('body').on('click', '.del-shoufang-att', function () {
  4529. const id = $(this).data('id');
  4530. const _self = $(this);
  4531. const data = { id };
  4532. const sfid = $(this).data('sfid');
  4533. postData('/wap/shoufang/delfile', data, function (result) {
  4534. _self.parents('tr').remove();
  4535. // 附件个数更新
  4536. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  4537. const sfInfo = _.find(sfData, { id: sfid });
  4538. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  4539. });
  4540. });
  4541. // 定位到对应的清单或计量单元
  4542. $('body').on('click', '.show-shoufang-node', function () {
  4543. const id = parseInt($(this).attr('data-id'));
  4544. const sfInfo = _.find(sfData, { id });
  4545. if (sfInfo) {
  4546. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4547. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  4548. stagePosSpreadObj.loadCurPosData();
  4549. if (sfInfo.pid) {
  4550. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  4551. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  4552. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  4553. }
  4554. }
  4555. });
  4556. // 定位到对应的清单或计量单元
  4557. $('body').on('click', '.show-shoufang-report', function () {
  4558. const id = parseInt($(this).attr('data-id'));
  4559. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  4560. sessionStorage.qrCodePath = qrCodePath;
  4561. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  4562. sessionStorage.req_params = JSON.stringify(req_params);
  4563. sessionStorage.rpt_name = rpt_name;
  4564. window.open('/individualReport/A4');
  4565. });
  4566. });
  4567. function makeOneShouFang(sf) {
  4568. const lData = _.find(ledgerData, { id: sf.lid });
  4569. sf.name = lData.b_code;
  4570. if (sf.pid) {
  4571. const pData = _.find(posData, { id: sf.pid });
  4572. sf.name = lData.b_code + ' / ' + pData.name;
  4573. }
  4574. return sf;
  4575. }
  4576. function makeShouFang() {
  4577. for (const sf of sfData) {
  4578. makeOneShouFang(sf);
  4579. }
  4580. getShouFangList();
  4581. }
  4582. // 生成收方单列表
  4583. function getShouFangList(currPageNum = 1) {
  4584. // 每页最多几个附件
  4585. const pageCount = 20;
  4586. // 附件总数
  4587. const total = sfData.length;
  4588. // 总页数
  4589. const pageNum = Math.ceil(total/pageCount);
  4590. $('#shoufang-totalPage').text(pageNum);
  4591. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  4592. // 当前页附件内容
  4593. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  4594. let html = '';
  4595. for(const att of currPageAttData) {
  4596. html += '<tr><td>' + att.name + '</td>' +
  4597. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  4598. '<td width="100">' +
  4599. '<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> ' +
  4600. '<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> ' +
  4601. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  4602. makeDelHtml(att.id, att.extra_upload) +
  4603. '</td></tr>';
  4604. }
  4605. function makeDelHtml(id, extra_upload) {
  4606. return cur_uid === stage.user_id &&
  4607. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4608. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  4609. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4610. }
  4611. $('#shoufang-table').html(html);
  4612. $('[data-toggle="tooltip"]').tooltip();
  4613. }
  4614. function makeReportData(sfid) {
  4615. const sfInfo = _.find(sfData, { id: sfid });
  4616. const ledger_code = sfInfo.name.split(' / ')[0];
  4617. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  4618. const replace_key_params = {
  4619. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  4620. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  4621. 'KEY_合同段': tenderInfo.deal_info.dealName,
  4622. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  4623. 'KEY_编号': '',
  4624. 'KEY_设计工程数量': 0,
  4625. };
  4626. // if (sfInfo.pid) {
  4627. // const pData = _.find(posData, { id: sfInfo.pid });
  4628. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  4629. // } else {
  4630. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4631. // }
  4632. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  4633. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  4634. const req_params = {
  4635. 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)
  4636. pageSize: 'A4',
  4637. project_id: tender.project_id,
  4638. tender_id: tender.id,
  4639. stage_id: stage.id,
  4640. };
  4641. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  4642. const qrCodePath = sfInfo.qrcode;
  4643. return [qrCodePath, replace_key_params, req_params, rpt_name];
  4644. }