stage.js 171 KB

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