stage.js 232 KB

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