stage.js 231 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783
  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. result.ledgerData && console.log('ledger: ' + result.ledgerData.length);
  1971. result.posData && console.log('pos: ' + result.posData.length);
  1972. result.detailData && console.log('detail: ' + result.detailData.length);
  1973. result.detailAtt && console.log('detailAtt: ' + result.detailAtt.length);
  1974. result.changeData && console.log('change: ' + result.changeData.length);
  1975. result.tags && console.log('tag: ' + result.tags.length);
  1976. result.cooperation && console.log('cooperation: ' + result.cooperation.length);
  1977. // 加载树结构
  1978. console.time('loadLedger');
  1979. stageTree.loadDatas(result.ledgerData);
  1980. console.timeEnd('loadLedger');
  1981. checkShowLast(result.ledgerData.length);
  1982. console.time('calcLedger');
  1983. treeCalc.calculateAll(stageTree);
  1984. console.timeEnd('calcLedger');
  1985. // 加载解锁相关
  1986. console.time('loadCooperation');
  1987. if (result.cooperation) {
  1988. stageTree.loadPwd(result.cooperation, 'bills-p-' + userID + '-' + window.location.pathname.split('/')[2], result.cooperationConfirm);
  1989. $('#cooperationCount').html(stageTree.pwd.length || '');
  1990. if (stageTree.pwd.length > 0) $('#cooperationCount').parent().show();
  1991. setCooperationSelectHtml();
  1992. reloadCooperationHtml();
  1993. }
  1994. console.timeEnd('loadCooperation');
  1995. console.time('loadTag');
  1996. for (const t of result.tags) {
  1997. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  1998. }
  1999. billsTag.loadDatas(result.tags);
  2000. console.timeEnd('loadTag');
  2001. // 加载部位明细
  2002. console.time('loadPos');
  2003. stagePos.loadDatas(result.posData);
  2004. console.timeEnd('loadPos');
  2005. stagePos.calculateAll();
  2006. console.time('showLedger');
  2007. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  2008. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  2009. console.timeEnd('showLedger');
  2010. console.time('showPos');
  2011. stagePosSpreadObj.loadCurPosData();
  2012. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  2013. console.timeEnd('showPos');
  2014. // 加载中间计量
  2015. console.time('loadIm');
  2016. stageIm.init(stage, imType, tenderInfo.decimal);
  2017. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData, result.detailAtt);
  2018. console.timeEnd('loadIm');
  2019. errorList.loadHisErrorData();
  2020. checkList.loadHisCheckData();
  2021. sumLoadMiss.loadHisMissData();
  2022. // 收方单赋值
  2023. ledgerData = result.ledgerData;
  2024. posData = result.posData;
  2025. makeShouFang();
  2026. }, null, true);
  2027. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2028. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2029. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2030. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2031. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2032. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2033. if (!readOnly) {
  2034. $('#pos-expr').bind('change onblur', function () {
  2035. if (this.readOnly) return;
  2036. const expr = $(this);
  2037. const posSheet = spSpread.getActiveSheet();
  2038. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2039. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2040. if (!select) return;
  2041. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2042. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2043. const data = {pid: select.id, lid: select.lid};
  2044. const exprInfo = getExprInfo(field);
  2045. if (newValue !== '') {
  2046. const num = _.toNumber(newValue);
  2047. if (num) {
  2048. data[field] = num;
  2049. if (exprInfo) data[exprInfo.expr] = '';
  2050. } else {
  2051. try {
  2052. data[field] = math.evaluate(transExpr(newValue));
  2053. if (exprInfo) data[exprInfo.expr] = newValue;
  2054. } catch (err) {
  2055. toastr.error('输入的表达式非法');
  2056. return;
  2057. }
  2058. }
  2059. } else {
  2060. data[field] = null;
  2061. if (exprInfo) data[exprInfo.expr] = '';
  2062. }
  2063. // 提交数据到服务器
  2064. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2065. if (result.pos) {
  2066. stagePos.updateDatas(result.pos.pos);
  2067. stagePos.loadCurStageData(result.pos.curStageData);
  2068. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2069. }
  2070. const refreshData = stageTree.loadPostStageData(result.ledger);
  2071. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2072. if (detail) {
  2073. detail.loadStagePosUpdateData(result, refreshData);
  2074. } else {
  2075. stageIm.loadUpdatePosData(result, refreshData);
  2076. }
  2077. });
  2078. });
  2079. }
  2080. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2081. $.contextMenu({
  2082. selector: '#stage-pos',
  2083. build: function ($trigger, e) {
  2084. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2085. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2086. },
  2087. items: {
  2088. 'del': {
  2089. name: '删除',
  2090. icon: 'fa-remove',
  2091. visible: function (key, opt) {
  2092. return !checkTzMeasureType();
  2093. },
  2094. disabled: function (key, opt) {
  2095. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2096. if (!node || node.lock) return true;
  2097. const sheet = spSpread.getActiveSheet();
  2098. if (sheet.zh_data && !readOnly) {
  2099. const selection = sheet.getSelections();
  2100. if (selection && selection[0]) {
  2101. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2102. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2103. const posData = sheet.zh_data[selection[0].row + iRow];
  2104. if (posData) {
  2105. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2106. valid = true;
  2107. break;
  2108. }
  2109. } else {
  2110. valid = true;
  2111. break;
  2112. }
  2113. }
  2114. return valid;
  2115. } else {
  2116. return true;
  2117. }
  2118. } else {
  2119. return true;
  2120. }
  2121. },
  2122. callback: function (key, opt) {
  2123. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2124. }
  2125. },
  2126. 'merge-peg': {
  2127. name: '合并起讫桩号',
  2128. visible: function (key, opt) {
  2129. return !checkTzMeasureType();
  2130. },
  2131. disabled: function (key, opt) {
  2132. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2133. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2134. },
  2135. callback: function (key, opt) {
  2136. mergePeg.show();
  2137. }
  2138. },
  2139. 'calcByRatio': {
  2140. name: '按比例计量',
  2141. visible: function (key, opt) {
  2142. const data = spSpread.getActiveSheet().zh_data;
  2143. return data && data.length > 0;
  2144. },
  2145. disabled: function (key, opt) {
  2146. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2147. return node.lock;
  2148. },
  2149. callback: function (key, opt) {
  2150. $('#cbr-ratio').val('');
  2151. $('#apply2sibling')[0].checked = false;
  2152. $('#cbr-check-all')[0].checked = false;
  2153. const html = [];
  2154. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2155. html.push('<tr>');
  2156. html.push('<td>', i+1, '</td>');
  2157. html.push('<td>', p.name, '</td>');
  2158. html.push('<td>', p.quantity, '</td>');
  2159. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2160. html.push('</tr>');
  2161. }
  2162. $('#cbr-pos-list').html(html.join(''));
  2163. $('#calc-by-ratio').modal('show');
  2164. }
  2165. },
  2166. 'remainCur': {
  2167. name: '填剩余量(选中行)',
  2168. disabled: function (key, opt) {
  2169. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2170. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2171. return readOnly || node.lock || !curPos;
  2172. },
  2173. callback: function (key, opt) {
  2174. const sheet = spSpread.getActiveSheet();
  2175. const sels = sheet.getSelections();
  2176. if (!sels || !sels[0]) return;
  2177. const data = { updateType: 'update', updateData: [] };
  2178. for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
  2179. const curRow = iRow + sels[0].row;
  2180. const curPos = SpreadJsObj.getRowObject(sheet, curRow);
  2181. if (!curPos) continue;
  2182. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2183. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2184. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty });
  2185. }
  2186. if (data.updateData.length > 0) {
  2187. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2188. if (result.pos) {
  2189. stagePos.updateDatas(result.pos.pos);
  2190. stagePos.loadCurStageData(result.pos.curStageData);
  2191. }
  2192. const nodes = stageTree.loadPostStageData(result.ledger);
  2193. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2194. stagePosSpreadObj.loadCurPosData();
  2195. if (detail) {
  2196. detail.loadStagePosUpdateData(result, nodes);
  2197. } else {
  2198. stageIm.loadUpdatePosData(result, nodes);
  2199. }
  2200. });
  2201. }
  2202. },
  2203. },
  2204. 'remainAll': {
  2205. name: '填剩余量(全部行)',
  2206. disabled: function (key, opt) {
  2207. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2208. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2209. return readOnly || node.lock || !curPos;
  2210. },
  2211. callback: function (key, opt) {
  2212. const sheet = spSpread.getActiveSheet();
  2213. if (!sheet.zh_data || sheet.zh_data.length === 0) return;
  2214. const data = { updateType: 'update', updateData: [] };
  2215. for (const curPos of sheet.zh_data) {
  2216. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2217. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2218. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty });
  2219. }
  2220. if (data.updateData.length > 0) {
  2221. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2222. if (result.pos) {
  2223. stagePos.updateDatas(result.pos.pos);
  2224. stagePos.loadCurStageData(result.pos.curStageData);
  2225. }
  2226. const nodes = stageTree.loadPostStageData(result.ledger);
  2227. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2228. stagePosSpreadObj.loadCurPosData();
  2229. if (detail) {
  2230. detail.loadStagePosUpdateData(result, nodes);
  2231. } else {
  2232. stageIm.loadUpdatePosData(result, nodes);
  2233. }
  2234. });
  2235. }
  2236. },
  2237. },
  2238. 'shoufangdan': {
  2239. name: '生成收方单',
  2240. visible: function(key, opt) {
  2241. if (cur_uid === stage.user_id) return true;
  2242. },
  2243. disabled: function (key, opt) {
  2244. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2245. if (!node || cur_uid !== stage.user_id) return true;
  2246. },
  2247. callback: function (key, opt) {
  2248. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2249. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2250. $('#shoufang-lid').val(node.lid);
  2251. $('#shoufang-pid').val(node.id);
  2252. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2253. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2254. $('#addshoufang').modal('show');
  2255. }
  2256. }
  2257. }
  2258. });
  2259. $.subMenu({
  2260. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2261. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2262. key: 'menu.1.0.0',
  2263. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2264. callback: function (info) {
  2265. if (info.mini) {
  2266. $('.panel-title').addClass('fluid');
  2267. $('#sub-menu').removeClass('panel-sidebar');
  2268. } else {
  2269. $('.panel-title').removeClass('fluid');
  2270. $('#sub-menu').addClass('panel-sidebar');
  2271. }
  2272. autoFlashHeight();
  2273. slSpread.refresh();
  2274. spSpread.refresh();
  2275. if (searchLedger) searchLedger.spread.refresh();
  2276. if (detail) detail.spread.refresh();
  2277. if (checkedChanges) checkedChanges.refresh();
  2278. if (errorList && errorList.spread) errorList.spread.refresh();
  2279. if (checkList) checkList.spread.refresh();
  2280. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2281. }
  2282. });
  2283. $('#row-view').on('show.bs.modal', function () {
  2284. const html = [], customDisplay = customColDisplay();
  2285. for (const cd of customDisplay) {
  2286. html.push('<tr>');
  2287. html.push('<td>', cd.title, '</td>');
  2288. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2289. html.push('</tr>');
  2290. }
  2291. $('#row-view-list').html(html.join(''));
  2292. });
  2293. $('#row-view-ok').click(function () {
  2294. const customDisplay = customColDisplay();
  2295. const cvl = $('#row-view-list').children();
  2296. for (const cv of cvl) {
  2297. const title = $(cv).children()[0].innerHTML;
  2298. const check = $('input', cv)[0].checked;
  2299. const cd = customDisplay.find(function (c) {
  2300. return c.title === title;
  2301. });
  2302. cd.visible = check;
  2303. }
  2304. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2305. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2306. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2307. $('#row-view').modal('hide');
  2308. });
  2309. const posSearch = (function () {
  2310. let resultArr = [];
  2311. const search = function () {
  2312. resultArr = [];
  2313. const keyword = $('#pos-search-keyword').val();
  2314. const checkOver = $('#pos-over-search')[0].checked;
  2315. const checkEmpty = $('#pos-empty-search')[0].checked;
  2316. const sortData = spSpread.getActiveSheet().zh_data;
  2317. if (checkOver || checkEmpty) {
  2318. if (sortData) {
  2319. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2320. const sd = sortData[i];
  2321. let match = false;
  2322. if (checkOver) {
  2323. if (sd.end_gather_qty) {
  2324. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2325. }
  2326. }
  2327. if (checkEmpty) {
  2328. if (sd.quantity) {
  2329. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2330. }
  2331. }
  2332. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2333. if (match) {
  2334. resultArr.push({index: i, data: sd});
  2335. }
  2336. }
  2337. }
  2338. } else if (keyword && keyword !== '') {
  2339. if (sortData) {
  2340. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2341. const sd = sortData[i];
  2342. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2343. resultArr.push({index: i, data: sd});
  2344. }
  2345. }
  2346. }
  2347. }
  2348. $('#pos-search-result').html('结果:' + resultArr.length);
  2349. };
  2350. const searchAndLocate = function () {
  2351. search();
  2352. if (resultArr.length > 0) {
  2353. const sheet = spSpread.getActiveSheet();
  2354. const sel = sheet.getSelections()[0];
  2355. const curRow = sel ? sel.row : 0;
  2356. const pos = resultArr[0];
  2357. if (pos.index !== curRow) {
  2358. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2359. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2360. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2361. }
  2362. }
  2363. };
  2364. const locateNext = function () {
  2365. if (resultArr.length > 0) {
  2366. const sheet = spSpread.getActiveSheet();
  2367. const sel = sheet.getSelections()[0];
  2368. const curRow = sel ? sel.row : 0;
  2369. let next = _.find(resultArr, function (d) {
  2370. return d.index > curRow;
  2371. });
  2372. if (!next) next = resultArr[0];
  2373. if (next.index !== curRow) {
  2374. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2375. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2376. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2377. }
  2378. }
  2379. };
  2380. const locatePre = function () {
  2381. if (resultArr.length > 0) {
  2382. const sheet = spSpread.getActiveSheet();
  2383. const sel = sheet.getSelections()[0];
  2384. const curRow = sel ? sel.row : 0;
  2385. let next = _.findLast(resultArr, function (d) {
  2386. return d.index < curRow;
  2387. });
  2388. if (!next) next = resultArr[resultArr.length - 1];
  2389. if (next.index !== curRow) {
  2390. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2391. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2392. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2393. }
  2394. }
  2395. };
  2396. return {search, searchAndLocate, locateNext, locatePre};
  2397. })();
  2398. $('#pos-search-keyword').bind('keydown', function(e){
  2399. if (e.keyCode == 13) posSearch.searchAndLocate();
  2400. });
  2401. $('#pos-empty-search').click(function () {
  2402. if (this.checked) {
  2403. $('[for=' + this.id +']').addClass('text-warning');
  2404. } else {
  2405. $('[for=' + this.id +']').removeClass('text-warning');
  2406. }
  2407. if (this.checked) {
  2408. if ($('#pos-over-search')[0].checked) {
  2409. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2410. } else {
  2411. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2412. }
  2413. } else {
  2414. if ($('#pos-over-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-over-search').click(function () {
  2423. if (this.checked) {
  2424. $('[for=' + this.id +']').addClass('text-danger');
  2425. } else {
  2426. $('[for=' + this.id +']').removeClass('text-danger');
  2427. }
  2428. if (this.checked) {
  2429. if ($('#pos-empty-search')[0].checked) {
  2430. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2431. } else {
  2432. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2433. }
  2434. } else {
  2435. if ($('#pos-empty-search')[0].checked) {
  2436. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2437. } else {
  2438. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2439. }
  2440. }
  2441. posSearch.searchAndLocate();
  2442. });
  2443. $('#pos-search-next').click(() => {posSearch.locateNext()});
  2444. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  2445. $.divResizer({
  2446. select: '#right-spr',
  2447. callback: function () {
  2448. slSpread.refresh();
  2449. spSpread.refresh();
  2450. if (searchLedger) {
  2451. searchLedger.spread.refresh();
  2452. }
  2453. if (detail) {
  2454. detail.spread.refresh();
  2455. }
  2456. if (checkedChanges) checkedChanges.refresh();
  2457. if (errorList && errorList.spread) errorList.spread.refresh();
  2458. if (checkList) checkList.spread.refresh();
  2459. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2460. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2461. }
  2462. });
  2463. // 中间计量加载上下窗口resizer
  2464. $.divResizer({
  2465. select: '#zhongjian-spr',
  2466. callback: function () {
  2467. if (detail) {
  2468. detail.spread.refresh();
  2469. }
  2470. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2471. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2472. }
  2473. });
  2474. // 附件加载上下窗口resizer
  2475. $.divResizer({
  2476. select: '#file-spr',
  2477. callback: function () {
  2478. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2479. }
  2480. });
  2481. // 变更令加载上下窗口resizer
  2482. $.divResizer({
  2483. select: '#change-spr',
  2484. callback: function () {
  2485. if (checkedChanges) checkedChanges.refresh();
  2486. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2487. }
  2488. });
  2489. class Detail {
  2490. constructor (obj) {
  2491. const self = this;
  2492. this.spreadSetting = {
  2493. cols: [
  2494. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2495. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2496. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  2497. {
  2498. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  2499. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  2500. },
  2501. {
  2502. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  2503. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  2504. return data.attachment ? data.attachment.length : 0;
  2505. }
  2506. },
  2507. ],
  2508. headRows: 1,
  2509. emptyRows: 0,
  2510. headRowHeight: [32],
  2511. headColWidth: [30],
  2512. defaultRowHeight: 21,
  2513. headerFont: '12px 微软雅黑',
  2514. font: '12px 微软雅黑',
  2515. readOnly: readOnly,
  2516. selectedBackColor: '#fffacd',
  2517. imageClick: function (data) {
  2518. self.makeAttTable(data);
  2519. $('#im-file').modal('show');
  2520. }
  2521. };
  2522. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  2523. this.sheet = this.spread.getActiveSheet();
  2524. this.spread.options.allowUserDragFill = true;
  2525. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  2526. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2527. this.detailObj = {
  2528. selectionChanged: function (e, info) {
  2529. self.reLoadDetailData();
  2530. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  2531. self.loadLocateInfo();
  2532. }
  2533. },
  2534. editEnded: function(e, info) {
  2535. if (info.sheet.zh_setting) {
  2536. const col = info.sheet.zh_setting.cols[info.col];
  2537. if (col.field !== 'doc_code') {
  2538. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2539. return;
  2540. }
  2541. const data = SpreadJsObj.getSelectObject(info.sheet);
  2542. if (data) {
  2543. const updateData = {lid: data.lid, pid: data.pid};
  2544. if (data.uuid) {
  2545. updateData.uuid = data.uuid;
  2546. } else {
  2547. updateData.code = data.code;
  2548. updateData.name = data.name;
  2549. updateData.unit = data.unit;
  2550. updateData.unit_price = data.unit_price;
  2551. updateData.pid = data.pid;
  2552. updateData.pos_name = data.pos_name;
  2553. updateData.im_type = data.im_type;
  2554. }
  2555. if (data.custom_define.indexOf('doc_code') === -1) {
  2556. updateData.custom_define = data.custom_define;
  2557. updateData.custom_define.push('doc_code');
  2558. updateData.custom_define = updateData.custom_define.join(',');
  2559. }
  2560. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  2561. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2562. stageIm.loadUpdateDetailData(result);
  2563. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2564. }, function () {
  2565. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2566. });
  2567. } else {
  2568. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2569. }
  2570. }
  2571. },
  2572. clipboardPasted: function (e, info) {
  2573. if (info.sheet.zh_setting && info.sheet.zh_data) {
  2574. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  2575. if (info.cellRange.colCount > 1) {
  2576. toastr.warning('请勿同时复制粘贴多列数据');
  2577. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2578. return;
  2579. }
  2580. if (col.field !== 'doc_code') {
  2581. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2582. return;
  2583. }
  2584. const datas = [];
  2585. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2586. const curRow = info.cellRange.row + iRow;
  2587. const data = info.sheet.zh_data[curRow];
  2588. if (data) {
  2589. const updateData = {lid: data.lid, pid: data.pid};
  2590. if (data.uuid) {
  2591. updateData.uuid = data.uuid;
  2592. } else {
  2593. updateData.code = data.code;
  2594. updateData.name = data.name;
  2595. updateData.unit = data.unit;
  2596. updateData.unit_price = data.unit_price;
  2597. updateData.pid = data.pid;
  2598. updateData.pos_name = data.pos_name;
  2599. updateData.im_type = data.im_type;
  2600. }
  2601. if (data.custom_define.indexOf('doc_code') === -1) {
  2602. updateData.custom_define = data.custom_define;
  2603. updateData.custom_define.push('doc_code');
  2604. updateData.custom_define = updateData.custom_define.join(',');
  2605. }
  2606. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  2607. datas.push(updateData);
  2608. }
  2609. }
  2610. if (datas.length > 0) {
  2611. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2612. stageIm.loadUpdateDetailData(result);
  2613. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2614. }, function () {
  2615. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2616. })
  2617. }
  2618. }
  2619. },
  2620. deletePress: function (sheet) {
  2621. if (sheet.zh_setting) {
  2622. const datas = [];
  2623. const sel = sheet.getSelections()[0];
  2624. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2625. const col = sheet.zh_setting.cols[iCol];
  2626. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2627. const data = sheet.zh_data[iRow];
  2628. if (col.field === 'doc_code') {
  2629. const updateData = {lid: data.lid};
  2630. if (data.uuid) {
  2631. updateData.uuid = data.uuid;
  2632. updateData.doc_code = '';
  2633. datas.push(updateData);
  2634. }
  2635. }
  2636. }
  2637. }
  2638. if (datas.length > 0) {
  2639. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2640. stageIm.loadUpdateDetailData(result);
  2641. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2642. }, function () {
  2643. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2644. });
  2645. }
  2646. }
  2647. },
  2648. dragFillBlock: function (e, info) {
  2649. info.cancel = true;
  2650. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2651. const sel = info.sheet.getSelections()[0];
  2652. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2653. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2654. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2655. if (text === '') return;
  2656. const regRst = /(\d+)$/g.exec(text), datas = [];
  2657. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2658. const curRow = info.fillRange.row + iRow;
  2659. const data = info.sheet.zh_data[curRow];
  2660. if (data) {
  2661. const updateData = {lid: data.lid};
  2662. if (data.uuid) {
  2663. updateData.uuid = data.uuid;
  2664. } else {
  2665. updateData.code = data.code;
  2666. updateData.name = data.name;
  2667. updateData.unit = data.unit;
  2668. updateData.unit_price = data.unit_price;
  2669. updateData.pid = data.pid;
  2670. updateData.pos_name = data.pos_name;
  2671. updateData.im_type = data.im_type;
  2672. }
  2673. if (regRst) {
  2674. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2675. } else {
  2676. updateData.doc_code = text.replace('\n', '');
  2677. }
  2678. if (data.custom_define.indexOf('doc_code') === -1) {
  2679. updateData.custom_define = data.custom_define;
  2680. updateData.custom_define.push('doc_code');
  2681. updateData.custom_define = updateData.custom_define.join(',');
  2682. }
  2683. datas.push(updateData);
  2684. }
  2685. }
  2686. if (datas.length > 0) {
  2687. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2688. stageIm.loadUpdateDetailData(result);
  2689. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2690. }, function () {
  2691. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2692. })
  2693. }
  2694. },
  2695. };
  2696. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2697. if (!readOnly) {
  2698. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2699. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2700. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2701. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2702. }
  2703. this._initImTypeSetRela();
  2704. this._initModifyDetail();
  2705. this._initLocateRela();
  2706. this._initAttRela();
  2707. // 草图相关
  2708. this._initImageRela();
  2709. this.reBuildImData();
  2710. }
  2711. makeAttTable (data) {
  2712. let html = [];
  2713. if (data.attachment) {
  2714. for (const att of data.attachment) {
  2715. const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked))
  2716. ? '<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>'
  2717. : '';
  2718. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  2719. 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>';
  2720. html.push('<tr><td style="width: 200px">' + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
  2721. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  2722. }
  2723. }
  2724. $('#im-attList').html(html.join(''));
  2725. }
  2726. _initAttRela() {
  2727. // 上传附件
  2728. const self = this;
  2729. $('#upload-im-file').change(function () {
  2730. const files = this.files;
  2731. const sels = self.sheet.getSelections();
  2732. const select = SpreadJsObj.getSelectObject(self.sheet);
  2733. if (!select) return;
  2734. const formData = new FormData();
  2735. const baseInfo = {};
  2736. if (select.att_uuid) {
  2737. baseInfo.uuid = select.att_uuid;
  2738. } else {
  2739. baseInfo.im_type = select.im_type;
  2740. baseInfo.lid = select.lid;
  2741. baseInfo.pid = select.pid;
  2742. baseInfo.code = select.code;
  2743. baseInfo.name = select.name;
  2744. baseInfo.unit = select.unit;
  2745. baseInfo.unit_price = select.unit_price;
  2746. baseInfo.pos_name = select.pos_name;
  2747. }
  2748. formData.append('base', JSON.stringify(baseInfo));
  2749. for (const file of files) {
  2750. if (file === undefined) {
  2751. toast('未选择上传文件!', 'error');
  2752. return false;
  2753. }
  2754. const filesize = file.size;
  2755. if (filesize > 30 * 1024 * 1024) {
  2756. toast('存在上传文件大小过大!', 'error');
  2757. return false;
  2758. }
  2759. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2760. if (whiteList.indexOf(fileext) === -1) {
  2761. toast('只能上传指定格式的附件!', 'error');
  2762. return false;
  2763. }
  2764. formData.append('size', filesize);
  2765. formData.append('file[]', file);
  2766. }
  2767. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  2768. stageIm.loadUpdateDetailAtt(data);
  2769. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  2770. self.makeAttTable(select);
  2771. $('#upload-im-file').val('');
  2772. });
  2773. });
  2774. // 删除附件
  2775. $('body').on('click', '.delete-att' ,function () {
  2776. const sels = self.sheet.getSelections();
  2777. const select = SpreadJsObj.getSelectObject(self.sheet);
  2778. if (!select) return;
  2779. const uuid = $(this).attr('data-imid');
  2780. const file_id = $(this).attr('data-attid');
  2781. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  2782. stageIm.loadUpdateDetailAtt(result);
  2783. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  2784. self.makeAttTable(select);
  2785. });
  2786. });
  2787. // 预览附件
  2788. $('body').on('click', '.preview-att', function () {
  2789. const uuid = $(this).attr('data-imid');
  2790. const file_id = $(this).attr('data-attid');
  2791. postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
  2792. const { filepath } = result;
  2793. $('#load-file').attr('href', filepath);
  2794. $('#load-file')[0].click();
  2795. });
  2796. })
  2797. }
  2798. _initImTypeSetRela() {
  2799. const self = this;
  2800. const gatherConfirmPopover = {
  2801. reBind: function (obj, eventName, fun) {
  2802. obj.unbind(eventName);
  2803. obj.bind(eventName, fun);
  2804. },
  2805. check: function (pos, hint, okCallback) {
  2806. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2807. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2808. this.reBind(cancelObj, 'click', function () {
  2809. confirmObj.hide();
  2810. });
  2811. this.reBind(okObj, 'click', function () {
  2812. okCallback();
  2813. confirmObj.hide();
  2814. });
  2815. hintObj.text(hint);
  2816. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2817. }
  2818. };
  2819. this.gsTree = stageIm.getGsTree();
  2820. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2821. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2822. jlCol.title = '本期计量金额';
  2823. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2824. $('[name=type-title-contract]').text('本期合同计量金额');
  2825. $('[name=type-title-qc]').text('本期变更计量金额');
  2826. } else {
  2827. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2828. jlCol.title = '本期计量数量';
  2829. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2830. $('[name=type-title-contract]').text('本期合同计量数量');
  2831. $('[name=type-title-qc]').text('本期变更计量数量');
  2832. }
  2833. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2834. $('#show-jldy').parent().show();
  2835. $('#jldy').parent().show();
  2836. $('#show-xm-name').parent().hide();
  2837. $('#xm-name').parent().hide();
  2838. } else {
  2839. $('#show-jldy').parent().hide();
  2840. $('#jldy').parent().hide();
  2841. $('#show-xm-name').parent().show();
  2842. $('#xm-name').parent().show();
  2843. }
  2844. // 选择中间计量模式
  2845. $('div[name="im-type"]').click(function () {
  2846. function chooseType(obj) {
  2847. obj.style.cursor = 'default';
  2848. $(obj).children().addClass('text-primary');
  2849. $(obj).addClass('border-primary');
  2850. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2851. }
  2852. function validType(obj) {
  2853. obj.style.cursor = 'pointer';
  2854. $(obj).children().removeClass('text-primary');
  2855. $(obj).removeClass('border-primary');
  2856. $('i', obj).remove();
  2857. }
  2858. if (this.style.cursor === 'pointer') {
  2859. const typeArr = $('div[name="im-type"]');
  2860. for (const t of typeArr) {
  2861. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2862. chooseType(t);
  2863. } else {
  2864. validType(t)
  2865. }
  2866. }
  2867. }
  2868. });
  2869. $('#choose').on('show.bs.modal', function () {
  2870. function chooseType(obj) {
  2871. obj.style.cursor = 'default';
  2872. $(obj).children().addClass('text-primary');
  2873. $('i', obj).remove();
  2874. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2875. }
  2876. function validType(obj) {
  2877. obj.style.cursor = 'pointer';
  2878. $(obj).children().removeClass('text-primary');
  2879. $('i', obj).remove();
  2880. }
  2881. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2882. $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
  2883. const typeArr = $('div[name="im-type"]');
  2884. for (const t of typeArr) {
  2885. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2886. chooseType(t);
  2887. } else {
  2888. validType(t)
  2889. }
  2890. }
  2891. });
  2892. // 提交 中间计量模式
  2893. $('#choose-ok').click(() => {
  2894. let startNum;
  2895. try {
  2896. startNum = parseInt($('#im-start-num').val());
  2897. if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
  2898. } catch (err) {
  2899. toastr.error("起始编号请输入正整数");
  2900. return;
  2901. }
  2902. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2903. return it.style.cursor !== 'pointer';
  2904. });
  2905. const data = {
  2906. im_type: parseInt($(chooseType).attr('im-type')),
  2907. im_pre: $('#im-pre').val(),
  2908. im_start_num: startNum,
  2909. };
  2910. postData(window.location.pathname + '/detail/build', data, function (result) {
  2911. stage.im_type = data.im_type;
  2912. stage.im_pre = data.im_pre;
  2913. stage.im_start_num = data.im_start_num;
  2914. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2915. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2916. jlCol.title = '本期计量金额';
  2917. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2918. $('[name=type-title-contract]').text('本期合同计量金额');
  2919. $('[name=type-title-qc]').text('本期变更计量金额');
  2920. } else {
  2921. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2922. jlCol.title = '本期计量数量';
  2923. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2924. $('[name=type-title-contract]').text('本期合同计量数量');
  2925. $('[name=type-title-qc]').text('本期变更计量数量');
  2926. }
  2927. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2928. $('#show-jldy').parent().show();
  2929. $('#jldy').parent().show();
  2930. $('#show-xm-name').parent().hide();
  2931. $('#xm-name').parent().hide();
  2932. } else {
  2933. $('#show-jldy').parent().hide();
  2934. $('#jldy').parent().hide();
  2935. $('#show-xm-name').parent().show();
  2936. $('#xm-name').parent().show();
  2937. }
  2938. // 加载生成数据
  2939. self.reBuildImData();
  2940. $('#choose').modal('hide');
  2941. });
  2942. });
  2943. // 显示树结构信息
  2944. $('#choose2').on('shown.bs.modal', function () {
  2945. if (!self.gsSpread) {
  2946. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2947. const setting = {
  2948. cols: [
  2949. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2950. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2951. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2952. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2953. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2954. ],
  2955. headRows: 1,
  2956. emptyRows: 0,
  2957. headRowHeight: [32],
  2958. defaultRowHeight: 21,
  2959. headerFont: '12px 微软雅黑',
  2960. font: '12px 微软雅黑',
  2961. };
  2962. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2963. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2964. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2965. function checkParent(node) {
  2966. const parent = self.gsTree.getParent(node);
  2967. if (parent) {
  2968. return parent.check ? parent.check : checkParent(parent);
  2969. } else {
  2970. return false;
  2971. }
  2972. }
  2973. function checkChildren(node) {
  2974. for (const child of node.children) {
  2975. if (child.check) {
  2976. return true;
  2977. } else if (checkChildren(child)) {
  2978. return true;
  2979. }
  2980. }
  2981. return false;
  2982. }
  2983. if (!$('#im-gather-check')[0].checked) { return; }
  2984. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2985. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2986. if (sheet.isEditing()) {
  2987. sheet.endEdit(true);
  2988. }
  2989. }
  2990. if (info.sheet.zh_setting) {
  2991. const col = info.sheet.zh_setting.cols[info.col];
  2992. if (col.field !== 'check') {
  2993. return;
  2994. }
  2995. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2996. const node = sortData[info.row];
  2997. if (!node.check) {
  2998. if (checkParent(node)) {
  2999. const rect = info.sheet.getCellRect(info.row, info.col);
  3000. gatherConfirmPopover.check({
  3001. x: rect.x + rect.width / 2 + 25,
  3002. y: rect.y + rect.height / 2 + 3,
  3003. }, '父项已勾选,继续将取消父项勾选。', function () {
  3004. node.check = true;
  3005. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  3006. const rows = [self.gsTree.nodes.indexOf(node)];
  3007. for (const p of parents) {
  3008. if (p.check) {
  3009. p.check = false;
  3010. rows.push(self.gsTree.nodes.indexOf(p));
  3011. }
  3012. }
  3013. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3014. });
  3015. } else if (checkChildren(node)) {
  3016. const rect = info.sheet.getCellRect(info.row, info.col);
  3017. gatherConfirmPopover.check({
  3018. x: rect.x + rect.width / 2 + 25,
  3019. y: rect.y + rect.height / 2 + 3,
  3020. }, '子项已勾选,继续将取消子项勾选。', function () {
  3021. node.check = true;
  3022. const posterity = self.gsTree.getPosterity(node);
  3023. const rows = [self.gsTree.nodes.indexOf(node)];
  3024. for (const p of posterity) {
  3025. if (p.check) {
  3026. rows.push(self.gsTree.nodes.indexOf(p));
  3027. p.check = false;
  3028. }
  3029. }
  3030. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3031. });
  3032. } else {
  3033. node.check = true;
  3034. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3035. }
  3036. } else {
  3037. node.check = false;
  3038. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3039. }
  3040. }
  3041. });
  3042. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3043. for (const node of self.gsTree.datas) {
  3044. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3045. }
  3046. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  3047. self.gsTree.expandByLevel(4);
  3048. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  3049. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  3050. } else {
  3051. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3052. for (const node of self.gsTree.datas) {
  3053. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3054. }
  3055. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  3056. }
  3057. });
  3058. // 提交 高级设置
  3059. $('#choose2-ok').click(() => {
  3060. if (!self.gsTree) { return; }
  3061. const nodes = [];
  3062. for (const node of self.gsTree.datas) {
  3063. if (node.check) {
  3064. nodes.push(node.id);
  3065. }
  3066. }
  3067. const data = {
  3068. im_gather: $('#im-gather-check')[0].checked,
  3069. im_gather_node: nodes.join(','),
  3070. };
  3071. postData(window.location.pathname + '/detail/adv', data, function (result) {
  3072. stage.im_gather = data.im_gather;
  3073. stage.im_gather_node = data.im_gather_node;
  3074. $('#choose2').modal('hide');
  3075. });
  3076. });
  3077. }
  3078. _initLocateRela() {
  3079. const self = this;
  3080. $('#im-locate2bills').click(function () {
  3081. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3082. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3083. if (select && select.source) {
  3084. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  3085. stagePosSpreadObj.loadCurPosData();
  3086. }
  3087. });
  3088. $('#im-locate-pre').click(function () {
  3089. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3090. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3091. if (select && select.source) {
  3092. const targetIndex = Math.max(curIndex-1, 1);
  3093. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3094. stagePosSpreadObj.loadCurPosData();
  3095. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3096. }
  3097. });
  3098. $('#im-locate-next').click(function () {
  3099. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3100. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3101. if (select && select.source) {
  3102. const targetIndex = Math.min(curIndex+1, select.source.length);
  3103. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3104. stagePosSpreadObj.loadCurPosData();
  3105. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3106. }
  3107. });
  3108. }
  3109. _initModifyDetail() {
  3110. const self = this;
  3111. // 重置
  3112. $('#reset-detail-ok').click(function () {
  3113. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3114. if (!data.uuid) return;
  3115. const updateData = {
  3116. lid: data.lid, pid: data.pid,
  3117. uuid: data.uuid,
  3118. custom_define: [],
  3119. };
  3120. for (const f of data.custom_define) {
  3121. if (stageIm.resetFields.indexOf(f) >= 0) {
  3122. updateData[f] = null;
  3123. } else {
  3124. updateData.custom_define.push(f);
  3125. }
  3126. }
  3127. updateData.custom_define = updateData.custom_define.join(',');
  3128. $('#reset-detail-modal').modal('hide');
  3129. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3130. stageIm.loadUpdateDetailData(result);
  3131. self.reLoadDetailData();
  3132. });
  3133. });
  3134. // 编辑
  3135. $('#edit-detail').click(function () {
  3136. $(this).hide();
  3137. $('#save-detail').show();
  3138. $('#cancel-detail').show();
  3139. $('#detail-show').hide();
  3140. $('#detail-edit').show();
  3141. self.updateImageData = null;
  3142. });
  3143. // 保存
  3144. $('#save-detail').click(() => {
  3145. function check(field, obj, org, update) {
  3146. const newValue = obj.val();
  3147. if (!org[field]) {
  3148. if (newValue !== '') {
  3149. update[field] = newValue;
  3150. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3151. return true;
  3152. }
  3153. } else if (newValue !== org[field]){
  3154. update[field] = newValue;
  3155. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3156. return true;
  3157. }
  3158. return false;
  3159. }
  3160. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3161. const updateData = {lid: data.lid, pid: data.pid};
  3162. if (data.uuid) {
  3163. updateData.uuid = data.uuid;
  3164. updateData.custom_define = data.custom_define;
  3165. } else {
  3166. updateData.code = data.code;
  3167. updateData.name = data.name;
  3168. updateData.unit = data.unit;
  3169. updateData.unit_price = data.unit_price;
  3170. updateData.pid = data.pid;
  3171. updateData.pos_name = data.pos_name;
  3172. updateData.im_type = data.im_type;
  3173. updateData.custom_define = [];
  3174. }
  3175. let infoUpdate = false;
  3176. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  3177. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  3178. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  3179. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  3180. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  3181. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  3182. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  3183. updateData.custom_define = updateData.custom_define.join(',');
  3184. if (infoUpdate) {
  3185. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3186. stageIm.loadUpdateDetailData(result);
  3187. self.reLoadDetailData();
  3188. if (!self.updateImageData) return;
  3189. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  3190. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3191. stageIm.loadUpdateDetailData(result);
  3192. self.reLoadDetailData();
  3193. });
  3194. });
  3195. } else if (self.updateImageData) {
  3196. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3197. stageIm.loadUpdateDetailData(result);
  3198. self.reLoadDetailData();
  3199. });
  3200. } else {
  3201. self.reLoadDetailData();
  3202. }
  3203. });
  3204. // 取消
  3205. $('#cancel-detail').click(() => {
  3206. self.reLoadDetailData();
  3207. });
  3208. }
  3209. _initImageRela() {
  3210. const self = this;
  3211. $('#edit-detail').click(function () {
  3212. loadImageItem();
  3213. });
  3214. function setdraggrable(){
  3215. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3216. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3217. stop: function( event, ui ) {
  3218. }
  3219. });
  3220. }
  3221. function upload(formData) {
  3222. if (formData.length < 1) {
  3223. return;
  3224. }
  3225. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3226. const html = [];
  3227. html.push('<div class="img-item">');
  3228. html.push('<div class="img-bar">');
  3229. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3230. html.push('</div>');
  3231. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3232. html.push('</div>');
  3233. $('.img-view').append(html.join(''));
  3234. $('.img-bar').click(removeImageItem);
  3235. setdraggrable();
  3236. $('#upload-img-file').val('');
  3237. });
  3238. }
  3239. function dragFile(e) {
  3240. var file = null,
  3241. data = e.dataTransfer.types;
  3242. for (var i = 0; i < data.length; i += 1) {
  3243. if (data[i] === 'Files') {
  3244. file = e.dataTransfer.files; //获取文件
  3245. break;
  3246. }
  3247. }
  3248. if (file && file[0].type.indexOf('image') !== -1) {
  3249. var formData = new FormData();
  3250. formData.append('file', file[0]); //上传单个文件的添加方式
  3251. upload(formData); //upload 异步上传
  3252. }
  3253. }
  3254. // 移动图片
  3255. const moveImageItem = function (ev) {
  3256. const item = this;
  3257. const view = $('.img-view')[0];
  3258. let oEvent = ev;
  3259. // 浏览器有一些图片的默认事件,这里要阻止
  3260. oEvent.preventDefault();
  3261. let disX = oEvent.clientX - item.offsetLeft;
  3262. let disY = oEvent.clientY - item.offsetTop;
  3263. view.onmousemove = function (ev) {
  3264. oEvent = ev;
  3265. oEvent.preventDefault();
  3266. let x = oEvent.clientX -disX;
  3267. let y = oEvent.clientY -disY;
  3268. // 图形移动的边界判断
  3269. x = x <= 0 ? 0 : x;
  3270. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  3271. y = y <= 0 ? 0 : y;
  3272. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  3273. item.style.left = x + 'px';
  3274. item.style.top = y + 'px';
  3275. };
  3276. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  3277. view.onmouseleave = function () {
  3278. view.onmousemove = null;
  3279. view.onmouseup = null;
  3280. };
  3281. // 鼠标弹起后停止移动
  3282. view.onmouseup=function() {
  3283. view.onmousemove = null;
  3284. view.onmouseup = null;
  3285. };
  3286. };
  3287. const removeImageItem = function () {
  3288. $(this).parent().remove();
  3289. };
  3290. // 加载草图组成
  3291. const loadImageItem = function () {
  3292. self.updateImageData = null;
  3293. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3294. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3295. const html = [];
  3296. for (const item of items) {
  3297. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3298. html.push('<div class="img-item" style="' + itemStyle + '">');
  3299. html.push('<div class="img-bar">');
  3300. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3301. html.push('</div>');
  3302. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3303. html.push('</div>');
  3304. }
  3305. $('.img-view').html(html.join(''));
  3306. $('.img-bar').click(removeImageItem);
  3307. setdraggrable();
  3308. };
  3309. // 上传图片
  3310. $('#upload-img').click(function () {
  3311. $('#upload-img-file').trigger('click');
  3312. });
  3313. // 拖拽上传
  3314. //拖拽上传文件
  3315. const dragbox = document.querySelector('#upload-img');
  3316. dragbox.addEventListener('dragover', function(e) {
  3317. e.preventDefault(); // 必须阻止默认事件
  3318. }, false);
  3319. dragbox.addEventListener('drop', function(e) {
  3320. e.preventDefault(); // 阻止默认事件
  3321. dragFile(e);
  3322. }, false);
  3323. //拖拽上传文件
  3324. const dragbox2 = document.querySelector('.img-view');
  3325. dragbox2.addEventListener('dragover', function(e) {
  3326. e.preventDefault(); // 必须阻止默认事件
  3327. }, false);
  3328. dragbox2.addEventListener('drop', function(e) {
  3329. e.preventDefault(); // 阻止默认事件
  3330. dragFile(e);
  3331. }, false);
  3332. // 粘贴上传
  3333. $(".img-view").on('paste', function(ev) {
  3334. let file = null;
  3335. const data = (event.clipboardData || window.clipboardData).items;
  3336. for (let i = 0; i < data.length; i += 1) {
  3337. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3338. file = data[i].getAsFile(); //读取图片文件
  3339. break;
  3340. }
  3341. }
  3342. if (file) {
  3343. const formData = new FormData();
  3344. formData.append('file', file); //上传单个文件的添加方式
  3345. upload(formData); //异步上传文件
  3346. }
  3347. });
  3348. $('#upload-img-file').change(function () {
  3349. const file = this.files[0];
  3350. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  3351. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  3352. if (!imgStr.test(ext)) {
  3353. toastr.error('请上传正确的图片格式文件');
  3354. return
  3355. }
  3356. if ($(this).val()) {
  3357. const formData = new FormData();
  3358. formData.append('file', this.files[0]);
  3359. upload(formData);
  3360. }
  3361. });
  3362. // 保存草图修改结果
  3363. $('#edit-img-ok').click(function () {
  3364. // 记录上传的图片的信息
  3365. const items = $('.img-item');
  3366. const img_remark = $('#text-edit').val();
  3367. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3368. // 生成上传数据
  3369. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  3370. if (data.uuid) {
  3371. updateData.uuid = data.uuid;
  3372. } else {
  3373. updateData.code = data.code;
  3374. updateData.name = data.name;
  3375. updateData.unit = data.unit;
  3376. updateData.unit_price = data.unit_price;
  3377. updateData.pid = data.pid;
  3378. updateData.pos_name = data.pos_name;
  3379. updateData.im_type = data.im_type;
  3380. }
  3381. if (items.length > 0) {
  3382. const itemInfo = [];
  3383. for (const item of items) {
  3384. const itemData = {
  3385. src: $('img', item).attr('src'),
  3386. left: item.style.left,
  3387. top: item.style.top,
  3388. width: item.style.width,
  3389. height: item.style.height,
  3390. };
  3391. itemInfo.push(itemData);
  3392. }
  3393. // 获取合并好的图片数据
  3394. const canvas = document.createElement('canvas');
  3395. const view = $('.img-view')[0];
  3396. canvas.height = view.clientHeight;
  3397. canvas.width = view.clientWidth;
  3398. const ctx = canvas.getContext('2d');
  3399. ctx.fillStyle = '#ffffff';
  3400. ctx.fillRect(0, 0, canvas.width, canvas.height);
  3401. for (const b of $('.img-item')) {
  3402. const pos = $(b).position();
  3403. const img = $('img', b)[0];
  3404. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  3405. }
  3406. updateData.img = canvas.toDataURL('image/png');
  3407. updateData.imgInfo = itemInfo;
  3408. self.updateImageData = updateData;
  3409. $('#calc-img').attr('src', updateData.img);
  3410. $('#calc-remark').html(img_remark);
  3411. $('#view-calc-img').attr('src', updateData.img);
  3412. $('#show-calc-img').attr('src', updateData.img);
  3413. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  3414. $('#view-calc-remark').text(img_remark);
  3415. $('#edit-img').modal('hide');
  3416. // updateImageData = updateData;
  3417. // $('#edit-img').modal('hide');
  3418. // postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  3419. // stageIm.loadUpdateDetailData(result);
  3420. // data.calc_img = result.calc_img;
  3421. // data.calc_img_org = result.calc_img_org;
  3422. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3423. // $('#show-calc-img').attr('src', calcImgSrc);
  3424. // $('#calc-img').attr('src', calcImgSrc);
  3425. // $('#view-calc-img').attr('src', calcImgSrc);
  3426. // $('#edit-img').modal('hide');
  3427. // });
  3428. } else if (data.calc_img) {
  3429. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  3430. $('#show-calc-img').attr('src', '');
  3431. $('#show-calc-remark').html('');
  3432. $('#calc-img').attr('src', '');
  3433. $('#calc-remark').html('');
  3434. $('#view-calc-img').attr('src', '');
  3435. $('#view-calc-remark').val('');
  3436. $('#text-edit').val('');
  3437. $('#edit-img').modal('hide');
  3438. // postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  3439. // stageIm.loadUpdateDetailData(result);
  3440. // data.calc_img = result.calc_img;
  3441. // data.calc_img_org = result.calc_img_org;
  3442. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3443. // $('#show-calc-img').attr('src', calcImgSrc);
  3444. // $('#calc-img').attr('src', calcImgSrc);
  3445. // $('#view-calc-img').attr('src', calcImgSrc);
  3446. // $('#edit-img').modal('hide');
  3447. // });
  3448. } else {
  3449. self.updateImageData = updateData;
  3450. $('#show-calc-img').attr('src', '');
  3451. $('#show-calc-remark').html('');
  3452. $('#calc-img').attr('src', '');
  3453. $('#calc-remark').html('');
  3454. $('#view-calc-img').attr('src', '');
  3455. $('#view-calc-remark').val('');
  3456. $('#text-edit').val('');
  3457. $('#edit-img').modal('hide');
  3458. }
  3459. });
  3460. }
  3461. reBuildImData() {
  3462. const imData = stageIm.buildImData();
  3463. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3464. this.reLoadDetailData();
  3465. this.loadLocateInfo();
  3466. }
  3467. loadStageLedgerUpdateData(data, nodes) {
  3468. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  3469. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3470. this.reLoadDetailData();
  3471. }
  3472. loadStagePosUpdateData(data, nodes) {
  3473. const imData = stageIm.loadUpdatePosData(data, nodes);
  3474. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3475. this.reLoadDetailData();
  3476. }
  3477. loadStageChangeUpdateData(data, nodes) {
  3478. const imData = stageIm.loadUpdateChangeData(data, nodes);
  3479. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3480. this.reLoadDetailData();
  3481. }
  3482. loadLocateInfo() {
  3483. const select = SpreadJsObj.getSelectObject(this.sheet);
  3484. if (select && select.source.length > 1) {
  3485. $('#im-locate2bills').next().show();
  3486. } else {
  3487. $('#im-locate2bills').next().hide();
  3488. }
  3489. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  3490. }
  3491. reLoadDetailData() {
  3492. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  3493. $('#reset-detail').hide();
  3494. if (data) {
  3495. for (const f of data.custom_define) {
  3496. if (stageIm.resetFields.indexOf(f) >= 0) {
  3497. $('#reset-detail').show();
  3498. break;
  3499. }
  3500. }
  3501. $('#edit-detail').show();
  3502. $('#modify-img').show();
  3503. } else {
  3504. $('#edit-detail').hide();
  3505. $('#modify-img').hide();
  3506. }
  3507. $('#save-detail').hide();
  3508. $('#cancel-detail').hide();
  3509. $('#detail-show').show();
  3510. $('#detail-edit').hide();
  3511. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  3512. $('#show-contract-jl').text(contractJl);
  3513. $('#contract-jl').val(contractJl);
  3514. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  3515. $('#show-qc-jl').text(qcJl);
  3516. $('#qc-jl').val(qcJl);
  3517. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  3518. $('#show-bgl-code').text(bglCode);
  3519. $('#bgl-code').val(bglCode);
  3520. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  3521. $('#show-bgl-drawing-code').text(bglDrawingCode);
  3522. $('#bgl-drawing-code').val(bglDrawingCode);
  3523. const bwName = data && data.bw ? data.bw : '';
  3524. $('#show-bw-name').text(bwName);
  3525. $('#bw-name').val(bwName);
  3526. const position = data && data.position ? data.position : '';
  3527. $('#show-position').text(position);
  3528. $('#position').val(position);
  3529. const peg = data && data.peg ? data.peg : '';
  3530. $('#show-peg').text(peg);
  3531. $('#peg').val(peg);
  3532. const xmName = data && data.xm ? data.xm: '';
  3533. $('#show-xm-name').text(xmName);
  3534. $('#xm-name').val(xmName);
  3535. const jldy = data && data.jldy ? data.jldy: '';
  3536. $('#show-jldy').text(jldy);
  3537. $('#jldy').val(jldy);
  3538. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  3539. $('#show-drawing-code').text(drawingCode);
  3540. $('#drawing-code').val(drawingCode);
  3541. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  3542. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  3543. $('#calc-memo').val(calcMemo);
  3544. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3545. $('#show-calc-img').attr('src', calcImgSrc);
  3546. $('#calc-img').attr('src', calcImgSrc);
  3547. $('#view-calc-img').attr('src', calcImgSrc);
  3548. const calcImgRemark = data && data.calc_img_remark || '';
  3549. $('#view-calc-remark').val(calcImgRemark);
  3550. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  3551. $('#calc-remark').html(calcImgRemark);
  3552. $("#view-calc-remark").attr('readonly', true);
  3553. // 处理 编辑 -> 添加草图中textarea多余的空格
  3554. $('#text-edit').val(calcImgRemark)
  3555. }
  3556. }
  3557. class CheckedChange {
  3558. constructor (setting) {
  3559. const self = this;
  3560. this.changeSpreadSetting = {
  3561. cols: [
  3562. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  3563. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  3564. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3565. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  3566. ],
  3567. emptyRows: 0,
  3568. headRows: 1,
  3569. headRowHeight: [32],
  3570. headColWidth: [30],
  3571. defaultRowHeight: 21,
  3572. headerFont: '12px 微软雅黑',
  3573. font: '12px 微软雅黑',
  3574. readOnly: true,
  3575. };
  3576. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  3577. this.changeSheet = this.changeSpread.getActiveSheet();
  3578. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  3579. const getTipText = function (data) {
  3580. if (!data) return '';
  3581. const tips = [];
  3582. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  3583. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  3584. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  3585. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  3586. return tips.join('-');
  3587. };
  3588. this.changeBillsSpreadSetting = {
  3589. cols: [
  3590. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', cellType: 'tip', getTip: getTipText},
  3591. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number', cellType: 'tip', getTip: getTipText},
  3592. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'tip', getTip: getTipText},
  3593. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', cellType: 'tip', getTip: getTipText},
  3594. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3595. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3596. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: getTipText},
  3597. ],
  3598. emptyRows: 0,
  3599. headRows: 1,
  3600. headRowHeight: [32],
  3601. defaultRowHeight: 21,
  3602. headerFont: '12px 微软雅黑',
  3603. font: '12px 微软雅黑',
  3604. readOnly: true
  3605. };
  3606. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  3607. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  3608. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  3609. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  3610. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3611. if (change.cid === self.curChangeId) { return; }
  3612. self.curChangeId = change.cid;
  3613. if (change.detail) {
  3614. self.loadChangeDetailData();
  3615. } else {
  3616. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  3617. change.detail = result;
  3618. self.analyzeChange(change);
  3619. self.loadChangeDetailData();
  3620. });
  3621. }
  3622. });
  3623. this.changes = null;
  3624. this.reloadChangeData();
  3625. setting.reloadObj.click(function() {
  3626. self.reloadChangeData();
  3627. });
  3628. $.contextMenu({
  3629. selector: '#' + setting.changeBillsObj.attr('id'),
  3630. build: function ($trigger, e) {
  3631. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  3632. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3633. },
  3634. items: {
  3635. 'locateZjjl': {
  3636. name: '定位至台账',
  3637. icon: 'fa-sign-in',
  3638. callback: function (key, opt) {
  3639. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3640. if (changeBills.gcl_id) {
  3641. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  3642. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3643. stagePosSpreadObj.loadCurPosData();
  3644. } else {
  3645. const cb = {
  3646. b_code: changeBills.code || '',
  3647. name: changeBills.name || '',
  3648. unit: changeBills.unit || '',
  3649. unit_price: changeBills.unit_price || 0,
  3650. };
  3651. for (const node of stageTree.nodes) {
  3652. if (node.children && node.children.length > 0) continue;
  3653. const b = {
  3654. b_code: node.b_code || '',
  3655. name: node.name || '',
  3656. unit: node.unit || '',
  3657. unit_price: node.unit_price || 0,
  3658. };
  3659. if (_.isMatch(cb, b)) {
  3660. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3661. stagePosSpreadObj.loadCurPosData();
  3662. return;
  3663. }
  3664. }
  3665. }
  3666. },
  3667. disabled: function (key, opt) {
  3668. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3669. return !changeBills;
  3670. }
  3671. },
  3672. }
  3673. });
  3674. }
  3675. loadChangeDetailData() {
  3676. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  3677. if (change) {
  3678. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  3679. } else {
  3680. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  3681. }
  3682. }
  3683. refresh() {
  3684. this.changeSpread.refresh();
  3685. this.changeBillsSpread.refresh();
  3686. }
  3687. reloadChangeData() {
  3688. const self = this;
  3689. postData(window.location.pathname + '/change/data', null, function (result) {
  3690. self.changes = result.changes;
  3691. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  3692. self.changeSheet.setSelection(0, 0, 1, 1);
  3693. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  3694. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  3695. self.loadChangeDetailData();
  3696. });
  3697. }
  3698. analyzeChange(change) {
  3699. change.bills = change.detail.bills;
  3700. for (const b of change.bills) {
  3701. const aub = change.detail.addUsedBills.find(function (x) {
  3702. return x.id === b.id;
  3703. });
  3704. if (aub) {
  3705. b.used_qty = aub.used_qty;
  3706. }
  3707. b.qty = _.toNumber(b.samount);
  3708. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  3709. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3710. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  3711. b.cur_qty = 0;
  3712. for (const p of b.pos) {
  3713. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  3714. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  3715. }
  3716. }
  3717. }
  3718. }
  3719. // 展开收起附件
  3720. $('a', '.right-nav').bind('click', function () {
  3721. //const main = $('#main-view'), tool = $('#tools-view');
  3722. const tab = $(this), tabPanel = $(tab.attr('content'));
  3723. if (!tab.hasClass('active')) {
  3724. $('a', '.side-menu').removeClass('active');
  3725. $('.tab-content .tab-select-show').removeClass('active');
  3726. tab.addClass('active');
  3727. tabPanel.addClass('active');
  3728. showSideTools(tab.hasClass('active'));
  3729. if (tab.attr('content') === '#search' && !searchLedger) {
  3730. searchLedger = $.billsSearch({
  3731. selector: '#search',
  3732. searchSpread: slSpread,
  3733. searchOver: true,
  3734. searchEmpty: true,
  3735. resultSpreadSetting: {
  3736. cols: [
  3737. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3738. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3739. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3740. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3741. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3742. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3743. {title: '完成率(%)', field: 'end_gather_percent', hAlign: 2, width: 70},
  3744. ],
  3745. emptyRows: 0,
  3746. headRows: 1,
  3747. headRowHeight: [32],
  3748. headColWidth: [30],
  3749. defaultRowHeight: 21,
  3750. headerFont: '12px 微软雅黑',
  3751. font: '12px 微软雅黑',
  3752. selectedBackColor: '#fffacd',
  3753. },
  3754. afterLocated: function () {
  3755. stagePosSpreadObj.loadCurPosData();
  3756. },
  3757. customSearch: [
  3758. {
  3759. key: 'less', title: '漏计', valid: true,
  3760. check: function (node) {
  3761. if (node.quantity) {
  3762. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  3763. } else if (node.total_price) {
  3764. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  3765. }
  3766. }
  3767. }, {
  3768. key: 'over', title: '超计', valid: true,
  3769. check: function (node) {
  3770. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  3771. }
  3772. }, {
  3773. key: 'empty', title: '漏计', valid: false,
  3774. check: function (node) {
  3775. if (node.quantity) {
  3776. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  3777. } else if (node.total_price) {
  3778. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  3779. }
  3780. }
  3781. }, {
  3782. key: 'estimate', title: '预计变更', valid: true,
  3783. check: function (node) {
  3784. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  3785. if (posRange.length > 0) {
  3786. for (const p of posRange) {
  3787. if (!checkZero(p.estimate_qty)) return true;
  3788. }
  3789. return false;
  3790. } else {
  3791. return false;
  3792. }
  3793. }
  3794. }
  3795. ],
  3796. });
  3797. searchLedger.spread.refresh();
  3798. }
  3799. if (tab.attr('content') === '#fujian') {
  3800. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3801. node && getNodeList(node.id);
  3802. }
  3803. if (tab.attr('content') === '#zhongjian') {
  3804. if (!detail) {
  3805. detail = new Detail($('#detail-spread'));
  3806. detail.spread.refresh();
  3807. $('#zhongjian .sjs-bottom').height('400px');
  3808. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3809. } else {
  3810. detail.spread.refresh();
  3811. }
  3812. }
  3813. if (tab.attr('content') === '#checked-change') {
  3814. if (!checkedChanges) {
  3815. checkedChanges = new CheckedChange({
  3816. changeObj: $('#cc-spread'),
  3817. changeBillsObj: $('#ccb-spread'),
  3818. reloadObj: $('#refresh-cc'),
  3819. });
  3820. checkedChanges.refresh();
  3821. } else {
  3822. $('#ccb-spread').height('400px');
  3823. checkedChanges.refresh();
  3824. }
  3825. }
  3826. if (tab.attr('content') === '#error-list') {
  3827. errorList.spread.refresh();
  3828. }
  3829. if (tab.attr('content') === '#check-list') {
  3830. checkList.spread.refresh();
  3831. }
  3832. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  3833. } else {
  3834. tab.removeClass('active');
  3835. tabPanel.removeClass('active');
  3836. showSideTools(tab.hasClass('active'));
  3837. }
  3838. slSpread.refresh();
  3839. spSpread.refresh();
  3840. });
  3841. // 切换附件里节点和所有附件
  3842. $('#fujian .nav-link').on('click', function () {
  3843. const tabPanel = $(this).attr('fujian-content');
  3844. if (tabPanel !== 'syfujian') {
  3845. $('#showPage').hide();
  3846. $('#bach-download').prop('type', 'curr');
  3847. } else {
  3848. $('#showPage').show();
  3849. $('#bach-download').prop('type', 'all')
  3850. }
  3851. $('#showAttachment').hide();
  3852. });
  3853. // 上传附件
  3854. $('#upload-file-btn').click(function () {
  3855. // if (curAuditor && curAuditor.aid !== cur_uid) {
  3856. // return toastr.error('当前操作没有权限!');
  3857. // }
  3858. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3859. if (!node) return
  3860. const files = $('#upload-file')[0].files;
  3861. const formData = new FormData();
  3862. formData.append('lid', node.id);
  3863. for (const file of files) {
  3864. if (file === undefined) {
  3865. toastr.error('未选择上传文件!');
  3866. return false;
  3867. }
  3868. const filesize = file.size;
  3869. if (filesize > 30 * 1024 * 1024) {
  3870. toastr.error('存在上传文件大小过大!');
  3871. return false;
  3872. }
  3873. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3874. if (whiteList.indexOf(fileext) === -1) {
  3875. toastr.error('只能上传指定格式的附件!');
  3876. return false;
  3877. }
  3878. formData.append('size', filesize);
  3879. formData.append('file[]', file);
  3880. }
  3881. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  3882. $('#upload').modal('hide');
  3883. // 插入到attData中
  3884. attData = data.concat(attData);
  3885. // 重新生成List
  3886. getAllList();
  3887. getNodeList(node.id);
  3888. }, function () {
  3889. toastr.error('附件上传失败');
  3890. });
  3891. $('#upload-file').val('');
  3892. });
  3893. // 获取附件信息
  3894. $('.list-table').on('click', '.att-file-name', function () {
  3895. const fid = $(this).attr('file-id');
  3896. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3897. return;
  3898. }
  3899. const att = attData.find(function (item) {
  3900. return item.id === parseInt(fid);
  3901. });
  3902. $('#edit-att').hide();
  3903. $('#show-att').show();
  3904. if (att !== undefined) {
  3905. // 进来先把编辑功能隐藏
  3906. $('#btn-att a').eq(3).hide()
  3907. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3908. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3909. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3910. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3911. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3912. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3913. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3914. $('#show-att tr').eq(3).children('td').text(att.remark);
  3915. // 附件uid等于当前用户id, 附件上传本人
  3916. if (parseInt(cur_uid) === att.uid) {
  3917. $('#btn-att').show();
  3918. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  3919. // if (!curAuditor) {
  3920. // stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  3921. // stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3922. // stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3923. // } else {
  3924. // curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  3925. // }
  3926. if (showDel) $('#btn-att a').eq(3).show();
  3927. // $('#btn-att a').eq(3).show();
  3928. $('#btn-att a').eq(2).hide();
  3929. $('#btn-att a').eq(4).hide();
  3930. $('#btn-att a').eq(5).hide();
  3931. } else {
  3932. $('#btn-att').hide();
  3933. $('#btn-att a').eq(3).hide();
  3934. $('#btn-att a').eq(2).hide();
  3935. $('#btn-att a').eq(4).hide();
  3936. $('#btn-att a').eq(5).hide();
  3937. }
  3938. $('#showAttachment').attr('file-id', fid);
  3939. $('#showAttachment').show();
  3940. } else {
  3941. $('#showAttachment').hide();
  3942. $('#showAttachment').attr('file-id', '');
  3943. toastr.error('附件信息获取失败');
  3944. }
  3945. });
  3946. // $('body').on('click', '.alllist-table a', handleFileList);
  3947. $('body').on('click', '#btn-att a', function () {
  3948. const content = $(this).attr('content');
  3949. const fid = $('#showAttachment').attr('file-id');
  3950. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3951. if (content === 'edit') {
  3952. $('#btn-att a').eq(3).hide();
  3953. $('#btn-att a').eq(2).show();
  3954. $('#btn-att a').eq(4).show();
  3955. $('#btn-att a').eq(5).show();
  3956. $('#show-att').hide();
  3957. $('#edit-att').show();
  3958. const att = attData.find(function (item) {
  3959. return item.id === parseInt(fid);
  3960. });
  3961. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3962. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3963. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3964. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3965. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3966. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3967. } else if (content === 'cancel') {
  3968. $('#show-att').show();
  3969. $('#edit-att').hide();
  3970. $('#btn-att a').eq(3).show();
  3971. $('#btn-att a').eq(2).hide();
  3972. $('#btn-att a').eq(4).hide();
  3973. $('#btn-att a').eq(5).hide();
  3974. } else if (content === 'save') {
  3975. const formData = new FormData();
  3976. formData.append('id', fid);
  3977. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3978. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3979. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3980. const file = $('#change-att-btn')[0];
  3981. if (file.files[0] !== undefined) {
  3982. const filesize = file.files[0].size;
  3983. formData.append('size', filesize);
  3984. formData.append('file', file.files[0]);
  3985. }
  3986. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3987. // 替换到attData中
  3988. const att_index = attData.findIndex(function (item) {
  3989. return item.id === parseInt(fid);
  3990. });
  3991. attData.splice(att_index, 1, data);
  3992. // 重新生成List
  3993. getAllList(parseInt($('#currentPage').text()));
  3994. getNodeList(node.id);
  3995. $('#show-att').show();
  3996. $('#edit-att').hide();
  3997. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3998. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3999. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4000. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  4001. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  4002. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  4003. $('#show-att tr').eq(4).children('td').text(data.remark);
  4004. $('#btn-att a').eq(3).show();
  4005. $('#btn-att a').eq(2).hide();
  4006. $('#btn-att a').eq(4).hide();
  4007. $('#btn-att a').eq(5).hide();
  4008. }, function () {
  4009. toastr.error('附件上传失败');
  4010. });
  4011. $('#change-att-btn').val('');
  4012. } else if (content === 'del') {
  4013. const data = {id: fid};
  4014. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  4015. // 删除到attData中
  4016. const att_index = attData.findIndex(function (item) {
  4017. return item.id === parseInt(fid);
  4018. });
  4019. attData.splice(att_index, 1);
  4020. // 重新生成List
  4021. if ($('#alllist-table tr').length === 1) {
  4022. getAllList(parseInt($('#currentPage').text()) - 1);
  4023. } else {
  4024. getAllList(parseInt($('#currentPage').text()));
  4025. }
  4026. getNodeList(node.id);
  4027. $('#showAttachment').hide();
  4028. $('#showAttachment').attr('file-id', '');
  4029. });
  4030. } else if (content === 'view') {
  4031. const data = {id: fid};
  4032. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  4033. const { filepath } = result
  4034. $('#load-file').attr('href', filepath);
  4035. $('#load-file')[0].click();
  4036. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  4037. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  4038. });
  4039. } else if (content === 'location') {
  4040. const att = attData.find(item => item.id === parseInt(fid));
  4041. if (Object.keys(att).length) {
  4042. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  4043. stagePosSpreadObj.loadCurPosData();
  4044. }
  4045. }
  4046. });
  4047. // 替换附件
  4048. $('#change-att-btn').on('change', function () {
  4049. const file = $('#change-att-btn')[0].files[0];
  4050. const name = file.name;
  4051. const filename = name.substring(0, name.lastIndexOf("."));
  4052. const fileext = name.substr(name.indexOf("."));
  4053. const filesize = file.size;
  4054. if (filesize > 10 * 1024 * 1024) {
  4055. toastr.error('文件大小过大!');
  4056. $('#change-att-btn').val('');
  4057. return false;
  4058. }
  4059. if (whiteList.indexOf(fileext) === -1) {
  4060. toastr.error('只能上传指定格式的附件!');
  4061. $('#change-att-btn').val('');
  4062. return false;
  4063. }
  4064. $('#edit-att .form-group').eq(0).find('input').val(filename);
  4065. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  4066. });
  4067. // 切换页数
  4068. $('.page-select').on('click', function () {
  4069. const totalPageNum = parseInt($('#totalPage').text());
  4070. const lastPageNum = parseInt($('#currentPage').text());
  4071. const status = $(this).attr('content');
  4072. if (status === 'pre' && lastPageNum > 1) {
  4073. getAllList(lastPageNum-1);
  4074. $('#showAttachment').hide();
  4075. $('#syfujian .check-all-file').prop('checked', false)
  4076. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4077. getAllList(lastPageNum+1);
  4078. $('#showAttachment').hide();
  4079. $('#syfujian .check-all-file').prop('checked', false)
  4080. }
  4081. });
  4082. // 批量下载
  4083. $('#bach-download').click(function() {
  4084. const fileIds = [];
  4085. const type = $(this).attr('type');
  4086. let node = ''
  4087. if (type === 'curr') {
  4088. node = '#nodelist-table .check-file:checked'
  4089. } else {
  4090. node = '#alllist-table .check-file:checked'
  4091. }
  4092. $(node).each(function() {
  4093. const fileId = $(this).attr('file-id');
  4094. fileId && fileIds.push(fileId);
  4095. });
  4096. if (fileIds.length) {
  4097. if (fileIds.length > 10) {
  4098. return toastr.warning(`最大允许10个文件(当前${fileIds.length}个)`)
  4099. }
  4100. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  4101. $(this).attr('disabled', "true")
  4102. const btn = $(this);
  4103. const fileArr = [];
  4104. for (const id of fileIds) {
  4105. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  4106. fileArr.push({
  4107. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  4108. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  4109. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  4110. });
  4111. }
  4112. const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
  4113. try {
  4114. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  4115. } catch (e) {
  4116. btn.removeAttr('disabled');
  4117. toastr.clear();
  4118. toastr.error('批量下载失败');
  4119. }
  4120. // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  4121. // toastr.clear()
  4122. // toastr.success('压缩文件成功')
  4123. // btn.removeAttr('disabled')
  4124. // const href = window.URL.createObjectURL(result)
  4125. // $('#zipDown').attr('href', href);
  4126. // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  4127. // $("#zipDown")[0].click();
  4128. // }, () => {
  4129. // btn.removeAttr('disabled')
  4130. // toastr.clear()
  4131. // toastr.error('批量下载失败')
  4132. // });
  4133. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  4134. // $('#zipDown').attr('href', url);
  4135. // $("#zipDown")[0].click();
  4136. }
  4137. });
  4138. // 监听附件check是否选中
  4139. $('.list-table').on('click', '.check-file', function() {
  4140. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  4141. const childs = $(this).parents('.list-table').children().length;
  4142. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  4143. if (checkedList.length === childs) {
  4144. checkBox.prop("checked", true);
  4145. } else {
  4146. checkBox.prop("checked", false);
  4147. }
  4148. });
  4149. $('.check-all-file').click(function() {
  4150. const isCheck = $(this).is(':checked');
  4151. $(this).parents('table').find('.list-table').each(function() {
  4152. $(this).find('input:checkbox').prop("checked", isCheck);
  4153. })
  4154. });
  4155. // 显示层次
  4156. (function (select, sheet) {
  4157. $(select).click(function () {
  4158. if (!sheet.zh_tree) return;
  4159. const tag = $(this).attr('tag');
  4160. const tree = sheet.zh_tree;
  4161. setTimeout(() => {
  4162. showWaitingView();
  4163. switch (tag) {
  4164. case "1":
  4165. case "2":
  4166. case "3":
  4167. case "4":
  4168. case "5":
  4169. tree.expandByLevel(parseInt(tag));
  4170. SpreadJsObj.refreshTreeRowVisible(sheet);
  4171. break;
  4172. case "last":
  4173. tree.expandByCustom(() => { return true; });
  4174. SpreadJsObj.refreshTreeRowVisible(sheet);
  4175. break;
  4176. case "leafXmj":
  4177. tree.expandToLeafXmj();
  4178. SpreadJsObj.refreshTreeRowVisible(sheet);
  4179. break;
  4180. case "curMeasure":
  4181. tree.expandByCustom(function (node) {
  4182. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  4183. if (node[field]) {
  4184. return true;
  4185. }
  4186. }
  4187. return false;
  4188. });
  4189. SpreadJsObj.refreshTreeRowVisible(sheet);
  4190. break;
  4191. }
  4192. closeWaitingView();
  4193. }, 100);
  4194. });
  4195. })('a[name=showLevel]', slSpread.getActiveSheet());
  4196. const stageCheckerSetting = {
  4197. ledgerTree: stageTree,
  4198. ledgerPos: stagePos,
  4199. checkList: checkList,
  4200. decimal: tenderInfo.decimal,
  4201. checkOption: checkOption,
  4202. };
  4203. if (!checkTzMeasureType()) {
  4204. stageCheckerSetting.checkOption.calc.fields.push('sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'quantity');
  4205. stageCheckerSetting.checkOption.tp.fields.push(
  4206. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  4207. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  4208. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  4209. {qty: 'quantity', tp: 'total_price'},
  4210. );
  4211. }
  4212. $('#ledger-check2').click(() => {
  4213. const result = ledgerCheck2(stageCheckerSetting);
  4214. check2Viewing({
  4215. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  4216. randomWait: true,
  4217. prefix: 'check2-',
  4218. checks: result,
  4219. checkList: checkList,
  4220. })
  4221. });
  4222. const dataChecker = DataChecker({
  4223. checkUrl: window.location.pathname + '/check',
  4224. completeData: function (data) {
  4225. stagePos.updateDatas({pos: data.source.pos});
  4226. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  4227. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  4228. stagePosSpreadObj.loadCurPosData();
  4229. for (const e of data.error) {
  4230. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  4231. }
  4232. },
  4233. errorList: errorList,
  4234. });
  4235. $('[name=stage-start]').submit(function (e) {
  4236. if (checkAuditorFrom()) {
  4237. // 再检查多人协同确认情况
  4238. const list = stageTree.pwd.find(x => {return !x.confirm });
  4239. if(list) {
  4240. toastr.error('请检查多人协同确认情况再上报');
  4241. $('#hide-all').hide();
  4242. return false;
  4243. }
  4244. $(this).parent().parent().parent().modal('hide');
  4245. dataChecker.checkAndPost(this.action, {});
  4246. $('#hide-all').hide();
  4247. }
  4248. return false;
  4249. });
  4250. $('#audit-check0').submit(function (e) {
  4251. // 再检查多人协同确认情况
  4252. const list = stageTree.pwd.find(x => {return !x.confirm });
  4253. if(list) {
  4254. toastr.error('请检查多人协同确认情况再审批通过');
  4255. $('#hide-all').hide();
  4256. return false;
  4257. }
  4258. const checkType = parseInt($('[name=checkType]').val());
  4259. const data = {
  4260. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4261. checkType,
  4262. };
  4263. $('#sp-done').modal('hide');
  4264. checkType && dataChecker.checkAndPost(this.action, data);
  4265. $('#hide-all').hide();
  4266. return false;
  4267. });
  4268. $('#audit-check1').submit(function (e) {
  4269. const checkType = parseInt($('[name=checkType]:checked').val());
  4270. const data = {
  4271. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4272. checkType,
  4273. };
  4274. if ($('#warning-text').length) $('#warning-text').remove()
  4275. if (!checkType && !$('#warning-text').length) {
  4276. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  4277. return false
  4278. }
  4279. $('#sp-back').modal('hide');
  4280. checkType && dataChecker.checkAndPost(this.action, data);
  4281. $('#hide-all').hide();
  4282. return false;
  4283. });
  4284. $('#exportExcel').click(function () {
  4285. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  4286. });
  4287. $('#cbr-check-all').click(function () {
  4288. if (this.checked) {
  4289. $('input', '#cbr-pos-list').attr('checked', 'checked');
  4290. } else {
  4291. $('input', '#cbr-pos-list').removeAttr('checked');
  4292. }
  4293. });
  4294. $('#cbr-ok').click(() => {
  4295. const ratio = parseInt($('#cbr-ratio').val());
  4296. if (!ratio) {
  4297. toastr.warning('请输入计量比例');
  4298. return;
  4299. } else if (ratio < 1) {
  4300. toastr.warning('计量比例不可小于1');
  4301. return;
  4302. } else if (ratio > 100) {
  4303. toastr.warning('计量比例不可大于100');
  4304. return;
  4305. }
  4306. const apply2sibling = $('#apply2sibling')[0].checked;
  4307. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  4308. if (posName.length === 0) {
  4309. toastr.warning('请勾选需要按计量比例的计量单元');
  4310. return;
  4311. }
  4312. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  4313. });
  4314. $('body').on('click', '[name=ledger-unlock]', function() {
  4315. $('#cooperation').modal('hide');
  4316. const lid = this.getAttribute('lid');
  4317. if (!lid) return;
  4318. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4319. if (!p) return;
  4320. $('#unlock-info').html(`${p.node.code} ${p.node.name} 解锁密码<b class="text-danger">*</b>`);
  4321. $('#unlock-pwd').val('').removeClass('is-invalid');
  4322. $('.invalid-feedback', '#unlock').hide();
  4323. $('.alert-warning', '#unlock').hide();
  4324. $('#unlock-ok').attr('lid', lid);
  4325. $('#unlock').modal('show');
  4326. });
  4327. $('#unlock-ok').click(function () {
  4328. const lid = this.getAttribute('lid');
  4329. if (!lid) return;
  4330. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4331. if (!p) return;
  4332. if (p.pwd === $('#unlock-pwd').val()) {
  4333. const refresh = stageTree.lockNode(p, false);
  4334. // 修改线上
  4335. SpreadJsObj.reloadRowsReadonly(slSpread.getActiveSheet(), refresh);
  4336. stagePosSpreadObj.loadCurPosData();
  4337. $('#unlock').modal('hide');
  4338. reloadCooperationHtml();
  4339. } else {
  4340. $('#unlock-pwd').addClass('is-invalid');
  4341. $('.invalid-feedback', '#unlock').show();
  4342. $('.alert-warning', '#unlock').show();
  4343. }
  4344. });
  4345. $('#cooperationSelect').change(function () {
  4346. reloadCooperationHtml();
  4347. });
  4348. // 确认
  4349. $('body').on('click', '[name=ledger-confirm]', function() {
  4350. const lid = this.getAttribute('lid');
  4351. if (!lid) return;
  4352. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4353. if (!p) return;
  4354. // 修改线上
  4355. postData(window.location.pathname + '/save/cooperation', { type: 'save-confirm', postData: { ledger_id: lid } }, function (result) {
  4356. p.confirm = true;
  4357. p.confirm_time = new Date();
  4358. stageTree.confirmList = result.cooperationConfirm;
  4359. reloadCooperationHtml();
  4360. });
  4361. });
  4362. // 确认
  4363. $('body').on('click', '[name=ledger-unconfirm]', function() {
  4364. const lid = this.getAttribute('lid');
  4365. if (!lid) return;
  4366. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4367. if (!p) return;
  4368. // 修改线上
  4369. postData(window.location.pathname + '/save/cooperation', { type: 'del-confirm', postData: { ledger_id: lid } }, function (result) {
  4370. p.confirm = false;
  4371. p.confirm_time = null;
  4372. stageTree.confirmList = result.cooperationConfirm;
  4373. reloadCooperationHtml();
  4374. });
  4375. });
  4376. // 收方单生成
  4377. $('#setshoufang').click(function () {
  4378. const lid = $('#shoufang-lid').val();
  4379. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  4380. // 修改线上
  4381. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  4382. // 收方单tab打开并显示在最新
  4383. if (!$('#shoufang-tab').hasClass('active')) {
  4384. $('#shoufang-tab').click();
  4385. }
  4386. const data = makeOneShouFang(result);
  4387. data.filenum = 0;
  4388. sfData = _.concat(data, sfData);
  4389. getShouFangList();
  4390. });
  4391. });
  4392. $('body').on('click', '.del-shoufang', function () {
  4393. const id = $(this).attr('data-id');
  4394. $('#del-shoufang-id').val(id);
  4395. const name = $(this).parents('tr').children('td').eq(0).text();
  4396. const ledger_code = name.split(' / ')[0];
  4397. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  4398. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  4399. if (pos_name) {
  4400. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  4401. } else {
  4402. $('#del-shoufang-pos').text('').hide();
  4403. }
  4404. });
  4405. // 收方单删除
  4406. $('#delshoufang').click(function () {
  4407. const sfid = $('#del-shoufang-id').val();
  4408. // 修改线上
  4409. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  4410. // 删除到sfData中
  4411. const att_index = sfData.findIndex(function (item) {
  4412. return item.id === parseInt(sfid);
  4413. });
  4414. sfData.splice(att_index, 1);
  4415. // 重新生成List
  4416. if ($('#shoufang-table tr').length === 1) {
  4417. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  4418. } else {
  4419. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  4420. }
  4421. $('#shoufangdelete').modal('hide');
  4422. });
  4423. });
  4424. // 切换页数
  4425. $('.shoufang-page-select').on('click', function () {
  4426. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  4427. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  4428. const status = $(this).attr('content');
  4429. if (status === 'pre' && lastPageNum > 1) {
  4430. getShouFangList(lastPageNum-1);
  4431. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4432. getShouFangList(lastPageNum+1);
  4433. }
  4434. });
  4435. // 获取单个收方单附件列表
  4436. $('body').on('click', '.show-shoufang-att', function () {
  4437. const id = parseInt($(this).attr('data-id'));
  4438. let html = '';
  4439. $('#shoufang-flie-list').html(html);
  4440. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  4441. for (const att of result) {
  4442. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  4443. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  4444. `<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>`;
  4445. }
  4446. $('#shoufang-flie-list').html(html);
  4447. $('[data-toggle="tooltip"]').tooltip()
  4448. });
  4449. function makeViewHtml(viewpath) {
  4450. 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>` : '';
  4451. }
  4452. function makeDelHtml(fid, extra_upload) {
  4453. return sfAttDelPower &&
  4454. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4455. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
  4456. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4457. }
  4458. });
  4459. function makeEditHtml(fid, filename, fileext, extra_upload) {
  4460. return sfAttDelPower &&
  4461. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4462. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  4463. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  4464. }
  4465. // 修改收方单附件文件名
  4466. $('body').on('click', '.edit-shoufang-att', function () {
  4467. $(this).children('i').tooltip('hide');
  4468. const fid = $(this).data('id');
  4469. const filename = $(this).data('filename');
  4470. const fileext = $(this).data('fileext');
  4471. const html = `<div class="input-group input-group-sm">
  4472. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  4473. <div class="input-group-append" id="button-${fid}">
  4474. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  4475. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  4476. </div>
  4477. </div>`;
  4478. $(this).parents('td').html(html);
  4479. });
  4480. // 确认修改文件名
  4481. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  4482. const validText = $.trim($(this).parents('td').find('input').val());
  4483. const orgValue = $.trim($(this).data('filename'));
  4484. const fileext = $(this).data('fileext');
  4485. const fid = $(this).data('fid');
  4486. if (!validText) {
  4487. toastr.error('文件名不能为空');
  4488. return;
  4489. }
  4490. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  4491. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  4492. toastr.error('文件名中不能包含.字符和空格');
  4493. return;
  4494. }
  4495. if(validText == orgValue) {
  4496. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  4497. $(this).parents('td').html(html);
  4498. return;
  4499. }
  4500. const data = {
  4501. id: fid,
  4502. filename: validText,
  4503. };
  4504. const _self = $(this);
  4505. postData('/wap/shoufang/editfile', data, function (result) {
  4506. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  4507. _self.parents('td').html(html);
  4508. });
  4509. });
  4510. // 取消修改文件名
  4511. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  4512. const fid = $(this).data('fid');
  4513. const filename = $(this).data('filename');
  4514. const fileext = $(this).data('fileext');
  4515. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  4516. $(this).parents('td').html(html);
  4517. });
  4518. // 删除收方单附件
  4519. $('body').on('click', '.del-shoufang-att', function () {
  4520. const id = $(this).data('id');
  4521. const _self = $(this);
  4522. const data = { id };
  4523. const sfid = $(this).data('sfid');
  4524. postData('/wap/shoufang/delfile', data, function (result) {
  4525. _self.parents('tr').remove();
  4526. // 附件个数更新
  4527. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  4528. const sfInfo = _.find(sfData, { id: sfid });
  4529. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  4530. });
  4531. });
  4532. // 定位到对应的清单或计量单元
  4533. $('body').on('click', '.show-shoufang-node', function () {
  4534. const id = parseInt($(this).attr('data-id'));
  4535. const sfInfo = _.find(sfData, { id });
  4536. if (sfInfo) {
  4537. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4538. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  4539. stagePosSpreadObj.loadCurPosData();
  4540. if (sfInfo.pid) {
  4541. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  4542. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  4543. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  4544. }
  4545. }
  4546. });
  4547. // 定位到对应的清单或计量单元
  4548. $('body').on('click', '.show-shoufang-report', function () {
  4549. const id = parseInt($(this).attr('data-id'));
  4550. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  4551. sessionStorage.qrCodePath = qrCodePath;
  4552. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  4553. sessionStorage.req_params = JSON.stringify(req_params);
  4554. sessionStorage.rpt_name = rpt_name;
  4555. window.open('/individualReport/A4');
  4556. });
  4557. });
  4558. function makeOneShouFang(sf) {
  4559. const lData = _.find(ledgerData, { id: sf.lid });
  4560. sf.name = lData.b_code;
  4561. if (sf.pid) {
  4562. const pData = _.find(posData, { id: sf.pid });
  4563. sf.name = lData.b_code + ' / ' + pData.name;
  4564. }
  4565. return sf;
  4566. }
  4567. function makeShouFang() {
  4568. for (const sf of sfData) {
  4569. makeOneShouFang(sf);
  4570. }
  4571. getShouFangList();
  4572. }
  4573. // 生成收方单列表
  4574. function getShouFangList(currPageNum = 1) {
  4575. // 每页最多几个附件
  4576. const pageCount = 20;
  4577. // 附件总数
  4578. const total = sfData.length;
  4579. // 总页数
  4580. const pageNum = Math.ceil(total/pageCount);
  4581. $('#shoufang-totalPage').text(pageNum);
  4582. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  4583. // 当前页附件内容
  4584. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  4585. let html = '';
  4586. for(const att of currPageAttData) {
  4587. html += '<tr><td>' + att.name + '</td>' +
  4588. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  4589. '<td width="100">' +
  4590. '<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> ' +
  4591. '<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> ' +
  4592. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  4593. makeDelHtml(att.id, att.extra_upload) +
  4594. '</td></tr>';
  4595. }
  4596. function makeDelHtml(id, extra_upload) {
  4597. return cur_uid === stage.user_id &&
  4598. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4599. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  4600. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4601. }
  4602. $('#shoufang-table').html(html);
  4603. $('[data-toggle="tooltip"]').tooltip();
  4604. }
  4605. function makeReportData(sfid) {
  4606. const sfInfo = _.find(sfData, { id: sfid });
  4607. const ledger_code = sfInfo.name.split(' / ')[0];
  4608. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  4609. const replace_key_params = {
  4610. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  4611. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  4612. 'KEY_合同段': tenderInfo.deal_info.dealName,
  4613. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  4614. 'KEY_编号': '',
  4615. 'KEY_设计工程数量': 0,
  4616. };
  4617. // if (sfInfo.pid) {
  4618. // const pData = _.find(posData, { id: sfInfo.pid });
  4619. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  4620. // } else {
  4621. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4622. // }
  4623. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  4624. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  4625. const req_params = {
  4626. 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)
  4627. pageSize: 'A4',
  4628. project_id: tender.project_id,
  4629. tender_id: tender.id,
  4630. stage_id: stage.id,
  4631. };
  4632. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  4633. const qrCodePath = sfInfo.qrcode;
  4634. return [qrCodePath, replace_key_params, req_params, rpt_name];
  4635. }