sr_detail.js 58 KB

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