stage.js 234 KB

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