stage.js 197 KB

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