stage.js 147 KB

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