stage.js 78 KB

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