stage.js 150 KB

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