stage.js 170 KB

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