stage.js 230 KB

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