stage.js 229 KB

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