stage.js 200 KB

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