sr_detail.js 61 KB

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