change_revise.js 245 KB

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