stage.js 245 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. function getExprInfo (field) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. /**
  26. * 从cookie中读取缓存的列显示设置,没有则取默认
  27. * @returns {*[]}
  28. */
  29. function customColDisplay () {
  30. const defaultSetting = [
  31. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  32. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl', 'qc_minus_qty'], visible: true },
  33. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  34. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  35. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  36. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent', 'end_final_1_precent'], visible: true },
  37. { title: '本期批注', fields: ['postil'], visible: true },
  38. { title: '图册号', fields: ['drawing_code'], visible: true },
  39. { title: '备注', fields: ['memo'], visible: true },
  40. { title: '总额计量', fields: ['is_tp'], visible: true},
  41. ];
  42. if (!checkTzMeasureType()) {
  43. defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
  44. }
  45. const settingStr = Cookies.get(ckColSetting);
  46. if (settingStr) {
  47. const customSetting = JSON.parse(settingStr);
  48. for (const ds of defaultSetting) {
  49. const cs = customSetting.find(x => {return x.title === ds.title});
  50. if (cs) ds.visible = cs.visible;
  51. }
  52. }
  53. return defaultSetting;
  54. }
  55. /**
  56. * 根据列显示设置,调整setting中的列是否显示
  57. * @param setting
  58. * @param customDisplay
  59. */
  60. function customizeStageTreeSetting(setting, customDisplay) {
  61. for (const cd of customDisplay) {
  62. for (const c of setting.cols) {
  63. if (cd.fields.indexOf(c.field) !== -1) {
  64. c.visible = c.defaultVisible === undefined ? cd.visible : c.defaultVisible && cd.visible;
  65. }
  66. }
  67. }
  68. }
  69. /**
  70. * 初始化 树结构 列事件
  71. * @param setting
  72. */
  73. function initTreeColSettingEvents(setting) {
  74. const Events = {
  75. readOnly: {
  76. measureData: function (node) {
  77. return node.children && node.children.length > 0;
  78. },
  79. },
  80. };
  81. const getEvent = function (eventName) {
  82. const names = eventName.split('.');
  83. let event = Events;
  84. for (let name of names) {
  85. if (event[name]) {
  86. event = event[name];
  87. } else {
  88. return null;
  89. }
  90. }
  91. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  92. return null;
  93. } else {
  94. return event;
  95. }
  96. };
  97. for (const col of setting.cols) {
  98. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  99. col.readOnly = getEvent(col.readOnly);
  100. }
  101. }
  102. }
  103. // 生成所有附件列表
  104. function getAllList(currPageNum = 1) {
  105. // 每页最多几个附件
  106. const pageCount = 20;
  107. // 附件总数
  108. const total = attData.length;
  109. // 总页数
  110. const pageNum = Math.ceil(total/pageCount);
  111. $('#totalPage').text(pageNum);
  112. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  113. // 当前页附件内容
  114. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  115. currPageFileData = currPageAttData;
  116. let html = '';
  117. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  118. for(const att of currPageAttData) {
  119. html += `<tr>
  120. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  121. <td>
  122. <div class="d-flex">
  123. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  124. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  125. </div>
  126. </td><td>${att.username}</td></tr>`
  127. }
  128. $('#alllist-table').html(html);
  129. $('#alllist-table').on('click', 'tr', function() {
  130. $('#alllist-table tr').removeClass('bg-light')
  131. $(this).addClass('bg-light')
  132. })
  133. }
  134. // 生成当前节点列表
  135. function getNodeList(node) {
  136. let html = '';
  137. for(const att of attData) {
  138. if (node === att.lid) {
  139. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  140. html += `<tr>
  141. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  142. <td>
  143. <div class="d-flex">
  144. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  145. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  146. </div>
  147. </td><td>${att.username}</td></tr>`
  148. }
  149. }
  150. $('#nodelist-table').html(html);
  151. $('#nodelist-table').on('click', 'tr', function() {
  152. $('#nodelist-table tr').removeClass('bg-light');
  153. $(this).addClass('bg-light');
  154. })
  155. }
  156. function getGxbyText(data) {
  157. const def = thirdParty.gxby.find(function (x) {
  158. return x.value === data.gxby_status;
  159. });
  160. return def ? def.name : '';
  161. }
  162. function getDaglText(data) {
  163. const def = thirdParty.dagl.find(function (x) {
  164. return x.value === data.dagl_status;
  165. });
  166. return def ? def.name : '';
  167. }
  168. function getHintMsg () {
  169. return {
  170. invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
  171. disableChange: {type: 'error', msg: '不可修改此数据'},
  172. }
  173. }
  174. let ledgerData, posData = '';
  175. $(document).ready(() => {
  176. const exportExcelSetting = {
  177. cols: [
  178. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  179. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  180. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  181. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  182. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  183. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  184. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  185. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  186. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  187. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  188. {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  189. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  190. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  191. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  192. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  193. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  194. {title: '截止本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  195. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  196. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  197. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  198. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_final_1_percent', hAlign: 2, width: 80, type: 'Number'},
  199. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  200. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  201. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  202. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  203. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  204. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  205. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  206. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  207. ],
  208. headRows: 2,
  209. headRowHeight: [25, 25],
  210. defaultRowHeight: 21,
  211. headerFont: 'bold 10px 微软雅黑',
  212. font: '10px 微软雅黑'
  213. };
  214. let detail, searchLedger, checkedChanges;
  215. const checkOption = {
  216. sibling: { enable: 0 },
  217. empty_code: { enable: 0 },
  218. calc: {
  219. enable: 1,
  220. fields: ['contract_qty', 'qc_qty', 'qc_minus_qty'],
  221. },
  222. zero: { enable: 0 },
  223. tp: {
  224. enable: 1,
  225. fields: [
  226. {qty: 'contract_qty', tp: 'contract_tp'},
  227. {qty: 'qc_qty', tp: 'qc_tp'},
  228. ],
  229. filter: function (node) {
  230. return node.is_tp;
  231. }
  232. },
  233. over: { enable: 1, isTz: checkTzMeasureType(), },
  234. limit3f: { enable: 1, checkType: [], status: thirdParty, },
  235. minus_cb: { enable: hintMinusCb },
  236. };
  237. if (tender.s2b_gxby_check) checkOption.limit3f.checkType.push('gxby');
  238. if (tender.s2b_dagl_check) checkOption.limit3f.checkType.push('dagl');
  239. // 界面布局
  240. autoFlashHeight();
  241. // 初始化 台账树结构 数据结构
  242. removeLocalCache('bills-fold');
  243. const stageTreeSetting = {
  244. id: 'ledger_id',
  245. pid: 'ledger_pid',
  246. order: 'order',
  247. level: 'level',
  248. rootId: -1,
  249. keys: ['id', 'tender_id', 'ledger_id'],
  250. stageId: 'id',
  251. autoExpand: 3,
  252. // markFoldKey: 'bills-fold',
  253. // markFoldSubKey: window.location.pathname.split('/')[2],
  254. markExpandKey: 'stage-bills-expand',
  255. markExpandSubKey: window.location.pathname.split('/')[2],
  256. };
  257. // 台账树结构计算相关设置
  258. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty', 'postil', 'used', 'contract_expr'];
  259. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp',
  260. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp', 'final_1_tp', 'end_final_1_tp'];
  261. stageTreeSetting.calcFun = function (node) {
  262. if (!node.children || node.children.length === 0) {
  263. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  264. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  265. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  266. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  267. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  268. node.end_qc_minus_qty = ZhCalc.add(node.pre_qc_minus_qty, node.qc_minus_qty);
  269. node.final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.quantity);
  270. node.final_1_tp = ZhCalc.mul(node.final_1_qty, node.unit_price, tenderInfo.decimal.tp);
  271. node.deal_final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.deal_qty);
  272. node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty);
  273. }
  274. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  275. node.gather_tp = ZhCalc.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
  276. node.end_contract_tp = ZhCalc.sum([node.pre_contract_tp, node.contract_tp, node.contract_pc_tp]);
  277. node.end_qc_tp = ZhCalc.sum([node.pre_qc_tp, node.qc_tp, node.qc_pc_tp]);
  278. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  279. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  280. node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
  281. if (!node.children || node.children.length === 0) {
  282. if (node.end_contract_qty) {
  283. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  284. } else {
  285. node.end_correct_tp = node.end_gather_tp;
  286. }
  287. }
  288. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  289. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  290. node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
  291. node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2);
  292. node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2);
  293. };
  294. const stageTree = createNewPathTree('stage', stageTreeSetting);
  295. // 初始化 计量单元 数据结构
  296. const stagePosSetting = {
  297. id: 'id', ledgerId: 'lid',
  298. updateFields: ['contract_qty', 'qc_qty', 'qc_minus_qty', 'postil', 'contract_expr'],
  299. };
  300. stagePosSetting.calcFun = function (pos) {
  301. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  302. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  303. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  304. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  305. pos.end_qc_minus_qty = ZhCalc.add(pos.pre_qc_minus_qty, pos.qc_minus_qty);
  306. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  307. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  308. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  309. pos.estimate_qty = !checkZero(pos.real_qty)
  310. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  311. : null;
  312. pos.final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.quantity);
  313. pos.deal_final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.deal_qty);
  314. pos.end_final_1_qty = ZhCalc.add(pos.end_qc_qty, pos.final_1_qty);
  315. };
  316. const stagePos = new StagePosData(stagePosSetting);
  317. const setCooperationSelectHtml = function () {
  318. const selectHtml = [];
  319. selectHtml.push('<option>全部</option>');
  320. const cooName = _.uniqWith(_.map(stageTree.pwd, 'company'));
  321. for (const i of cooName) {
  322. selectHtml.push('<option>', i, '</option>');
  323. }
  324. $('#cooperationSelect').html(selectHtml.join(''));
  325. };
  326. function checkUsed(tree, pos, node) {
  327. if (node.children && node.children.length > 0) {
  328. const posterity = tree.getPosterity(node);
  329. for (const p of posterity) {
  330. if (p.children && p.children.length > 0) continue;
  331. if (!checkZero(p.contract_qty) || !checkZero(p.contract_tp) ||
  332. !checkZero(p.qc_qty) || !checkZero(p.qc_tp) || !checkZero(p.qc_minus_qty))
  333. return true;
  334. const pPos = pos.getLedgerPos(p.id);
  335. if (!pPos || pPos.length === 0) continue;
  336. for (const pp of pPos) {
  337. if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
  338. }
  339. }
  340. return false;
  341. } else {
  342. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp) ||
  343. !checkZero(node.qc_qty) || !checkZero(node.qc_tp) || !checkZero(node.qc_minus_qty))
  344. return true;
  345. const pPos = pos.getLedgerPos(node.id);
  346. if (!pPos || pPos.length === 0) return false;
  347. for (const pp of pPos) {
  348. if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
  349. }
  350. }
  351. }
  352. const reloadCooperationHtml = function () {
  353. const html = [];
  354. const select = $('#cooperationSelect').val();
  355. const list = select !== '全部' ? _.filter(stageTree.pwd, { company: select }) : stageTree.pwd;
  356. for (const p of list) {
  357. if (!p.node) continue;
  358. if (p.confirm) {
  359. html.push(`<tr class="text-success">`);
  360. } else {
  361. html.push(`<tr>`);
  362. }
  363. html.push(`<td>${p.node.code}</td>`, `<td>${p.node.name}</td>`);
  364. if(coopwd) {
  365. html.push('<td>', p.check ? `已解锁:${p.pwd}` : `<a name="ledger-unlock" lid="${p.ledger_id}" href="javascript: void(0);">解锁</a>`, '</td>');
  366. }
  367. html.push('<td>', p.company, '</td>');
  368. if (stage.status === auditConst.status.checking && !checkUsed(stageTree, stagePos, p.node)) {
  369. html.push('<td>', '本期未计量', '</td>');
  370. } else if (p.check && p.confirm) {
  371. html.push('<td>', moment(p.confirm_time).format('YYYY-MM-DD HH:mm') + ' ' + (coopwd ? `<a name="ledger-unconfirm" href="javascript: void(0);" lid="${p.ledger_id}">重新审批</a>` : ''), '</td>');
  372. } else if (!p.check && p.confirm) {
  373. html.push('<td>', moment(p.confirm_time).format('YYYY-MM-DD HH:mm'), '</td>');
  374. } else if (p.check && !p.confirm && coopwd) {
  375. html.push('<td>', `<a name="ledger-confirm" href="javascript: void(0);" lid="${p.ledger_id}" class="btn btn-sm btn-success">确认</a>`, '</td>');
  376. } else {
  377. html.push('<td>', '</td>');
  378. }
  379. html.push('</tr>');
  380. }
  381. $('#cooperationList').html(html.join(''));
  382. };
  383. class Changes {
  384. constructor(obj) {
  385. const self = this;
  386. this.obj = obj;
  387. // 初始化 清单编号窗口 参数
  388. this.spreadSetting = {
  389. cols: [
  390. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  391. if (data.uamount && !checkZero(data.uamount)) {
  392. return $('#icon-ok')[0];
  393. } else {
  394. return null;
  395. }
  396. }},
  397. {title: '变更令号', field: 'p_code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  398. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  399. {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
  400. //{title: '总数量', field: 'b_amount', width: 60, readOnly: true, hAlign: 2, },
  401. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, type: 'Number', getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  402. {title: '本期计量', field: 'uamount', width: 60, hAlign: 2, type: 'Number', },
  403. ],
  404. emptyRows: 0,
  405. headRows: 1,
  406. headRowHeight: [32],
  407. headerFont: '12px 微软雅黑',
  408. font: '12px 微软雅黑',
  409. getColor: function (sheet, data, row, col, defaultColor) {
  410. if (col.field === 'uamount') {
  411. if (data.bamount > 0) {
  412. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  413. return usedAmount < 0 || usedAmount > data.bamount ? spreadColor.stage.over : defaultColor;
  414. } else if (data.bamount < 0) {
  415. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  416. return usedAmount > 0 || usedAmount < data.bamount ? spreadColor.stage.over : defaultColor;
  417. } else {
  418. return data.uamount ? spreadColor.stage.over : defaultColor;
  419. }
  420. } else {
  421. return defaultColor;
  422. }
  423. }
  424. };
  425. this.curChangeId = '';
  426. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  427. this.firstView = true;
  428. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  429. // 初次显示,需刷新spread界面,保证界面绘制正确
  430. this.obj.bind('shown.bs.modal', function () {
  431. if (self.firstView) {
  432. self.firstView = false;
  433. self.spread.refresh();
  434. }
  435. });
  436. // 切换变更令,加载右侧明细数据
  437. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  438. const change = SpreadJsObj.getSelectObject(info.sheet);
  439. if(change) self._loadChangeDetail(change);
  440. });
  441. // 填写本期计量
  442. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  443. if (info.sheet.zh_setting) {
  444. const col = info.sheet.zh_setting.cols[info.col];
  445. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  446. const node = sortData[info.row];
  447. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  448. // 刷新界面
  449. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  450. }
  451. });
  452. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  453. if (info.sheet.zh_setting) {
  454. const sortData = SpreadJsObj.getSortData(info.sheet);
  455. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  456. const curRow = iRow + info.cellRange.row;
  457. const curCol = info.cellRange.col;
  458. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  459. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  460. }
  461. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  462. }
  463. });
  464. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  465. if (sheet.zh_setting) {
  466. const sel = sheet.getSelections()[0];
  467. const sortData = SpreadJsObj.getSortData(sheet);
  468. // 仅本期计量可删除
  469. if (sel.col === 5 && sel.colCount === 1) {
  470. const col = sheet.zh_setting.cols[sel.col];
  471. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  472. const data = sortData[iRow];
  473. data[col.field] = null;
  474. }
  475. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  476. }
  477. }
  478. });
  479. // 过滤可变更数量为0
  480. $('#filterEmpty').click(function () {
  481. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  482. });
  483. // 匹配编号
  484. $('#matchPos').click(function () {
  485. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  486. });
  487. // 展开收起 变更令详细信息
  488. $('#show-bgl-detail').bind('click', function () {
  489. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  490. if (detail.hasClass('col-4')) {
  491. detail.attr('class', 'col').hide();
  492. bgl.attr('class', 'col-12');
  493. $('a', obj).attr('title', '展开侧栏');
  494. $('i', obj).attr('class', 'fa fa-chevron-left');
  495. self.spread.refresh();
  496. } else {
  497. detail.attr('class', 'col-4').show();
  498. bgl.attr('class', 'col-8');
  499. $('a', obj).attr('title', '收起侧栏');
  500. $('i', obj).attr('class', 'fa fa-chevron-right');
  501. self.spread.refresh();
  502. }
  503. });
  504. // 添加调用变更令
  505. $('#usg-bg-ok').click(function () {
  506. const data = { target: self.callData, change: [] };
  507. for (const c of self.displayChanges) {
  508. if (c.uamount) {
  509. if (c.bamount > 0) {
  510. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  511. if (usedAmount < 0 || usedAmount > c.bamount) {
  512. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  513. return;
  514. }
  515. } else if (c.bamount < 0) {
  516. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  517. if (usedAmount > 0 || usedAmount < c.bamount) {
  518. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  519. return;
  520. }
  521. } else {
  522. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  523. return;
  524. }
  525. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount, minus: c.bamount < 0 });
  526. }
  527. }
  528. // 提交数据到后端
  529. postData(window.location.pathname + '/use-change', data, function(result) {
  530. if (result.pos) {
  531. stagePos.loadCurStageData(result.pos.curStageData);
  532. }
  533. const nodes = stageTree.loadPostStageData(result.bills);
  534. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  535. stagePosSpreadObj.loadCurPosData();
  536. if (detail) {
  537. detail.loadStageChangeUpdateData(result, nodes);
  538. } else {
  539. stageIm.loadUpdateChangeData(result, nodes)
  540. }
  541. self.obj.modal('hide');
  542. });
  543. })
  544. }
  545. _calculateAmount() {
  546. for (const c of this.changes) {
  547. c.bamount = _.toNumber(c.b_amount);
  548. c.vamount = ZhCalc.sub(ZhCalc.sub(c.bamount, c.used_amount), c.stage_used_amount);
  549. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid, no_value: this.callData.noValue});
  550. if (uc) {
  551. c.org_uamount = uc.qty;
  552. c.uamount = uc.qty;
  553. c.vamount = ZhCalc.add(c.vamount, uc.qty);
  554. }
  555. c.pre_amount = ZhCalc.sub(ZhCalc.add(c.used_amount, c.stage_used_amount), c.uamount);
  556. }
  557. }
  558. _loadChangeDetail(change) {
  559. if (change) {
  560. if (change.cid === this.curChangeId) { return; }
  561. this.curChangeId = change.cid;
  562. const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
  563. for (const i of inputs) {
  564. const field = $(i).attr('name');
  565. const text = (field && change[field]) ? change[field] : '';
  566. $(i).val(text);
  567. }
  568. const textareas = $('textarea', this.obj);
  569. for (const ta of textareas) {
  570. const field = $(ta).attr('name');
  571. const text = (field && change[field]) ? change[field].replace(/<br><br>/g, '\r\n') : '';
  572. ta.textContent = text;
  573. }
  574. const html = [];
  575. for (const a of change.attachments) {
  576. html.push('<tr>');
  577. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  578. html.push('<td>', a.u_name, '</td>');
  579. html.push('</tr>');
  580. }
  581. // 变更类型
  582. if (change.type) {
  583. const cType = change.type.split(',');
  584. $('input[name="type"]').prop("checked", false);
  585. for (const c of cType) {
  586. $('input[name="type"][value='+ c +']').prop("checked", true);
  587. }
  588. }
  589. // 变更类别
  590. $('select[name=class]').val(change.class);
  591. // 变更性质
  592. $('select[name=quality]').val(change.quality);
  593. // 变更单位
  594. $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
  595. // 费用承担方
  596. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  597. // 附件
  598. $('#attachment').html(html.join(''));
  599. } else {
  600. const inputs = $('input', this.obj);
  601. for (const i of inputs) {
  602. $(i).val('');
  603. }
  604. const textareas = $('textarea', this.obj);
  605. for (const ta of textareas) {
  606. ta.innerText = '';
  607. }
  608. $('#attachment').html('');
  609. }
  610. }
  611. _viewChanges() {
  612. const sheet = this.spread.getActiveSheet();
  613. if (this.changes) {
  614. sheet.setSelection(0, 0, 1, 1);
  615. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  616. this._loadChangeDetail(this.displayChanges[0]);
  617. } else {
  618. toastr.error('查询变更令有误,请刷新页面后重试');
  619. }
  620. }
  621. _filterChange(filterEmpty, matchPosName) {
  622. this.displayChanges = [];
  623. for (const c of this.changes) {
  624. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  625. const matchVisible = matchPosName && this.callData.pos
  626. ? (c.gcl_id === this.callData.bills.id && c.b_bwmx === this.callData.pos.name)
  627. : true;
  628. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  629. this.displayChanges.push(c);
  630. }
  631. }
  632. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  633. this._loadChangeDetail(this.displayChanges[0]);
  634. }
  635. loadChanges(data) {
  636. this.callData = data;
  637. if (this.callData.pos) {
  638. $('#matchPos').parent().show();
  639. } else {
  640. $('#matchPos').parent().hide();
  641. }
  642. const self = this;
  643. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  644. postData(window.location.pathname + '/valid-change', data, function (result) {
  645. self.changes = result.changes;
  646. self.useChanges = result.useChanges;
  647. self._calculateAmount();
  648. self._viewChanges();
  649. self.obj.modal('show');
  650. });
  651. }
  652. }
  653. const changesObj = new Changes($('#use-bg'));
  654. // 初始化 台账 spread
  655. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  656. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  657. // 数量变更列,添加按钮
  658. const qcColShowImage = function (data) {
  659. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  660. return false;
  661. } else {
  662. const nodePos = stagePos.getLedgerPos(data.id);
  663. return !(nodePos && nodePos.length > 0);
  664. }
  665. };
  666. sjsSettingObj.setQcCols(ledgerSpreadSetting.cols, [
  667. {field: 'qc_qty', showImage: qcColShowImage},
  668. {field: 'qc_minus_qty', showImage: qcColShowImage},
  669. ]);
  670. sjsSettingObj.setOrgPriceCol(ledgerSpreadSetting.cols, [ {field: 'org_price'} ]);
  671. // const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_percent' || x.field === 'end_correct_percent'});
  672. // if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_percent' : 'end_gather_percent';
  673. const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'});
  674. if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
  675. ledgerSpreadSetting.imageClick = function (data, hitinfo) {
  676. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  677. switch (col.field) {
  678. case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
  679. case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
  680. case 'qc_qty':
  681. case 'qc_minus_qty':
  682. if (data.children && data.children.length > 0 || data.lock || data.is_import) return;
  683. const nodePos = stagePos.getLedgerPos(data.id);
  684. if (nodePos && nodePos.length > 0) return;
  685. const minus = col.field === 'qc_minus_qty' ? 1 : 0;
  686. changesObj.loadChanges({bills: data, minus, noValue: minus});
  687. break;
  688. default: return;
  689. }
  690. };
  691. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  692. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  693. if (data) {
  694. if (col.field === 'gxby') {
  695. const def = thirdParty.gxby.find(function (x) {
  696. return x.value === data.gxby_status;
  697. });
  698. if (def && def.color) return def.color;
  699. } else if (col.field === 'dagl') {
  700. const def = thirdParty.dagl.find(function (x) {
  701. return x.value === data.dagl_status;
  702. });
  703. if (def && def.color) return def.color;
  704. }
  705. return hintOver && checkUtils.billsOver(data, checkTzMeasureType(), stagePos) ? spreadColor.stage.over : defaultColor;
  706. } else {
  707. return defaultColor;
  708. }
  709. };
  710. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  711. sjsSettingObj.set3FCols(ledgerSpreadSetting.cols, [
  712. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  713. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  714. ]);
  715. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  716. ledgerSpreadSetting.headColWidth = [50];
  717. ledgerSpreadSetting.rowHeader = [
  718. {
  719. rowHeaderType: 'tag',
  720. setting: {
  721. indent: 14,
  722. tagSize: 0.8,
  723. tagFont: '8px 微软雅黑',
  724. getColor: function (index, data) {
  725. if (!data) return;
  726. return billsTag.getBillsTagsColor(data.id);
  727. },
  728. getTagHtml: function (index, data) {
  729. if (!data) return;
  730. const getHtml = function (list) {
  731. if (!list || list.length === 0) return '';
  732. const html = [];
  733. for (const l of list) {
  734. html.push('<div class="row mr-1">');
  735. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  736. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  737. html.push('</div>');
  738. }
  739. return html.join('');
  740. };
  741. return getHtml(billsTag.getBillsTagsInfo(data.id));
  742. }
  743. },
  744. },
  745. ];
  746. ledgerSpreadSetting.readOnly = function (data) {
  747. if (!data) return false;
  748. return data.lock || false;
  749. };
  750. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  751. //初始化所有附件列表
  752. getAllList();
  753. // 初始化 计量单元 Spread
  754. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  755. const posQcColShowImage = function (data) {
  756. return data !== undefined && data !== null;
  757. };
  758. sjsSettingObj.setQcCols(posSpreadSetting.cols, [
  759. { field: 'qc_qty', showImage: posQcColShowImage },
  760. { field: 'qc_minus_qty', showImage: posQcColShowImage }
  761. ]);
  762. posSpreadSetting.imageClick = function (data, hitinfo) {
  763. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  764. switch (col.field) {
  765. case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
  766. case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
  767. case 'qc_qty':
  768. case 'qc_minus_qty':
  769. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  770. if (node.lock) return;
  771. const minus = col.field === 'qc_minus_qty' ? 1 : 0;
  772. changesObj.loadChanges({bills: node, pos: data, minus, noValue: minus});
  773. break;
  774. default: return;
  775. }
  776. };
  777. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  778. if (data) {
  779. if (col.field === 'gxby') {
  780. const def = thirdParty.gxby.find(function (x) {
  781. return x.value === data.gxby_status;
  782. });
  783. if (def && def.color) return def.color;
  784. } else if (col.field === 'dagl') {
  785. const def = thirdParty.dagl.find(function (x) {
  786. return x.value === data.dagl_status;
  787. });
  788. if (def && def.color) return def.color;
  789. }
  790. }
  791. if (checkTzMeasureType()) {
  792. return hintOver && checkUtils.posOver(data) ? spreadColor.stage.over : defaultColor;
  793. }
  794. };
  795. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  796. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  797. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  798. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  799. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  800. ]);
  801. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  802. const billsTag = $.billsTag({
  803. selector: '#bills-tag',
  804. relaSpread: slSpread,
  805. updateUrl: window.location.pathname + '/tag',
  806. afterModify: function (nodes) {
  807. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  808. },
  809. afterLocated: function () {
  810. stagePosSpreadObj.loadCurPosData();
  811. },
  812. afterShow: function () {
  813. slSpread.refresh();
  814. if (spSpread) spSpread.refresh();
  815. },
  816. });
  817. const errorList = $.cs_errorList({
  818. tabSelector: '#error-list-tab',
  819. selector: '#error-list',
  820. relaSpread: slSpread,
  821. storeKey: 'stage-error-' + stage.id,
  822. afterLocated: function () {
  823. stagePosSpreadObj.loadCurPosData();
  824. },
  825. afterShow: function () {
  826. slSpread.refresh();
  827. if (spSpread) spSpread.refresh();
  828. },
  829. });
  830. const checkList = $.ledger_checkList({
  831. id: 'check-list',
  832. tabSelector: '#check-list-tab',
  833. selector: '#check-list',
  834. relaSpread: slSpread,
  835. storeKey: 'stage-check-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
  836. checkType: getCheckType(checkOption),
  837. afterLocated: function () {
  838. stagePosSpreadObj.loadCurPosData();
  839. },
  840. afterShow: function () {
  841. slSpread.refresh();
  842. if (spSpread) spSpread.refresh();
  843. },
  844. });
  845. const sumLoadMiss = $.sumLoadMiss({
  846. tabSelector: '#sum-load-miss-tab',
  847. selector: '#sum-load-miss',
  848. relaSpread: slSpread,
  849. storeKey: 'stage-slm-' + stage.id,
  850. id: 'stage-slm',
  851. type: 'stage',
  852. afterLocated: function () {
  853. stagePosSpreadObj.loadCurPosData();
  854. },
  855. afterShow: function () {
  856. slSpread.refresh();
  857. if (spSpread) spSpread.refresh();
  858. },
  859. });
  860. const stageTreeSpreadObj = {
  861. cut: function (sheet, sel, callback) {
  862. callback(true);
  863. },
  864. loadExprToInput(sheet) {
  865. const sel = sheet.getSelections()[0];
  866. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  867. if (col.type === 'Number') {
  868. const data = SpreadJsObj.getSelectObject(sheet);
  869. if (!data) {
  870. $('#bills-expr').val('').attr('readOnly', true);
  871. $('#bills-expr').removeAttr('data-row');
  872. return;
  873. }
  874. const nodePos = stagePos.getLedgerPos(data.id);
  875. if (nodePos && nodePos.length > 0) {
  876. $('#bills-expr').val('').attr('readOnly', true);
  877. } else {
  878. const exprInfo = getExprInfo(col.field);
  879. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  880. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  881. if (col.field.indexOf('tp') >= 0) {
  882. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
  883. } else {
  884. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
  885. }
  886. }
  887. $('#bills-expr').attr('data-row', sel.row);
  888. } else {
  889. $('#bills-expr').val('').attr('readOnly', true);
  890. $('#bills-expr').removeAttr('data-row');
  891. }
  892. },
  893. refreshTreeNodes: function (sheet, nodes) {
  894. const tree = sheet.zh_tree;
  895. if (!tree) { return }
  896. const rows = [];
  897. for (const node of nodes) {
  898. rows.push(tree.nodes.indexOf(node));
  899. }
  900. SpreadJsObj.reLoadRowsData(sheet, rows);
  901. },
  902. editEnded: function (e, info) {
  903. if (info.sheet.zh_setting) {
  904. const col = info.sheet.zh_setting.cols[info.col];
  905. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  906. const node = sortData[info.row], updateData = {};
  907. const orgValue = node[col.field];
  908. let newValue = trimInvalidChar(info.editingText);
  909. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  910. return;
  911. }
  912. if (col.type === 'Number' && newValue && newValue !== '') {
  913. const num = _.toNumber(newValue);
  914. if (_.isFinite(num)) {
  915. newValue = num;
  916. } else {
  917. try {
  918. newValue = math.evaluate(transExpr(newValue));
  919. } catch(err) {
  920. toastr.error('输入的表达式非法');
  921. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  922. return;
  923. }
  924. }
  925. }
  926. if (col.field.indexOf('_dgn_') > 0) {
  927. if (node.b_code && node.b_code !== '') {
  928. toastr.error('仅项目节可输入项目节数量');
  929. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  930. return;
  931. }
  932. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  933. if (node.children && node.children.length > 0) {
  934. toastr.error('清单父项不可计量');
  935. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  936. return;
  937. } else {
  938. const nodePos = stagePos.getLedgerPos(node.id);
  939. if (nodePos && nodePos.length > 0) {
  940. toastr.error('该清单有计量单元,请在计量单元处计量');
  941. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  942. return;
  943. }
  944. }
  945. }
  946. if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  947. updateData.main = {
  948. id: node.id
  949. };
  950. updateData.main[col.field] = newValue;
  951. } else if (col.field.indexOf('_dgn_') > 0) {
  952. updateData.dgn = {
  953. id: node.id
  954. };
  955. updateData.dgn[col.field] = newValue;
  956. } else if (col.field !== 'is_tp') {
  957. updateData.stage = {
  958. lid: node.id
  959. };
  960. updateData.stage[col.field] = newValue;
  961. const exprInfo = getExprInfo(col.field);
  962. if (exprInfo) {
  963. updateData.stage[exprInfo.expr] = info.editingText !== newValue+ '' ? trimInvalidChar(info.editingText) : '';
  964. }
  965. }
  966. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  967. // tag update
  968. const nodes = stageTree.loadPostStageData(data);
  969. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  970. if (detail) {
  971. detail.loadStageLedgerUpdateData(data, nodes);
  972. } else {
  973. stageIm.loadUpdateLedgerData(data, nodes);
  974. }
  975. }, function () {
  976. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  977. });
  978. }
  979. },
  980. loadRelaData: function () {
  981. const billsSheet = slSpread.getActiveSheet();
  982. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  983. const posSheet = spSpread.getActiveSheet();
  984. SpreadJsObj.resetTopAndSelect(posSheet);
  985. stagePosSpreadObj.loadCurPosData();
  986. if (posSearch) posSearch.search();
  987. },
  988. selectionChanged: function (e, info) {
  989. console.log(SpreadJsObj.getSelectObject(info.sheet));
  990. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  991. stageTreeSpreadObj.loadRelaData();
  992. // 全选去除
  993. $('#dqjiedian').find('.check-all-file').prop('checked', false);
  994. }
  995. stageTreeSpreadObj.loadExprToInput(info.sheet);
  996. },
  997. deletePress(sheet) {
  998. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  999. const tree = sheet.zh_tree;
  1000. if (!tree) { return; }
  1001. const sel = sheet.getSelections()[0];
  1002. const validCols = [];
  1003. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1004. const colSetting = sheet.zh_setting.cols[iCol];
  1005. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  1006. validCols.push(iCol);
  1007. }
  1008. }
  1009. if (validCols.length === 0) { return; }
  1010. const sortData = sheet.zh_tree.nodes;
  1011. const datas = [], dgnDatas = [], mainDatas = [];
  1012. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1013. const node = sortData[iRow];
  1014. if (node && !node.lock) {
  1015. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  1016. let filter = true, filterDgn = true, filterMain = true;
  1017. for (const iCol of validCols) {
  1018. const colSetting = sheet.zh_setting.cols[iCol];
  1019. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  1020. if (node.b_code && node.b_code !== '') continue;
  1021. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) < 0) {
  1022. if (colSetting.field === 'contract_qty') {
  1023. if (node.is_tp) continue;
  1024. } else if (colSetting.field === 'contract_tp') {
  1025. if (!node.is_tp) continue;
  1026. }
  1027. if (node.children && node.children.length > 0) {
  1028. continue;
  1029. }
  1030. const nodePos = stagePos.getLedgerPos(node.id);
  1031. if (nodePos && nodePos.length > 0) {
  1032. continue;
  1033. }
  1034. }
  1035. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  1036. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  1037. dgnData[colSetting.field] = 0;
  1038. filterDgn = false;
  1039. }
  1040. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) >= 0) {
  1041. mainData[colSetting.field] = null;
  1042. filterMain = false;
  1043. } else {
  1044. data[colSetting.field] = null;
  1045. const exprInfo = getExprInfo(colSetting.field);
  1046. if (exprInfo) {
  1047. data[exprInfo.expr] = '';
  1048. }
  1049. filter = false;
  1050. }
  1051. }
  1052. if (!filter) datas.push(data);
  1053. if (!filterDgn) dgnDatas.push(dgnData);
  1054. if (!filterMain) mainDatas.push(mainData);
  1055. }
  1056. }
  1057. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1058. const bills = {};
  1059. if (datas.length > 0) bills.stage = datas;
  1060. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  1061. if (mainDatas.length > 0) bills.main = mainDatas;
  1062. postData(window.location.href + '/update', {bills: bills}, function (result) {
  1063. const nodes = stageTree.loadPostStageData(result);
  1064. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1065. if (detail) {
  1066. detail.loadStageLedgerUpdateData(result, nodes);
  1067. } else {
  1068. stageIm.loadUpdateLedgerData(result, nodes);
  1069. }
  1070. stageTreeSpreadObj.loadExprToInput(sheet);
  1071. });
  1072. }
  1073. }
  1074. },
  1075. clipboardPasting(e, info) {
  1076. if (info.sheet.zh_setting) {
  1077. const setting = info.sheet.zh_setting;
  1078. const range = info.cellRange;
  1079. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_minus_qty', 'postil'].concat(['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'], setting.dgnUpFields);
  1080. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1081. const col = info.sheet.zh_setting.cols[iCol];
  1082. if ((validField.indexOf(col.field) === -1)) {
  1083. toastr.error('不可修改此数据');
  1084. info.cancel = true;
  1085. return;
  1086. }
  1087. }
  1088. }
  1089. },
  1090. clipboardPasted(e, info) {
  1091. const pasteHint = getHintMsg();
  1092. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  1093. const sheet = info.sheet, setting = info.sheet.zh_setting;
  1094. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  1095. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1096. const curRow = iRow + info.cellRange.row;
  1097. const node = sheet.zh_tree.getItemsByIndex(curRow);
  1098. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  1099. let filter = true, filterDgn = true, filterMain = true;
  1100. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1101. const curCol = info.cellRange.col + iCol;
  1102. const col = info.sheet.zh_setting.cols[curCol];
  1103. if (col.field === 'contract_tp') {
  1104. if (!node.is_tp) continue;
  1105. } else if (col.field === 'contract_qty') {
  1106. if (node.is_tp) continue;
  1107. }
  1108. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1109. if (node.b_code && node.b_code !== '') continue;
  1110. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  1111. if (node.children && node.children.length > 0) continue;
  1112. const nodePos = stagePos.getLedgerPos(node.id);
  1113. if (nodePos && nodePos.length > 0) continue;
  1114. }
  1115. const text = trimInvalidChar(sheet.getText(curRow, curCol));
  1116. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1117. const num = _.toNumber(text);
  1118. if (num) {
  1119. dgnData[col.field] = num;
  1120. filterDgn = false;
  1121. } else {
  1122. try {
  1123. dgnData[col.field] = math.evaluate(transExpr(text));
  1124. filterDgn = false;
  1125. } catch(err) {
  1126. toastMessageUniq(pasteHint.invalidExpr);
  1127. }
  1128. }
  1129. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1130. mainData[col.field] = text;
  1131. filterMain = false;
  1132. } else {
  1133. if (col.type === 'Number') {
  1134. const exprInfo = getExprInfo(col.field);
  1135. if (text) {
  1136. const num = _.toNumber(text);
  1137. data[col.field] = num;
  1138. if (exprInfo) data[exprInfo.expr] = '';
  1139. if (_.isFinite(num)) {
  1140. filter = false;
  1141. } else {
  1142. try {
  1143. data[col.field] = math.evaluate(transExpr(text));
  1144. if (exprInfo) data[exprInfo.expr] = text;
  1145. filter = false;
  1146. } catch(err) {
  1147. toastMessageUniq(pasteHint.invalidExpr);
  1148. }
  1149. }
  1150. } else {
  1151. data[col.field] = null;
  1152. if (exprInfo) data[exprInfo.expr] = '';
  1153. filter = false;
  1154. }
  1155. } else {
  1156. data[col.field] = text;
  1157. }
  1158. }
  1159. }
  1160. if (filter && filterDgn && filterMain) {
  1161. filterNodes.push(node);
  1162. } else {
  1163. if (!filter) datas.push(data);
  1164. if (!filterDgn) dgnDatas.push(dgnData);
  1165. if (!filterMain) mainDatas.push(mainData);
  1166. }
  1167. }
  1168. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1169. const updateData = {};
  1170. if (datas.length > 0) updateData.stage = datas;
  1171. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  1172. if (mainDatas.length > 0) updateData.main = mainDatas;
  1173. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  1174. const nodes = stageTree.loadPostStageData(data);
  1175. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  1176. if (detail) {
  1177. detail.loadStageLedgerUpdateData(data, nodes);
  1178. } else {
  1179. stageIm.loadUpdateLedgerData(data, nodes);
  1180. }
  1181. stageTreeSpreadObj.loadExprToInput(sheet);
  1182. }, function () {
  1183. // todo
  1184. //stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1185. });
  1186. } else {
  1187. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1188. }
  1189. }
  1190. },
  1191. measureAllPosInNode(node, ratio = 1) {
  1192. const posterity = stageTree.getPosterity(node);
  1193. const data = {updateType: 'update', updateData: []};
  1194. for (const p of posterity) {
  1195. if (p.children && p.children.length > 0) continue;
  1196. const posRange = stagePos.getLedgerPos(p.id);
  1197. if (posRange && posRange.length > 0) {
  1198. for (const pr of posRange) {
  1199. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  1200. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  1201. if (validValue <= 0) continue;
  1202. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  1203. const pData = {
  1204. pid: pr.id,
  1205. lid: pr.lid,
  1206. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  1207. };
  1208. data.updateData.push(pData);
  1209. }
  1210. }
  1211. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  1212. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  1213. break;
  1214. }
  1215. }
  1216. if (data.updateData.length === 0) {
  1217. toastr.info('其下全部计量单元均已计量');
  1218. return;
  1219. }
  1220. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1221. if (result.pos) {
  1222. stagePos.updateDatas(result.pos.pos);
  1223. stagePos.loadCurStageData(result.pos.curStageData);
  1224. }
  1225. const nodes = stageTree.loadPostStageData(result.ledger);
  1226. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1227. stagePosSpreadObj.loadCurPosData();
  1228. if (detail) {
  1229. detail.loadStagePosUpdateData(result, nodes);
  1230. } else {
  1231. stageIm.loadUpdatePosData(result, nodes);
  1232. }
  1233. toastr.success('已计量' + data.updateData.length + '条');
  1234. }, function () {
  1235. stagePosSpreadObj.loadCurPosData();
  1236. });
  1237. },
  1238. topRowChanged(e, info) {
  1239. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1240. },
  1241. editStarting(e, info) {
  1242. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1243. const col = info.sheet.zh_setting.cols[info.col];
  1244. const node = info.sheet.zh_tree.nodes[info.row];
  1245. const exprInfo = getExprInfo(col.field);
  1246. if (exprInfo) {
  1247. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1248. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1249. }
  1250. }
  1251. switch (col.field) {
  1252. case 'contract_qty':
  1253. case 'qc_qty':
  1254. case 'qc_minus_qty':
  1255. info.cancel = node.is_tp;
  1256. break;
  1257. case 'contract_tp':
  1258. info.cancel = !node.is_tp;
  1259. break;
  1260. case 'is_tp':
  1261. info.cancel = true;
  1262. break;
  1263. }
  1264. },
  1265. buttonClicked: function (e, info) {
  1266. if (info.sheet.zh_setting) {
  1267. const node = SpreadJsObj.getSelectObject(info.sheet);
  1268. const col = info.sheet.zh_setting.cols[info.col];
  1269. const posRange = stagePos.getLedgerPos(node.id);
  1270. if (node.pre_used === 1 ||
  1271. (node.children && node.children.length > 0) ||
  1272. (node.unit !== '总额' && node.unit !== '元') ||
  1273. (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  1274. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1275. return;
  1276. }
  1277. const postIsTp = function () {
  1278. const data = { calcType: {id: node.id} };
  1279. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  1280. // 更新至服务器
  1281. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  1282. const nodes = stageTree.loadPostStageData(result);
  1283. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1284. if (detail) {
  1285. detail.loadStageLedgerUpdateData(result, nodes);
  1286. } else {
  1287. stageIm.loadUpdateLedgerData(result, nodes);
  1288. }
  1289. });
  1290. };
  1291. if (col.field === 'is_tp') {
  1292. if (info.sheet.isEditing()) {
  1293. info.sheet.endEdit(true);
  1294. }
  1295. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp)) {
  1296. $.msgBox({
  1297. id: 'calc-type',
  1298. title: '提示',
  1299. message: '切换计量模式,已计量数据会被清空。',
  1300. ok: {
  1301. caption: '确定',
  1302. callback: postIsTp,
  1303. },
  1304. cancel: {
  1305. caption: '取消',
  1306. callback: function () {
  1307. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1308. }
  1309. }
  1310. });
  1311. } else {
  1312. postIsTp();
  1313. }
  1314. }
  1315. }
  1316. },
  1317. measureByBatch: function (posNames, ratio, apply2sibling) {
  1318. if (posNames.length <= 0) return;
  1319. if (ratio <= 0) return;
  1320. const fRatio = ZhCalc.div(ratio, 100);
  1321. const sheet = slSpread.getActiveSheet();
  1322. const node = SpreadJsObj.getSelectObject(sheet);
  1323. const parent = stageTree.getParent(node);
  1324. const nodes = apply2sibling === true ? (parent ? parent.children : stageTree.children) : [node];
  1325. const data = {updateType: 'batchUpdate', updateData: []};
  1326. for (const node of nodes) {
  1327. const posRange = stagePos.getLedgerPos(node.id);
  1328. if (!posRange || posRange <= 0) continue;
  1329. for (const p of posRange) {
  1330. if (posNames.indexOf(p.name) < 0) continue;
  1331. data.updateData.push({
  1332. pid: p.id, lid: p.lid,
  1333. contract_qty: ZhCalc.mul(p.quantity, fRatio),
  1334. contract_expr: `${p.quantity}*${ratio}%`,
  1335. });
  1336. }
  1337. }
  1338. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1339. if (result.pos) {
  1340. stagePos.updateDatas(result.pos.pos);
  1341. stagePos.loadCurStageData(result.pos.curStageData);
  1342. }
  1343. const nodes = stageTree.loadPostStageData(result.ledger);
  1344. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1345. stagePosSpreadObj.loadCurPosData();
  1346. if (detail) {
  1347. detail.loadStagePosUpdateData(result, nodes);
  1348. } else {
  1349. stageIm.loadUpdatePosData(result, nodes);
  1350. }
  1351. $('#calc-by-ratio').modal('hide');
  1352. }, function () {
  1353. stagePosSpreadObj.loadCurPosData();
  1354. $('#calc-by-ratio').modal('hide');
  1355. });
  1356. },
  1357. exportExcel: function (filename, nodes) {
  1358. const exportNodesData = function (data, nodes) {
  1359. for (const node of nodes) {
  1360. data.push({
  1361. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  1362. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  1363. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  1364. qc_qty: node.qc_qty, qc_tp: node.qc_tp,
  1365. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  1366. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  1367. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp,
  1368. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_final_1_percent: node.end_final_1_percent,
  1369. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  1370. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  1371. final_dgn_price: node.final_dgn_price,
  1372. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  1373. });
  1374. if (node.children && node.children.length > 0) {
  1375. exportNodesData(data, node.children);
  1376. } else {
  1377. const posRange = stagePos.getLedgerPos(node.id);
  1378. if (posRange && posRange.length > 0) {
  1379. for (const [i, p] of posRange.entries()) {
  1380. data.push({
  1381. pos_code: (i + 1) + '', name: p.name,
  1382. quantity: p.quantity,
  1383. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  1384. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  1385. drawing_code: p.drawing_code, memo: p.memo, postil: p.postil,
  1386. });
  1387. }
  1388. }
  1389. }
  1390. }
  1391. };
  1392. const data = [];
  1393. exportNodesData(data, nodes ? nodes : stageTree.children);
  1394. SpreadExcelObj.exportSimpleXlsxSheet(exportExcelSetting, data, filename);
  1395. }
  1396. };
  1397. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1398. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1399. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1400. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1401. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1402. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1403. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1404. SpreadJsObj.addCutEvents(slSpread, stageTreeSpreadObj.cut);
  1405. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1406. if (!readOnly) {
  1407. $('#bills-expr').bind('change onblur', function () {
  1408. if (this.readOnly) return;
  1409. const expr = $(this);
  1410. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1411. const select = stageTree.getItemsByIndex(row);
  1412. if (!select) return;
  1413. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1414. let newValue = expr.val();
  1415. const num = _.toNumber(newValue);
  1416. if (_.isFinite(num)) {
  1417. newValue = num;
  1418. } else {
  1419. try {
  1420. newValue = math.evaluate(transExpr(newValue));
  1421. } catch(err) {
  1422. toastr.error('输入的表达式非法');
  1423. return;
  1424. }
  1425. }
  1426. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1427. if (field.indexOf('_dgn_') > 0) {
  1428. updateData.dgn = {
  1429. id: select.id
  1430. };
  1431. updateData.dgn[field] = newValue;
  1432. } else {
  1433. updateData.stage = {
  1434. lid: select.id
  1435. };
  1436. updateData.stage[field] = newValue;
  1437. const exprInfo = getExprInfo(field);
  1438. if (exprInfo) {
  1439. updateData.stage[exprInfo.expr] = expr.val();
  1440. }
  1441. }
  1442. // 更新至服务器
  1443. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1444. const nodes = stageTree.loadPostStageData(result);
  1445. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1446. if (detail) {
  1447. detail.loadStageLedgerUpdateData(result, nodes);
  1448. } else {
  1449. stageIm.loadUpdateLedgerData(result, nodes);
  1450. }
  1451. });
  1452. });
  1453. }
  1454. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1455. const addTag = newTag({ledgerSheet: slSpread.getActiveSheet(), billsTag});
  1456. const tenderSelect = TenderSelect({
  1457. type: 'stage',
  1458. afterLoad: function (result, select) {
  1459. const nodes = stageTree.loadPostStageData(result);
  1460. const posterity = stageTree.getPosterity(select);
  1461. for (const p of posterity) {
  1462. p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
  1463. }
  1464. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1465. if (detail) {
  1466. detail.loadStageLedgerUpdateData(result, nodes);
  1467. } else {
  1468. stageIm.loadUpdateLedgerData(result, nodes);
  1469. }
  1470. if (result.sumLoadHis.errors.length > 0) {
  1471. sumLoadMiss.loadMissData(result.sumLoadHis.errors);
  1472. sumLoadMiss.show();
  1473. } else {
  1474. sumLoadMiss.clearMissData();
  1475. }
  1476. // todo 优化,仅加载需要刷新的变更令
  1477. if (checkedChanges) checkedChanges.reloadChangeData();
  1478. }
  1479. });
  1480. $.contextMenu({
  1481. selector: '#stage-ledger',
  1482. build: function ($trigger, e) {
  1483. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1484. stageTreeSpreadObj.loadRelaData();
  1485. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1486. },
  1487. items: {
  1488. 'locateZjjl': {
  1489. name: '定位至中间计量',
  1490. icon: 'fa-sign-in',
  1491. callback: function (key, opt) {
  1492. if (!detail) {
  1493. detail = new Detail($('#detail-spread'));
  1494. }
  1495. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1496. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1497. if (leafUsedBills) {
  1498. if (!$('#zhongjian').hasClass('active')) {
  1499. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  1500. $('a', '.side-menu').removeClass('active');
  1501. $('.tab-content .tab-select-show').removeClass('active');
  1502. tab.addClass('active');
  1503. tabPanel.addClass('active');
  1504. showSideTools(tab.hasClass('active'));
  1505. slSpread.refresh();
  1506. spSpread.refresh();
  1507. }
  1508. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1509. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1510. SpreadJsObj.locateData(detail.sheet, im);
  1511. detail.spread.refresh();
  1512. $('#zhongjian .sjs-bottom').height('400px');
  1513. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1514. detail.reLoadDetailData();
  1515. } else {
  1516. toastr.error('无可定位中间计量');
  1517. }
  1518. },
  1519. disabled: function (key, opt) {
  1520. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1521. return !node;
  1522. }
  1523. },
  1524. tagSpr: '----',
  1525. tag: {
  1526. name: '书签',
  1527. callback: function (key, opt, menu, e) {
  1528. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1529. addTag.do(node);
  1530. },
  1531. disabled: function (key, opt) {
  1532. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1533. return !node;
  1534. }
  1535. },
  1536. showSpr: '----',
  1537. showLast: {
  1538. name: '显示至最底层',
  1539. callback: function (key, opt, menu, e) {
  1540. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1541. setTimeout(() => {
  1542. showWaitingView();
  1543. stageTree.expandByCustom(x => {
  1544. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1545. });
  1546. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  1547. closeWaitingView();
  1548. }, 100);
  1549. },
  1550. disabled: function (key, opt) {
  1551. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1552. return !node;
  1553. }
  1554. },
  1555. exportSpr: '----',
  1556. exportSelectNodeXlsx: {
  1557. name: '导出选中节点至Excel',
  1558. callback: function (key, opt, menu, e) {
  1559. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1560. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  1561. },
  1562. disabled: function (key, opt) {
  1563. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1564. return !node;
  1565. }
  1566. },
  1567. importSpr: '---',
  1568. importStageGcl: {
  1569. name: '导入(其他标段)工程量清单计量数据',
  1570. icon: 'fa-link',
  1571. disabled: function (key, opt) {
  1572. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1573. return readOnly || !node || !stageTree.isLeafXmj(node);
  1574. },
  1575. callback: function (key, opt) {
  1576. tenderSelect.showSelect(SpreadJsObj.getSelectObject(slSpread.getActiveSheet()));
  1577. }
  1578. },
  1579. shoufangdanSpr: '---',
  1580. shoufangdan: {
  1581. name: '生成收方单',
  1582. visible: function(key, opt) {
  1583. if (cur_uid === stage.user_id) return true;
  1584. },
  1585. disabled: function (key, opt) {
  1586. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1587. if (!node || !node.b_code || !node.is_leaf || cur_uid !== stage.user_id) return true;
  1588. },
  1589. callback: function (key, opt) {
  1590. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1591. $('#shoufang-lid').val(node.id);
  1592. $('#shoufang-pid').val('');
  1593. $('#shoufang-ledger').text('清单:' + node.b_code);
  1594. $('#shoufang-pos').text('').hide();
  1595. $('#addshoufang').modal('show');
  1596. }
  1597. }
  1598. }
  1599. });
  1600. const stagePosSpreadObj = {
  1601. loadExprToInput(sheet) {
  1602. const sel = sheet.getSelections()[0];
  1603. if (!sel) return;
  1604. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1605. if (col && col.type === 'Number') {
  1606. const data = SpreadJsObj.getSelectObject(sheet);
  1607. if (data) {
  1608. const exprInfo = getExprInfo(col.field);
  1609. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1610. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1611. .attr('readOnly', readOnly || cell.locked());
  1612. $('#pos-expr').attr('data-row', sel.row);
  1613. } else {
  1614. $('#pos-expr').val('').attr('readOnly', true);
  1615. $('#pos-expr').removeAttr('data-row');
  1616. }
  1617. } else {
  1618. $('#pos-expr').val('').attr('readOnly', true);
  1619. $('#pos-expr').removeAttr('data-row');
  1620. }
  1621. },
  1622. /**
  1623. * 加载计量单元 根据当前台账选择节点
  1624. */
  1625. loadCurPosData: function () {
  1626. const sheet = slSpread.getActiveSheet();
  1627. const node = SpreadJsObj.getSelectObject(sheet);
  1628. if (node) {
  1629. const posReadOnly = node.lock || (node.children && node.children.length > 0) || !node.b_code;
  1630. spSpread.getActiveSheet().zh_setting.readOnly = posReadOnly;
  1631. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1632. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData, posReadOnly);
  1633. getNodeList(node.id);
  1634. } else {
  1635. spSpread.getActiveSheet().zh_setting.readOnly = true;
  1636. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', [], true);
  1637. }
  1638. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1639. },
  1640. editEnded: function (e, info) {
  1641. if (info.sheet.zh_setting) {
  1642. // 未改变过,则直接跳过
  1643. const sortData = info.sheet.zh_data;
  1644. const posData = sortData ? sortData[info.row] : null;
  1645. const col = info.sheet.zh_setting.cols[info.col];
  1646. const orgText = posData ? posData[col.field] : null;
  1647. const newText = trimInvalidChar(info.editingText);
  1648. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1649. return;
  1650. }
  1651. // 台账模式下,不可新增
  1652. if (checkTzMeasureType() && !posData) {
  1653. toastr.error('台账模式不可新增计量单元数据');
  1654. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1655. return ;
  1656. }
  1657. // 不同节点下,计量单元检查输入
  1658. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1659. const node = stagePosSpreadObj.stageTreeNode;
  1660. if (!node) {
  1661. toastr.warning('数据错误, 请刷新页面后再试');
  1662. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1663. return;
  1664. } else if (newText !== '' && node.children && node.children.length > 0) {
  1665. toastr.error('父节点不可插入计量单元');
  1666. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1667. return;
  1668. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1669. toastr.error('项目节不可插入计量单元');
  1670. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1671. return;
  1672. }
  1673. // 生成提交数据
  1674. const data = {};
  1675. if (col.field === 'name') {
  1676. if ((!newText || newText === '') && posData) {
  1677. toastr.error('部位名称不可为空');
  1678. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1679. return;
  1680. } else if (!posData) {
  1681. if (newText !== '') {
  1682. data.updateType = 'add';
  1683. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1684. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1685. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1686. return;
  1687. }
  1688. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1689. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1690. } else {
  1691. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1692. return;
  1693. }
  1694. } else {
  1695. data.updateType = 'update';
  1696. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1697. }
  1698. } else if (!posData) {
  1699. toastr.warning('新增计量单元请先输入名称');
  1700. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1701. data.updateType = 'update';
  1702. data.updateData = {pid: posData.id, lid: posData.lid};
  1703. data.updateData[col.field] = newText;
  1704. } else {
  1705. data.updateType = 'update';
  1706. data.updateData = {pid: posData.id, lid: posData.lid};
  1707. if (col.type === 'Number') {
  1708. const exprInfo = getExprInfo(col.field);
  1709. const num = _.toNumber(newText);
  1710. if (_.isFinite(num)) {
  1711. data.updateData[col.field] = num;
  1712. if (exprInfo) {
  1713. data.updateData[exprInfo.expr] = '';
  1714. }
  1715. } else {
  1716. try {
  1717. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1718. if (exprInfo) {
  1719. data.updateData[exprInfo.expr] = newText;
  1720. }
  1721. } catch(err) {
  1722. toastr.error('输入的表达式非法');
  1723. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1724. return;
  1725. }
  1726. }
  1727. } else {
  1728. data.updateData[col.field] = newText;
  1729. }
  1730. }
  1731. // 提交数据到服务器
  1732. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1733. if (result.pos) {
  1734. stagePos.updateDatas(result.pos.pos);
  1735. stagePos.loadCurStageData(result.pos.curStageData);
  1736. }
  1737. const refreshData = stageTree.loadPostStageData(result.ledger);
  1738. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1739. stagePosSpreadObj.loadCurPosData();
  1740. if (detail) {
  1741. detail.loadStagePosUpdateData(result, refreshData);
  1742. } else {
  1743. stageIm.loadUpdatePosData(result, refreshData);
  1744. }
  1745. }, function () {
  1746. stagePosSpreadObj.loadCurPosData();
  1747. });
  1748. }
  1749. },
  1750. editStarting: function (e, info) {
  1751. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1752. const sel = info.sheet.getSelections();
  1753. if (!sel || !sel[0]) return;
  1754. const col = info.sheet.zh_setting.cols[sel[0].col];
  1755. const node = SpreadJsObj.getSelectObject(info.sheet);
  1756. const exprInfo = getExprInfo(col.field);
  1757. if (exprInfo && node) {
  1758. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1759. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1760. }
  1761. }
  1762. },
  1763. clipboardPasting: function (e, info) {
  1764. if (info.sheet.zh_setting) {
  1765. const sortData = info.sheet.zh_data;
  1766. const range = info.cellRange;
  1767. const validField = ['contract_qty', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3'];
  1768. if (!checkTzMeasureType()) {
  1769. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1770. }
  1771. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1772. const col = info.sheet.zh_setting.cols[iCol];
  1773. if (validField.indexOf(col.field) === -1) {
  1774. if (checkTzMeasureType()) {
  1775. toastr.error('不可修改此数据');
  1776. info.cancel = true;
  1777. return;
  1778. } else {
  1779. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1780. const pos = sortData(iRow);
  1781. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1782. toastr.error('不可修改此数据');
  1783. info.cancel = true;
  1784. return;
  1785. }
  1786. }
  1787. }
  1788. }
  1789. }
  1790. }
  1791. },
  1792. clipboardPasted: function (e, info) {
  1793. if (info.sheet.zh_setting) {
  1794. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1795. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1796. }
  1797. const data = { updateType: '', updateData: [], };
  1798. const sortData = info.sheet.zh_data;
  1799. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1800. if (node.children && node.children.length > 0) return;
  1801. if (sortData && (info.cellRange.row >= sortData.length)) {
  1802. data.updateType = 'add';
  1803. if (info.cellRange.col !== 0) {
  1804. toastr.warning('新增计量单元请先输入名称');
  1805. stagePosSpreadObj.loadCurPosData();
  1806. return;
  1807. }
  1808. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1809. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1810. stagePosSpreadObj.loadCurPosData();
  1811. return;
  1812. }
  1813. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1814. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1815. const curRow = info.cellRange.row + iRow;
  1816. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1817. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1818. const curCol = info.cellRange.col + iCol;
  1819. const colSetting = info.sheet.zh_setting.cols[curCol];
  1820. if (!colSetting) continue;
  1821. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1822. if (colSetting.type === 'Number') {
  1823. const exprInfo = getExprInfo(colSetting.field);
  1824. if (newValue) {
  1825. const num = _.toNumber(newValue);
  1826. if (num) {
  1827. newData[colSetting.field] = num;
  1828. if (exprInfo) {
  1829. newData[exprInfo.expr] = '';
  1830. }
  1831. } else {
  1832. try {
  1833. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1834. if (exprInfo) {
  1835. newData[exprInfo.expr] = newValue;
  1836. }
  1837. } catch(err) {
  1838. toastr.error('输入的表达式非法');
  1839. stagePosSpreadObj.loadCurPosData();
  1840. return;
  1841. }
  1842. }
  1843. } else {
  1844. newData[colSetting.field] = null;
  1845. if (exprInfo) newData[exprInfo.expr] = '';
  1846. }
  1847. } else {
  1848. newData[colSetting.field] = newValue;
  1849. }
  1850. }
  1851. data.updateData.push(newData);
  1852. }
  1853. } else {
  1854. data.updateType = 'update';
  1855. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1856. const curRow = info.cellRange.row + iRow;
  1857. const curPos = sortData[curRow];
  1858. if (curPos) {
  1859. const newData = {pid: curPos.id, lid: curPos.lid};
  1860. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1861. const curCol = info.cellRange.col + iCol;
  1862. const colSetting = info.sheet.zh_setting.cols[curCol];
  1863. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1864. if (colSetting.type === 'Number') {
  1865. const exprInfo = getExprInfo(colSetting.field);
  1866. if (!newValue) {
  1867. newData[colSetting.field] = newValue;
  1868. if (exprInfo) newData[exprInfo.expr] = '';
  1869. continue;
  1870. }
  1871. const num = _.toNumber(newValue);
  1872. if (num) {
  1873. newData[colSetting.field] = num;
  1874. if (exprInfo) newData[exprInfo.expr] = '';
  1875. } else {
  1876. try {
  1877. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1878. const exprInfo = getExprInfo(colSetting.field);
  1879. if (exprInfo) newData[exprInfo.expr] = newValue;
  1880. } catch(err) {
  1881. toastr.error('输入的表达式非法');
  1882. stagePosSpreadObj.loadCurPosData();
  1883. return;
  1884. }
  1885. }
  1886. } else {
  1887. newData[colSetting.field] = newValue;
  1888. }
  1889. }
  1890. data.updateData.push(newData);
  1891. }
  1892. }
  1893. }
  1894. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1895. if (result.pos) {
  1896. stagePos.updateDatas(result.pos.pos);
  1897. stagePos.loadCurStageData(result.pos.curStageData);
  1898. }
  1899. const nodes = stageTree.loadPostStageData(result.ledger);
  1900. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1901. stagePosSpreadObj.loadCurPosData();
  1902. if (detail) {
  1903. detail.loadStagePosUpdateData(result, nodes);
  1904. } else {
  1905. stageIm.loadUpdatePosData(result, nodes);
  1906. }
  1907. }, function () {
  1908. stagePosSpreadObj.loadCurPosData();
  1909. });
  1910. }
  1911. },
  1912. deletePress: function (sheet) {
  1913. if (sheet.zh_setting.readOnly) return;
  1914. if (sheet.zh_setting && sheet.zh_data) {
  1915. const sortData = sheet.zh_data;
  1916. if (!sortData || sortData.length === 0) { return; }
  1917. const sel = sheet.getSelections()[0];
  1918. const validCols = [];
  1919. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1920. const colSetting = sheet.zh_setting.cols[iCol];
  1921. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  1922. validCols.push(iCol);
  1923. }
  1924. }
  1925. if (validCols.length === 0) { return; }
  1926. const datas = [], posSelects = [];
  1927. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1928. const node = sortData[iRow];
  1929. if (node) {
  1930. const data = {pid: node.id, lid: node.lid};
  1931. for (const iCol of validCols) {
  1932. const colSetting = sheet.zh_setting.cols[iCol];
  1933. if (colSetting.field === 'name') {
  1934. toastr.error('部位名称不能为空');
  1935. return;
  1936. }
  1937. data[colSetting.field] = null;
  1938. const exprInfo = getExprInfo(colSetting.field);
  1939. if (exprInfo) {
  1940. data[exprInfo.expr] = '';
  1941. }
  1942. }
  1943. datas.push(data);
  1944. posSelects.push(node);
  1945. }
  1946. }
  1947. if (datas.length > 0) {
  1948. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1949. if (result.pos) {
  1950. stagePos.updateDatas(result.pos.pos);
  1951. stagePos.loadCurStageData(result.pos.curStageData);
  1952. }
  1953. const nodes = stageTree.loadPostStageData(result.ledger);
  1954. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1955. if (detail) {
  1956. detail.loadStagePosUpdateData(result, nodes);
  1957. } else {
  1958. stageIm.loadUpdatePosData(result, nodes);
  1959. }
  1960. // todo 只加载改变项
  1961. stagePosSpreadObj.loadCurPosData();
  1962. });
  1963. }
  1964. }
  1965. },
  1966. deletePos: function (sheet) {
  1967. const sels = sheet.getSelections();
  1968. const sel = sels ? sels[0] : null;
  1969. if (sheet.zh_data && sel) {
  1970. const data = {updateType: 'delete', updateData: []};
  1971. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1972. const posData = sheet.zh_data[sel.row + iRow];
  1973. if (posData) {
  1974. data.updateData.push(posData.id);
  1975. }
  1976. }
  1977. if (data.updateData.length > 0) {
  1978. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1979. stagePos.removeDatas(result.pos.pos);
  1980. const refreshData = stageTree.loadPostStageData(result.ledger);
  1981. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1982. stagePosSpreadObj.loadCurPosData();
  1983. if (detail) {
  1984. detail.loadStagePosUpdateData(result, refreshData);
  1985. } else {
  1986. stageIm.loadUpdatePosData(result, refreshData);
  1987. }
  1988. });
  1989. }
  1990. }
  1991. },
  1992. selectionChanged: function (e, info) {
  1993. stagePosSpreadObj.loadExprToInput(info.sheet);
  1994. },
  1995. addPegs: function (pegs) {
  1996. if (!pegs || pegs.length <= 0) return;
  1997. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1998. if (!node) return;
  1999. const sheet = spSpread.getActiveSheet();
  2000. const sortData = sheet.zh_data || [];
  2001. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2002. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2003. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  2004. if (result.pos) {
  2005. stagePos.updateDatas(result.pos.pos);
  2006. }
  2007. stagePosSpreadObj.loadCurPosData();
  2008. });
  2009. }
  2010. };
  2011. // 加载上下窗口resizer
  2012. $.divResizer({
  2013. select: '#main-resize',
  2014. callback: function () {
  2015. slSpread.refresh();
  2016. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2017. $(".sp-wrap").height(bcontent-30);
  2018. spSpread.refresh();
  2019. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2020. }
  2021. });
  2022. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  2023. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;import_change;tag;cooperation' }, function (result) {
  2024. // 加载树结构
  2025. stageTree.loadDatas(result.ledgerData);
  2026. // 加载部位明细
  2027. stagePos.loadDatas(result.posData);
  2028. checkShowLast(result.ledgerData.length);
  2029. treeCalc.calculateAll(stageTree);
  2030. // 加载解锁相关
  2031. if (result.cooperation) {
  2032. stageTree.loadPwd(result.cooperation, 'bills-p-' + userID + '-' + window.location.pathname.split('/')[2], result.cooperationConfirm);
  2033. $('#cooperationCount').html(stageTree.pwd.length || '');
  2034. if (stageTree.pwd.length > 0) $('#cooperationCount').parent().show();
  2035. setCooperationSelectHtml();
  2036. reloadCooperationHtml();
  2037. }
  2038. for (const t of result.tags) {
  2039. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  2040. }
  2041. billsTag.loadDatas(result.tags);
  2042. stagePos.calculateAll();
  2043. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  2044. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  2045. stagePosSpreadObj.loadCurPosData();
  2046. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  2047. // 加载中间计量
  2048. stageIm.init(stage, imType, tenderInfo.decimal);
  2049. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData, result.import_change, result.detailAtt);
  2050. errorList.loadHisErrorData();
  2051. checkList.loadHisCheckData();
  2052. sumLoadMiss.loadHisMissData();
  2053. // 收方单赋值
  2054. ledgerData = result.ledgerData;
  2055. posData = result.posData;
  2056. makeShouFang();
  2057. }, null, true);
  2058. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2059. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2060. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2061. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2062. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2063. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2064. if (!readOnly) {
  2065. $('#pos-expr').bind('change onblur', function () {
  2066. if (this.readOnly) return;
  2067. const expr = $(this);
  2068. const posSheet = spSpread.getActiveSheet();
  2069. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2070. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2071. if (!select) return;
  2072. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2073. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2074. const data = {pid: select.id, lid: select.lid};
  2075. const exprInfo = getExprInfo(field);
  2076. if (newValue !== '') {
  2077. const num = _.toNumber(newValue);
  2078. if (num) {
  2079. data[field] = num;
  2080. if (exprInfo) data[exprInfo.expr] = '';
  2081. } else {
  2082. try {
  2083. data[field] = math.evaluate(transExpr(newValue));
  2084. if (exprInfo) data[exprInfo.expr] = newValue;
  2085. } catch (err) {
  2086. toastr.error('输入的表达式非法');
  2087. return;
  2088. }
  2089. }
  2090. } else {
  2091. data[field] = null;
  2092. if (exprInfo) data[exprInfo.expr] = '';
  2093. }
  2094. // 提交数据到服务器
  2095. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2096. if (result.pos) {
  2097. stagePos.updateDatas(result.pos.pos);
  2098. stagePos.loadCurStageData(result.pos.curStageData);
  2099. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2100. }
  2101. const refreshData = stageTree.loadPostStageData(result.ledger);
  2102. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2103. if (detail) {
  2104. detail.loadStagePosUpdateData(result, refreshData);
  2105. } else {
  2106. stageIm.loadUpdatePosData(result, refreshData);
  2107. }
  2108. });
  2109. });
  2110. }
  2111. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2112. $.contextMenu({
  2113. selector: '#stage-pos',
  2114. build: function ($trigger, e) {
  2115. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2116. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2117. },
  2118. items: {
  2119. 'del': {
  2120. name: '删除',
  2121. icon: 'fa-remove',
  2122. visible: function (key, opt) {
  2123. return !checkTzMeasureType();
  2124. },
  2125. disabled: function (key, opt) {
  2126. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2127. if (!node || node.lock) return true;
  2128. const sheet = spSpread.getActiveSheet();
  2129. if (sheet.zh_data && !readOnly) {
  2130. const selection = sheet.getSelections();
  2131. if (selection && selection[0]) {
  2132. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2133. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2134. const posData = sheet.zh_data[selection[0].row + iRow];
  2135. if (posData) {
  2136. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2137. valid = true;
  2138. break;
  2139. }
  2140. } else {
  2141. valid = true;
  2142. break;
  2143. }
  2144. }
  2145. return valid;
  2146. } else {
  2147. return true;
  2148. }
  2149. } else {
  2150. return true;
  2151. }
  2152. },
  2153. callback: function (key, opt) {
  2154. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2155. }
  2156. },
  2157. 'sort': {
  2158. name: '排序',
  2159. items: {
  2160. "addStageReverse": {
  2161. name: '按新增期倒序',
  2162. icon: 'fa-sort-amount-desc',
  2163. callback: function (key, opt) {
  2164. stagePos.sort = [['add_stage_order', 'desc'], ['porder', 'asc']];
  2165. const spSheet = spSpread.getActiveSheet();
  2166. if (spSheet.zh_data) {
  2167. spSheet.zh_data.sort((x, y) => { return y.add_stage_order - x.add_stage_order || x.porder - y.porder; });
  2168. SpreadJsObj.reLoadSheetData(spSheet);
  2169. }
  2170. }
  2171. }
  2172. }
  2173. },
  2174. 'merge-peg': {
  2175. name: '合并起讫桩号',
  2176. visible: function (key, opt) {
  2177. return !checkTzMeasureType();
  2178. },
  2179. disabled: function (key, opt) {
  2180. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2181. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2182. },
  2183. callback: function (key, opt) {
  2184. mergePeg.show();
  2185. }
  2186. },
  2187. 'calcByRatio': {
  2188. name: '按比例计量',
  2189. visible: function (key, opt) {
  2190. const data = spSpread.getActiveSheet().zh_data;
  2191. return checkTzMeasureType() && data && data.length > 0;
  2192. },
  2193. disabled: function (key, opt) {
  2194. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2195. return node.lock;
  2196. },
  2197. callback: function (key, opt) {
  2198. $('#cbr-ratio').val('');
  2199. $('#apply2sibling')[0].checked = false;
  2200. $('#cbr-check-all')[0].checked = false;
  2201. const html = [];
  2202. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2203. html.push('<tr>');
  2204. html.push('<td>', i+1, '</td>');
  2205. html.push('<td>', p.name, '</td>');
  2206. html.push('<td>', p.quantity, '</td>');
  2207. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2208. html.push('</tr>');
  2209. }
  2210. $('#cbr-pos-list').html(html.join(''));
  2211. $('#calc-by-ratio').modal('show');
  2212. }
  2213. },
  2214. 'remainCur': {
  2215. name: '填剩余量(选中行)',
  2216. disabled: function (key, opt) {
  2217. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2218. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2219. return readOnly || node.lock || !curPos;
  2220. },
  2221. callback: function (key, opt) {
  2222. const sheet = spSpread.getActiveSheet();
  2223. const sels = sheet.getSelections();
  2224. if (!sels || !sels[0]) return;
  2225. const data = { updateType: 'update', updateData: [] };
  2226. for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
  2227. const curRow = iRow + sels[0].row;
  2228. const curPos = SpreadJsObj.getRowObject(sheet, curRow);
  2229. if (!curPos) continue;
  2230. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2231. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2232. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2233. }
  2234. if (data.updateData.length > 0) {
  2235. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2236. if (result.pos) {
  2237. stagePos.updateDatas(result.pos.pos);
  2238. stagePos.loadCurStageData(result.pos.curStageData);
  2239. }
  2240. const nodes = stageTree.loadPostStageData(result.ledger);
  2241. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2242. stagePosSpreadObj.loadCurPosData();
  2243. if (detail) {
  2244. detail.loadStagePosUpdateData(result, nodes);
  2245. } else {
  2246. stageIm.loadUpdatePosData(result, nodes);
  2247. }
  2248. });
  2249. }
  2250. },
  2251. visible: function(key, opt) {
  2252. return checkTzMeasureType();
  2253. },
  2254. },
  2255. 'remainAll': {
  2256. name: '填剩余量(全部行)',
  2257. disabled: function (key, opt) {
  2258. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2259. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2260. return readOnly || node.lock || !curPos;
  2261. },
  2262. callback: function (key, opt) {
  2263. const sheet = spSpread.getActiveSheet();
  2264. if (!sheet.zh_data || sheet.zh_data.length === 0) return;
  2265. const data = { updateType: 'update', updateData: [] };
  2266. for (const curPos of sheet.zh_data) {
  2267. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2268. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2269. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2270. }
  2271. if (data.updateData.length > 0) {
  2272. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2273. if (result.pos) {
  2274. stagePos.updateDatas(result.pos.pos);
  2275. stagePos.loadCurStageData(result.pos.curStageData);
  2276. }
  2277. const nodes = stageTree.loadPostStageData(result.ledger);
  2278. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2279. stagePosSpreadObj.loadCurPosData();
  2280. if (detail) {
  2281. detail.loadStagePosUpdateData(result, nodes);
  2282. } else {
  2283. stageIm.loadUpdatePosData(result, nodes);
  2284. }
  2285. });
  2286. }
  2287. },
  2288. visible: function(key, opt) {
  2289. return checkTzMeasureType();
  2290. },
  2291. },
  2292. 'shoufangdan': {
  2293. name: '生成收方单',
  2294. visible: function(key, opt) {
  2295. if (cur_uid === stage.user_id) return true;
  2296. },
  2297. disabled: function (key, opt) {
  2298. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2299. if (!node || cur_uid !== stage.user_id) return true;
  2300. },
  2301. callback: function (key, opt) {
  2302. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2303. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2304. $('#shoufang-lid').val(node.lid);
  2305. $('#shoufang-pid').val(node.id);
  2306. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2307. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2308. $('#addshoufang').modal('show');
  2309. }
  2310. }
  2311. }
  2312. });
  2313. $.subMenu({
  2314. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2315. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2316. key: 'menu.1.0.0',
  2317. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2318. callback: function (info) {
  2319. if (info.mini) {
  2320. $('.panel-title').addClass('fluid');
  2321. $('#sub-menu').removeClass('panel-sidebar');
  2322. } else {
  2323. $('.panel-title').removeClass('fluid');
  2324. $('#sub-menu').addClass('panel-sidebar');
  2325. }
  2326. autoFlashHeight();
  2327. slSpread.refresh();
  2328. spSpread.refresh();
  2329. if (searchLedger) searchLedger.spread.refresh();
  2330. if (detail) detail.spread.refresh();
  2331. if (checkedChanges) checkedChanges.refresh();
  2332. if (errorList && errorList.spread) errorList.spread.refresh();
  2333. if (checkList) checkList.spread.refresh();
  2334. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2335. }
  2336. });
  2337. $('#row-view').on('show.bs.modal', function () {
  2338. const html = [], customDisplay = customColDisplay();
  2339. for (const cd of customDisplay) {
  2340. html.push('<tr>');
  2341. html.push('<td>', cd.title, '</td>');
  2342. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2343. html.push('</tr>');
  2344. }
  2345. $('#row-view-list').html(html.join(''));
  2346. });
  2347. $('#row-view-ok').click(function () {
  2348. const customDisplay = customColDisplay();
  2349. const cvl = $('#row-view-list').children();
  2350. for (const cv of cvl) {
  2351. const title = $(cv).children()[0].innerHTML;
  2352. const check = $('input', cv)[0].checked;
  2353. const cd = customDisplay.find(function (c) {
  2354. return c.title === title;
  2355. });
  2356. cd.visible = check;
  2357. }
  2358. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2359. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2360. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2361. $('#row-view').modal('hide');
  2362. });
  2363. const posSearch = (function () {
  2364. let resultArr = [];
  2365. const search = function () {
  2366. resultArr = [];
  2367. const keyword = $('#pos-search-keyword').val();
  2368. const checkOver = $('#pos-over-search')[0].checked;
  2369. const checkEmpty = $('#pos-empty-search')[0].checked;
  2370. const sortData = spSpread.getActiveSheet().zh_data;
  2371. if (checkOver || checkEmpty) {
  2372. if (sortData) {
  2373. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2374. const sd = sortData[i];
  2375. let match = false;
  2376. if (checkOver) {
  2377. if (sd.end_gather_qty) {
  2378. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2379. }
  2380. }
  2381. if (checkEmpty) {
  2382. if (sd.quantity) {
  2383. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2384. }
  2385. }
  2386. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2387. if (match) {
  2388. resultArr.push({index: i, data: sd});
  2389. }
  2390. }
  2391. }
  2392. } else if (keyword && keyword !== '') {
  2393. if (sortData) {
  2394. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2395. const sd = sortData[i];
  2396. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2397. resultArr.push({index: i, data: sd});
  2398. }
  2399. }
  2400. }
  2401. }
  2402. $('#pos-search-result').html('结果:' + resultArr.length);
  2403. };
  2404. const searchAndLocate = function () {
  2405. search();
  2406. if (resultArr.length > 0) {
  2407. const sheet = spSpread.getActiveSheet();
  2408. const sel = sheet.getSelections()[0];
  2409. const curRow = sel ? sel.row : 0;
  2410. const pos = resultArr[0];
  2411. if (pos.index !== curRow) {
  2412. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2413. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2414. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2415. }
  2416. }
  2417. };
  2418. const locateNext = function () {
  2419. if (resultArr.length > 0) {
  2420. const sheet = spSpread.getActiveSheet();
  2421. const sel = sheet.getSelections()[0];
  2422. const curRow = sel ? sel.row : 0;
  2423. let next = _.find(resultArr, function (d) {
  2424. return d.index > curRow;
  2425. });
  2426. if (!next) next = resultArr[0];
  2427. if (next.index !== curRow) {
  2428. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2429. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2430. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2431. }
  2432. }
  2433. };
  2434. const locatePre = function () {
  2435. if (resultArr.length > 0) {
  2436. const sheet = spSpread.getActiveSheet();
  2437. const sel = sheet.getSelections()[0];
  2438. const curRow = sel ? sel.row : 0;
  2439. let next = _.findLast(resultArr, function (d) {
  2440. return d.index < curRow;
  2441. });
  2442. if (!next) next = resultArr[resultArr.length - 1];
  2443. if (next.index !== curRow) {
  2444. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2445. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2446. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2447. }
  2448. }
  2449. };
  2450. return {search, searchAndLocate, locateNext, locatePre};
  2451. })();
  2452. $('#pos-search-keyword').bind('keydown', function(e){
  2453. if (e.keyCode == 13) posSearch.searchAndLocate();
  2454. });
  2455. $('#pos-empty-search').click(function () {
  2456. if (this.checked) {
  2457. $('[for=' + this.id +']').addClass('text-warning');
  2458. } else {
  2459. $('[for=' + this.id +']').removeClass('text-warning');
  2460. }
  2461. if (this.checked) {
  2462. if ($('#pos-over-search')[0].checked) {
  2463. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2464. } else {
  2465. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2466. }
  2467. } else {
  2468. if ($('#pos-over-search')[0].checked) {
  2469. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2470. } else {
  2471. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2472. }
  2473. }
  2474. posSearch.searchAndLocate();
  2475. });
  2476. $('#pos-over-search').click(function () {
  2477. if (this.checked) {
  2478. $('[for=' + this.id +']').addClass('text-danger');
  2479. } else {
  2480. $('[for=' + this.id +']').removeClass('text-danger');
  2481. }
  2482. if (this.checked) {
  2483. if ($('#pos-empty-search')[0].checked) {
  2484. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2485. } else {
  2486. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2487. }
  2488. } else {
  2489. if ($('#pos-empty-search')[0].checked) {
  2490. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2491. } else {
  2492. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2493. }
  2494. }
  2495. posSearch.searchAndLocate();
  2496. });
  2497. $('#pos-search-next').click(() => {posSearch.locateNext()});
  2498. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  2499. $.divResizer({
  2500. select: '#right-spr',
  2501. callback: function () {
  2502. slSpread.refresh();
  2503. spSpread.refresh();
  2504. if (searchLedger) {
  2505. searchLedger.spread.refresh();
  2506. }
  2507. if (detail) {
  2508. detail.spread.refresh();
  2509. }
  2510. if (checkedChanges) checkedChanges.refresh();
  2511. if (errorList && errorList.spread) errorList.spread.refresh();
  2512. if (checkList) checkList.spread.refresh();
  2513. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2514. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2515. }
  2516. });
  2517. // 中间计量加载上下窗口resizer
  2518. $.divResizer({
  2519. select: '#zhongjian-spr',
  2520. callback: function () {
  2521. if (detail) {
  2522. detail.spread.refresh();
  2523. }
  2524. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2525. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2526. }
  2527. });
  2528. // 附件加载上下窗口resizer
  2529. $.divResizer({
  2530. select: '#file-spr',
  2531. callback: function () {
  2532. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2533. }
  2534. });
  2535. // 变更令加载上下窗口resizer
  2536. $.divResizer({
  2537. select: '#change-spr',
  2538. callback: function () {
  2539. if (checkedChanges) checkedChanges.refresh();
  2540. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2541. }
  2542. });
  2543. class Detail {
  2544. constructor (obj) {
  2545. const self = this;
  2546. this.spreadSetting = {
  2547. cols: [
  2548. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2549. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2550. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  2551. {
  2552. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  2553. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  2554. },
  2555. {
  2556. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  2557. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  2558. return data.attachment ? data.attachment.length : 0;
  2559. }
  2560. },
  2561. ],
  2562. headRows: 1,
  2563. emptyRows: 0,
  2564. headRowHeight: [32],
  2565. headColWidth: [30],
  2566. defaultRowHeight: 21,
  2567. headerFont: '12px 微软雅黑',
  2568. font: '12px 微软雅黑',
  2569. readOnly: readOnly,
  2570. selectedBackColor: '#fffacd',
  2571. imageClick: function (data) {
  2572. self.makeAttTable(data);
  2573. $('#im-file').modal('show');
  2574. }
  2575. };
  2576. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  2577. this.sheet = this.spread.getActiveSheet();
  2578. this.spread.options.allowUserDragFill = true;
  2579. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  2580. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2581. this.detailObj = {
  2582. selectionChanged: function (e, info) {
  2583. self.reLoadDetailData();
  2584. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  2585. self.loadLocateInfo();
  2586. }
  2587. },
  2588. editEnded: function(e, info) {
  2589. if (info.sheet.zh_setting) {
  2590. const col = info.sheet.zh_setting.cols[info.col];
  2591. if (col.field !== 'doc_code') {
  2592. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2593. return;
  2594. }
  2595. const data = SpreadJsObj.getSelectObject(info.sheet);
  2596. if (data) {
  2597. const updateData = {lid: data.lid, pid: data.pid};
  2598. if (data.uuid) {
  2599. updateData.uuid = data.uuid;
  2600. } else {
  2601. updateData.code = data.code;
  2602. updateData.name = data.name;
  2603. updateData.unit = data.unit;
  2604. updateData.unit_price = data.unit_price;
  2605. updateData.pid = data.pid;
  2606. updateData.pos_name = data.pos_name;
  2607. updateData.im_type = data.im_type;
  2608. }
  2609. if (data.custom_define.indexOf('doc_code') === -1) {
  2610. updateData.custom_define = data.custom_define;
  2611. updateData.custom_define.push('doc_code');
  2612. updateData.custom_define = updateData.custom_define.join(',');
  2613. }
  2614. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  2615. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2616. stageIm.loadUpdateDetailData(result);
  2617. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2618. }, function () {
  2619. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2620. });
  2621. } else {
  2622. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2623. }
  2624. }
  2625. },
  2626. clipboardPasted: function (e, info) {
  2627. if (info.sheet.zh_setting && info.sheet.zh_data) {
  2628. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  2629. if (info.cellRange.colCount > 1) {
  2630. toastr.warning('请勿同时复制粘贴多列数据');
  2631. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2632. return;
  2633. }
  2634. if (col.field !== 'doc_code') {
  2635. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2636. return;
  2637. }
  2638. const datas = [];
  2639. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2640. const curRow = info.cellRange.row + iRow;
  2641. const data = info.sheet.zh_data[curRow];
  2642. if (data) {
  2643. const updateData = {lid: data.lid, pid: data.pid};
  2644. if (data.uuid) {
  2645. updateData.uuid = data.uuid;
  2646. } else {
  2647. updateData.code = data.code;
  2648. updateData.name = data.name;
  2649. updateData.unit = data.unit;
  2650. updateData.unit_price = data.unit_price;
  2651. updateData.pid = data.pid;
  2652. updateData.pos_name = data.pos_name;
  2653. updateData.im_type = data.im_type;
  2654. }
  2655. if (data.custom_define.indexOf('doc_code') === -1) {
  2656. updateData.custom_define = data.custom_define;
  2657. updateData.custom_define.push('doc_code');
  2658. updateData.custom_define = updateData.custom_define.join(',');
  2659. }
  2660. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  2661. datas.push(updateData);
  2662. }
  2663. }
  2664. if (datas.length > 0) {
  2665. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2666. stageIm.loadUpdateDetailData(result);
  2667. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2668. }, function () {
  2669. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2670. })
  2671. }
  2672. }
  2673. },
  2674. deletePress: function (sheet) {
  2675. if (sheet.zh_setting) {
  2676. const datas = [];
  2677. const sel = sheet.getSelections()[0];
  2678. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2679. const col = sheet.zh_setting.cols[iCol];
  2680. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2681. const data = sheet.zh_data[iRow];
  2682. if (col.field === 'doc_code') {
  2683. const updateData = {lid: data.lid};
  2684. if (data.uuid) {
  2685. updateData.uuid = data.uuid;
  2686. updateData.doc_code = '';
  2687. datas.push(updateData);
  2688. }
  2689. }
  2690. }
  2691. }
  2692. if (datas.length > 0) {
  2693. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2694. stageIm.loadUpdateDetailData(result);
  2695. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2696. }, function () {
  2697. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2698. });
  2699. }
  2700. }
  2701. },
  2702. dragFillBlock: function (e, info) {
  2703. info.cancel = true;
  2704. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2705. const sel = info.sheet.getSelections()[0];
  2706. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2707. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2708. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2709. if (text === '') return;
  2710. const regRst = /(\d+)$/g.exec(text), datas = [];
  2711. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2712. const curRow = info.fillRange.row + iRow;
  2713. const data = info.sheet.zh_data[curRow];
  2714. if (data) {
  2715. const updateData = {lid: data.lid};
  2716. if (data.uuid) {
  2717. updateData.uuid = data.uuid;
  2718. } else {
  2719. updateData.code = data.code;
  2720. updateData.name = data.name;
  2721. updateData.unit = data.unit;
  2722. updateData.unit_price = data.unit_price;
  2723. updateData.pid = data.pid;
  2724. updateData.pos_name = data.pos_name;
  2725. updateData.im_type = data.im_type;
  2726. }
  2727. if (regRst) {
  2728. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2729. } else {
  2730. updateData.doc_code = text.replace('\n', '');
  2731. }
  2732. if (data.custom_define.indexOf('doc_code') === -1) {
  2733. updateData.custom_define = data.custom_define;
  2734. updateData.custom_define.push('doc_code');
  2735. updateData.custom_define = updateData.custom_define.join(',');
  2736. }
  2737. datas.push(updateData);
  2738. }
  2739. }
  2740. if (datas.length > 0) {
  2741. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2742. stageIm.loadUpdateDetailData(result);
  2743. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2744. }, function () {
  2745. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2746. })
  2747. }
  2748. },
  2749. };
  2750. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2751. if (!readOnly) {
  2752. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2753. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2754. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2755. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2756. }
  2757. this._initImTypeSetRela();
  2758. this._initModifyDetail();
  2759. this._initLocateRela();
  2760. this._initAttRela();
  2761. // 草图相关
  2762. this._initImageRela();
  2763. this.reBuildImData();
  2764. }
  2765. makeAttTable (data) {
  2766. let html = [];
  2767. if (data.attachment) {
  2768. for (const att of data.attachment) {
  2769. const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked))
  2770. ? '<a class="delete-att text-danger ml-1" href="javascript:void(0);" data-imid="'+ data.att_uuid +'" data-attid="'+ att.file_id +'" title="删除"><i class="fa fa-remove "></i></a>'
  2771. : '';
  2772. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  2773. const downloadHtml = '<a href="'+ window.location.pathname + '/im-file/download?im_id='+ data.att_uuid +'&file_id='+ att.file_id +'" title="下载"><i class="fa fa-download "></i></a>';
  2774. html.push('<tr><td style="width: 200px">' + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
  2775. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  2776. }
  2777. }
  2778. $('#im-attList').html(html.join(''));
  2779. }
  2780. _initAttRela() {
  2781. // 上传附件
  2782. const self = this;
  2783. $('#upload-im-file').change(function () {
  2784. const files = this.files;
  2785. const sels = self.sheet.getSelections();
  2786. const select = SpreadJsObj.getSelectObject(self.sheet);
  2787. if (!select) return;
  2788. const formData = new FormData();
  2789. const baseInfo = {};
  2790. if (select.att_uuid) {
  2791. baseInfo.uuid = select.att_uuid;
  2792. } else {
  2793. baseInfo.im_type = select.im_type;
  2794. baseInfo.lid = select.lid;
  2795. baseInfo.pid = select.pid;
  2796. baseInfo.code = select.code;
  2797. baseInfo.name = select.name;
  2798. baseInfo.unit = select.unit;
  2799. baseInfo.unit_price = select.unit_price;
  2800. baseInfo.pos_name = select.pos_name;
  2801. }
  2802. formData.append('base', JSON.stringify(baseInfo));
  2803. for (const file of files) {
  2804. if (file === undefined) {
  2805. toast('未选择上传文件!', 'error');
  2806. return false;
  2807. }
  2808. const filesize = file.size;
  2809. if (filesize > 30 * 1024 * 1024) {
  2810. toast('存在上传文件大小过大!', 'error');
  2811. return false;
  2812. }
  2813. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2814. if (whiteList.indexOf(fileext) === -1) {
  2815. toast('只能上传指定格式的附件!', 'error');
  2816. return false;
  2817. }
  2818. formData.append('size', filesize);
  2819. formData.append('file[]', file);
  2820. }
  2821. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  2822. stageIm.loadUpdateDetailAtt(data);
  2823. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  2824. self.makeAttTable(select);
  2825. $('#upload-im-file').val('');
  2826. });
  2827. });
  2828. // 删除附件
  2829. $('body').on('click', '.delete-att' ,function () {
  2830. const sels = self.sheet.getSelections();
  2831. const select = SpreadJsObj.getSelectObject(self.sheet);
  2832. if (!select) return;
  2833. const uuid = $(this).attr('data-imid');
  2834. const file_id = $(this).attr('data-attid');
  2835. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  2836. stageIm.loadUpdateDetailAtt(result);
  2837. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  2838. self.makeAttTable(select);
  2839. });
  2840. });
  2841. // 预览附件
  2842. $('body').on('click', '.preview-att', function () {
  2843. const uuid = $(this).attr('data-imid');
  2844. const file_id = $(this).attr('data-attid');
  2845. postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
  2846. const { filepath } = result;
  2847. $('#load-file').attr('href', filepath);
  2848. $('#load-file')[0].click();
  2849. });
  2850. })
  2851. }
  2852. _initImTypeSetRela() {
  2853. const self = this;
  2854. const gatherConfirmPopover = {
  2855. reBind: function (obj, eventName, fun) {
  2856. obj.unbind(eventName);
  2857. obj.bind(eventName, fun);
  2858. },
  2859. check: function (pos, hint, okCallback) {
  2860. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2861. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2862. this.reBind(cancelObj, 'click', function () {
  2863. confirmObj.hide();
  2864. });
  2865. this.reBind(okObj, 'click', function () {
  2866. okCallback();
  2867. confirmObj.hide();
  2868. });
  2869. hintObj.text(hint);
  2870. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2871. }
  2872. };
  2873. this.gsTree = stageIm.getGsTree();
  2874. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2875. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2876. jlCol.title = '本期计量金额';
  2877. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2878. $('[name=type-title-contract]').text('本期合同计量金额');
  2879. $('[name=type-title-qc]').text('本期变更计量金额');
  2880. if ($('#show-qc-minus-jl').length > 0) {
  2881. $('#show-qc-minus-jl').parent().hide();
  2882. $('#qc-minus-jl').parent().hide();
  2883. }
  2884. } else {
  2885. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2886. jlCol.title = '本期计量数量';
  2887. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2888. $('[name=type-title-contract]').text('本期合同计量数量');
  2889. $('[name=type-title-qc]').text('本期变更计量数量');
  2890. if ($('#show-qc-minus-jl').length > 0) {
  2891. $('#show-qc-minus-jl').parent().show();
  2892. $('#qc-minus-jl').parent().show();
  2893. }
  2894. }
  2895. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2896. $('#show-jldy').parent().show();
  2897. $('#jldy').parent().show();
  2898. $('#show-xm-name').parent().hide();
  2899. $('#xm-name').parent().hide();
  2900. } else {
  2901. $('#show-jldy').parent().hide();
  2902. $('#jldy').parent().hide();
  2903. $('#show-xm-name').parent().show();
  2904. $('#xm-name').parent().show();
  2905. }
  2906. // 选择中间计量模式
  2907. $('div[name="im-type"]').click(function () {
  2908. function chooseType(obj) {
  2909. obj.style.cursor = 'default';
  2910. $(obj).children().addClass('text-primary');
  2911. $(obj).addClass('border-primary');
  2912. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2913. }
  2914. function validType(obj) {
  2915. obj.style.cursor = 'pointer';
  2916. $(obj).children().removeClass('text-primary');
  2917. $(obj).removeClass('border-primary');
  2918. $('i', obj).remove();
  2919. }
  2920. if (this.style.cursor === 'pointer') {
  2921. const typeArr = $('div[name="im-type"]');
  2922. for (const t of typeArr) {
  2923. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2924. chooseType(t);
  2925. } else {
  2926. validType(t)
  2927. }
  2928. }
  2929. }
  2930. });
  2931. $('#choose').on('show.bs.modal', function () {
  2932. function chooseType(obj) {
  2933. obj.style.cursor = 'default';
  2934. $(obj).children().addClass('text-primary');
  2935. $('i', obj).remove();
  2936. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2937. }
  2938. function validType(obj) {
  2939. obj.style.cursor = 'pointer';
  2940. $(obj).children().removeClass('text-primary');
  2941. $('i', obj).remove();
  2942. }
  2943. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2944. $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
  2945. const typeArr = $('div[name="im-type"]');
  2946. for (const t of typeArr) {
  2947. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2948. chooseType(t);
  2949. } else {
  2950. validType(t)
  2951. }
  2952. }
  2953. });
  2954. // 提交 中间计量模式
  2955. $('#choose-ok').click(() => {
  2956. let startNum;
  2957. try {
  2958. startNum = parseInt($('#im-start-num').val());
  2959. if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
  2960. } catch (err) {
  2961. toastr.error("起始编号请输入正整数");
  2962. return;
  2963. }
  2964. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2965. return it.style.cursor !== 'pointer';
  2966. });
  2967. const data = {
  2968. im_type: parseInt($(chooseType).attr('im-type')),
  2969. im_pre: $('#im-pre').val(),
  2970. im_start_num: startNum,
  2971. };
  2972. postData(window.location.pathname + '/detail/build', data, function (result) {
  2973. stage.im_type = data.im_type;
  2974. stage.im_pre = data.im_pre;
  2975. stage.im_start_num = data.im_start_num;
  2976. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2977. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2978. jlCol.title = '本期计量金额';
  2979. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2980. $('[name=type-title-contract]').text('本期合同计量金额');
  2981. $('[name=type-title-qc]').text('本期变更计量金额');
  2982. if ($('#show-qc-minus-jl').length > 0) {
  2983. $('#show-qc-minus-jl').parent().hide();
  2984. $('#qc-minus-jl').parent().hide();
  2985. }
  2986. } else {
  2987. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2988. jlCol.title = '本期计量数量';
  2989. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2990. $('[name=type-title-contract]').text('本期合同计量数量');
  2991. $('[name=type-title-qc]').text('本期变更计量数量');
  2992. if ($('#show-qc-minus-jl').length > 0) {
  2993. $('#show-qc-minus-jl').parent().show();
  2994. $('#qc-minus-jl').parent().show();
  2995. }
  2996. }
  2997. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2998. $('#show-jldy').parent().show();
  2999. $('#jldy').parent().show();
  3000. $('#show-xm-name').parent().hide();
  3001. $('#xm-name').parent().hide();
  3002. } else {
  3003. $('#show-jldy').parent().hide();
  3004. $('#jldy').parent().hide();
  3005. $('#show-xm-name').parent().show();
  3006. $('#xm-name').parent().show();
  3007. }
  3008. // 加载生成数据
  3009. self.reBuildImData();
  3010. $('#choose').modal('hide');
  3011. });
  3012. });
  3013. // 显示树结构信息
  3014. $('#choose2').on('shown.bs.modal', function () {
  3015. if (!self.gsSpread) {
  3016. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  3017. const setting = {
  3018. cols: [
  3019. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  3020. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  3021. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3022. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  3023. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  3024. ],
  3025. headRows: 1,
  3026. emptyRows: 0,
  3027. headRowHeight: [32],
  3028. defaultRowHeight: 21,
  3029. headerFont: '12px 微软雅黑',
  3030. font: '12px 微软雅黑',
  3031. };
  3032. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  3033. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  3034. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  3035. function checkParent(node) {
  3036. const parent = self.gsTree.getParent(node);
  3037. if (parent) {
  3038. return parent.check ? parent.check : checkParent(parent);
  3039. } else {
  3040. return false;
  3041. }
  3042. }
  3043. function checkChildren(node) {
  3044. for (const child of node.children) {
  3045. if (child.check) {
  3046. return true;
  3047. } else if (checkChildren(child)) {
  3048. return true;
  3049. }
  3050. }
  3051. return false;
  3052. }
  3053. if (!$('#im-gather-check')[0].checked) { return; }
  3054. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  3055. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  3056. if (sheet.isEditing()) {
  3057. sheet.endEdit(true);
  3058. }
  3059. }
  3060. if (info.sheet.zh_setting) {
  3061. const col = info.sheet.zh_setting.cols[info.col];
  3062. if (col.field !== 'check') {
  3063. return;
  3064. }
  3065. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  3066. const node = sortData[info.row];
  3067. if (!node.check) {
  3068. if (checkParent(node)) {
  3069. const rect = info.sheet.getCellRect(info.row, info.col);
  3070. gatherConfirmPopover.check({
  3071. x: rect.x + rect.width / 2 + 25,
  3072. y: rect.y + rect.height / 2 + 3,
  3073. }, '父项已勾选,继续将取消父项勾选。', function () {
  3074. node.check = true;
  3075. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  3076. const rows = [self.gsTree.nodes.indexOf(node)];
  3077. for (const p of parents) {
  3078. if (p.check) {
  3079. p.check = false;
  3080. rows.push(self.gsTree.nodes.indexOf(p));
  3081. }
  3082. }
  3083. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3084. });
  3085. } else if (checkChildren(node)) {
  3086. const rect = info.sheet.getCellRect(info.row, info.col);
  3087. gatherConfirmPopover.check({
  3088. x: rect.x + rect.width / 2 + 25,
  3089. y: rect.y + rect.height / 2 + 3,
  3090. }, '子项已勾选,继续将取消子项勾选。', function () {
  3091. node.check = true;
  3092. const posterity = self.gsTree.getPosterity(node);
  3093. const rows = [self.gsTree.nodes.indexOf(node)];
  3094. for (const p of posterity) {
  3095. if (p.check) {
  3096. rows.push(self.gsTree.nodes.indexOf(p));
  3097. p.check = false;
  3098. }
  3099. }
  3100. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3101. });
  3102. } else {
  3103. node.check = true;
  3104. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3105. }
  3106. } else {
  3107. node.check = false;
  3108. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3109. }
  3110. }
  3111. });
  3112. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3113. for (const node of self.gsTree.datas) {
  3114. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3115. }
  3116. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  3117. self.gsTree.expandByLevel(4);
  3118. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  3119. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  3120. } else {
  3121. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3122. for (const node of self.gsTree.datas) {
  3123. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3124. }
  3125. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  3126. }
  3127. });
  3128. // 提交 高级设置
  3129. $('#choose2-ok').click(() => {
  3130. if (!self.gsTree) { return; }
  3131. const nodes = [];
  3132. for (const node of self.gsTree.datas) {
  3133. if (node.check) {
  3134. nodes.push(node.id);
  3135. }
  3136. }
  3137. const data = {
  3138. im_gather: $('#im-gather-check')[0].checked,
  3139. im_gather_node: nodes.join(','),
  3140. };
  3141. postData(window.location.pathname + '/detail/adv', data, function (result) {
  3142. stage.im_gather = data.im_gather;
  3143. stage.im_gather_node = data.im_gather_node;
  3144. $('#choose2').modal('hide');
  3145. });
  3146. });
  3147. }
  3148. _initLocateRela() {
  3149. const self = this;
  3150. $('#im-locate2bills').click(function () {
  3151. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3152. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3153. if (select && select.source) {
  3154. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  3155. stagePosSpreadObj.loadCurPosData();
  3156. }
  3157. });
  3158. $('#im-locate-pre').click(function () {
  3159. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3160. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3161. if (select && select.source) {
  3162. const targetIndex = Math.max(curIndex-1, 1);
  3163. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3164. stagePosSpreadObj.loadCurPosData();
  3165. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3166. }
  3167. });
  3168. $('#im-locate-next').click(function () {
  3169. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3170. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3171. if (select && select.source) {
  3172. const targetIndex = Math.min(curIndex+1, select.source.length);
  3173. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3174. stagePosSpreadObj.loadCurPosData();
  3175. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3176. }
  3177. });
  3178. }
  3179. _initModifyDetail() {
  3180. const self = this;
  3181. // 重置
  3182. $('#reset-detail-ok').click(function () {
  3183. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3184. if (!data.uuid) return;
  3185. const updateData = {
  3186. lid: data.lid, pid: data.pid,
  3187. uuid: data.uuid,
  3188. custom_define: [],
  3189. };
  3190. for (const f of data.custom_define) {
  3191. if (stageIm.resetFields.indexOf(f) >= 0) {
  3192. updateData[f] = null;
  3193. } else {
  3194. updateData.custom_define.push(f);
  3195. }
  3196. }
  3197. updateData.custom_define = updateData.custom_define.join(',');
  3198. $('#reset-detail-modal').modal('hide');
  3199. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3200. stageIm.loadUpdateDetailData(result);
  3201. self.reLoadDetailData();
  3202. });
  3203. });
  3204. // 编辑
  3205. $('#edit-detail').click(function () {
  3206. $(this).hide();
  3207. $('#save-detail').show();
  3208. $('#cancel-detail').show();
  3209. $('#detail-show').hide();
  3210. $('#detail-edit').show();
  3211. self.updateImageData = null;
  3212. });
  3213. // 保存
  3214. $('#save-detail').click(() => {
  3215. function check(field, obj, org, update) {
  3216. const newValue = obj.val();
  3217. if (!org[field]) {
  3218. if (newValue !== '') {
  3219. update[field] = newValue;
  3220. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3221. return true;
  3222. }
  3223. } else if (newValue !== org[field]){
  3224. update[field] = newValue;
  3225. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3226. return true;
  3227. }
  3228. return false;
  3229. }
  3230. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3231. const updateData = {lid: data.lid, pid: data.pid};
  3232. if (data.uuid) {
  3233. updateData.uuid = data.uuid;
  3234. updateData.custom_define = data.custom_define;
  3235. } else {
  3236. updateData.code = data.code;
  3237. updateData.name = data.name;
  3238. updateData.unit = data.unit;
  3239. updateData.unit_price = data.unit_price;
  3240. updateData.pid = data.pid;
  3241. updateData.pos_name = data.pos_name;
  3242. updateData.im_type = data.im_type;
  3243. updateData.custom_define = [];
  3244. }
  3245. let infoUpdate = false;
  3246. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  3247. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  3248. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  3249. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  3250. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  3251. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  3252. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  3253. updateData.custom_define = updateData.custom_define.join(',');
  3254. if (infoUpdate) {
  3255. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3256. stageIm.loadUpdateDetailData(result);
  3257. self.reLoadDetailData();
  3258. if (!self.updateImageData) return;
  3259. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  3260. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3261. stageIm.loadUpdateDetailData(result);
  3262. self.reLoadDetailData();
  3263. });
  3264. });
  3265. } else if (self.updateImageData) {
  3266. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3267. stageIm.loadUpdateDetailData(result);
  3268. self.reLoadDetailData();
  3269. });
  3270. } else {
  3271. self.reLoadDetailData();
  3272. }
  3273. });
  3274. // 取消
  3275. $('#cancel-detail').click(() => {
  3276. self.reLoadDetailData();
  3277. });
  3278. }
  3279. _initImageRela() {
  3280. const self = this;
  3281. $('#edit-detail').click(function () {
  3282. loadImageItem();
  3283. });
  3284. function setdraggrable(){
  3285. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3286. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3287. stop: function( event, ui ) {
  3288. }
  3289. });
  3290. }
  3291. function upload(formData) {
  3292. if (formData.length < 1) {
  3293. return;
  3294. }
  3295. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3296. const html = [];
  3297. html.push('<div class="img-item">');
  3298. html.push('<div class="img-bar">');
  3299. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3300. html.push('</div>');
  3301. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3302. html.push('</div>');
  3303. $('.img-view').append(html.join(''));
  3304. $('.img-bar').click(removeImageItem);
  3305. setdraggrable();
  3306. $('#upload-img-file').val('');
  3307. });
  3308. }
  3309. function dragFile(e) {
  3310. var file = null,
  3311. data = e.dataTransfer.types;
  3312. for (var i = 0; i < data.length; i += 1) {
  3313. if (data[i] === 'Files') {
  3314. file = e.dataTransfer.files; //获取文件
  3315. break;
  3316. }
  3317. }
  3318. if (file && file[0].type.indexOf('image') !== -1) {
  3319. var formData = new FormData();
  3320. formData.append('file', file[0]); //上传单个文件的添加方式
  3321. upload(formData); //upload 异步上传
  3322. }
  3323. }
  3324. // 移动图片
  3325. const moveImageItem = function (ev) {
  3326. const item = this;
  3327. const view = $('.img-view')[0];
  3328. let oEvent = ev;
  3329. // 浏览器有一些图片的默认事件,这里要阻止
  3330. oEvent.preventDefault();
  3331. let disX = oEvent.clientX - item.offsetLeft;
  3332. let disY = oEvent.clientY - item.offsetTop;
  3333. view.onmousemove = function (ev) {
  3334. oEvent = ev;
  3335. oEvent.preventDefault();
  3336. let x = oEvent.clientX -disX;
  3337. let y = oEvent.clientY -disY;
  3338. // 图形移动的边界判断
  3339. x = x <= 0 ? 0 : x;
  3340. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  3341. y = y <= 0 ? 0 : y;
  3342. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  3343. item.style.left = x + 'px';
  3344. item.style.top = y + 'px';
  3345. };
  3346. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  3347. view.onmouseleave = function () {
  3348. view.onmousemove = null;
  3349. view.onmouseup = null;
  3350. };
  3351. // 鼠标弹起后停止移动
  3352. view.onmouseup=function() {
  3353. view.onmousemove = null;
  3354. view.onmouseup = null;
  3355. };
  3356. };
  3357. const removeImageItem = function () {
  3358. $(this).parent().remove();
  3359. };
  3360. // 加载草图组成
  3361. const loadImageItem = function () {
  3362. self.updateImageData = null;
  3363. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3364. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3365. const html = [];
  3366. for (const item of items) {
  3367. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3368. html.push('<div class="img-item" style="' + itemStyle + '">');
  3369. html.push('<div class="img-bar">');
  3370. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3371. html.push('</div>');
  3372. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3373. html.push('</div>');
  3374. }
  3375. $('.img-view').html(html.join(''));
  3376. $('.img-bar').click(removeImageItem);
  3377. setdraggrable();
  3378. };
  3379. // 上传图片
  3380. $('#upload-img').click(function () {
  3381. $('#upload-img-file').trigger('click');
  3382. });
  3383. // 拖拽上传
  3384. //拖拽上传文件
  3385. const dragbox = document.querySelector('#upload-img');
  3386. dragbox.addEventListener('dragover', function(e) {
  3387. e.preventDefault(); // 必须阻止默认事件
  3388. }, false);
  3389. dragbox.addEventListener('drop', function(e) {
  3390. e.preventDefault(); // 阻止默认事件
  3391. dragFile(e);
  3392. }, false);
  3393. //拖拽上传文件
  3394. const dragbox2 = document.querySelector('.img-view');
  3395. dragbox2.addEventListener('dragover', function(e) {
  3396. e.preventDefault(); // 必须阻止默认事件
  3397. }, false);
  3398. dragbox2.addEventListener('drop', function(e) {
  3399. e.preventDefault(); // 阻止默认事件
  3400. dragFile(e);
  3401. }, false);
  3402. // 粘贴上传
  3403. $(".img-view").on('paste', function(ev) {
  3404. let file = null;
  3405. const data = (event.clipboardData || window.clipboardData).items;
  3406. for (let i = 0; i < data.length; i += 1) {
  3407. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3408. file = data[i].getAsFile(); //读取图片文件
  3409. break;
  3410. }
  3411. }
  3412. if (file) {
  3413. const formData = new FormData();
  3414. formData.append('file', file); //上传单个文件的添加方式
  3415. upload(formData); //异步上传文件
  3416. }
  3417. });
  3418. $('#upload-img-file').change(function () {
  3419. const file = this.files[0];
  3420. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  3421. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  3422. if (!imgStr.test(ext)) {
  3423. toastr.error('请上传正确的图片格式文件');
  3424. return
  3425. }
  3426. if ($(this).val()) {
  3427. const formData = new FormData();
  3428. formData.append('file', this.files[0]);
  3429. upload(formData);
  3430. }
  3431. });
  3432. // 保存草图修改结果
  3433. $('#edit-img-ok').click(function () {
  3434. // 记录上传的图片的信息
  3435. const items = $('.img-item');
  3436. const img_remark = $('#text-edit').val();
  3437. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3438. // 生成上传数据
  3439. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  3440. if (data.uuid) {
  3441. updateData.uuid = data.uuid;
  3442. } else {
  3443. updateData.code = data.code;
  3444. updateData.name = data.name;
  3445. updateData.unit = data.unit;
  3446. updateData.unit_price = data.unit_price;
  3447. updateData.pid = data.pid;
  3448. updateData.pos_name = data.pos_name;
  3449. updateData.im_type = data.im_type;
  3450. }
  3451. if (items.length > 0) {
  3452. const itemInfo = [];
  3453. for (const item of items) {
  3454. const itemData = {
  3455. src: $('img', item).attr('src'),
  3456. left: item.style.left,
  3457. top: item.style.top,
  3458. width: item.style.width,
  3459. height: item.style.height,
  3460. };
  3461. itemInfo.push(itemData);
  3462. }
  3463. // 获取合并好的图片数据
  3464. const canvas = document.createElement('canvas');
  3465. const view = $('.img-view')[0];
  3466. canvas.height = view.clientHeight;
  3467. canvas.width = view.clientWidth;
  3468. const ctx = canvas.getContext('2d');
  3469. ctx.fillStyle = '#ffffff';
  3470. ctx.fillRect(0, 0, canvas.width, canvas.height);
  3471. for (const b of $('.img-item')) {
  3472. const pos = $(b).position();
  3473. const img = $('img', b)[0];
  3474. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  3475. }
  3476. updateData.img = canvas.toDataURL('image/png');
  3477. updateData.imgInfo = itemInfo;
  3478. self.updateImageData = updateData;
  3479. $('#calc-img').attr('src', updateData.img);
  3480. $('#calc-remark').html(img_remark);
  3481. $('#view-calc-img').attr('src', updateData.img);
  3482. $('#show-calc-img').attr('src', updateData.img);
  3483. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  3484. $('#view-calc-remark').text(img_remark);
  3485. $('#edit-img').modal('hide');
  3486. // });
  3487. } else if (data.calc_img) {
  3488. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  3489. $('#show-calc-img').attr('src', '');
  3490. $('#show-calc-remark').html('');
  3491. $('#calc-img').attr('src', '');
  3492. $('#calc-remark').html(img_remark);
  3493. $('#view-calc-img').attr('src', '');
  3494. $('#view-calc-remark').val(img_remark);
  3495. $('#text-edit').val(img_remark);
  3496. $('#edit-img').modal('hide');
  3497. } else {
  3498. self.updateImageData = updateData;
  3499. $('#show-calc-img').attr('src', '');
  3500. $('#show-calc-remark').html('');
  3501. $('#calc-img').attr('src', '');
  3502. $('#calc-remark').html(img_remark);
  3503. $('#view-calc-img').attr('src', '');
  3504. $('#view-calc-remark').val(img_remark);
  3505. $('#text-edit').val(img_remark);
  3506. $('#edit-img').modal('hide');
  3507. }
  3508. });
  3509. }
  3510. reBuildImData() {
  3511. const imData = stageIm.buildImData();
  3512. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3513. this.reLoadDetailData();
  3514. this.loadLocateInfo();
  3515. }
  3516. loadStageLedgerUpdateData(data, nodes) {
  3517. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  3518. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3519. this.reLoadDetailData();
  3520. }
  3521. loadStagePosUpdateData(data, nodes) {
  3522. const imData = stageIm.loadUpdatePosData(data, nodes);
  3523. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3524. this.reLoadDetailData();
  3525. }
  3526. loadStageChangeUpdateData(data, nodes) {
  3527. const imData = stageIm.loadUpdateChangeData(data, nodes);
  3528. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3529. this.reLoadDetailData();
  3530. }
  3531. loadLocateInfo() {
  3532. const select = SpreadJsObj.getSelectObject(this.sheet);
  3533. if (select && select.source.length > 1) {
  3534. $('#im-locate2bills').next().show();
  3535. } else {
  3536. $('#im-locate2bills').next().hide();
  3537. }
  3538. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  3539. }
  3540. reLoadDetailData() {
  3541. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  3542. $('#reset-detail').hide();
  3543. if (data) {
  3544. for (const f of data.custom_define) {
  3545. if (stageIm.resetFields.indexOf(f) >= 0) {
  3546. $('#reset-detail').show();
  3547. break;
  3548. }
  3549. }
  3550. $('#edit-detail').show();
  3551. $('#modify-img').show();
  3552. } else {
  3553. $('#edit-detail').hide();
  3554. $('#modify-img').hide();
  3555. }
  3556. $('#save-detail').hide();
  3557. $('#cancel-detail').hide();
  3558. $('#detail-show').show();
  3559. $('#detail-edit').hide();
  3560. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  3561. $('#show-contract-jl').text(contractJl);
  3562. $('#contract-jl').val(contractJl);
  3563. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  3564. $('#show-qc-jl').text(qcJl);
  3565. $('#qc-jl').val(qcJl);
  3566. const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
  3567. $('#show-qc-minus-jl').text(qcMinusJl);
  3568. $('#qc-minus-jl').val(qcMinusJl);
  3569. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  3570. $('#show-bgl-code').text(bglCode);
  3571. $('#bgl-code').val(bglCode);
  3572. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  3573. $('#show-bgl-drawing-code').text(bglDrawingCode);
  3574. $('#bgl-drawing-code').val(bglDrawingCode);
  3575. const bwName = data && data.bw ? data.bw : '';
  3576. $('#show-bw-name').text(bwName);
  3577. $('#bw-name').val(bwName);
  3578. const position = data && data.position ? data.position : '';
  3579. $('#show-position').text(position);
  3580. $('#position').val(position);
  3581. const peg = data && data.peg ? data.peg : '';
  3582. $('#show-peg').text(peg);
  3583. $('#peg').val(peg);
  3584. const xmName = data && data.xm ? data.xm: '';
  3585. $('#show-xm-name').text(xmName);
  3586. $('#xm-name').val(xmName);
  3587. const jldy = data && data.jldy ? data.jldy: '';
  3588. $('#show-jldy').text(jldy);
  3589. $('#jldy').val(jldy);
  3590. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  3591. $('#show-drawing-code').text(drawingCode);
  3592. $('#drawing-code').val(drawingCode);
  3593. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  3594. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  3595. $('#calc-memo').val(calcMemo);
  3596. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3597. $('#show-calc-img').attr('src', calcImgSrc);
  3598. $('#calc-img').attr('src', calcImgSrc);
  3599. $('#view-calc-img').attr('src', calcImgSrc);
  3600. const calcImgRemark = data && data.calc_img_remark || '';
  3601. $('#view-calc-remark').val(calcImgRemark);
  3602. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  3603. $('#calc-remark').html(calcImgRemark);
  3604. $("#view-calc-remark").attr('readonly', true);
  3605. // 处理 编辑 -> 添加草图中textarea多余的空格
  3606. $('#text-edit').val(calcImgRemark)
  3607. }
  3608. }
  3609. class CheckedChange {
  3610. constructor (setting) {
  3611. const self = this;
  3612. this.changeSpreadSetting = {
  3613. cols: [
  3614. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: function (x) { return x.t_name ? `所属标段:${x.t_name}` : ''; }},
  3615. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  3616. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3617. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  3618. ],
  3619. emptyRows: 0,
  3620. headRows: 1,
  3621. headRowHeight: [32],
  3622. headColWidth: [30],
  3623. defaultRowHeight: 21,
  3624. headerFont: '12px 微软雅黑',
  3625. font: '12px 微软雅黑',
  3626. readOnly: true,
  3627. getColor: function (sheet, data, row, col, defaultColor) {
  3628. if (data && data.is_import) {
  3629. return '#eee';
  3630. } else {
  3631. return defaultColor;
  3632. }
  3633. }
  3634. };
  3635. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  3636. this.changeSheet = this.changeSpread.getActiveSheet();
  3637. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  3638. const getTipText = function (data) {
  3639. if (!data) return '';
  3640. const tips = [];
  3641. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  3642. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  3643. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  3644. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  3645. return tips.join('-');
  3646. };
  3647. this.changeBillsSpreadSetting = {
  3648. cols: [
  3649. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  3650. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number', cellType: 'delayTip', getTip: getTipText},
  3651. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3652. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  3653. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  3654. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  3655. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  3656. ],
  3657. emptyRows: 0,
  3658. headRows: 1,
  3659. headRowHeight: [32],
  3660. defaultRowHeight: 21,
  3661. headerFont: '12px 微软雅黑',
  3662. font: '12px 微软雅黑',
  3663. readOnly: true
  3664. };
  3665. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  3666. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  3667. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  3668. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  3669. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3670. if (change.cid === self.curChangeId) { return; }
  3671. self.curChangeId = change.cid;
  3672. if (change.detail) {
  3673. self.loadChangeDetailData();
  3674. } else {
  3675. postData(window.location.pathname + '/change/detail', {cid: change.cid, is_import: change.is_import}, function (result) {
  3676. change.detail = result;
  3677. self.analyzeChange(change);
  3678. self.loadChangeDetailData();
  3679. });
  3680. }
  3681. });
  3682. this.changes = null;
  3683. this.reloadChangeData();
  3684. setting.reloadObj.click(function() {
  3685. self.reloadChangeData();
  3686. });
  3687. $.contextMenu({
  3688. selector: '#' + setting.changeBillsObj.attr('id'),
  3689. build: function ($trigger, e) {
  3690. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  3691. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3692. },
  3693. items: {
  3694. 'locateZjjl': {
  3695. name: '定位至台账',
  3696. icon: 'fa-sign-in',
  3697. callback: function (key, opt) {
  3698. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3699. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3700. if (change.is_import) {
  3701. if (changeBills.pos && changeBills.pos.length > 0) {
  3702. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), changeBills.pos[0].ledger_id, true);
  3703. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  3704. stagePosSpreadObj.loadCurPosData();
  3705. }
  3706. } else if (changeBills.gcl_id) {
  3707. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  3708. if (!node) return;
  3709. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id, true);
  3710. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  3711. stagePosSpreadObj.loadCurPosData();
  3712. const posData = spSpread.getActiveSheet().zh_data;
  3713. if (!posData || posData.length === 0) return;
  3714. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  3715. if (changePos) SpreadJsObj.locateData(spSpread.getActiveSheet(), changePos);
  3716. } else {
  3717. const cb = {
  3718. b_code: changeBills.code || '',
  3719. name: changeBills.name || '',
  3720. unit: changeBills.unit || '',
  3721. unit_price: changeBills.unit_price || 0,
  3722. };
  3723. for (const node of stageTree.nodes) {
  3724. if (node.children && node.children.length > 0) continue;
  3725. const b = {
  3726. b_code: node.b_code || '',
  3727. name: node.name || '',
  3728. unit: node.unit || '',
  3729. unit_price: node.unit_price || 0,
  3730. };
  3731. if (_.isMatch(cb, b)) {
  3732. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3733. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  3734. stagePosSpreadObj.loadCurPosData();
  3735. return;
  3736. }
  3737. }
  3738. }
  3739. },
  3740. disabled: function (key, opt) {
  3741. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3742. return !changeBills;
  3743. }
  3744. },
  3745. 'autoUse': {
  3746. name: '调用',
  3747. icon: 'fa-play',
  3748. callback: function (key, opt) {
  3749. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3750. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3751. const billsPos = self.findBillsPos(curChange, changeBills);
  3752. if (!billsPos) toastr.warning('无可调用的清单或计量单元');
  3753. const data = { autoType: 'bills', bills: [{ ...billsPos, cid: changeBills.cid, cbid: changeBills.cbid }] };
  3754. postData(window.location.pathname + '/auto-change', data, function(result) {
  3755. if (result.pos) {
  3756. stagePos.loadCurStageData(result.pos.curStageData);
  3757. }
  3758. const nodes = stageTree.loadPostStageData(result.bills);
  3759. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  3760. stagePosSpreadObj.loadCurPosData();
  3761. if (detail) {
  3762. detail.loadStageChangeUpdateData(result, nodes);
  3763. } else {
  3764. stageIm.loadUpdateChangeData(result, nodes)
  3765. }
  3766. });
  3767. },
  3768. disable: function (key, opt) {
  3769. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3770. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3771. return !changeBills || curChange.is_import;
  3772. },
  3773. visible: function (key, opt) {
  3774. return false;
  3775. }
  3776. },
  3777. }
  3778. });
  3779. $.contextMenu({
  3780. selector: '#' + setting.changeObj.attr('id'),
  3781. build: function ($trigger, e) {
  3782. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeSpread);
  3783. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3784. },
  3785. items: {
  3786. 'autoUseCur': {
  3787. name: '自动调用',
  3788. icon: 'fa-play',
  3789. callback: function (key, opt) {
  3790. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3791. const changeBills = SpreadJsObj.zh_data;
  3792. const data = { bills: [], autoType: 'bills' };
  3793. for (const cb of changeBills) {
  3794. const billsPos = self.findBillsPos(curChange, cb);
  3795. if (billsPos) data.push({ ...billsPos, cid: curChange.cid, cbid: cb.cbid })
  3796. }
  3797. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  3798. if (result.pos) {
  3799. stagePos.loadCurStageData(result.pos.curStageData);
  3800. }
  3801. const nodes = stageTree.loadPostStageData(result.bills);
  3802. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  3803. stagePosSpreadObj.loadCurPosData();
  3804. if (detail) {
  3805. detail.loadStageChangeUpdateData(result, nodes);
  3806. } else {
  3807. stageIm.loadUpdateChangeData(result, nodes)
  3808. }
  3809. });
  3810. },
  3811. disable: function (key, opt) {
  3812. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3813. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3814. return !changeBills || curChange.is_import;
  3815. },
  3816. visible: function (key, opt) {
  3817. return false;
  3818. }
  3819. },
  3820. 'autoUseAll': {
  3821. name: '自动调用(全部变更令)',
  3822. icon: 'fa-play',
  3823. callback: function (key, opt) {
  3824. postData(window.location.pathname + '/auto-use-change', { autoType: 'all' }, function(result) {
  3825. window.location.reload();
  3826. });
  3827. },
  3828. disable: function (key, opt) {
  3829. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  3830. return !curChange || curChange.is_import;
  3831. },
  3832. visible: function (key, opt) {
  3833. return is_debug && stage.status === 1;
  3834. }
  3835. }
  3836. }
  3837. });
  3838. }
  3839. loadChangeDetailData() {
  3840. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  3841. if (change) {
  3842. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  3843. } else {
  3844. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  3845. }
  3846. }
  3847. refresh() {
  3848. this.changeSpread.refresh();
  3849. this.changeBillsSpread.refresh();
  3850. }
  3851. reloadChangeData() {
  3852. const self = this;
  3853. postData(window.location.pathname + '/change/data', null, function (result) {
  3854. self.changes = [];
  3855. result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
  3856. result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; self.changes.push(x); });
  3857. if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
  3858. if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
  3859. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  3860. self.changeSheet.setSelection(0, 0, 1, 1);
  3861. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  3862. self.loadChangeDetailData();
  3863. });
  3864. }
  3865. _analyzeCommon(change) {
  3866. for (const b of change.bills) {
  3867. const eub = change.detail.endUsedBills.find(function (x) {
  3868. return x.cbid === b.id;
  3869. });
  3870. if (eub) b.used_qty = eub.qty;
  3871. b.qty = _.toNumber(b.samount);
  3872. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  3873. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3874. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  3875. b.cur_qty = 0;
  3876. for (const p of b.pos) {
  3877. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  3878. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  3879. }
  3880. }
  3881. }
  3882. _analyzeImport(change) {
  3883. for (const b of change.bills) {
  3884. const eub = change.detail.endUsedBills.find(function (x) {
  3885. return x.rela_cbid === b.id;
  3886. });
  3887. if (eub) b.used_qty = eub.rela_qty;
  3888. b.qty = _.toNumber(b.samount);
  3889. delete b.unit_price;
  3890. // b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3891. b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
  3892. b.cur_qty = 0;
  3893. for (const p of b.pos) {
  3894. p.qty = p.rela_qty;
  3895. const node = stageTree.datas.find(x => { return x.id === p.lid; });
  3896. p.ledger_id = node.ledger_id;
  3897. p.f_qty = node.quantity;
  3898. b.cur_qty = ZhCalc.add(b.cur_qty, p.rela_qty);
  3899. }
  3900. }
  3901. }
  3902. analyzeChange(change) {
  3903. change.bills = change.detail.bills;
  3904. if (change.is_import) {
  3905. this._analyzeImport(change);
  3906. } else {
  3907. this._analyzeCommon(change);
  3908. }
  3909. }
  3910. findBillsPos(change, changeBills) {
  3911. if (change.is_import) {
  3912. return null;
  3913. } else if (changeBills.gcl_id) {
  3914. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  3915. posData = stagePos.getLedgerPos(node.id);
  3916. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  3917. return { lid: node.id, pid: changePos ? changePos.id : (posData.length > 0 ? posData[0].id : -1) };
  3918. } else {
  3919. const cb = {
  3920. b_code: changeBills.code || '',
  3921. name: changeBills.name || '',
  3922. unit: changeBills.unit || '',
  3923. unit_price: changeBills.unit_price || 0,
  3924. };
  3925. for (const node of stageTree.nodes) {
  3926. if (node.children && node.children.length > 0) continue;
  3927. const b = {
  3928. b_code: node.b_code || '',
  3929. name: node.name || '',
  3930. unit: node.unit || '',
  3931. unit_price: node.unit_price || 0,
  3932. };
  3933. if (_.isMatch(cb, b)) {
  3934. posData = stagePos.getLedgerPos(node.id);
  3935. return { lid: node.id, pid: posData.length > 0 ? posData[0].id : -1 };
  3936. }
  3937. }
  3938. return null;
  3939. }
  3940. }
  3941. }
  3942. // 展开收起附件
  3943. $('a', '.right-nav').bind('click', function () {
  3944. //const main = $('#main-view'), tool = $('#tools-view');
  3945. const tab = $(this), tabPanel = $(tab.attr('content'));
  3946. if (!tab.hasClass('active')) {
  3947. $('a', '.side-menu').removeClass('active');
  3948. $('.tab-content .tab-select-show').removeClass('active');
  3949. tab.addClass('active');
  3950. tabPanel.addClass('active');
  3951. showSideTools(tab.hasClass('active'));
  3952. if (tab.attr('content') === '#search' && !searchLedger) {
  3953. searchLedger = $.billsSearch({
  3954. selector: '#search',
  3955. searchSpread: slSpread,
  3956. searchOver: true,
  3957. searchEmpty: true,
  3958. resultSpreadSetting: {
  3959. cols: [
  3960. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3961. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3962. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3963. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3964. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3965. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3966. {title: '完成率(%)', field: 'end_gather_percent', hAlign: 2, width: 70},
  3967. ],
  3968. emptyRows: 0,
  3969. headRows: 1,
  3970. headRowHeight: [32],
  3971. headColWidth: [30],
  3972. defaultRowHeight: 21,
  3973. headerFont: '12px 微软雅黑',
  3974. font: '12px 微软雅黑',
  3975. selectedBackColor: '#fffacd',
  3976. },
  3977. afterLocated: function () {
  3978. stagePosSpreadObj.loadCurPosData();
  3979. },
  3980. customSearch: [
  3981. {
  3982. key: 'less', title: '漏计', valid: true,
  3983. check: function (node) {
  3984. if (node.quantity) {
  3985. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  3986. } else if (node.total_price) {
  3987. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  3988. }
  3989. }
  3990. }, {
  3991. key: 'over', title: '超计', valid: true,
  3992. check: function (node) {
  3993. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  3994. }
  3995. }, {
  3996. key: 'empty', title: '漏计', valid: false,
  3997. check: function (node) {
  3998. if (node.quantity) {
  3999. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  4000. } else if (node.total_price) {
  4001. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  4002. }
  4003. }
  4004. }, {
  4005. key: 'estimate', title: '预计变更', valid: true,
  4006. check: function (node) {
  4007. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  4008. if (posRange.length > 0) {
  4009. for (const p of posRange) {
  4010. if (!checkZero(p.estimate_qty)) return true;
  4011. }
  4012. return false;
  4013. } else {
  4014. return false;
  4015. }
  4016. }
  4017. }
  4018. ],
  4019. });
  4020. searchLedger.spread.refresh();
  4021. }
  4022. if (tab.attr('content') === '#fujian') {
  4023. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4024. node && getNodeList(node.id);
  4025. }
  4026. if (tab.attr('content') === '#zhongjian') {
  4027. if (!detail) {
  4028. detail = new Detail($('#detail-spread'));
  4029. detail.spread.refresh();
  4030. $('#zhongjian .sjs-bottom').height('400px');
  4031. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  4032. } else {
  4033. detail.spread.refresh();
  4034. }
  4035. }
  4036. if (tab.attr('content') === '#checked-change') {
  4037. if (!checkedChanges) {
  4038. checkedChanges = new CheckedChange({
  4039. changeObj: $('#cc-spread'),
  4040. changeBillsObj: $('#ccb-spread'),
  4041. reloadObj: $('#refresh-cc'),
  4042. });
  4043. checkedChanges.refresh();
  4044. } else {
  4045. $('#ccb-spread').height('400px');
  4046. checkedChanges.refresh();
  4047. }
  4048. }
  4049. if (tab.attr('content') === '#error-list') {
  4050. errorList.spread.refresh();
  4051. }
  4052. if (tab.attr('content') === '#check-list') {
  4053. checkList.spread.refresh();
  4054. }
  4055. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  4056. } else {
  4057. tab.removeClass('active');
  4058. tabPanel.removeClass('active');
  4059. showSideTools(tab.hasClass('active'));
  4060. }
  4061. slSpread.refresh();
  4062. spSpread.refresh();
  4063. });
  4064. // 切换附件里节点和所有附件
  4065. $('#fujian .nav-link').on('click', function () {
  4066. const tabPanel = $(this).attr('fujian-content');
  4067. if (tabPanel !== 'syfujian') {
  4068. $('#showPage').hide();
  4069. $('#bach-download').prop('type', 'curr');
  4070. } else {
  4071. $('#showPage').show();
  4072. $('#bach-download').prop('type', 'all')
  4073. }
  4074. $('#showAttachment').hide();
  4075. });
  4076. // 上传附件
  4077. $('#upload-file-btn').click(function () {
  4078. // if (curAuditor && curAuditor.aid !== cur_uid) {
  4079. // return toastr.error('当前操作没有权限!');
  4080. // }
  4081. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4082. if (!node) return
  4083. const files = $('#upload-file')[0].files;
  4084. const formData = new FormData();
  4085. formData.append('lid', node.id);
  4086. for (const file of files) {
  4087. if (file === undefined) {
  4088. toastr.error('未选择上传文件!');
  4089. return false;
  4090. }
  4091. const filesize = file.size;
  4092. if (filesize > 30 * 1024 * 1024) {
  4093. toastr.error('存在上传文件大小过大!');
  4094. return false;
  4095. }
  4096. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  4097. if (whiteList.indexOf(fileext) === -1) {
  4098. toastr.error('只能上传指定格式的附件!');
  4099. return false;
  4100. }
  4101. formData.append('size', filesize);
  4102. formData.append('file[]', file);
  4103. }
  4104. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  4105. $('#upload').modal('hide');
  4106. // 插入到attData中
  4107. attData = data.concat(attData);
  4108. // 重新生成List
  4109. getAllList();
  4110. getNodeList(node.id);
  4111. }, function () {
  4112. toastr.error('附件上传失败');
  4113. });
  4114. $('#upload-file').val('');
  4115. });
  4116. // 获取附件信息
  4117. $('.list-table').on('click', '.att-file-name', function () {
  4118. const fid = $(this).attr('file-id');
  4119. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  4120. return;
  4121. }
  4122. const att = attData.find(function (item) {
  4123. return item.id === parseInt(fid);
  4124. });
  4125. $('#edit-att').hide();
  4126. $('#show-att').show();
  4127. if (att !== undefined) {
  4128. // 进来先把编辑功能隐藏
  4129. $('#btn-att a').eq(3).hide()
  4130. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  4131. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4132. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  4133. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  4134. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  4135. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  4136. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  4137. $('#show-att tr').eq(3).children('td').text(att.remark);
  4138. // 附件uid等于当前用户id, 附件上传本人
  4139. if (parseInt(cur_uid) === att.uid) {
  4140. $('#btn-att').show();
  4141. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  4142. // if (!curAuditor) {
  4143. // stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  4144. // stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  4145. // stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  4146. // } else {
  4147. // curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  4148. // }
  4149. if (showDel) $('#btn-att a').eq(3).show();
  4150. // $('#btn-att a').eq(3).show();
  4151. $('#btn-att a').eq(2).hide();
  4152. $('#btn-att a').eq(4).hide();
  4153. $('#btn-att a').eq(5).hide();
  4154. } else {
  4155. $('#btn-att').hide();
  4156. $('#btn-att a').eq(3).hide();
  4157. $('#btn-att a').eq(2).hide();
  4158. $('#btn-att a').eq(4).hide();
  4159. $('#btn-att a').eq(5).hide();
  4160. }
  4161. $('#showAttachment').attr('file-id', fid);
  4162. $('#showAttachment').show();
  4163. } else {
  4164. $('#showAttachment').hide();
  4165. $('#showAttachment').attr('file-id', '');
  4166. toastr.error('附件信息获取失败');
  4167. }
  4168. });
  4169. // $('body').on('click', '.alllist-table a', handleFileList);
  4170. $('body').on('click', '#btn-att a', function () {
  4171. const content = $(this).attr('content');
  4172. const fid = $('#showAttachment').attr('file-id');
  4173. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4174. if (content === 'edit') {
  4175. $('#btn-att a').eq(3).hide();
  4176. $('#btn-att a').eq(2).show();
  4177. $('#btn-att a').eq(4).show();
  4178. $('#btn-att a').eq(5).show();
  4179. $('#show-att').hide();
  4180. $('#edit-att').show();
  4181. const att = attData.find(function (item) {
  4182. return item.id === parseInt(fid);
  4183. });
  4184. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  4185. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  4186. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4187. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  4188. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  4189. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  4190. } else if (content === 'cancel') {
  4191. $('#show-att').show();
  4192. $('#edit-att').hide();
  4193. $('#btn-att a').eq(3).show();
  4194. $('#btn-att a').eq(2).hide();
  4195. $('#btn-att a').eq(4).hide();
  4196. $('#btn-att a').eq(5).hide();
  4197. } else if (content === 'save') {
  4198. const formData = new FormData();
  4199. formData.append('id', fid);
  4200. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  4201. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  4202. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  4203. const file = $('#change-att-btn')[0];
  4204. if (file.files[0] !== undefined) {
  4205. const filesize = file.files[0].size;
  4206. formData.append('size', filesize);
  4207. formData.append('file', file.files[0]);
  4208. }
  4209. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  4210. // 替换到attData中
  4211. const att_index = attData.findIndex(function (item) {
  4212. return item.id === parseInt(fid);
  4213. });
  4214. attData.splice(att_index, 1, data);
  4215. // 重新生成List
  4216. getAllList(parseInt($('#currentPage').text()));
  4217. getNodeList(node.id);
  4218. $('#show-att').show();
  4219. $('#edit-att').hide();
  4220. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4221. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4222. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4223. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  4224. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  4225. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  4226. $('#show-att tr').eq(4).children('td').text(data.remark);
  4227. $('#btn-att a').eq(3).show();
  4228. $('#btn-att a').eq(2).hide();
  4229. $('#btn-att a').eq(4).hide();
  4230. $('#btn-att a').eq(5).hide();
  4231. }, function () {
  4232. toastr.error('附件上传失败');
  4233. });
  4234. $('#change-att-btn').val('');
  4235. } else if (content === 'del') {
  4236. const data = {id: fid};
  4237. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  4238. // 删除到attData中
  4239. const att_index = attData.findIndex(function (item) {
  4240. return item.id === parseInt(fid);
  4241. });
  4242. attData.splice(att_index, 1);
  4243. // 重新生成List
  4244. if ($('#alllist-table tr').length === 1) {
  4245. getAllList(parseInt($('#currentPage').text()) - 1);
  4246. } else {
  4247. getAllList(parseInt($('#currentPage').text()));
  4248. }
  4249. getNodeList(node.id);
  4250. $('#showAttachment').hide();
  4251. $('#showAttachment').attr('file-id', '');
  4252. });
  4253. } else if (content === 'view') {
  4254. const data = {id: fid};
  4255. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  4256. const { filepath } = result
  4257. $('#load-file').attr('href', filepath);
  4258. $('#load-file')[0].click();
  4259. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  4260. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  4261. });
  4262. } else if (content === 'location') {
  4263. const att = attData.find(item => item.id === parseInt(fid));
  4264. if (Object.keys(att).length) {
  4265. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  4266. stagePosSpreadObj.loadCurPosData();
  4267. }
  4268. }
  4269. });
  4270. // 替换附件
  4271. $('#change-att-btn').on('change', function () {
  4272. const file = $('#change-att-btn')[0].files[0];
  4273. const name = file.name;
  4274. const filename = name.substring(0, name.lastIndexOf("."));
  4275. const fileext = name.substr(name.indexOf("."));
  4276. const filesize = file.size;
  4277. if (filesize > 30 * 1024 * 1024) {
  4278. toastr.error('文件大小过大!');
  4279. $('#change-att-btn').val('');
  4280. return false;
  4281. }
  4282. if (whiteList.indexOf(fileext) === -1) {
  4283. toastr.error('只能上传指定格式的附件!');
  4284. $('#change-att-btn').val('');
  4285. return false;
  4286. }
  4287. $('#edit-att .form-group').eq(0).find('input').val(filename);
  4288. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  4289. });
  4290. // 切换页数
  4291. $('.page-select').on('click', function () {
  4292. const totalPageNum = parseInt($('#totalPage').text());
  4293. const lastPageNum = parseInt($('#currentPage').text());
  4294. const status = $(this).attr('content');
  4295. if (status === 'pre' && lastPageNum > 1) {
  4296. getAllList(lastPageNum-1);
  4297. $('#showAttachment').hide();
  4298. $('#syfujian .check-all-file').prop('checked', false)
  4299. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4300. getAllList(lastPageNum+1);
  4301. $('#showAttachment').hide();
  4302. $('#syfujian .check-all-file').prop('checked', false)
  4303. }
  4304. });
  4305. // 批量下载
  4306. $('#bach-download').click(function() {
  4307. const fileIds = [];
  4308. const type = $(this).attr('type');
  4309. let node = ''
  4310. if (type === 'curr') {
  4311. node = '#nodelist-table .check-file:checked'
  4312. } else {
  4313. node = '#alllist-table .check-file:checked'
  4314. }
  4315. $(node).each(function() {
  4316. const fileId = $(this).attr('file-id');
  4317. fileId && fileIds.push(fileId);
  4318. });
  4319. if (fileIds.length) {
  4320. if (fileIds.length > 20) {
  4321. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  4322. }
  4323. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  4324. $(this).attr('disabled', "true")
  4325. const btn = $(this);
  4326. const fileArr = [];
  4327. for (const id of fileIds) {
  4328. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  4329. fileArr.push({
  4330. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  4331. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  4332. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  4333. });
  4334. }
  4335. const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
  4336. try {
  4337. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  4338. } catch (e) {
  4339. btn.removeAttr('disabled');
  4340. toastr.clear();
  4341. toastr.error('批量下载失败');
  4342. }
  4343. // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  4344. // toastr.clear()
  4345. // toastr.success('压缩文件成功')
  4346. // btn.removeAttr('disabled')
  4347. // const href = window.URL.createObjectURL(result)
  4348. // $('#zipDown').attr('href', href);
  4349. // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  4350. // $("#zipDown")[0].click();
  4351. // }, () => {
  4352. // btn.removeAttr('disabled')
  4353. // toastr.clear()
  4354. // toastr.error('批量下载失败')
  4355. // });
  4356. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  4357. // $('#zipDown').attr('href', url);
  4358. // $("#zipDown")[0].click();
  4359. }
  4360. });
  4361. // 监听附件check是否选中
  4362. $('.list-table').on('click', '.check-file', function() {
  4363. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  4364. const childs = $(this).parents('.list-table').children().length;
  4365. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  4366. if (checkedList.length === childs) {
  4367. checkBox.prop("checked", true);
  4368. } else {
  4369. checkBox.prop("checked", false);
  4370. }
  4371. });
  4372. $('.check-all-file').click(function() {
  4373. const isCheck = $(this).is(':checked');
  4374. $(this).parents('table').find('.list-table').each(function() {
  4375. $(this).find('input:checkbox').prop("checked", isCheck);
  4376. })
  4377. });
  4378. // 显示层次
  4379. (function (select, sheet) {
  4380. $(select).click(function () {
  4381. if (!sheet.zh_tree) return;
  4382. const tag = $(this).attr('tag');
  4383. const tree = sheet.zh_tree;
  4384. setTimeout(() => {
  4385. showWaitingView();
  4386. switch (tag) {
  4387. case "1":
  4388. case "2":
  4389. case "3":
  4390. case "4":
  4391. case "5":
  4392. tree.expandByLevel(parseInt(tag));
  4393. SpreadJsObj.refreshTreeRowVisible(sheet);
  4394. break;
  4395. case "last":
  4396. tree.expandByCustom(() => { return true; });
  4397. SpreadJsObj.refreshTreeRowVisible(sheet);
  4398. break;
  4399. case "leafXmj":
  4400. tree.expandToLeafXmj();
  4401. SpreadJsObj.refreshTreeRowVisible(sheet);
  4402. break;
  4403. case "curMeasure":
  4404. tree.expandByCustom(function (node) {
  4405. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  4406. if (node[field]) {
  4407. return true;
  4408. }
  4409. }
  4410. return false;
  4411. });
  4412. SpreadJsObj.refreshTreeRowVisible(sheet);
  4413. break;
  4414. }
  4415. closeWaitingView();
  4416. }, 100);
  4417. });
  4418. })('a[name=showLevel]', slSpread.getActiveSheet());
  4419. const stageCheckerSetting = {
  4420. ledgerTree: stageTree,
  4421. ledgerPos: stagePos,
  4422. checkList: checkList,
  4423. decimal: tenderInfo.decimal,
  4424. checkOption: checkOption,
  4425. };
  4426. if (!checkTzMeasureType()) {
  4427. stageCheckerSetting.checkOption.tp.fields.push(
  4428. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  4429. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  4430. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  4431. {qty: 'quantity', tp: 'total_price'},
  4432. );
  4433. }
  4434. $('#ledger-check2').click(() => {
  4435. ledgerCheck2(stageCheckerSetting).then(result => {
  4436. check2Viewing({
  4437. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  4438. randomWait: true,
  4439. prefix: 'check2-',
  4440. checks: result,
  4441. checkList: checkList,
  4442. });
  4443. });
  4444. });
  4445. const dataChecker = DataChecker({
  4446. checkUrl: window.location.pathname + '/check',
  4447. completeData: function (data) {
  4448. stagePos.updateDatas({pos: data.source.pos});
  4449. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  4450. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  4451. stagePosSpreadObj.loadCurPosData();
  4452. for (const e of data.error) {
  4453. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  4454. }
  4455. },
  4456. errorList: errorList,
  4457. });
  4458. $('[name=stage-start]').submit(function (e) {
  4459. if (checkAuditorFrom()) {
  4460. // 再检查多人协同确认情况
  4461. const list = stageTree.pwd.find(x => {return !x.confirm });
  4462. if(list) {
  4463. toastr.error('请检查多人协同确认情况再上报');
  4464. $('#hide-all').hide();
  4465. return false;
  4466. }
  4467. $(this).parent().parent().parent().modal('hide');
  4468. dataChecker.checkAndPost(this.action, {});
  4469. $('#hide-all').hide();
  4470. }
  4471. return false;
  4472. });
  4473. $('#audit-check0').submit(function (e) {
  4474. // 再检查多人协同确认情况
  4475. const list = stageTree.pwd.find(x => {return !x.confirm && checkUsed(stageTree, stagePos, x.node) });
  4476. if(list) {
  4477. toastr.error('请检查多人协同确认情况再审批通过');
  4478. $('#hide-all').hide();
  4479. return false;
  4480. }
  4481. const checkType = parseInt($('[name=checkType]').val());
  4482. const noUsed = stageTree.pwd.filter(x => {return !checkUsed(stageTree, stagePos, x.node) });
  4483. const data = {
  4484. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4485. noUsed: noUsed.map(x => { return x.id; }),
  4486. checkType,
  4487. };
  4488. $('#sp-done').modal('hide');
  4489. checkType && dataChecker.checkAndPost(this.action, data);
  4490. $('#hide-all').hide();
  4491. return false;
  4492. });
  4493. $('#audit-check1').submit(function (e) {
  4494. const checkType = parseInt($('[name=checkType]:checked').val());
  4495. const data = {
  4496. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4497. checkType,
  4498. };
  4499. if ($('#warning-text').length) $('#warning-text').remove()
  4500. if (!checkType && !$('#warning-text').length) {
  4501. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  4502. return false
  4503. }
  4504. $('#sp-back').modal('hide');
  4505. checkType && dataChecker.checkAndPost(this.action, data);
  4506. $('#hide-all').hide();
  4507. return false;
  4508. });
  4509. $('#exportExcel').click(function () {
  4510. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  4511. });
  4512. $('#cbr-check-all').click(function () {
  4513. if (this.checked) {
  4514. $('input', '#cbr-pos-list').attr('checked', 'checked');
  4515. } else {
  4516. $('input', '#cbr-pos-list').removeAttr('checked');
  4517. }
  4518. });
  4519. $('#cbr-ok').click(() => {
  4520. const ratio = parseInt($('#cbr-ratio').val());
  4521. if (!ratio) {
  4522. toastr.warning('请输入计量比例');
  4523. return;
  4524. } else if (ratio < 1) {
  4525. toastr.warning('计量比例不可小于1');
  4526. return;
  4527. } else if (ratio > 100) {
  4528. toastr.warning('计量比例不可大于100');
  4529. return;
  4530. }
  4531. const apply2sibling = $('#apply2sibling')[0].checked;
  4532. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  4533. if (posName.length === 0) {
  4534. toastr.warning('请勾选需要按计量比例的计量单元');
  4535. return;
  4536. }
  4537. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  4538. });
  4539. $('body').on('click', '[name=ledger-unlock]', function() {
  4540. $('#cooperation').modal('hide');
  4541. const lid = this.getAttribute('lid');
  4542. if (!lid) return;
  4543. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4544. if (!p) return;
  4545. $('#unlock-info').html(`${p.node.code} ${p.node.name} 解锁密码<b class="text-danger">*</b>`);
  4546. $('#unlock-pwd').val('').removeClass('is-invalid');
  4547. $('.invalid-feedback', '#unlock').hide();
  4548. $('.alert-warning', '#unlock').hide();
  4549. $('#unlock-ok').attr('lid', lid);
  4550. $('#unlock').modal('show');
  4551. });
  4552. $('#unlock-ok').click(function () {
  4553. const lid = this.getAttribute('lid');
  4554. if (!lid) return;
  4555. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4556. if (!p) return;
  4557. if (p.pwd === $('#unlock-pwd').val()) {
  4558. const refresh = stageTree.lockNode(p, false);
  4559. // 修改线上
  4560. SpreadJsObj.reloadRowsReadonly(slSpread.getActiveSheet(), refresh);
  4561. stagePosSpreadObj.loadCurPosData();
  4562. $('#unlock').modal('hide');
  4563. reloadCooperationHtml();
  4564. } else {
  4565. $('#unlock-pwd').addClass('is-invalid');
  4566. $('.invalid-feedback', '#unlock').show();
  4567. $('.alert-warning', '#unlock').show();
  4568. }
  4569. });
  4570. $('#cooperationSelect').change(function () {
  4571. reloadCooperationHtml();
  4572. });
  4573. // 确认
  4574. $('body').on('click', '[name=ledger-confirm]', function() {
  4575. const lid = this.getAttribute('lid');
  4576. if (!lid) return;
  4577. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4578. if (!p) return;
  4579. // 修改线上
  4580. postData(window.location.pathname + '/save/cooperation', { type: 'save-confirm', postData: { ledger_id: lid } }, function (result) {
  4581. p.confirm = true;
  4582. p.confirm_time = new Date();
  4583. stageTree.confirmList = result.cooperationConfirm;
  4584. reloadCooperationHtml();
  4585. });
  4586. });
  4587. // 确认
  4588. $('body').on('click', '[name=ledger-unconfirm]', function() {
  4589. const lid = this.getAttribute('lid');
  4590. if (!lid) return;
  4591. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4592. if (!p) return;
  4593. // 修改线上
  4594. postData(window.location.pathname + '/save/cooperation', { type: 'del-confirm', postData: { ledger_id: lid } }, function (result) {
  4595. p.confirm = false;
  4596. p.confirm_time = null;
  4597. stageTree.confirmList = result.cooperationConfirm;
  4598. reloadCooperationHtml();
  4599. });
  4600. });
  4601. // 收方单生成
  4602. $('#setshoufang').click(function () {
  4603. const lid = $('#shoufang-lid').val();
  4604. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  4605. // 修改线上
  4606. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  4607. // 收方单tab打开并显示在最新
  4608. if (!$('#shoufang-tab').hasClass('active')) {
  4609. $('#shoufang-tab').click();
  4610. }
  4611. const data = makeOneShouFang(result);
  4612. data.filenum = 0;
  4613. sfData = _.concat(data, sfData);
  4614. getShouFangList();
  4615. });
  4616. });
  4617. $('body').on('click', '.del-shoufang', function () {
  4618. const id = $(this).attr('data-id');
  4619. $('#del-shoufang-id').val(id);
  4620. const name = $(this).parents('tr').children('td').eq(0).text();
  4621. const ledger_code = name.split(' / ')[0];
  4622. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  4623. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  4624. if (pos_name) {
  4625. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  4626. } else {
  4627. $('#del-shoufang-pos').text('').hide();
  4628. }
  4629. });
  4630. // 收方单删除
  4631. $('#delshoufang').click(function () {
  4632. const sfid = $('#del-shoufang-id').val();
  4633. // 修改线上
  4634. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  4635. // 删除到sfData中
  4636. const att_index = sfData.findIndex(function (item) {
  4637. return item.id === parseInt(sfid);
  4638. });
  4639. sfData.splice(att_index, 1);
  4640. // 重新生成List
  4641. if ($('#shoufang-table tr').length === 1) {
  4642. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  4643. } else {
  4644. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  4645. }
  4646. $('#shoufangdelete').modal('hide');
  4647. });
  4648. });
  4649. // 切换页数
  4650. $('.shoufang-page-select').on('click', function () {
  4651. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  4652. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  4653. const status = $(this).attr('content');
  4654. if (status === 'pre' && lastPageNum > 1) {
  4655. getShouFangList(lastPageNum-1);
  4656. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4657. getShouFangList(lastPageNum+1);
  4658. }
  4659. });
  4660. // 获取单个收方单附件列表
  4661. $('body').on('click', '.show-shoufang-att', function () {
  4662. const id = parseInt($(this).attr('data-id'));
  4663. let html = '';
  4664. $('#shoufang-flie-list').html(html);
  4665. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  4666. for (const att of result) {
  4667. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  4668. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  4669. `<a href="${att.filepath}" target="_blank"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a>` + makeViewHtml(att.viewpath) + makeDelHtml(att.id, att.extra_upload) +`</td></tr>`;
  4670. }
  4671. $('#shoufang-flie-list').html(html);
  4672. $('[data-toggle="tooltip"]').tooltip()
  4673. });
  4674. function makeViewHtml(viewpath) {
  4675. return viewpath ? `<a href="${viewpath}" target="_blank" class="ml-1"><i data-toggle="tooltip" data-placement="left" data-original-title="预览" class="fa fa-eye"></i></a>` : '';
  4676. }
  4677. function makeDelHtml(fid, extra_upload) {
  4678. return sfAttDelPower &&
  4679. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4680. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
  4681. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4682. }
  4683. });
  4684. function makeEditHtml(fid, filename, fileext, extra_upload) {
  4685. return sfAttDelPower &&
  4686. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4687. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  4688. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  4689. }
  4690. // 修改收方单附件文件名
  4691. $('body').on('click', '.edit-shoufang-att', function () {
  4692. $(this).children('i').tooltip('hide');
  4693. const fid = $(this).data('id');
  4694. const filename = $(this).data('filename');
  4695. const fileext = $(this).data('fileext');
  4696. const html = `<div class="input-group input-group-sm">
  4697. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  4698. <div class="input-group-append" id="button-${fid}">
  4699. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  4700. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  4701. </div>
  4702. </div>`;
  4703. $(this).parents('td').html(html);
  4704. });
  4705. // 确认修改文件名
  4706. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  4707. const validText = $.trim($(this).parents('td').find('input').val());
  4708. const orgValue = $.trim($(this).data('filename'));
  4709. const fileext = $(this).data('fileext');
  4710. const fid = $(this).data('fid');
  4711. if (!validText) {
  4712. toastr.error('文件名不能为空');
  4713. return;
  4714. }
  4715. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  4716. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  4717. toastr.error('文件名中不能包含.字符和空格');
  4718. return;
  4719. }
  4720. if(validText == orgValue) {
  4721. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  4722. $(this).parents('td').html(html);
  4723. return;
  4724. }
  4725. const data = {
  4726. id: fid,
  4727. filename: validText,
  4728. };
  4729. const _self = $(this);
  4730. postData('/wap/shoufang/editfile', data, function (result) {
  4731. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  4732. _self.parents('td').html(html);
  4733. });
  4734. });
  4735. // 取消修改文件名
  4736. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  4737. const fid = $(this).data('fid');
  4738. const filename = $(this).data('filename');
  4739. const fileext = $(this).data('fileext');
  4740. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  4741. $(this).parents('td').html(html);
  4742. });
  4743. // 删除收方单附件
  4744. $('body').on('click', '.del-shoufang-att', function () {
  4745. const id = $(this).data('id');
  4746. const _self = $(this);
  4747. const data = { id };
  4748. const sfid = $(this).data('sfid');
  4749. postData('/wap/shoufang/delfile', data, function (result) {
  4750. _self.parents('tr').remove();
  4751. // 附件个数更新
  4752. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  4753. const sfInfo = _.find(sfData, { id: sfid });
  4754. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  4755. });
  4756. });
  4757. // 定位到对应的清单或计量单元
  4758. $('body').on('click', '.show-shoufang-node', function () {
  4759. const id = parseInt($(this).attr('data-id'));
  4760. const sfInfo = _.find(sfData, { id });
  4761. if (sfInfo) {
  4762. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4763. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  4764. stagePosSpreadObj.loadCurPosData();
  4765. if (sfInfo.pid) {
  4766. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  4767. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  4768. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  4769. }
  4770. }
  4771. });
  4772. // 定位到对应的清单或计量单元
  4773. $('body').on('click', '.show-shoufang-report', function () {
  4774. const id = parseInt($(this).attr('data-id'));
  4775. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  4776. sessionStorage.qrCodePath = qrCodePath;
  4777. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  4778. sessionStorage.req_params = JSON.stringify(req_params);
  4779. sessionStorage.rpt_name = rpt_name;
  4780. window.open('/individualReport/A4');
  4781. });
  4782. $('#importExcel').click(() => {
  4783. importExcel.doImport({
  4784. template: {
  4785. hint: '计量台账',
  4786. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/导入计量台账Excel格式.xlsx',
  4787. },
  4788. callback: function (sheet) {
  4789. postDataCompress(window.location.pathname + '/importStageSheet', {sheet}, function (result) {
  4790. window.location.reload();
  4791. }, null);
  4792. }
  4793. });
  4794. })
  4795. });
  4796. function makeOneShouFang(sf) {
  4797. const lData = _.find(ledgerData, { id: sf.lid });
  4798. sf.name = lData.b_code;
  4799. if (sf.pid) {
  4800. const pData = _.find(posData, { id: sf.pid });
  4801. sf.name = lData.b_code + ' / ' + pData.name;
  4802. }
  4803. return sf;
  4804. }
  4805. function makeShouFang() {
  4806. for (const sf of sfData) {
  4807. makeOneShouFang(sf);
  4808. }
  4809. getShouFangList();
  4810. }
  4811. // 生成收方单列表
  4812. function getShouFangList(currPageNum = 1) {
  4813. // 每页最多几个附件
  4814. const pageCount = 20;
  4815. // 附件总数
  4816. const total = sfData.length;
  4817. // 总页数
  4818. const pageNum = Math.ceil(total/pageCount);
  4819. $('#shoufang-totalPage').text(pageNum);
  4820. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  4821. // 当前页附件内容
  4822. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  4823. let html = '';
  4824. for(const att of currPageAttData) {
  4825. html += '<tr><td>' + att.name + '</td>' +
  4826. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  4827. '<td width="100">' +
  4828. '<a href="javascript:void(0);" data-id="'+ att.id +'" class="show-shoufang-node mr-1" data-toggle="tooltip" data-placement="left" data-original-title="定位"><i class="fa fa-crosshairs"></i></a> ' +
  4829. '<a href="javascript:void(0);" data-id="'+ att.id +'" class="show-shoufang-report mr-1"><i data-toggle="tooltip" data-placement="left" data-original-title="预览" class="fa fa-eye"></i></a> ' +
  4830. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  4831. makeDelHtml(att.id, att.extra_upload) +
  4832. '</td></tr>';
  4833. }
  4834. function makeDelHtml(id, extra_upload) {
  4835. return cur_uid === stage.user_id &&
  4836. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4837. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  4838. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4839. }
  4840. $('#shoufang-table').html(html);
  4841. $('[data-toggle="tooltip"]').tooltip();
  4842. }
  4843. function makeReportData(sfid) {
  4844. const sfInfo = _.find(sfData, { id: sfid });
  4845. const ledger_code = sfInfo.name.split(' / ')[0];
  4846. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  4847. const replace_key_params = {
  4848. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  4849. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  4850. 'KEY_合同段': tenderInfo.deal_info.dealName,
  4851. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  4852. 'KEY_编号': '',
  4853. 'KEY_设计工程数量': 0,
  4854. };
  4855. // if (sfInfo.pid) {
  4856. // const pData = _.find(posData, { id: sfInfo.pid });
  4857. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  4858. // } else {
  4859. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4860. // }
  4861. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  4862. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  4863. const req_params = {
  4864. rpt_tpl_id: window.location.host === '127.0.0.1:7002' || window.location.host === 'jlqa.smartcost.com.cn:7002' ? 1784 : (window.location.host === 'jluat.smartcost.com.cn' ? 315 : 2138), // 1784(qa的,外网是2138)
  4865. pageSize: 'A4',
  4866. project_id: tender.project_id,
  4867. tender_id: tender.id,
  4868. stage_id: stage.id,
  4869. };
  4870. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  4871. const qrCodePath = sfInfo.qrcode;
  4872. return [qrCodePath, replace_key_params, req_params, rpt_name];
  4873. }