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