ledger.js 238 KB

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