stage.js 159 KB

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