stage.js 195 KB

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