stage.js 202 KB

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