stage.js 195 KB

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