ledger.js 243 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206
  1. /**
  2. * 台账相关js
  3. *
  4. * @author Mai
  5. * @date 2018/02/05
  6. * @version
  7. */
  8. const ckBillsSpread = window.location.pathname + '-billsSelect';
  9. function checkTzMeasureType () {
  10. return tender.measure_type === measureType.tz.value;
  11. }
  12. function getTenderId() {
  13. return window.location.pathname.split('/')[2];
  14. }
  15. const copyBlockTag = 'zh.calc.copyBlock';
  16. const invalidFields = {
  17. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price', 'ex_qty1'],
  18. gcl: ['dgn_qty1', 'dgn_qty2'],
  19. posCode: ['b_code'],
  20. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'ex_tp1'],
  21. posXmj: ['code'],
  22. };
  23. function getExprInfo (field, converse = false) {
  24. const exprField = [
  25. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  26. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  27. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  28. ];
  29. if (converse) return _.find(exprField, { expr: field });
  30. return _.find(exprField, {qty: field});
  31. }
  32. function transExpr(expr) {
  33. return expr.replace('=', '').replace(new RegExp('%', 'gm'), '/100');
  34. }
  35. const checkOption = {
  36. sibling: { enable: 1 },
  37. empty_code: { enable: 1 },
  38. calc: {
  39. enable: 1,
  40. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  41. },
  42. zero: { enable: 1 },
  43. zeroPos: { enable: 1 },
  44. pos_drawingCode: { enable: 1 },
  45. tp: {
  46. enable: 1,
  47. fields: [
  48. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  49. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  50. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  51. {qty: 'quantity', tp: 'total_price'},
  52. {qty: 'deal_qty', tp: 'deal_tp'},
  53. ],
  54. },
  55. same_code: { enable: 1 },
  56. same_bills: { enable: 1 },
  57. };
  58. $(document).ready(function() {
  59. const unit = ledgerSpreadSetting.cols.find(x => { return x.field === 'unit'; });
  60. if (unit) unit.comboEdit = true;
  61. let stdXmj, stdGcl, dealBills, searchLedger, featureDisplay;
  62. autoFlashHeight();
  63. const changeFeaturesDisplay = function (show, init = false) {
  64. $('#features-show').html(show ? '<i class="fa fa-eye-slash"></i> 隐藏特征' : '<i class="fa fa-eye"></i> 显示特征');
  65. const featureCols = ledgerSpreadSetting.cols.find(x => { return x.field === 'features'; });
  66. if (!featureCols) return;
  67. featureCols.visible = show ? true : false;
  68. if (!init) {
  69. featureDisplay = show;
  70. setLocalCache(featureShowCache, show ? 1 : 0);
  71. SpreadJsObj.refreshColumnVisible(ledgerSheet, 1);
  72. }
  73. };
  74. const reloadFeaturesDisplayCache = function () {
  75. const featureCols = ledgerSpreadSetting.cols.find(x => { return x.field === 'features'; });
  76. if (featureCols) {
  77. $('#features-show').show();
  78. featureDisplay = getLocalCache(featureShowCache);
  79. featureDisplay = featureDisplay ? parseInt(featureDisplay) : 1;
  80. changeFeaturesDisplay(featureDisplay, true);
  81. } else {
  82. $('#features-show').hide();
  83. }
  84. };
  85. reloadFeaturesDisplayCache();
  86. $('#features-show').click(function() {
  87. changeFeaturesDisplay(!featureDisplay);
  88. });
  89. // 初始化台账
  90. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  91. const ledgerSheet = ledgerSpread.getActiveSheet();
  92. removeLocalCache('bills-fold');
  93. const treeSetting = {
  94. id: 'ledger_id',
  95. pid: 'ledger_pid',
  96. order: 'order',
  97. level: 'level',
  98. rootId: -1,
  99. keys: ['id', 'tender_id', 'ledger_id'],
  100. preUrl: '/tender/' + getTenderId() + '/ledger',
  101. //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(),
  102. autoExpand: 3,
  103. // markFoldKey: 'bills-fold',
  104. // markFoldSubKey: window.location.pathname.split('/')[2],
  105. markExpandKey: 'bills-expand',
  106. markExpandSubKey: window.location.pathname.split('/')[2],
  107. calcFields: ['deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price', 'ex_tp1'],
  108. };
  109. treeSetting.calcFun = function (node) {
  110. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  111. };
  112. const ledgerTree = createNewPathTree('ledger', treeSetting);
  113. //初始化所有附件列表
  114. getAllList();
  115. // 初始化 计量单元
  116. const pos = new PosData({
  117. id: 'id', ledgerId: 'lid',
  118. });
  119. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  120. const posSheet = posSpread.getActiveSheet();
  121. // 初始化 附属工程量
  122. const ancGcl = createAncillaryGcl({ id: 'id', masterId: 'lid', sort: [['g_order', 'asc']] });
  123. const ancGclSpread = SpreadJsObj.createNewSpread($('#anc-gcl-spread')[0]);
  124. const ancGclSheet = ancGclSpread.getActiveSheet();
  125. const billsTag = $.billsTag({
  126. relaTree: ledgerTree,
  127. selector: '#bills-tag',
  128. relaSpread: ledgerSpread,
  129. relaPosSpread: posSpread,
  130. updateUrl: window.location.pathname + '/tag',
  131. afterModify: function (nodes) {
  132. SpreadJsObj.repaintNodesRowHeader(ledgerSpread.getActiveSheet(), nodes);
  133. },
  134. afterLocated: function (lid, pos_id) {
  135. posOperationObj.loadCurPosData();
  136. ancGclObj.loadCurAncillaryGcl();
  137. if (pos_id) {
  138. const posSheet = posSpread.getActiveSheet();
  139. const relaPos = posSheet.zh_data.find(x => { return x.id === pos_id; });
  140. SpreadJsObj.locateData(posSheet, relaPos);
  141. }
  142. },
  143. afterShow: function () {
  144. ledgerSpread.refresh();
  145. if (posSpread) posSpread.refresh();
  146. if (ancGclSpread) ancGclSpread.refresh();
  147. },
  148. });
  149. const errorList = $.cs_errorList({
  150. tabSelector: '#error-list-tab',
  151. selector: '#error-list',
  152. relaSpread: ledgerSpread,
  153. storeKey: 'ledger-error-' + getTenderId(),
  154. afterLocated: function () {
  155. posOperationObj.loadCurPosData();
  156. ancGclObj.loadCurAncillaryGcl();
  157. },
  158. afterShow: function () {
  159. ledgerSpread.refresh();
  160. if (posSpread) posSpread.refresh();
  161. if (ancGclSpread) ancGclSpread.refresh();
  162. },
  163. });
  164. const checkList = $.ledger_checkList({
  165. id: 'check-list',
  166. tabSelector: '#check-list-tab',
  167. selector: '#check-list',
  168. relaSpread: ledgerSpread,
  169. storeKey: 'ledger-check-' + getTenderId(),
  170. checkType: getCheckType(checkOption),
  171. afterLocated: function () {
  172. posOperationObj.loadCurPosData();
  173. ancGclObj.loadCurAncillaryGcl();
  174. },
  175. afterShow: function () {
  176. ledgerSpread.refresh();
  177. if (posSpread) posSpread.refresh();
  178. if (ancGclSpread) ancGclSpread.refresh();
  179. },
  180. });
  181. const gclGather = $.cs_gclGather({
  182. selector: '#gcl-gather',
  183. id: 'gcl-gather',
  184. relaSheet: ledgerSpread.getActiveSheet(),
  185. });
  186. $.subMenu({
  187. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  188. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  189. key: 'menu.1.0.0',
  190. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  191. callback: function (info) {
  192. if (info.mini) {
  193. $('.panel-title').addClass('fluid');
  194. $('#sub-menu').removeClass('panel-sidebar');
  195. } else {
  196. $('.panel-title').removeClass('fluid');
  197. $('#sub-menu').addClass('panel-sidebar');
  198. }
  199. autoFlashHeight();
  200. ledgerSpread.refresh();
  201. if (posSpread) posSpread.refresh();
  202. if (ancGclSpread) ancGclSpread.refresh();
  203. if (stdXmj) stdXmj.spread.refresh();
  204. if (stdGcl) stdGcl.spread.refresh();
  205. if (dealBills) dealBills.spread.refresh();
  206. if (searchLedger) searchLedger.spread.refresh();
  207. if (errorList) errorList.spread.refresh();
  208. if (checkList) checkList.spread.refresh();
  209. if (gclGather) gclGather.spread.refresh();
  210. }
  211. });
  212. // 定义事件
  213. const treeOperationObj = {
  214. loadExprToInput(sheet) {
  215. const sel = sheet.getSelections()[0];
  216. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  217. if (col && col.type === 'Number') {
  218. const data = SpreadJsObj.getSelectObject(sheet);
  219. if (data) {
  220. const exprInfo = getExprInfo(col.field);
  221. if (exprInfo) {
  222. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  223. .attr('field', col.field).attr('org', data[col.field]);
  224. } else {
  225. $('#bills-expr').val(data[col.field])
  226. .attr('field', col.field).attr('org', data[col.field]);
  227. }
  228. if (col.field.indexOf('dgn') >= 0) {
  229. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
  230. } else {
  231. const nodePos = pos.getLedgerPos(data.id);
  232. if (nodePos && nodePos.length > 0) {
  233. $('#bills-expr').val('').attr('readOnly', true);
  234. $('#bills-expr').removeAttr('data-row');
  235. } else {
  236. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
  237. }
  238. }
  239. $('#bills-expr').attr('data-row', sel.row);
  240. } else {
  241. $('#bills-expr').val('').attr('readOnly', true);
  242. $('#bills-expr').removeAttr('data-row');
  243. }
  244. } else {
  245. $('#bills-expr').val('').attr('readOnly', true);
  246. $('#bills-expr').removeAttr('data-row');
  247. }
  248. },
  249. getSelectNode: function (sheet) {
  250. if (!sheet || !sheet.zh_tree) {
  251. return null;
  252. } else {
  253. const sel = sheet.getSelections()[0];
  254. return sheet.zh_tree.nodes[sel.row];
  255. }
  256. },
  257. getDefaultSelectInfo: function (sheet) {
  258. const tree = sheet.zh_tree;
  259. if (!tree) return;
  260. const sel = sheet.getSelections()[0];
  261. const node = sheet.zh_tree.nodes[sel.row];
  262. if (!node) return;
  263. let count = 1;
  264. if (sel.rowCount > 1) {
  265. for (let r = 1; r < sel.rowCount; r++) {
  266. const rNode = sheet.zh_tree.nodes[sel.row + r];
  267. if (rNode.level > node.level) continue;
  268. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  269. toastr.error('请选择同一清单下的节点,进行该操作');
  270. return;
  271. }
  272. count += 1;
  273. }
  274. }
  275. return [tree, node, count];
  276. },
  277. /**
  278. * 刷新顶部按钮是否可用
  279. * @param sheet
  280. * @param selections
  281. */
  282. refreshOperationValid: function (sheet, selection) {
  283. const setObjEnable = function (obj, enable) {
  284. if (enable) {
  285. obj.removeClass('disabled');
  286. } else {
  287. obj.addClass('disabled');
  288. }
  289. };
  290. const invalidAll = function () {
  291. setObjEnable($('#insert'), false);
  292. setObjEnable($('#delete'), false);
  293. setObjEnable($('#up-move'), false);
  294. setObjEnable($('#down-move'), false);
  295. setObjEnable($('#up-level'), false);
  296. setObjEnable($('#down-level'), false);
  297. };
  298. const sel = selection ? selection[0] : sheet.getSelections()[0];
  299. const row = sel ? sel.row : -1;
  300. const tree = sheet.zh_tree;
  301. if (!tree) {
  302. invalidAll();
  303. return;
  304. }
  305. const first = sheet.zh_tree.nodes[row];
  306. if (!first) {
  307. invalidAll();
  308. return;
  309. }
  310. let last = first, sameParent = true;
  311. if (sel.rowCount > 1 && first) {
  312. for (let r = 1; r < sel.rowCount; r++) {
  313. const rNode = tree.nodes[row + r];
  314. if (!rNode) {
  315. sameParent = false;
  316. break;
  317. }
  318. if (rNode.level > first.level) continue;
  319. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  320. sameParent = false;
  321. break;
  322. }
  323. last = rNode;
  324. }
  325. }
  326. const preNode = tree.getPreSiblingNode(first);
  327. const valid = !sheet.zh_setting.readOnly;
  328. setObjEnable($('#insert'), valid && first && first.level > 1);
  329. setObjEnable($('#delete'), valid && first && sameParent && !(first.level === 1 && first.node_type));
  330. setObjEnable($('#up-move'), valid && first && sameParent && first.level > 1 && preNode);
  331. setObjEnable($('#down-move'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  332. if (checkTzMeasureType()) {
  333. const posRange = last ? pos.getLedgerPos(last.id) : [];
  334. setObjEnable($('#up-level'), valid && first && sameParent && tree.getParent(first) && first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
  335. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  336. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
  337. } else {
  338. setObjEnable($('#up-level'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
  339. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode);
  340. }
  341. setObjEnable($('#cut'), valid);
  342. setObjEnable($('#paste'), valid);
  343. },
  344. refreshTree: function (sheet, data) {
  345. SpreadJsObj.massOperationSheet(sheet, function () {
  346. const tree = sheet.zh_tree;
  347. // 处理删除
  348. if (data.delete) {
  349. data.delete.sort(function (x, y) {
  350. return y.deleteIndex - x.deleteIndex;
  351. });
  352. for (const d of data.delete) {
  353. sheet.deleteRows(d.deleteIndex, 1);
  354. }
  355. }
  356. // 处理新增
  357. if (data.create) {
  358. const newNodes = data.create;
  359. if (newNodes) {
  360. newNodes.sort(function (a, b) {
  361. return a.index - b.index;
  362. });
  363. for (const node of newNodes) {
  364. sheet.addRows(node.index, 1);
  365. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  366. }
  367. }
  368. }
  369. // 处理更新
  370. if (data.update) {
  371. const rows = [];
  372. for (const u of data.update) {
  373. rows.push(tree.nodes.indexOf(u));
  374. billsTag.refreshBillsTagView(u);
  375. }
  376. SpreadJsObj.reLoadRowsData(sheet, rows);
  377. }
  378. // 处理展开
  379. if (data.expand) {
  380. const expanded = [];
  381. for (const e of data.expand) {
  382. if (expanded.indexOf(e) === -1) {
  383. const posterity = tree.getPosterity(e);
  384. for (const p of posterity) {
  385. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  386. expanded.push(p);
  387. }
  388. }
  389. }
  390. }
  391. });
  392. },
  393. refreshPosterity: function (sheet, node) {
  394. const posterity = sheet.zh_tree.getPosterity(node);
  395. SpreadJsObj.reLoadRowData(sheet, node.index + 1, posterity.length);
  396. },
  397. /**
  398. * 新增节点
  399. * @param spread
  400. */
  401. addNode: function (sheet, count = 1) {
  402. const self = this;
  403. const sel = sheet.getSelections()[0];
  404. const row = sheet.getSelections()[0].row;
  405. const tree = sheet.zh_tree;
  406. if (!tree) { return; }
  407. const node = sheet.zh_tree.nodes[row];
  408. if (!node) { return; }
  409. postData(window.location.pathname + '/update', {
  410. postType: 'add',
  411. postData: {
  412. id: tree.getNodeKey(node),
  413. count: count,
  414. }
  415. }, function (result) {
  416. const refreshNode = tree.loadPostData(result);
  417. self.refreshTree(sheet, refreshNode);
  418. sheet.setSelection(refreshNode.create[0].index, sel.col, sel.rowCount, sel.colCount);
  419. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, refreshNode.create[0].index]);
  420. self.refreshOperationValid(sheet);
  421. });
  422. },
  423. /**
  424. * 删除选中节点
  425. * @param spread
  426. */
  427. deleteNode: function (sheet) {
  428. const self = this;
  429. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  430. if (tree && node && count) {
  431. const data = {
  432. postType: 'delete',
  433. postData: {
  434. id: tree.getNodeKey(node),
  435. count: count
  436. }
  437. };
  438. deleteAfterHint(function () {
  439. postData(window.location.pathname + '/update', data, function (result) {
  440. const refreshNode = tree.loadPostData(result);
  441. for (const d of refreshNode.delete) {
  442. pos.removeDatasByMasterId(d.id);
  443. ancGcl.removeDatasByMasterId(d.id);
  444. }
  445. self.refreshTree(sheet, refreshNode);
  446. self.refreshOperationValid(sheet);
  447. posOperationObj.loadCurPosData();
  448. ancGclObj.loadCurAncillaryGcl();
  449. billsTag.afterDeleteBills(refreshNode.delete);
  450. });
  451. });
  452. }
  453. },
  454. /**
  455. * 上移选中节点
  456. * @param spread
  457. */
  458. upMove: function (sheet) {
  459. const self = this;
  460. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  461. if (tree && node && count) {
  462. const data = {
  463. postType: 'up-move',
  464. postData: {
  465. id: tree.getNodeKey(node),
  466. count: count
  467. }
  468. };
  469. postData(window.location.pathname + '/update', data, function (result) {
  470. const refreshNode = tree.loadPostData(result);
  471. self.refreshTree(sheet, refreshNode);
  472. const sel = sheet.getSelections()[0];
  473. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  474. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  475. self.refreshOperationValid(sheet);
  476. });
  477. }
  478. },
  479. /**
  480. * 下移选中节点
  481. * @param spread
  482. */
  483. downMove: function (sheet) {
  484. const self = this;
  485. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  486. if (tree && node && count) {
  487. const data = {
  488. postType: 'down-move',
  489. postData: {
  490. id: tree.getNodeKey(node),
  491. count: count
  492. }
  493. };
  494. postData(window.location.pathname + '/update', data, function (result) {
  495. const refreshNode = tree.loadPostData(result);
  496. self.refreshTree(sheet, refreshNode);
  497. const sel = sheet.getSelections()[0];
  498. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  499. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  500. self.refreshOperationValid(sheet);
  501. });
  502. }
  503. },
  504. /**
  505. * 升级选中节点
  506. * @param spread
  507. */
  508. upLevel: function (sheet) {
  509. const self = this;
  510. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  511. if (tree && node && count) {
  512. const data = {
  513. postType: 'up-level',
  514. postData: {
  515. id: tree.getNodeKey(node),
  516. count: count
  517. }
  518. };
  519. postData(window.location.pathname + '/update', data, function (result) {
  520. const refreshNode = tree.loadPostData(result);
  521. self.refreshTree(sheet, refreshNode);
  522. self.refreshOperationValid(sheet);
  523. });
  524. }
  525. },
  526. /**
  527. * 降级选中节点
  528. * @param spread
  529. */
  530. downLevel: function (sheet) {
  531. const self = this;
  532. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  533. if (tree && node && count) {
  534. const data = {
  535. postType: 'down-level',
  536. postData: {
  537. id: tree.getNodeKey(node),
  538. count: count
  539. }
  540. };
  541. postData(window.location.pathname + '/update', data, function (result) {
  542. const refreshNode = tree.loadPostData(result);
  543. self.refreshTree(sheet, refreshNode);
  544. self.refreshOperationValid(sheet);
  545. });
  546. }
  547. },
  548. /**
  549. * 编辑单元格响应事件
  550. * @param {Object} e
  551. * @param {Object} info
  552. */
  553. editEnded: function (e, info) {
  554. if (info.sheet.zh_setting) {
  555. const col = info.sheet.zh_setting.cols[info.col];
  556. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  557. const node = sortData[info.row];
  558. const data = {
  559. id: node.id,
  560. tender_id: node.tender_id,
  561. ledger_id: node.ledger_id
  562. };
  563. // 未改变值则不提交
  564. const orgValue = node[col.field];
  565. if (info.editingText === null) info.editingText = '';
  566. const newValue = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  567. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  568. return;
  569. }
  570. // 台账模式,检查计量单元相关
  571. if (checkTzMeasureType()) {
  572. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  573. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  574. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  575. col.field === 'ex_qty1' || col.field === 'ex_tp1') {
  576. if (!node.children || node.children.length ===0) {
  577. const lPos = pos.getLedgerPos(node.id);
  578. if (lPos && lPos.length > 0) {
  579. toastr.error('清单含有计量单元,请在计量单元输入数量');
  580. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  581. return;
  582. }
  583. }
  584. }
  585. if (col.field === 'b_code' && (info.editingText === '' || !info.editingText)) {
  586. const lPos = pos.getLedgerPos(node.id);
  587. if (lPos && lPos.length > 0) {
  588. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  589. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  590. return;
  591. }
  592. }
  593. }
  594. if (col.field === 'node_type' && newValue && newValue !== '0' && newValue !== '19') {
  595. const sameNodeType = sortData.find(x => { return x.node_type == newValue; });
  596. if (sameNodeType) {
  597. toastr.error('已存在该费用类别,请勿重复选择');
  598. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  599. return;
  600. }
  601. }
  602. // 获取更新数据
  603. if (col.type === 'Number') {
  604. const exprInfo = getExprInfo(col.field);
  605. if (newValue) {
  606. const num = _.toNumber(newValue);
  607. if (_.isFinite(num)) {
  608. data[col.field] = num;
  609. } else {
  610. try {
  611. data[col.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  612. if (exprInfo) {
  613. data[exprInfo.expr] = newValue;
  614. }
  615. } catch(err) {
  616. toastr.error('输入的表达式非法');
  617. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  618. return;
  619. }
  620. }
  621. } else {
  622. data[col.field] = null;
  623. if (exprInfo) {
  624. data[exprInfo.expr] = '';
  625. }
  626. }
  627. } else {
  628. data[col.field] = newValue;
  629. }
  630. // 更新至服务器
  631. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  632. const refreshNode = ledgerTree.loadPostData(result);
  633. treeOperationObj.refreshTree(info.sheet, refreshNode);
  634. });
  635. }
  636. },
  637. /**
  638. * 粘贴单元格响应事件
  639. * @param e
  640. * @param info
  641. */
  642. clipboardPasted: function (e, info) {
  643. if (info.sheet.zh_setting && info.sheet.zh_dataType === 'tree') {
  644. const tree = info.sheet.zh_tree;
  645. if (!tree) { return; }
  646. const sortData = info.sheet.zh_tree.nodes;
  647. const datas = [], filterNodes = [];
  648. let bHint = false, bPaste;
  649. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  650. bPaste = false;
  651. const curRow = info.cellRange.row + iRow;
  652. const node = sortData[curRow];
  653. if (node) {
  654. const data = info.sheet.zh_tree.getNodeKeyData(node);
  655. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  656. const curCol = info.cellRange.col + iCol;
  657. const colSetting = info.sheet.zh_setting.cols[curCol];
  658. const value = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  659. const lPos = pos.getLedgerPos(node.id);
  660. if (lPos && lPos.length > 0) {
  661. if (value === '' && colSetting.field === 'b_code') {
  662. if (!bHint) {
  663. toastr.warning('清单含有计量单元,请先删除计量单元,再删除清单编号');
  664. bHint = true;
  665. }
  666. continue;
  667. }
  668. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  669. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  670. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
  671. colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
  672. if (!bHint) {
  673. toastr.warning('清单含有计量单元,数量金额根据计量单元汇总计算所得,不可编辑');
  674. bHint = true;
  675. }
  676. continue;
  677. }
  678. }
  679. if (colSetting.type === 'Number') {
  680. const num = _.toNumber(value);
  681. if (num) {
  682. data[colSetting.field] = num;
  683. bPaste = true;
  684. } else {
  685. try {
  686. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  687. bPaste = true;
  688. } catch(err) {
  689. delete data[colSetting.field];
  690. if (!bHint) {
  691. toastr.warning('输入的表达式非法');
  692. bHint = true;
  693. }
  694. }
  695. }
  696. } else {
  697. data[colSetting.field] = value;
  698. bPaste = true;
  699. }
  700. }
  701. if (bPaste) {
  702. datas.push(data);
  703. } else {
  704. filterNodes.push(node);
  705. }
  706. }
  707. }
  708. if (datas.length > 0) {
  709. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  710. const refreshNode = tree.loadPostData(result);
  711. if (refreshNode.update) {
  712. refreshNode.update = refreshNode.update.concat(filterNodes);
  713. }
  714. treeOperationObj.refreshTree(info.sheet, refreshNode);
  715. }, function () {
  716. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  717. });
  718. } else {
  719. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  720. }
  721. }
  722. },
  723. clipboardPasting: function (e, info) {
  724. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  725. info.cancel = true;
  726. if (!setting || !tree) return;
  727. const pasteData = info.pasteData.html
  728. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  729. : (info.pasteData.text === ''
  730. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  731. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  732. const hint = {
  733. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  734. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  735. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  736. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  737. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  738. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  739. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  740. };
  741. const datas = [], filterNodes = [];
  742. let pid, level, filterRow = 0;
  743. for (let iRow = 0; iRow < info.cellRange.rowCount + filterRow; iRow++) {
  744. const curRow = info.cellRange.row + iRow;
  745. const node = tree.nodes[curRow];
  746. if (!node) continue;
  747. if (!pid) pid = node.ledger_pid;
  748. if (!level) level = node.level;
  749. // if (node.ledger_pid !== pid) {
  750. // toastMessageUniq(hint.sameParent);
  751. // filterRow+=1;
  752. // continue;
  753. // }
  754. if (node.level < level) break;
  755. let bPaste = false;
  756. const data = info.sheet.zh_tree.getNodeKeyData(node);
  757. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  758. const curCol = info.cellRange.col + iCol;
  759. const colSetting = info.sheet.zh_setting.cols[curCol];
  760. const value = colSetting.wordWrap ? pasteData[iRow-filterRow][iCol] : trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  761. const lPos = pos.getLedgerPos(node.id);
  762. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  763. toastMessageUniq(hint.parent);
  764. continue;
  765. }
  766. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  767. toastMessageUniq(hint.gcl);
  768. continue;
  769. }
  770. if (lPos && lPos.length > 0) {
  771. if (value === '' && invalidFields.posCode.indexOf(colSetting.field) >= 0) {
  772. toastMessageUniq(hint.posCode);
  773. continue;
  774. }
  775. if (invalidFields.posCalc.indexOf(colSetting.field) >= 0) {
  776. toastMessageUniq(hint.posQty);
  777. continue;
  778. }
  779. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  780. toastMessageUniq(hint.posXmj);
  781. continue;
  782. }
  783. }
  784. if (colSetting.type === 'Number') {
  785. const num = _.toNumber(value);
  786. if (num) {
  787. data[colSetting.field] = num;
  788. bPaste = true;
  789. } else {
  790. try {
  791. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  792. const exprInfo = getExprInfo(colSetting.field);
  793. if (exprInfo) {
  794. data[exprInfo.expr] = value;
  795. bPaste = true;
  796. }
  797. } catch(err) {
  798. toastMessageUniq(hint.invalidExpr);
  799. }
  800. }
  801. } else {
  802. data[colSetting.field] = value;
  803. bPaste = true;
  804. }
  805. }
  806. if (bPaste) {
  807. datas.push(data);
  808. } else {
  809. filterNodes.push(node);
  810. }
  811. }
  812. if (datas.length > 0) {
  813. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  814. const refreshNode = tree.loadPostData(result);
  815. if (refreshNode.update) {
  816. refreshNode.update = refreshNode.update.concat(filterNodes);
  817. }
  818. treeOperationObj.refreshTree(info.sheet, refreshNode);
  819. }, function () {
  820. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  821. });
  822. } else {
  823. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  824. }
  825. },
  826. /**
  827. * 删除按钮响应事件
  828. * @param sheet
  829. */
  830. deletePress: function (sheet) {
  831. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  832. const tree = sheet.zh_tree;
  833. if (!tree) { return; }
  834. const sortData = sheet.zh_tree.nodes;
  835. const datas = [], nodes = [];
  836. const sel = sheet.getSelections()[0];
  837. let bHint = false;
  838. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  839. const node = sortData[iRow];
  840. if (node) {
  841. let bDel = false;
  842. const data = sheet.zh_tree.getNodeKeyData(node);
  843. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  844. const col = sheet.zh_setting.cols[iCol];
  845. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  846. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  847. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  848. col.field === 'ex_qty1' || col.field === 'ex_tp1' ) {
  849. const lPos = pos.getLedgerPos(node.id);
  850. if (lPos && lPos.length > 0) {
  851. if (!bHint) {
  852. if (col.field === 'code') {
  853. toastr.warning('清单含有计量单元,请先删除计量单元,再删除清单编号');
  854. } else {
  855. toastr.warning('清单含有计量单元,数量金额根据计量单元汇总计算所得,不可删除');
  856. }
  857. bHint = true;
  858. }
  859. continue;
  860. }
  861. }
  862. const style = sheet.getStyle(iRow, iCol);
  863. if (!style.locked) {
  864. const colSetting = sheet.zh_setting.cols[iCol];
  865. data[colSetting.field] = colSetting.type === 'Number' ? 0 : '';
  866. const exprInfo = getExprInfo(colSetting.field);
  867. if (exprInfo) {
  868. data[exprInfo.expr] = '';
  869. }
  870. bDel = true;
  871. }
  872. }
  873. if (bDel) {
  874. datas.push(data);
  875. nodes.push(node);
  876. }
  877. }
  878. }
  879. if (datas.length > 0) {
  880. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  881. const refreshNode = tree.loadPostData(result);
  882. treeOperationObj.refreshTree(sheet, refreshNode);
  883. treeOperationObj.loadExprToInput(sheet);
  884. });
  885. }
  886. }
  887. },
  888. /**
  889. * 粘贴整块
  890. * @param spread
  891. * @param block
  892. */
  893. pasteBlock: function (spread, copyInfo) {
  894. const self = this;
  895. const sheet = spread.getActiveSheet();
  896. const sel = sheet.getSelections()[0];
  897. const row = sel.row;
  898. const tree = sheet.zh_tree;
  899. if (!tree) { return; }
  900. const node = tree.nodes[row];
  901. if (!node) { return; }
  902. postData(window.location.pathname + '/update', {
  903. postType: 'paste-block',
  904. postData: {
  905. id: tree.getNodeKey(node),
  906. tid: copyInfo.tid,
  907. block: copyInfo.block,
  908. }
  909. }, function (data) {
  910. pos.updateDatas(data.pos);
  911. if (data.ancGcl) ancGcl.updateDatas(data.ancGcl);
  912. const result = tree.loadPostData(data.ledger);
  913. self.refreshTree(sheet, result);
  914. sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  915. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, result.create[0].index]);
  916. self.refreshOperationValid(sheet);
  917. removeLocalCache(copyBlockTag);
  918. }, null, true);
  919. },
  920. loadRelaData: function () {
  921. posOperationObj.loadCurPosData();
  922. ancGclObj.loadCurAncillaryGcl();
  923. posSearch.search($('#pos-keyword').val());
  924. treeOperationObj.loadExprToInput(ledgerSpread.getActiveSheet());
  925. },
  926. selectionChanged: function (e, info) {
  927. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  928. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  929. treeOperationObj.loadRelaData();
  930. // 全选去除
  931. $('#dqjiedian').find('.check-all-file').prop('checked', false);
  932. }
  933. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  934. },
  935. topRowChanged(e, info) {
  936. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  937. },
  938. cut: function (sheet, sel, callback) {
  939. if (!sheet || !sel) return;
  940. if (sel.colCount >= sheet.zh_setting.cols.length) {
  941. toastr.warning('请勿选中整行剪切');
  942. return;
  943. }
  944. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  945. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  946. const node = sortData[iRow];
  947. if (node) {
  948. const data = sheet.zh_tree.getNodeKeyData(node);
  949. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  950. const col = sheet.zh_setting.cols[iCol];
  951. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  952. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  953. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  954. col.field === 'ex_qty1' || col.field === 'ex_tp1' ) {
  955. const lPos = pos.getLedgerPos(node.id);
  956. if (lPos && lPos.length > 0) {
  957. toastr.error('不可剪切');
  958. return;
  959. }
  960. }
  961. const style = sheet.getStyle(iRow, iCol);
  962. if (style.locked) {
  963. toastr.error('不可剪切');
  964. return;
  965. }
  966. const colSetting = sheet.zh_setting.cols[iCol];
  967. data[colSetting.field] = null;
  968. const exprInfo = getExprInfo(colSetting.field);
  969. if (exprInfo) {
  970. data[exprInfo.expr] = '';
  971. }
  972. }
  973. datas.push(data);
  974. }
  975. }
  976. if (datas.length > 0) {
  977. callback();
  978. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  979. const refreshNode = sheet.zh_tree.loadPostData(result);
  980. treeOperationObj.refreshTree(sheet, refreshNode);
  981. });
  982. }
  983. },
  984. editStarting(e, info) {
  985. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  986. const tree = info.sheet.zh_tree;
  987. const col = info.sheet.zh_setting.cols[info.col];
  988. const node = info.sheet.zh_tree.nodes[info.row];
  989. if (!node) {
  990. info.cancel = true;
  991. return;
  992. }
  993. const exprInfo = getExprInfo(col.field);
  994. if (exprInfo) {
  995. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  996. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  997. }
  998. }
  999. switch (col.field) {
  1000. case 'code':
  1001. const posRange = pos.getLedgerPos(node.id);
  1002. info.cancel = posRange && posRange.length > 0;
  1003. break;
  1004. case 'unit_price':
  1005. case 'sgfh_qty':
  1006. case 'sgfh_tp':
  1007. case 'sjcl_qty':
  1008. case 'sjcl_tp':
  1009. case 'qtcl_qty':
  1010. case 'qtcl_tp':
  1011. case 'deal_qty':
  1012. case 'deal_tp':
  1013. case 'ex_qty1':
  1014. case 'ex_tp1':
  1015. info.cancel = node.children && node.children.length > 0;
  1016. break;
  1017. case 'dgn_qty1':
  1018. case 'dgn_qty2':
  1019. info.cancel = !_.isEmpty(node.b_code);
  1020. break;
  1021. case 'node_type':
  1022. const parent = tree.getParent(node);
  1023. if (parent) {
  1024. info.cancel = false;
  1025. // const topParent = tree.getTopParent(node);
  1026. // info.cancel = [1, 5].indexOf(topParent.node_type) < 0;
  1027. } else {
  1028. info.cancel = true;
  1029. }
  1030. break;
  1031. }
  1032. },
  1033. sortCode: function (sheet) {
  1034. const tree = sheet.zh_tree;
  1035. if (!tree) return;
  1036. const select = SpreadJsObj.getSelectObject(sheet);
  1037. if (!select || !select.code) return;
  1038. const getChildSort = function (i, split) {
  1039. if (i <= 0) throw '参数错误';
  1040. switch(split) {
  1041. case '0':
  1042. return i < 10 ? split + i : i + '';
  1043. case '-':
  1044. default:
  1045. return split + i;
  1046. }
  1047. };
  1048. const recursiveSortCode = function (data, parentCode, children, split) {
  1049. if (!children || children.length === 0) return;
  1050. for (const [i, child] of children.entries()) {
  1051. if (!child.b_code || child.b_code === '') {
  1052. const code = parentCode + getChildSort(i + 1, split);
  1053. const cData = tree.getNodeKeyData(child);
  1054. cData.code = code;
  1055. data.push(cData);
  1056. if (!tree.isLeafXmj(child)) {
  1057. recursiveSortCode(data, code, child.children, split);
  1058. }
  1059. }
  1060. }
  1061. };
  1062. const data = [];
  1063. recursiveSortCode(data, select.code, select.children, tree.getCodeSplit());
  1064. if (data.length > 0) {
  1065. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1066. const refreshNode = tree.loadPostData(result);
  1067. treeOperationObj.refreshTree(sheet, refreshNode);
  1068. })
  1069. }
  1070. },
  1071. batchReplace: function(orgInfo, newInfo) {
  1072. const updateData = [];
  1073. for (const d of ledgerTree.nodes) {
  1074. if (!d.b_code) continue;
  1075. const checkInfo = { code: d.b_code || '', name: d.name || '', unit: d.unit || '', unit_price: d.unit_price || 0 };
  1076. if (_.isMatch(checkInfo, orgInfo)) {
  1077. const data = ledgerTree.getNodeKeyData(d);
  1078. data.b_code = newInfo.code;
  1079. data.name = newInfo.name;
  1080. data.unit = newInfo.unit;
  1081. data.unit_price = newInfo.unit_price;
  1082. updateData.push(data);
  1083. }
  1084. }
  1085. if (updateData.length === 0) {
  1086. toastr.warning('没有可以替换的数据');
  1087. return;
  1088. }
  1089. postData(window.location.pathname + '/update', {postType: 'update', postData: updateData}, function (result) {
  1090. const refreshNode = ledgerTree.loadPostData(result);
  1091. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1092. });
  1093. },
  1094. };
  1095. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  1096. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  1097. ledgerTreeCol.initSpreadSetting(ledgerSpreadSetting);
  1098. ledgerSpreadSetting.headColWidth = [50];
  1099. ledgerSpreadSetting.rowHeader = [
  1100. {
  1101. rowHeaderType: 'tag',
  1102. setting: {
  1103. indent: 14,
  1104. tagSize: 0.8,
  1105. tagFont: '8px 微软雅黑',
  1106. getColor: function (index, data) {
  1107. if (!data) return;
  1108. return billsTag.getBillsTagsColor(data.id);
  1109. },
  1110. getTagHtml: function (index, data) {
  1111. if (!data) return;
  1112. const getHtml = function (list) {
  1113. if (!list || list.length === 0) return '';
  1114. const html = [];
  1115. for (const l of list) {
  1116. html.push('<div class="row mr-1">');
  1117. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  1118. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  1119. html.push('</div>');
  1120. }
  1121. return html.join('');
  1122. };
  1123. return getHtml(billsTag.getBillsTagsInfo(data.id));
  1124. }
  1125. },
  1126. },
  1127. ];
  1128. // ledgerSpreadSetting.cols.push(
  1129. // {title: 'ledger_id', colSpan: '1', rowSpan: '2', field: 'ledger_id', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1130. // {title: 'ledger_pid', colSpan: '1', rowSpan: '2', field: 'ledger_pid', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1131. // {title: 'level', colSpan: '1', rowSpan: '2', field: 'level', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1132. // {title: 'order', colSpan: '1', rowSpan: '2', field: 'order', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1133. // {title: 'is_leaf', colSpan: '1', rowSpan: '2', field: 'is_leaf', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1134. // {title: 'full_path', colSpan: '1', rowSpan: '2', field: 'full_path', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1135. // {title: 'node_type', colSpan: '1', rowSpan: '2', field: 'node_type', hAlign: 2, width: 60, type: 'Number', readOnly: true}
  1136. // );
  1137. sjsSettingObj.setNodeTypeCol(ledgerSpreadSetting.cols, [{ field: 'node_type' }]);
  1138. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  1139. SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
  1140. // 绑定事件
  1141. ledgerSpread.bind(spreadNS.Events.SelectionChanged, treeOperationObj.selectionChanged);
  1142. ledgerSpread.bind(spreadNS.Events.TopRowChanged, treeOperationObj.topRowChanged);
  1143. ledgerSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1144. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1145. SpreadJsObj.Clipboard.setCopyData(copyText);
  1146. });
  1147. if (!ledgerSpreadSetting.readOnly) {
  1148. ledgerSpread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1149. treeOperationObj.refreshOperationValid(info.sheet, info.newSelections);
  1150. });
  1151. ledgerSpread.bind(spreadNS.Events.EditEnded, treeOperationObj.editEnded);
  1152. SpreadJsObj.addDeleteBind(ledgerSpread, treeOperationObj.deletePress);
  1153. ledgerSpread.bind(spreadNS.Events.ClipboardPasting, treeOperationObj.clipboardPasting);
  1154. ledgerSpread.bind(spreadNS.Events.EditStarting, treeOperationObj.editStarting);
  1155. SpreadJsObj.addCutEvents(ledgerSpread, treeOperationObj.cut);
  1156. // 绑定 删除等 顶部按钮
  1157. $('#insert').click(() => {
  1158. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  1159. });
  1160. $('#delete').click(function () {
  1161. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  1162. });
  1163. $('#up-move').click(function () {
  1164. treeOperationObj.upMove(ledgerSpread.getActiveSheet());
  1165. });
  1166. $('#down-move').click(function () {
  1167. treeOperationObj.downMove(ledgerSpread.getActiveSheet());
  1168. });
  1169. $('#up-level').click(function () {
  1170. treeOperationObj.upLevel(ledgerSpread.getActiveSheet());
  1171. });
  1172. $('#down-level').click(function () {
  1173. treeOperationObj.downLevel(ledgerSpread.getActiveSheet());
  1174. });
  1175. $('#copy').click(function () {
  1176. ledgerSpread.commandManager().execute({
  1177. cmd: 'copy',
  1178. sheetName: ledgerSpread.getActiveSheet().name()
  1179. });
  1180. });
  1181. $('#paste').click(function () {
  1182. ledgerSpread.commandManager().execute({
  1183. cmd: 'paste',
  1184. sheetName: ledgerSpread.getActiveSheet().name()
  1185. });
  1186. });
  1187. $('#cut').click(function () {
  1188. ledgerSpread.commandManager().execute({
  1189. cmd: 'cut',
  1190. sheetName: ledgerSpread.getActiveSheet().name()
  1191. });
  1192. });
  1193. $('#bills-expr').bind('change onblur', function () {
  1194. const expr = $(this);
  1195. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1196. const select = ledgerTree.getItemsByIndex(row);
  1197. if (!select) return;
  1198. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1199. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1200. // 台账模式,检查计量单元相关
  1201. if (checkTzMeasureType()) {
  1202. if (field === 'sgfh_qty' || field === 'sgfh_tp' ||
  1203. field === 'sjcl_qty' || field === 'sjcl_tp' ||
  1204. field === 'qtcl_qty' || field === 'qtcl_tp' ||
  1205. field === 'ex_qty1' || field === 'ex_tp1') {
  1206. if (!select.children || select.children.length === 0) {
  1207. const lPos = pos.getLedgerPos(select.id);
  1208. if (lPos && lPos.length > 0) {
  1209. toastr.error('清单含有计量单元,请在计量单元输入数量');
  1210. expr.val('');
  1211. return;
  1212. }
  1213. }
  1214. }
  1215. }
  1216. const data = {
  1217. id: select.id,
  1218. tender_id: select.tender_id,
  1219. ledger_id: select.ledger_id
  1220. };
  1221. const exprInfo = getExprInfo(field);
  1222. if (newValue !== '') {
  1223. const num = _.toNumber(newValue);
  1224. if (num) {
  1225. data[field] = num;
  1226. if (exprInfo) {
  1227. data[exprInfo.expr] = '';
  1228. }
  1229. } else {
  1230. try {
  1231. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  1232. if (exprInfo) {
  1233. data[exprInfo.expr] = newValue;
  1234. }
  1235. } catch (err) {
  1236. toastr.error('输入的表达式非法');
  1237. return;
  1238. }
  1239. }
  1240. } else {
  1241. data[field] = null;
  1242. if (exprInfo) {
  1243. data[exprInfo.expr] = '';
  1244. }
  1245. }
  1246. // 更新至服务器
  1247. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1248. const refreshNode = ledgerTree.loadPostData(result);
  1249. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  1250. });
  1251. });
  1252. }
  1253. let batchInsertObj, contractExprObj;
  1254. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1255. const self = this;
  1256. if ($.isFunction(item.icon)) {
  1257. item._icon = item.icon.call(this, this, $t, key, item);
  1258. } else {
  1259. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1260. // to enable font awesome
  1261. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1262. } else {
  1263. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1264. }
  1265. }
  1266. this.addClass(item._icon);
  1267. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  1268. .appendTo(this);
  1269. const $input = $obj.find('input');
  1270. const event = () => {
  1271. if (self.hasClass('context-menu-disabled')) return;
  1272. item.batchInsert($input[0], root);
  1273. };
  1274. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1275. $input.click((e) => {e.stopPropagation();})
  1276. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1277. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1278. };
  1279. // $.contextMenu.types.switch = function (item, opt, root) {
  1280. // const self = this;
  1281. // if ($.isFunction(item.icon)) {
  1282. // item._icon = item.icon.call(this, this, $t, key, item);
  1283. // } else {
  1284. // if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1285. // // to enable font awesome
  1286. // item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1287. // } else {
  1288. // item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1289. // }
  1290. // }
  1291. // const html = [];
  1292. // html.push('<div>');
  1293. // html.push('</div>');
  1294. // const $obj = $('<div>' + item.name +)
  1295. // };
  1296. // 右键菜单
  1297. const addTag = newTag({ledgerSheet: ledgerSpread.getActiveSheet(), posSheet: posSpread.getActiveSheet(), billsTag});
  1298. const billsContextMenuOptions = {
  1299. selector: '#ledger-spread',
  1300. build: function ($trigger, e) {
  1301. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
  1302. treeOperationObj.loadRelaData();
  1303. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1304. },
  1305. items: {},
  1306. };
  1307. if (!readOnly) {
  1308. billsContextMenuOptions.items.create = {
  1309. name: '新增',
  1310. icon: 'fa-sign-in',
  1311. callback: function (key, opt) {
  1312. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  1313. },
  1314. disabled: function (key, opt) {
  1315. const sheet = ledgerSpread.getActiveSheet();
  1316. const selection = sheet.getSelections();
  1317. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1318. const row = sel ? sel.row : -1;
  1319. const tree = sheet.zh_tree;
  1320. if (!tree) return true;
  1321. const first = sheet.zh_tree.nodes[row];
  1322. let last = first, sameParent = true;
  1323. if (sel.rowCount > 1) {
  1324. for (let r = 1; r < sel.rowCount; r++) {
  1325. const rNode = tree.nodes[sel.row + r];
  1326. if (rNode.level > first.level) continue;
  1327. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1328. sameParent = false;
  1329. break;
  1330. }
  1331. last = rNode;
  1332. }
  1333. }
  1334. const valid = !sheet.zh_setting.readOnly;
  1335. return !(valid && first && first.level > 1);
  1336. },
  1337. visible: function (key, opt) {
  1338. return !readOnly;
  1339. }
  1340. };
  1341. billsContextMenuOptions.items.delete = {
  1342. name: '删除',
  1343. icon: 'fa-remove',
  1344. callback: function (key, opt) {
  1345. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  1346. },
  1347. disabled: function (key, opt) {
  1348. const sheet = ledgerSpread.getActiveSheet();
  1349. const selection = sheet.getSelections();
  1350. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1351. const row = sel ? sel.row : -1;
  1352. const tree = sheet.zh_tree;
  1353. if (!tree) return true;
  1354. const first = sheet.zh_tree.nodes[row];
  1355. let last = first, sameParent = true;
  1356. if (sel.rowCount > 1) {
  1357. for (let r = 1; r < sel.rowCount; r++) {
  1358. const rNode = tree.nodes[sel.row + r];
  1359. if (rNode.level > first.level) continue;
  1360. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1361. sameParent = false;
  1362. break;
  1363. }
  1364. last = rNode;
  1365. }
  1366. }
  1367. const valid = !sheet.zh_setting.readOnly;
  1368. return !(valid && first && sameParent && !(first.level === 1 && first.node_type));
  1369. },
  1370. visible: function (key, opt) {
  1371. return !readOnly;
  1372. }
  1373. };
  1374. billsContextMenuOptions.items.sprBase = '----';
  1375. }
  1376. if (!readOnly) {
  1377. billsContextMenuOptions.items.batchInsert = {
  1378. name: '批量插入',
  1379. type: 'batchInsert',
  1380. value: '2',
  1381. icon: 'fa-sign-in',
  1382. batchInsert: function (obj, root) {
  1383. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1384. obj.value = obj.max;
  1385. toastr.warning('批量插入不可多于' + obj.max);
  1386. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1387. obj.value = obj.min;
  1388. toastr.warning('批量插入不可少于' + obj.min);
  1389. } else {
  1390. treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  1391. root.$menu.trigger('contextmenu:hide');
  1392. }
  1393. },
  1394. disabled: function (key, opt) {
  1395. const sheet = ledgerSpread.getActiveSheet();
  1396. const selection = sheet.getSelections();
  1397. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1398. const row = sel ? sel.row : -1;
  1399. const tree = sheet.zh_tree;
  1400. if (!tree) return true;
  1401. const first = sheet.zh_tree.nodes[row];
  1402. let last = first, sameParent = true;
  1403. if (sel.rowCount > 1) {
  1404. for (let r = 1; r < sel.rowCount; r++) {
  1405. const rNode = tree.nodes[sel.row + r];
  1406. if (rNode.level > first.level) continue;
  1407. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1408. sameParent = false;
  1409. break;
  1410. }
  1411. last = rNode;
  1412. }
  1413. }
  1414. const valid = !sheet.zh_setting.readOnly;
  1415. return !(valid && first && first.level > 1);
  1416. },
  1417. visible: function (key, opt) {
  1418. return !readOnly;
  1419. }
  1420. };
  1421. billsContextMenuOptions.items.batchInsertBillsPos = {
  1422. name: '批量插入清单-计量单元',
  1423. icon: 'fa-sign-in',
  1424. disabled: function (key, opt) {
  1425. if (!checkTzMeasureType()) return true;
  1426. const sheet = ledgerSpread.getActiveSheet();
  1427. const selection = sheet.getSelections();
  1428. const row = selection[0].row;
  1429. const select = ledgerTree.nodes[row];
  1430. if (select) {
  1431. if (select.code && select.code !== '') {
  1432. return !ledgerTree.isLeafXmj(select);
  1433. } else {
  1434. const parent = ledgerTree.getParent(select);
  1435. return !(parent && ledgerTree.isLeafXmj(parent));
  1436. }
  1437. } else {
  1438. return true;
  1439. }
  1440. },
  1441. callback: function (key, opt) {
  1442. if (!batchInsertObj) {
  1443. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1444. } else {
  1445. batchInsertObj.initView();
  1446. }
  1447. $('#batch').modal('show');
  1448. },
  1449. visible: function (key, opt) {
  1450. return !readOnly;
  1451. }
  1452. };
  1453. billsContextMenuOptions.items.batchReplace = {
  1454. name: '批量替换清单',
  1455. icon: 'fa-sign-in',
  1456. callback: function(key, opt) {
  1457. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  1458. if (!node) return;
  1459. BatchReplace.load(node.b_code, node.name, node.unit, node.unit_price, treeOperationObj.batchReplace);
  1460. },
  1461. disabled: function (key, opt) {
  1462. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  1463. return !node || !node.b_code;
  1464. },
  1465. visible: function (key, opt) {
  1466. return !readOnly;
  1467. }
  1468. };
  1469. billsContextMenuOptions.items.sprBatch = '----';
  1470. }
  1471. billsContextMenuOptions.items.copyBlock = {
  1472. name: '复制整块',
  1473. icon: 'fa-files-o',
  1474. callback: function (key, opt) {
  1475. /*ledgerSpread.commandManager().execute({
  1476. cmd:"copy",
  1477. sheetName:ledgerSpread.getActiveSheet().name()
  1478. });*/
  1479. treeOperationObj.block = [];
  1480. const copyBlockList = [];
  1481. const sheet = ledgerSpread.getActiveSheet();
  1482. const sel = sheet.getSelections()[0];
  1483. let iRow = sel.row;
  1484. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1485. while (iRow < sel.row + sel.rowCount) {
  1486. const node = sheet.zh_tree.nodes[iRow];
  1487. if (node.ledger_pid !== pid) {
  1488. toastr.error('仅可同时选中同层节点');
  1489. return;
  1490. }
  1491. const posterity = sheet.zh_tree.getPosterity(node);
  1492. iRow += posterity.length + 1;
  1493. posterity.unshift(node);
  1494. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1495. }
  1496. for (const cbl of copyBlockList) {
  1497. for (const b of cbl) {
  1498. const posRange = pos.getLedgerPos(b.id);
  1499. if (posRange && posRange.length > 0) b.pos = posRange;
  1500. const gclRange = ancGcl.getPartData(b.id);
  1501. if (gclRange && gclRange.length > 0) b.ancGcl = gclRange;
  1502. }
  1503. }
  1504. setLocalCache(copyBlockTag, JSON.stringify({block: copyBlockList}));
  1505. },
  1506. visible: function (key, opt) {
  1507. const sheet = ledgerSpread.getActiveSheet();
  1508. const selection = sheet.getSelections();
  1509. const row = selection[0].row;
  1510. const select = ledgerTree.nodes[row];
  1511. return select;
  1512. },
  1513. disabled: function (key, opt) {
  1514. const sheet = ledgerSpread.getActiveSheet();
  1515. const selection = sheet.getSelections();
  1516. const row = selection[0].row;
  1517. const select = ledgerTree.nodes[row];
  1518. return select && select.level <= 1;
  1519. }
  1520. };
  1521. billsContextMenuOptions.items.copyBlockXmj = {
  1522. name: '复制整块(只复制项目节)',
  1523. icon: 'fa-files-o',
  1524. callback: function (key, opt) {
  1525. treeOperationObj.block = [];
  1526. const copyBlockList = [];
  1527. const sheet = ledgerSpread.getActiveSheet();
  1528. const sel = sheet.getSelections()[0];
  1529. let iRow = sel.row;
  1530. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1531. while (iRow < sel.row + sel.rowCount) {
  1532. const node = sheet.zh_tree.nodes[iRow];
  1533. if (node.ledger_pid !== pid) {
  1534. toastr.error('仅可同时选中同层节点');
  1535. return;
  1536. }
  1537. const posterity = sheet.zh_tree.getPosterity(node);
  1538. iRow += posterity.length + 1;
  1539. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1540. copyPosterity.unshift(node);
  1541. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1542. for (const p of copyData) {
  1543. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1544. p.is_leaf = children.length === 0;
  1545. }
  1546. copyBlockList.push(copyData);
  1547. }
  1548. setLocalCache(copyBlockTag, JSON.stringify({block: copyBlockList}));
  1549. },
  1550. visible: function (key, opt) {
  1551. const sheet = ledgerSpread.getActiveSheet();
  1552. const selection = sheet.getSelections();
  1553. const row = selection[0].row;
  1554. const select = ledgerTree.nodes[row];
  1555. return select;
  1556. },
  1557. disabled: function (key, opt) {
  1558. const sheet = ledgerSpread.getActiveSheet();
  1559. const selection = sheet.getSelections();
  1560. const row = selection[0].row;
  1561. const select = ledgerTree.nodes[row];
  1562. return select && select.level <= 1;
  1563. }
  1564. };
  1565. if (!readOnly) {
  1566. billsContextMenuOptions.items.pasteBlock = {
  1567. name: '粘贴整块',
  1568. icon: 'fa-clipboard',
  1569. disabled: function (key, opt) {
  1570. //const block = treeOperationObj.block || [];
  1571. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1572. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1573. },
  1574. callback: function (key, opt) {
  1575. //const block = treeOperationObj.block || [];
  1576. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1577. if (copyInfo.block.length > 0) {
  1578. treeOperationObj.pasteBlock(ledgerSpread, copyInfo);
  1579. } else {
  1580. document.execCommand('paste');
  1581. }
  1582. },
  1583. visible: function (key, opt) {
  1584. return !readOnly;
  1585. }
  1586. };
  1587. }
  1588. billsContextMenuOptions.items.sprBlock = '----';
  1589. if (!readOnly) {
  1590. billsContextMenuOptions.items.sortChildren = {
  1591. name: '顺序重排子项编号',
  1592. icon: 'fa-sort-numeric-asc',
  1593. disabled: function (key, opt) {
  1594. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1595. return !node || !node.code || !node.children || node.children === 0 || node.code.length < 3;
  1596. },
  1597. callback: function (key, opt) {
  1598. treeOperationObj.sortCode(ledgerSpread.getActiveSheet());
  1599. },
  1600. visible: function (key, opt) {
  1601. return !readOnly;
  1602. }
  1603. };
  1604. if (!checkTzMeasureType()) {
  1605. billsContextMenuOptions.items.applyDeal2Sgfh = {
  1606. name: '填设计量',
  1607. icon: 'fa-pencil',
  1608. callback: function (key, opt) {
  1609. postData(window.location.pathname + '/deal2sgfh', null, function (result) {
  1610. ledgerTree.loadDatas(result.bills);
  1611. treeCalc.calculateAll(ledgerTree);
  1612. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1613. });
  1614. }
  1615. };
  1616. billsContextMenuOptions.items.applySgfh2Deal = {
  1617. name: '填签约量',
  1618. icon: 'fa-pencil',
  1619. callback: function (key, opt) {
  1620. postData(window.location.pathname + '/sgfh2deal', null, function (result) {
  1621. ledgerTree.loadDatas(result.bills);
  1622. treeCalc.calculateAll(ledgerTree);
  1623. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1624. });
  1625. }
  1626. };
  1627. }
  1628. billsContextMenuOptions.items.sprSort = '----';
  1629. }
  1630. if (!readOnly) {
  1631. const tenderSelect = TenderSelect({
  1632. type: 'ledger',
  1633. afterLoad: function (result, select) {
  1634. const ledgerSheet = ledgerSpread.getActiveSheet();
  1635. const refreshNode = ledgerTree.loadPostData(result);
  1636. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1637. treeOperationObj.refreshPosterity(ledgerSheet, select);
  1638. treeOperationObj.refreshOperationValid(ledgerSheet);
  1639. }
  1640. });
  1641. billsContextMenuOptions.items.importExcel = {
  1642. name: '导入分项清单Excel',
  1643. icon: 'fa-file-excel-o',
  1644. disabled: function (key, opt) {
  1645. return readOnly;
  1646. },
  1647. callback: function (key, opt) {
  1648. importExcel.doImport({
  1649. template: {
  1650. hint: '0号台账',
  1651. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/A/导入分项清单EXCEL格式.xlsx',
  1652. },
  1653. filter: true,
  1654. callback: function (sheet, filter) {
  1655. postDataCompress(window.location.pathname + '/upload-excel/tz', {sheet, filter}, function (result) {
  1656. ledgerTree.loadDatas(result.bills);
  1657. treeCalc.calculateAll(ledgerTree);
  1658. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1659. pos.loadDatas(result.pos);
  1660. posOperationObj.loadCurPosData();
  1661. ancGclObj.loadCurAncillaryGcl();
  1662. checkShowLast(result.bills.length);
  1663. }, null);
  1664. },
  1665. // callback: function (file, select) {
  1666. // const formData = new FormData();
  1667. // formData.append('file', file.files[0]);
  1668. // postDataWithFileProgress(window.location.pathname + '/upload-excel?ueType=tz&sheetName=' + select, formData, function (result) {
  1669. // ledgerTree.loadDatas(result.bills);
  1670. // treeCalc.calculateAll(ledgerTree);
  1671. // SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1672. // pos.loadDatas(result.pos);
  1673. // posOperationObj.loadCurPosData();
  1674. // }, null);
  1675. // }
  1676. //u_type: importExcel.uploadType.file,
  1677. });
  1678. }
  1679. };
  1680. billsContextMenuOptions.items.importGclBills2Xmj = {
  1681. name: '导入工程量清单至项目节',
  1682. icon: 'fa-file-excel-o',
  1683. disabled: function (key, opt) {
  1684. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1685. return readOnly || !node
  1686. || (node.children && node.children.length > 0)
  1687. || (!_.isNil(node.b_code) && node.b_code !== '');
  1688. },
  1689. callback: function (key, opt) {
  1690. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1691. importExcel.doImport({
  1692. template: {
  1693. hint: '工程量清单',
  1694. url: '/template/导入工程量清单EXCEL格式.xls',
  1695. },
  1696. callback: function (sheet) {
  1697. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  1698. const ledgerSheet = ledgerSpread.getActiveSheet();
  1699. const sel = ledgerSheet.getSelections();
  1700. const refreshNode = ledgerTree.loadPostData(result);
  1701. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1702. if (refreshNode.create[0]) {
  1703. if (sel && sel[0]) {
  1704. ledgerSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  1705. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [sel[0].row, refreshNode.create[0].index]);
  1706. } else {
  1707. ledgerSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  1708. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [refreshNode.create[0].index]);
  1709. }
  1710. }
  1711. treeOperationObj.refreshOperationValid(ledgerSheet);
  1712. }, null);
  1713. }
  1714. });
  1715. }
  1716. };
  1717. billsContextMenuOptions.items.importOtherTender = {
  1718. name: '导入(其他标段)工程量清单至项目节',
  1719. icon: 'fa-link',
  1720. disabled: function (key, opt) {
  1721. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1722. return readOnly || !node
  1723. || (node.children && node.children.length > 0)
  1724. || !ledgerTree.isLeafXmj(node);
  1725. },
  1726. callback: function (key, opt) {
  1727. tenderSelect.showSelect(SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet()));
  1728. }
  1729. };
  1730. billsContextMenuOptions.items.sprImport = '----';
  1731. }
  1732. billsContextMenuOptions.items.tag = {
  1733. name: '书签',
  1734. callback: function (key, opt, menu, e) {
  1735. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1736. addTag.do(node);
  1737. },
  1738. disabled: function (key, opt) {
  1739. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1740. return !node;
  1741. }
  1742. };
  1743. billsContextMenuOptions.items.sprTag = '----';
  1744. billsContextMenuOptions.items.showLast = {
  1745. name: '显示至最底层',
  1746. callback: function (key, opt, menu, e) {
  1747. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1748. setTimeout(() => {
  1749. showWaitingView();
  1750. ledgerTree.expandByCustom(x => {
  1751. return x.expanded ||(x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1752. });
  1753. SpreadJsObj.refreshTreeRowVisible(ledgerSpread.getActiveSheet());
  1754. closeWaitingView();
  1755. }, 100);
  1756. },
  1757. };
  1758. billsContextMenuOptions.items.exportJSON = {
  1759. name: '导出后台标准表json',
  1760. callback: function (key, opt, menu, e) {
  1761. const result = [];
  1762. for (const node of ledgerTree.nodes) {
  1763. result.push({
  1764. id: node.ledger_id, pid: node.ledger_pid, level: node.level, order: node.order,
  1765. is_leaf: !node.children || node.children.length === 0, full_path: node.full_path,
  1766. code: node.code || '', b_code: node.b_code || '', name: node.name || '', unit: node.unit || '',
  1767. node_type: node.node_type,
  1768. });
  1769. }
  1770. const blob = new Blob([JSON.stringify(result, '', '\t')], { type: 'application/text'});
  1771. saveAs(blob, "台账分解.json");
  1772. },
  1773. visible: function() {
  1774. return is_debug;
  1775. }
  1776. };
  1777. if (contractExpr && readOnly) {
  1778. billsContextMenuOptions.items.exprTag = '----';
  1779. billsContextMenuOptions.items.contractExpr = {
  1780. name: '预设本期合同计量公式',
  1781. callback: function (key, opt, menu, e) {
  1782. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1783. if (!contractExprObj) {
  1784. contractExprObj = new ContractExpr({ sourceTree: ledgerTree });
  1785. }
  1786. contractExprObj.initView(node);
  1787. $('#contract_expr').modal('show');
  1788. },
  1789. visible: function (key, opt) {
  1790. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1791. if (node.children && node.children.length > 0) return false;
  1792. const posRange = pos.getLedgerPos(node.id);
  1793. if (posRange && posRange.length > 0) return false;
  1794. return true;
  1795. }
  1796. };
  1797. }
  1798. $.contextMenu(billsContextMenuOptions);
  1799. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  1800. // 台账模式加载计量单元数据
  1801. if (checkTzMeasureType()) {
  1802. $.divResizer({
  1803. select: '#main-resize',
  1804. callback: function () {
  1805. ledgerSpread.refresh();
  1806. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1807. $(".sp-wrap").height(bcontent-30);
  1808. posSpread.refresh();
  1809. if (ancGclSpread) ancGclSpread.refresh();
  1810. }
  1811. });
  1812. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  1813. }
  1814. posSpreadSetting.headColWidth = [50];
  1815. posSpreadSetting.rowHeader = [
  1816. {
  1817. rowHeaderType: 'tag',
  1818. setting: {
  1819. indent: 14,
  1820. tagSize: 0.8,
  1821. tagFont: '8px 微软雅黑',
  1822. getColor: function (index, data) {
  1823. if (!data) return;
  1824. return billsTag.getPosTagsColor(data.lid, data.id);
  1825. },
  1826. getTagHtml: function (index, data) {
  1827. if (!data) return;
  1828. const getHtml = function (list) {
  1829. if (!list || list.length === 0) return '';
  1830. const html = [];
  1831. for (const l of list) {
  1832. html.push('<div class="row mr-1">');
  1833. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  1834. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  1835. html.push('</div>');
  1836. }
  1837. return html.join('');
  1838. };
  1839. return getHtml(billsTag.getPosTagsInfo(data.lid, data.id));
  1840. }
  1841. },
  1842. },
  1843. ];
  1844. SpreadJsObj.initSheet(posSpread.getActiveSheet(), posSpreadSetting);
  1845. //绑定计量单元编辑事件
  1846. const posOperationObj = {
  1847. /**
  1848. * 刷新顶部按钮是否可用
  1849. * @param sheet
  1850. * @param selections
  1851. */
  1852. refreshOperationValid: function (sheet, selection) {
  1853. const setObjEnable = function (obj, enable) {
  1854. if (enable) {
  1855. obj.removeClass('disabled');
  1856. } else {
  1857. obj.addClass('disabled');
  1858. }
  1859. };
  1860. const invalidAll = function () {
  1861. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1862. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1863. };
  1864. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1865. const row = sel ? sel.row : -1;
  1866. const first = sheet.zh_data[row];
  1867. if (!first) {
  1868. invalidAll();
  1869. return;
  1870. }
  1871. let last = first;
  1872. if (sel.rowCount > 1 && first) {
  1873. for (let r = 1; r < sel.rowCount; r++) {
  1874. const rNode = sheet.zh_data[sel.row + r];
  1875. if (!rNode) break;
  1876. last = rNode;
  1877. }
  1878. }
  1879. const preNode = sheet.zh_data[row - 1];
  1880. const valid = !sheet.zh_setting.readOnly;
  1881. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode);
  1882. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1));
  1883. },
  1884. editStarting: function (e, info) {
  1885. posOperationObj.ledgerTreeNode = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1886. const sel = info.sheet.getSelections();
  1887. if (!sel || !sel[0]) return;
  1888. const col = info.sheet.zh_setting.cols[sel[0].col];
  1889. const node = SpreadJsObj.getSelectObject(info.sheet);
  1890. const exprInfo = getExprInfo(col.field);
  1891. if (exprInfo) {
  1892. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1893. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1894. }
  1895. }
  1896. },
  1897. loadExprToInput: function () {
  1898. const sheet = posSpread.getActiveSheet();
  1899. const sel = sheet.getSelections()[0];
  1900. if (!sel || !sheet.zh_setting) return;
  1901. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1902. if (col && col.type === 'Number') {
  1903. const data = SpreadJsObj.getSelectObject(sheet);
  1904. if (data) {
  1905. const exprInfo = getExprInfo(col.field);
  1906. const value = exprInfo
  1907. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1908. : data[col.field];
  1909. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1910. .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
  1911. } else {
  1912. $('#pos-expr').val('').attr('readOnly', true);
  1913. $('#pos-expr').removeAttr('data-row');
  1914. }
  1915. } else {
  1916. $('#pos-expr').val('').attr('readOnly', true);
  1917. $('#pos-expr').removeAttr('data-row');
  1918. }
  1919. },
  1920. /**
  1921. * 加载计量单元 根据当前台账选择节点
  1922. */
  1923. loadCurPosData: function () {
  1924. //spreadJsObj.reinitSheet(posSpread.getActiveSheet());
  1925. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  1926. if (node) {
  1927. const posData = pos.ledgerPos[itemsPre + node.id] || [];
  1928. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', posData);
  1929. getNodeList(node.id);
  1930. } else {
  1931. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', []);
  1932. }
  1933. posOperationObj.loadExprToInput();
  1934. posOperationObj.refreshOperationValid(posSpread.getActiveSheet());
  1935. },
  1936. baseOpr: function (sheet, type) {
  1937. const data = {
  1938. updateType: type === 'delete' ? type : 'update',
  1939. updateData: [],
  1940. };
  1941. const selection = sheet.getSelections();
  1942. const row = selection[0].row, count = selection[0].rowCount;
  1943. const first = sheet.zh_data[row];
  1944. if (type === 'delete') {
  1945. for (let iRow = 0; iRow < count; iRow++) {
  1946. const posData = sheet.zh_data[iRow + row];
  1947. if (posData) {
  1948. data.updateData.push(sheet.zh_data[iRow + row].id);
  1949. }
  1950. }
  1951. } else if (type === 'up-move') {
  1952. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1953. for (let iRow = 0; iRow < count; iRow++) {
  1954. const posData = sheet.zh_data[iRow + row];
  1955. if (posData) {
  1956. data.updateData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1957. preUpdate.porder = posData.porder;
  1958. }
  1959. }
  1960. data.updateData.push(preUpdate);
  1961. } else if (type === 'down-move') {
  1962. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1963. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1964. const posData = sheet.zh_data[iRow + row];
  1965. if (posData) {
  1966. data.updateData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1967. nextUpdate.porder = posData.porder;
  1968. }
  1969. }
  1970. data.updateData.push(nextUpdate);
  1971. }
  1972. if (data.updateData.length > 0) {
  1973. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1974. if (type === 'delete') {
  1975. for (const p of result.pos) {
  1976. const posInfo = pos.getPos(p);
  1977. billsTag.afterDeletePos([posInfo]);
  1978. }
  1979. pos.removeDatas(result.pos);
  1980. sheet.deleteRows(row, count);
  1981. const loadResult = ledgerTree.loadPostData(result.ledger);
  1982. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1983. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1984. } else {
  1985. const updateRst = pos.updateDatas(result.pos);
  1986. billsTag.refreshPosTagView(updateRst.update);
  1987. const sel = selection[0];
  1988. if (sel) {
  1989. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1990. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1991. }
  1992. posOperationObj.loadCurPosData();
  1993. }
  1994. });
  1995. }
  1996. },
  1997. /**
  1998. * 编辑单元格响应事件
  1999. * @param {Object} e
  2000. * @param {Object} info
  2001. */
  2002. editEnded: function (e, info) {
  2003. if (info.sheet.zh_setting) {
  2004. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  2005. const col = info.sheet.zh_setting.cols[info.col];
  2006. const orgText = posData ? posData[col.field] : null;
  2007. const newText = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  2008. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) {
  2009. return;
  2010. }
  2011. const node = posOperationObj.ledgerTreeNode;
  2012. if (!node) {
  2013. toastr.error('数据错误,请选择台账节点后再试');
  2014. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2015. return;
  2016. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  2017. toastr.error('父节点不可插入计量单元');
  2018. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2019. return;
  2020. }else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  2021. toastr.error('项目节不可插入计量单元');
  2022. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2023. return;
  2024. }
  2025. const data = { updateType: posData ? 'update' : 'add' };
  2026. if (!posData) {
  2027. const sortData = info.sheet.zh_data;
  2028. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2029. data.updateData = { lid: node.id, tid: tender.id, porder: order };
  2030. } else {
  2031. data.updateData = { id: posData.id };
  2032. }
  2033. if (col.type === 'Number') {
  2034. const exprInfo = getExprInfo(col.field);
  2035. const num = _.toNumber(newText);
  2036. if (_.isFinite(num)) {
  2037. data.updateData[col.field] = num;
  2038. if (exprInfo) {
  2039. data.updateData[exprInfo.expr] = '';
  2040. }
  2041. } else {
  2042. try {
  2043. data.updateData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2044. if (exprInfo) {
  2045. data.updateData[exprInfo.expr] = newText;
  2046. }
  2047. } catch(err) {
  2048. toastr.error('输入的表达式非法');
  2049. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2050. return;
  2051. }
  2052. }
  2053. } else if (col.field.indexOf('_expr') > 0) {
  2054. const exprInfo = getExprInfo(col.field, true);
  2055. if (!exprInfo) return;
  2056. if (newText) {
  2057. try {
  2058. data.updateData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2059. data.updateData[exprInfo.expr] = newText;
  2060. } catch(err) {
  2061. toastr.error('输入的表达式非法');
  2062. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2063. return;
  2064. }
  2065. } else {
  2066. data.updateData[exprInfo.qty] = 0;
  2067. data.updateData[exprInfo.expr] = '';
  2068. }
  2069. } else {
  2070. data.updateData[col.field] = newText;
  2071. }
  2072. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  2073. const updateRst = pos.updateDatas(result.pos);
  2074. billsTag.refreshPosTagView(updateRst.update);
  2075. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2076. if (updateRst.create.length > 0) {
  2077. // info.sheet.addRows(info.row, 1);
  2078. // if (info.sheet.zh_data.length === 0) {
  2079. // info.sheet.zh_data = pos.ledgerPos[itemsPre + node.id] || [];
  2080. // }
  2081. // SpreadJsObj.reLoadRowData(info.sheet, info.sheet.zh_data.length - 1);
  2082. posOperationObj.loadCurPosData();
  2083. } else {
  2084. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2085. }
  2086. const loadResult = ledgerTree.loadPostData(result.ledger);
  2087. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2088. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2089. }, function () {
  2090. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2091. });
  2092. }
  2093. },
  2094. /**
  2095. * 删除按钮响应事件
  2096. * @param sheet
  2097. */
  2098. deletePress: function (sheet) {
  2099. const self = this;
  2100. if (sheet.zh_setting) {
  2101. const sortData = sheet.zh_data;
  2102. const datas = [], posSelects = [];
  2103. const sel = sheet.getSelections()[0];
  2104. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2105. let bDel = false;
  2106. const node = sortData[iRow];
  2107. if (node) {
  2108. const data = {id: node.id};
  2109. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2110. const colSetting = sheet.zh_setting.cols[iCol];
  2111. const style = sheet.getStyle(iRow, iCol);
  2112. if (!style.locked) {
  2113. const colSetting = sheet.zh_setting.cols[iCol];
  2114. if (colSetting.field.indexOf('_expr') > 0) {
  2115. const exprInfo = getExprInfo(colSetting.field, true);
  2116. if (!exprInfo) continue;
  2117. data[exprInfo.expr] = '';
  2118. data[exprInfo.qty] = 0;
  2119. } else {
  2120. data[colSetting.field] = null;
  2121. const exprInfo = getExprInfo(colSetting.field);
  2122. if (exprInfo) data[exprInfo.expr] = '';
  2123. }
  2124. bDel = true;
  2125. }
  2126. }
  2127. if (bDel) {
  2128. datas.push(data);
  2129. posSelects.push(node);
  2130. }
  2131. }
  2132. }
  2133. if (datas.length > 0) {
  2134. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: datas}, function (result) {
  2135. const updateRst = pos.updateDatas(result.pos);
  2136. billsTag.refreshPosTagView(updateRst.update);
  2137. posOperationObj.loadCurPosData();
  2138. const loadResult = ledgerTree.loadPostData(result.ledger);
  2139. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2140. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2141. }, function () {
  2142. posOperationObj.loadCurPosData();
  2143. });
  2144. }
  2145. }
  2146. },
  2147. /**
  2148. * 删除 计量单元
  2149. * @param sheet
  2150. */
  2151. deletePos: function (sheet) {
  2152. const selection = sheet.getSelections();
  2153. const data = {
  2154. updateType: 'delete',
  2155. updateData: [],
  2156. };
  2157. const row = selection[0].row, count = selection[0].rowCount;
  2158. const sortData = sheet.zh_data;
  2159. for (let iRow = 0; iRow < count; iRow++) {
  2160. if (sortData[iRow + row]) {
  2161. data.updateData.push(sortData[iRow + row].id);
  2162. }
  2163. }
  2164. if (data.updateData.length > 0) {
  2165. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  2166. for (const p of result.pos) {
  2167. const posInfo = pos.getPos(p);
  2168. billsTag.afterDeletePos([posInfo]);
  2169. }
  2170. pos.removeDatas(result.pos);
  2171. sheet.deleteRows(row, count);
  2172. const loadResult = ledgerTree.loadPostData(result.ledger);
  2173. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2174. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2175. });
  2176. }
  2177. },
  2178. insertPos: function (sheet) {
  2179. const selection = sheet.getSelections();
  2180. const sortData = sheet.zh_data;
  2181. const row = selection[0].row;
  2182. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2183. const select = SpreadJsObj.getSelectObject(sheet);
  2184. const porder = select ? select.porder : sortData.length + 1;
  2185. const data = {
  2186. updateType: 'insert',
  2187. updateData: [ { lid: node.id, tid: tender.id, porder } ],
  2188. };
  2189. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  2190. const updateRst = pos.updateDatas(result.pos);
  2191. posOperationObj.loadCurPosData();
  2192. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2193. });
  2194. },
  2195. /**
  2196. * 粘贴单元格响应事件
  2197. * @param e
  2198. * @param info
  2199. */
  2200. clipboardPasted: function (e, info) {
  2201. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2202. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2203. }
  2204. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  2205. if (node.code && (node.code !== '')) {
  2206. toastr.error('项目节不可含有清单明细');
  2207. posOperationObj.loadCurPosData();
  2208. return;
  2209. }
  2210. if (node.children && (node.children.length > 0)) {
  2211. toastr.error('仅清单子项可以含有计量单元');
  2212. posOperationObj.loadCurPosData();
  2213. return;
  2214. }
  2215. const hint = {
  2216. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2217. };
  2218. if (info.sheet.zh_setting) {
  2219. const data = [];
  2220. const sortData = info.sheet.zh_data || [];
  2221. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  2222. const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
  2223. if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
  2224. toastr.warning('新增计量单元请先输入名称');
  2225. posOperationObj.loadCurPosData();
  2226. return;
  2227. }
  2228. }
  2229. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2230. let filterExprFields = [];
  2231. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2232. let bPaste = false;
  2233. const curRow = info.cellRange.row + iRow;
  2234. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  2235. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2236. const curCol = info.cellRange.col + iCol;
  2237. const colSetting = info.sheet.zh_setting.cols[curCol];
  2238. if (!colSetting) continue;
  2239. const checkExprInfo = getExprInfo(colSetting.field);
  2240. if (checkExprInfo) filterExprFields.push(checkExprInfo.expr);
  2241. if (filterExprFields.indexOf(colSetting.field) >= 0) continue;
  2242. posData[colSetting.field] = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  2243. if (colSetting.type === 'Number') {
  2244. const exprInfo = getExprInfo(colSetting.field);
  2245. const num = _.toNumber(posData[colSetting.field]);
  2246. if (num) {
  2247. posData[colSetting.field] = num;
  2248. if (exprInfo) posData[exprInfo.expr] = '';
  2249. bPaste = true;
  2250. } else {
  2251. try {
  2252. if (exprInfo) posData[exprInfo.expr] = posData[colSetting.field];
  2253. posData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(posData[colSetting.field]));
  2254. bPaste = true;
  2255. } catch (err) {
  2256. delete posData[colSetting.field];
  2257. toastMessageUniq(hint.expr);
  2258. }
  2259. }
  2260. } else if (colSetting.field.indexOf('_expr') > 0) {
  2261. try {
  2262. const exprInfo = getExprInfo(colSetting.field, true);
  2263. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2264. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  2265. posData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(posData[exprInfo.expr]));
  2266. }
  2267. bPaste = true;
  2268. } catch (err) {
  2269. toastMessageUniq(hint.expr);
  2270. }
  2271. } else {
  2272. bPaste = true;
  2273. }
  2274. }
  2275. if (bPaste) {
  2276. data.push(posData);
  2277. }
  2278. }
  2279. if (data.length > 0) {
  2280. postData('/tender/' + getTenderId() + '/pos/paste', data, function (result) {
  2281. const updateRst = pos.updateDatas(result.pos);
  2282. billsTag.refreshPosTagView(updateRst.update);
  2283. posOperationObj.loadCurPosData();
  2284. const loadResult = ledgerTree.loadPostData(result.ledger);
  2285. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2286. posOperationObj.loadCurPosData();
  2287. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2288. }, function () {
  2289. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2290. });
  2291. } else {
  2292. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2293. }
  2294. }
  2295. },
  2296. selectionChanged: function (e, info) {
  2297. posOperationObj.loadExprToInput();
  2298. posOperationObj.refreshOperationValid(posSpread.getActiveSheet());
  2299. },
  2300. addPegs: function (pegs) {
  2301. if (!pegs || pegs.length <= 0) return;
  2302. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2303. if (!node) return;
  2304. const sheet = posSpread.getActiveSheet();
  2305. const sortData = sheet.zh_data || [];
  2306. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2307. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2308. postData('/tender/' + getTenderId() + '/pos/paste', pegs, function (result) {
  2309. pos.updateDatas(result.pos);
  2310. posOperationObj.loadCurPosData();
  2311. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2312. });
  2313. }
  2314. };
  2315. posSpread.bind(spreadNS.Events.SelectionChanged, posOperationObj.selectionChanged);
  2316. if (!posSpreadSetting.readOnly) {
  2317. $('a[name="pos-opr"]').click(function () {
  2318. posOperationObj.baseOpr(posSpread.getActiveSheet(), this.getAttribute('type'));
  2319. });
  2320. $('#pos-expr').bind('change onblur', function () {
  2321. const expr = $(this);
  2322. const posSheet = posSpread.getActiveSheet();
  2323. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2324. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2325. if (!select) return;
  2326. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2327. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2328. const data = {id: select.id};
  2329. const exprInfo = getExprInfo(field);
  2330. if (newValue !== '') {
  2331. const num = _.toNumber(newValue);
  2332. if (num) {
  2333. data[field] = num;
  2334. if (exprInfo) {
  2335. data[exprInfo.expr] = '';
  2336. }
  2337. } else {
  2338. try {
  2339. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2340. if (exprInfo) {
  2341. data[exprInfo.expr] = newValue;
  2342. }
  2343. } catch (err) {
  2344. toastr.error('输入的表达式非法');
  2345. return;
  2346. }
  2347. }
  2348. } else {
  2349. data[field] = null;
  2350. if (exprInfo) {
  2351. data[exprInfo.expr] = '';
  2352. }
  2353. }
  2354. // 更新至服务器
  2355. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: data}, function (result) {
  2356. const updateRst = pos.updateDatas(result.pos);
  2357. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2358. const loadResult = ledgerTree.loadPostData(result.ledger);
  2359. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2360. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2361. });
  2362. });
  2363. SpreadJsObj.addDeleteBind(posSpread, posOperationObj.deletePress);
  2364. posSpread.bind(spreadNS.Events.EditStarting, posOperationObj.editStarting);
  2365. posSpread.bind(spreadNS.Events.EditEnded, posOperationObj.editEnded);
  2366. posSpread.bind(spreadNS.Events.ClipboardPasted, posOperationObj.clipboardPasted);
  2367. }
  2368. const mergePeg = NewMergePeg({ callback: posOperationObj.addPegs });
  2369. // 右键菜单
  2370. $.contextMenu({
  2371. selector: '#pos-spread',
  2372. build: function ($trigger, e) {
  2373. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  2374. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2375. },
  2376. items: {
  2377. 'insert': {
  2378. name: '插入',
  2379. icon: 'fa-plus',
  2380. disabled: function (key, opt) {
  2381. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2382. return node && node.children && node.children.length > 0;
  2383. },
  2384. callback: function (key, opt) {
  2385. posOperationObj.insertPos(posSpread.getActiveSheet());
  2386. },
  2387. visible: function(key, opt) {
  2388. return !readOnly;
  2389. }
  2390. },
  2391. 'delete': {
  2392. name: '删除',
  2393. icon: 'fa-remove',
  2394. disabled: function (key, opt) {
  2395. const sheet = posSpread.getActiveSheet();
  2396. if (sheet.zh_data) {
  2397. const selection = sheet.getSelections();
  2398. return sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2399. } else {
  2400. return true;
  2401. }
  2402. },
  2403. callback: function (key, opt) {
  2404. posOperationObj.deletePos(posSpread.getActiveSheet());
  2405. },
  2406. visible: function(key, opt) {
  2407. return !readOnly;
  2408. }
  2409. },
  2410. 'merge-peg': {
  2411. name: '合并起讫桩号',
  2412. disabled: function (key, opt) {
  2413. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2414. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  2415. },
  2416. callback: function (key, opt) {
  2417. mergePeg.show();
  2418. },
  2419. visible: function(key, opt) {
  2420. return !readOnly;
  2421. }
  2422. },
  2423. tag: {
  2424. name: '书签',
  2425. disabled: function(key, opt) {
  2426. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2427. const pos = SpreadJsObj.getSelectObject(posSpread.getActiveSheet());
  2428. return _.isNil(node) || _.isNil(pos);
  2429. },
  2430. callback: function(key, opt) {
  2431. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2432. const pos = SpreadJsObj.getSelectObject(posSpread.getActiveSheet());
  2433. addTag.do(node, pos);
  2434. }
  2435. }
  2436. }
  2437. });
  2438. // 附属工程量相关
  2439. const ancGclSpreadSetting = {
  2440. cols: [
  2441. {title: '辅材', colSpan: '1', rowSpan: '1', field: 'is_aux', hAlign: 1, width: 40, cellType: 'checkbox'},
  2442. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2443. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 40, formatter: '@', cellType: 'unit'},
  2444. {title: '设计量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  2445. {title: '设计量公式', colSpan: '1', rowSpan: '1', field: 'expr', hAlign: 0, width: 80, formatter: '@'},
  2446. {title: '图册号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  2447. {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 80, formatter: '@'},
  2448. ],
  2449. emptyRows: 3,
  2450. headRows: 1,
  2451. headRowHeight: [32],
  2452. headColWidth: [30],
  2453. defaultRowHeight: 21,
  2454. headerFont: '12px 微软雅黑',
  2455. font: '12px 微软雅黑',
  2456. };
  2457. SpreadJsObj.initSheet(ancGclSheet, ancGclSpreadSetting);
  2458. const ancGclObj = {
  2459. loadCurAncillaryGcl: function () {
  2460. const node = treeOperationObj.getSelectNode(ledgerSheet);
  2461. const gclData = node ? ancGcl.getPartData(node.id) || [] : [];
  2462. SpreadJsObj.loadSheetData(ancGclSheet, SpreadJsObj.DataType.Data, gclData);
  2463. },
  2464. baseOpr: function (type) {
  2465. const data = {};
  2466. const gclRange = ancGclSheet.zh_data;
  2467. if (type !== 'insert' && (!gclRange || gclRange.length === 0)) return;
  2468. const sel = ancGclSheet.getSelections();
  2469. if (!sel[0]) return;
  2470. const row = sel[0].row, count = sel[0].rowCount;
  2471. const first = gclRange[row];
  2472. if (type === 'insert') {
  2473. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  2474. data.add = [{ lid: node.id, g_order: gclRange.length + 1 }];
  2475. } else if (type === 'delete') {
  2476. data.del = [];
  2477. for (let iRow = 0; iRow < count; iRow++) {
  2478. const gclData = gclRange[row + iRow];
  2479. if (!gclData) continue;
  2480. data.del.push(gclData.id);
  2481. }
  2482. if (data.del.length === 0) return;
  2483. } else if (type === 'up-move') {
  2484. data.update = [];
  2485. const pre = gclRange[row - 1];
  2486. if (!pre) return;
  2487. const preUpdate = { id: pre.id };
  2488. for (let iRow = 0; iRow < count; iRow++) {
  2489. const gclData = gclRange[iRow + row];
  2490. if (!gclData) continue;
  2491. data.update.push({ id: gclData.id, g_order: gclRange[iRow + row - 1].g_order });
  2492. preUpdate.g_order = gclData.g_order;
  2493. }
  2494. data.update.push(preUpdate);
  2495. if (data.update <= 1) return;
  2496. } else if (type === 'down-move') {
  2497. data.update = [];
  2498. const next = gclRange[row + count];
  2499. if (!next) return;
  2500. const nextUpdate = { id: next.id };
  2501. for (let iRow = count - 1; iRow >= 0; iRow--) {
  2502. const gclData = gclRange[iRow + row];
  2503. if (!gclData) continue;
  2504. data.update.push({ id: gclData.id, g_order: gclRange[iRow + row + 1].g_order});
  2505. nextUpdate.g_order = gclData.g_order;
  2506. }
  2507. data.update.push(nextUpdate);
  2508. if (data.update <= 1) return;
  2509. }
  2510. postData('/tender/' + getTenderId() + '/anc-gcl/update', data, function(result) {
  2511. ancGcl.updateDatas(result);
  2512. ancGclObj.loadCurAncillaryGcl();
  2513. if (type !== 'delete') SpreadJsObj.locateData(ancGclSheet, first);
  2514. });
  2515. },
  2516. editStarting: function (e, info) {
  2517. ancGclObj.ledgerTreeNode = SpreadJsObj.getSelectObject(ledgerSheet);
  2518. },
  2519. editEnded: function (e, info) {
  2520. const setting = info.sheet.zh_setting;
  2521. if (!setting) return;
  2522. const gclData = SpreadJsObj.getSelectObject(info.sheet);
  2523. const col = setting.cols[info.col];
  2524. const orgText = gclData ? gclData[col.field] : '', newText = trimInvalidChar(info.editingText);
  2525. if (orgText === newText || (!orgText && !newText)) return;
  2526. const node = ancGclObj.ledgerTreeNode;
  2527. if (!node) {
  2528. toastr.error('数据错误,请选择台账节点后再试');
  2529. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2530. return;
  2531. }
  2532. if (!!newText && node.children && node.children.length > 0) {
  2533. toastr.error('父节点不可添加附属工程量');
  2534. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2535. return;
  2536. }
  2537. if (!!newText && (!node.b_code || node.b_code === '')) {
  2538. toastr.error('项目节不可插入附属工程量');
  2539. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2540. return;
  2541. }
  2542. const data = {};
  2543. if (gclData) {
  2544. const updateData = { id: gclData.id };
  2545. if (col.type === 'Number') {
  2546. const num = _.toNumber(newText);
  2547. if (!_.isFinite(num)) {
  2548. toastr.error('输入的数字非法');
  2549. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2550. return;
  2551. }
  2552. updateData[col.field] = num;
  2553. if (gclData.expr) updateData.expr = '';
  2554. } else if (col.field === 'expr') {
  2555. try {
  2556. updateData.expr = newText;
  2557. updateData.quantity = ZhCalc.mathCalcExpr(transExpr(newText));
  2558. } catch(err) {
  2559. toastr.error('输入的计算式非法');
  2560. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2561. return;
  2562. }
  2563. } else {
  2564. updateData[col.field] = newText;
  2565. }
  2566. data.update = [ updateData ];
  2567. } else {
  2568. const sortData = info.sheet.zh_data;
  2569. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].g_order + 1, sortData.length + 1);
  2570. const addData = { lid: node.id, g_order: order };
  2571. if (col.type === 'Number') {
  2572. const num = _.toNumber(newText);
  2573. if (!_.isFinite(num)) {
  2574. toastr.error('输入的数字非法');
  2575. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2576. return;
  2577. }
  2578. addData[col.field] = num;
  2579. if (gclData.expr) addData.expr = '';
  2580. } else if (col.field === 'expr') {
  2581. try {
  2582. addData.expr = newText;
  2583. addData.quantity = ZhCalc.mathCalcExpr(transExpr(newText));
  2584. } catch(err) {
  2585. toastr.error('输入的计算式非法');
  2586. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2587. return;
  2588. }
  2589. } else {
  2590. addData[col.field] = newText;
  2591. }
  2592. data.add = [addData];
  2593. }
  2594. postData('/tender/' + getTenderId() + '/anc-gcl/update', data, function (result) {
  2595. ancGcl.updateDatas(result);
  2596. ancGclObj.loadCurAncillaryGcl();
  2597. }, function () {
  2598. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2599. });
  2600. },
  2601. deletePress: function (sheet) {
  2602. const setting = sheet.zh_setting;
  2603. if (!setting) return;
  2604. const sortData = sheet.zh_data;
  2605. if (!sortData || sortData.length === 0) return;
  2606. const sel = sheet.getSelections()[0];
  2607. const data = { update: [] };
  2608. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2609. let bDel = false;
  2610. const node = sortData[iRow];
  2611. if (!node) continue;
  2612. const updateData = { id: node.id };
  2613. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2614. const style = sheet.getStyle(iRow, iCol);
  2615. if (style.locked) continue;
  2616. const col = setting.cols[iCol];
  2617. if (col.field === 'expr') {
  2618. updateData.expr = '';
  2619. updateData.quantity = 0;
  2620. } else {
  2621. updateData[col.field] = col.type === 'Number' ? 0 : '';
  2622. if (col.field === 'quantity') updateDataexpr = '';
  2623. }
  2624. bDel = true;
  2625. }
  2626. if (bDel) data.update.push(updateData);
  2627. }
  2628. if (data.update.length === 0) return;
  2629. postData('/tender/' + getTenderId() + '/anc-gcl/update', data, function (result) {
  2630. ancGcl.updateDatas(result);
  2631. ancGclObj.loadCurAncillaryGcl();
  2632. }, function () {
  2633. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2634. });
  2635. },
  2636. clipboardPasting: function(e, info) {
  2637. info.cancel = true;
  2638. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  2639. if (!node) {
  2640. toastr.error('数据错误,请选择台账节点后再试');
  2641. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2642. return;
  2643. }
  2644. if (node.children && node.children.length > 0) {
  2645. toastr.error('父节点不可添加附属工程量');
  2646. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2647. return;
  2648. }
  2649. if ((!node.b_code || node.b_code === '')) {
  2650. toastr.error('项目节不可插入附属工程量');
  2651. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2652. return;
  2653. }
  2654. const hint = {
  2655. expr: {type: 'warning', msg: '输入的 计算式 非法,已过滤'},
  2656. num: {type: 'warning', msg: '输入的 数字 非法,已过滤'},
  2657. };
  2658. const setting = info.sheet.zh_setting;
  2659. const sortData = info.sheet.zh_data || [];
  2660. const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text);
  2661. const data = {};
  2662. const analysisData = function(pasteRow, targetData) {
  2663. pasteRow.forEach((value, iCol) => {
  2664. const col = setting.cols[info.cellRange.col + iCol];
  2665. if (col.field === 'expr') {
  2666. try {
  2667. targetData.expr = trimInvalidChar(value);
  2668. targetData.quantity = ZhCalc.mathCalcExpr(transExpr(targetData.expr));
  2669. } catch(err) {
  2670. toastMessageUniq(hint.expr);
  2671. targetData.expr = '';
  2672. return;
  2673. }
  2674. } else if (col.type === 'Number') {
  2675. const num = _.toNumber(value);
  2676. if (!_.isFinite(num)) {
  2677. toastMessageUniq(hint.num);
  2678. return;
  2679. }
  2680. targetData[col.field] = num;
  2681. if (col.field === 'quantity') targetData.expr = '';
  2682. } else {
  2683. targetData[col.field] = value;
  2684. }
  2685. });
  2686. };
  2687. for (let iRow = 0; iRow < pasteData.length; iRow++) {
  2688. const curRow = iRow + info.cellRange.row;
  2689. const gclData = sortData[curRow];
  2690. if (gclData) {
  2691. if (!data.update) data.update = [];
  2692. const updateData = { id: gclData.id };
  2693. analysisData(pasteData[iRow], updateData);
  2694. data.update.push(updateData);
  2695. } else {
  2696. if (!data.add) data.add = [];
  2697. const addData = { lid: node.id, g_order: curRow + 1};
  2698. analysisData(pasteData[iRow], addData);
  2699. data.add.push(addData);
  2700. }
  2701. }
  2702. if ((!data.update || data.update.length === 0) && (!data.add || data.add.length === 0)) return;
  2703. postData('/tender/' + getTenderId() + '/anc-gcl/update', data, function (result) {
  2704. ancGcl.updateDatas(result);
  2705. ancGclObj.loadCurAncillaryGcl();
  2706. }, function () {
  2707. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2708. });
  2709. },
  2710. buttonClicked: function (e, info) {
  2711. const setting = info.sheet.zh_setting;
  2712. if (!setting) return;
  2713. const node = SpreadJsObj.getSelectObject(info.sheet);
  2714. if (!node) {
  2715. toastr.warning('请先添加附属工程量再设置辅材');
  2716. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2717. return;
  2718. }
  2719. const col = setting.cols[info.col];
  2720. const updateData = { id: node.id };
  2721. updateData[col.field] = node[col.field] ? 0 : 1;
  2722. postData('/tender/' + getTenderId() + '/anc-gcl/update', { update: [updateData]}, function (result) {
  2723. ancGcl.updateDatas(result);
  2724. ancGclObj.loadCurAncillaryGcl();
  2725. }, function () {
  2726. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2727. });
  2728. },
  2729. };
  2730. SpreadJsObj.addDeleteBind(ancGclSpread, ancGclObj.deletePress);
  2731. ancGclSpread.bind(spreadNS.Events.EditStarting, ancGclObj.editStarting);
  2732. ancGclSpread.bind(spreadNS.Events.EditEnded, ancGclObj.editEnded);
  2733. ancGclSpread.bind(spreadNS.Events.ClipboardPasting, ancGclObj.clipboardPasting);
  2734. ancGclSpread.bind(spreadNS.Events.ButtonClicked, ancGclObj.buttonClicked);
  2735. $.contextMenu({
  2736. selector: '#anc-gcl-spread',
  2737. build: function ($trigger, e) {
  2738. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ancGclSpread);
  2739. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2740. },
  2741. items: {
  2742. 'insert': {
  2743. name: '插入',
  2744. icon: 'fa-plus',
  2745. disabled: function (key, opt) {
  2746. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  2747. return !node || !node.b_code || (node.children && node.children.length > 0);
  2748. },
  2749. callback: function (key, opt) {
  2750. ancGclObj.baseOpr('insert');
  2751. }
  2752. },
  2753. 'delete': {
  2754. name: '删除',
  2755. icon: 'fa-remove',
  2756. disabled: function (key, opt) {
  2757. const gclData = SpreadJsObj.getSelectObject(ancGclSheet);
  2758. return !gclData;
  2759. },
  2760. callback: function (key, opt) {
  2761. ancGclObj.baseOpr('delete');
  2762. }
  2763. },
  2764. 'down-move': {
  2765. name: '下移',
  2766. icon: 'fa-arrow-down',
  2767. disabled: function(key, opt) {
  2768. const sel = ancGclSheet.getSelections()[0];
  2769. const row = sel ? sel.row : -1;
  2770. const first = ancGclSheet.zh_data[row];
  2771. const next = ancGclSheet.zh_data[sel.row + sel.rowCount];
  2772. return !first || !next;
  2773. },
  2774. callback: function(key, opt) {
  2775. ancGclObj.baseOpr('down-move');
  2776. }
  2777. },
  2778. 'up-move': {
  2779. name: '上移',
  2780. icon: 'fa-arrow-up',
  2781. disabled: function(key, opt) {
  2782. const sel = ancGclSheet.getSelections()[0];
  2783. const row = sel ? sel.row : -1;
  2784. const first = ancGclSheet.zh_data[row];
  2785. const preNode = ancGclSheet.zh_data[row - 1];
  2786. return !first || !preNode;
  2787. },
  2788. callback: function(key, opt) {
  2789. ancGclObj.baseOpr('up-move');
  2790. }
  2791. },
  2792. }
  2793. });
  2794. $('#filter-anc-gcl').change(function() {
  2795. if (this.checked) {
  2796. const condition = {};
  2797. condition[this.getAttribute('name')] = parseInt(this.value);
  2798. ancGcl.filter = condition;
  2799. } else {
  2800. ancGcl.filter = null;
  2801. }
  2802. ancGclObj.loadCurAncillaryGcl();
  2803. });
  2804. postData(window.location.pathname + '/load', {}, function (data) {
  2805. ledgerTree.loadDatas(data.bills);
  2806. treeCalc.calculateAll(ledgerTree);
  2807. checkShowLast(data.bills.length);
  2808. pos.loadDatas(data.pos);
  2809. ancGcl.loadDatas(data.ancGcl);
  2810. for (const t of data.tags) {
  2811. t.node = ledgerTree.datas.find(x => { return x.id === t.lid; });
  2812. if (t.pos_id) {
  2813. const posRange = pos.getLedgerPos(t.lid) || [];
  2814. t.pos = posRange.find(x => { return x.id === t.pos_id; });
  2815. }
  2816. }
  2817. billsTag.loadDatas(data.tags);
  2818. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  2819. SpreadJsObj.loadTopAndSelect(ledgerSpread.getActiveSheet(), ckBillsSpread);
  2820. posOperationObj.loadCurPosData();
  2821. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  2822. ancGclObj.loadCurAncillaryGcl();
  2823. SpreadJsObj.resetTopAndSelect(ancGclSheet);
  2824. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2825. treeOperationObj.loadExprToInput(ledgerSpread.getActiveSheet());
  2826. checkList.loadHisCheckData();
  2827. }, null, true);
  2828. $.divResizer({
  2829. select: '#right-spr',
  2830. callback: function () {
  2831. ledgerSpread.refresh();
  2832. if (posSpread) posSpread.refresh();
  2833. if (ancGclSpread) ancGclSpread.refresh();
  2834. if (stdXmj) stdXmj.spread.refresh();
  2835. if (stdGcl) stdGcl.spread.refresh();
  2836. if (dealBills) dealBills.spread.refresh();
  2837. if (searchLedger) searchLedger.spread.refresh();
  2838. if (errorList) errorList.spread.refresh();
  2839. if (checkList) checkList.spread.refresh();
  2840. if (gclGather) gclGather.spread.refresh();
  2841. }
  2842. });
  2843. const stdLibCellDoubleClick = function (updateData, stdNode) {
  2844. if (!stdNode) return;
  2845. const mainNode = SpreadJsObj.getSelectObject(ledgerSheet);
  2846. if (!mainNode) return;
  2847. if (updateData.postData.stdType === 'gcl') {
  2848. if (!!mainNode.code && !ledgerTree.isLeafXmj(mainNode)) {
  2849. toastr.warning('非最底层项目下,不应添加清单');
  2850. return;
  2851. }
  2852. }
  2853. updateData.postData.id = ledgerTree.getNodeKey(mainNode);
  2854. updateData.postData.tender_id = mainNode.tender_id;
  2855. postData(window.location.pathname + '/update', updateData, function (result) {
  2856. const sel = ledgerSheet.getSelections()[0];
  2857. const refreshNode = ledgerTree.loadPostData(result);
  2858. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  2859. if (refreshNode.create && refreshNode.create.length > 0) {
  2860. ledgerSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2861. const refreshRow = [sel.row, refreshNode.create[refreshNode.create.length - 1].index];
  2862. const curIndex = ledgerTree.nodes.indexOf(mainNode);
  2863. if (sel.row !== curIndex && curIndex >= 0) refreshRow.push(curIndex);
  2864. SpreadJsObj.reloadRowsBackColor(ledgerSheet, refreshRow);
  2865. } else {
  2866. const node = _.find(ledgerTree.nodes, {code: stdNode.code, name: stdNode.name});
  2867. if (node) {
  2868. ledgerSheet.setSelection(ledgerTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2869. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [sel.row, ledgerTree.nodes.indexOf(node)]);
  2870. }
  2871. }
  2872. treeOperationObj.refreshOperationValid(ledgerSheet);
  2873. ledgerSpread.focus();
  2874. treeOperationObj.loadRelaData();
  2875. });
  2876. };
  2877. const stdXmjSetting = {
  2878. selector: '#std-xmj',
  2879. stdType: 'xmj',
  2880. libs: stdChapters,
  2881. treeSetting: {
  2882. id: 'chapter_id',
  2883. pid: 'pid',
  2884. order: 'order',
  2885. level: 'level',
  2886. rootId: -1,
  2887. keys: ['id', 'list_id', 'chapter_id'],
  2888. },
  2889. spreadSetting: {
  2890. cols: [
  2891. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2892. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2893. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2894. ],
  2895. treeCol: 0,
  2896. emptyRows: 0,
  2897. headRows: 1,
  2898. headRowHeight: [32],
  2899. defaultRowHeight: 21,
  2900. headerFont: '12px 微软雅黑',
  2901. font: '12px 微软雅黑',
  2902. headColWidth: [30],
  2903. selectedBackColor: '#fffacd',
  2904. },
  2905. cellDoubleClick: stdLibCellDoubleClick,
  2906. page: 'ledger',
  2907. tid: getTenderId(),
  2908. };
  2909. const stdGclSetting = {
  2910. selector: '#std-gcl',
  2911. stdType: 'gcl',
  2912. libs: stdBills,
  2913. treeSetting: {
  2914. id: 'bill_id',
  2915. pid: 'pid',
  2916. order: 'order',
  2917. level: 'level',
  2918. rootId: -1,
  2919. keys: ['id', 'list_id', 'bill_id']
  2920. },
  2921. spreadSetting: {
  2922. cols: [
  2923. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2924. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2925. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2926. ],
  2927. treeCol: 0,
  2928. emptyRows: 0,
  2929. headRows: 1,
  2930. headRowHeight: [32],
  2931. defaultRowHeight: 21,
  2932. headerFont: '12px 微软雅黑',
  2933. font: '12px 微软雅黑',
  2934. headColWidth: [30],
  2935. selectedBackColor: '#fffacd',
  2936. },
  2937. cellDoubleClick: stdLibCellDoubleClick,
  2938. page: 'ledger',
  2939. tid: getTenderId(),
  2940. showAddType: 1,
  2941. };
  2942. // 展开收起标准清单
  2943. $('a', '#side-menu').bind('click', function (e) {
  2944. e.preventDefault();
  2945. const tab = $(this), tabPanel = $(tab.attr('content'));
  2946. // 展开工具栏、切换标签
  2947. if (!tab.hasClass('active')) {
  2948. // const close = $('.active', '#side-menu').length === 0;
  2949. $('a', '#side-menu').removeClass('active');
  2950. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  2951. tab.addClass('active');
  2952. tabPanel.addClass('active');
  2953. // $('.tab-content .tab-pane').removeClass('active');
  2954. showSideTools(tab.hasClass('active'));
  2955. if (tab.attr('content') === '#std-xmj') {
  2956. if (!stdXmj) {
  2957. stdXmj = $.stdLib(stdXmjSetting);
  2958. }
  2959. stdXmj.spread.refresh();
  2960. } else if (tab.attr('content') === '#std-gcl') {
  2961. if (!stdGcl) {
  2962. stdGcl = $.stdLib(stdGclSetting);
  2963. }
  2964. stdGcl.spread.refresh();
  2965. } else if (tab.attr('content') === '#deal-bills') {
  2966. if (!dealBills) {
  2967. dealBills = new DealBills('#deal-bills-spread', {
  2968. cols: [
  2969. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2970. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2971. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2972. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2973. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2974. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2975. ],
  2976. emptyRows: 3,
  2977. headRows: 1,
  2978. headRowHeight: [32],
  2979. defaultRowHeight: 21,
  2980. headerFont: '12px 微软雅黑',
  2981. font: '12px 微软雅黑',
  2982. headColWidth: [30],
  2983. selectedBackColor: '#fffacd',
  2984. readOnly: true,
  2985. });
  2986. dealBills.loadData();
  2987. }
  2988. dealBills.spread.refresh();
  2989. } else if (tab.attr('content') === '#search') {
  2990. if (!searchLedger) {
  2991. searchLedger = $.ledgerSearch({
  2992. selector: '#search',
  2993. ledger: { billsTree: ledgerTree, pos: pos },
  2994. resultSpreadSetting: {
  2995. cols: [
  2996. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  2997. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2998. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2999. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3000. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3001. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3002. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  3003. ],
  3004. emptyRows: 0,
  3005. headRows: 1,
  3006. headRowHeight: [32],
  3007. headColWidth: [30],
  3008. defaultRowHeight: 21,
  3009. headerFont: '12px 微软雅黑',
  3010. font: '12px 微软雅黑',
  3011. selectedBackColor: '#fffacd',
  3012. readOnly: true,
  3013. },
  3014. locate: function(cur) {
  3015. if (!cur.lid) return;
  3016. SpreadJsObj.locateTreeNode(ledgerSheet, cur.lid, true);
  3017. treeOperationObj.loadRelaData();
  3018. if (cur.pid && cur.pid !== -1) {
  3019. const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  3020. SpreadJsObj.locateRow(posSheet, pIndex);
  3021. }
  3022. },
  3023. calcSum: function (result) {
  3024. const sum = { name: '合计' };
  3025. for (const r of result) {
  3026. sum.quantity = ZhCalc.add(r.quantity, sum.quantity);
  3027. }
  3028. return sum;
  3029. }
  3030. });
  3031. }
  3032. searchLedger.spread.refresh();
  3033. } else if (tab.attr('content') === '#bills-tag') {
  3034. // do something
  3035. } else if (tab.attr('content') === '#error-list') {
  3036. errorList.spread.refresh();
  3037. } else if (tab.attr('content') === '#check-list') {
  3038. checkList.spread.refresh();
  3039. } else if (tab.attr('content') === '#fujian') {
  3040. $('#showAttachment').hide();
  3041. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  3042. getNodeList(node.id);
  3043. getAllList();
  3044. } else if (tab.attr('content') === '#gcl-gather') {
  3045. gclGather.spread.refresh();
  3046. }
  3047. } else { // 收起工具栏
  3048. tab.removeClass('active');
  3049. tabPanel.removeClass('active');
  3050. showSideTools(tab.hasClass('active'));
  3051. }
  3052. ledgerSpread.refresh();
  3053. if (posSpread) {
  3054. posSpread.refresh();
  3055. }
  3056. if (ancGclSpread) ancGclSpread.refresh();
  3057. });
  3058. class DealBills {
  3059. constructor (selector, spreadSetting) {
  3060. const self = this;
  3061. this.obj = $(selector)[0];
  3062. this.url = '/tender/' + getTenderId() + '/deal';
  3063. this.spreadSetting = spreadSetting;
  3064. this.spread = SpreadJsObj.createNewSpread(this.obj);
  3065. this.sheet = this.spread.getActiveSheet();
  3066. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3067. this.OprObj = {
  3068. /**
  3069. * 删除按钮响应事件
  3070. * @param sheet
  3071. */
  3072. deletePress: function (sheet) {
  3073. if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
  3074. const sortData = sheet.zh_data;
  3075. const datas = [];
  3076. const sels = sheet.getSelections();
  3077. if (!sels || !sels[0]) return;
  3078. for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
  3079. let bDel = false;
  3080. const node = sortData[iRow];
  3081. if (node) {
  3082. const data = {id: node.id};
  3083. for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
  3084. const colSetting = sheet.zh_setting.cols[iCol];
  3085. if (colSetting.field === 'code') {
  3086. toastr.error('清单编号不能为空,如需删除签约清单请使用右键删除');
  3087. return;
  3088. }
  3089. const style = sheet.getStyle(iRow, iCol);
  3090. if (!style.locked) {
  3091. const colSetting = sheet.zh_setting.cols[iCol];
  3092. data[colSetting.field] = null;
  3093. bDel = true;
  3094. }
  3095. }
  3096. if (bDel) {
  3097. datas.push(data);
  3098. }
  3099. }
  3100. }
  3101. if (datas.length > 0) {
  3102. postData(self.url + '/update', {update: datas}, function (result) {
  3103. self.loadUpdateData(result);
  3104. SpreadJsObj.reLoadSheetData(sheet);
  3105. }, function () {
  3106. SpreadJsObj.reLoadSheetData(sheet);
  3107. });
  3108. }
  3109. },
  3110. delete: function (sheet) {
  3111. if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
  3112. const sortData = sheet.zh_data;
  3113. const datas = [];
  3114. const sels = sheet.getSelections();
  3115. if (!sels || !sels[0]) return;
  3116. for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {
  3117. const node = sortData[iRow];
  3118. datas.push(node.id);
  3119. }
  3120. if (datas.length > 0) {
  3121. postData(self.url + '/update', {del: datas}, function (result) {
  3122. self.loadUpdateData(result);
  3123. SpreadJsObj.reLoadSheetData(sheet);
  3124. }, function () {
  3125. SpreadJsObj.reLoadSheetData(sheet);
  3126. });
  3127. }
  3128. },
  3129. insert: function (sheet) {
  3130. if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
  3131. const select = SpreadJsObj.getSelectObject(sheet);
  3132. const data = { insert: { select_id: select ? select.id: null, count: 1 } };
  3133. postData(self.url + '/update', data, function (result) {
  3134. self.loadUpdateData(result);
  3135. SpreadJsObj.reLoadSheetData(sheet);
  3136. }, function () {
  3137. SpreadJsObj.reLoadSheetData(sheet);
  3138. });
  3139. },
  3140. editEnded: function (e, info) {
  3141. if (!info.sheet.zh_setting || !info.sheet.zh_data || info.sheet.zh_setting.readOnly) return;
  3142. const node = info.sheet.zh_data[info.row];
  3143. const col = info.sheet.zh_setting.cols[info.col];
  3144. const data = {};
  3145. if (node) {
  3146. data.update = {};
  3147. data.update.id = node.id;
  3148. const oldValue = node ? node[col.field] : null;
  3149. const newValue = trimInvalidChar(info.editingText);
  3150. if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
  3151. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3152. return;
  3153. }
  3154. data.update[col.field] = newValue;
  3155. } else {
  3156. if (col.field !== 'code') {
  3157. toastr.warning('新增签约清单,请先输入清单编号');
  3158. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3159. return;
  3160. }
  3161. data.add = {};
  3162. data.add.order = info.row + 1;
  3163. data.add.code = trimInvalidChar(info.editingText);
  3164. }
  3165. postData(self.url + '/update', data, function (result) {
  3166. self.loadUpdateData(result);
  3167. SpreadJsObj.reLoadSheetData(info.sheet);
  3168. }, function () {
  3169. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3170. });
  3171. },
  3172. clipboardPasting(e, info) {
  3173. const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;
  3174. info.cancel = true;
  3175. if (!setting || !sortData || setting.readOnly) return;
  3176. const pasteData = info.pasteData.html
  3177. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  3178. : (info.pasteData.text === ''
  3179. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  3180. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  3181. const hint = {
  3182. code: {type: 'warning', msg: '签约清单编号不可为空,已过滤'},
  3183. unit_price: {type: 'warning', msg: '输入的 单价 非法,已过滤'},
  3184. quantity: {type: 'warning', msg: '输入的 数量 非法,已过滤'},
  3185. };
  3186. const uDatas = [], iDatas = [];
  3187. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3188. const curRow = info.cellRange.row + iRow;
  3189. const node = sortData[curRow];
  3190. let bPaste = false;
  3191. const data = {};
  3192. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  3193. const curCol = info.cellRange.col + iCol;
  3194. const colSetting = setting.cols[curCol];
  3195. const value = trimInvalidChar(pasteData[iRow][iCol]);
  3196. if (colSetting.field === 'code' && (!value || value === '')) {
  3197. toastMessageUniq(hint.code);
  3198. break;
  3199. }
  3200. if (colSetting.type === 'Number') {
  3201. const num = _.toNumber(value);
  3202. if (num) {
  3203. data[colSetting.field] = num;
  3204. bPaste = true;
  3205. } else if (colSetting.field === 'unit_price') {
  3206. toastMessageUniq(hint.unit_price);
  3207. } else if (colSetting.field === 'quantity') {
  3208. toastMessageUniq(hint.quantity);
  3209. }
  3210. } else {
  3211. data[colSetting.field] = value;
  3212. bPaste = true;
  3213. }
  3214. }
  3215. if (bPaste) {
  3216. if (node) {
  3217. data.id = node.id;
  3218. uDatas.push(data);
  3219. } else {
  3220. data.order = curRow + 1;
  3221. iDatas.push(data);
  3222. }
  3223. }
  3224. }
  3225. const updateData = {};
  3226. if (uDatas.length > 0) updateData.update = uDatas;
  3227. if (iDatas.length > 0) updateData.add = iDatas;
  3228. if (uDatas.length > 0 || iDatas.length > 0) {
  3229. postData(self.url + '/update', updateData, function (result) {
  3230. self.loadUpdateData(result);
  3231. SpreadJsObj.reLoadSheetData(info.sheet);
  3232. });
  3233. } else {
  3234. SpreadJsObj.reLoadSheetData(info.sheet);
  3235. }
  3236. },
  3237. };
  3238. if (!readOnly) {
  3239. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3240. const dealSheet = info.sheet;
  3241. if (!dealSheet.zh_setting.readOnly) return;
  3242. const mainSheet = ledgerSpread.getActiveSheet();
  3243. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3244. if (!dealBills) { return; }
  3245. const mainTree = mainSheet.zh_tree;
  3246. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3247. if (!mainNode || !mainTree) { return; }
  3248. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3249. toastr.error('非最底层项目下,不应添加清单');
  3250. return;
  3251. }
  3252. postData(window.location.pathname + '/update', {
  3253. postType: 'add-deal',
  3254. postData: {
  3255. id: mainNode.ledger_id,
  3256. type: mainNode.code ? 'child' : 'next',
  3257. dealBills: {
  3258. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3259. unit_price: dealBills.unit_price,
  3260. }
  3261. },
  3262. }, function (result) {
  3263. const refreshData = mainTree.loadPostData(result);
  3264. treeOperationObj.refreshTree(mainSheet, refreshData);
  3265. const sel = mainSheet.getSelections()[0];
  3266. mainSheet.setSelection(refreshData.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3267. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshData.create[0].index]);
  3268. treeOperationObj.refreshOperationValid(mainSheet);
  3269. ledgerSpread.focus();
  3270. posOperationObj.loadCurPosData();
  3271. ancGclObj.loadCurAncillaryGcl();
  3272. });
  3273. });
  3274. }
  3275. const dealBillsPermission = $('[href="#upload-deal"]').length > 0;
  3276. if (!readOnly || dealBillsPermission) {
  3277. this.spread.bind(spreadNS.Events.EditEnded, this.OprObj.editEnded);
  3278. this.spread.bind(spreadNS.Events.ClipboardPasting, this.OprObj.clipboardPasting);
  3279. SpreadJsObj.addDeleteBind(this.spread, this.OprObj.deletePress);
  3280. $.contextMenu({
  3281. selector: selector,
  3282. build: function ($trigger, e) {
  3283. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.spread);
  3284. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3285. },
  3286. items: {
  3287. edit: {
  3288. name: '进入编辑模式',
  3289. icon: 'fa-edit',
  3290. visible: function (key, opt) {
  3291. return self.sheet.zh_setting.readOnly;
  3292. },
  3293. callback: function (key, opt) {
  3294. self.sheet.zh_setting.readOnly = false;
  3295. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  3296. },
  3297. },
  3298. read: {
  3299. name: '退出编辑模式',
  3300. icon: 'fa-sign-out',
  3301. visible: function (key, opt) {
  3302. return !self.sheet.zh_setting.readOnly;
  3303. },
  3304. callback: function (key, opt) {
  3305. self.sheet.zh_setting.readOnly = true;
  3306. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  3307. },
  3308. },
  3309. add: {
  3310. name: '插入',
  3311. icon: 'fa-plus',
  3312. visible: function (key, opt) {
  3313. return !self.sheet.zh_setting.readOnly;
  3314. },
  3315. disabled: function (key, opt) {
  3316. const select = SpreadJsObj.getSelectObject(self.sheet);
  3317. return !select;
  3318. },
  3319. callback: function (key, opt) {
  3320. self.OprObj.insert(self.sheet);
  3321. },
  3322. },
  3323. del: {
  3324. name: '删除',
  3325. icon: 'fa-times',
  3326. visible: function (key, opt) {
  3327. return !self.sheet.zh_setting.readOnly;
  3328. },
  3329. disabled: function (key, opt) {
  3330. const select = SpreadJsObj.getSelectObject(self.sheet);
  3331. return !select;
  3332. },
  3333. callback: function (key, opt) {
  3334. self.OprObj.delete(self.sheet);
  3335. },
  3336. },
  3337. sprEdit: '----',
  3338. apply: {
  3339. name: '应用全部清单单价至台账',
  3340. icon: 'fa-magic',
  3341. disabled: function (key, opt) {
  3342. const sheet = self.spread.getActiveSheet();
  3343. return sheet.getRowCount() === 0 || readOnly;
  3344. },
  3345. callback: function (key, opt) {
  3346. const datas = [], sourceData = self.spread.getActiveSheet().zh_data;
  3347. for (const db of sourceData) {
  3348. const targets = ledgerTree.nodes.filter(function (x) {
  3349. return x.b_code === db.code && x.name === db.name && x.unit === db.unit;
  3350. });
  3351. for (const t of targets) {
  3352. if (t.children && t.children.length > 0) continue;
  3353. const data = ledgerTree.getNodeKeyData(t);
  3354. data.unit_price = db.unit_price;
  3355. datas.push(data);
  3356. }
  3357. }
  3358. if (datas.length > 0) {
  3359. doAfterHint({
  3360. fun: function() {
  3361. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  3362. const refreshNode = ledgerTree.loadPostData(result);
  3363. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  3364. });
  3365. },
  3366. hint: '此操作会替换台账里所有同编号、名称、单位的清单,请谨慎操作',
  3367. });
  3368. } else {
  3369. toastr.warning('没有可应用的清单。');
  3370. }
  3371. },
  3372. }
  3373. }
  3374. });
  3375. }
  3376. $('#upload-deal-bills').click(function () {
  3377. const file = $('#deal-bills-file')[0];
  3378. const formData = new FormData();
  3379. formData.append('file', file.files[0]);
  3380. postDataWithFile(self.url+'/upload-excel', formData, function (data) {
  3381. self.data = data;
  3382. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  3383. $('#upload-deal').modal('hide');
  3384. }, function () {
  3385. $('#upload-deal').modal('hide');
  3386. });
  3387. });
  3388. this.initDealBillsSearch();
  3389. }
  3390. search(keyword) {
  3391. this.searchResult = [];
  3392. this.searchCur = 0;
  3393. if (keyword) {
  3394. for (const [i, d] of this.data.entries()) {
  3395. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  3396. }
  3397. }
  3398. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  3399. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.sheet, this.searchResult[0]);
  3400. }
  3401. searchPre() {
  3402. this.searchCur = this.searchCur - 1;
  3403. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  3404. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  3405. }
  3406. searchNext() {
  3407. this.searchCur = this.searchCur + 1;
  3408. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  3409. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  3410. }
  3411. searchClear() {
  3412. $('#dbs-keyword').val('');
  3413. this.searchResult = [];
  3414. this.searchCur = 0;
  3415. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  3416. }
  3417. initDealBillsSearch() {
  3418. const self = this;
  3419. $('#dbs-keyword').change(function () { self.search(this.value); });
  3420. $('#dbs-pre').click(function (e) {
  3421. self.searchPre();
  3422. e.stopPropagation();
  3423. });
  3424. $('#dbs-next').click(function (e) {
  3425. self.searchNext();
  3426. e.stopPropagation();
  3427. });
  3428. $('#dbs-clear').click(function (e) {
  3429. self.searchClear();
  3430. e.stopPropagation();
  3431. });
  3432. }
  3433. loadData () {
  3434. const self = this;
  3435. postData(this.url+'/get-data', {}, function (data) {
  3436. self.data = data;
  3437. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  3438. if (data.length > 0) self.spread.getActiveSheet().setSelection(0, 0, 1, 1);
  3439. });
  3440. }
  3441. calculateData () {
  3442. if (this.data) {
  3443. for (const d of this.data) {
  3444. d.total_price = _.multiply(d.quantity, d.unit_price);
  3445. }
  3446. }
  3447. }
  3448. loadUpdateData(updateData) {
  3449. if (updateData.add) {
  3450. for (const a of updateData.add) {
  3451. this.data.push(a);
  3452. }
  3453. }
  3454. if (updateData.update) {
  3455. for (const u of updateData.update) {
  3456. const d = this.data.find(function (x) {
  3457. return u.id === x.id;
  3458. });
  3459. if (d) {
  3460. _.assign(d, u);
  3461. } else {
  3462. this.data.push(d);
  3463. }
  3464. }
  3465. }
  3466. if (updateData.del) {
  3467. _.remove(this.data, function (d) {
  3468. return updateData.del.indexOf(d.id) >= 0;
  3469. });
  3470. }
  3471. this.data.sort((x, y) => { return x.order - y.order; });
  3472. }
  3473. }
  3474. class BatchInsertBillsPosObj {
  3475. constructor (obj) {
  3476. const self = this;
  3477. this.obj = obj;
  3478. this.billsCount = 6;
  3479. this.posCount = 1000;
  3480. this.filter = getLocalCache('zh-calc-batch-filter');
  3481. if (!this.filter) {
  3482. this.filter = '1';
  3483. }
  3484. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  3485. // 初始化 清单编号窗口 参数
  3486. this.qdSpreadSetting = {
  3487. cols: [
  3488. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  3489. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  3490. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3491. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3492. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  3493. ],
  3494. emptyRows: this.billsCount,
  3495. headRows: 1,
  3496. headRowHeight: [32],
  3497. headerFont: '12px 微软雅黑',
  3498. font: '12px 微软雅黑',
  3499. };
  3500. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  3501. // 初始化 部位数量复核表 参数
  3502. this.posSpreadSetting = {
  3503. cols: [
  3504. {title: '计量单元', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  3505. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  3506. ],
  3507. emptyRows: this.posCount,
  3508. headRows: 1,
  3509. headRowHeight: [32],
  3510. headerFont: '12px 微软雅黑',
  3511. font: '12px 微软雅黑',
  3512. };
  3513. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  3514. this.posSpreadSetting.cols.push(
  3515. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  3516. )
  3517. }
  3518. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  3519. // 初始化 签约清单 参数
  3520. this.dealSpreadSetting = {
  3521. cols: [
  3522. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  3523. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  3524. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3525. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  3526. ],
  3527. emptyRows: 0,
  3528. headRows: 1,
  3529. headRowHeight: [32],
  3530. headerFont: '12px 微软雅黑',
  3531. font: '12px 微软雅黑',
  3532. };
  3533. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  3534. this.dealSheet = this.dealSpread.getActiveSheet();
  3535. // 初始化 清单编号、部位数量复核表 表格
  3536. this.initView();
  3537. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  3538. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  3539. $.contextMenu({
  3540. selector: '.batch-l-t',
  3541. build: function ($trigger, e) {
  3542. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  3543. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3544. },
  3545. items: {
  3546. 'create': {
  3547. name: '新增行',
  3548. icon: 'fa-sign-in',
  3549. callback: function (key, opt) {
  3550. const qdSheet = self.qdSpread.getActiveSheet();
  3551. const posSheet = self.posSpread.getActiveSheet();
  3552. qdSheet.addRows(qdSheet.getRowCount(), 1);
  3553. const index = qdSheet.getRowCount();
  3554. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  3555. posSheet.addColumns(posSheet.getColumnCount(), 1);
  3556. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  3557. },
  3558. },
  3559. 'delete': {
  3560. name: '删除行',
  3561. icon: 'fa-remove',
  3562. callback: function (key, opt) {
  3563. const qdSheet = self.qdSpread.getActiveSheet();
  3564. const posSheet = self.posSpread.getActiveSheet();
  3565. const sel = qdSheet.getSelections()[0];
  3566. qdSheet.deleteRows(sel.row, sel.rowCount);
  3567. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  3568. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  3569. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  3570. }
  3571. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  3572. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  3573. }
  3574. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  3575. },
  3576. }
  3577. }
  3578. });
  3579. // 拉取签约清单数据
  3580. if (dealBills) {
  3581. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3582. } else {
  3583. postData('/tender/' + getTenderId() + '/deal/get-data', {}, function (data) {
  3584. SpreadJsObj.loadSheetData(self.dealSpread.getActiveSheet(), 'data', data);
  3585. });
  3586. }
  3587. // 双击签约清单,自动添加到清单编号窗口
  3588. this.dealSpread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3589. const deal = info.sheet.zh_data[info.row];
  3590. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  3591. const sel = qdSheet.getSelections()[0];
  3592. qdSheet.getCell(sel.row, 0).value(deal.code);
  3593. qdSheet.getCell(sel.row, 1).value(deal.name);
  3594. qdSheet.getCell(sel.row, 2).value(deal.unit);
  3595. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  3596. if (sel.row + 1 === qdSheet.getRowCount()) {
  3597. const count = sel.row + 2;
  3598. qdSheet.setRowCount(count);
  3599. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  3600. const colCount = posSheet.getColumnCount() + 1
  3601. posSheet.setColumnCount(colCount);
  3602. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  3603. }
  3604. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  3605. });
  3606. this.qdSpread.bind(spreadNS.Events.ClipboardPasting, function (e, info) {
  3607. info.cancel = true;
  3608. const transpose = $('[name=batch-transpose]')[0].checked;
  3609. const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text, transpose);
  3610. const billsSheet = info.sheet, posSheet = self.posSpread.getActiveSheet();
  3611. const billsCount = info.sheet.getRowCount(), finalCount = info.cellRange.row + pasteData.length + 1;
  3612. SpreadJsObj.beginMassOperation(billsSheet);
  3613. if (finalCount > billsCount) {
  3614. billsSheet.setRowCount(finalCount);
  3615. posSheet.setColumnCount(finalCount + 2);
  3616. for (let i = billsCount - 1; i <= finalCount; i++) {
  3617. billsSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3618. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3619. }
  3620. }
  3621. for (let iRow = 0; iRow < pasteData.length; iRow++) {
  3622. const curRow = iRow + info.cellRange.row;
  3623. pasteData[iRow].forEach((value, iCol) => {
  3624. billsSheet.getCell(curRow, iCol + info.cellRange.col).value(value);
  3625. });
  3626. if ([0, 1].indexOf(info.cellRange.col) >= 0) {
  3627. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3628. const bills = _.find(dealBills, {code: billsSheet.getText(curRow, 0)});
  3629. if (bills) {
  3630. billsSheet.getCell(curRow, 1).value(bills.name);
  3631. billsSheet.getCell(curRow, 2).value(bills.unit);
  3632. billsSheet.getCell(curRow, 3).value(bills.unit_price);
  3633. }
  3634. }
  3635. }
  3636. SpreadJsObj.endMassOperation(billsSheet);
  3637. });
  3638. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3639. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  3640. const count = qdSheet.getRowCount();
  3641. if (billsCount > count) {
  3642. qdSheet.setRowCount(billsCount);
  3643. for (let i = count + 1; i <= billsCount; i++) {
  3644. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3645. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3646. }
  3647. }
  3648. });
  3649. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  3650. if (info.col === 0) {
  3651. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3652. if (dealBills && dealBills.length > 0) {
  3653. const bills = _.find(dealBills, {code: info.editingText});
  3654. if (bills) {
  3655. info.sheet.getCell(info.row, 1).value(bills.name);
  3656. info.sheet.getCell(info.row, 2).value(bills.unit);
  3657. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  3658. }
  3659. }
  3660. }
  3661. });
  3662. this.obj.bind('shown.bs.modal', function () {
  3663. self.qdSpread.refresh();
  3664. self.posSpread.refresh();
  3665. self.dealSpread.refresh();
  3666. });
  3667. $('#batch-ok').click(function () {
  3668. const sheet = ledgerSpread.getActiveSheet();
  3669. const sel = sheet.getSelections()[0];
  3670. const row = sel.row;
  3671. const select = ledgerTree.nodes[row];
  3672. if (select) {
  3673. const insertData = {};
  3674. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  3675. insertData.id = ledgerTree.getNodeKey(select);
  3676. insertData.batchData = self.getBatchData();
  3677. if (insertData.batchData.length > 0) {
  3678. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  3679. pos.updateDatas(data.pos);
  3680. const result = ledgerTree.loadPostData(data.ledger);
  3681. treeOperationObj.refreshTree(sheet, result);
  3682. sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3683. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, result.create[0].index]);
  3684. treeOperationObj.refreshOperationValid(sheet);
  3685. posOperationObj.loadCurPosData();
  3686. ancGclObj.loadCurAncillaryGcl();
  3687. self.obj.modal('hide');
  3688. }, null, true);
  3689. } else {
  3690. self.obj.modal('hide');
  3691. }
  3692. }
  3693. });
  3694. $('input[name=batch-filter]').change(function () {
  3695. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3696. });
  3697. this.initDealBillsSearch();
  3698. }
  3699. search(keyword) {
  3700. this.searchResult = [];
  3701. this.searchCur = 0;
  3702. if (keyword) {
  3703. for (const [i, d] of this.dealSheet.zh_data.entries()) {
  3704. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  3705. }
  3706. }
  3707. $('#batch-dbs-count').html(`结果:${this.searchResult.length}`);
  3708. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.dealSheet, this.searchResult[0]);
  3709. }
  3710. searchPre() {
  3711. this.searchCur = this.searchCur - 1;
  3712. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  3713. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3714. }
  3715. searchNext() {
  3716. this.searchCur = this.searchCur + 1;
  3717. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  3718. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3719. }
  3720. initDealBillsSearch() {
  3721. const self = this;
  3722. $('#batch-dbs-keyword').change(function () { self.search(this.value); });
  3723. $('#batch-dbs-pre').click(function (e) {
  3724. self.searchPre();
  3725. e.stopPropagation();
  3726. });
  3727. $('#batch-dbs-next').click(function (e) {
  3728. self.searchNext();
  3729. e.stopPropagation();
  3730. });
  3731. }
  3732. // 初始化左侧表格
  3733. initView () {
  3734. // 初始化 清单编号
  3735. const qdSheet = this.qdSpread.getActiveSheet();
  3736. qdSheet.setColumnWidth(0, 45, spreadNS.SheetArea.rowHeader);
  3737. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3738. SpreadJsObj.refreshColumnAlign(qdSheet);
  3739. // 清理原有数据
  3740. SpreadJsObj.beginMassOperation(qdSheet);
  3741. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3742. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3743. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3744. }
  3745. qdSheet.setSelection(0, 0, 1 ,1);
  3746. SpreadJsObj.endMassOperation(qdSheet);
  3747. // 初始化 部位数量复核表
  3748. const posSheet = this.posSpread.getActiveSheet();
  3749. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3750. SpreadJsObj.refreshColumnAlign(posSheet);
  3751. // 清理原有数据
  3752. SpreadJsObj.beginMassOperation(posSheet);
  3753. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3754. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3755. posSheet.setSelection(0, 0, 1 ,1);
  3756. SpreadJsObj.endMassOperation(posSheet);
  3757. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  3758. }
  3759. // 获取界面数据
  3760. getBatchData () {
  3761. const result = [];
  3762. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  3763. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  3764. if (qdSheet.getText(iRow, 0) === '') { continue; }
  3765. const qd = {
  3766. b_code: qdSheet.getText(iRow, 0),
  3767. name: qdSheet.getText(iRow, 1),
  3768. unit: qdSheet.getText(iRow, 2),
  3769. price: _.toNumber(qdSheet.getText(iRow, 3)),
  3770. pos: [],
  3771. };
  3772. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  3773. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  3774. if (value !== 0 && !isNaN(value)) {
  3775. qd.pos.push({
  3776. name: posSheet.getText(iPosRow, 0),
  3777. drawing_code: posSheet.getText(iPosRow, 1),
  3778. quantity: value, porder: qd.pos.length + 1,
  3779. });
  3780. }
  3781. }
  3782. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  3783. }
  3784. return result;
  3785. }
  3786. }
  3787. class ContractExpr {
  3788. constructor(setting) {
  3789. const self = this;
  3790. this.obj = $('#contract_expr');
  3791. this.exprObj = $('#ce-expr');
  3792. this.exprSpread = SpreadJsObj.createNewSpread($('#expr_spread')[0]);
  3793. this.exprSheet = this.exprSpread.getActiveSheet();
  3794. const exprSpreadSetting = {
  3795. cols: [
  3796. { title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 180, formatter: '@', cellType: 'tree' },
  3797. { title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 100, formatter: '@' },
  3798. { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@' },
  3799. { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit' },
  3800. ],
  3801. emptyRows: 0,
  3802. headRows: 2,
  3803. headRowHeight: [25, 25],
  3804. defaultRowHeight: 21,
  3805. headerFont: '12px 微软雅黑',
  3806. font: '12px 微软雅黑',
  3807. readOnly: true,
  3808. getColor: function (sheet, data, row, col, defaultColor) {
  3809. if (self.targetNode && data && data.id === self.targetNode.id) {
  3810. return spreadColor.pay.expr_err;
  3811. } if (self.invalidRows && self.invalidRows.indexOf(row + 1) >= 0) {
  3812. return spreadColor.pay.yf_without;
  3813. } else {
  3814. return defaultColor;
  3815. }
  3816. }
  3817. };
  3818. sjsSettingObj.setFxTreeStyle(exprSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  3819. SpreadJsObj.initSheet(this.exprSheet, exprSpreadSetting);
  3820. this.exprTree = createNewPathTree('ledger', {
  3821. id: 'ledger_id',
  3822. pid: 'ledger_pid',
  3823. order: 'order',
  3824. level: 'level',
  3825. rootId: -1,
  3826. keys: ['id', 'tender_id', 'ledger_id'],
  3827. });
  3828. this.exprTree.loadDatas(setting.sourceTree.datas);
  3829. SpreadJsObj.loadSheetData(this.exprSheet, SpreadJsObj.DataType.Tree, this.exprTree);
  3830. // this.exprSpread.bind(spreadNS.Events.SelectionChanged, function(e, info) {
  3831. // const select = SpreadJsObj.getSelectObject(info.sheet);
  3832. // if (select && self.targetNode && select.id === self.targetNode.id) {
  3833. // $('#select-row').html('');
  3834. // } else {
  3835. // $('#select-row').html(`(${select.code || ''}${select.b_code || ''})`);
  3836. // }
  3837. // });
  3838. this.obj.bind('shown.bs.modal', function () {
  3839. self.exprSpread.refresh();
  3840. });
  3841. $('td[exprValue]').dblclick(function() {
  3842. const name = this.getAttribute('name');
  3843. let row;
  3844. if (name === 'tr') {
  3845. row = self.targetRow;
  3846. } else {
  3847. const node = SpreadJsObj.getSelectObject(self.exprSheet);
  3848. if (node.id === self.targetNode.id) return;
  3849. row = self.exprTree.nodes.indexOf(node) + 1;
  3850. }
  3851. if (self.invalidRows.indexOf(row) >= 0) return;
  3852. self.exprObj.val(self.exprObj.val() + `<<f${row}$${this.getAttribute('exprValue')}>>`);
  3853. });
  3854. $('#contract-expr-ok').click(function() {
  3855. const exprStr = $('#ce-expr').val().toLowerCase();
  3856. if ((!exprStr && !self.orgExpr) || (exprStr === self.orgExpr)) {
  3857. self.obj.modal('hide');
  3858. return;
  3859. }
  3860. const [valid, msg] = TreeExprCalc.checkExprValid(exprStr, self.invalidRows);
  3861. if (!valid) {
  3862. toastr.error(msg);
  3863. return;
  3864. }
  3865. const expr = TreeExprCalc.exprStr2Expr(exprStr);
  3866. if (expr.length > 500) {
  3867. toastr.error('输入表达式过长');
  3868. return;
  3869. }
  3870. // $('#ce-expr-org').val(expr + ' ' + TreeExprCalc.expr2ExprStr(expr));
  3871. postData('expr/save', { calc_module: 'stage', calc_tag: 'contract', calc_id: self.targetNode.id, expr }, function() {
  3872. self.targetNode.contract_expr = expr;
  3873. self.obj.modal('hide');
  3874. });
  3875. });
  3876. this.initLedgerSearch();
  3877. this.initShowLevel();
  3878. TreeExprCalc.init({ tree: this.exprTree });
  3879. }
  3880. search(keyword) {
  3881. this.searchResult = [];
  3882. this.searchCur = 0;
  3883. if (keyword) {
  3884. for (const [i, d] of this.exprSheet.zh_tree.nodes.entries()) {
  3885. if (d.code && d.code.indexOf(keyword) >= 0) {
  3886. this.searchResult.push(d);
  3887. continue;
  3888. }
  3889. if (d.b_code && d.b_code.indexOf(keyword) >= 0) {
  3890. this.searchResult.push(d);
  3891. continue;
  3892. }
  3893. if (d.name && d.name.indexOf(keyword) >= 0) {
  3894. this.searchResult.push(d);
  3895. continue;
  3896. }
  3897. }
  3898. }
  3899. $('#expr_search_count').html(`结果:${this.searchResult.length}`);
  3900. if (this.searchResult.length > 0) SpreadJsObj.locateTreeNode(this.exprSheet, this.searchResult[0].ledger_id);
  3901. }
  3902. searchPre() {
  3903. this.searchCur = this.searchCur - 1;
  3904. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  3905. SpreadJsObj.locateTreeNode(this.exprSheet, this.searchResult[this.searchCur].ledger_id);
  3906. }
  3907. searchNext() {
  3908. this.searchCur = this.searchCur + 1;
  3909. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  3910. SpreadJsObj.locateTreeNode(this.exprSheet, this.searchResult[this.searchCur].ledger_id);
  3911. }
  3912. initLedgerSearch() {
  3913. const self = this;
  3914. this.searchResult = [];
  3915. this.searchCur = 0;
  3916. $('#expr_search_count').html(`结果:${this.searchResult.length}`);
  3917. $('#expr_search_keyword').change(function () { self.search(this.value); });
  3918. $('#expr_search_pre').click(function (e) {
  3919. self.searchPre();
  3920. e.stopPropagation();
  3921. });
  3922. $('#expr_search_next').click(function (e) {
  3923. self.searchNext();
  3924. e.stopPropagation();
  3925. });
  3926. }
  3927. initShowLevel(){
  3928. // 显示层次
  3929. (function (select, sheet) {
  3930. $(select).click(function () {
  3931. const tag = $(this).attr('tag');
  3932. const tree = sheet.zh_tree;
  3933. if (!tree) return;
  3934. setTimeout(() => {
  3935. showWaitingView();
  3936. switch (tag) {
  3937. case "1":
  3938. case "2":
  3939. case "3":
  3940. case "4":
  3941. case "5":
  3942. tree.expandByLevel(parseInt(tag));
  3943. SpreadJsObj.refreshTreeRowVisible(sheet);
  3944. break;
  3945. case "last":
  3946. tree.expandByCustom(() => { return true; });
  3947. SpreadJsObj.refreshTreeRowVisible(sheet);
  3948. break;
  3949. case "leafXmj":
  3950. tree.expandToLeafXmj();
  3951. SpreadJsObj.refreshTreeRowVisible(sheet);
  3952. break;
  3953. }
  3954. closeWaitingView();
  3955. }, 100);
  3956. });
  3957. })('a[name=ce-showLevel]', this.exprSheet);
  3958. }
  3959. async setTargetNode(node) {
  3960. const self = this;
  3961. this.targetNode = node;
  3962. const relaNode = this.exprTree.getItems(node.ledger_id);
  3963. this.invalidNode = this.exprTree.getAllParents(relaNode);
  3964. this.invalidRows = this.invalidNode.map(x => {
  3965. return self.exprTree.nodes.indexOf(x) + 1;
  3966. });
  3967. this.targetRow = this.exprTree.nodes.indexOf(relaNode) + 1;
  3968. if (node.contract_expr === undefined) {
  3969. node.contract_expr = await postDataAsync('expr/load', {calc_module: 'stage', calc_tag: 'contract', calc_id: node.id});
  3970. }
  3971. this.orgExpr = node.contract_expr;
  3972. $('#ce-expr').val(TreeExprCalc.expr2ExprStr(this.orgExpr));
  3973. }
  3974. initView(node) {
  3975. this.orgExpr = '';
  3976. this.setTargetNode(node);
  3977. $('#expr-hint').html(`${node.code || ''}${node.b_code || ''} ${node.name || ''}`);
  3978. $('#target-row').html(`(${node.code || ''}${node.b_code || ''})`);
  3979. SpreadJsObj.locateTreeNode(this.exprSheet, node.ledger_id);
  3980. SpreadJsObj.reloadRowBackColor(this.exprSheet, 0, this.exprSheet.getRowCount());
  3981. this.exprSpread.refresh();
  3982. }
  3983. }
  3984. $('a', '#anc-gcl-nav').bind('click', function(e) {
  3985. e.preventDefault();
  3986. const tab = $(this);
  3987. const showSideTab = function (show) {
  3988. const left = $('#pos-spread'), right = $('#pos-right'), parent = left.parent();
  3989. if (show) {
  3990. right.show();
  3991. autoFlashHeight();
  3992. /**
  3993. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  3994. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  3995. * 故需要通过最终的parent.width再计算一次left.width
  3996. *
  3997. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  3998. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  3999. *
  4000. */
  4001. const percent = 100 - right.outerWidth() /parent.width() * 100;
  4002. left.css('width', percent + '%');
  4003. } else {
  4004. left.width(parent.width());
  4005. right.hide();
  4006. }
  4007. };
  4008. if (!tab.hasClass('active')) {
  4009. tab.addClass('active');
  4010. showSideTab(tab.hasClass('active'));
  4011. } else {
  4012. tab.removeClass('active');
  4013. showSideTab(tab.hasClass('active'));
  4014. }
  4015. if (posSpread) posSpread.refresh();
  4016. if (ancGclSpread) ancGclSpread.refresh();
  4017. });
  4018. $.divResizer({
  4019. select: '#pos-right-spr',
  4020. callback: function () {
  4021. if (posSpread) posSpread.refresh();
  4022. if (ancGclSpread) ancGclSpread.refresh();
  4023. }
  4024. });
  4025. // $('#searchAccount').click(() => {
  4026. // const data = {
  4027. // keyword: $('#searchName').val(),
  4028. // };
  4029. // postData('/search/user', data, (data) => {
  4030. // const resultDiv = $('#searchResult');
  4031. // if (data) {
  4032. // $('h5>span', resultDiv).text(data.name);
  4033. // $('#addAuditor').attr('auditorId', data.id);
  4034. // $('h6', resultDiv).text(data.role);
  4035. // $('p', resultDiv).text(data.company);
  4036. // resultDiv.show();
  4037. // } else {
  4038. // toastr.info('未查询到该审核人');
  4039. // resultDiv.hide();
  4040. // }
  4041. // }, () => {
  4042. // $('#searchResult').hide();
  4043. // });
  4044. // });
  4045. // // 审批人分组选择
  4046. // $('#account_group').change(function () {
  4047. // let account_html = '<option value="0">选择审批人</option>';
  4048. // for (const account of accountList) {
  4049. // if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  4050. // const role = account.role !== '' ? '(' + account.role + ')' : '';
  4051. // const company = account.company !== '' ? ' -' + account.company : '';
  4052. // account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  4053. // }
  4054. // }
  4055. // $('#account_list').html(account_html);
  4056. // });
  4057. let timer = null;
  4058. let oldSearchVal = null;
  4059. $('#gr-search').bind('input propertychange', function(e) {
  4060. oldSearchVal = e.target.value
  4061. timer && clearTimeout(timer)
  4062. timer = setTimeout(() => {
  4063. const newVal = $('#gr-search').val()
  4064. let html = ''
  4065. if (newVal && newVal === oldSearchVal) {
  4066. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  4067. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  4068. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  4069. class="ml-auto">${item.mobile || ''}</span></p>
  4070. <span class="text-muted">${item.role || ''}</span>
  4071. </dd>`
  4072. })
  4073. $('.book-list').empty()
  4074. $('.book-list').append(html)
  4075. } else {
  4076. if (!$('.acc-btn').length) {
  4077. accountGroup.forEach((group, idx) => {
  4078. if (!group) return
  4079. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  4080. </a> ${group.groupName}</dt>
  4081. <div class="dd-content" data-toggleid="${idx}">`
  4082. group.groupList.forEach(item => {
  4083. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  4084. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  4085. class="ml-auto">${item.mobile || ''}</span></p>
  4086. <span class="text-muted">${item.role || ''}</span>
  4087. </dd>`
  4088. });
  4089. html += '</div>'
  4090. })
  4091. $('.book-list').empty()
  4092. $('.book-list').append(html)
  4093. }
  4094. }
  4095. }, 400);
  4096. });
  4097. // 添加审批流程按钮逻辑
  4098. $('body').on('click', '.book-list dt', function () {
  4099. const idx = $(this).find('.acc-btn').attr('data-groupid')
  4100. const type = $(this).find('.acc-btn').attr('data-type')
  4101. if (type === 'hide') {
  4102. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  4103. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  4104. $(this).find('.acc-btn').attr('data-type', 'show')
  4105. })
  4106. } else {
  4107. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  4108. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  4109. $(this).find('.acc-btn').attr('data-type', 'hide')
  4110. })
  4111. }
  4112. return false
  4113. });
  4114. // 添加到审批流程中
  4115. $('#book-list').on('click', 'dd', function () {
  4116. const auditorId = parseInt($(this).data('id'));
  4117. if (!auditorId) return;
  4118. postData('/tender/' + getTenderId() + '/ledger/audit/add', { auditorId }, (datas) => {
  4119. const html = [];
  4120. // 如果是重新上报,添加到重新上报列表中
  4121. const auditorshtml = [];
  4122. for (const [index,data] of datas.entries()) {
  4123. if (index !== 0) {
  4124. html.push('<li class="list-group-item d-flex" auditorId="'+ data[0].audit_id +'">');
  4125. html.push(`<div class="col-auto">${index}</div>`);
  4126. html.push('<div class="col">');
  4127. for (const auditor of data) {
  4128. html.push(`<div class="d-inline-block mx-1"><i class="fa fa-user text-muted"></i> ${auditor.name} <small class="text-muted">${auditor.role}</small></div>`);
  4129. }
  4130. html.push('</div>');
  4131. html.push('<div class="col-auto">');
  4132. if (data[0].audit_type !== auditType.key.common) {
  4133. html.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} badge-bg-small"><small>${auditType.info[data[0].audit_type].long}</small></span>`);
  4134. }
  4135. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  4136. html.push('<a href="javascript: void(0)" class="text-danger pull-right ml-1">移除</a>');
  4137. }
  4138. html.push('</div>');
  4139. html.push('</li>');
  4140. }
  4141. auditorshtml.push('<li class="list-group-item" data-auditorid="' + data.audit_id + '">');
  4142. auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
  4143. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  4144. if (index === 0) {
  4145. auditorshtml.push('<span class="pull-right">原报</span>');
  4146. } else if (index+1 === datas.length) {
  4147. auditorshtml.push('<span class="pull-right">终审</span>');
  4148. } else {
  4149. auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
  4150. }
  4151. auditorshtml.push('</li>');
  4152. }
  4153. $('#auditors').html(html.join(''));
  4154. $('#auditors-list').html(auditorshtml.join(''));
  4155. });
  4156. });
  4157. $('body').on('click', '#auditors li>div>a', function () {
  4158. const li = $(this).parent().parent();
  4159. const data = {
  4160. auditorId: parseInt(li.attr('auditorId')),
  4161. };
  4162. postData('/tender/' + getTenderId() + '/ledger/audit/delete', data, (data2) => {
  4163. li.remove();
  4164. for (const a of data2) {
  4165. const aLi = $('li[auditorId=' + a.audit_id + ']');
  4166. $('div:first', aLi).text(a.audit_order);
  4167. }
  4168. // 如果是重新上报
  4169. // 令最后一个图标转换
  4170. $('#auditors-list li[data-auditorid="' + data.auditorId + '"]').remove();
  4171. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  4172. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  4173. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  4174. }
  4175. // $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  4176. // if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  4177. // $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  4178. // .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  4179. // }
  4180. for (let i = 0; i < $('#auditors-list li').length; i++) {
  4181. $('#auditors-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审')
  4182. // $('#auditors-list2 li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2 li').length ? '终' : transFormToChinese(i+1)) + '审')
  4183. }
  4184. });
  4185. });
  4186. $('#hideSp').click(function () {
  4187. $('#sp-list').modal('hide');
  4188. });
  4189. $('a[f-target]').click(function () {
  4190. $($(this).attr('f-target')).modal('show');
  4191. });
  4192. // 多层modal关闭后的滚动bug修复
  4193. $('#sp-list').on('hidden.bs.modal', function (e) {
  4194. $(document.body).addClass('modal-open');
  4195. });
  4196. // 管理员更改审批流程js部分
  4197. let timer2 = null;
  4198. let oldSearchVal2 = null;
  4199. $('body').on('input propertychange', '.gr-search', function(e) {
  4200. oldSearchVal2 = e.target.value;
  4201. timer2 && clearTimeout(timer2);
  4202. timer2 = setTimeout(() => {
  4203. const newVal = $(this).val();
  4204. const code = $(this).attr('data-code');
  4205. let html = '';
  4206. if (newVal && newVal === oldSearchVal2) {
  4207. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  4208. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  4209. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  4210. class="ml-auto">${item.mobile || ''}</span></p>
  4211. <span class="text-muted">${item.role || ''}</span>
  4212. </dd>`
  4213. });
  4214. $('#' + code + '_dropdownMenu .book-list').empty();
  4215. $('#' + code + '_dropdownMenu .book-list').append(html);
  4216. } else {
  4217. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  4218. accountGroup.forEach((group, idx) => {
  4219. if (!group) return;
  4220. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  4221. </a> ${group.groupName}</dt>
  4222. <div class="dd-content" data-toggleid="${idx}">`;
  4223. group.groupList.forEach(item => {
  4224. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  4225. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  4226. class="ml-auto">${item.mobile || ''}</span></p>
  4227. <span class="text-muted">${item.role || ''}</span>
  4228. </dd>`;
  4229. });
  4230. html += '</div>';
  4231. });
  4232. $('#' + code + '_dropdownMenu .book-list').empty();
  4233. $('#' + code + '_dropdownMenu .book-list').append(html);
  4234. }
  4235. }
  4236. }, 400);
  4237. });
  4238. const getAdminEditShenpiListHtml = function(auditGroup) {
  4239. const html = [];
  4240. for (const [i, group] of auditGroup.entries()) {
  4241. if (i === 0) continue;
  4242. for (const [j, auditor] of group.entries()) {
  4243. html.push('<tr>');
  4244. if (j === 0) {
  4245. const auditTypeHtml = auditor.type === auditType.key.common ? '' : `<span class="ml-2 badge badge-pill badge-${auditType.info[auditor.audit_type].class} p-1"><small>${auditType.info[auditor.audit_type].short}</small></span>`;
  4246. html.push(`<td class="text-left d-flex">${i + '审'}${auditTypeHtml}</td>`);
  4247. } else {
  4248. html.push(`<td class="text-left d-flex"></td>`);
  4249. }
  4250. html.push(`<td></span> ${auditor.name} <small class="text-muted">${auditor.role}</small></td>`);
  4251. html.push(`<td style="text-align: center"><span class="${auditConst.auditStringClass[auditor.status]}">${ auditor.status !== auditConst.status.uncheck ? auditConst.auditString[auditor.status] : '待审批' }</span></td>`);
  4252. html.push('<td style="text-align: center">');
  4253. if (auditor.status === auditConst.status.checking && j === group.length - 1) {
  4254. html.push('<span class="dropdown mr-2">',
  4255. `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,
  4256. makeSelectAudit(auditor.audit_id+'_add', auditor.audit_id, 'add'),'</div>', '</span>');
  4257. }
  4258. if (auditor.status === auditConst.status.uncheck) {
  4259. if (j === group.length - 1) {
  4260. html.push('<span class="dropdown mr-2">',
  4261. `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,
  4262. makeSelectAudit(auditor.audit_id+'_add', auditor.audit_id, 'add'),'</div>', '</span>');
  4263. if (auditor.audit_type !== auditType.key.common) {
  4264. html.push('<span class="dropdown mr-2">',
  4265. `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">平级</a>`,
  4266. makeSelectAudit(auditor.audit_id+'_add-sibling', auditor.audit_id, 'add-sibling'),'</div>', '</span>');
  4267. }
  4268. }
  4269. html.push('<span class="dropdown mr-2">',
  4270. `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">更换</a>`,
  4271. makeSelectAudit(auditor.audit_id+'_change', auditor.audit_id, 'change'),'</div>', '</span>');
  4272. html.push(`<span class="dropdown">
  4273. <a href="javascript: void(0)" class="text-danger" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">移除</a>
  4274. <div class="dropdown-menu">
  4275. <span class="dropdown-item" href="javascript:void(0);">确认移除审批人?</span>
  4276. <div class="dropdown-divider"></div>
  4277. <div class="px-2 py-1 text-center">
  4278. <button class="remove-audit btn btn-sm btn-danger" data-id="${auditor.audit_id}">移除</button>
  4279. <button class="btn btn-sm btn-secondary">取消</button>
  4280. </div>
  4281. </div>
  4282. </span>`);
  4283. }
  4284. html.push('</td>');
  4285. html.push('</tr>');
  4286. }
  4287. }
  4288. return html.join('');
  4289. };
  4290. $('body').on('click', '#admin-edit-shenpi dl dd', function () {
  4291. const id = parseInt($(this).attr('data-id'));
  4292. if (!id) return;
  4293. let this_aid = parseInt($(this).parents('.book-list').attr('data-aid'));
  4294. let this_operate = $(this).parents('.book-list').attr('data-operate');
  4295. const user = _.find(accountList, function (item) {
  4296. return item.id === id;
  4297. });
  4298. const auditorIndex = _.findIndex(auditorList, { audit_id: id });
  4299. if (auditorIndex !== -1) {
  4300. toastr.warning('该审核人已存在,请勿重复添加');
  4301. return;
  4302. }
  4303. const prop = {
  4304. operate: this_operate,
  4305. old_aid: this_aid,
  4306. new_aid: user.id,
  4307. };
  4308. postData('/tender/' + getTenderId() + '/ledger/audit/save', prop, (datas) => {
  4309. auditorList = datas.auditors;
  4310. $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas.auditorUniqs));
  4311. changeLiucheng(datas.auditorUniqs);
  4312. });
  4313. });
  4314. // 移除审批人
  4315. $('body').on('click', '.remove-audit', function () {
  4316. const id = parseInt($(this).attr('data-id'));
  4317. const prop = {
  4318. operate: 'del',
  4319. old_aid: id,
  4320. };
  4321. postData('/tender/' + getTenderId() + '/ledger/audit/save', prop, (datas) => {
  4322. auditorList = datas.auditors;
  4323. $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas.auditorUniqs));
  4324. changeLiucheng(datas.auditorUniqs);
  4325. });
  4326. });
  4327. const getAuditTypeText = function (type) {
  4328. if (type === auditType.key.common) return '';
  4329. return `<span class="text-${auditType.info[type].class}">${auditType.info[type].long}</span>`;
  4330. };
  4331. function changeLiucheng(datas) {
  4332. const auditorshtml = [];
  4333. let lastAuditorHtml = [];
  4334. for (const [index,data] of datas.entries()) {
  4335. auditorshtml.push('<li class="list-group-item d-flex justify-content-between align-items-center">');
  4336. if (index === 0) {
  4337. auditorshtml.push('<span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>');
  4338. } else if (index+1 === datas.length) {
  4339. auditorshtml.push('<span class="mr-1"><i class="fa fa fa-stop-circle"></i></span>');
  4340. } else {
  4341. auditorshtml.push('<span class="mr-1"><i class="fa fa-chevron-circle-down"></i></span>');
  4342. }
  4343. auditorshtml.push('<span class="text-muted">');
  4344. for (const u of data) {
  4345. auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${u.role}" data-auditorId="${u.audit_id}">${u.name}</small>`);
  4346. }
  4347. auditorshtml.push('</span>');
  4348. auditorshtml.push('<div class="d-flex ml-auto">');
  4349. if (data[0].audit_type !== auditType.key.common) auditorshtml.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} p-1"><small>${auditType.info[data[0].audit_type].short}</small></span>`);
  4350. if (index === 0) {
  4351. auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
  4352. } else if (index+1 === datas.length) {
  4353. auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
  4354. } else {
  4355. auditorshtml.push('<span class="badge badge-light badge-pill"><small>'+ transFormToChinese(index) +'审</small></span>');
  4356. }
  4357. auditorshtml.push('</div>');
  4358. auditorshtml.push('</li>');
  4359. if (data[0].status === auditConst.status.uncheck) {
  4360. lastAuditorHtml.push('<li class="timeline-list-item pb-2 is_uncheck">');
  4361. if (index < datas.length - 1) {
  4362. lastAuditorHtml.push('<div class="timeline-item-tail"></div>');
  4363. }
  4364. lastAuditorHtml.push('<div class="timeline-item-icon bg-secondary text-light"></div>');
  4365. lastAuditorHtml.push('<div class="timeline-item-content">');
  4366. lastAuditorHtml.push(`<div class="py-1">
  4367. <span class="text-black-50">
  4368. ${ index !== datas.length - 1 ? data[0].audit_order + '' : '终' }审 ${getAuditTypeText(data[0].audit_type)}
  4369. </span>
  4370. </div>`);
  4371. lastAuditorHtml.push('<div class="card"><div class="card-body px-3 py-0">');
  4372. for (const [i, auditor] of data.entries()) {
  4373. lastAuditorHtml.push(`<div class="card-text p-2 py-3 row ${ ( i > 0 ? 'border-top' : '') }">`);
  4374. lastAuditorHtml.push(`<div class="col"><span class="h6">${auditor.name}</span><span class="text-muted ml-1">${auditor.role}</span></div>`);
  4375. lastAuditorHtml.push('<div class="col">');
  4376. lastAuditorHtml.push('</div>');
  4377. lastAuditorHtml.push('</div>');
  4378. }
  4379. lastAuditorHtml.push('</div></div>');
  4380. lastAuditorHtml.push('</div>');
  4381. lastAuditorHtml.push('</li>');
  4382. }
  4383. }
  4384. $('.last-auditor-list .is_uncheck').remove();
  4385. $('.last-auditor-list').append(lastAuditorHtml.join(''));
  4386. $('.auditors-list').html(auditorshtml.join(''));
  4387. }
  4388. // 审批流程-选择审批人html 生成
  4389. function makeSelectAudit(code, aid, status) {
  4390. let divhtml = '';
  4391. accountGroup.forEach((group, idx) => {
  4392. let didivhtml = '';
  4393. if(group) {
  4394. group.groupList.forEach(item => {
  4395. didivhtml += '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  4396. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  4397. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  4398. ' <span class="text-muted">' + item.role + '</span>\n' +
  4399. ' </dd>\n';
  4400. });
  4401. divhtml += '<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="' + idx + '" data-type="hide"><i class="fa fa-plus-square"></i></a> ' + group.groupName + '</dt>\n' +
  4402. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  4403. ' </div>\n';
  4404. }
  4405. });
  4406. let html = '<div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  4407. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  4408. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  4409. ' <dl class="list-unstyled book-list" data-aid="'+ aid +'" data-operate="'+ status +'">\n' + divhtml +
  4410. ' </dl>\n' +
  4411. ' </div>\n' +
  4412. ' </div>\n' +
  4413. ' </span>\n' +
  4414. ' </span>\n' +
  4415. ' </li>';
  4416. return html;
  4417. }
  4418. // 显示层次
  4419. (function (select, sheet) {
  4420. $(select).click(function () {
  4421. const tag = $(this).attr('tag');
  4422. const tree = sheet.zh_tree;
  4423. if (!tree) return;
  4424. setTimeout(() => {
  4425. showWaitingView();
  4426. switch (tag) {
  4427. case "1":
  4428. case "2":
  4429. case "3":
  4430. case "4":
  4431. case "5":
  4432. tree.expandByLevel(parseInt(tag));
  4433. SpreadJsObj.refreshTreeRowVisible(sheet);
  4434. break;
  4435. case "last":
  4436. tree.expandByCustom(() => { return true; });
  4437. SpreadJsObj.refreshTreeRowVisible(sheet);
  4438. break;
  4439. case "leafXmj":
  4440. tree.expandToLeafXmj();
  4441. SpreadJsObj.refreshTreeRowVisible(sheet);
  4442. break;
  4443. }
  4444. closeWaitingView();
  4445. }, 100);
  4446. });
  4447. })('a[name=showLevel]', ledgerSpread.getActiveSheet());
  4448. // $('#exportLedger').click(function () {
  4449. // const data = [];
  4450. // const setting = {
  4451. // header: ['项目节编号', '清单子目号', '部位明细', '名称', '单位', '清单数量', '设计数量1', '设计数量2', '单价', '合价', '图号', '备注'],
  4452. // width: [100, 70, 70, 300, 60, 80, 80, 80, 80, 80, 100, 100],
  4453. // hAlign: ['left', 'left', 'left', 'left','center', 'right', 'right', 'right', 'right', 'right', 'left', 'left'],
  4454. // };
  4455. // for (const node of ledgerTree.nodes) {
  4456. // data.push([node.code, node.b_code, '', node.name, node.unit,
  4457. // node.quantity, node.dgn_qty1, node.dgn_qty2, node.unit_price, node.total_price,
  4458. // node.drawing_code, node.memo
  4459. // ]);
  4460. // const posRange = pos.getLedgerPos(node.id);
  4461. // if (posRange && posRange.length > 0) {
  4462. // for (const [i, p] of posRange.entries()) {
  4463. // data.push(['', '', (i + 1) + '', p.name, '',
  4464. // p.quantity, '', '', '', '',
  4465. // p.drawing_code, p.memo
  4466. // ]);
  4467. // }
  4468. // }
  4469. // }
  4470. //
  4471. // XLSXObj.exportXlsxSheet(setting, data, "台账分解.xlsx");
  4472. // });
  4473. $('#exportLedger').click(function () {
  4474. const data = [], groupData = [];
  4475. const setting = {
  4476. cols: [
  4477. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  4478. {title: '清单子目号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  4479. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'pos_code', hAlign: 1, width: 70, formatter: '@'},
  4480. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@'},
  4481. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  4482. {title: '签约数量', colSpan: '1', rowSpan: '1', field: 'deal_qty', hAlign: 2, width: 80, type: 'Number'},
  4483. {title: '签约金额', colSpan: '1', rowSpan: '1', field: 'deal_tp', hAlign: 2, width: 80, type: 'Number'},
  4484. {title: '清单数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  4485. {title: '设计数量1', colSpan: '1', rowSpan: '1', field: 'dgn_qty1', hAlign: 2, width: 80, type: 'Number'},
  4486. {title: '设计数量2', colSpan: '1', rowSpan: '1', field: 'dgn_qty2', hAlign: 2, width: 80, type: 'Number'},
  4487. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  4488. {title: '合价', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  4489. {title: '图号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 100, formatter: '@'},
  4490. {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 100, formatter: '@'},
  4491. {title: '项目特征', colSpan: '1', rowSpan: '1', field: 'features', hAlign: 0, width: 120, formatter: '@', wordWrap: true },
  4492. ],
  4493. headRows: 1,
  4494. headRowHeight: [32],
  4495. defaultRowHeight: 21,
  4496. headerFont: 'bold 10px 微软雅黑',
  4497. font: '10px 微软雅黑'
  4498. };
  4499. const hasCl = ledgerSpreadSetting.cols.find(x => { return x.field === 'sjcl_qty'});
  4500. const qtyF = hasCl ? 'quantity' : 'sgfh_qty';
  4501. const tpF = hasCl ? 'total_price' : 'sgfh_tp';
  4502. ledgerTree.recursiveExe(function(node) {
  4503. if (node.children && node.children.length > 0) {
  4504. node._export_group = _.sum(node.children.map(x => { return x._export_group; })) + node.children.length;
  4505. } else {
  4506. const posRange = pos.getLedgerPos(node.id);
  4507. node._export_group = posRange ? posRange.length : 0;
  4508. }
  4509. });
  4510. for (const node of ledgerTree.nodes) {
  4511. data.push({
  4512. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  4513. unit_price: node.unit_price, quantity: node[qtyF], total_price: node[tpF],
  4514. deal_qty: node.deal_qty, deal_tp: node.deal_tp,
  4515. dgn_qty1: node.dgn_qty1, dgn_qty2: node.dgn_qty2,
  4516. drawing_code: node.drawing_code, memo: node.memo, features: node.features,
  4517. });
  4518. // if (ledgerTree.isLeafXmj(node) && node._export_group) groupData.push({ code: node.code, b_code: node.b_code, start: data.length, count: node._export_group });
  4519. const posRange = pos.getLedgerPos(node.id);
  4520. if (posRange && posRange.length > 0) {
  4521. if (node._export_group) groupData.push({ code: node.code, b_code: node.b_code, start: data.length, count: node._export_group });
  4522. for (const [i, p] of posRange.entries()) {
  4523. data.push({
  4524. pos_code: (i + 1) + '', name: p.name,
  4525. quantity: p[qtyF], drawing_code: p.drawing_code, memo: p.memo
  4526. });
  4527. }
  4528. }
  4529. }
  4530. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, "台账分解.xlsx", groupData);
  4531. });
  4532. $('#sync-ledger').click(function () {
  4533. postData(syncLedgerUrl, {}, function (result) {
  4534. ledgerTree.loadDatas(result.bills);
  4535. treeCalc.calculateAll(ledgerTree);
  4536. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  4537. pos.loadDatas(result.pos);
  4538. posOperationObj.loadCurPosData();
  4539. ancGclObj.loadCurAncillaryGcl();
  4540. checkShowLast(result.bills.length);
  4541. });
  4542. });
  4543. const dataChecker = DataChecker({
  4544. checkUrl: window.location.pathname + '/check',
  4545. completeData: function (data) {
  4546. pos.updateDatas({update: data.source.pos});
  4547. const loadResult = ledgerTree.loadPostData({update: data.source.bills});
  4548. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  4549. posOperationObj.loadCurPosData();
  4550. ancGclObj.loadCurAncillaryGcl();
  4551. for (const e of data.error) {
  4552. e.serialNo = ledgerTree.getNodeIndex(ledgerTree.getItems(e.ledger_id)) + 1;
  4553. }
  4554. },
  4555. errorList: errorList,
  4556. });
  4557. $('[name=audit-start]').submit(function (e) {
  4558. if (checkAuditorFrom()) {
  4559. $(this).parent().parent().parent().modal('hide');
  4560. dataChecker.checkAndPost(this.action, {});
  4561. $('#hide-all').hide();
  4562. }
  4563. return false;
  4564. });
  4565. $('#ledger-check2').click(() => {
  4566. ledgerCheck2({
  4567. ledgerTree: ledgerTree,
  4568. ledgerPos: pos,
  4569. checkList: checkList,
  4570. decimal: tenderInfo.decimal,
  4571. checkOption: checkOption,
  4572. }).then(result => {
  4573. check2Viewing({
  4574. extra: ZhCalc.div(ledgerTree.datas.length + pos.datas.length, 10000, 0),
  4575. randomWait: true,
  4576. prefix: 'check2-',
  4577. checks: result,
  4578. checkList: checkList,
  4579. });
  4580. });
  4581. });
  4582. // 切换附件里节点和所有附件
  4583. $('#fujian .nav-link').on('click', function () {
  4584. const tabPanel = $(this).attr('fujian-content');
  4585. if (tabPanel !== 'syfujian') {
  4586. $('#showPage').hide();
  4587. $('#bach-download').prop('type', 'curr');
  4588. } else {
  4589. $('#showPage').show();
  4590. $('#bach-download').prop('type', 'all');
  4591. }
  4592. $('#showAttachment').hide();
  4593. });
  4594. // 上传附件
  4595. $('#upload-file-btn').click(function () {
  4596. // if (curAuditor && curAuditor.aid !== userID) {
  4597. // return toastr.error('当前操作没有权限!');
  4598. // }
  4599. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  4600. if (!node) return;
  4601. const files = $('#upload-file')[0].files;
  4602. const formData = new FormData();
  4603. formData.append('lid', node.id);
  4604. for (const file of files) {
  4605. if (file === undefined) {
  4606. toastr.error('未选择上传文件!');
  4607. return false;
  4608. }
  4609. const filesize = file.size;
  4610. if (filesize > 50 * 1024 * 1024) {
  4611. toastr.error('存在上传文件大小过大!');
  4612. return false;
  4613. }
  4614. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  4615. if (whiteList && !whiteList.includes(fileext)) {
  4616. toastr.error('只能上传指定格式的附件!');
  4617. return false;
  4618. }
  4619. formData.append('size', filesize);
  4620. formData.append('file[]', file);
  4621. }
  4622. postDataWithFile('/tender/' + tender.id + '/ledger/upload/file', formData, function (data) {
  4623. $('#upload').modal('hide');
  4624. // 插入到attData中
  4625. attData = data.concat(attData);
  4626. // 重新生成List
  4627. getAllList();
  4628. getNodeList(node.id);
  4629. }, function () {
  4630. toastr.error('附件上传失败');
  4631. });
  4632. $('#upload-file').val('');
  4633. });
  4634. // 获取附件信息
  4635. $('.list-table').on('click', '.att-file-name', function () {
  4636. const fid = $(this).attr('file-id');
  4637. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  4638. return;
  4639. }
  4640. const att = attData.find(function (item) {
  4641. return item.id === parseInt(fid);
  4642. });
  4643. $('#edit-att').hide();
  4644. $('#show-att').show();
  4645. if (att !== undefined) {
  4646. // 进来先把编辑功能隐藏
  4647. $('#btn-att a').eq(3).hide()
  4648. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  4649. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4650. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  4651. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  4652. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  4653. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  4654. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  4655. $('#show-att tr').eq(3).children('td').text(att.remark);
  4656. // 附件uid等于当前用户id, 附件上传本人
  4657. if (parseInt(userID) === att.uid) {
  4658. $('#btn-att').show();
  4659. const showDel = tender.ledger_status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  4660. if (showDel) $('#btn-att a').eq(3).show();
  4661. // $('#btn-att a').eq(3).show();
  4662. $('#btn-att a').eq(2).hide();
  4663. $('#btn-att a').eq(4).hide();
  4664. $('#btn-att a').eq(5).hide();
  4665. } else {
  4666. $('#btn-att').hide();
  4667. $('#btn-att a').eq(3).hide();
  4668. $('#btn-att a').eq(2).hide();
  4669. $('#btn-att a').eq(4).hide();
  4670. $('#btn-att a').eq(5).hide();
  4671. }
  4672. $('#showAttachment').attr('file-id', fid);
  4673. $('#showAttachment').show();
  4674. } else {
  4675. $('#showAttachment').hide();
  4676. $('#showAttachment').attr('file-id', '');
  4677. toastr.error('附件信息获取失败');
  4678. }
  4679. });
  4680. // $('body').on('click', '.alllist-table a', handleFileList);
  4681. $('body').on('click', '#btn-att a', function () {
  4682. const content = $(this).attr('content');
  4683. const fid = $('#showAttachment').attr('file-id');
  4684. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  4685. if (content === 'edit') {
  4686. $('#btn-att a').eq(3).hide();
  4687. $('#btn-att a').eq(2).show();
  4688. $('#btn-att a').eq(4).show();
  4689. $('#btn-att a').eq(5).show();
  4690. $('#show-att').hide();
  4691. $('#edit-att').show();
  4692. const att = attData.find(function (item) {
  4693. return item.id === parseInt(fid);
  4694. });
  4695. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  4696. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  4697. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4698. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  4699. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  4700. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  4701. } else if (content === 'cancel') {
  4702. $('#show-att').show();
  4703. $('#edit-att').hide();
  4704. $('#btn-att a').eq(3).show();
  4705. $('#btn-att a').eq(2).hide();
  4706. $('#btn-att a').eq(4).hide();
  4707. $('#btn-att a').eq(5).hide();
  4708. } else if (content === 'save') {
  4709. const formData = new FormData();
  4710. formData.append('id', fid);
  4711. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  4712. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  4713. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  4714. const file = $('#change-att-btn')[0];
  4715. if (file.files[0] !== undefined) {
  4716. const filesize = file.files[0].size;
  4717. formData.append('size', filesize);
  4718. formData.append('file', file.files[0]);
  4719. }
  4720. postDataWithFile('/tender/' + tender.id + '/ledger/save/file', formData, function (data) {
  4721. // 替换到attData中
  4722. const att_index = attData.findIndex(function (item) {
  4723. return item.id === parseInt(fid);
  4724. });
  4725. attData.splice(att_index, 1, data);
  4726. // 重新生成List
  4727. getAllList(parseInt($('#currentPage').text()));
  4728. getNodeList(node.id);
  4729. $('#show-att').show();
  4730. $('#edit-att').hide();
  4731. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4732. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4733. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4734. $('#show-att tr').eq(2).children('td').eq(0).text(data.username);
  4735. $('#show-att tr').eq(2).children('td').eq(1).text(data.in_time);
  4736. $('#show-att tr').eq(3).children('td').text(data.remark);
  4737. $('#btn-att a').eq(3).show();
  4738. $('#btn-att a').eq(2).hide();
  4739. $('#btn-att a').eq(4).hide();
  4740. $('#btn-att a').eq(5).hide();
  4741. }, function () {
  4742. toastr.error('附件上传失败');
  4743. });
  4744. $('#change-att-btn').val('');
  4745. } else if (content === 'del') {
  4746. const data = {id: fid};
  4747. postData('/tender/' + tender.id + '/ledger/delete/file', data, function (result) {
  4748. // 删除到attData中
  4749. const att_index = attData.findIndex(function (item) {
  4750. return item.id === parseInt(fid);
  4751. });
  4752. attData.splice(att_index, 1);
  4753. // 重新生成List
  4754. if ($('#alllist-table tr').length === 1) {
  4755. getAllList(parseInt($('#currentPage').text()) - 1);
  4756. } else {
  4757. getAllList(parseInt($('#currentPage').text()));
  4758. }
  4759. getNodeList(node.id);
  4760. $('#showAttachment').hide();
  4761. $('#showAttachment').attr('file-id', '');
  4762. });
  4763. } else if (content === 'view') {
  4764. const data = {id: fid};
  4765. postData('/tender/' + tender.id + '/ledger/check/file', data, function (result) {
  4766. const { filepath } = result
  4767. $('#load-file').attr('href', filepath);
  4768. $('#load-file')[0].click();
  4769. });
  4770. } else if (content === 'location') {
  4771. const att = attData.find(item => item.id === parseInt(fid));
  4772. if (Object.keys(att).length) {
  4773. SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), att.ledger_id, true);
  4774. posOperationObj.loadCurPosData();
  4775. ancGclObj.loadCurAncillaryGcl();
  4776. }
  4777. }
  4778. });
  4779. // 替换附件
  4780. $('#change-att-btn').on('change', function () {
  4781. const file = $('#change-att-btn')[0].files[0];
  4782. const name = file.name;
  4783. const filename = name.substring(0, name.lastIndexOf("."));
  4784. const fileext = name.substr(name.indexOf("."));
  4785. const filesize = file.size;
  4786. if (filesize > 50 * 1024 * 1024) {
  4787. toastr.error('文件大小过大!');
  4788. $('#change-att-btn').val('');
  4789. return false;
  4790. }
  4791. if (whiteList && !whiteList.includes(fileext)) {
  4792. toastr.error('只能上传指定格式的附件!');
  4793. $('#change-att-btn').val('');
  4794. return false;
  4795. }
  4796. $('#edit-att .form-group').eq(0).find('input').val(filename);
  4797. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  4798. });
  4799. // 切换页数
  4800. $('.page-select').on('click', function () {
  4801. const totalPageNum = parseInt($('#totalPage').text());
  4802. const lastPageNum = parseInt($('#currentPage').text());
  4803. const status = $(this).attr('content');
  4804. if (status === 'pre' && lastPageNum > 1) {
  4805. getAllList(lastPageNum-1);
  4806. $('#showAttachment').hide();
  4807. $('#syfujian .check-all-file').prop('checked', false)
  4808. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4809. getAllList(lastPageNum+1);
  4810. $('#showAttachment').hide();
  4811. $('#syfujian .check-all-file').prop('checked', false)
  4812. }
  4813. });
  4814. // 批量下载
  4815. $('#bach-download').click(function() {
  4816. const fileIds = [];
  4817. const type = $(this).attr('type');
  4818. let node = ''
  4819. if (type === 'curr') {
  4820. node = '#nodelist-table .check-file:checked'
  4821. } else {
  4822. node = '#alllist-table .check-file:checked'
  4823. }
  4824. $(node).each(function() {
  4825. const fileId = $(this).attr('file-id');
  4826. fileId && fileIds.push(fileId);
  4827. });
  4828. if (fileIds.length) {
  4829. if (fileIds.length > 20) {
  4830. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  4831. }
  4832. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  4833. $(this).attr('disabled', "true")
  4834. const btn = $(this);
  4835. const fileArr = [];
  4836. for (const id of fileIds) {
  4837. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  4838. fileArr.push({
  4839. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  4840. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  4841. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  4842. });
  4843. }
  4844. const packageName = `${tender.name}-台账分解-附件.zip`;
  4845. try {
  4846. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  4847. } catch (e) {
  4848. btn.removeAttr('disabled');
  4849. toastr.clear();
  4850. toastr.error('批量下载失败');
  4851. }
  4852. // postCompressFile(`/tender/${tender.id}/ledger/compresse/file`, {fileIds}, function(result) {
  4853. // toastr.clear()
  4854. // toastr.success('压缩文件成功')
  4855. // btn.removeAttr('disabled')
  4856. // const href = window.URL.createObjectURL(result)
  4857. // $('#zipDown').attr('href', href);
  4858. // $('#zipDown').attr('download', `${tender.name}-台账分解-附件.zip`);
  4859. // $("#zipDown")[0].click();
  4860. // }, () => {
  4861. // btn.removeAttr('disabled')
  4862. // toastr.clear()
  4863. // toastr.error('批量下载失败')
  4864. // });
  4865. // const url = `/tender/${tender.id}/ledger/compresse/file?fileIds=${JSON.stringify(fileIds)}`;
  4866. }
  4867. });
  4868. // 监听附件check是否选中
  4869. $('.list-table').on('click', '.check-file', function() {
  4870. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  4871. const childs = $(this).parents('.list-table').children().length;
  4872. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  4873. if (checkedList.length === childs) {
  4874. checkBox.prop("checked", true);
  4875. } else {
  4876. checkBox.prop("checked", false);
  4877. }
  4878. });
  4879. $('.check-all-file').click(function() {
  4880. const isCheck = $(this).is(':checked');
  4881. $(this).parents('table').find('.list-table').each(function() {
  4882. $(this).find('input:checkbox').prop("checked", isCheck);
  4883. })
  4884. });
  4885. $('body').on('click', 'a[name=att-delete]', function() {
  4886. const fid = this.getAttribute('file-id');
  4887. if (!fid) return;
  4888. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  4889. const data = {id: fid};
  4890. postData('/tender/' + tender.id + '/ledger/delete/file', data, function (result) {
  4891. // 删除到attData中
  4892. const att_index = attData.findIndex(function (item) {
  4893. return item.id === parseInt(fid);
  4894. });
  4895. attData.splice(att_index, 1);
  4896. // 重新生成List
  4897. if ($('#alllist-table tr').length === 1) {
  4898. getAllList(parseInt($('#currentPage').text()) - 1);
  4899. } else {
  4900. getAllList(parseInt($('#currentPage').text()));
  4901. }
  4902. getNodeList(node.id);
  4903. $('#showAttachment').hide();
  4904. $('#showAttachment').attr('file-id', '');
  4905. });
  4906. });
  4907. $('#upload-ybp-file').click(function () {
  4908. const file = $('#ybp-file')[0];
  4909. const formData = new FormData();
  4910. formData.append('file', file.files[0]);
  4911. postDataWithFile('ledger/ybp', formData, function (result) {
  4912. ledgerTree.loadDatas(result.bills);
  4913. treeCalc.calculateAll(ledgerTree);
  4914. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  4915. pos.loadDatas(result.pos);
  4916. posOperationObj.loadCurPosData();
  4917. checkShowLast(result.bills.length);
  4918. $('#upload-ybp').modal('hide');
  4919. }, function () {
  4920. $('#upload-ybp').modal('hide');
  4921. });
  4922. });
  4923. $('#id-upload-ybp').click(function() {
  4924. $('#import-dsk').modal('hide');
  4925. $('#upload-ybp').modal('show');
  4926. });
  4927. $('#id-post-dsk').click(async function() {
  4928. if (await dsk.checkBind()) {
  4929. $('#import-dsk').modal('hide');
  4930. dsk.chooseSubject({
  4931. validCheck: function (node, tree) {
  4932. const checkType = node.type !== dsk.projectTypeKey.folder;
  4933. if (!checkType) {
  4934. toastr.warning('请勿选择文件夹');
  4935. return false;
  4936. }
  4937. const choosed = tree.datas.filter(x => { return !!x.selected; });
  4938. if (choosed.length === 0) return true;
  4939. if (node.project_id !== choosed[0].project_id) {
  4940. toastr.warning('请勿跨建设项目选择');
  4941. return false;
  4942. }
  4943. return true;
  4944. },
  4945. callback: async function (subjects) {
  4946. // console.log(await dsk.loadBills(subjects[0].compilationId, subjects[0].subjectId));
  4947. postData('ledger/dsk', {subjects}, function (result) {
  4948. ledgerTree.loadDatas(result.bills);
  4949. treeCalc.calculateAll(ledgerTree);
  4950. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  4951. pos.loadDatas(result.pos);
  4952. posOperationObj.loadCurPosData();
  4953. checkShowLast(result.bills.length);
  4954. });
  4955. }
  4956. });
  4957. } else {
  4958. $('#binddskuser').modal('show');
  4959. }
  4960. });
  4961. });
  4962. // 生成当前节点列表
  4963. function getNodeList(node) {
  4964. let html = '';
  4965. for(const att of attData) {
  4966. if (node === att.lid) {
  4967. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  4968. const delHtml = deleteFilePermission && parseInt(userID) === att.uid
  4969. ? `<a class="ml-1 text-danger" href="javascript:void(0)" name="att-delete" file-id="${att.id}"><i class="fa fa-close" title="删除"></i></a>`
  4970. : '';
  4971. html += `<tr>
  4972. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  4973. <td>
  4974. <div class="d-flex">
  4975. <a href="javascript:void(0)" class="pl-0 col-10 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  4976. <div class="att-file-btn col-2">
  4977. <a href="/tender/${tender.id}/ledger/download/file/${att.id}" class="pl-0"><i class="fa fa-download"></i></a>
  4978. ${delHtml}
  4979. </div>
  4980. </div>
  4981. </td><td>${att.username}</td></tr>`
  4982. }
  4983. }
  4984. $('#nodelist-table').html(html);
  4985. $('#nodelist-table').on('click', 'tr', function() {
  4986. $('#nodelist-table tr').removeClass('bg-light')
  4987. $(this).addClass('bg-light')
  4988. })
  4989. }
  4990. // 生成所有附件列表
  4991. function getAllList(currPageNum = 1) {
  4992. // 每页最多几个附件
  4993. const pageCount = 20;
  4994. // 附件总数
  4995. const total = attData.length;
  4996. // 总页数
  4997. const pageNum = Math.ceil(total/pageCount);
  4998. $('#totalPage').text(pageNum);
  4999. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  5000. // 当前页附件内容
  5001. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  5002. currPageFileData = currPageAttData;
  5003. let html = '';
  5004. for(const att of currPageAttData) {
  5005. const delHtml = deleteFilePermission && parseInt(userID) === att.uid
  5006. ? `<a class="ml-1 text-danger" href="javascript:void(0)" name="att-delete" file-id="${att.id}"><i class="fa fa-close" title="删除"></i></a>`
  5007. : '';
  5008. html += `<tr>
  5009. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  5010. <td>
  5011. <div class="d-flex">
  5012. <a href="javascript:void(0)" class="pl-0 col-10 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  5013. <div class="att-file-btn col-2">
  5014. <a href="/tender/${tender.id}/ledger/download/file/${att.id}" class="pl-0"><i class="fa fa-download"></i></a>
  5015. ${delHtml}
  5016. </div>
  5017. </div>
  5018. </td><td>${att.username}</td></tr>`
  5019. }
  5020. $('#alllist-table').html(html);
  5021. $('#alllist-table').on('click', 'tr', function() {
  5022. $('#alllist-table tr').removeClass('bg-light')
  5023. $(this).addClass('bg-light')
  5024. })
  5025. }
  5026. // 检查上报情况
  5027. function checkAuditorFrom () {
  5028. if ($('#auditors li').length === 0) {
  5029. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  5030. toastr.error('请联系管理员添加审批人');
  5031. } else {
  5032. toastr.error('请先选择审批人,再上报数据');
  5033. }
  5034. return false;
  5035. } else {
  5036. $('#hide-all').show();
  5037. return true;
  5038. }
  5039. }
  5040. // texterea换行
  5041. function auditCheck(i) {
  5042. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  5043. $('textarea[name="opinion"]').eq(i).val(opinion);
  5044. return true;
  5045. }