change_revise.js 247 KB

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