sr_detail.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  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. }
  164. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  165. node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
  166. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  167. if (!node.children || node.children.length === 0) {
  168. if (node.end_contract_qty) {
  169. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  170. } else {
  171. node.end_correct_tp = node.end_gather_tp;
  172. }
  173. }
  174. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  175. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  176. 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);
  177. };
  178. const stageTree = createNewPathTree('stage', stageTreeSetting);
  179. // 初始化 计量单元 数据结构
  180. const stagePosSetting = { id: 'id', ledgerId: 'lid' };
  181. stagePosSetting.calcFun = function (pos) {
  182. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  183. pos.end_gather_qty = ZhCalc.add(pos.end_contract_qty, pos.end_qc_qty);
  184. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  185. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  186. pos.estimate_qty = !checkZero(pos.real_qty)
  187. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  188. : null;
  189. };
  190. const stagePos = new StagePosData(stagePosSetting);
  191. // 初始化 台账 spread
  192. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  193. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  194. const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_percent' || x.field === 'end_correct_percent'});
  195. ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_percent' : 'end_gather_percent';
  196. ledgerSpreadSetting.imageClick = function (data, hitinfo) {
  197. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  198. if (col.field === 'dagl') data.dagl_url && window.open(data.dagl_url);
  199. };
  200. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  201. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  202. if (data) {
  203. if (col.field === 'gxby') {
  204. const def = thirdParty.gxby.find(function (x) {
  205. return x.value === data.gxby_status;
  206. });
  207. if (def && def.color) return def.color;
  208. } else if (col.field === 'dagl') {
  209. const def = thirdParty.dagl.find(function (x) {
  210. return x.value === data.dagl_status;
  211. });
  212. if (def && def.color) return def.color;
  213. }
  214. return checkUtils.billsOver(data, checkTzMeasureType(), stagePos) ? '#f8d7da' : defaultColor;
  215. } else {
  216. return defaultColor;
  217. }
  218. };
  219. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  220. sjsSettingObj.setPropValue(ledgerSpreadSetting, ['gxby'], 'getValue', getGxbyText);
  221. sjsSettingObj.setPropValue(ledgerSpreadSetting, ['dagl'], 'getValue', getDaglText);
  222. const lDaglCol = _.find(ledgerSpreadSetting.cols, {field: 'dagl'});
  223. if (lDaglCol) {
  224. lDaglCol.getValue = getDaglText;
  225. lDaglCol.cellType = 'activeImageBtn';
  226. lDaglCol.normalImg = '#rela-file-icon';
  227. lDaglCol.indent = 5;
  228. lDaglCol.imgAlign = 2;
  229. lDaglCol.showImage = function (data) { return data && data.dagl_url; }
  230. }
  231. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  232. ledgerSpreadSetting.headColWidth = [50];
  233. ledgerSpreadSetting.rowHeader = [
  234. {
  235. rowHeaderType: 'tag',
  236. setting: {
  237. indent: 14,
  238. tagSize: 0.8,
  239. tagFont: '8px 微软雅黑',
  240. getColor: function (index, data) {
  241. if (!data) return;
  242. return billsTag.getBillsTagsColor(data.id);
  243. },
  244. getTagHtml: function (index, data) {
  245. if (!data) return;
  246. const getHtml = function (list) {
  247. if (!list || list.length === 0) return '';
  248. const html = [];
  249. for (const l of list) {
  250. html.push('<div class="row mr-1">');
  251. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  252. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  253. html.push('</div>');
  254. }
  255. return html.join('');
  256. };
  257. return getHtml(billsTag.getBillsTagsInfo(data.id));
  258. }
  259. },
  260. },
  261. ];
  262. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  263. slSpread.getActiveSheet().frozenColumnCount(5);
  264. slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
  265. //初始化所有附件列表
  266. getAllList();
  267. // 初始化 计量单元 Spread
  268. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  269. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  270. spCol.cellType = 'activeImageBtn';
  271. spCol.normalImg = '#ellipsis-icon';
  272. spCol.indent = 5;
  273. spCol.showImage = function (data) {
  274. return data !== undefined && data !== null;
  275. };
  276. posSpreadSetting.imageClick = function (data, hitinfo) {
  277. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  278. if (col.field === 'dagl') data.dagl_url && window.open(data.dagl_url);
  279. };
  280. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  281. if (data) {
  282. if (col.field === 'gxby') {
  283. const def = thirdParty.gxby.find(function (x) {
  284. return x.value === data.gxby_status;
  285. });
  286. if (def && def.color) return def.color;
  287. } else if (col.field === 'dagl') {
  288. const def = thirdParty.dagl.find(function (x) {
  289. return x.value === data.dagl_status;
  290. });
  291. if (def && def.color) return def.color;
  292. }
  293. }
  294. if (checkTzMeasureType()) {
  295. return checkUtils.posOver(data) ? '#f8d7da' : defaultColor;
  296. }
  297. };
  298. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  299. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  300. sjsSettingObj.setPropValue(posSpreadSetting, ['gxby'], 'getValue', getGxbyText);
  301. sjsSettingObj.setPropValue(posSpreadSetting, ['dagl'], 'getValue', getDaglText);
  302. const pDaglCol = _.find(posSpreadSetting.cols, {field: 'dagl'});
  303. if (pDaglCol) {
  304. pDaglCol.getValue = getDaglText;
  305. pDaglCol.cellType = 'activeImageBtn';
  306. pDaglCol.normalImg = '#rela-file-icon';
  307. pDaglCol.indent = 5;
  308. pDaglCol.imgAlign = 2;
  309. pDaglCol.showImage = function (data) { return data && data.dagl_url; }
  310. }
  311. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  312. const billsTag = $.billsTag({
  313. selector: '#bills-tag',
  314. relaSpread: slSpread,
  315. updateUrl: window.location.pathname + '/tag',
  316. afterModify: function (nodes) {
  317. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  318. },
  319. afterLocated: function () {
  320. stagePosSpreadObj.loadCurPosData();
  321. },
  322. afterShow: function () {
  323. slSpread.refresh();
  324. if (spSpread) spSpread.refresh();
  325. },
  326. });
  327. const stageTreeSpreadObj = {
  328. loadExprToInput(sheet) {
  329. const sel = sheet.getSelections()[0];
  330. const col = sheet.zh_setting.cols[sel.col];
  331. if (col.type === 'Number') {
  332. const data = SpreadJsObj.getSelectObject(sheet);
  333. if (!data) {
  334. $('#bills-expr').val('');
  335. return;
  336. }
  337. const nodePos = stagePos.getLedgerPos(data.id);
  338. if (nodePos && nodePos.length > 0) {
  339. $('#bills-expr').val('');
  340. } else {
  341. const exprInfo = getExprInfo(col.field);
  342. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  343. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  344. }
  345. } else {
  346. $('#bills-expr').val('');
  347. }
  348. },
  349. selectionChanged: function (e, info) {
  350. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  351. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  352. stagePosSpreadObj.loadCurPosData();
  353. if (posSearch) {
  354. posSearch.search();
  355. }
  356. }
  357. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  358. stageTreeSpreadObj.loadExprToInput(info.sheet);
  359. },
  360. topRowChanged(e, info) {
  361. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  362. },
  363. };
  364. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  365. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  366. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  367. $.contextMenu({
  368. selector: '#stage-ledger',
  369. build: function ($trigger, e) {
  370. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  371. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  372. },
  373. items: {
  374. 'locateZjjl': {
  375. name: '定位至中间计量',
  376. icon: 'fa-sign-in',
  377. callback: function (key, opt) {
  378. if (!detail) {
  379. detail = new Detail($('#detail-spread'));
  380. }
  381. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  382. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  383. if (leafUsedBills) {
  384. if (!$('#zhongjian').hasClass('active')) {
  385. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  386. $('a', '.side-menu').removeClass('active');
  387. $('.tab-content .tab-select-show').removeClass('active');
  388. tab.addClass('active');
  389. tabPanel.addClass('active');
  390. showSideTools(tab.hasClass('active'));
  391. slSpread.refresh();
  392. spSpread.refresh();
  393. }
  394. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  395. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  396. SpreadJsObj.locateData(detail.sheet, im);
  397. detail.spread.refresh();
  398. $('#zhongjian .sjs-bottom').height('400px');
  399. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  400. detail.reLoadDetailData();
  401. } else {
  402. toastr.error('无可定位中间计量');
  403. }
  404. },
  405. },
  406. tagSpr: '----',
  407. tag: {
  408. name: '书签',
  409. callback: function (key, opt, menu, e) {
  410. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  411. addTag.do(node);
  412. },
  413. disabled: function (key, opt) {
  414. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  415. return !node;
  416. }
  417. },
  418. showSpr: '----',
  419. showLast: {
  420. name: '显示至最底层',
  421. callback: function (key, opt, menu, e) {
  422. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  423. setTimeout(() => {
  424. showWaitingView();
  425. stageTree.expandByCustom(x => {
  426. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  427. });
  428. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  429. closeWaitingView();
  430. }, 100);
  431. },
  432. },
  433. exportSpr: '----',
  434. exportSelectNodeXlsx: {
  435. name: '导出选中节点至Excel',
  436. callback: function (key, opt, menu, e) {
  437. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  438. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  439. },
  440. disabled: function (key, opt) {
  441. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  442. return !node;
  443. }
  444. },
  445. }
  446. });
  447. const stagePosSpreadObj = {
  448. loadExprToInput(sheet) {
  449. const sel = sheet.getSelections()[0];
  450. if (!sel) return;
  451. const col = sheet.zh_setting.cols[sel.col];
  452. if (col && col.type === 'Number') {
  453. const data = SpreadJsObj.getSelectObject(sheet);
  454. if (data) {
  455. const exprInfo = getExprInfo(col.field);
  456. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  457. $('#pos-expr').val(value);
  458. } else {
  459. $('#pos-expr').val('');
  460. }
  461. } else {
  462. $('#pos-expr').val('');
  463. }
  464. },
  465. /**
  466. * 加载计量单元 根据当前台账选择节点
  467. */
  468. loadCurPosData: function () {
  469. const sheet = slSpread.getActiveSheet();
  470. const node = SpreadJsObj.getSelectObject(sheet);
  471. if (node) {
  472. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  473. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  474. getNodeList(node.id);
  475. // 如果是附件是当前节点,隐藏
  476. // if ($('#dqjiedian').hasClass('active')) {
  477. // $('#showAttachment').hide();
  478. // }
  479. } else {
  480. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  481. }
  482. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  483. },
  484. selectionChanged: function (e, info) {
  485. stagePosSpreadObj.loadExprToInput(info.sheet);
  486. },
  487. };
  488. // 加载上下窗口resizer
  489. $.divResizer({
  490. select: '#main-resize',
  491. callback: function () {
  492. slSpread.refresh();
  493. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  494. $(".sp-wrap").height(bcontent-30);
  495. spSpread.refresh();
  496. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  497. }
  498. });
  499. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  500. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag' }, function (result) {
  501. // 加载树结构
  502. stageTree.loadDatas(result.ledgerData);
  503. treeCalc.calculateAll(stageTree);
  504. for (const t of result.tags) {
  505. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  506. }
  507. billsTag.loadDatas(result.tags);
  508. // 加载部位明细
  509. stagePos.loadDatas(result.posData);
  510. stagePos.calculateAll();
  511. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  512. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  513. stagePosSpreadObj.loadCurPosData();
  514. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  515. // 加载中间计量
  516. stageIm.init(relaStage, imType, tenderInfo.decimal);
  517. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  518. }, null, true);
  519. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  520. $.subMenu({
  521. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  522. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  523. key: 'menu.1.0.0',
  524. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  525. callback: function (info) {
  526. if (info.mini) {
  527. $('.panel-title').addClass('fluid');
  528. $('#sub-menu').removeClass('panel-sidebar');
  529. } else {
  530. $('.panel-title').removeClass('fluid');
  531. $('#sub-menu').addClass('panel-sidebar');
  532. }
  533. autoFlashHeight();
  534. slSpread.refresh();
  535. spSpread.refresh();
  536. if (searchLedger) searchLedger.spread.refresh();
  537. if (detail) detail.spread.refresh();
  538. }
  539. });
  540. const posSearch = (function () {
  541. let resultArr = [];
  542. const search = function () {
  543. resultArr = [];
  544. const keyword = $('#pos-search-keyword').val();
  545. const checkOver = $('#pos-over-search')[0].checked;
  546. const checkEmpty = $('#pos-empty-search')[0].checked;
  547. const sortData = spSpread.getActiveSheet().zh_data;
  548. if (checkOver || checkEmpty) {
  549. if (sortData) {
  550. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  551. const sd = sortData[i];
  552. let match = false;
  553. if (checkOver) {
  554. if (sd.end_gather_qty) {
  555. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  556. }
  557. }
  558. if (checkEmpty) {
  559. if (sd.quantity) {
  560. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  561. }
  562. }
  563. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  564. if (match) {
  565. resultArr.push({index: i, data: sd});
  566. }
  567. }
  568. }
  569. } else if (keyword && keyword !== '') {
  570. if (sortData) {
  571. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  572. const sd = sortData[i];
  573. if (sd.name && sd.name.indexOf(keyword) > -1) {
  574. resultArr.push({index: i, data: sd});
  575. }
  576. }
  577. }
  578. }
  579. $('#pos-search-result').html('结果:' + resultArr.length);
  580. };
  581. const searchAndLocate = function () {
  582. search();
  583. if (resultArr.length > 0) {
  584. const sheet = spSpread.getActiveSheet();
  585. const sel = sheet.getSelections()[0];
  586. const curRow = sel ? sel.row : 0;
  587. const pos = resultArr[0];
  588. if (pos.index !== curRow) {
  589. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  590. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  591. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  592. }
  593. }
  594. };
  595. const locateNext = function () {
  596. if (resultArr.length > 0) {
  597. const sheet = spSpread.getActiveSheet();
  598. const sel = sheet.getSelections()[0];
  599. const curRow = sel ? sel.row : 0;
  600. let next = _.find(resultArr, function (d) {
  601. return d.index > curRow;
  602. });
  603. if (!next) next = resultArr[0];
  604. if (next.index !== curRow) {
  605. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  606. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  607. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  608. }
  609. }
  610. };
  611. const locatePre = function () {
  612. if (resultArr.length > 0) {
  613. const sheet = spSpread.getActiveSheet();
  614. const sel = sheet.getSelections()[0];
  615. const curRow = sel ? sel.row : 0;
  616. let next = _.findLast(resultArr, function (d) {
  617. return d.index < curRow;
  618. });
  619. if (!next) next = resultArr[resultArr.length - 1];
  620. if (next.index !== curRow) {
  621. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  622. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  623. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  624. }
  625. }
  626. };
  627. return {search, searchAndLocate, locateNext, locatePre};
  628. })();
  629. $('#pos-search-keyword').bind('keydown', function(e){
  630. if (e.keyCode == 13) posSearch.searchAndLocate();
  631. });
  632. $('#pos-empty-search').click(function () {
  633. if (this.checked) {
  634. $('[for=' + this.id +']').addClass('text-warning');
  635. } else {
  636. $('[for=' + this.id +']').removeClass('text-warning');
  637. }
  638. if (this.checked) {
  639. if ($('#pos-over-search')[0].checked) {
  640. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  641. } else {
  642. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  643. }
  644. } else {
  645. if ($('#pos-over-search')[0].checked) {
  646. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  647. } else {
  648. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  649. }
  650. }
  651. posSearch.searchAndLocate();
  652. });
  653. $('#pos-over-search').click(function () {
  654. if (this.checked) {
  655. $('[for=' + this.id +']').addClass('text-danger');
  656. } else {
  657. $('[for=' + this.id +']').removeClass('text-danger');
  658. }
  659. if (this.checked) {
  660. if ($('#pos-empty-search')[0].checked) {
  661. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  662. } else {
  663. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  664. }
  665. } else {
  666. if ($('#pos-empty-search')[0].checked) {
  667. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  668. } else {
  669. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  670. }
  671. }
  672. posSearch.searchAndLocate();
  673. });
  674. $('#pos-search-next').click(() => {posSearch.locateNext()});
  675. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  676. $.divResizer({
  677. select: '#right-spr',
  678. callback: function () {
  679. slSpread.refresh();
  680. spSpread.refresh();
  681. if (searchLedger) {
  682. searchLedger.spread.refresh();
  683. }
  684. if (detail) {
  685. detail.spread.refresh();
  686. }
  687. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  688. }
  689. });
  690. // 中间计量加载上下窗口resizer
  691. $.divResizer({
  692. select: '#zhongjian-spr',
  693. callback: function () {
  694. if (detail) {
  695. detail.spread.refresh();
  696. }
  697. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  698. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  699. }
  700. });
  701. // 附件加载上下窗口resizer
  702. $.divResizer({
  703. select: '#file-spr',
  704. callback: function () {
  705. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  706. }
  707. });
  708. class Detail {
  709. constructor (obj) {
  710. const self = this;
  711. this.spreadSetting = {
  712. cols: [
  713. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  714. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@'},
  715. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  716. {
  717. title: relaStage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  718. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@'
  719. },
  720. ],
  721. headRows: 1,
  722. emptyRows: 0,
  723. headRowHeight: [32],
  724. headColWidth: [30],
  725. defaultRowHeight: 21,
  726. headerFont: '12px 微软雅黑',
  727. font: '12px 微软雅黑',
  728. readOnly: true,
  729. selectedBackColor: '#fffacd',
  730. };
  731. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  732. this.sheet = this.spread.getActiveSheet();
  733. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  734. this.detailObj = {
  735. selectionChanged: function (e, info) {
  736. self.reLoadDetailData();
  737. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  738. self.loadLocateInfo();
  739. }
  740. },
  741. };
  742. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  743. this._initLocateRela();
  744. this.reBuildImData();
  745. }
  746. _initImTypeSetRela() {
  747. const self = this;
  748. const gatherConfirmPopover = {
  749. reBind: function (obj, eventName, fun) {
  750. obj.unbind(eventName);
  751. obj.bind(eventName, fun);
  752. },
  753. check: function (pos, hint, okCallback) {
  754. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  755. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  756. this.reBind(cancelObj, 'click', function () {
  757. confirmObj.hide();
  758. });
  759. this.reBind(okObj, 'click', function () {
  760. okCallback();
  761. confirmObj.hide();
  762. });
  763. hintObj.text(hint);
  764. confirmObj.css("top", pos.y).css("left", pos.x).show();
  765. }
  766. };
  767. this.gsTree = stageIm.getGsTree();
  768. if (relaStage.im_type === imType.tz.value || relaStage.im_type === imType.bb.value) {
  769. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  770. jlCol.title = '本期计量金额';
  771. SpreadJsObj.reLoadSheetHeader(self.sheet);
  772. $('#type-title-contract').text('本期合同计量金额');
  773. $('#type-title-qc').text('本期变更计量金额');
  774. } else {
  775. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  776. jlCol.title = '本期计量数量';
  777. SpreadJsObj.reLoadSheetHeader(self.sheet);
  778. $('#type-title-contract').text('本期合同计量数量');
  779. $('#type-title-qc').text('本期变更计量数量');
  780. }
  781. if (relaStage.im_type === imType.bb.value || relaStage.im_type === imType.bw.value) {
  782. $('#show-jldy').parent().show();
  783. $('#jldy').parent().show();
  784. $('#show-xm-name').parent().hide();
  785. $('#xm-name').parent().hide();
  786. } else {
  787. $('#show-jldy').parent().hide();
  788. $('#jldy').parent().hide();
  789. $('#show-xm-name').parent().show();
  790. $('#xm-name').parent().show();
  791. }
  792. }
  793. _initLocateRela() {
  794. const self = this;
  795. $('#im-locate2bills').click(function () {
  796. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  797. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  798. if (select && select.source) {
  799. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  800. stagePosSpreadObj.loadCurPosData();
  801. }
  802. });
  803. $('#im-locate-pre').click(function () {
  804. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  805. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  806. if (select && select.source) {
  807. const targetIndex = math.max(curIndex-1, 1);
  808. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  809. stagePosSpreadObj.loadCurPosData();
  810. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  811. }
  812. });
  813. $('#im-locate-next').click(function () {
  814. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  815. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  816. if (select && select.source) {
  817. const targetIndex = math.min(curIndex+1, select.source.length);
  818. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  819. stagePosSpreadObj.loadCurPosData();
  820. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  821. }
  822. });
  823. }
  824. loadLocateInfo() {
  825. const select = SpreadJsObj.getSelectObject(this.sheet);
  826. if (select && select.source.length > 1) {
  827. $('#im-locate2bills').next().show();
  828. } else {
  829. $('#im-locate2bills').next().hide();
  830. }
  831. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  832. }
  833. reLoadDetailData() {
  834. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  835. $('#detail-show').show();
  836. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  837. $('#show-contract-jl').text(contractJl);
  838. $('#contract-jl').val(contractJl);
  839. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  840. $('#show-qc-jl').text(qcJl);
  841. $('#qc-jl').val(qcJl);
  842. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  843. $('#show-bgl-code').text(bglCode);
  844. $('#bgl-code').val(bglCode);
  845. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  846. $('#show-bgl-drawing-code').text(bglDrawingCode);
  847. $('#bgl-drawing-code').val(bglDrawingCode);
  848. const bwName = data && data.bw ? data.bw : '';
  849. $('#show-bw-name').text(bwName);
  850. $('#bw-name').val(bwName);
  851. const position = data && data.position ? data.position : '';
  852. $('#show-position').text(position);
  853. $('#position').val(position);
  854. const peg = data && data.peg ? data.peg : '';
  855. $('#show-peg').text(peg);
  856. $('#peg').val(peg);
  857. const xmName = data && data.xm ? data.xm: '';
  858. $('#show-xm-name').text(xmName);
  859. $('#xm-name').val(xmName);
  860. const jldy = data && data.jldy ? data.jldy: '';
  861. $('#show-jldy').text(jldy);
  862. $('#jldy').val(jldy);
  863. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  864. $('#show-drawing-code').text(drawingCode);
  865. $('#drawing-code').val(drawingCode);
  866. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  867. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  868. $('#calc-memo').val(calcMemo);
  869. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  870. $('#show-calc-img').attr('src', calcImgSrc);
  871. $('#calc-img').attr('src', calcImgSrc);
  872. $('#view-calc-img').attr('src', calcImgSrc);
  873. const calcImgRemark = data && data.calc_img_remark || '';
  874. $('#view-calc-remark').val(calcImgRemark);
  875. $("#view-calc-remark").attr('readonly', true);
  876. $('#text-edit').val(calcImgRemark)
  877. }
  878. reBuildImData() {
  879. const imData = stageIm.buildImData();
  880. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  881. this.reLoadDetailData();
  882. this.loadLocateInfo();
  883. }
  884. }
  885. // 展开收起附件
  886. $('a', '.right-nav').bind('click', function () {
  887. //const main = $('#main-view'), tool = $('#tools-view');
  888. const tab = $(this), tabPanel = $(tab.attr('content'));
  889. if (!tab.hasClass('active')) {
  890. $('a', '.side-menu').removeClass('active');
  891. $('.tab-content .tab-select-show').removeClass('active');
  892. tab.addClass('active');
  893. tabPanel.addClass('active');
  894. showSideTools(tab.hasClass('active'));
  895. if (tab.attr('content') === '#search' && !searchLedger) {
  896. searchLedger = $.billsSearch({
  897. selector: '#search',
  898. searchSpread: slSpread,
  899. searchRangeStr: '项目节编号/名称',
  900. searchOver: true,
  901. searchEmpty: true,
  902. resultSpreadSetting: {
  903. cols: [
  904. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  905. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  906. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  907. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  908. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  909. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  910. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  911. ],
  912. emptyRows: 0,
  913. headRows: 1,
  914. headRowHeight: [32],
  915. headColWidth: [30],
  916. defaultRowHeight: 21,
  917. headerFont: '12px 微软雅黑',
  918. font: '12px 微软雅黑',
  919. selectedBackColor: '#fffacd',
  920. },
  921. afterLocated: function () {
  922. stagePosSpreadObj.loadCurPosData();
  923. },
  924. customSearch: [
  925. {
  926. key: 'less', title: '漏计', valid: true,
  927. check: function (node) {
  928. if (node.quantity) {
  929. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  930. } else if (node.total_price) {
  931. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  932. }
  933. }
  934. }, {
  935. key: 'over', title: '超计', valid: true,
  936. check: function (node) {
  937. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  938. }
  939. }, {
  940. key: 'empty', title: '漏计', valid: false,
  941. check: function (node) {
  942. if (node.quantity) {
  943. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  944. } else if (node.total_price) {
  945. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  946. }
  947. }
  948. }, {
  949. key: 'estimate', title: '预计变更', valid: true,
  950. check: function (node) {
  951. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  952. if (posRange.length > 0) {
  953. for (const p of posRange) {
  954. if (!checkZero(p.estimate_qty)) return true;
  955. }
  956. return false;
  957. } else {
  958. return false;
  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).prop('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. const url = `/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  1092. $('#zipDown').attr('href', url);
  1093. $("#zipDown")[0].click();
  1094. }
  1095. });
  1096. // 监听附件check是否选中
  1097. $('.list-table').on('click', '.check-file', function() {
  1098. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  1099. const childs = $(this).parents('.list-table').children().length;
  1100. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  1101. if (checkedList.length === childs) {
  1102. checkBox.prop("checked", true);
  1103. } else {
  1104. checkBox.prop("checked", false);
  1105. }
  1106. });
  1107. $('.check-all-file').click(function() {
  1108. const isCheck = $(this).is(':checked');
  1109. $(this).parents('table').find('.list-table').each(function() {
  1110. $(this).find('input:checkbox').prop("checked", isCheck);
  1111. })
  1112. });
  1113. // 显示层次
  1114. (function (select, sheet) {
  1115. $(select).click(function () {
  1116. if (!sheet.zh_tree) return;
  1117. const tag = $(this).attr('tag');
  1118. const tree = sheet.zh_tree;
  1119. setTimeout(() => {
  1120. showWaitingView();
  1121. switch (tag) {
  1122. case "1":
  1123. case "2":
  1124. case "3":
  1125. case "4":
  1126. case "5":
  1127. tree.expandByLevel(parseInt(tag));
  1128. SpreadJsObj.refreshTreeRowVisible(sheet);
  1129. break;
  1130. case "last":
  1131. tree.expandByCustom(() => { return true; });
  1132. SpreadJsObj.refreshTreeRowVisible(sheet);
  1133. break;
  1134. case "leafXmj":
  1135. tree.expandToLeafXmj();
  1136. SpreadJsObj.refreshTreeRowVisible(sheet);
  1137. break;
  1138. case "curMeasure":
  1139. tree.expandByCustom(function (node) {
  1140. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1141. if (node[field]) {
  1142. return true;
  1143. }
  1144. }
  1145. return false;
  1146. });
  1147. SpreadJsObj.refreshTreeRowVisible(sheet);
  1148. break;
  1149. }
  1150. closeWaitingView();
  1151. }, 100);
  1152. });
  1153. })('a[name=showLevel]', slSpread.getActiveSheet());
  1154. });