stage.js 152 KB

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