ledger.js 218 KB

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