sr_detail.js 60 KB

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