stage.js 130 KB

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