change_revise.js 246 KB

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