stage.js 200 KB

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