stage.js 201 KB

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