change_revise.js 246 KB

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