sr_detail.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  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. if (col.field === 'gxby') data.gxby_url && window.open(data.gxby_url);
  201. };
  202. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  203. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  204. if (data) {
  205. if (col.field === 'gxby') {
  206. const def = thirdParty.gxby.find(function (x) {
  207. return x.value === data.gxby_status;
  208. });
  209. if (def && def.color) return def.color;
  210. } else if (col.field === 'dagl') {
  211. const def = thirdParty.dagl.find(function (x) {
  212. return x.value === data.dagl_status;
  213. });
  214. if (def && def.color) return def.color;
  215. }
  216. return checkUtils.billsOver(data, checkTzMeasureType(), stagePos) ? '#f8d7da' : defaultColor;
  217. } else {
  218. return defaultColor;
  219. }
  220. };
  221. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  222. sjsSettingObj.set3FCols(ledgerSpreadSetting.cols, [
  223. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  224. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  225. ]);
  226. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  227. ledgerSpreadSetting.headColWidth = [50];
  228. ledgerSpreadSetting.rowHeader = [
  229. {
  230. rowHeaderType: 'tag',
  231. setting: {
  232. indent: 14,
  233. tagSize: 0.8,
  234. tagFont: '8px 微软雅黑',
  235. getColor: function (index, data) {
  236. if (!data) return;
  237. return billsTag.getBillsTagsColor(data.id);
  238. },
  239. getTagHtml: function (index, data) {
  240. if (!data) return;
  241. const getHtml = function (list) {
  242. if (!list || list.length === 0) return '';
  243. const html = [];
  244. for (const l of list) {
  245. html.push('<div class="row mr-1">');
  246. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  247. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  248. html.push('</div>');
  249. }
  250. return html.join('');
  251. };
  252. return getHtml(billsTag.getBillsTagsInfo(data.id));
  253. }
  254. },
  255. },
  256. ];
  257. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  258. slSpread.getActiveSheet().frozenColumnCount(5);
  259. slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
  260. //初始化所有附件列表
  261. getAllList();
  262. // 初始化 计量单元 Spread
  263. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  264. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  265. spCol.cellType = 'activeImageBtn';
  266. spCol.normalImg = '#ellipsis-icon';
  267. spCol.indent = 5;
  268. spCol.showImage = function (data) {
  269. return data !== undefined && data !== null;
  270. };
  271. posSpreadSetting.imageClick = function (data, hitinfo) {
  272. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  273. if (col.field === 'dagl') data.dagl_url && window.open(data.dagl_url);
  274. if (col.field === 'gxby') data.gxby_url && window.open(data.gxby_url);
  275. };
  276. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  277. if (data) {
  278. if (col.field === 'gxby') {
  279. const def = thirdParty.gxby.find(function (x) {
  280. return x.value === data.gxby_status;
  281. });
  282. if (def && def.color) return def.color;
  283. } else if (col.field === 'dagl') {
  284. const def = thirdParty.dagl.find(function (x) {
  285. return x.value === data.dagl_status;
  286. });
  287. if (def && def.color) return def.color;
  288. }
  289. }
  290. if (checkTzMeasureType()) {
  291. return checkUtils.posOver(data) ? '#f8d7da' : defaultColor;
  292. }
  293. };
  294. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  295. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  296. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  297. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  298. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  299. ]);
  300. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  301. const billsTag = $.billsTag({
  302. selector: '#bills-tag',
  303. relaSpread: slSpread,
  304. updateUrl: window.location.pathname + '/tag',
  305. readOnly: true,
  306. afterModify: function (nodes) {
  307. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  308. },
  309. afterLocated: function () {
  310. stagePosSpreadObj.loadCurPosData();
  311. },
  312. afterShow: function () {
  313. slSpread.refresh();
  314. if (spSpread) spSpread.refresh();
  315. },
  316. });
  317. const stageTreeSpreadObj = {
  318. loadExprToInput(sheet) {
  319. const sel = sheet.getSelections()[0];
  320. const col = sheet.zh_setting.cols[sel.col];
  321. if (col.type === 'Number') {
  322. const data = SpreadJsObj.getSelectObject(sheet);
  323. if (!data) {
  324. $('#bills-expr').val('');
  325. return;
  326. }
  327. const nodePos = stagePos.getLedgerPos(data.id);
  328. if (nodePos && nodePos.length > 0) {
  329. $('#bills-expr').val('');
  330. } else {
  331. const exprInfo = getExprInfo(col.field);
  332. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  333. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  334. }
  335. } else {
  336. $('#bills-expr').val('');
  337. }
  338. },
  339. selectionChanged: function (e, info) {
  340. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  341. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  342. stagePosSpreadObj.loadCurPosData();
  343. if (posSearch) {
  344. posSearch.search();
  345. }
  346. }
  347. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  348. stageTreeSpreadObj.loadExprToInput(info.sheet);
  349. },
  350. topRowChanged(e, info) {
  351. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  352. },
  353. };
  354. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  355. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  356. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  357. $.contextMenu({
  358. selector: '#stage-ledger',
  359. build: function ($trigger, e) {
  360. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  361. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  362. },
  363. items: {
  364. 'locateZjjl': {
  365. name: '定位至中间计量',
  366. icon: 'fa-sign-in',
  367. callback: function (key, opt) {
  368. if (!detail) {
  369. detail = new Detail($('#detail-spread'));
  370. }
  371. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  372. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  373. if (leafUsedBills) {
  374. if (!$('#zhongjian').hasClass('active')) {
  375. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  376. $('a', '.side-menu').removeClass('active');
  377. $('.tab-content .tab-select-show').removeClass('active');
  378. tab.addClass('active');
  379. tabPanel.addClass('active');
  380. showSideTools(tab.hasClass('active'));
  381. slSpread.refresh();
  382. spSpread.refresh();
  383. }
  384. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  385. const im = stageIm.getRelaImData4Rela(relaXmj, leafUsedBills, usedPos);
  386. SpreadJsObj.locateData(detail.sheet, im);
  387. detail.spread.refresh();
  388. $('#zhongjian .sjs-bottom').height('400px');
  389. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  390. detail.reLoadDetailData();
  391. } else {
  392. toastr.error('无可定位中间计量');
  393. }
  394. },
  395. },
  396. tagSpr: '----',
  397. tag: {
  398. name: '书签',
  399. callback: function (key, opt, menu, e) {
  400. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  401. addTag.do(node);
  402. },
  403. disabled: function (key, opt) {
  404. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  405. return !node;
  406. }
  407. },
  408. showSpr: '----',
  409. showLast: {
  410. name: '显示至最底层',
  411. callback: function (key, opt, menu, e) {
  412. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  413. setTimeout(() => {
  414. showWaitingView();
  415. stageTree.expandByCustom(x => {
  416. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  417. });
  418. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  419. closeWaitingView();
  420. }, 100);
  421. },
  422. },
  423. exportSpr: '----',
  424. exportSelectNodeXlsx: {
  425. name: '导出选中节点至Excel',
  426. callback: function (key, opt, menu, e) {
  427. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  428. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  429. },
  430. disabled: function (key, opt) {
  431. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  432. return !node;
  433. }
  434. },
  435. }
  436. });
  437. const stagePosSpreadObj = {
  438. loadExprToInput(sheet) {
  439. const sel = sheet.getSelections()[0];
  440. if (!sel) return;
  441. const col = sheet.zh_setting.cols[sel.col];
  442. if (col && col.type === 'Number') {
  443. const data = SpreadJsObj.getSelectObject(sheet);
  444. if (data) {
  445. const exprInfo = getExprInfo(col.field);
  446. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  447. $('#pos-expr').val(value);
  448. } else {
  449. $('#pos-expr').val('');
  450. }
  451. } else {
  452. $('#pos-expr').val('');
  453. }
  454. },
  455. /**
  456. * 加载计量单元 根据当前台账选择节点
  457. */
  458. loadCurPosData: function () {
  459. const sheet = slSpread.getActiveSheet();
  460. const node = SpreadJsObj.getSelectObject(sheet);
  461. if (node) {
  462. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  463. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  464. getNodeList(node.id);
  465. // 如果是附件是当前节点,隐藏
  466. // if ($('#dqjiedian').hasClass('active')) {
  467. // $('#showAttachment').hide();
  468. // }
  469. } else {
  470. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  471. }
  472. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  473. },
  474. selectionChanged: function (e, info) {
  475. stagePosSpreadObj.loadExprToInput(info.sheet);
  476. },
  477. };
  478. // 加载上下窗口resizer
  479. $.divResizer({
  480. select: '#main-resize',
  481. callback: function () {
  482. slSpread.refresh();
  483. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  484. $(".sp-wrap").height(bcontent-30);
  485. spSpread.refresh();
  486. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  487. }
  488. });
  489. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  490. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;sumDeal' }, function (result) {
  491. for (const l of result.ledgerData) {
  492. if (!l.is_leaf) continue;
  493. const sd = result.sumDeal.find(x => { return x.code === l.b_code && x.name === l.name && x.unit === l.unit; });
  494. l.unit_price = sd ? sd.unit_price : 0;
  495. l.deal_tp = ZhCalc.mul(l.unit_price, l.deal_qty, tenderInfo.decimal.tp);
  496. l.sgfh_tp = ZhCalc.mul(l.unit_price, l.sgfh_qty, tenderInfo.decimal.tp);
  497. l.sjcl_tp = ZhCalc.mul(l.unit_price, l.sjcl_qty, tenderInfo.decimal.tp);
  498. l.qtcl_tp = ZhCalc.mul(l.unit_price, l.qtcl_qty, tenderInfo.decimal.tp);
  499. l.total_price = ZhCalc.mul(l.unit_price, l.quantity, tenderInfo.decimal.tp);
  500. }
  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.loadData4Rela(result.ledgerData, result.posData, result.detailData, result.changeData, result.detailAtt);
  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. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  722. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  723. return data.attachment ? data.attachment.length : 0;
  724. }
  725. },
  726. ],
  727. headRows: 1,
  728. emptyRows: 0,
  729. headRowHeight: [32],
  730. headColWidth: [30],
  731. defaultRowHeight: 21,
  732. headerFont: '12px 微软雅黑',
  733. font: '12px 微软雅黑',
  734. readOnly: true,
  735. selectedBackColor: '#fffacd',
  736. imageClick: function (data) {
  737. self.makeAttTable(data);
  738. $('#im-file').modal('show');
  739. }
  740. };
  741. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  742. this.sheet = this.spread.getActiveSheet();
  743. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  744. this.detailObj = {
  745. selectionChanged: function (e, info) {
  746. self.reLoadDetailData();
  747. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  748. self.loadLocateInfo();
  749. }
  750. },
  751. };
  752. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  753. this._initImTypeSetRela();
  754. this._initLocateRela();
  755. this._initAttRela();
  756. this.reBuildImData();
  757. }
  758. makeAttTable (data) {
  759. let html = [];
  760. if (data.attachment) {
  761. for (const att of data.attachment) {
  762. const delHtml = (parseInt(att.uid) === userID && att.renew)
  763. ? '<a class="delete-att text-danger ml-1" href="javascript:void(0);" data-imid="'+ data.att_uuid +'" data-attid="'+ att.file_id +'" title="删除"><i class="fa fa-remove "></i></a>'
  764. : '';
  765. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  766. const downloadHtml = '<a href="'+ window.location.pathname + '/im-file/download?im_id='+ data.att_uuid +'&file_id='+ att.file_id +'" title="下载"><i class="fa fa-download "></i></a>';
  767. html.push('<tr><td style="width: 200px">' + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
  768. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  769. }
  770. }
  771. $('#im-attList').html(html.join(''));
  772. }
  773. _initAttRela() {
  774. // 上传附件
  775. const self = this;
  776. $('#upload-im-file').change(function () {
  777. const files = this.files;
  778. const sels = self.sheet.getSelections();
  779. const select = SpreadJsObj.getSelectObject(self.sheet);
  780. if (!select) return;
  781. const formData = new FormData();
  782. const baseInfo = {};
  783. if (select.att_uuid) {
  784. baseInfo.uuid = select.att_uuid;
  785. } else {
  786. baseInfo.im_type = select.im_type;
  787. baseInfo.lid = select.lid;
  788. baseInfo.pid = select.pid;
  789. baseInfo.code = select.code;
  790. baseInfo.name = select.name;
  791. baseInfo.unit = select.unit;
  792. baseInfo.unit_price = select.unit_price;
  793. baseInfo.pos_name = select.pos_name;
  794. }
  795. formData.append('base', JSON.stringify(baseInfo));
  796. for (const file of files) {
  797. if (file === undefined) {
  798. toast('未选择上传文件!', 'error');
  799. return false;
  800. }
  801. const filesize = file.size;
  802. if (filesize > 30 * 1024 * 1024) {
  803. toast('存在上传文件大小过大!', 'error');
  804. return false;
  805. }
  806. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  807. if (whiteList.indexOf(fileext) === -1) {
  808. toast('只能上传指定格式的附件!', 'error');
  809. return false;
  810. }
  811. formData.append('size', filesize);
  812. formData.append('file[]', file);
  813. }
  814. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  815. stageIm.loadUpdateDetailAtt(data);
  816. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  817. self.makeAttTable(select);
  818. $('#upload-im-file').val('');
  819. });
  820. });
  821. // 删除附件
  822. $('body').on('click', '.delete-att' ,function () {
  823. const sels = self.sheet.getSelections();
  824. const select = SpreadJsObj.getSelectObject(self.sheet);
  825. if (!select) return;
  826. const uuid = $(this).attr('data-imid');
  827. const file_id = $(this).attr('data-attid');
  828. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  829. stageIm.loadUpdateDetailAtt(result);
  830. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  831. self.makeAttTable(select);
  832. });
  833. });
  834. }
  835. _initImTypeSetRela() {
  836. const self = this;
  837. const gatherConfirmPopover = {
  838. reBind: function (obj, eventName, fun) {
  839. obj.unbind(eventName);
  840. obj.bind(eventName, fun);
  841. },
  842. check: function (pos, hint, okCallback) {
  843. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  844. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  845. this.reBind(cancelObj, 'click', function () {
  846. confirmObj.hide();
  847. });
  848. this.reBind(okObj, 'click', function () {
  849. okCallback();
  850. confirmObj.hide();
  851. });
  852. hintObj.text(hint);
  853. confirmObj.css("top", pos.y).css("left", pos.x).show();
  854. }
  855. };
  856. this.gsTree = stageIm.getGsTree();
  857. if (relaStage.im_type === imType.tz.value || relaStage.im_type === imType.bb.value) {
  858. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  859. jlCol.title = '本期计量金额';
  860. SpreadJsObj.reLoadSheetHeader(self.sheet);
  861. $('[name=type-title-contract]').text('本期合同计量金额');
  862. $('[name=type-title-qc]').text('本期变更计量金额');
  863. } else {
  864. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  865. jlCol.title = '本期计量数量';
  866. SpreadJsObj.reLoadSheetHeader(self.sheet);
  867. $('[name=type-title-contract]').text('本期合同计量数量');
  868. $('[name=type-title-qc]').text('本期变更计量数量');
  869. }
  870. if (relaStage.im_type === imType.bb.value || relaStage.im_type === imType.bw.value) {
  871. $('#show-jldy').parent().show();
  872. $('#jldy').parent().show();
  873. $('#show-xm-name').parent().hide();
  874. $('#xm-name').parent().hide();
  875. } else {
  876. $('#show-jldy').parent().hide();
  877. $('#jldy').parent().hide();
  878. $('#show-xm-name').parent().show();
  879. $('#xm-name').parent().show();
  880. }
  881. }
  882. _initLocateRela() {
  883. const self = this;
  884. $('#im-locate2bills').click(function () {
  885. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  886. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  887. if (select && select.source) {
  888. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  889. stagePosSpreadObj.loadCurPosData();
  890. }
  891. });
  892. $('#im-locate-pre').click(function () {
  893. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  894. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  895. if (select && select.source) {
  896. const targetIndex = Math.max(curIndex-1, 1);
  897. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  898. stagePosSpreadObj.loadCurPosData();
  899. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  900. }
  901. });
  902. $('#im-locate-next').click(function () {
  903. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  904. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  905. if (select && select.source) {
  906. const targetIndex = Math.min(curIndex+1, select.source.length);
  907. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  908. stagePosSpreadObj.loadCurPosData();
  909. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  910. }
  911. });
  912. }
  913. loadLocateInfo() {
  914. const select = SpreadJsObj.getSelectObject(this.sheet);
  915. if (select && select.source.length > 1) {
  916. $('#im-locate2bills').next().show();
  917. } else {
  918. $('#im-locate2bills').next().hide();
  919. }
  920. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  921. }
  922. reLoadDetailData() {
  923. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  924. $('#detail-show').show();
  925. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  926. $('#show-contract-jl').text(contractJl);
  927. $('#contract-jl').val(contractJl);
  928. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  929. $('#show-qc-jl').text(qcJl);
  930. $('#qc-jl').val(qcJl);
  931. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  932. $('#show-bgl-code').text(bglCode);
  933. $('#bgl-code').val(bglCode);
  934. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  935. $('#show-bgl-drawing-code').text(bglDrawingCode);
  936. $('#bgl-drawing-code').val(bglDrawingCode);
  937. const bwName = data && data.bw ? data.bw : '';
  938. $('#show-bw-name').text(bwName);
  939. $('#bw-name').val(bwName);
  940. const position = data && data.position ? data.position : '';
  941. $('#show-position').text(position);
  942. $('#position').val(position);
  943. const peg = data && data.peg ? data.peg : '';
  944. $('#show-peg').text(peg);
  945. $('#peg').val(peg);
  946. const xmName = data && data.xm ? data.xm: '';
  947. $('#show-xm-name').text(xmName);
  948. $('#xm-name').val(xmName);
  949. const jldy = data && data.jldy ? data.jldy: '';
  950. $('#show-jldy').text(jldy);
  951. $('#jldy').val(jldy);
  952. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  953. $('#show-drawing-code').text(drawingCode);
  954. $('#drawing-code').val(drawingCode);
  955. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  956. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  957. $('#calc-memo').val(calcMemo);
  958. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  959. $('#show-calc-img').attr('src', calcImgSrc);
  960. $('#calc-img').attr('src', calcImgSrc);
  961. $('#view-calc-img').attr('src', calcImgSrc);
  962. const calcImgRemark = data && data.calc_img_remark || '';
  963. $('#view-calc-remark').val(calcImgRemark);
  964. $("#view-calc-remark").attr('readonly', true);
  965. $('#text-edit').val(calcImgRemark)
  966. }
  967. reBuildImData() {
  968. const imData = stageIm.buildImData();
  969. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  970. this.reLoadDetailData();
  971. this.loadLocateInfo();
  972. }
  973. }
  974. // 展开收起附件
  975. $('a', '.right-nav').bind('click', function () {
  976. //const main = $('#main-view'), tool = $('#tools-view');
  977. const tab = $(this), tabPanel = $(tab.attr('content'));
  978. if (!tab.hasClass('active')) {
  979. $('a', '.side-menu').removeClass('active');
  980. $('.tab-content .tab-select-show').removeClass('active');
  981. tab.addClass('active');
  982. tabPanel.addClass('active');
  983. showSideTools(tab.hasClass('active'));
  984. if (tab.attr('content') === '#search' && !searchLedger) {
  985. searchLedger = $.billsSearch({
  986. selector: '#search',
  987. searchSpread: slSpread,
  988. searchOver: true,
  989. searchEmpty: true,
  990. resultSpreadSetting: {
  991. cols: [
  992. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  993. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  994. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  995. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  996. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  997. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  998. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  999. ],
  1000. emptyRows: 0,
  1001. headRows: 1,
  1002. headRowHeight: [32],
  1003. headColWidth: [30],
  1004. defaultRowHeight: 21,
  1005. headerFont: '12px 微软雅黑',
  1006. font: '12px 微软雅黑',
  1007. selectedBackColor: '#fffacd',
  1008. },
  1009. afterLocated: function () {
  1010. stagePosSpreadObj.loadCurPosData();
  1011. },
  1012. customSearch: [
  1013. {
  1014. key: 'less', title: '漏计', valid: true,
  1015. check: function (node) {
  1016. if (node.quantity) {
  1017. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  1018. } else if (node.total_price) {
  1019. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  1020. }
  1021. }
  1022. }, {
  1023. key: 'over', title: '超计', valid: true,
  1024. check: function (node) {
  1025. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  1026. }
  1027. }, {
  1028. key: 'empty', title: '漏计', valid: false,
  1029. check: function (node) {
  1030. if (node.quantity) {
  1031. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  1032. } else if (node.total_price) {
  1033. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  1034. }
  1035. }
  1036. },
  1037. ],
  1038. });
  1039. searchLedger.spread.refresh();
  1040. }
  1041. if (tab.attr('content') === '#fujian') {
  1042. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1043. getNodeList(node.id);
  1044. }
  1045. if (tab.attr('content') === '#zhongjian') {
  1046. if (!detail) {
  1047. detail = new Detail($('#detail-spread'));
  1048. detail.spread.refresh();
  1049. $('#zhongjian .sjs-bottom').height('400px');
  1050. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1051. } else {
  1052. detail.spread.refresh();
  1053. }
  1054. }
  1055. } else {
  1056. tab.removeClass('active');
  1057. tabPanel.removeClass('active');
  1058. showSideTools(tab.hasClass('active'));
  1059. }
  1060. slSpread.refresh();
  1061. spSpread.refresh();
  1062. });
  1063. // 切换附件里节点和所有附件
  1064. $('#fujian .nav-link').on('click', function () {
  1065. const tabPanel = $(this).attr('fujian-content');
  1066. if (tabPanel !== 'syfujian') {
  1067. $('#showPage').hide();
  1068. $('#bach-download').prop('type', 'curr');
  1069. } else {
  1070. $('#showPage').show();
  1071. $('#bach-download').prop('type', 'all')
  1072. }
  1073. $('#showAttachment').hide();
  1074. });
  1075. // 获取附件信息
  1076. $('.list-table').on('click', '.att-file-name', function () {
  1077. const fid = $(this).attr('file-id');
  1078. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1079. return;
  1080. }
  1081. const att = attData.find(function (item) {
  1082. return item.id === parseInt(fid);
  1083. });
  1084. $('#edit-att').hide();
  1085. $('#show-att').show();
  1086. if (att !== undefined) {
  1087. // 进来先把编辑功能隐藏
  1088. $('#btn-att a').eq(3).hide()
  1089. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1090. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1091. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  1092. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  1093. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  1094. $('#show-att tr').eq(3).children('td').text(att.remark);
  1095. // 附件uid等于当前用户id, 附件上传本人
  1096. if (parseInt(cur_uid) === att.uid) {
  1097. $('#btn-att').show();
  1098. $('#btn-att a').eq(2).hide();
  1099. $('#btn-att a').eq(4).hide();
  1100. $('#btn-att a').eq(5).hide();
  1101. } else {
  1102. $('#btn-att').hide();
  1103. $('#btn-att a').eq(3).hide();
  1104. $('#btn-att a').eq(2).hide();
  1105. $('#btn-att a').eq(4).hide();
  1106. $('#btn-att a').eq(5).hide();
  1107. }
  1108. $('#showAttachment').attr('file-id', fid);
  1109. $('#showAttachment').show();
  1110. } else {
  1111. $('#showAttachment').hide();
  1112. $('#showAttachment').attr('file-id', '');
  1113. toastr.error('附件信息获取失败');
  1114. }
  1115. });
  1116. // $('body').on('click', '.alllist-table a', handleFileList);
  1117. $('body').on('click', '#btn-att a', function () {
  1118. const content = $(this).attr('content');
  1119. const fid = $('#showAttachment').attr('file-id');
  1120. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1121. if (content === 'view') {
  1122. const data = {id: fid};
  1123. postData('/tender/' + relaTender.id + '/measure/stage/' + relaStage.order + '/check/file', data, function (result) {
  1124. const { filepath } = result
  1125. $('#load-file').attr('href', filepath);
  1126. $('#load-file')[0].click();
  1127. });
  1128. } else if (content === 'location') {
  1129. const att = attData.find(item => item.id === parseInt(fid));
  1130. if (Object.keys(att).length) {
  1131. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  1132. stagePosSpreadObj.loadCurPosData();
  1133. }
  1134. }
  1135. });
  1136. // 切换页数
  1137. $('.page-select').on('click', function () {
  1138. const totalPageNum = parseInt($('#totalPage').text());
  1139. const lastPageNum = parseInt($('#currentPage').text());
  1140. const status = $(this).attr('content');
  1141. if (status === 'pre' && lastPageNum > 1) {
  1142. getAllList(lastPageNum-1);
  1143. $('#showAttachment').hide();
  1144. $('#syfujian .check-all-file').prop('checked', false)
  1145. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1146. getAllList(lastPageNum+1);
  1147. $('#showAttachment').hide();
  1148. $('#syfujian .check-all-file').prop('checked', false)
  1149. }
  1150. });
  1151. // 批量下载
  1152. $('#bach-download').click(function() {
  1153. const fileIds = [];
  1154. const type = $(this).attr('type');
  1155. let node = ''
  1156. if (type === 'curr') {
  1157. node = '#nodelist-table .check-file:checked'
  1158. } else {
  1159. node = '#alllist-table .check-file:checked'
  1160. }
  1161. $(node).each(function() {
  1162. const fileId = $(this).attr('file-id');
  1163. fileId && fileIds.push(fileId);
  1164. });
  1165. if (fileIds.length) {
  1166. if (fileIds.length > 10) {
  1167. return toastr.warning(`最大允许10个文件(当前${fileIds.length}个)`)
  1168. }
  1169. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  1170. $(this).attr('disabled', "true")
  1171. const btn = $(this)
  1172. postCompressFile(`/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/compresse-file`, {fileIds}, function(result) {
  1173. toastr.clear()
  1174. toastr.success('压缩文件成功')
  1175. btn.removeAttr('disabled')
  1176. const href = window.URL.createObjectURL(result)
  1177. $('#zipDown').attr('href', href);
  1178. $('#zipDown').attr('download', `${relaTender.name}-计量台账-第${relaStage.order}期-附件.zip`);
  1179. $("#zipDown")[0].click();
  1180. }, () => {
  1181. btn.removeAttr('disabled')
  1182. toastr.clear()
  1183. toastr.error('批量下载失败')
  1184. });
  1185. }
  1186. });
  1187. // 监听附件check是否选中
  1188. $('.list-table').on('click', '.check-file', function() {
  1189. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  1190. const childs = $(this).parents('.list-table').children().length;
  1191. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  1192. if (checkedList.length === childs) {
  1193. checkBox.prop("checked", true);
  1194. } else {
  1195. checkBox.prop("checked", false);
  1196. }
  1197. });
  1198. $('.check-all-file').click(function() {
  1199. const isCheck = $(this).is(':checked');
  1200. $(this).parents('table').find('.list-table').each(function() {
  1201. $(this).find('input:checkbox').prop("checked", isCheck);
  1202. })
  1203. });
  1204. // 显示层次
  1205. (function (select, sheet) {
  1206. $(select).click(function () {
  1207. if (!sheet.zh_tree) return;
  1208. const tag = $(this).attr('tag');
  1209. const tree = sheet.zh_tree;
  1210. setTimeout(() => {
  1211. showWaitingView();
  1212. switch (tag) {
  1213. case "1":
  1214. case "2":
  1215. case "3":
  1216. case "4":
  1217. case "5":
  1218. tree.expandByLevel(parseInt(tag));
  1219. SpreadJsObj.refreshTreeRowVisible(sheet);
  1220. break;
  1221. case "last":
  1222. tree.expandByCustom(() => { return true; });
  1223. SpreadJsObj.refreshTreeRowVisible(sheet);
  1224. break;
  1225. case "leafXmj":
  1226. tree.expandToLeafXmj();
  1227. SpreadJsObj.refreshTreeRowVisible(sheet);
  1228. break;
  1229. case "curMeasure":
  1230. tree.expandByCustom(function (node) {
  1231. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1232. if (node[field]) {
  1233. return true;
  1234. }
  1235. }
  1236. return false;
  1237. });
  1238. SpreadJsObj.refreshTreeRowVisible(sheet);
  1239. break;
  1240. }
  1241. closeWaitingView();
  1242. }, 100);
  1243. });
  1244. })('a[name=showLevel]', slSpread.getActiveSheet());
  1245. });