sr_detail.js 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  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 relaTender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. function getExprInfo (field) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. /**
  26. * 从cookie中读取缓存的列显示设置,没有则取默认
  27. * @returns {*[]}
  28. */
  29. function customColDisplay () {
  30. const defaultSetting = [
  31. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  32. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  33. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  34. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  35. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  36. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent'], visible: true },
  37. { title: '本期批注', fields: ['postil'], visible: true },
  38. { title: '图册号', fields: ['drawing_code'], visible: true },
  39. { title: '备注', fields: ['memo'], visible: true },
  40. { title: '总额计量', fields: ['is_tp'], visible: true},
  41. ];
  42. if (!checkTzMeasureType()) {
  43. defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
  44. }
  45. const settingStr = Cookies.get(ckColSetting);
  46. if (settingStr) {
  47. const customSetting = JSON.parse(settingStr);
  48. for (const ds of defaultSetting) {
  49. const cs = customSetting.find(x => {return x.title === ds.title});
  50. if (cs) ds.visible = cs.visible;
  51. }
  52. }
  53. return defaultSetting;
  54. }
  55. /**
  56. * 根据列显示设置,调整setting中的列是否显示
  57. * @param setting
  58. * @param customDisplay
  59. */
  60. function customizeStageTreeSetting(setting, customDisplay) {
  61. for (const cd of customDisplay) {
  62. for (const c of setting.cols) {
  63. if (cd.fields.indexOf(c.field) !== -1) {
  64. c.visible = cd.visible;
  65. }
  66. }
  67. }
  68. }
  69. // 生成所有附件列表
  70. function getAllList(currPageNum = 1) {
  71. // 每页最多几个附件
  72. const pageCount = 15;
  73. // 附件总数
  74. const total = attData.length;
  75. // 总页数
  76. const pageNum = Math.ceil(total/pageCount);
  77. $('#totalPage').text(pageNum);
  78. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  79. // 当前页附件内容
  80. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  81. let html = '';
  82. for(const att of currPageAttData) {
  83. html += `<tr>
  84. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  85. <td>
  86. <div class="d-flex">
  87. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  88. <a href="/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  89. </div>
  90. </td><td>${att.username}</td></tr>`
  91. }
  92. $('#alllist-table').html(html);
  93. $('#alllist-table').on('click', 'tr', function() {
  94. $('#alllist-table tr').removeClass('bg-light')
  95. $(this).addClass('bg-light')
  96. })
  97. }
  98. // 生成当前节点列表
  99. function getNodeList(node) {
  100. let html = '';
  101. for(const att of attData) {
  102. if (node === att.lid) {
  103. html += `<tr>
  104. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  105. <td>
  106. <div class="d-flex">
  107. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  108. <a href="/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  109. </div>
  110. </td><td>${att.username}</td></tr>`
  111. }
  112. }
  113. $('#nodelist-table').html(html);
  114. $('#nodelist-table').on('click', 'tr', function() {
  115. $('#nodelist-table tr').removeClass('bg-light');
  116. $(this).addClass('bg-light');
  117. })
  118. }
  119. function getGxbyText(data) {
  120. const def = thirdParty.gxby.find(function (x) {
  121. return x.value === data.gxby_status;
  122. });
  123. return def ? def.name : '';
  124. }
  125. function getDaglText(data) {
  126. const def = thirdParty.dagl.find(function (x) {
  127. return x.value === data.dagl_status;
  128. });
  129. return def ? def.name : '';
  130. }
  131. function getHintMsg () {
  132. return {
  133. invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
  134. disableChange: {type: 'error', msg: '不可修改此数据'},
  135. }
  136. }
  137. $(document).ready(() => {
  138. let detail, searchLedger;
  139. // 界面布局
  140. autoFlashHeight();
  141. // 初始化 台账树结构 数据结构
  142. removeLocalCache('bills-fold');
  143. const stageTreeSetting = {
  144. id: 'ledger_id',
  145. pid: 'ledger_pid',
  146. order: 'order',
  147. level: 'level',
  148. rootId: -1,
  149. keys: ['id', 'tender_id', 'ledger_id'],
  150. stageId: 'id',
  151. autoExpand: 3,
  152. // markFoldKey: 'bills-fold',
  153. // markFoldSubKey: window.location.pathname.split('/')[2],
  154. markExpandKey: 'stage-bills-expand',
  155. markExpandSubKey: window.location.pathname.split('/')[2],
  156. };
  157. // 台账树结构计算相关设置
  158. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];
  159. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp'];
  160. stageTreeSetting.calcFun = function (node) {
  161. if (!node.children || node.children.length === 0) {
  162. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  163. node.end_gather_qty = ZhCalc.add(node.end_contract_qty, node.end_qc_qty);
  164. }
  165. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  166. node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
  167. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  168. if (!node.children || node.children.length === 0) {
  169. if (node.end_contract_qty) {
  170. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  171. } else {
  172. node.end_correct_tp = node.end_gather_tp;
  173. }
  174. }
  175. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  176. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  177. 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);
  178. };
  179. const stageTree = createNewPathTree('stage', stageTreeSetting);
  180. // 初始化 计量单元 数据结构
  181. const stagePosSetting = { id: 'id', ledgerId: 'lid' };
  182. stagePosSetting.calcFun = function (pos) {
  183. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  184. pos.end_gather_qty = ZhCalc.add(pos.end_contract_qty, pos.end_qc_qty);
  185. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  186. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  187. pos.estimate_qty = !checkZero(pos.real_qty)
  188. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  189. : null;
  190. };
  191. const stagePos = new StagePosData(stagePosSetting);
  192. // 初始化 台账 spread
  193. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  194. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  195. const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_percent' || x.field === 'end_correct_percent'});
  196. ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_percent' : 'end_gather_percent';
  197. ledgerSpreadSetting.imageClick = function (data, hitinfo) {
  198. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  199. if (col.field === 'dagl') data.dagl_url && window.open(data.dagl_url);
  200. };
  201. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  202. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  203. if (data) {
  204. if (col.field === 'gxby') {
  205. const def = thirdParty.gxby.find(function (x) {
  206. return x.value === data.gxby_status;
  207. });
  208. if (def && def.color) return def.color;
  209. } else if (col.field === 'dagl') {
  210. const def = thirdParty.dagl.find(function (x) {
  211. return x.value === data.dagl_status;
  212. });
  213. if (def && def.color) return def.color;
  214. }
  215. return checkUtils.billsOver(data, checkTzMeasureType(), stagePos) ? '#f8d7da' : defaultColor;
  216. } else {
  217. return defaultColor;
  218. }
  219. };
  220. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  221. sjsSettingObj.setPropValue(ledgerSpreadSetting, ['gxby'], 'getValue', getGxbyText);
  222. sjsSettingObj.setPropValue(ledgerSpreadSetting, ['dagl'], 'getValue', getDaglText);
  223. const lDaglCol = _.find(ledgerSpreadSetting.cols, {field: 'dagl'});
  224. if (lDaglCol) {
  225. lDaglCol.getValue = getDaglText;
  226. lDaglCol.cellType = 'activeImageBtn';
  227. lDaglCol.normalImg = '#rela-file-icon';
  228. lDaglCol.indent = 5;
  229. lDaglCol.imgAlign = 2;
  230. lDaglCol.showImage = function (data) { return data && data.dagl_url; }
  231. }
  232. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  233. ledgerSpreadSetting.headColWidth = [50];
  234. ledgerSpreadSetting.rowHeader = [
  235. {
  236. rowHeaderType: 'tag',
  237. setting: {
  238. indent: 14,
  239. tagSize: 0.8,
  240. tagFont: '8px 微软雅黑',
  241. getColor: function (index, data) {
  242. if (!data) return;
  243. return billsTag.getBillsTagsColor(data.id);
  244. },
  245. getTagHtml: function (index, data) {
  246. if (!data) return;
  247. const getHtml = function (list) {
  248. if (!list || list.length === 0) return '';
  249. const html = [];
  250. for (const l of list) {
  251. html.push('<div class="row mr-1">');
  252. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  253. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  254. html.push('</div>');
  255. }
  256. return html.join('');
  257. };
  258. return getHtml(billsTag.getBillsTagsInfo(data.id));
  259. }
  260. },
  261. },
  262. ];
  263. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  264. slSpread.getActiveSheet().frozenColumnCount(5);
  265. slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
  266. //初始化所有附件列表
  267. getAllList();
  268. // 初始化 计量单元 Spread
  269. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  270. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  271. spCol.cellType = 'activeImageBtn';
  272. spCol.normalImg = '#ellipsis-icon';
  273. spCol.indent = 5;
  274. spCol.showImage = function (data) {
  275. return data !== undefined && data !== null;
  276. };
  277. posSpreadSetting.imageClick = function (data, hitinfo) {
  278. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  279. if (col.field === 'dagl') data.dagl_url && window.open(data.dagl_url);
  280. };
  281. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  282. if (data) {
  283. if (col.field === 'gxby') {
  284. const def = thirdParty.gxby.find(function (x) {
  285. return x.value === data.gxby_status;
  286. });
  287. if (def && def.color) return def.color;
  288. } else if (col.field === 'dagl') {
  289. const def = thirdParty.dagl.find(function (x) {
  290. return x.value === data.dagl_status;
  291. });
  292. if (def && def.color) return def.color;
  293. }
  294. }
  295. if (checkTzMeasureType()) {
  296. return checkUtils.posOver(data) ? '#f8d7da' : defaultColor;
  297. }
  298. };
  299. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  300. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  301. sjsSettingObj.setPropValue(posSpreadSetting, ['gxby'], 'getValue', getGxbyText);
  302. sjsSettingObj.setPropValue(posSpreadSetting, ['dagl'], 'getValue', getDaglText);
  303. const pDaglCol = _.find(posSpreadSetting.cols, {field: 'dagl'});
  304. if (pDaglCol) {
  305. pDaglCol.getValue = getDaglText;
  306. pDaglCol.cellType = 'activeImageBtn';
  307. pDaglCol.normalImg = '#rela-file-icon';
  308. pDaglCol.indent = 5;
  309. pDaglCol.imgAlign = 2;
  310. pDaglCol.showImage = function (data) { return data && data.dagl_url; }
  311. }
  312. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  313. const billsTag = $.billsTag({
  314. selector: '#bills-tag',
  315. relaSpread: slSpread,
  316. updateUrl: window.location.pathname + '/tag',
  317. readOnly: true,
  318. afterModify: function (nodes) {
  319. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  320. },
  321. afterLocated: function () {
  322. stagePosSpreadObj.loadCurPosData();
  323. },
  324. afterShow: function () {
  325. slSpread.refresh();
  326. if (spSpread) spSpread.refresh();
  327. },
  328. });
  329. const stageTreeSpreadObj = {
  330. loadExprToInput(sheet) {
  331. const sel = sheet.getSelections()[0];
  332. const col = sheet.zh_setting.cols[sel.col];
  333. if (col.type === 'Number') {
  334. const data = SpreadJsObj.getSelectObject(sheet);
  335. if (!data) {
  336. $('#bills-expr').val('');
  337. return;
  338. }
  339. const nodePos = stagePos.getLedgerPos(data.id);
  340. if (nodePos && nodePos.length > 0) {
  341. $('#bills-expr').val('');
  342. } else {
  343. const exprInfo = getExprInfo(col.field);
  344. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  345. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  346. }
  347. } else {
  348. $('#bills-expr').val('');
  349. }
  350. },
  351. selectionChanged: function (e, info) {
  352. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  353. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  354. stagePosSpreadObj.loadCurPosData();
  355. if (posSearch) {
  356. posSearch.search();
  357. }
  358. }
  359. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  360. stageTreeSpreadObj.loadExprToInput(info.sheet);
  361. },
  362. topRowChanged(e, info) {
  363. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  364. },
  365. };
  366. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  367. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  368. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  369. $.contextMenu({
  370. selector: '#stage-ledger',
  371. build: function ($trigger, e) {
  372. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  373. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  374. },
  375. items: {
  376. 'locateZjjl': {
  377. name: '定位至中间计量',
  378. icon: 'fa-sign-in',
  379. callback: function (key, opt) {
  380. if (!detail) {
  381. detail = new Detail($('#detail-spread'));
  382. }
  383. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  384. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  385. if (leafUsedBills) {
  386. if (!$('#zhongjian').hasClass('active')) {
  387. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  388. $('a', '.side-menu').removeClass('active');
  389. $('.tab-content .tab-select-show').removeClass('active');
  390. tab.addClass('active');
  391. tabPanel.addClass('active');
  392. showSideTools(tab.hasClass('active'));
  393. slSpread.refresh();
  394. spSpread.refresh();
  395. }
  396. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  397. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  398. SpreadJsObj.locateData(detail.sheet, im);
  399. detail.spread.refresh();
  400. $('#zhongjian .sjs-bottom').height('400px');
  401. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  402. detail.reLoadDetailData();
  403. } else {
  404. toastr.error('无可定位中间计量');
  405. }
  406. },
  407. },
  408. tagSpr: '----',
  409. tag: {
  410. name: '书签',
  411. callback: function (key, opt, menu, e) {
  412. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  413. addTag.do(node);
  414. },
  415. disabled: function (key, opt) {
  416. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  417. return !node;
  418. }
  419. },
  420. showSpr: '----',
  421. showLast: {
  422. name: '显示至最底层',
  423. callback: function (key, opt, menu, e) {
  424. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  425. setTimeout(() => {
  426. showWaitingView();
  427. stageTree.expandByCustom(x => {
  428. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  429. });
  430. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  431. closeWaitingView();
  432. }, 100);
  433. },
  434. },
  435. exportSpr: '----',
  436. exportSelectNodeXlsx: {
  437. name: '导出选中节点至Excel',
  438. callback: function (key, opt, menu, e) {
  439. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  440. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  441. },
  442. disabled: function (key, opt) {
  443. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  444. return !node;
  445. }
  446. },
  447. }
  448. });
  449. const stagePosSpreadObj = {
  450. loadExprToInput(sheet) {
  451. const sel = sheet.getSelections()[0];
  452. if (!sel) return;
  453. const col = sheet.zh_setting.cols[sel.col];
  454. if (col && col.type === 'Number') {
  455. const data = SpreadJsObj.getSelectObject(sheet);
  456. if (data) {
  457. const exprInfo = getExprInfo(col.field);
  458. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  459. $('#pos-expr').val(value);
  460. } else {
  461. $('#pos-expr').val('');
  462. }
  463. } else {
  464. $('#pos-expr').val('');
  465. }
  466. },
  467. /**
  468. * 加载计量单元 根据当前台账选择节点
  469. */
  470. loadCurPosData: function () {
  471. const sheet = slSpread.getActiveSheet();
  472. const node = SpreadJsObj.getSelectObject(sheet);
  473. if (node) {
  474. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  475. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  476. getNodeList(node.id);
  477. // 如果是附件是当前节点,隐藏
  478. // if ($('#dqjiedian').hasClass('active')) {
  479. // $('#showAttachment').hide();
  480. // }
  481. } else {
  482. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  483. }
  484. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  485. },
  486. selectionChanged: function (e, info) {
  487. stagePosSpreadObj.loadExprToInput(info.sheet);
  488. },
  489. };
  490. // 加载上下窗口resizer
  491. $.divResizer({
  492. select: '#main-resize',
  493. callback: function () {
  494. slSpread.refresh();
  495. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  496. $(".sp-wrap").height(bcontent-30);
  497. spSpread.refresh();
  498. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  499. }
  500. });
  501. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  502. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;sumDeal' }, function (result) {
  503. for (const l of result.ledgerData) {
  504. const sd = result.sumDeal.find(x => { return x.code === l.b_code && x.name === l.name && x.unit === l.unit; });
  505. if (sd) {
  506. l.unit_price = sd.unit_price;
  507. l.deal_tp = ZhCalc.mul(l.unit_price, l.deal_qty, tenderInfo.decimal.tp);
  508. l.sgfh_tp = ZhCalc.mul(l.unit_price, l.sgfh_qty, tenderInfo.decimal.tp);
  509. l.sjcl_tp = ZhCalc.mul(l.unit_price, l.sjcl_qty, tenderInfo.decimal.tp);
  510. l.qtcl_tp = ZhCalc.mul(l.unit_price, l.qtcl_qty, tenderInfo.decimal.tp);
  511. l.total_price = ZhCalc.mul(l.unit_price, l.quantity, tenderInfo.decimal.tp);
  512. }
  513. }
  514. // 加载树结构
  515. stageTree.loadDatas(result.ledgerData);
  516. treeCalc.calculateAll(stageTree);
  517. for (const t of result.tags) {
  518. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  519. }
  520. billsTag.loadDatas(result.tags);
  521. // 加载部位明细
  522. stagePos.loadDatas(result.posData);
  523. stagePos.calculateAll();
  524. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  525. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  526. stagePosSpreadObj.loadCurPosData();
  527. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  528. // 加载中间计量
  529. stageIm.init(relaStage, imType, tenderInfo.decimal);
  530. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  531. }, null, true);
  532. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  533. $.subMenu({
  534. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  535. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  536. key: 'menu.1.0.0',
  537. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  538. callback: function (info) {
  539. if (info.mini) {
  540. $('.panel-title').addClass('fluid');
  541. $('#sub-menu').removeClass('panel-sidebar');
  542. } else {
  543. $('.panel-title').removeClass('fluid');
  544. $('#sub-menu').addClass('panel-sidebar');
  545. }
  546. autoFlashHeight();
  547. slSpread.refresh();
  548. spSpread.refresh();
  549. if (searchLedger) searchLedger.spread.refresh();
  550. if (detail) detail.spread.refresh();
  551. }
  552. });
  553. const posSearch = (function () {
  554. let resultArr = [];
  555. const search = function () {
  556. resultArr = [];
  557. const keyword = $('#pos-search-keyword').val();
  558. const checkOver = $('#pos-over-search')[0].checked;
  559. const checkEmpty = $('#pos-empty-search')[0].checked;
  560. const sortData = spSpread.getActiveSheet().zh_data;
  561. if (checkOver || checkEmpty) {
  562. if (sortData) {
  563. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  564. const sd = sortData[i];
  565. let match = false;
  566. if (checkOver) {
  567. if (sd.end_gather_qty) {
  568. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  569. }
  570. }
  571. if (checkEmpty) {
  572. if (sd.quantity) {
  573. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  574. }
  575. }
  576. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  577. if (match) {
  578. resultArr.push({index: i, data: sd});
  579. }
  580. }
  581. }
  582. } else if (keyword && keyword !== '') {
  583. if (sortData) {
  584. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  585. const sd = sortData[i];
  586. if (sd.name && sd.name.indexOf(keyword) > -1) {
  587. resultArr.push({index: i, data: sd});
  588. }
  589. }
  590. }
  591. }
  592. $('#pos-search-result').html('结果:' + resultArr.length);
  593. };
  594. const searchAndLocate = function () {
  595. search();
  596. if (resultArr.length > 0) {
  597. const sheet = spSpread.getActiveSheet();
  598. const sel = sheet.getSelections()[0];
  599. const curRow = sel ? sel.row : 0;
  600. const pos = resultArr[0];
  601. if (pos.index !== curRow) {
  602. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  603. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  604. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  605. }
  606. }
  607. };
  608. const locateNext = function () {
  609. if (resultArr.length > 0) {
  610. const sheet = spSpread.getActiveSheet();
  611. const sel = sheet.getSelections()[0];
  612. const curRow = sel ? sel.row : 0;
  613. let next = _.find(resultArr, function (d) {
  614. return d.index > curRow;
  615. });
  616. if (!next) next = resultArr[0];
  617. if (next.index !== curRow) {
  618. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  619. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  620. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  621. }
  622. }
  623. };
  624. const locatePre = function () {
  625. if (resultArr.length > 0) {
  626. const sheet = spSpread.getActiveSheet();
  627. const sel = sheet.getSelections()[0];
  628. const curRow = sel ? sel.row : 0;
  629. let next = _.findLast(resultArr, function (d) {
  630. return d.index < curRow;
  631. });
  632. if (!next) next = resultArr[resultArr.length - 1];
  633. if (next.index !== curRow) {
  634. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  635. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  636. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  637. }
  638. }
  639. };
  640. return {search, searchAndLocate, locateNext, locatePre};
  641. })();
  642. $('#pos-search-keyword').bind('keydown', function(e){
  643. if (e.keyCode == 13) posSearch.searchAndLocate();
  644. });
  645. $('#pos-empty-search').click(function () {
  646. if (this.checked) {
  647. $('[for=' + this.id +']').addClass('text-warning');
  648. } else {
  649. $('[for=' + this.id +']').removeClass('text-warning');
  650. }
  651. if (this.checked) {
  652. if ($('#pos-over-search')[0].checked) {
  653. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  654. } else {
  655. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  656. }
  657. } else {
  658. if ($('#pos-over-search')[0].checked) {
  659. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  660. } else {
  661. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  662. }
  663. }
  664. posSearch.searchAndLocate();
  665. });
  666. $('#pos-over-search').click(function () {
  667. if (this.checked) {
  668. $('[for=' + this.id +']').addClass('text-danger');
  669. } else {
  670. $('[for=' + this.id +']').removeClass('text-danger');
  671. }
  672. if (this.checked) {
  673. if ($('#pos-empty-search')[0].checked) {
  674. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  675. } else {
  676. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  677. }
  678. } else {
  679. if ($('#pos-empty-search')[0].checked) {
  680. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  681. } else {
  682. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  683. }
  684. }
  685. posSearch.searchAndLocate();
  686. });
  687. $('#pos-search-next').click(() => {posSearch.locateNext()});
  688. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  689. $.divResizer({
  690. select: '#right-spr',
  691. callback: function () {
  692. slSpread.refresh();
  693. spSpread.refresh();
  694. if (searchLedger) {
  695. searchLedger.spread.refresh();
  696. }
  697. if (detail) {
  698. detail.spread.refresh();
  699. }
  700. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  701. }
  702. });
  703. // 中间计量加载上下窗口resizer
  704. $.divResizer({
  705. select: '#zhongjian-spr',
  706. callback: function () {
  707. if (detail) {
  708. detail.spread.refresh();
  709. }
  710. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  711. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  712. }
  713. });
  714. // 附件加载上下窗口resizer
  715. $.divResizer({
  716. select: '#file-spr',
  717. callback: function () {
  718. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  719. }
  720. });
  721. class Detail {
  722. constructor (obj) {
  723. const self = this;
  724. this.spreadSetting = {
  725. cols: [
  726. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  727. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@'},
  728. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  729. {
  730. title: relaStage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  731. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@'
  732. },
  733. ],
  734. headRows: 1,
  735. emptyRows: 0,
  736. headRowHeight: [32],
  737. headColWidth: [30],
  738. defaultRowHeight: 21,
  739. headerFont: '12px 微软雅黑',
  740. font: '12px 微软雅黑',
  741. readOnly: true,
  742. selectedBackColor: '#fffacd',
  743. };
  744. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  745. this.sheet = this.spread.getActiveSheet();
  746. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  747. this.detailObj = {
  748. selectionChanged: function (e, info) {
  749. self.reLoadDetailData();
  750. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  751. self.loadLocateInfo();
  752. }
  753. },
  754. };
  755. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  756. this._initLocateRela();
  757. this.reBuildImData();
  758. }
  759. _initImTypeSetRela() {
  760. const self = this;
  761. const gatherConfirmPopover = {
  762. reBind: function (obj, eventName, fun) {
  763. obj.unbind(eventName);
  764. obj.bind(eventName, fun);
  765. },
  766. check: function (pos, hint, okCallback) {
  767. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  768. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  769. this.reBind(cancelObj, 'click', function () {
  770. confirmObj.hide();
  771. });
  772. this.reBind(okObj, 'click', function () {
  773. okCallback();
  774. confirmObj.hide();
  775. });
  776. hintObj.text(hint);
  777. confirmObj.css("top", pos.y).css("left", pos.x).show();
  778. }
  779. };
  780. this.gsTree = stageIm.getGsTree();
  781. if (relaStage.im_type === imType.tz.value || relaStage.im_type === imType.bb.value) {
  782. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  783. jlCol.title = '本期计量金额';
  784. SpreadJsObj.reLoadSheetHeader(self.sheet);
  785. $('#type-title-contract').text('本期合同计量金额');
  786. $('#type-title-qc').text('本期变更计量金额');
  787. } else {
  788. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  789. jlCol.title = '本期计量数量';
  790. SpreadJsObj.reLoadSheetHeader(self.sheet);
  791. $('#type-title-contract').text('本期合同计量数量');
  792. $('#type-title-qc').text('本期变更计量数量');
  793. }
  794. if (relaStage.im_type === imType.bb.value || relaStage.im_type === imType.bw.value) {
  795. $('#show-jldy').parent().show();
  796. $('#jldy').parent().show();
  797. $('#show-xm-name').parent().hide();
  798. $('#xm-name').parent().hide();
  799. } else {
  800. $('#show-jldy').parent().hide();
  801. $('#jldy').parent().hide();
  802. $('#show-xm-name').parent().show();
  803. $('#xm-name').parent().show();
  804. }
  805. }
  806. _initLocateRela() {
  807. const self = this;
  808. $('#im-locate2bills').click(function () {
  809. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  810. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  811. if (select && select.source) {
  812. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  813. stagePosSpreadObj.loadCurPosData();
  814. }
  815. });
  816. $('#im-locate-pre').click(function () {
  817. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  818. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  819. if (select && select.source) {
  820. const targetIndex = Math.max(curIndex-1, 1);
  821. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  822. stagePosSpreadObj.loadCurPosData();
  823. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  824. }
  825. });
  826. $('#im-locate-next').click(function () {
  827. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  828. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  829. if (select && select.source) {
  830. const targetIndex = Math.min(curIndex+1, select.source.length);
  831. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  832. stagePosSpreadObj.loadCurPosData();
  833. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  834. }
  835. });
  836. }
  837. loadLocateInfo() {
  838. const select = SpreadJsObj.getSelectObject(this.sheet);
  839. if (select && select.source.length > 1) {
  840. $('#im-locate2bills').next().show();
  841. } else {
  842. $('#im-locate2bills').next().hide();
  843. }
  844. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  845. }
  846. reLoadDetailData() {
  847. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  848. $('#detail-show').show();
  849. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  850. $('#show-contract-jl').text(contractJl);
  851. $('#contract-jl').val(contractJl);
  852. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  853. $('#show-qc-jl').text(qcJl);
  854. $('#qc-jl').val(qcJl);
  855. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  856. $('#show-bgl-code').text(bglCode);
  857. $('#bgl-code').val(bglCode);
  858. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  859. $('#show-bgl-drawing-code').text(bglDrawingCode);
  860. $('#bgl-drawing-code').val(bglDrawingCode);
  861. const bwName = data && data.bw ? data.bw : '';
  862. $('#show-bw-name').text(bwName);
  863. $('#bw-name').val(bwName);
  864. const position = data && data.position ? data.position : '';
  865. $('#show-position').text(position);
  866. $('#position').val(position);
  867. const peg = data && data.peg ? data.peg : '';
  868. $('#show-peg').text(peg);
  869. $('#peg').val(peg);
  870. const xmName = data && data.xm ? data.xm: '';
  871. $('#show-xm-name').text(xmName);
  872. $('#xm-name').val(xmName);
  873. const jldy = data && data.jldy ? data.jldy: '';
  874. $('#show-jldy').text(jldy);
  875. $('#jldy').val(jldy);
  876. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  877. $('#show-drawing-code').text(drawingCode);
  878. $('#drawing-code').val(drawingCode);
  879. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  880. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  881. $('#calc-memo').val(calcMemo);
  882. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  883. $('#show-calc-img').attr('src', calcImgSrc);
  884. $('#calc-img').attr('src', calcImgSrc);
  885. $('#view-calc-img').attr('src', calcImgSrc);
  886. const calcImgRemark = data && data.calc_img_remark || '';
  887. $('#view-calc-remark').val(calcImgRemark);
  888. $("#view-calc-remark").attr('readonly', true);
  889. $('#text-edit').val(calcImgRemark)
  890. }
  891. reBuildImData() {
  892. const imData = stageIm.buildImData();
  893. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  894. this.reLoadDetailData();
  895. this.loadLocateInfo();
  896. }
  897. }
  898. // 展开收起附件
  899. $('a', '.right-nav').bind('click', function () {
  900. //const main = $('#main-view'), tool = $('#tools-view');
  901. const tab = $(this), tabPanel = $(tab.attr('content'));
  902. if (!tab.hasClass('active')) {
  903. $('a', '.side-menu').removeClass('active');
  904. $('.tab-content .tab-select-show').removeClass('active');
  905. tab.addClass('active');
  906. tabPanel.addClass('active');
  907. showSideTools(tab.hasClass('active'));
  908. if (tab.attr('content') === '#search' && !searchLedger) {
  909. searchLedger = $.billsSearch({
  910. selector: '#search',
  911. searchSpread: slSpread,
  912. searchRangeStr: '项目节编号/名称',
  913. searchOver: true,
  914. searchEmpty: true,
  915. resultSpreadSetting: {
  916. cols: [
  917. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  918. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  919. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  920. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  921. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  922. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  923. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  924. ],
  925. emptyRows: 0,
  926. headRows: 1,
  927. headRowHeight: [32],
  928. headColWidth: [30],
  929. defaultRowHeight: 21,
  930. headerFont: '12px 微软雅黑',
  931. font: '12px 微软雅黑',
  932. selectedBackColor: '#fffacd',
  933. },
  934. afterLocated: function () {
  935. stagePosSpreadObj.loadCurPosData();
  936. },
  937. customSearch: [
  938. {
  939. key: 'less', title: '漏计', valid: true,
  940. check: function (node) {
  941. if (node.quantity) {
  942. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  943. } else if (node.total_price) {
  944. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  945. }
  946. }
  947. }, {
  948. key: 'over', title: '超计', valid: true,
  949. check: function (node) {
  950. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  951. }
  952. }, {
  953. key: 'empty', title: '漏计', valid: false,
  954. check: function (node) {
  955. if (node.quantity) {
  956. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  957. } else if (node.total_price) {
  958. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  959. }
  960. }
  961. },
  962. ],
  963. });
  964. searchLedger.spread.refresh();
  965. }
  966. if (tab.attr('content') === '#fujian') {
  967. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  968. getNodeList(node.id);
  969. }
  970. if (tab.attr('content') === '#zhongjian') {
  971. if (!detail) {
  972. detail = new Detail($('#detail-spread'));
  973. detail.spread.refresh();
  974. $('#zhongjian .sjs-bottom').height('400px');
  975. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  976. } else {
  977. detail.spread.refresh();
  978. }
  979. }
  980. } else {
  981. tab.removeClass('active');
  982. tabPanel.removeClass('active');
  983. showSideTools(tab.hasClass('active'));
  984. }
  985. slSpread.refresh();
  986. spSpread.refresh();
  987. });
  988. // 切换附件里节点和所有附件
  989. $('#fujian .nav-link').on('click', function () {
  990. const tabPanel = $(this).attr('fujian-content');
  991. if (tabPanel !== 'syfujian') {
  992. $('#showPage').hide();
  993. $('#bach-download').prop('type', 'curr');
  994. } else {
  995. $('#showPage').show();
  996. $('#bach-download').prop('type', 'all')
  997. }
  998. $('#showAttachment').hide();
  999. });
  1000. // 获取附件信息
  1001. $('.list-table').on('click', '.att-file-name', function () {
  1002. const fid = $(this).attr('file-id');
  1003. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1004. return;
  1005. }
  1006. const att = attData.find(function (item) {
  1007. return item.id === parseInt(fid);
  1008. });
  1009. $('#edit-att').hide();
  1010. $('#show-att').show();
  1011. if (att !== undefined) {
  1012. // 进来先把编辑功能隐藏
  1013. $('#btn-att a').eq(3).hide()
  1014. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1015. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1016. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  1017. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  1018. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  1019. $('#show-att tr').eq(3).children('td').text(att.remark);
  1020. // 附件uid等于当前用户id, 附件上传本人
  1021. if (parseInt(cur_uid) === att.uid) {
  1022. $('#btn-att').show();
  1023. $('#btn-att a').eq(2).hide();
  1024. $('#btn-att a').eq(4).hide();
  1025. $('#btn-att a').eq(5).hide();
  1026. } else {
  1027. $('#btn-att').hide();
  1028. $('#btn-att a').eq(3).hide();
  1029. $('#btn-att a').eq(2).hide();
  1030. $('#btn-att a').eq(4).hide();
  1031. $('#btn-att a').eq(5).hide();
  1032. }
  1033. $('#showAttachment').attr('file-id', fid);
  1034. $('#showAttachment').show();
  1035. } else {
  1036. $('#showAttachment').hide();
  1037. $('#showAttachment').attr('file-id', '');
  1038. toastr.error('附件信息获取失败');
  1039. }
  1040. });
  1041. // $('body').on('click', '.alllist-table a', handleFileList);
  1042. $('body').on('click', '#btn-att a', function () {
  1043. const content = $(this).attr('content');
  1044. const fid = $('#showAttachment').attr('file-id');
  1045. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1046. if (content === 'view') {
  1047. const data = {id: fid};
  1048. postData('/tender/' + relaTender.id + '/measure/stage/' + relaStage.order + '/check/file', data, function (result) {
  1049. const { filepath } = result
  1050. $('#load-file').attr('href', filepath);
  1051. $('#load-file')[0].click();
  1052. });
  1053. } else if (content === 'location') {
  1054. const att = attData.find(item => item.id === parseInt(fid));
  1055. if (Object.keys(att).length) {
  1056. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  1057. stagePosSpreadObj.loadCurPosData();
  1058. }
  1059. }
  1060. });
  1061. // 切换页数
  1062. $('.page-select').on('click', function () {
  1063. const totalPageNum = parseInt($('#totalPage').text());
  1064. const lastPageNum = parseInt($('#currentPage').text());
  1065. const status = $(this).attr('content');
  1066. if (status === 'pre' && lastPageNum > 1) {
  1067. getAllList(lastPageNum-1);
  1068. $('#showAttachment').hide();
  1069. $('#syfujian .check-all-file').prop('checked', false)
  1070. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1071. getAllList(lastPageNum+1);
  1072. $('#showAttachment').hide();
  1073. $('#syfujian .check-all-file').prop('checked', false)
  1074. }
  1075. });
  1076. // 批量下载
  1077. $('#bach-download').click(function() {
  1078. const fileIds = [];
  1079. const type = $(this).attr('type');
  1080. let node = ''
  1081. if (type === 'curr') {
  1082. node = '#nodelist-table .check-file:checked'
  1083. } else {
  1084. node = '#alllist-table .check-file:checked'
  1085. }
  1086. $(node).each(function() {
  1087. const fileId = $(this).attr('file-id');
  1088. fileId && fileIds.push(fileId);
  1089. });
  1090. if (fileIds.length) {
  1091. if (fileIds.length > 10) {
  1092. return toastr.warning(`最大允许10个文件(当前${fileIds.length}个)`)
  1093. }
  1094. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  1095. $(this).attr('disabled', "true")
  1096. const btn = $(this)
  1097. postCompressFile(`/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/compresse-file`, {fileIds}, function(result) {
  1098. toastr.clear()
  1099. toastr.success('压缩文件成功')
  1100. btn.removeAttr('disabled')
  1101. const href = window.URL.createObjectURL(result)
  1102. $('#zipDown').attr('href', href);
  1103. $('#zipDown').attr('download', `${relaTender.name}-计量台账-第${relaStage.order}期-附件.zip`);
  1104. $("#zipDown")[0].click();
  1105. }, () => {
  1106. btn.removeAttr('disabled')
  1107. toastr.clear()
  1108. toastr.error('批量下载失败')
  1109. });
  1110. }
  1111. });
  1112. // 监听附件check是否选中
  1113. $('.list-table').on('click', '.check-file', function() {
  1114. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  1115. const childs = $(this).parents('.list-table').children().length;
  1116. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  1117. if (checkedList.length === childs) {
  1118. checkBox.prop("checked", true);
  1119. } else {
  1120. checkBox.prop("checked", false);
  1121. }
  1122. });
  1123. $('.check-all-file').click(function() {
  1124. const isCheck = $(this).is(':checked');
  1125. $(this).parents('table').find('.list-table').each(function() {
  1126. $(this).find('input:checkbox').prop("checked", isCheck);
  1127. })
  1128. });
  1129. // 显示层次
  1130. (function (select, sheet) {
  1131. $(select).click(function () {
  1132. if (!sheet.zh_tree) return;
  1133. const tag = $(this).attr('tag');
  1134. const tree = sheet.zh_tree;
  1135. setTimeout(() => {
  1136. showWaitingView();
  1137. switch (tag) {
  1138. case "1":
  1139. case "2":
  1140. case "3":
  1141. case "4":
  1142. case "5":
  1143. tree.expandByLevel(parseInt(tag));
  1144. SpreadJsObj.refreshTreeRowVisible(sheet);
  1145. break;
  1146. case "last":
  1147. tree.expandByCustom(() => { return true; });
  1148. SpreadJsObj.refreshTreeRowVisible(sheet);
  1149. break;
  1150. case "leafXmj":
  1151. tree.expandToLeafXmj();
  1152. SpreadJsObj.refreshTreeRowVisible(sheet);
  1153. break;
  1154. case "curMeasure":
  1155. tree.expandByCustom(function (node) {
  1156. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1157. if (node[field]) {
  1158. return true;
  1159. }
  1160. }
  1161. return false;
  1162. });
  1163. SpreadJsObj.refreshTreeRowVisible(sheet);
  1164. break;
  1165. }
  1166. closeWaitingView();
  1167. }, 100);
  1168. });
  1169. })('a[name=showLevel]', slSpread.getActiveSheet());
  1170. });