stage.js 200 KB

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