stage.js 185 KB

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