sr_detail.js 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  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. afterModify: function (nodes) {
  318. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  319. },
  320. afterLocated: function () {
  321. stagePosSpreadObj.loadCurPosData();
  322. },
  323. afterShow: function () {
  324. slSpread.refresh();
  325. if (spSpread) spSpread.refresh();
  326. },
  327. });
  328. const stageTreeSpreadObj = {
  329. loadExprToInput(sheet) {
  330. const sel = sheet.getSelections()[0];
  331. const col = sheet.zh_setting.cols[sel.col];
  332. if (col.type === 'Number') {
  333. const data = SpreadJsObj.getSelectObject(sheet);
  334. if (!data) {
  335. $('#bills-expr').val('');
  336. return;
  337. }
  338. const nodePos = stagePos.getLedgerPos(data.id);
  339. if (nodePos && nodePos.length > 0) {
  340. $('#bills-expr').val('');
  341. } else {
  342. const exprInfo = getExprInfo(col.field);
  343. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  344. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  345. }
  346. } else {
  347. $('#bills-expr').val('');
  348. }
  349. },
  350. selectionChanged: function (e, info) {
  351. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  352. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  353. stagePosSpreadObj.loadCurPosData();
  354. if (posSearch) {
  355. posSearch.search();
  356. }
  357. }
  358. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  359. stageTreeSpreadObj.loadExprToInput(info.sheet);
  360. },
  361. topRowChanged(e, info) {
  362. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  363. },
  364. };
  365. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  366. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  367. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  368. $.contextMenu({
  369. selector: '#stage-ledger',
  370. build: function ($trigger, e) {
  371. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  372. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  373. },
  374. items: {
  375. 'locateZjjl': {
  376. name: '定位至中间计量',
  377. icon: 'fa-sign-in',
  378. callback: function (key, opt) {
  379. if (!detail) {
  380. detail = new Detail($('#detail-spread'));
  381. }
  382. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  383. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  384. if (leafUsedBills) {
  385. if (!$('#zhongjian').hasClass('active')) {
  386. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  387. $('a', '.side-menu').removeClass('active');
  388. $('.tab-content .tab-select-show').removeClass('active');
  389. tab.addClass('active');
  390. tabPanel.addClass('active');
  391. showSideTools(tab.hasClass('active'));
  392. slSpread.refresh();
  393. spSpread.refresh();
  394. }
  395. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  396. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  397. SpreadJsObj.locateData(detail.sheet, im);
  398. detail.spread.refresh();
  399. $('#zhongjian .sjs-bottom').height('400px');
  400. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  401. detail.reLoadDetailData();
  402. } else {
  403. toastr.error('无可定位中间计量');
  404. }
  405. },
  406. },
  407. tagSpr: '----',
  408. tag: {
  409. name: '书签',
  410. callback: function (key, opt, menu, e) {
  411. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  412. addTag.do(node);
  413. },
  414. disabled: function (key, opt) {
  415. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  416. return !node;
  417. }
  418. },
  419. showSpr: '----',
  420. showLast: {
  421. name: '显示至最底层',
  422. callback: function (key, opt, menu, e) {
  423. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  424. setTimeout(() => {
  425. showWaitingView();
  426. stageTree.expandByCustom(x => {
  427. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  428. });
  429. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  430. closeWaitingView();
  431. }, 100);
  432. },
  433. },
  434. exportSpr: '----',
  435. exportSelectNodeXlsx: {
  436. name: '导出选中节点至Excel',
  437. callback: function (key, opt, menu, e) {
  438. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  439. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  440. },
  441. disabled: function (key, opt) {
  442. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  443. return !node;
  444. }
  445. },
  446. }
  447. });
  448. const stagePosSpreadObj = {
  449. loadExprToInput(sheet) {
  450. const sel = sheet.getSelections()[0];
  451. if (!sel) return;
  452. const col = sheet.zh_setting.cols[sel.col];
  453. if (col && col.type === 'Number') {
  454. const data = SpreadJsObj.getSelectObject(sheet);
  455. if (data) {
  456. const exprInfo = getExprInfo(col.field);
  457. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  458. $('#pos-expr').val(value);
  459. } else {
  460. $('#pos-expr').val('');
  461. }
  462. } else {
  463. $('#pos-expr').val('');
  464. }
  465. },
  466. /**
  467. * 加载计量单元 根据当前台账选择节点
  468. */
  469. loadCurPosData: function () {
  470. const sheet = slSpread.getActiveSheet();
  471. const node = SpreadJsObj.getSelectObject(sheet);
  472. if (node) {
  473. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  474. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  475. getNodeList(node.id);
  476. // 如果是附件是当前节点,隐藏
  477. // if ($('#dqjiedian').hasClass('active')) {
  478. // $('#showAttachment').hide();
  479. // }
  480. } else {
  481. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  482. }
  483. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  484. },
  485. selectionChanged: function (e, info) {
  486. stagePosSpreadObj.loadExprToInput(info.sheet);
  487. },
  488. };
  489. // 加载上下窗口resizer
  490. $.divResizer({
  491. select: '#main-resize',
  492. callback: function () {
  493. slSpread.refresh();
  494. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  495. $(".sp-wrap").height(bcontent-30);
  496. spSpread.refresh();
  497. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  498. }
  499. });
  500. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  501. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;sumDeal' }, function (result) {
  502. for (const l of result.ledgerData) {
  503. const sd = result.sumDeal.find(x => { return x.code === l.b_code && x.name === l.name && x.unit === l.unit; });
  504. if (sd) {
  505. l.unit_price = sd.unit_price;
  506. l.deal_tp = ZhCalc.mul(l.unit_price, l.deal_qty, tenderInfo.decimal.tp);
  507. l.sgfh_tp = ZhCalc.mul(l.unit_price, l.sgfh_qty, tenderInfo.decimal.tp);
  508. l.sjcl_tp = ZhCalc.mul(l.unit_price, l.sjcl_qty, tenderInfo.decimal.tp);
  509. l.qtcl_tp = ZhCalc.mul(l.unit_price, l.qtcl_qty, tenderInfo.decimal.tp);
  510. l.total_price = ZhCalc.mul(l.unit_price, l.quantity, tenderInfo.decimal.tp);
  511. }
  512. }
  513. // 加载树结构
  514. stageTree.loadDatas(result.ledgerData);
  515. treeCalc.calculateAll(stageTree);
  516. for (const t of result.tags) {
  517. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  518. }
  519. billsTag.loadDatas(result.tags);
  520. // 加载部位明细
  521. stagePos.loadDatas(result.posData);
  522. stagePos.calculateAll();
  523. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  524. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  525. stagePosSpreadObj.loadCurPosData();
  526. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  527. // 加载中间计量
  528. stageIm.init(relaStage, imType, tenderInfo.decimal);
  529. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  530. }, null, true);
  531. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  532. $.subMenu({
  533. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  534. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  535. key: 'menu.1.0.0',
  536. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  537. callback: function (info) {
  538. if (info.mini) {
  539. $('.panel-title').addClass('fluid');
  540. $('#sub-menu').removeClass('panel-sidebar');
  541. } else {
  542. $('.panel-title').removeClass('fluid');
  543. $('#sub-menu').addClass('panel-sidebar');
  544. }
  545. autoFlashHeight();
  546. slSpread.refresh();
  547. spSpread.refresh();
  548. if (searchLedger) searchLedger.spread.refresh();
  549. if (detail) detail.spread.refresh();
  550. }
  551. });
  552. const posSearch = (function () {
  553. let resultArr = [];
  554. const search = function () {
  555. resultArr = [];
  556. const keyword = $('#pos-search-keyword').val();
  557. const checkOver = $('#pos-over-search')[0].checked;
  558. const checkEmpty = $('#pos-empty-search')[0].checked;
  559. const sortData = spSpread.getActiveSheet().zh_data;
  560. if (checkOver || checkEmpty) {
  561. if (sortData) {
  562. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  563. const sd = sortData[i];
  564. let match = false;
  565. if (checkOver) {
  566. if (sd.end_gather_qty) {
  567. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  568. }
  569. }
  570. if (checkEmpty) {
  571. if (sd.quantity) {
  572. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  573. }
  574. }
  575. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  576. if (match) {
  577. resultArr.push({index: i, data: sd});
  578. }
  579. }
  580. }
  581. } else if (keyword && keyword !== '') {
  582. if (sortData) {
  583. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  584. const sd = sortData[i];
  585. if (sd.name && sd.name.indexOf(keyword) > -1) {
  586. resultArr.push({index: i, data: sd});
  587. }
  588. }
  589. }
  590. }
  591. $('#pos-search-result').html('结果:' + resultArr.length);
  592. };
  593. const searchAndLocate = function () {
  594. search();
  595. if (resultArr.length > 0) {
  596. const sheet = spSpread.getActiveSheet();
  597. const sel = sheet.getSelections()[0];
  598. const curRow = sel ? sel.row : 0;
  599. const pos = resultArr[0];
  600. if (pos.index !== curRow) {
  601. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  602. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  603. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  604. }
  605. }
  606. };
  607. const locateNext = function () {
  608. if (resultArr.length > 0) {
  609. const sheet = spSpread.getActiveSheet();
  610. const sel = sheet.getSelections()[0];
  611. const curRow = sel ? sel.row : 0;
  612. let next = _.find(resultArr, function (d) {
  613. return d.index > curRow;
  614. });
  615. if (!next) next = resultArr[0];
  616. if (next.index !== curRow) {
  617. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  618. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  619. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  620. }
  621. }
  622. };
  623. const locatePre = function () {
  624. if (resultArr.length > 0) {
  625. const sheet = spSpread.getActiveSheet();
  626. const sel = sheet.getSelections()[0];
  627. const curRow = sel ? sel.row : 0;
  628. let next = _.findLast(resultArr, function (d) {
  629. return d.index < curRow;
  630. });
  631. if (!next) next = resultArr[resultArr.length - 1];
  632. if (next.index !== curRow) {
  633. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  634. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  635. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  636. }
  637. }
  638. };
  639. return {search, searchAndLocate, locateNext, locatePre};
  640. })();
  641. $('#pos-search-keyword').bind('keydown', function(e){
  642. if (e.keyCode == 13) posSearch.searchAndLocate();
  643. });
  644. $('#pos-empty-search').click(function () {
  645. if (this.checked) {
  646. $('[for=' + this.id +']').addClass('text-warning');
  647. } else {
  648. $('[for=' + this.id +']').removeClass('text-warning');
  649. }
  650. if (this.checked) {
  651. if ($('#pos-over-search')[0].checked) {
  652. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  653. } else {
  654. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  655. }
  656. } else {
  657. if ($('#pos-over-search')[0].checked) {
  658. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  659. } else {
  660. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  661. }
  662. }
  663. posSearch.searchAndLocate();
  664. });
  665. $('#pos-over-search').click(function () {
  666. if (this.checked) {
  667. $('[for=' + this.id +']').addClass('text-danger');
  668. } else {
  669. $('[for=' + this.id +']').removeClass('text-danger');
  670. }
  671. if (this.checked) {
  672. if ($('#pos-empty-search')[0].checked) {
  673. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  674. } else {
  675. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  676. }
  677. } else {
  678. if ($('#pos-empty-search')[0].checked) {
  679. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  680. } else {
  681. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  682. }
  683. }
  684. posSearch.searchAndLocate();
  685. });
  686. $('#pos-search-next').click(() => {posSearch.locateNext()});
  687. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  688. $.divResizer({
  689. select: '#right-spr',
  690. callback: function () {
  691. slSpread.refresh();
  692. spSpread.refresh();
  693. if (searchLedger) {
  694. searchLedger.spread.refresh();
  695. }
  696. if (detail) {
  697. detail.spread.refresh();
  698. }
  699. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  700. }
  701. });
  702. // 中间计量加载上下窗口resizer
  703. $.divResizer({
  704. select: '#zhongjian-spr',
  705. callback: function () {
  706. if (detail) {
  707. detail.spread.refresh();
  708. }
  709. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  710. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  711. }
  712. });
  713. // 附件加载上下窗口resizer
  714. $.divResizer({
  715. select: '#file-spr',
  716. callback: function () {
  717. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  718. }
  719. });
  720. class Detail {
  721. constructor (obj) {
  722. const self = this;
  723. this.spreadSetting = {
  724. cols: [
  725. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  726. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@'},
  727. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  728. {
  729. title: relaStage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  730. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@'
  731. },
  732. ],
  733. headRows: 1,
  734. emptyRows: 0,
  735. headRowHeight: [32],
  736. headColWidth: [30],
  737. defaultRowHeight: 21,
  738. headerFont: '12px 微软雅黑',
  739. font: '12px 微软雅黑',
  740. readOnly: true,
  741. selectedBackColor: '#fffacd',
  742. };
  743. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  744. this.sheet = this.spread.getActiveSheet();
  745. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  746. this.detailObj = {
  747. selectionChanged: function (e, info) {
  748. self.reLoadDetailData();
  749. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  750. self.loadLocateInfo();
  751. }
  752. },
  753. };
  754. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  755. this._initLocateRela();
  756. this.reBuildImData();
  757. }
  758. _initImTypeSetRela() {
  759. const self = this;
  760. const gatherConfirmPopover = {
  761. reBind: function (obj, eventName, fun) {
  762. obj.unbind(eventName);
  763. obj.bind(eventName, fun);
  764. },
  765. check: function (pos, hint, okCallback) {
  766. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  767. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  768. this.reBind(cancelObj, 'click', function () {
  769. confirmObj.hide();
  770. });
  771. this.reBind(okObj, 'click', function () {
  772. okCallback();
  773. confirmObj.hide();
  774. });
  775. hintObj.text(hint);
  776. confirmObj.css("top", pos.y).css("left", pos.x).show();
  777. }
  778. };
  779. this.gsTree = stageIm.getGsTree();
  780. if (relaStage.im_type === imType.tz.value || relaStage.im_type === imType.bb.value) {
  781. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  782. jlCol.title = '本期计量金额';
  783. SpreadJsObj.reLoadSheetHeader(self.sheet);
  784. $('#type-title-contract').text('本期合同计量金额');
  785. $('#type-title-qc').text('本期变更计量金额');
  786. } else {
  787. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  788. jlCol.title = '本期计量数量';
  789. SpreadJsObj.reLoadSheetHeader(self.sheet);
  790. $('#type-title-contract').text('本期合同计量数量');
  791. $('#type-title-qc').text('本期变更计量数量');
  792. }
  793. if (relaStage.im_type === imType.bb.value || relaStage.im_type === imType.bw.value) {
  794. $('#show-jldy').parent().show();
  795. $('#jldy').parent().show();
  796. $('#show-xm-name').parent().hide();
  797. $('#xm-name').parent().hide();
  798. } else {
  799. $('#show-jldy').parent().hide();
  800. $('#jldy').parent().hide();
  801. $('#show-xm-name').parent().show();
  802. $('#xm-name').parent().show();
  803. }
  804. }
  805. _initLocateRela() {
  806. const self = this;
  807. $('#im-locate2bills').click(function () {
  808. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  809. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  810. if (select && select.source) {
  811. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  812. stagePosSpreadObj.loadCurPosData();
  813. }
  814. });
  815. $('#im-locate-pre').click(function () {
  816. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  817. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  818. if (select && select.source) {
  819. const targetIndex = math.max(curIndex-1, 1);
  820. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  821. stagePosSpreadObj.loadCurPosData();
  822. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  823. }
  824. });
  825. $('#im-locate-next').click(function () {
  826. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  827. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  828. if (select && select.source) {
  829. const targetIndex = math.min(curIndex+1, select.source.length);
  830. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  831. stagePosSpreadObj.loadCurPosData();
  832. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  833. }
  834. });
  835. }
  836. loadLocateInfo() {
  837. const select = SpreadJsObj.getSelectObject(this.sheet);
  838. if (select && select.source.length > 1) {
  839. $('#im-locate2bills').next().show();
  840. } else {
  841. $('#im-locate2bills').next().hide();
  842. }
  843. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  844. }
  845. reLoadDetailData() {
  846. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  847. $('#detail-show').show();
  848. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  849. $('#show-contract-jl').text(contractJl);
  850. $('#contract-jl').val(contractJl);
  851. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  852. $('#show-qc-jl').text(qcJl);
  853. $('#qc-jl').val(qcJl);
  854. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  855. $('#show-bgl-code').text(bglCode);
  856. $('#bgl-code').val(bglCode);
  857. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  858. $('#show-bgl-drawing-code').text(bglDrawingCode);
  859. $('#bgl-drawing-code').val(bglDrawingCode);
  860. const bwName = data && data.bw ? data.bw : '';
  861. $('#show-bw-name').text(bwName);
  862. $('#bw-name').val(bwName);
  863. const position = data && data.position ? data.position : '';
  864. $('#show-position').text(position);
  865. $('#position').val(position);
  866. const peg = data && data.peg ? data.peg : '';
  867. $('#show-peg').text(peg);
  868. $('#peg').val(peg);
  869. const xmName = data && data.xm ? data.xm: '';
  870. $('#show-xm-name').text(xmName);
  871. $('#xm-name').val(xmName);
  872. const jldy = data && data.jldy ? data.jldy: '';
  873. $('#show-jldy').text(jldy);
  874. $('#jldy').val(jldy);
  875. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  876. $('#show-drawing-code').text(drawingCode);
  877. $('#drawing-code').val(drawingCode);
  878. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  879. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  880. $('#calc-memo').val(calcMemo);
  881. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  882. $('#show-calc-img').attr('src', calcImgSrc);
  883. $('#calc-img').attr('src', calcImgSrc);
  884. $('#view-calc-img').attr('src', calcImgSrc);
  885. const calcImgRemark = data && data.calc_img_remark || '';
  886. $('#view-calc-remark').val(calcImgRemark);
  887. $("#view-calc-remark").attr('readonly', true);
  888. $('#text-edit').val(calcImgRemark)
  889. }
  890. reBuildImData() {
  891. const imData = stageIm.buildImData();
  892. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  893. this.reLoadDetailData();
  894. this.loadLocateInfo();
  895. }
  896. }
  897. // 展开收起附件
  898. $('a', '.right-nav').bind('click', function () {
  899. //const main = $('#main-view'), tool = $('#tools-view');
  900. const tab = $(this), tabPanel = $(tab.attr('content'));
  901. if (!tab.hasClass('active')) {
  902. $('a', '.side-menu').removeClass('active');
  903. $('.tab-content .tab-select-show').removeClass('active');
  904. tab.addClass('active');
  905. tabPanel.addClass('active');
  906. showSideTools(tab.hasClass('active'));
  907. if (tab.attr('content') === '#search' && !searchLedger) {
  908. searchLedger = $.billsSearch({
  909. selector: '#search',
  910. searchSpread: slSpread,
  911. searchRangeStr: '项目节编号/名称',
  912. searchOver: true,
  913. searchEmpty: true,
  914. resultSpreadSetting: {
  915. cols: [
  916. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  917. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  918. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  919. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  920. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  921. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  922. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  923. ],
  924. emptyRows: 0,
  925. headRows: 1,
  926. headRowHeight: [32],
  927. headColWidth: [30],
  928. defaultRowHeight: 21,
  929. headerFont: '12px 微软雅黑',
  930. font: '12px 微软雅黑',
  931. selectedBackColor: '#fffacd',
  932. },
  933. afterLocated: function () {
  934. stagePosSpreadObj.loadCurPosData();
  935. },
  936. customSearch: [
  937. {
  938. key: 'less', title: '漏计', valid: true,
  939. check: function (node) {
  940. if (node.quantity) {
  941. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  942. } else if (node.total_price) {
  943. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  944. }
  945. }
  946. }, {
  947. key: 'over', title: '超计', valid: true,
  948. check: function (node) {
  949. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  950. }
  951. }, {
  952. key: 'empty', title: '漏计', valid: false,
  953. check: function (node) {
  954. if (node.quantity) {
  955. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  956. } else if (node.total_price) {
  957. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  958. }
  959. }
  960. }, {
  961. key: 'estimate', title: '预计变更', valid: true,
  962. check: function (node) {
  963. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  964. if (posRange.length > 0) {
  965. for (const p of posRange) {
  966. if (!checkZero(p.estimate_qty)) return true;
  967. }
  968. return false;
  969. } else {
  970. return false;
  971. }
  972. }
  973. }
  974. ],
  975. });
  976. searchLedger.spread.refresh();
  977. }
  978. if (tab.attr('content') === '#fujian') {
  979. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  980. getNodeList(node.id);
  981. }
  982. if (tab.attr('content') === '#zhongjian') {
  983. if (!detail) {
  984. detail = new Detail($('#detail-spread'));
  985. detail.spread.refresh();
  986. $('#zhongjian .sjs-bottom').height('400px');
  987. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  988. } else {
  989. detail.spread.refresh();
  990. }
  991. }
  992. } else {
  993. tab.removeClass('active');
  994. tabPanel.removeClass('active');
  995. showSideTools(tab.hasClass('active'));
  996. }
  997. slSpread.refresh();
  998. spSpread.refresh();
  999. });
  1000. // 切换附件里节点和所有附件
  1001. $('#fujian .nav-link').on('click', function () {
  1002. const tabPanel = $(this).attr('fujian-content');
  1003. if (tabPanel !== 'syfujian') {
  1004. $('#showPage').hide();
  1005. $('#bach-download').prop('type', 'curr');
  1006. } else {
  1007. $('#showPage').show();
  1008. $('#bach-download').prop('type', 'all')
  1009. }
  1010. $('#showAttachment').hide();
  1011. });
  1012. // 获取附件信息
  1013. $('.list-table').on('click', '.att-file-name', function () {
  1014. const fid = $(this).attr('file-id');
  1015. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1016. return;
  1017. }
  1018. const att = attData.find(function (item) {
  1019. return item.id === parseInt(fid);
  1020. });
  1021. $('#edit-att').hide();
  1022. $('#show-att').show();
  1023. if (att !== undefined) {
  1024. // 进来先把编辑功能隐藏
  1025. $('#btn-att a').eq(3).hide()
  1026. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1027. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1028. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  1029. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  1030. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  1031. $('#show-att tr').eq(3).children('td').text(att.remark);
  1032. // 附件uid等于当前用户id, 附件上传本人
  1033. if (parseInt(cur_uid) === att.uid) {
  1034. $('#btn-att').show();
  1035. $('#btn-att a').eq(2).hide();
  1036. $('#btn-att a').eq(4).hide();
  1037. $('#btn-att a').eq(5).hide();
  1038. } else {
  1039. $('#btn-att').hide();
  1040. $('#btn-att a').eq(3).hide();
  1041. $('#btn-att a').eq(2).hide();
  1042. $('#btn-att a').eq(4).hide();
  1043. $('#btn-att a').eq(5).hide();
  1044. }
  1045. $('#showAttachment').attr('file-id', fid);
  1046. $('#showAttachment').show();
  1047. } else {
  1048. $('#showAttachment').hide();
  1049. $('#showAttachment').attr('file-id', '');
  1050. toastr.error('附件信息获取失败');
  1051. }
  1052. });
  1053. // $('body').on('click', '.alllist-table a', handleFileList);
  1054. $('body').on('click', '#btn-att a', function () {
  1055. const content = $(this).attr('content');
  1056. const fid = $('#showAttachment').attr('file-id');
  1057. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1058. if (content === 'view') {
  1059. const data = {id: fid};
  1060. postData('/tender/' + relaTender.id + '/measure/stage/' + relaStage.order + '/check/file', data, function (result) {
  1061. const { filepath } = result
  1062. $('#load-file').attr('href', filepath);
  1063. $('#load-file')[0].click();
  1064. });
  1065. } else if (content === 'location') {
  1066. const att = attData.find(item => item.id === parseInt(fid));
  1067. if (Object.keys(att).length) {
  1068. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  1069. stagePosSpreadObj.loadCurPosData();
  1070. }
  1071. }
  1072. });
  1073. // 切换页数
  1074. $('.page-select').on('click', function () {
  1075. const totalPageNum = parseInt($('#totalPage').text());
  1076. const lastPageNum = parseInt($('#currentPage').text());
  1077. const status = $(this).attr('content');
  1078. if (status === 'pre' && lastPageNum > 1) {
  1079. getAllList(lastPageNum-1);
  1080. $('#showAttachment').hide();
  1081. $('#syfujian .check-all-file').prop('checked', false)
  1082. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1083. getAllList(lastPageNum+1);
  1084. $('#showAttachment').hide();
  1085. $('#syfujian .check-all-file').prop('checked', false)
  1086. }
  1087. });
  1088. // 批量下载
  1089. $('#bach-download').click(function() {
  1090. const fileIds = [];
  1091. const type = $(this).prop('type');
  1092. let node = ''
  1093. if (type === 'curr') {
  1094. node = '#nodelist-table .check-file:checked'
  1095. } else {
  1096. node = '#alllist-table .check-file:checked'
  1097. }
  1098. $(node).each(function() {
  1099. const fileId = $(this).attr('file-id');
  1100. fileId && fileIds.push(fileId);
  1101. });
  1102. if (fileIds.length) {
  1103. const url = `/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  1104. $('#zipDown').attr('href', url);
  1105. $("#zipDown")[0].click();
  1106. }
  1107. });
  1108. // 监听附件check是否选中
  1109. $('.list-table').on('click', '.check-file', function() {
  1110. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  1111. const childs = $(this).parents('.list-table').children().length;
  1112. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  1113. if (checkedList.length === childs) {
  1114. checkBox.prop("checked", true);
  1115. } else {
  1116. checkBox.prop("checked", false);
  1117. }
  1118. });
  1119. $('.check-all-file').click(function() {
  1120. const isCheck = $(this).is(':checked');
  1121. $(this).parents('table').find('.list-table').each(function() {
  1122. $(this).find('input:checkbox').prop("checked", isCheck);
  1123. })
  1124. });
  1125. // 显示层次
  1126. (function (select, sheet) {
  1127. $(select).click(function () {
  1128. if (!sheet.zh_tree) return;
  1129. const tag = $(this).attr('tag');
  1130. const tree = sheet.zh_tree;
  1131. setTimeout(() => {
  1132. showWaitingView();
  1133. switch (tag) {
  1134. case "1":
  1135. case "2":
  1136. case "3":
  1137. case "4":
  1138. case "5":
  1139. tree.expandByLevel(parseInt(tag));
  1140. SpreadJsObj.refreshTreeRowVisible(sheet);
  1141. break;
  1142. case "last":
  1143. tree.expandByCustom(() => { return true; });
  1144. SpreadJsObj.refreshTreeRowVisible(sheet);
  1145. break;
  1146. case "leafXmj":
  1147. tree.expandToLeafXmj();
  1148. SpreadJsObj.refreshTreeRowVisible(sheet);
  1149. break;
  1150. case "curMeasure":
  1151. tree.expandByCustom(function (node) {
  1152. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1153. if (node[field]) {
  1154. return true;
  1155. }
  1156. }
  1157. return false;
  1158. });
  1159. SpreadJsObj.refreshTreeRowVisible(sheet);
  1160. break;
  1161. }
  1162. closeWaitingView();
  1163. }, 100);
  1164. });
  1165. })('a[name=showLevel]', slSpread.getActiveSheet());
  1166. });