stage.js 229 KB

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