stage.js 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  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 tender.measure_type === measureType.tz.value;
  12. }
  13. /**
  14. * 从cookie中读取缓存的列显示设置,没有则取默认
  15. * @returns {*[]}
  16. */
  17. function customColDisplay () {
  18. const defaultSetting = [
  19. { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
  20. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  21. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  22. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  23. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  24. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  25. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp'], visible: true },
  26. { title: '图册号', fields: ['drawing_code'], visible: true },
  27. { title: '累计完成率(%)', fields: ['percent'], visible: true },
  28. { title: '备注', fields: ['memo'], visible: true },
  29. ];
  30. const settingStr = Cookies.get('stage-col-visible-1.0.0');
  31. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  32. }
  33. /**
  34. * 根据列显示设置,调整setting中的列是否显示
  35. * @param setting
  36. * @param customDisplay
  37. */
  38. function customizeStageTreeSetting(setting, customDisplay) {
  39. for (const cd of customDisplay) {
  40. for (const c of setting.cols) {
  41. if (cd.fields.indexOf(c.field) !== -1) {
  42. c.visible = cd.visible;
  43. }
  44. }
  45. }
  46. }
  47. /**
  48. * 初始化 树结构 列事件
  49. * @param setting
  50. */
  51. function initTreeColSettingEvents(setting) {
  52. const Events = {
  53. readOnly: {
  54. measureData: function (node) {
  55. return node.children && node.children.length > 0;
  56. },
  57. },
  58. };
  59. const getEvent = function (eventName) {
  60. const names = eventName.split('.');
  61. let event = Events;
  62. for (let name of names) {
  63. if (event[name]) {
  64. event = event[name];
  65. } else {
  66. return null;
  67. }
  68. }
  69. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  70. return null;
  71. } else {
  72. return event;
  73. }
  74. };
  75. for (const col of setting.cols) {
  76. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  77. col.readOnly = getEvent(col.readOnly);
  78. }
  79. }
  80. }
  81. function needCheckDetail() {
  82. stage.check_detail = true;
  83. $('#check_point').show();
  84. }
  85. // 生成所有附件列表
  86. function getAllList(currPageNum = 1) {
  87. // 每页最多几个附件
  88. const pageCount = 11;
  89. // 附件总数
  90. const total = attData.length;
  91. // 总页数
  92. const pageNum = Math.ceil(total/pageCount);
  93. $('#totalPage').text(pageNum);
  94. $('#currentPage').text(currPageNum);
  95. // 当前页附件内容
  96. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  97. let html = '';
  98. for(const att of currPageAttData) {
  99. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  100. }
  101. $('#alllist-table').html(html);
  102. }
  103. // 生成当前节点列表
  104. function getNodeList(node) {
  105. let html = '';
  106. for(const att of attData) {
  107. if (node === att.lid) {
  108. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  109. }
  110. }
  111. $('#nodelist-table').html(html);
  112. }
  113. $(document).ready(() => {
  114. // 提示窗
  115. toastr.options = {
  116. "closeButton": false,
  117. "debug": false,
  118. "newestOnTop": false,
  119. "progressBar": false,
  120. "positionClass": "toast-top-center",
  121. "preventDuplicates": false,
  122. "onclick": null,
  123. "showDuration": "300",
  124. "hideDuration": "1000",
  125. "timeOut": "5000",
  126. "extendedTimeOut": "1000",
  127. "showEasing": "swing",
  128. "hideEasing": "linear",
  129. "showMethod": "fadeIn",
  130. "hideMethod": "fadeOut"
  131. };
  132. // 界面布局
  133. autoFlashHeight();
  134. // 初始化 台账树结构 数据结构
  135. const stageTreeSetting = {
  136. id: 'ledger_id',
  137. pid: 'ledger_pid',
  138. order: 'order',
  139. level: 'level',
  140. rootId: -1,
  141. keys: ['id', 'tender_id', 'ledger_id'],
  142. stageId: 'id',
  143. };
  144. // 台账树结构计算相关设置
  145. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'];
  146. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  147. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  148. stageTreeSetting.calcFun = function (node) {
  149. if (node.children && node.children.length === 0) {
  150. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  151. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  152. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  153. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  154. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  155. }
  156. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  157. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  158. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  159. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  160. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  161. 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);
  162. };
  163. const stageTree = createNewPathTree('stage', stageTreeSetting);
  164. // 初始化 部位明细 数据结构
  165. const stagePosSetting = {
  166. id: 'id', ledgerId: 'lid',
  167. updateFields: ['contract_qty', 'qc_qty', 'postil'],
  168. };
  169. stagePosSetting.calcFun = function (pos) {
  170. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  171. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  172. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  173. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  174. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  175. };
  176. const stagePos = new StagePosData(stagePosSetting);
  177. class Changes {
  178. constructor(obj) {
  179. const self = this;
  180. this.obj = obj;
  181. // 初始化 清单编号窗口 参数
  182. this.spreadSetting = {
  183. cols: [
  184. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  185. if (data.uamount && !checkZero(data.uamount)) {
  186. return $('#icon-ok')[0];
  187. } else {
  188. return null;
  189. }
  190. }},
  191. {title: '变更令号', field: 'code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  192. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  193. {title: '总数量', field: 'b_amount', width: 60, formatter: '@', readOnly: true, hAlign: 2, },
  194. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  195. {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, type: 'Number', },
  196. ],
  197. emptyRows: 0,
  198. headRows: 1,
  199. headRowHeight: [40],
  200. getColor: function (data, col, defaultColor) {
  201. if (col.field === 'uamount') {
  202. if (!data.vamount) {
  203. return (data.uamount && data.uamount > 0) ? '#ff6f5c' : defaultColor;
  204. } else if (data.uamount) {
  205. return data.uamount > data.vamount ? '#ff6f5c' : defaultColor;
  206. } else {
  207. return defaultColor;
  208. }
  209. } else {
  210. return defaultColor;
  211. }
  212. }
  213. };
  214. this.curChangeId = '';
  215. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  216. this.firstView = true;
  217. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  218. // 初次显示,需刷新spread界面,保证界面绘制正确
  219. this.obj.bind('shown.bs.modal', function () {
  220. if (self.firstView) {
  221. self.firstView = false;
  222. self.spread.refresh();
  223. }
  224. });
  225. // 切换变更令,加载右侧明细数据
  226. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  227. const change = SpreadJsObj.getSelectObject(info.sheet);
  228. self._loadChangeDetail(change);
  229. });
  230. // 填写本期计量
  231. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  232. if (info.sheet.zh_setting) {
  233. const col = info.sheet.zh_setting.cols[info.col];
  234. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  235. const node = sortData[info.row];
  236. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  237. // 刷新界面
  238. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  239. }
  240. });
  241. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  242. if (info.sheet.zh_setting) {
  243. const sortData = SpreadJsObj.getSortData(info.sheet);
  244. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  245. const curRow = iRow + info.cellRange.row;
  246. const curCol = info.cellRange.col;
  247. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  248. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  249. }
  250. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  251. }
  252. });
  253. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  254. if (sheet.zh_setting) {
  255. const sel = sheet.getSelections()[0];
  256. const sortData = SpreadJsObj.getSortData(sheet);
  257. // 仅本期计量可删除
  258. if (sel.col === 5 || sel.colCount === 1) {
  259. const col = sheet.zh_setting.cols[sel.col];
  260. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  261. const data = sortData[iRow];
  262. data[col.field] = null;
  263. }
  264. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  265. }
  266. }
  267. });
  268. // 过滤可变更数量为0
  269. $('#filterEmpty').click(function () {
  270. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  271. });
  272. // 匹配编号
  273. $('#matchPos').click(function () {
  274. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  275. });
  276. // 展开收起 变更令详细信息
  277. $('#show-bgl-detail').bind('click', function () {
  278. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  279. if (detail.hasClass('col-4')) {
  280. detail.attr('class', 'col').hide();
  281. bgl.attr('class', 'col-12');
  282. $('a', obj).attr('title', '展开侧栏');
  283. $('i', obj).attr('class', 'fa fa-chevron-left');
  284. self.spread.refresh();
  285. } else {
  286. detail.attr('class', 'col-4').show();
  287. bgl.attr('class', 'col-8');
  288. $('a', obj).attr('title', '收起侧栏');
  289. $('i', obj).attr('class', 'fa fa-chevron-right');
  290. self.spread.refresh();
  291. }
  292. });
  293. // 添加调用变更令
  294. $('#usg-bg-ok').click(function () {
  295. const data = { target: self.callData, change: [] };
  296. for (const c of self.displayChanges) {
  297. if (c.uamount) {
  298. const vamount = (!c.vamount || checkZero(c.vamount)) ? 0 : c.vamount;
  299. if (c.uamount > vamount) {
  300. toast('变更令:' + c.code + ' 超计,请修改本期计量后,再提交', 'error');
  301. return;
  302. }
  303. // if (!c.vamount || checkZero(c.vamount)) {
  304. // toast('变更令:' + c.code + ' 当前不可使用', 'error');
  305. // return;
  306. // } else {
  307. // if (c.uamount > c.vamount) {
  308. // toast('变更令:' + c.code + ' 超计,请修改本期计量后,再提交', 'error');
  309. // return;
  310. // }
  311. // }
  312. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  313. }
  314. }
  315. // 提交数据到后端
  316. postData(window.location.pathname + '/use-change', data, function(result) {
  317. if (result.pos) {
  318. stagePos.loadCurStageData(result.pos.curStageData);
  319. }
  320. const nodes = stageTree.loadPostStageData(result.bills);
  321. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  322. stagePosSpreadObj.loadCurPosData();
  323. needCheckDetail();
  324. self.obj.modal('hide');
  325. });
  326. })
  327. }
  328. _calculateAmount() {
  329. for (const c of this.changes) {
  330. c.bamount = _.toNumber(c.b_amount);
  331. c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
  332. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  333. if (uc) {
  334. c.org_uamount = uc.qty;
  335. c.uamount = uc.qty;
  336. c.vamount = ZhCalc.add(c.vamount, c.uamount);
  337. }
  338. }
  339. }
  340. _loadChangeDetail(change) {
  341. if (change) {
  342. if (change.cid === this.curChangeId) { return; }
  343. this.curChangeId = change.cid;
  344. const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
  345. for (const i of inputs) {
  346. const field = $(i).attr('name');
  347. const text = (field && change[field]) ? change[field] : '';
  348. $(i).val(text);
  349. }
  350. const textareas = $('textarea', this.obj);
  351. for (const ta of textareas) {
  352. const field = $(ta).attr('name');
  353. const text = (field && change[field]) ? change[field] : '';
  354. ta.textContent = text;
  355. }
  356. const html = [];
  357. for (const a of change.attachments) {
  358. html.push('<tr>');
  359. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  360. html.push('<td>', a.u_name, '</td>');
  361. html.push('</tr>');
  362. }
  363. // 变更类型
  364. if (change.type) {
  365. const cType = change.type.split(',');
  366. $('input[name="type"]').prop("checked", false);
  367. for (const c of cType) {
  368. $('input[name="type"][value='+ c +']').prop("checked", true);
  369. }
  370. }
  371. // 变更类别
  372. $('select[name=class]').val(change.class);
  373. // 变更性质
  374. $('select[name=quality]').val(change.quality);
  375. // 变更单位
  376. $('select[name=company]').html('<option>' + change.company + '</option>');
  377. // 费用承担方
  378. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  379. // 附件
  380. $('#attachment').html(html.join(''));
  381. } else {
  382. const inputs = $('input', this.obj);
  383. for (const i of inputs) {
  384. $(i).val('');
  385. }
  386. const textareas = $('textarea', this.obj);
  387. for (const ta of textareas) {
  388. ta.innerText = '';
  389. }
  390. $('#attachment').html('');
  391. }
  392. }
  393. _viewChanges() {
  394. const sheet = this.spread.getActiveSheet();
  395. if (this.changes) {
  396. sheet.setSelection(0, 0, 1, 1);
  397. //SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, this.changes);
  398. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  399. this._loadChangeDetail(this.changes[0]);
  400. } else {
  401. toast('查询变更令有误,请刷新页面后重试', 'warning');
  402. }
  403. }
  404. _filterChange(filterEmpty, matchPosName) {
  405. this.displayChanges = [];
  406. for (const c of this.changes) {
  407. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  408. const matchVisible = matchPosName && this.callData.pos ? c.b_bwmx === this.callData.pos.name : true;
  409. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  410. this.displayChanges.push(c);
  411. }
  412. //c.visible = filterVisible && matchVisible;
  413. }
  414. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  415. //SpreadJsObj.refreshTreeRowVisible(this.spread.getActiveSheet());
  416. }
  417. loadChanges(data) {
  418. this.callData = data;
  419. if (this.callData.pos) {
  420. $('#matchPos').parent().show();
  421. } else {
  422. $('#matchPos').parent().hide();
  423. }
  424. const self = this;
  425. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  426. postData(window.location.pathname + '/valid-change', data, function (result) {
  427. self.changes = result.changes;
  428. self.useChanges = result.useChanges;
  429. self._calculateAmount();
  430. self._viewChanges();
  431. self.obj.modal('show');
  432. });
  433. }
  434. }
  435. const changesObj = new Changes($('#use-bg'));
  436. // 初始化 台账 spread
  437. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  438. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  439. // 数量变更列,添加按钮
  440. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  441. col.readOnly = true;
  442. col.cellType = 'imageBtn';
  443. col.hoverImg = '#ellipsis-icon';
  444. col.indent = 5;
  445. col.showImage = function (data) {
  446. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  447. return false;
  448. } else {
  449. const nodePos = stagePos.getLedgerPos(data.id);
  450. return !(nodePos && nodePos.length > 0);
  451. }
  452. };
  453. ledgerSpreadSetting.imageClick = function (data) {
  454. changesObj.loadChanges({bills: data});
  455. };
  456. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  457. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  458. stageTree.loadDatas(ledgerData);
  459. // stageTree.loadCurStageData(curStageData);
  460. // stageTree.loadPreStageData(preStageData);
  461. // 根据设置 计算 台账树结构
  462. treeCalc.calculateAll(stageTree);
  463. // 绘制界面
  464. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  465. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  466. //初始化所有附件列表
  467. getAllList();
  468. // 初始化 部位明细 Spread
  469. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  470. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  471. spCol.readOnly = true;
  472. spCol.cellType = 'imageBtn';
  473. spCol.hoverImg = '#ellipsis-icon';
  474. spCol.indent = 5;
  475. spCol.showImage = function (data) {
  476. return data;
  477. };
  478. posSpreadSetting.imageClick = function (data) {
  479. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  480. changesObj.loadChanges({bills: node, pos: data});
  481. };
  482. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  483. const stageTreeSpreadObj = {
  484. refreshTreeNodes: function (sheet, nodes) {
  485. const tree = sheet.zh_tree;
  486. if (!tree) { return }
  487. const rows = [];
  488. for (const node of nodes) {
  489. rows.push(tree.nodes.indexOf(node));
  490. }
  491. SpreadJsObj.reLoadRowsData(sheet, rows);
  492. },
  493. editEnded: function (e, info) {
  494. if (info.sheet.zh_setting) {
  495. const col = info.sheet.zh_setting.cols[info.col];
  496. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  497. const node = sortData[info.row], updateData = {};
  498. const orgValue = node[col.field];
  499. const newValue = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  500. if (orgValue == newValue || ((!orgValue || orgValue === '') && (newValue === ''))) {
  501. return;
  502. }
  503. if (col.field.indexOf('_dgn_') > 0) {
  504. if (node.b_code && node.b_code !== '') {
  505. toast('仅项目节可输入设计数量');
  506. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  507. return;
  508. }
  509. } else if (col.field !== 'postil') {
  510. if (node.children && node.children.length > 0) {
  511. toast('清单父项不可计量', 'error');
  512. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  513. return;
  514. } else {
  515. const nodePos = stagePos.getLedgerPos(node.id);
  516. if (nodePos && nodePos.length > 0) {
  517. toast('该清单有部位明细,请在部位明细处计量', 'error');
  518. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  519. return;
  520. }
  521. }
  522. }
  523. if (col.field.indexOf('_dgn_') > 0) {
  524. updateData.dgn = {
  525. id: node.id
  526. };
  527. updateData.dgn[col.field] = newValue;
  528. } else {
  529. updateData.stage = {
  530. lid: node.id
  531. };
  532. updateData.stage[col.field] = newValue;
  533. }
  534. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  535. const nodes = stageTree.loadPostStageData(data);
  536. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  537. needCheckDetail();
  538. });
  539. }
  540. },
  541. selectionChanged: function (e, info) {
  542. if (!info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  543. stagePosSpreadObj.loadCurPosData();
  544. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  545. posSearch.search();
  546. }
  547. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  548. },
  549. deletePress(sheet) {
  550. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  551. const tree = sheet.zh_tree;
  552. if (!tree) { return; }
  553. const sel = sheet.getSelections()[0];
  554. const validCols = [];
  555. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  556. if (!sheet.zh_setting.cols[iCol].readOnly) {
  557. validCols.push(iCol);
  558. }
  559. }
  560. if (validCols.length === 0) { return; }
  561. const sortData = sheet.zh_tree.nodes;
  562. const datas = [], dgnDatas = [];
  563. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  564. const node = sortData[iRow];
  565. if (node) {
  566. const data = { lid: node.id }, dgnData = { id: node.id };
  567. let filter = true, filterDgn = true;
  568. for (const iCol of validCols) {
  569. const colSetting = sheet.zh_setting.cols[iCol];
  570. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  571. if (node.b_code && node.b_code !== '') continue;
  572. } else if (colSetting.field !== 'postil') {
  573. if (node.children && node.children.length > 0) { continue; }
  574. const nodePos = stagePos.getLedgerPos(node.id);
  575. if (nodePos && nodePos.length > 0) { continue; }
  576. }
  577. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  578. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  579. dgnData[colSetting.field] = 0;
  580. filterDgn = false;
  581. }
  582. } else {
  583. data[colSetting.field] = null;
  584. filter = false;
  585. }
  586. }
  587. if (!filter) datas.push(data);
  588. if (!filterDgn) dgnDatas.push(dgnData);
  589. }
  590. }
  591. if (datas.length > 0 || dgnDatas.length > 0) {
  592. const bills = {};
  593. if (datas.length > 0) bills.stage = datas;
  594. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  595. postData(window.location.href + '/update', {bills: bills}, function (result) {
  596. const nodes = stageTree.loadPostStageData(result);
  597. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  598. needCheckDetail();
  599. });
  600. }
  601. }
  602. },
  603. clipboardPasting(e, info) {
  604. if (info.sheet.zh_setting) {
  605. const setting = info.sheet.zh_setting;
  606. const range = info.cellRange;
  607. const stageField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  608. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  609. const col = info.sheet.zh_setting.cols[iCol];
  610. if ((stageField.indexOf(col.field) === -1) && setting.dgnUpFields.indexOf(col.field) === -1) {
  611. toast('不可修改此数据', 'error');
  612. info.cancel = true;
  613. return;
  614. }
  615. }
  616. }
  617. },
  618. clipboardPasted(e, info) {
  619. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  620. const sheet = info.sheet, setting = info.sheet.zh_setting;
  621. const filterNodes = [], datas = [], dgnDatas = [];
  622. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  623. const curRow = iRow + info.cellRange.row;
  624. const node = sheet.zh_tree.getItemsByIndex(curRow);
  625. const data = {lid: node.id}, dgnData = {id: node.id};
  626. let filter = true, filterDgn = true;
  627. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  628. const curCol = info.cellRange.col + iCol;
  629. const col = info.sheet.zh_setting.cols[curCol];
  630. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  631. if (node.b_code && node.b_code !== '') continue;
  632. } else if (col.field !== 'postil') {
  633. if (node.children && node.children.length > 0) continue;
  634. const nodePos = stagePos.getLedgerPos(node.id);
  635. if (nodePos && nodePos.length > 0) continue;
  636. }
  637. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  638. dgnData[col.field] = _.toNumber(sheet.getText(curRow, curCol));
  639. filterDgn = false;
  640. } else {
  641. data[col.field] = col.type === 'Number' ? _.toNumber(sheet.getText(curRow, curCol)) : sheet.getText(curRow, curCol);
  642. filter = false;
  643. }
  644. }
  645. if (filter && filterDgn) {
  646. filterNodes.push(node);
  647. } else {
  648. if (!filter) datas.push(data);
  649. if (!filterDgn) dgnDatas.push(dgnData);
  650. }
  651. }
  652. if (datas.length > 0 || dgnDatas.length > 0) {
  653. const updateData = {};
  654. if (datas.length > 0) updateData.stage = datas;
  655. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  656. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  657. const nodes = stageTree.loadPostStageData(data);
  658. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  659. needCheckDetail();
  660. });
  661. } else {
  662. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  663. }
  664. }
  665. },
  666. measureAllPosInNode(node, ratio = 1) {
  667. const posterity = stageTree.getPosterity(node);
  668. const data = {updateType: 'update', updateData: []};
  669. for (const p of posterity) {
  670. if (p.children && p.children.length > 0) continue;
  671. const posRange = stagePos.getLedgerPos(p.id);
  672. if (posRange && posRange.length > 0) {
  673. for (const pr of posRange) {
  674. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  675. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  676. if (validValue <= 0) continue;
  677. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  678. const pData = {
  679. pid: pr.id,
  680. lid: pr.lid,
  681. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  682. };
  683. data.updateData.push(pData);
  684. }
  685. }
  686. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 200) {
  687. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  688. break;
  689. }
  690. }
  691. console.log(data);
  692. if (data.updateData.length === 0) {
  693. toastr.info('其下全部部位明细均已计量');
  694. return;
  695. }
  696. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  697. if (result.pos) {
  698. stagePos.updateDatas(result.pos.pos);
  699. stagePos.loadCurStageData(result.pos.curStageData);
  700. }
  701. const nodes = stageTree.loadPostStageData(result.ledger);
  702. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  703. stagePosSpreadObj.loadCurPosData();
  704. needCheckDetail();
  705. toastr.success('已计量' + data.updateData.length + '条');
  706. }, function () {
  707. stagePosSpreadObj.loadCurPosData();
  708. });
  709. },
  710. topRowChanged(e, info) {
  711. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  712. },
  713. };
  714. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  715. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  716. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  717. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  718. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  719. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  720. $.contextMenu({
  721. selector: '#stage-ledger',
  722. build: function ($trigger, e) {
  723. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  724. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  725. },
  726. items: {
  727. 'measureAll': {
  728. name: '计量其下所有部位明细',
  729. icon: 'fa-rocket',
  730. callback: function (key, opt) {
  731. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  732. stageTreeSpreadObj.measureAllPosInNode(node);
  733. },
  734. visible: function (key, opt) {
  735. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  736. return select;
  737. }
  738. },
  739. 'measureAllFiveTenth': {
  740. name: '计量其下所有部位明细(计量50%)',
  741. icon: 'fa-plane',
  742. callback: function (key, opt) {
  743. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  744. stageTreeSpreadObj.measureAllPosInNode(node, 0.5);
  745. },
  746. visible: function (key, opt) {
  747. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  748. return select;
  749. }
  750. },
  751. 'measureAllOneTenth': {
  752. name: '计量其下所有部位明细(计量10%)',
  753. icon: 'fa-car',
  754. callback: function (key, opt) {
  755. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  756. stageTreeSpreadObj.measureAllPosInNode(node, 0.1);
  757. },
  758. visible: function (key, opt) {
  759. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  760. return select;
  761. }
  762. },
  763. 'hint1': {
  764. name: '最多计量200条清单下1000条部位明细',
  765. className: 'text-danger',
  766. visible: function (key, opt) {
  767. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  768. return select;
  769. },
  770. disabled: function (key, opt) {
  771. return true;
  772. }
  773. },
  774. 'hint1_1': {
  775. name: '(计数以清单为准,会计完清单下全部部位)',
  776. className: 'text-danger',
  777. visible: function (key, opt) {
  778. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  779. return select;
  780. },
  781. disabled: function (key, opt) {
  782. return true;
  783. }
  784. },
  785. 'hint2': {
  786. name: '可再次使用该功能计量剩下的节点',
  787. className: 'text-danger',
  788. visible: function (key, opt) {
  789. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  790. return select;
  791. },
  792. disabled: function (key, opt) {
  793. return true;
  794. }
  795. },
  796. 'hint2_2': {
  797. name: '(凡是计量的部位,不论计量多少,均不再计量)',
  798. className: 'text-danger',
  799. visible: function (key, opt) {
  800. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  801. return select;
  802. },
  803. disabled: function (key, opt) {
  804. return true;
  805. }
  806. },
  807. 'hint3': {
  808. name: '如提示数据过多后,未成功,请缩小范围再试',
  809. className: 'text-danger',
  810. visible: function (key, opt) {
  811. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  812. return select;
  813. },
  814. disabled: function (key, opt) {
  815. return true;
  816. }
  817. },
  818. 'hint4': {
  819. name: '该功能仅供测试用,请勿滥用,可能导致服务挂掉',
  820. className: 'text-danger',
  821. visible: function (key, opt) {
  822. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  823. return select;
  824. },
  825. disabled: function (key, opt) {
  826. return true;
  827. }
  828. },
  829. }
  830. });
  831. const stagePosSpreadObj = {
  832. /**
  833. * 加载部位明细 根据当前台账选择节点
  834. */
  835. loadCurPosData: function () {
  836. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  837. if (node) {
  838. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  839. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  840. getNodeList(node.id);
  841. // 如果是附件是当前节点,隐藏
  842. if ($('#dqjiedian').hasClass('active')) {
  843. $('#showAttachment').hide();
  844. }
  845. } else {
  846. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  847. }
  848. },
  849. editEnded: function (e, info) {
  850. if (info.sheet.zh_setting) {
  851. // 未改变过,则直接跳过
  852. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  853. const col = info.sheet.zh_setting.cols[info.col];
  854. const orgText = posData ? posData[col.field] : null;
  855. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  856. return;
  857. }
  858. // 台账模式下,不可新增
  859. if (checkTzMeasureType() && !posData) {
  860. toast('台账模式不可新增部位明细数据', 'error');
  861. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  862. info.cancel = true;
  863. return ;
  864. }
  865. // 不同节点下,部位明细检查输入
  866. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  867. const node = stagePosSpreadObj.stageTreeNode;
  868. if (!node) {
  869. toast('数据错误, 请刷新页面后再试', 'warning');
  870. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  871. return;
  872. } else if (info.editingText !== '' && node.children && node.children > 0) {
  873. toast('父节点不可插入部位明细', 'error');
  874. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  875. return;
  876. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  877. toast('项目节不可插入部位明细', 'error');
  878. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  879. return;
  880. }
  881. // 生成提交数据
  882. const data = {};
  883. if (col.field === 'name') {
  884. if (info.editingText === '' && pos) {
  885. toast('部位名称不可为空', 'error', 'exclamation-circle');
  886. info.cancel = true;
  887. return;
  888. } else if (!posData) {
  889. if (info.editingText !== '') {
  890. data.updateType = 'add';
  891. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
  892. } else {
  893. return;
  894. }
  895. } else {
  896. data.updateType = 'update';
  897. data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
  898. }
  899. } else if (!posData) {
  900. toast('新增部位请先输入名称', 'warning');
  901. } else {
  902. data.updateType = 'update';
  903. data.updateData = {pid: posData.id, lid: posData.lid};
  904. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  905. }
  906. // 提交数据到服务器
  907. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  908. if (result.pos) {
  909. stagePos.updateDatas(result.pos.pos);
  910. stagePos.loadCurStageData(result.pos.curStageData);
  911. }
  912. const refreshData = stageTree.loadPostStageData(result.ledger);
  913. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  914. stagePosSpreadObj.loadCurPosData();
  915. needCheckDetail();
  916. }, function () {
  917. stagePosSpreadObj.loadCurPosData();
  918. });
  919. }
  920. },
  921. editStarting: function (e, info) {
  922. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  923. },
  924. clipboardPasting: function (e, info) {
  925. if (info.sheet.zh_setting) {
  926. const sortData = info.sheet.zh_data;
  927. const range = info.cellRange;
  928. const validField = ['contract_qty', 'qc_qty', 'postil'];
  929. if (!checkTzMeasureType()) {
  930. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
  931. }
  932. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  933. const col = info.sheet.zh_setting.cols[iCol];
  934. if (validField.indexOf(col.field) === -1) {
  935. if (checkTzMeasureType()) {
  936. toast('不可修改此数据', 'error');
  937. info.cancel = true;
  938. return;
  939. } else {
  940. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  941. const pos = sortData(iRow);
  942. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  943. toast('不可修改此数据', 'error');
  944. info.cancel = true;
  945. return;
  946. }
  947. }
  948. }
  949. }
  950. }
  951. }
  952. },
  953. clipboardPasted: function (e, info) {
  954. const self = this;
  955. if (info.sheet.zh_setting) {
  956. const data = { updateType: '', updateData: [], };
  957. const sortData = info.sheet.zh_data;
  958. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  959. if (sortData && (info.cellRange.row >= sortData.length)) {
  960. data.updateType = 'add';
  961. if (info.cellRange.col !== 0) {
  962. toast('新增部位请先输入名称', 'warning');
  963. self.loadCurPosData();
  964. return;
  965. }
  966. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  967. const curRow = info.cellRange.row + iRow;
  968. const newData = {lid: node.id};
  969. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  970. const curCol = info.cellRange.col + iCol;
  971. const colSetting = info.sheet.zh_setting.cols[curCol];
  972. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  973. if (colSetting.type === 'Number') {
  974. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  975. }
  976. }
  977. data.updateData.push(newData);
  978. }
  979. } else {
  980. data.updateType = 'update';
  981. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  982. const curRow = info.cellRange.row + iRow;
  983. const curPos = sortData[curRow];
  984. if (curPos) {
  985. const newData = {pid: curPos.id, lid: curPos.lid};
  986. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  987. const curCol = info.cellRange.col + iCol;
  988. const colSetting = info.sheet.zh_setting.cols[curCol];
  989. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  990. if (colSetting.type === 'Number') {
  991. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  992. }
  993. }
  994. data.updateData.push(newData);
  995. }
  996. }
  997. }
  998. console.log(data);
  999. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1000. if (result.pos) {
  1001. stagePos.updateDatas(result.pos.pos);
  1002. stagePos.loadCurStageData(result.pos.curStageData);
  1003. }
  1004. const nodes = stageTree.loadPostStageData(result.ledger);
  1005. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1006. stagePosSpreadObj.loadCurPosData();
  1007. needCheckDetail();
  1008. }, function () {
  1009. stagePosSpreadObj.loadCurPosData();
  1010. });
  1011. }
  1012. },
  1013. deletePress: function (sheet) {
  1014. if (sheet.zh_setting && sheet.zh_data) {
  1015. const sortData = sheet.zh_data;
  1016. if (!sortData || sortData.length === 0) { return; }
  1017. const sel = sheet.getSelections()[0];
  1018. const validCols = [];
  1019. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1020. if (!sheet.zh_setting.cols[iCol].readOnly) {
  1021. validCols.push(iCol);
  1022. }
  1023. }
  1024. if (validCols.length === 0) { return; }
  1025. const datas = [], posSelects = [];
  1026. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1027. const node = sortData[iRow];
  1028. if (node) {
  1029. const data = {pid: node.id, lid: node.lid};
  1030. for (const iCol of validCols) {
  1031. const colSetting = sheet.zh_setting.cols[iCol];
  1032. if (colSetting.field === 'name') {
  1033. toast('部位名称不能为空', 'error');
  1034. return;
  1035. }
  1036. data[colSetting.field] = null;
  1037. }
  1038. datas.push(data);
  1039. posSelects.push(node);
  1040. }
  1041. }
  1042. if (datas.length > 0) {
  1043. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1044. if (result.pos) {
  1045. stagePos.updateDatas(result.pos.pos);
  1046. stagePos.loadCurStageData(result.pos.curStageData);
  1047. }
  1048. const nodes = stageTree.loadPostStageData(result.ledger);
  1049. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1050. needCheckDetail();
  1051. // todo 只加载改变项
  1052. stagePosSpreadObj.loadCurPosData();
  1053. });
  1054. }
  1055. }
  1056. },
  1057. leaveCell: function (e, info) {
  1058. console.log(1);
  1059. },
  1060. };
  1061. // 加载上下窗口resizer
  1062. $.divResizer({
  1063. select: '#main-resize',
  1064. callback: function () {
  1065. slSpread.refresh();
  1066. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1067. $(".sp-wrap").height(bcontent-40);
  1068. spSpread.refresh();
  1069. }
  1070. });
  1071. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1072. console.time('loadPosFromServer');
  1073. postData(window.location.pathname + '/pos', null, function (result) {
  1074. console.timeEnd('loadPosFromServer');
  1075. console.log('pos: ' + result.length);
  1076. stagePos.loadDatas(result);
  1077. stagePos.calculateAll();
  1078. stagePosSpreadObj.loadCurPosData();
  1079. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1080. });
  1081. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1082. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1083. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1084. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1085. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1086. if (!checkTzMeasureType()) {
  1087. }
  1088. $('#row-view').on('show.bs.modal', function () {
  1089. const html = [], customDisplay = customColDisplay();
  1090. for (const cd of customDisplay) {
  1091. html.push('<tr>');
  1092. html.push('<td>', cd.title, '</td>');
  1093. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1094. html.push('</tr>');
  1095. }
  1096. $('#row-view-list').html(html.join(''));
  1097. });
  1098. $('#row-view-ok').click(function () {
  1099. const customDisplay = customColDisplay();
  1100. const cvl = $('#row-view-list').children();
  1101. for (const cv of cvl) {
  1102. const title = $(cv).children()[0].innerHTML;
  1103. const check = $('input', cv)[0].checked;
  1104. const cd = customDisplay.find(function (c) {
  1105. return c.title === title;
  1106. });
  1107. cd.visible = check;
  1108. }
  1109. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1110. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1111. Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
  1112. $('#row-view').modal('hide');
  1113. });
  1114. class SearchLedger {
  1115. constructor(obj, mainSpread) {
  1116. const self = this;
  1117. this.obj = obj;
  1118. this.mainSpread = mainSpread;
  1119. this.spreadSetting = {
  1120. cols: [
  1121. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  1122. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  1123. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@'},
  1124. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  1125. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1126. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  1127. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  1128. ],
  1129. emptyRows: 3,
  1130. headRows: 1,
  1131. headRowHeight: [40],
  1132. defaultRowHeight: 21,
  1133. readOnly: true
  1134. };
  1135. this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
  1136. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1137. $('#keyword', this.obj).bind('keydown', function(e) {
  1138. if (e.keyCode == 13) self.searchText();
  1139. });
  1140. $('#searchLedger', this.obj).bind('click', () => {self.searchText()});
  1141. $('#over', this.obj).bind('change', () => {self.searchOver()});
  1142. $('#empty', this.obj).bind('change', () => {self.searchEmpty()});
  1143. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1144. const sheet = info.sheet;
  1145. const data = sheet.zh_data;
  1146. if (!data) { return }
  1147. const curBills = data[info.row];
  1148. if (!curBills) { return }
  1149. SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id);
  1150. });
  1151. }
  1152. searchText() {
  1153. const keyword = $('#keyword', this.obj).val();
  1154. if (keyword !== '') {
  1155. $('#over', this.obj)[0].checked = false;
  1156. $('#empty', this.obj)[0].checked = false;
  1157. this.searchResult = [];
  1158. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1159. for (const node of sortData) {
  1160. if ((node.code && node.code.indexOf(keyword) > -1) ||
  1161. node.b_code && node.b_code.indexOf(keyword) > -1 ||
  1162. node.name && node.name.indexOf(keyword) > -1) {
  1163. this.searchResult.push(node);
  1164. }
  1165. }
  1166. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1167. }
  1168. }
  1169. searchOver() {
  1170. this.searchResult = [];
  1171. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1172. for (const node of sortData) {
  1173. if (node.children && node.children.length > 0) continue;
  1174. if (node.end_gather_qty) {
  1175. if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(node.quantity)) {
  1176. this.searchResult.push(node);
  1177. }
  1178. } else if (node.end_gather_tp) {
  1179. if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(node.total_price)) {
  1180. this.searchResult.push(node);
  1181. }
  1182. }
  1183. }
  1184. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1185. }
  1186. searchEmpty() {
  1187. this.searchResult = [];
  1188. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1189. for (const node of sortData) {
  1190. if (node.children && node.children.length > 0) continue;
  1191. if (node.quantity) {
  1192. if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
  1193. this.searchResult.push(node);
  1194. }
  1195. } else if (node.total_price) {
  1196. if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
  1197. this.searchResult.push(node);
  1198. }
  1199. }
  1200. }
  1201. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1202. }
  1203. }
  1204. let searchLedger;
  1205. const posSearch = (function () {
  1206. let resultArr = [];
  1207. const search = function () {
  1208. resultArr = [];
  1209. const keyword = $('#pos-search-keyword').val();
  1210. const checkOver = $('#pos-over-search')[0].checked;
  1211. const checkEmpty = $('#pos-empty-search')[0].checked;
  1212. const sortData = spSpread.getActiveSheet().zh_data;
  1213. if (checkOver || checkEmpty) {
  1214. if (sortData) {
  1215. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1216. const sd = sortData[i];
  1217. let match = false;
  1218. if (checkOver) {
  1219. if (sd.end_gather_qty) {
  1220. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(sd.quantity)) match = true;
  1221. }
  1222. }
  1223. if (checkEmpty) {
  1224. if (sd.quantity) {
  1225. if (!sd.end_gather_qty || checkZero(sd.end_gather_qty)) match = true;
  1226. }
  1227. }
  1228. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1229. if (match) {
  1230. resultArr.push({index: i, data: sd});
  1231. }
  1232. }
  1233. }
  1234. } else if (keyword && keyword !== '') {
  1235. if (sortData) {
  1236. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1237. const sd = sortData[i];
  1238. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1239. resultArr.push({index: i, data: sd});
  1240. }
  1241. }
  1242. }
  1243. }
  1244. $('#pos-search-result').html('结果:' + resultArr.length);
  1245. };
  1246. const searchAndLocate = function () {
  1247. search();
  1248. if (resultArr.length > 0) {
  1249. const sheet = spSpread.getActiveSheet();
  1250. const sel = sheet.getSelections()[0];
  1251. const curRow = sel ? sel.row : 0;
  1252. const pos = resultArr[0];
  1253. if (pos.index !== curRow) {
  1254. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1255. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1256. }
  1257. }
  1258. };
  1259. const locateNext = function () {
  1260. if (resultArr.length > 0) {
  1261. const sheet = spSpread.getActiveSheet();
  1262. const sel = sheet.getSelections()[0];
  1263. const curRow = sel ? sel.row : 0;
  1264. let next = _.find(resultArr, function (d) {
  1265. return d.index > curRow;
  1266. });
  1267. if (!next) next = resultArr[0];
  1268. if (next.index !== curRow) {
  1269. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1270. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1271. }
  1272. }
  1273. };
  1274. const locatePre = function () {
  1275. if (resultArr.length > 0) {
  1276. const sheet = spSpread.getActiveSheet();
  1277. const sel = sheet.getSelections()[0];
  1278. const curRow = sel ? sel.row : 0;
  1279. let next = _.findLast(resultArr, function (d) {
  1280. return d.index < curRow;
  1281. });
  1282. if (!next) next = resultArr[resultArr.length - 1];
  1283. if (next.index !== curRow) {
  1284. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1285. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1286. }
  1287. }
  1288. };
  1289. return {search, searchAndLocate, locateNext, locatePre};
  1290. })();
  1291. $('#pos-search-keyword').bind('keydown', function(e){
  1292. if (e.keyCode == 13) posSearch.searchAndLocate();
  1293. });
  1294. $('#pos-empty-search').click(function () {
  1295. if (this.checked) {
  1296. $('[for=' + this.id +']').addClass('text-warning');
  1297. } else {
  1298. $('[for=' + this.id +']').removeClass('text-warning');
  1299. }
  1300. posSearch.searchAndLocate();
  1301. });
  1302. $('#pos-over-search').click(function () {
  1303. if (this.checked) {
  1304. $('[for=' + this.id +']').addClass('text-danger');
  1305. } else {
  1306. $('[for=' + this.id +']').removeClass('text-danger');
  1307. }
  1308. posSearch.searchAndLocate();
  1309. });
  1310. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1311. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1312. $.divResizer({
  1313. select: '#right-spr',
  1314. callback: function () {
  1315. slSpread.refresh();
  1316. spSpread.refresh();
  1317. if (searchLedger) {
  1318. searchLedger.spread.refresh();
  1319. }
  1320. }
  1321. });
  1322. // 展开收起附件
  1323. $('a', '.right-nav').bind('click', function () {
  1324. //const main = $('#main-view'), tool = $('#tools-view');
  1325. const tab = $(this), tabPanel = $(tab.attr('content'));
  1326. const showTools = function (show) {
  1327. const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
  1328. if (show) {
  1329. right.show();
  1330. autoFlashHeight();
  1331. /**
  1332. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1333. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1334. * 故需要通过最终的parent.width再计算一次left.width
  1335. *
  1336. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1337. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1338. *
  1339. */
  1340. //left.css('width', parent.width() - right.outerWidth());
  1341. //left.css('width', parent.width() - right.outerWidth());
  1342. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1343. left.css('width', percent + '%');
  1344. } else {
  1345. right.hide();
  1346. left.css('width', '100%');
  1347. }
  1348. };
  1349. if (!tab.hasClass('active')) {
  1350. $('a', '.side-menu').removeClass('active');
  1351. $('.tab-content .tab-select-show').removeClass('active');
  1352. tab.addClass('active');
  1353. tabPanel.addClass('active');
  1354. showTools(tab.hasClass('active'));
  1355. if (tab.attr('content') === '#search' && !searchLedger) {
  1356. searchLedger = new SearchLedger($('#search'), slSpread);
  1357. searchLedger.spread.refresh();
  1358. }
  1359. if (tab.attr('content') === '#fujian') {
  1360. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1361. getNodeList(node.id);
  1362. }
  1363. } else {
  1364. tab.removeClass('active');
  1365. tabPanel.removeClass('active');
  1366. showTools(tab.hasClass('active'));
  1367. }
  1368. slSpread.refresh();
  1369. spSpread.refresh();
  1370. });
  1371. // 切换附件里节点和所有附件
  1372. $('#fujian .nav-link').on('click', function () {
  1373. const tabPanel = $(this).attr('fujian-content');
  1374. if (tabPanel !== 'syfujian') {
  1375. $('#showPage').hide();
  1376. } else {
  1377. $('#showPage').show();
  1378. }
  1379. $('#showAttachment').hide();
  1380. });
  1381. // 上传附件
  1382. $('#upload-file-btn').click(function () {
  1383. const files = $('#upload-file')[0].files;
  1384. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1385. const formData = new FormData();
  1386. formData.append('lid', node.id);
  1387. for (const file of files) {
  1388. if (file === undefined) {
  1389. toast('未选择上传文件!', 'error');
  1390. return false;
  1391. }
  1392. const filesize = file.size;
  1393. if (filesize > 10 * 1024 * 1024) {
  1394. toast('存在上传文件大小过大!', 'error');
  1395. return false;
  1396. }
  1397. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  1398. if (whiteList.indexOf(fileext) === -1) {
  1399. toast('只能上传指定格式的附件!', 'error');
  1400. return false;
  1401. }
  1402. formData.append('size', filesize);
  1403. formData.append('file[]', file);
  1404. }
  1405. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  1406. $('#upload').modal('hide');
  1407. // 插入到attData中
  1408. attData = data.concat(attData);
  1409. // 重新生成List
  1410. getAllList();
  1411. getNodeList(node.id);
  1412. }, function () {
  1413. toast('附件上传失败', 'error');
  1414. });
  1415. $('#upload-file').val('');
  1416. });
  1417. // 获取附件信息
  1418. $('body').on('click', '.list-table a', function () {
  1419. const fid = $(this).attr('file-id');
  1420. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1421. return;
  1422. }
  1423. const att = attData.find(function (item) {
  1424. return item.id === parseInt(fid);
  1425. });
  1426. $('#edit-att').hide();
  1427. $('#show-att').show();
  1428. if (att !== undefined) {
  1429. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1430. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1431. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  1432. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  1433. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  1434. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  1435. $('#show-att tr').eq(4).children('td').text(att.remark);
  1436. if (parseInt(userID) === att.uid) {
  1437. $('#btn-att').show();
  1438. $('#btn-att a').eq(1).show();
  1439. $('#btn-att a').eq(0).hide();
  1440. $('#btn-att a').eq(2).hide();
  1441. $('#btn-att a').eq(3).hide();
  1442. } else {
  1443. $('#btn-att').hide();
  1444. $('#btn-att a').eq(1).hide();
  1445. $('#btn-att a').eq(0).hide();
  1446. $('#btn-att a').eq(2).hide();
  1447. $('#btn-att a').eq(3).hide();
  1448. }
  1449. $('#showAttachment').attr('file-id', fid);
  1450. $('#showAttachment').show();
  1451. } else {
  1452. $('#showAttachment').hide();
  1453. $('#showAttachment').attr('file-id', '');
  1454. toast('附件信息获取失败', 'error');
  1455. }
  1456. });
  1457. $('body').on('click', '#btn-att a', function () {
  1458. const content = $(this).attr('content');
  1459. const fid = $('#showAttachment').attr('file-id');
  1460. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1461. if (content === 'edit') {
  1462. $('#btn-att a').eq(1).hide();
  1463. $('#btn-att a').eq(0).show();
  1464. $('#btn-att a').eq(2).show();
  1465. $('#btn-att a').eq(3).show();
  1466. $('#show-att').hide();
  1467. $('#edit-att').show();
  1468. const att = attData.find(function (item) {
  1469. return item.id === parseInt(fid);
  1470. });
  1471. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  1472. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  1473. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1474. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  1475. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  1476. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  1477. } else if (content === 'cancel') {
  1478. $('#show-att').show();
  1479. $('#edit-att').hide();
  1480. $('#btn-att a').eq(1).show();
  1481. $('#btn-att a').eq(0).hide();
  1482. $('#btn-att a').eq(2).hide();
  1483. $('#btn-att a').eq(3).hide();
  1484. } else if (content === 'save') {
  1485. const formData = new FormData();
  1486. formData.append('id', fid);
  1487. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  1488. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  1489. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  1490. const file = $('#change-att-btn')[0];
  1491. if (file.files[0] !== undefined) {
  1492. const filesize = file.files[0].size;
  1493. formData.append('size', filesize);
  1494. formData.append('file', file.files[0]);
  1495. }
  1496. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  1497. // 替换到attData中
  1498. const att_index = attData.findIndex(function (item) {
  1499. return item.id === parseInt(fid);
  1500. });
  1501. attData.splice(att_index, 1, data);
  1502. // 重新生成List
  1503. getAllList(parseInt($('#currentPage').text()));
  1504. getNodeList(node.id);
  1505. $('#show-att').show();
  1506. $('#edit-att').hide();
  1507. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  1508. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  1509. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  1510. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  1511. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  1512. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  1513. $('#show-att tr').eq(4).children('td').text(data.remark);
  1514. $('#btn-att a').eq(1).show();
  1515. $('#btn-att a').eq(0).hide();
  1516. $('#btn-att a').eq(2).hide();
  1517. $('#btn-att a').eq(3).hide();
  1518. }, function () {
  1519. toast('附件上传失败', 'error');
  1520. });
  1521. $('#change-att-btn').val('');
  1522. } else if (content === 'del') {
  1523. const data = {id: fid};
  1524. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  1525. // 删除到attData中
  1526. const att_index = attData.findIndex(function (item) {
  1527. return item.id === parseInt(fid);
  1528. });
  1529. attData.splice(att_index, 1);
  1530. // 重新生成List
  1531. getAllList();
  1532. getNodeList(node.id);
  1533. $('#showAttachment').hide();
  1534. $('#showAttachment').attr('file-id', '');
  1535. });
  1536. }
  1537. });
  1538. // 替换附件
  1539. $('#change-att-btn').on('change', function () {
  1540. const file = $('#change-att-btn')[0].files[0];
  1541. const name = file.name;
  1542. const filename = name.substring(0, name.lastIndexOf("."));
  1543. const fileext = name.substr(name.indexOf("."));
  1544. const filesize = file.size;
  1545. if (filesize > 10 * 1024 * 1024) {
  1546. toast('文件大小过大!', 'error');
  1547. $('#change-att-btn').val('');
  1548. return false;
  1549. }
  1550. if (whiteList.indexOf(fileext) === -1) {
  1551. toast('只能上传指定格式的附件!', 'error');
  1552. $('#change-att-btn').val('');
  1553. return false;
  1554. }
  1555. $('#edit-att .form-group').eq(0).find('input').val(filename);
  1556. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  1557. });
  1558. // 切换页数
  1559. $('.page-select').on('click', function () {
  1560. const totalPageNum = $('#totalPage').text();
  1561. const lastPageNum = $('#currentPage').text();
  1562. const status = $(this).attr('content');
  1563. if (status === 'pre' && lastPageNum > 1) {
  1564. getAllList(parseInt(lastPageNum)-1);
  1565. $('#showAttachment').hide();
  1566. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1567. getAllList(parseInt(lastPageNum)+1);
  1568. $('#showAttachment').hide();
  1569. }
  1570. });
  1571. // 显示层次
  1572. (function (select, sheet) {
  1573. if (!sheet.zh_tree) return;
  1574. $(select).click(function () {
  1575. const tag = $(this).attr('tag');
  1576. const tree = sheet.zh_tree;
  1577. switch (tag) {
  1578. case "1":
  1579. case "2":
  1580. case "3":
  1581. case "4":
  1582. case "5":
  1583. tree.expandByLevel(parseInt(tag));
  1584. SpreadJsObj.refreshTreeRowVisible(sheet);
  1585. break;
  1586. case "last":
  1587. tree.expandByCustom(() => { return true; });
  1588. SpreadJsObj.refreshTreeRowVisible(sheet);
  1589. break;
  1590. case "leafXmj":
  1591. tree.expandToLeafXmj();
  1592. SpreadJsObj.refreshTreeRowVisible(sheet);
  1593. break;
  1594. case "curMeasure":
  1595. tree.expandByCustom(function (node) {
  1596. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1597. if (node[field]) {
  1598. return true;
  1599. }
  1600. }
  1601. return false;
  1602. });
  1603. SpreadJsObj.refreshTreeRowVisible(sheet);
  1604. break;
  1605. }
  1606. });
  1607. })('a[name=showLevel]', slSpread.getActiveSheet());
  1608. });