stage.js 200 KB

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