stage.js 197 KB

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