stage.js 201 KB

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