sr_detail.js 60 KB

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