sr_detail.js 53 KB

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