sr_detail.js 58 KB

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