stage.js 195 KB

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