stage.js 202 KB

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