stage.js 256 KB

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