stage.js 167 KB

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