stage.js 159 KB

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