stage.js 183 KB

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