stage.js 130 KB

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