stage.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. function checkTzMeasureType () {
  10. return tender.measure_type === measureType.tz.value;
  11. }
  12. /**
  13. * 从cookie中读取缓存的列显示设置,没有则取默认
  14. * @returns {*[]}
  15. */
  16. function customColDisplay () {
  17. const defaultSetting = [
  18. { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
  19. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  20. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  21. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  22. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  23. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  24. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp'], visible: true },
  25. { title: '图册号', fields: ['drawing_code'], visible: true },
  26. { title: '累计完成率(%)', fields: ['percent'], visible: true },
  27. { title: '备注', fields: ['memo'], visible: true },
  28. ];
  29. const settingStr = Cookies.get('stage-col-visible-1.0.0');
  30. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  31. }
  32. /**
  33. * 根据列显示设置,调整setting中的列是否显示
  34. * @param setting
  35. * @param customDisplay
  36. */
  37. function customizeStageTreeSetting(setting, customDisplay) {
  38. for (const cd of customDisplay) {
  39. for (const c of setting.cols) {
  40. if (cd.fields.indexOf(c.field) !== -1) {
  41. c.visible = cd.visible;
  42. }
  43. }
  44. }
  45. }
  46. /**
  47. * 初始化 树结构 列事件
  48. * @param setting
  49. */
  50. function initTreeColSettingEvents(setting) {
  51. const Events = {
  52. readOnly: {
  53. measureData: function (node) {
  54. return node.children && node.children.length > 0;
  55. },
  56. },
  57. };
  58. const getEvent = function (eventName) {
  59. const names = eventName.split('.');
  60. let event = Events;
  61. for (let name of names) {
  62. if (event[name]) {
  63. event = event[name];
  64. } else {
  65. return null;
  66. }
  67. }
  68. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  69. return null;
  70. } else {
  71. return event;
  72. }
  73. };
  74. for (const col of setting.cols) {
  75. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  76. col.readOnly = getEvent(col.readOnly);
  77. }
  78. }
  79. }
  80. function needCheckDetail() {
  81. stage.check_detail = true;
  82. $('#check_point').show();
  83. }
  84. // 生成所有附件列表
  85. function getAllList(currPageNum = 1) {
  86. // 每页最多几个附件
  87. const pageCount = 11;
  88. // 附件总数
  89. const total = attData.length;
  90. // 总页数
  91. const pageNum = Math.ceil(total/pageCount);
  92. $('#totalPage').text(pageNum);
  93. $('#currentPage').text(currPageNum);
  94. // 当前页附件内容
  95. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  96. let html = '';
  97. for(const att of currPageAttData) {
  98. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  99. }
  100. $('#alllist-table').html(html);
  101. }
  102. // 生成当前节点列表
  103. function getNodeList(node) {
  104. let html = '';
  105. for(const att of attData) {
  106. if (parseInt(node) === att.lid) {
  107. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  108. }
  109. }
  110. $('#nodelist-table').html(html);
  111. }
  112. $(document).ready(() => {
  113. // 界面布局
  114. autoFlashHeight();
  115. // 初始化 台账树结构 数据结构
  116. const stageTreeSetting = {
  117. id: 'ledger_id',
  118. pid: 'ledger_pid',
  119. order: 'order',
  120. level: 'level',
  121. rootId: -1,
  122. keys: ['id', 'tender_id', 'ledger_id'],
  123. stageId: 'id',
  124. };
  125. // 台账树结构计算相关设置
  126. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'];
  127. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  128. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  129. stageTreeSetting.calcFun = function (node) {
  130. if (node.children && node.children.length === 0) {
  131. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  132. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  133. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  134. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  135. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  136. }
  137. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  138. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  139. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  140. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  141. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  142. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), tenderInfo.decimal.up);
  143. };
  144. const stageTree = createNewPathTree('stage', stageTreeSetting);
  145. // 初始化 部位明细 数据结构
  146. const stagePosSetting = {
  147. id: 'id', ledgerId: 'lid',
  148. updateFields: ['contract_qty', 'qc_qty', 'postil'],
  149. };
  150. stagePosSetting.calcFun = function (pos) {
  151. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  152. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  153. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  154. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  155. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  156. };
  157. const stagePos = new StagePosData(stagePosSetting);
  158. class Changes {
  159. constructor(obj) {
  160. const self = this;
  161. this.obj = obj;
  162. // 初始化 清单编号窗口 参数
  163. this.spreadSetting = {
  164. cols: [
  165. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  166. if (data.uamount && !checkZero(data.uamount)) {
  167. return $('#icon-ok')[0];
  168. } else {
  169. return null;
  170. }
  171. }},
  172. {title: '变更令号', field: 'code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  173. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  174. {title: '总数量', field: 'b_amount', width: 60, formatter: '@', readOnly: true, hAlign: 2, },
  175. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, },
  176. {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, type: 'Number', },
  177. ],
  178. emptyRows: 0,
  179. headRows: 1,
  180. headRowHeight: [40],
  181. getColor: function (data, col, defaultColor) {
  182. if (col.field === 'uamount') {
  183. if (!data.vamount) {
  184. return data.uamount ? '#ff6f5c' : defaultColor;
  185. } else if (data.uamount) {
  186. return data.uamount > data.vamount ? '#ff6f5c' : defaultColor;
  187. } else {
  188. return defaultColor;
  189. }
  190. } else {
  191. return defaultColor;
  192. }
  193. }
  194. };
  195. this.curChangeId = '';
  196. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  197. this.firstView = true;
  198. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  199. // 初次显示,需刷新spread界面,保证界面绘制正确
  200. this.obj.bind('shown.bs.modal', function () {
  201. if (self.firstView) {
  202. self.firstView = false;
  203. self.spread.refresh();
  204. }
  205. });
  206. // 切换变更令,加载右侧明细数据
  207. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  208. const change = SpreadJsObj.getSelectObject(info.sheet);
  209. self._loadChangeDetail(change);
  210. });
  211. // 填写本期计量
  212. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  213. if (info.sheet.zh_setting) {
  214. const col = info.sheet.zh_setting.cols[info.col];
  215. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  216. const node = sortData[info.row];
  217. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  218. // 刷新界面
  219. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  220. }
  221. });
  222. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  223. if (info.sheet.zh_setting) {
  224. const sortData = SpreadJsObj.getSortData(info.sheet);
  225. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  226. const curRow = iRow + info.cellRange.row;
  227. const curCol = info.cellRange.col;
  228. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  229. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  230. }
  231. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  232. }
  233. });
  234. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  235. if (sheet.zh_setting) {
  236. const sel = sheet.getSelections()[0];
  237. const sortData = SpreadJsObj.getSortData(sheet);
  238. // 仅本期计量可删除
  239. if (sel.col === 5 || sel.colCount === 1) {
  240. const col = sheet.zh_setting.cols[sel.col];
  241. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  242. const data = sortData[iRow];
  243. data[col.field] = null;
  244. }
  245. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  246. }
  247. }
  248. });
  249. // 过滤可变更数量为0
  250. $('#filterEmpty').click(function () {
  251. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  252. });
  253. // 匹配编号
  254. $('#matchPos').click(function () {
  255. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  256. });
  257. // 展开收起 变更令详细信息
  258. $('#show-bgl-detail').bind('click', function () {
  259. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  260. if (detail.hasClass('col-4')) {
  261. detail.attr('class', 'col').hide();
  262. bgl.attr('class', 'col-12');
  263. $('a', obj).attr('title', '展开侧栏');
  264. $('i', obj).attr('class', 'fa fa-chevron-left');
  265. self.spread.refresh();
  266. } else {
  267. detail.attr('class', 'col-4').show();
  268. bgl.attr('class', 'col-8');
  269. $('a', obj).attr('title', '收起侧栏');
  270. $('i', obj).attr('class', 'fa fa-chevron-right');
  271. self.spread.refresh();
  272. }
  273. });
  274. // 添加调用变更令
  275. $('#usg-bg-ok').click(function () {
  276. const data = { target: self.callData, change: [] };
  277. for (const c of self.changes) {
  278. if (c.uamount) {
  279. if (!c.vamount || checkZero(c.vamount)) {
  280. toast('变更令:' + c.code + ' 当前不可使用', 'error');
  281. return;
  282. } else {
  283. if (c.uamount > c.vamount) {
  284. toast('变更令:' + c.code + ' 超计,请修改本期计量后,再提交', 'error');
  285. return;
  286. }
  287. }
  288. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  289. }
  290. }
  291. // 提交数据到后端
  292. postData(window.location.pathname + '/use-change', data, function(result) {
  293. if (result.pos) {
  294. stagePos.loadCurStageData(result.pos.curStageData);
  295. }
  296. const nodes = stageTree.loadPostStageData(result.bills);
  297. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  298. stagePosSpreadObj.loadCurPosData();
  299. needCheckDetail();
  300. self.obj.modal('hide');
  301. });
  302. })
  303. }
  304. _calculateAmount() {
  305. for (const c of this.changes) {
  306. c.bamount = _.toNumber(c.b_amount);
  307. c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
  308. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  309. if (uc) {
  310. c.uamount = uc.qty;
  311. c.vamount = ZhCalc.add(c.vamount, c.uamount);
  312. }
  313. }
  314. }
  315. _loadChangeDetail(change) {
  316. if (change) {
  317. if (change.cid === this.curChangeId) { return; }
  318. this.curChangeId = change.cid;
  319. const inputs = $('input[type!=checkbox]', this.obj);
  320. for (const i of inputs) {
  321. const field = $(i).attr('name');
  322. const text = (field && change[field]) ? change[field] : '';
  323. $(i).val(text);
  324. }
  325. const textareas = $('textarea', this.obj);
  326. for (const ta of textareas) {
  327. const field = $(ta).attr('name');
  328. const text = (field && change[field]) ? change[field] : '';
  329. ta.innerText = text;
  330. }
  331. const html = [];
  332. for (const a of change.attachments) {
  333. html.push('<tr>');
  334. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  335. html.push('<td>', a.u_name, '</td>');
  336. html.push('</tr>');
  337. }
  338. // 变更类型
  339. if (change.type) {
  340. const cType = change.type.split(',');
  341. $('input[name="type"]').prop("checked", false);
  342. for (const c of cType) {
  343. $('input[name="type"][value='+ c +']').prop("checked", true);
  344. }
  345. }
  346. // 变更类别
  347. $('select[name=class]').val(change.class);
  348. // 变更性质
  349. $('select[name=quality]').val(change.quality);
  350. // 变更单位
  351. $('select[name=company]').html('<option>' + change.company + '</option>');
  352. // 费用承担方
  353. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  354. // 附件
  355. $('#attachment').html(html.join(''));
  356. } else {
  357. const inputs = $('input', this.obj);
  358. for (const i of inputs) {
  359. $(i).val('');
  360. }
  361. const textareas = $('textarea', this.obj);
  362. for (const ta of textareas) {
  363. ta.innerText = '';
  364. }
  365. $('#attachment').html('');
  366. }
  367. }
  368. _viewChanges() {
  369. const sheet = this.spread.getActiveSheet();
  370. if (this.changes) {
  371. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, this.changes);
  372. sheet.setSelection(0, 0, 1, 1);
  373. this._loadChangeDetail(this.changes[0]);
  374. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  375. } else {
  376. toast('查询变更令有误,请刷新页面后重试', 'warning');
  377. }
  378. }
  379. _filterChange(filterEmpty, matchPosName) {
  380. for (const c of this.changes) {
  381. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  382. const matchVisible = matchPosName && this.callData.pos ? c.b_detail === this.callData.pos.name : true;
  383. c.visible = filterVisible && matchVisible;
  384. }
  385. SpreadJsObj.refreshTreeRowVisible(this.spread.getActiveSheet());
  386. }
  387. loadChanges(data) {
  388. this.callData = data;
  389. if (this.callData.pos) {
  390. $('#matchPos').parent().show();
  391. } else {
  392. $('#matchPos').parent().hide();
  393. }
  394. const self = this;
  395. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  396. postData(window.location.pathname + '/valid-change', data, function (result) {
  397. self.changes = result.changes;
  398. self.useChanges = result.useChanges;
  399. self._calculateAmount();
  400. self._viewChanges();
  401. self.obj.modal('show');
  402. });
  403. }
  404. }
  405. const changesObj = new Changes($('#use-bg'));
  406. // 初始化 台账 spread
  407. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  408. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  409. // 数量变更列,添加按钮
  410. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  411. col.readOnly = true;
  412. col.cellType = 'imageBtn';
  413. col.hoverImg = '#ellipsis-icon';
  414. col.indent = 5;
  415. col.showImage = function (data) {
  416. if (!data || (data.children && data.children.length > 0)) {
  417. return false;
  418. } else {
  419. const nodePos = stagePos.getLedgerPos(data.id);
  420. return !(nodePos && nodePos.length > 0);
  421. }
  422. };
  423. ledgerSpreadSetting.imageClick = function (data) {
  424. changesObj.loadChanges({bills: data});
  425. };
  426. //
  427. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  428. stageTree.loadDatas(ledgerData);
  429. stageTree.loadCurStageData(curStageData);
  430. stageTree.loadPreStageData(preStageData);
  431. // 根据设置 计算 台账树结构
  432. treeCalc.calculateAll(stageTree);
  433. // 绘制界面
  434. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  435. //初始化所有附件列表
  436. getAllList();
  437. // 初始化 部位明细 Spread
  438. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  439. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  440. spCol.readOnly = true;
  441. spCol.cellType = 'imageBtn';
  442. spCol.hoverImg = '#ellipsis-icon';
  443. spCol.indent = 5;
  444. spCol.showImage = function (data) {
  445. return data;
  446. };
  447. posSpreadSetting.imageClick = function (data) {
  448. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  449. changesObj.loadChanges({bills: node, pos: data});
  450. };
  451. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  452. const stageTreeSpreadObj = {
  453. refreshTreeNodes: function (sheet, nodes) {
  454. const tree = sheet.zh_tree;
  455. if (!tree) { return }
  456. const rows = [];
  457. for (const node of nodes) {
  458. rows.push(tree.nodes.indexOf(node));
  459. }
  460. SpreadJsObj.reLoadRowsData(sheet, rows);
  461. },
  462. editEnded: function (e, info) {
  463. if (info.sheet.zh_setting) {
  464. const col = info.sheet.zh_setting.cols[info.col];
  465. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  466. const node = sortData[info.row];
  467. if (col.field !== 'postil') {
  468. if (node.children && node.children.length > 0) {
  469. toast('清单父项不可计量', 'error');
  470. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  471. return;
  472. } else {
  473. const nodePos = stagePos.getLedgerPos(node.id);
  474. if (nodePos && nodePos.length > 0) {
  475. toast('该清单有部位明细,请在部位明细处计量', 'error');
  476. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  477. return;
  478. }
  479. }
  480. }
  481. const billsData = {
  482. lid: node.id
  483. };
  484. billsData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  485. postData(window.location.href + '/update', { bills: billsData }, function (data) {
  486. const nodes = stageTree.loadPostStageData(data);
  487. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  488. needCheckDetail();
  489. });
  490. }
  491. },
  492. selectionChanged: function (e, info) {
  493. stagePosSpreadObj.loadCurPosData();
  494. },
  495. deletePress(sheet) {
  496. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  497. const tree = sheet.zh_tree;
  498. if (!tree) { return; }
  499. const sel = sheet.getSelections()[0];
  500. const validCols = [];
  501. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  502. if (!sheet.zh_setting.cols[iCol].readOnly) {
  503. validCols.push(iCol);
  504. }
  505. }
  506. if (validCols.length === 0) { return; }
  507. const sortData = sheet.zh_tree.nodes;
  508. const datas = [];
  509. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  510. const node = sortData[iRow];
  511. if (node) {
  512. const data = { lid: node.id };
  513. let filter = true;
  514. for (const iCol of validCols) {
  515. const colSetting = sheet.zh_setting.cols[iCol];
  516. if (colSetting.field !== 'postil') {
  517. if (node.children && node.children.length > 0) { continue; }
  518. const nodePos = stagePos.getLedgerPos(node.id);
  519. if (nodePos && nodePos.length > 0) { continue; }
  520. }
  521. data[colSetting.field] = null;
  522. filter = false;
  523. }
  524. if (!filter) {
  525. datas.push(data);
  526. }
  527. }
  528. }
  529. if (datas.length > 0) {
  530. postData(window.location.href + '/update', {bills: datas}, function (result) {
  531. const nodes = stageTree.loadPostStageData(result);
  532. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  533. needCheckDetail();
  534. });
  535. }
  536. }
  537. },
  538. clipboardPasting(e, info) {
  539. if (info.sheet.zh_setting) {
  540. const sortData = info.sheet.zh_data;
  541. const range = info.cellRange;
  542. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  543. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  544. const col = info.sheet.zh_setting.cols[iCol];
  545. if (validField.indexOf(col.field) === -1) {
  546. toast('不可修改此数据', 'error');
  547. info.cancel = true;
  548. return;
  549. }
  550. }
  551. }
  552. },
  553. clipboardPasted(e, info) {
  554. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  555. const sheet = info.sheet;
  556. const filterNodes = [], datas = [];
  557. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  558. const curRow = iRow + info.cellRange.row;
  559. const node = sheet.zh_tree.getItemsByIndex(curRow);
  560. const data = {lid: node.id};
  561. let filter = true;
  562. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  563. const curCol = info.cellRange.col + iCol;
  564. const col = info.sheet.zh_setting.cols[curCol];
  565. if (col.field !== 'postil') {
  566. if (node.children && node.children.length > 0) {
  567. continue;
  568. }
  569. const nodePos = stagePos.getLedgerPos(node.id);
  570. if (nodePos && nodePos.length > 0) {
  571. continue;
  572. }
  573. }
  574. data[col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  575. filter = false;
  576. }
  577. if (filter) {
  578. filterNodes.push(node);
  579. } else {
  580. datas.push(data);
  581. }
  582. }
  583. if (datas.length > 0) {
  584. postData(window.location.href + '/update', { bills: datas }, function (data) {
  585. const nodes = stageTree.loadPostStageData(data);
  586. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  587. needCheckDetail();
  588. });
  589. } else {
  590. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  591. }
  592. }
  593. }
  594. };
  595. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  596. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  597. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  598. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  599. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  600. const stagePosSpreadObj = {
  601. /**
  602. * 加载部位明细 根据当前台账选择节点
  603. */
  604. loadCurPosData: function () {
  605. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  606. if (node) {
  607. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  608. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  609. } else {
  610. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  611. }
  612. getNodeList(node.id);
  613. },
  614. editEnded: function (e, info) {
  615. if (info.sheet.zh_setting) {
  616. // 未改变过,则直接跳过
  617. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  618. const col = info.sheet.zh_setting.cols[info.col];
  619. const orgText = posData ? posData[col.field] : null;
  620. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  621. return;
  622. }
  623. // 台账模式下,不可新增
  624. if (checkTzMeasureType() && !posData) {
  625. toast('台账模式不可新增部位明细数据', 'error');
  626. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  627. info.cancel = true;
  628. return ;
  629. }
  630. // 不同节点下,部位明细检查输入
  631. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  632. const node = stagePosSpreadObj.stageTreeNode;
  633. if (!node) {
  634. toast('数据错误, 请刷新页面后再试', 'warning');
  635. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  636. return;
  637. } else if (info.editingText !== '' && node.children && node.children > 0) {
  638. toast('父节点不可插入部位明细', 'error');
  639. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  640. return;
  641. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  642. toast('项目节不可插入部位明细', 'error');
  643. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  644. return;
  645. }
  646. // 生成提交数据
  647. const data = {};
  648. if (col.field === 'name') {
  649. if (info.editingText === '' && pos) {
  650. toast('部位名称不可为空', 'error', 'exclamation-circle');
  651. info.cancel = true;
  652. return;
  653. } else if (!posData) {
  654. if (info.editingText !== '') {
  655. data.updateType = 'add';
  656. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
  657. } else {
  658. return;
  659. }
  660. } else {
  661. data.updateType = 'update';
  662. data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
  663. }
  664. } else if (!posData) {
  665. toast('新增部位请先输入名称', 'warning');
  666. } else {
  667. data.updateType = 'update';
  668. data.updateData = {pid: posData.id, lid: posData.lid};
  669. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  670. }
  671. // 提交数据到服务器
  672. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  673. if (result.pos) {
  674. stagePos.updateDatas(result.pos.pos);
  675. stagePos.loadCurStageData(result.pos.curStageData);
  676. }
  677. const refreshData = stageTree.loadPostStageData(result.ledger);
  678. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  679. stagePosSpreadObj.loadCurPosData();
  680. needCheckDetail();
  681. }, function () {
  682. stagePosSpreadObj.loadCurPosData();
  683. });
  684. }
  685. },
  686. editStarting: function (e, info) {
  687. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  688. },
  689. clipboardPasting: function (e, info) {
  690. if (info.sheet.zh_setting) {
  691. const sortData = info.sheet.zh_data;
  692. const range = info.cellRange;
  693. const validField = ['contract_qty', 'qc_qty', 'postil'];
  694. if (!checkTzMeasureType()) {
  695. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
  696. }
  697. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  698. const col = info.sheet.zh_setting.cols[iCol];
  699. if (validField.indexOf(col.field) === -1) {
  700. if (checkTzMeasureType()) {
  701. toast('不可修改此数据', 'error');
  702. info.cancel = true;
  703. return;
  704. } else {
  705. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  706. const pos = sortData(iRow);
  707. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  708. toast('不可修改此数据', 'error');
  709. info.cancel = true;
  710. return;
  711. }
  712. }
  713. }
  714. }
  715. }
  716. }
  717. },
  718. clipboardPasted: function (e, info) {
  719. const self = this;
  720. if (info.sheet.zh_setting) {
  721. const data = { updateType: '', updateData: [], };
  722. const sortData = info.sheet.zh_data;
  723. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  724. if (sortData && (info.cellRange.row >= sortData.length)) {
  725. data.updateType = 'add';
  726. if (info.cellRange.col !== 0) {
  727. toast('新增部位请先输入名称', 'warning');
  728. self.loadCurPosData();
  729. return;
  730. }
  731. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  732. const curRow = info.cellRange.row + iRow;
  733. const newData = {lid: node.id};
  734. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  735. const curCol = info.cellRange.col + iCol;
  736. const colSetting = info.sheet.zh_setting.cols[curCol];
  737. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  738. if (colSetting.type === 'Number') {
  739. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  740. }
  741. }
  742. data.updateData.push(newData);
  743. }
  744. } else {
  745. data.updateType = 'update';
  746. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  747. const curRow = info.cellRange.row + iRow;
  748. const curPos = sortData[curRow];
  749. if (curPos) {
  750. const newData = {pid: curPos.id, lid: curPos.lid};
  751. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  752. const curCol = info.cellRange.col + iCol;
  753. const colSetting = info.sheet.zh_setting.cols[curCol];
  754. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  755. if (colSetting.type === 'Number') {
  756. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  757. }
  758. }
  759. data.updateData.push(newData);
  760. }
  761. }
  762. }
  763. console.log(data);
  764. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  765. if (result.pos) {
  766. stagePos.updateDatas(result.pos.pos);
  767. stagePos.loadCurStageData(result.pos.curStageData);
  768. }
  769. const nodes = stageTree.loadPostStageData(result.ledger);
  770. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  771. stagePosSpreadObj.loadCurPosData();
  772. needCheckDetail();
  773. }, function () {
  774. stagePosSpreadObj.loadCurPosData();
  775. });
  776. }
  777. },
  778. deletePress: function (sheet) {
  779. if (sheet.zh_setting && sheet.zh_data) {
  780. const sortData = sheet.zh_data;
  781. if (!sortData || sortData.length === 0) { return; }
  782. const sel = sheet.getSelections()[0];
  783. const validCols = [];
  784. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  785. if (!sheet.zh_setting.cols[iCol].readOnly) {
  786. validCols.push(iCol);
  787. }
  788. }
  789. if (validCols.length === 0) { return; }
  790. const datas = [], posSelects = [];
  791. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  792. const node = sortData[iRow];
  793. if (node) {
  794. const data = {pid: node.id, lid: node.lid};
  795. for (const iCol of validCols) {
  796. const colSetting = sheet.zh_setting.cols[iCol];
  797. if (colSetting.field === 'name') {
  798. toast('部位名称不能为空', 'error');
  799. return;
  800. }
  801. data[colSetting.field] = null;
  802. }
  803. datas.push(data);
  804. posSelects.push(node);
  805. }
  806. }
  807. if (datas.length > 0) {
  808. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  809. if (result.pos) {
  810. stagePos.updateDatas(result.pos.pos);
  811. stagePos.loadCurStageData(result.pos.curStageData);
  812. }
  813. const nodes = stageTree.loadPostStageData(result.ledger);
  814. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  815. needCheckDetail();
  816. // todo 只加载改变项
  817. stagePosSpreadObj.loadCurPosData();
  818. });
  819. }
  820. }
  821. },
  822. leaveCell: function (e, info) {
  823. console.log(1);
  824. },
  825. };
  826. // 加载上下窗口resizer
  827. $.divResizer({
  828. select: '#main-resize',
  829. callback: function () {
  830. slSpread.refresh();
  831. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  832. $(".sp-wrap").height(bcontent-40);
  833. spSpread.refresh();
  834. }
  835. });
  836. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  837. postData(window.location.pathname + '/pos', null, function (result) {
  838. stagePos.loadDatas(result.pos);
  839. if (result.curStageData) {
  840. stagePos.loadCurStageData(result.curStageData);
  841. }
  842. if (result.preStageData) {
  843. stagePos.loadPreStageData(result.preStageData);
  844. }
  845. stagePos.calculateAll();
  846. stagePosSpreadObj.loadCurPosData();
  847. });
  848. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  849. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  850. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  851. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  852. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  853. if (!checkTzMeasureType()) {
  854. }
  855. $('#row-view').on('show.bs.modal', function () {
  856. const html = [], customDisplay = customColDisplay();
  857. for (const cd of customDisplay) {
  858. html.push('<tr>');
  859. html.push('<td>', cd.title, '</td>');
  860. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  861. html.push('</tr>');
  862. }
  863. $('#row-view-list').html(html.join(''));
  864. });
  865. $('#row-view-ok').click(function () {
  866. const customDisplay = customColDisplay();
  867. const cvl = $('#row-view-list').children();
  868. for (const cv of cvl) {
  869. const title = $(cv).children()[0].innerHTML;
  870. const check = $('input', cv)[0].checked;
  871. const cd = customDisplay.find(function (c) {
  872. return c.title === title;
  873. });
  874. cd.visible = check;
  875. }
  876. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  877. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  878. Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
  879. $('#row-view').modal('hide');
  880. });
  881. class SearchLedger {
  882. constructor(obj, mainSpread) {
  883. const self = this;
  884. this.obj = obj;
  885. this.mainSpread = mainSpread;
  886. this.spreadSetting = {
  887. cols: [
  888. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  889. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  890. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@'},
  891. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  892. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  893. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  894. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  895. ],
  896. emptyRows: 3,
  897. headRows: 1,
  898. headRowHeight: [40],
  899. defaultRowHeight: 21,
  900. readOnly: true
  901. };
  902. this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
  903. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  904. $('#searchLedger', this.obj).bind('click', function () {
  905. const keyword = $('#keyword', self.obj).val();
  906. if (keyword !== '') {
  907. $('#over', obj)[0].checked = false;
  908. $('#empty', obj)[0].checked = false;
  909. this.searchResult = [];
  910. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  911. for (const node of sortData) {
  912. if ((node.code && node.code.indexOf(keyword) > -1) ||
  913. node.b_code && node.b_code.indexOf(keyword) > -1 ||
  914. node.name && node.name.indexOf(keyword) > -1) {
  915. this.searchResult.push(node);
  916. }
  917. }
  918. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  919. }
  920. });
  921. $('#over', this.obj).bind('change', function () {
  922. this.searchResult = [];
  923. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  924. for (const node of sortData) {
  925. if (node.children && node.children.length > 0) continue;
  926. if (node.end_gather_qty) {
  927. if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(node.quantity)) {
  928. this.searchResult.push(node);
  929. }
  930. } else if (node.end_gather_tp) {
  931. if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(node.total_price)) {
  932. this.searchResult.push(node);
  933. }
  934. }
  935. }
  936. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  937. });
  938. $('#empty', this.obj).bind('change', function () {
  939. this.searchResult = [];
  940. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  941. for (const node of sortData) {
  942. if (node.children && node.children.length > 0) continue;
  943. if (node.quantity) {
  944. if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
  945. this.searchResult.push(node);
  946. }
  947. } else if (node.total_price) {
  948. if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
  949. this.searchResult.push(node);
  950. }
  951. }
  952. }
  953. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  954. });
  955. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  956. const sheet = info.sheet;
  957. const data = sheet.zh_data;
  958. if (!data) { return }
  959. const curBills = data[info.row];
  960. if (!curBills) { return }
  961. SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id);
  962. });
  963. }
  964. }
  965. let searchLedger;
  966. $.divResizer({
  967. select: '#right-spr',
  968. callback: function () {
  969. slSpread.refresh();
  970. spSpread.refresh();
  971. if (searchLedger) {
  972. searchLedger.spread.refresh();
  973. }
  974. }
  975. });
  976. // 展开收起附件
  977. $('a', '.right-nav').bind('click', function () {
  978. //const main = $('#main-view'), tool = $('#tools-view');
  979. const tab = $(this), tabPanel = $(tab.attr('content'));
  980. const showTools = function (show) {
  981. const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
  982. if (show) {
  983. right.show();
  984. autoFlashHeight();
  985. /**
  986. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  987. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  988. * 故需要通过最终的parent.width再计算一次left.width
  989. *
  990. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  991. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  992. *
  993. */
  994. //left.css('width', parent.width() - right.outerWidth());
  995. //left.css('width', parent.width() - right.outerWidth());
  996. const percent = 100 - right.outerWidth() /parent.width() * 100;
  997. left.css('width', percent + '%');
  998. } else {
  999. right.hide();
  1000. left.css('width', '100%');
  1001. }
  1002. };
  1003. if (!tab.hasClass('active')) {
  1004. $('a', '.side-menu').removeClass('active');
  1005. $('.tab-content .tab-select-show').removeClass('active');
  1006. tab.addClass('active');
  1007. tabPanel.addClass('active');
  1008. showTools(tab.hasClass('active'));
  1009. if (tab.attr('content') === '#search' && !searchLedger) {
  1010. searchLedger = new SearchLedger($('#search'), slSpread);
  1011. searchLedger.spread.refresh();
  1012. }
  1013. if (tab.attr('content') === '#fujian') {
  1014. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1015. getNodeList(node.id);
  1016. }
  1017. } else {
  1018. tab.removeClass('active');
  1019. tabPanel.removeClass('active');
  1020. showTools(tab.hasClass('active'));
  1021. }
  1022. slSpread.refresh();
  1023. spSpread.refresh();
  1024. });
  1025. // 切换附件里节点和所有附件
  1026. $('#fujian .nav-link').on('click', function () {
  1027. const tabPanel = $(this).attr('fujian-content');
  1028. if (tabPanel !== 'syfujian') {
  1029. $('#showPage').hide();
  1030. } else {
  1031. $('#showPage').show();
  1032. }
  1033. });
  1034. // 上传附件
  1035. $('#upload-file-btn').click(function () {
  1036. const file = $('#upload-file')[0];
  1037. if (file.files[0] === undefined) {
  1038. toast('未选择上传文件!', 'error');
  1039. return false;
  1040. }
  1041. const filesize = file.files[0].size;
  1042. if (filesize > 10 * 1024 * 1024) {
  1043. toast('文件大小过大!', 'error');
  1044. return false;
  1045. }
  1046. const fileext = '.' + file.files[0].name.toLowerCase().split('.').splice(-1)[0];
  1047. if (whiteList.indexOf(fileext) === -1) {
  1048. toast('只能上传指定格式的附件!', 'error');
  1049. return false;
  1050. }
  1051. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1052. const formData = new FormData();
  1053. formData.append('lid', node.id);
  1054. formData.append('size', filesize);
  1055. formData.append('file', file.files[0]);
  1056. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/upload/file', formData, function (data) {
  1057. $('#upload').modal('hide');
  1058. // 插入到attData中
  1059. console.log(data);
  1060. attData.unshift(data);
  1061. // 重新生成LIst
  1062. getAllList();
  1063. getNodeList(node.id);
  1064. }, function () {
  1065. toast('附件上传失败', 'error');
  1066. });
  1067. $('#upload-file').val('');
  1068. });
  1069. // 获取附件信息
  1070. $('body').on('click', '.list-table a', function () {
  1071. const fid = $(this).attr('file-id');
  1072. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1073. return;
  1074. }
  1075. const att = attData.find(function (item) {
  1076. return item.id === parseInt(fid);
  1077. });
  1078. console.log(att);
  1079. $('#edit-att').hide();
  1080. $('#show-att').show();
  1081. if (att !== undefined) {
  1082. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1083. const name = att.code !== null && att.code !== '' ? att.code : att.b_code;
  1084. $('#show-att tr').eq(1).children('td').text(name + ' ' + att.lname);
  1085. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/download/file/' + att.id);
  1086. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  1087. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  1088. $('#show-att tr').eq(4).children('td').text(att.remark);
  1089. console.log(userID);
  1090. console.log(att.uid);
  1091. if (parseInt(userID) === att.uid) {
  1092. $('#btn-att').show();
  1093. $('#btn-att a').eq(1).show();
  1094. $('#btn-att a').eq(0).hide();
  1095. $('#btn-att a').eq(2).hide();
  1096. $('#btn-att a').eq(3).hide();
  1097. } else {
  1098. $('#btn-att').hide();
  1099. $('#btn-att a').eq(1).hide();
  1100. $('#btn-att a').eq(0).hide();
  1101. $('#btn-att a').eq(2).hide();
  1102. $('#btn-att a').eq(3).hide();
  1103. }
  1104. $('#showAttachment').attr('file-id', fid);
  1105. $('#showAttachment').show();
  1106. } else {
  1107. $('#showAttachment').hide();
  1108. $('#showAttachment').attr('file-id', '');
  1109. toast('附件信息获取失败', 'error');
  1110. }
  1111. });
  1112. $('body').on('click', '#btn-att a', function () {
  1113. const content = $(this).attr('content');
  1114. const fid = $('#showAttachment').attr('file-id');
  1115. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1116. if (content === 'edit') {
  1117. $('#btn-att a').eq(1).hide();
  1118. $('#btn-att a').eq(0).show();
  1119. $('#btn-att a').eq(2).show();
  1120. $('#btn-att a').eq(3).show();
  1121. $('#show-att').hide();
  1122. $('#edit-att').show();
  1123. const att = attData.find(function (item) {
  1124. return item.id === parseInt(fid);
  1125. });
  1126. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  1127. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  1128. const name = att.code !== null && att.code !== '' ? att.code : att.b_code;
  1129. $('#edit-att .form-group').eq(1).find('input').val(name + ' ' + att.lname);
  1130. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  1131. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  1132. } else if (content === 'cancel') {
  1133. $('#show-att').show();
  1134. $('#edit-att').hide();
  1135. $('#btn-att a').eq(1).show();
  1136. $('#btn-att a').eq(0).hide();
  1137. $('#btn-att a').eq(2).hide();
  1138. $('#btn-att a').eq(3).hide();
  1139. } else if (content === 'save') {
  1140. const formData = new FormData();
  1141. formData.append('id', fid);
  1142. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  1143. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  1144. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  1145. const file = $('#change-att-btn')[0];
  1146. if (file.files[0] !== undefined) {
  1147. const filesize = file.files[0].size;
  1148. formData.append('size', filesize);
  1149. formData.append('file', file.files[0]);
  1150. }
  1151. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/save/file', formData, function (data) {
  1152. // 替换到attData中
  1153. const att_index = attData.findIndex(function (item) {
  1154. return item.id === parseInt(fid);
  1155. });
  1156. attData.splice(att_index, 1, data);
  1157. // 重新生成List
  1158. getAllList(parseInt($('#currentPage').text()));
  1159. getNodeList(node.id);
  1160. $('#show-att').show();
  1161. $('#edit-att').hide();
  1162. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  1163. const name = data.code !== null && data.code !== '' ? data.code : data.b_code;
  1164. $('#show-att tr').eq(1).children('td').text(name + ' ' + data.lname);
  1165. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/download/file/' + data.id);
  1166. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  1167. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  1168. $('#show-att tr').eq(4).children('td').text(data.remark);
  1169. $('#btn-att a').eq(1).show();
  1170. $('#btn-att a').eq(0).hide();
  1171. $('#btn-att a').eq(2).hide();
  1172. $('#btn-att a').eq(3).hide();
  1173. }, function () {
  1174. toast('附件上传失败', 'error');
  1175. });
  1176. $('#change-att-btn').val('');
  1177. } else if (content === 'del') {
  1178. const data = {id: fid};
  1179. postData('/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/delete/file', data, function (result) {
  1180. // 删除到attData中
  1181. const att_index = attData.findIndex(function (item) {
  1182. return item.id === parseInt(fid);
  1183. });
  1184. attData.splice(att_index, 1);
  1185. // 重新生成List
  1186. getAllList();
  1187. getNodeList(node.id);
  1188. $('#showAttachment').hide();
  1189. $('#showAttachment').attr('file-id', '');
  1190. });
  1191. }
  1192. });
  1193. // 替换附件
  1194. $('#change-att-btn').on('change', function () {
  1195. const file = $('#change-att-btn')[0].files[0];
  1196. const name = file.name;
  1197. const filename = name.substring(0, name.lastIndexOf("."));
  1198. const fileext = name.substr(name.indexOf("."));
  1199. const filesize = file.size;
  1200. if (filesize > 10 * 1024 * 1024) {
  1201. toast('文件大小过大!', 'error');
  1202. $('#change-att-btn').val('');
  1203. return false;
  1204. }
  1205. if (whiteList.indexOf(fileext) === -1) {
  1206. toast('只能上传指定格式的附件!', 'error');
  1207. $('#change-att-btn').val('');
  1208. return false;
  1209. }
  1210. $('#edit-att .form-group').eq(0).find('input').val(filename);
  1211. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  1212. });
  1213. // 切换页数
  1214. $('.page-select').on('click', function () {
  1215. const totalPageNum = $('#totalPage').text();
  1216. const lastPageNum = $('#currentPage').text();
  1217. const status = $(this).attr('content');
  1218. console.log(totalPageNum,lastPageNum,status);
  1219. if (status === 'pre' && lastPageNum > 1) {
  1220. getAllList(parseInt(lastPageNum)-1);
  1221. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1222. getAllList(parseInt(lastPageNum)+1);
  1223. }
  1224. });
  1225. // 显示层次
  1226. (function (select, sheet) {
  1227. if (!sheet.zh_tree) return;
  1228. $(select).click(function () {
  1229. const tag = $(this).attr('tag');
  1230. const tree = sheet.zh_tree;
  1231. switch (tag) {
  1232. case "1":
  1233. case "2":
  1234. case "3":
  1235. case "4":
  1236. case "5":
  1237. tree.expandByLevel(parseInt(tag));
  1238. SpreadJsObj.refreshTreeRowVisible(sheet);
  1239. break;
  1240. case "last":
  1241. tree.expandByCustom(() => { return true; });
  1242. SpreadJsObj.refreshTreeRowVisible(sheet);
  1243. break;
  1244. case "leafXmj":
  1245. tree.expandToLeafXmj();
  1246. SpreadJsObj.refreshTreeRowVisible(sheet);
  1247. break;
  1248. case "curMeasure":
  1249. tree.expandByCustom(function (node) {
  1250. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1251. if (node[field]) {
  1252. return true;
  1253. }
  1254. }
  1255. return false;
  1256. });
  1257. SpreadJsObj.refreshTreeRowVisible(sheet);
  1258. break;
  1259. }
  1260. });
  1261. })('a[name=showLevel]', slSpread.getActiveSheet());
  1262. });