stage.js 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  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 (parseInt(node) === parseInt(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.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.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, },
  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 ? '#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.changes) {
  297. if (c.uamount) {
  298. if (!c.vamount || checkZero(c.vamount)) {
  299. toast('变更令:' + c.code + ' 当前不可使用', 'error');
  300. return;
  301. } else {
  302. if (c.uamount > c.vamount) {
  303. toast('变更令:' + c.code + ' 超计,请修改本期计量后,再提交', 'error');
  304. return;
  305. }
  306. }
  307. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  308. }
  309. }
  310. // 提交数据到后端
  311. postData(window.location.pathname + '/use-change', data, function(result) {
  312. if (result.pos) {
  313. stagePos.loadCurStageData(result.pos.curStageData);
  314. }
  315. const nodes = stageTree.loadPostStageData(result.bills);
  316. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  317. stagePosSpreadObj.loadCurPosData();
  318. needCheckDetail();
  319. self.obj.modal('hide');
  320. });
  321. })
  322. }
  323. _calculateAmount() {
  324. for (const c of this.changes) {
  325. c.bamount = _.toNumber(c.b_amount);
  326. c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
  327. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  328. if (uc) {
  329. c.uamount = uc.qty;
  330. c.vamount = ZhCalc.add(c.vamount, c.uamount);
  331. }
  332. }
  333. }
  334. _loadChangeDetail(change) {
  335. if (change) {
  336. if (change.cid === this.curChangeId) { return; }
  337. this.curChangeId = change.cid;
  338. const inputs = $('input[type!=checkbox]', this.obj);
  339. for (const i of inputs) {
  340. const field = $(i).attr('name');
  341. const text = (field && change[field]) ? change[field] : '';
  342. $(i).val(text);
  343. }
  344. const textareas = $('textarea', this.obj);
  345. for (const ta of textareas) {
  346. const field = $(ta).attr('name');
  347. const text = (field && change[field]) ? change[field] : '';
  348. ta.innerText = text;
  349. }
  350. const html = [];
  351. for (const a of change.attachments) {
  352. html.push('<tr>');
  353. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  354. html.push('<td>', a.u_name, '</td>');
  355. html.push('</tr>');
  356. }
  357. // 变更类型
  358. if (change.type) {
  359. const cType = change.type.split(',');
  360. $('input[name="type"]').prop("checked", false);
  361. for (const c of cType) {
  362. $('input[name="type"][value='+ c +']').prop("checked", true);
  363. }
  364. }
  365. // 变更类别
  366. $('select[name=class]').val(change.class);
  367. // 变更性质
  368. $('select[name=quality]').val(change.quality);
  369. // 变更单位
  370. $('select[name=company]').html('<option>' + change.company + '</option>');
  371. // 费用承担方
  372. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  373. // 附件
  374. $('#attachment').html(html.join(''));
  375. } else {
  376. const inputs = $('input', this.obj);
  377. for (const i of inputs) {
  378. $(i).val('');
  379. }
  380. const textareas = $('textarea', this.obj);
  381. for (const ta of textareas) {
  382. ta.innerText = '';
  383. }
  384. $('#attachment').html('');
  385. }
  386. }
  387. _viewChanges() {
  388. const sheet = this.spread.getActiveSheet();
  389. if (this.changes) {
  390. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, this.changes);
  391. sheet.setSelection(0, 0, 1, 1);
  392. this._loadChangeDetail(this.changes[0]);
  393. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  394. } else {
  395. toast('查询变更令有误,请刷新页面后重试', 'warning');
  396. }
  397. }
  398. _filterChange(filterEmpty, matchPosName) {
  399. for (const c of this.changes) {
  400. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  401. const matchVisible = matchPosName && this.callData.pos ? c.b_bwmx === this.callData.pos.name : true;
  402. c.visible = filterVisible && matchVisible;
  403. }
  404. SpreadJsObj.refreshTreeRowVisible(this.spread.getActiveSheet());
  405. }
  406. loadChanges(data) {
  407. this.callData = data;
  408. if (this.callData.pos) {
  409. $('#matchPos').parent().show();
  410. } else {
  411. $('#matchPos').parent().hide();
  412. }
  413. const self = this;
  414. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  415. postData(window.location.pathname + '/valid-change', data, function (result) {
  416. self.changes = result.changes;
  417. self.useChanges = result.useChanges;
  418. self._calculateAmount();
  419. self._viewChanges();
  420. self.obj.modal('show');
  421. });
  422. }
  423. }
  424. const changesObj = new Changes($('#use-bg'));
  425. // 初始化 台账 spread
  426. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  427. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  428. // 数量变更列,添加按钮
  429. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  430. col.readOnly = true;
  431. col.cellType = 'imageBtn';
  432. col.hoverImg = '#ellipsis-icon';
  433. col.indent = 5;
  434. col.showImage = function (data) {
  435. if (!data || (data.children && data.children.length > 0)) {
  436. return false;
  437. } else {
  438. const nodePos = stagePos.getLedgerPos(data.id);
  439. return !(nodePos && nodePos.length > 0);
  440. }
  441. };
  442. ledgerSpreadSetting.imageClick = function (data) {
  443. changesObj.loadChanges({bills: data});
  444. };
  445. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  446. stageTree.loadDatas(ledgerData);
  447. stageTree.loadCurStageData(curStageData);
  448. stageTree.loadPreStageData(preStageData);
  449. // 根据设置 计算 台账树结构
  450. treeCalc.calculateAll(stageTree);
  451. // 绘制界面
  452. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  453. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  454. //初始化所有附件列表
  455. getAllList();
  456. // 初始化 部位明细 Spread
  457. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  458. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  459. spCol.readOnly = true;
  460. spCol.cellType = 'imageBtn';
  461. spCol.hoverImg = '#ellipsis-icon';
  462. spCol.indent = 5;
  463. spCol.showImage = function (data) {
  464. return data;
  465. };
  466. posSpreadSetting.imageClick = function (data) {
  467. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  468. changesObj.loadChanges({bills: node, pos: data});
  469. };
  470. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  471. const stageTreeSpreadObj = {
  472. refreshTreeNodes: function (sheet, nodes) {
  473. const tree = sheet.zh_tree;
  474. if (!tree) { return }
  475. const rows = [];
  476. for (const node of nodes) {
  477. rows.push(tree.nodes.indexOf(node));
  478. }
  479. SpreadJsObj.reLoadRowsData(sheet, rows);
  480. },
  481. editEnded: function (e, info) {
  482. if (info.sheet.zh_setting) {
  483. const col = info.sheet.zh_setting.cols[info.col];
  484. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  485. const node = sortData[info.row];
  486. if (col.field !== 'postil') {
  487. if (node.children && node.children.length > 0) {
  488. toast('清单父项不可计量', 'error');
  489. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  490. return;
  491. } else {
  492. const nodePos = stagePos.getLedgerPos(node.id);
  493. if (nodePos && nodePos.length > 0) {
  494. toast('该清单有部位明细,请在部位明细处计量', 'error');
  495. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  496. return;
  497. }
  498. }
  499. }
  500. const billsData = {
  501. lid: node.id
  502. };
  503. billsData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  504. postData(window.location.href + '/update', { bills: billsData }, function (data) {
  505. const nodes = stageTree.loadPostStageData(data);
  506. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  507. needCheckDetail();
  508. });
  509. }
  510. },
  511. selectionChanged: function (e, info) {
  512. stagePosSpreadObj.loadCurPosData();
  513. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  514. },
  515. deletePress(sheet) {
  516. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  517. const tree = sheet.zh_tree;
  518. if (!tree) { return; }
  519. const sel = sheet.getSelections()[0];
  520. const validCols = [];
  521. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  522. if (!sheet.zh_setting.cols[iCol].readOnly) {
  523. validCols.push(iCol);
  524. }
  525. }
  526. if (validCols.length === 0) { return; }
  527. const sortData = sheet.zh_tree.nodes;
  528. const datas = [];
  529. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  530. const node = sortData[iRow];
  531. if (node) {
  532. const data = { lid: node.id };
  533. let filter = true;
  534. for (const iCol of validCols) {
  535. const colSetting = sheet.zh_setting.cols[iCol];
  536. if (colSetting.field !== 'postil') {
  537. if (node.children && node.children.length > 0) { continue; }
  538. const nodePos = stagePos.getLedgerPos(node.id);
  539. if (nodePos && nodePos.length > 0) { continue; }
  540. }
  541. data[colSetting.field] = null;
  542. filter = false;
  543. }
  544. if (!filter) {
  545. datas.push(data);
  546. }
  547. }
  548. }
  549. if (datas.length > 0) {
  550. postData(window.location.href + '/update', {bills: datas}, function (result) {
  551. const nodes = stageTree.loadPostStageData(result);
  552. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  553. needCheckDetail();
  554. });
  555. }
  556. }
  557. },
  558. clipboardPasting(e, info) {
  559. if (info.sheet.zh_setting) {
  560. const sortData = info.sheet.zh_data;
  561. const range = info.cellRange;
  562. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  563. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  564. const col = info.sheet.zh_setting.cols[iCol];
  565. if (validField.indexOf(col.field) === -1) {
  566. toast('不可修改此数据', 'error');
  567. info.cancel = true;
  568. return;
  569. }
  570. }
  571. }
  572. },
  573. clipboardPasted(e, info) {
  574. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  575. const sheet = info.sheet;
  576. const filterNodes = [], datas = [];
  577. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  578. const curRow = iRow + info.cellRange.row;
  579. const node = sheet.zh_tree.getItemsByIndex(curRow);
  580. const data = {lid: node.id};
  581. let filter = true;
  582. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  583. const curCol = info.cellRange.col + iCol;
  584. const col = info.sheet.zh_setting.cols[curCol];
  585. if (col.field !== 'postil') {
  586. if (node.children && node.children.length > 0) {
  587. continue;
  588. }
  589. const nodePos = stagePos.getLedgerPos(node.id);
  590. if (nodePos && nodePos.length > 0) {
  591. continue;
  592. }
  593. }
  594. data[col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  595. filter = false;
  596. }
  597. if (filter) {
  598. filterNodes.push(node);
  599. } else {
  600. datas.push(data);
  601. }
  602. }
  603. if (datas.length > 0) {
  604. postData(window.location.href + '/update', { bills: datas }, function (data) {
  605. const nodes = stageTree.loadPostStageData(data);
  606. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  607. needCheckDetail();
  608. });
  609. } else {
  610. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  611. }
  612. }
  613. },
  614. measureAllPosInNode(node, ratio = 1) {
  615. const posterity = stageTree.getPosterity(node);
  616. const data = {updateType: 'update', updateData: []};
  617. for (const p of posterity) {
  618. if (p.children && p.children.length > 0) continue;
  619. const posRange = stagePos.getLedgerPos(p.id);
  620. if (posRange && posRange.length > 0) {
  621. for (const pr of posRange) {
  622. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  623. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  624. if (validValue <= 0) continue;
  625. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  626. const pData = {
  627. pid: pr.id,
  628. lid: pr.lid,
  629. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  630. };
  631. data.updateData.push(pData);
  632. }
  633. }
  634. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 200) {
  635. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  636. break;
  637. }
  638. }
  639. console.log(data);
  640. if (data.updateData.length === 0) {
  641. toastr.info('其下全部部位明细均已计量');
  642. return;
  643. }
  644. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  645. if (result.pos) {
  646. stagePos.updateDatas(result.pos.pos);
  647. stagePos.loadCurStageData(result.pos.curStageData);
  648. }
  649. const nodes = stageTree.loadPostStageData(result.ledger);
  650. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  651. stagePosSpreadObj.loadCurPosData();
  652. needCheckDetail();
  653. toastr.success('已计量' + data.updateData.length + '条');
  654. }, function () {
  655. stagePosSpreadObj.loadCurPosData();
  656. });
  657. },
  658. topRowChanged(e, info) {
  659. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  660. },
  661. };
  662. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  663. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  664. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  665. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  666. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  667. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  668. $.contextMenu({
  669. selector: '#stage-ledger',
  670. build: function ($trigger, e) {
  671. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  672. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  673. },
  674. items: {
  675. 'measureAll': {
  676. name: '计量其下所有部位明细',
  677. icon: 'fa-rocket',
  678. callback: function (key, opt) {
  679. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  680. stageTreeSpreadObj.measureAllPosInNode(node);
  681. },
  682. visible: function (key, opt) {
  683. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  684. return select;
  685. }
  686. },
  687. 'measureAllFiveTenth': {
  688. name: '计量其下所有部位明细(计量50%)',
  689. icon: 'fa-plane',
  690. callback: function (key, opt) {
  691. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  692. stageTreeSpreadObj.measureAllPosInNode(node, 0.5);
  693. },
  694. visible: function (key, opt) {
  695. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  696. return select;
  697. }
  698. },
  699. 'measureAllOneTenth': {
  700. name: '计量其下所有部位明细(计量10%)',
  701. icon: 'fa-car',
  702. callback: function (key, opt) {
  703. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  704. stageTreeSpreadObj.measureAllPosInNode(node, 0.1);
  705. },
  706. visible: function (key, opt) {
  707. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  708. return select;
  709. }
  710. },
  711. 'hint1': {
  712. name: '最多计量200条清单下1000条部位明细',
  713. className: 'text-danger',
  714. visible: function (key, opt) {
  715. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  716. return select;
  717. },
  718. disabled: function (key, opt) {
  719. return true;
  720. }
  721. },
  722. 'hint1_1': {
  723. name: '(计数以清单为准,会计完清单下全部部位)',
  724. className: 'text-danger',
  725. visible: function (key, opt) {
  726. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  727. return select;
  728. },
  729. disabled: function (key, opt) {
  730. return true;
  731. }
  732. },
  733. 'hint2': {
  734. name: '可再次使用该功能计量剩下的节点',
  735. className: 'text-danger',
  736. visible: function (key, opt) {
  737. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  738. return select;
  739. },
  740. disabled: function (key, opt) {
  741. return true;
  742. }
  743. },
  744. 'hint2_2': {
  745. name: '(凡是计量的部位,不论计量多少,均不再计量)',
  746. className: 'text-danger',
  747. visible: function (key, opt) {
  748. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  749. return select;
  750. },
  751. disabled: function (key, opt) {
  752. return true;
  753. }
  754. },
  755. 'hint3': {
  756. name: '如提示数据过多后,未成功,请缩小范围再试',
  757. className: 'text-danger',
  758. visible: function (key, opt) {
  759. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  760. return select;
  761. },
  762. disabled: function (key, opt) {
  763. return true;
  764. }
  765. },
  766. 'hint4': {
  767. name: '该功能仅供测试用,请勿滥用,可能导致服务挂掉',
  768. className: 'text-danger',
  769. visible: function (key, opt) {
  770. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  771. return select;
  772. },
  773. disabled: function (key, opt) {
  774. return true;
  775. }
  776. },
  777. }
  778. });
  779. const stagePosSpreadObj = {
  780. /**
  781. * 加载部位明细 根据当前台账选择节点
  782. */
  783. loadCurPosData: function () {
  784. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  785. if (node) {
  786. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  787. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  788. getNodeList(node.id);
  789. } else {
  790. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  791. }
  792. },
  793. editEnded: function (e, info) {
  794. if (info.sheet.zh_setting) {
  795. // 未改变过,则直接跳过
  796. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  797. const col = info.sheet.zh_setting.cols[info.col];
  798. const orgText = posData ? posData[col.field] : null;
  799. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  800. return;
  801. }
  802. // 台账模式下,不可新增
  803. if (checkTzMeasureType() && !posData) {
  804. toast('台账模式不可新增部位明细数据', 'error');
  805. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  806. info.cancel = true;
  807. return ;
  808. }
  809. // 不同节点下,部位明细检查输入
  810. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  811. const node = stagePosSpreadObj.stageTreeNode;
  812. if (!node) {
  813. toast('数据错误, 请刷新页面后再试', 'warning');
  814. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  815. return;
  816. } else if (info.editingText !== '' && node.children && node.children > 0) {
  817. toast('父节点不可插入部位明细', 'error');
  818. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  819. return;
  820. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  821. toast('项目节不可插入部位明细', 'error');
  822. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  823. return;
  824. }
  825. // 生成提交数据
  826. const data = {};
  827. if (col.field === 'name') {
  828. if (info.editingText === '' && pos) {
  829. toast('部位名称不可为空', 'error', 'exclamation-circle');
  830. info.cancel = true;
  831. return;
  832. } else if (!posData) {
  833. if (info.editingText !== '') {
  834. data.updateType = 'add';
  835. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
  836. } else {
  837. return;
  838. }
  839. } else {
  840. data.updateType = 'update';
  841. data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
  842. }
  843. } else if (!posData) {
  844. toast('新增部位请先输入名称', 'warning');
  845. } else {
  846. data.updateType = 'update';
  847. data.updateData = {pid: posData.id, lid: posData.lid};
  848. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  849. }
  850. // 提交数据到服务器
  851. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  852. if (result.pos) {
  853. stagePos.updateDatas(result.pos.pos);
  854. stagePos.loadCurStageData(result.pos.curStageData);
  855. }
  856. const refreshData = stageTree.loadPostStageData(result.ledger);
  857. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  858. stagePosSpreadObj.loadCurPosData();
  859. needCheckDetail();
  860. }, function () {
  861. stagePosSpreadObj.loadCurPosData();
  862. });
  863. }
  864. },
  865. editStarting: function (e, info) {
  866. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  867. },
  868. clipboardPasting: function (e, info) {
  869. if (info.sheet.zh_setting) {
  870. const sortData = info.sheet.zh_data;
  871. const range = info.cellRange;
  872. const validField = ['contract_qty', 'qc_qty', 'postil'];
  873. if (!checkTzMeasureType()) {
  874. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
  875. }
  876. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  877. const col = info.sheet.zh_setting.cols[iCol];
  878. if (validField.indexOf(col.field) === -1) {
  879. if (checkTzMeasureType()) {
  880. toast('不可修改此数据', 'error');
  881. info.cancel = true;
  882. return;
  883. } else {
  884. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  885. const pos = sortData(iRow);
  886. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  887. toast('不可修改此数据', 'error');
  888. info.cancel = true;
  889. return;
  890. }
  891. }
  892. }
  893. }
  894. }
  895. }
  896. },
  897. clipboardPasted: function (e, info) {
  898. const self = this;
  899. if (info.sheet.zh_setting) {
  900. const data = { updateType: '', updateData: [], };
  901. const sortData = info.sheet.zh_data;
  902. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  903. if (sortData && (info.cellRange.row >= sortData.length)) {
  904. data.updateType = 'add';
  905. if (info.cellRange.col !== 0) {
  906. toast('新增部位请先输入名称', 'warning');
  907. self.loadCurPosData();
  908. return;
  909. }
  910. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  911. const curRow = info.cellRange.row + iRow;
  912. const newData = {lid: node.id};
  913. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  914. const curCol = info.cellRange.col + iCol;
  915. const colSetting = info.sheet.zh_setting.cols[curCol];
  916. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  917. if (colSetting.type === 'Number') {
  918. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  919. }
  920. }
  921. data.updateData.push(newData);
  922. }
  923. } else {
  924. data.updateType = 'update';
  925. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  926. const curRow = info.cellRange.row + iRow;
  927. const curPos = sortData[curRow];
  928. if (curPos) {
  929. const newData = {pid: curPos.id, lid: curPos.lid};
  930. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  931. const curCol = info.cellRange.col + iCol;
  932. const colSetting = info.sheet.zh_setting.cols[curCol];
  933. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  934. if (colSetting.type === 'Number') {
  935. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  936. }
  937. }
  938. data.updateData.push(newData);
  939. }
  940. }
  941. }
  942. console.log(data);
  943. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  944. if (result.pos) {
  945. stagePos.updateDatas(result.pos.pos);
  946. stagePos.loadCurStageData(result.pos.curStageData);
  947. }
  948. const nodes = stageTree.loadPostStageData(result.ledger);
  949. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  950. stagePosSpreadObj.loadCurPosData();
  951. needCheckDetail();
  952. }, function () {
  953. stagePosSpreadObj.loadCurPosData();
  954. });
  955. }
  956. },
  957. deletePress: function (sheet) {
  958. if (sheet.zh_setting && sheet.zh_data) {
  959. const sortData = sheet.zh_data;
  960. if (!sortData || sortData.length === 0) { return; }
  961. const sel = sheet.getSelections()[0];
  962. const validCols = [];
  963. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  964. if (!sheet.zh_setting.cols[iCol].readOnly) {
  965. validCols.push(iCol);
  966. }
  967. }
  968. if (validCols.length === 0) { return; }
  969. const datas = [], posSelects = [];
  970. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  971. const node = sortData[iRow];
  972. if (node) {
  973. const data = {pid: node.id, lid: node.lid};
  974. for (const iCol of validCols) {
  975. const colSetting = sheet.zh_setting.cols[iCol];
  976. if (colSetting.field === 'name') {
  977. toast('部位名称不能为空', 'error');
  978. return;
  979. }
  980. data[colSetting.field] = null;
  981. }
  982. datas.push(data);
  983. posSelects.push(node);
  984. }
  985. }
  986. if (datas.length > 0) {
  987. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  988. if (result.pos) {
  989. stagePos.updateDatas(result.pos.pos);
  990. stagePos.loadCurStageData(result.pos.curStageData);
  991. }
  992. const nodes = stageTree.loadPostStageData(result.ledger);
  993. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  994. needCheckDetail();
  995. // todo 只加载改变项
  996. stagePosSpreadObj.loadCurPosData();
  997. });
  998. }
  999. }
  1000. },
  1001. leaveCell: function (e, info) {
  1002. console.log(1);
  1003. },
  1004. };
  1005. // 加载上下窗口resizer
  1006. $.divResizer({
  1007. select: '#main-resize',
  1008. callback: function () {
  1009. slSpread.refresh();
  1010. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1011. $(".sp-wrap").height(bcontent-40);
  1012. spSpread.refresh();
  1013. }
  1014. });
  1015. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1016. console.time('loadPosFromServer');
  1017. postData(window.location.pathname + '/pos', null, function (result) {
  1018. console.timeEnd('loadPosFromServer');
  1019. console.log('pos: ' + result.pos.length);
  1020. console.log('cur: ' + result.curStageData.length);
  1021. console.log('pre: ' + result.preStageData.length);
  1022. stagePos.loadDatas(result.pos);
  1023. if (result.curStageData) {
  1024. stagePos.loadCurStageData(result.curStageData);
  1025. }
  1026. if (result.preStageData) {
  1027. stagePos.loadPreStageData(result.preStageData);
  1028. }
  1029. stagePos.calculateAll();
  1030. stagePosSpreadObj.loadCurPosData();
  1031. });
  1032. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1033. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1034. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1035. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1036. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1037. if (!checkTzMeasureType()) {
  1038. }
  1039. $('#row-view').on('show.bs.modal', function () {
  1040. const html = [], customDisplay = customColDisplay();
  1041. for (const cd of customDisplay) {
  1042. html.push('<tr>');
  1043. html.push('<td>', cd.title, '</td>');
  1044. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1045. html.push('</tr>');
  1046. }
  1047. $('#row-view-list').html(html.join(''));
  1048. });
  1049. $('#row-view-ok').click(function () {
  1050. const customDisplay = customColDisplay();
  1051. const cvl = $('#row-view-list').children();
  1052. for (const cv of cvl) {
  1053. const title = $(cv).children()[0].innerHTML;
  1054. const check = $('input', cv)[0].checked;
  1055. const cd = customDisplay.find(function (c) {
  1056. return c.title === title;
  1057. });
  1058. cd.visible = check;
  1059. }
  1060. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1061. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1062. Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
  1063. $('#row-view').modal('hide');
  1064. });
  1065. class SearchLedger {
  1066. constructor(obj, mainSpread) {
  1067. const self = this;
  1068. this.obj = obj;
  1069. this.mainSpread = mainSpread;
  1070. this.spreadSetting = {
  1071. cols: [
  1072. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  1073. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  1074. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@'},
  1075. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  1076. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1077. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  1078. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  1079. ],
  1080. emptyRows: 3,
  1081. headRows: 1,
  1082. headRowHeight: [40],
  1083. defaultRowHeight: 21,
  1084. readOnly: true
  1085. };
  1086. this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
  1087. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1088. $('#searchLedger', this.obj).bind('click', function () {
  1089. const keyword = $('#keyword', self.obj).val();
  1090. if (keyword !== '') {
  1091. $('#over', obj)[0].checked = false;
  1092. $('#empty', obj)[0].checked = false;
  1093. this.searchResult = [];
  1094. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  1095. for (const node of sortData) {
  1096. if ((node.code && node.code.indexOf(keyword) > -1) ||
  1097. node.b_code && node.b_code.indexOf(keyword) > -1 ||
  1098. node.name && node.name.indexOf(keyword) > -1) {
  1099. this.searchResult.push(node);
  1100. }
  1101. }
  1102. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1103. }
  1104. });
  1105. $('#over', this.obj).bind('change', function () {
  1106. this.searchResult = [];
  1107. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  1108. for (const node of sortData) {
  1109. if (node.children && node.children.length > 0) continue;
  1110. if (node.end_gather_qty) {
  1111. if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(node.quantity)) {
  1112. this.searchResult.push(node);
  1113. }
  1114. } else if (node.end_gather_tp) {
  1115. if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(node.total_price)) {
  1116. this.searchResult.push(node);
  1117. }
  1118. }
  1119. }
  1120. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1121. });
  1122. $('#empty', this.obj).bind('change', function () {
  1123. this.searchResult = [];
  1124. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  1125. for (const node of sortData) {
  1126. if (node.children && node.children.length > 0) continue;
  1127. if (node.quantity) {
  1128. if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
  1129. this.searchResult.push(node);
  1130. }
  1131. } else if (node.total_price) {
  1132. if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
  1133. this.searchResult.push(node);
  1134. }
  1135. }
  1136. }
  1137. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1138. });
  1139. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1140. const sheet = info.sheet;
  1141. const data = sheet.zh_data;
  1142. if (!data) { return }
  1143. const curBills = data[info.row];
  1144. if (!curBills) { return }
  1145. SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id);
  1146. });
  1147. }
  1148. }
  1149. let searchLedger;
  1150. $.divResizer({
  1151. select: '#right-spr',
  1152. callback: function () {
  1153. slSpread.refresh();
  1154. spSpread.refresh();
  1155. if (searchLedger) {
  1156. searchLedger.spread.refresh();
  1157. }
  1158. }
  1159. });
  1160. // 展开收起附件
  1161. $('a', '.right-nav').bind('click', function () {
  1162. //const main = $('#main-view'), tool = $('#tools-view');
  1163. const tab = $(this), tabPanel = $(tab.attr('content'));
  1164. const showTools = function (show) {
  1165. const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
  1166. if (show) {
  1167. right.show();
  1168. autoFlashHeight();
  1169. /**
  1170. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1171. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1172. * 故需要通过最终的parent.width再计算一次left.width
  1173. *
  1174. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1175. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1176. *
  1177. */
  1178. //left.css('width', parent.width() - right.outerWidth());
  1179. //left.css('width', parent.width() - right.outerWidth());
  1180. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1181. left.css('width', percent + '%');
  1182. } else {
  1183. right.hide();
  1184. left.css('width', '100%');
  1185. }
  1186. };
  1187. if (!tab.hasClass('active')) {
  1188. $('a', '.side-menu').removeClass('active');
  1189. $('.tab-content .tab-select-show').removeClass('active');
  1190. tab.addClass('active');
  1191. tabPanel.addClass('active');
  1192. showTools(tab.hasClass('active'));
  1193. if (tab.attr('content') === '#search' && !searchLedger) {
  1194. searchLedger = new SearchLedger($('#search'), slSpread);
  1195. searchLedger.spread.refresh();
  1196. }
  1197. if (tab.attr('content') === '#fujian') {
  1198. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1199. getNodeList(node.id);
  1200. }
  1201. } else {
  1202. tab.removeClass('active');
  1203. tabPanel.removeClass('active');
  1204. showTools(tab.hasClass('active'));
  1205. }
  1206. slSpread.refresh();
  1207. spSpread.refresh();
  1208. });
  1209. // 切换附件里节点和所有附件
  1210. $('#fujian .nav-link').on('click', function () {
  1211. const tabPanel = $(this).attr('fujian-content');
  1212. if (tabPanel !== 'syfujian') {
  1213. $('#showPage').hide();
  1214. } else {
  1215. $('#showPage').show();
  1216. }
  1217. });
  1218. // 上传附件
  1219. $('#upload-file-btn').click(function () {
  1220. const file = $('#upload-file')[0];
  1221. if (file.files[0] === undefined) {
  1222. toast('未选择上传文件!', 'error');
  1223. return false;
  1224. }
  1225. const filesize = file.files[0].size;
  1226. if (filesize > 10 * 1024 * 1024) {
  1227. toast('文件大小过大!', 'error');
  1228. return false;
  1229. }
  1230. const fileext = '.' + file.files[0].name.toLowerCase().split('.').splice(-1)[0];
  1231. if (whiteList.indexOf(fileext) === -1) {
  1232. toast('只能上传指定格式的附件!', 'error');
  1233. return false;
  1234. }
  1235. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1236. const formData = new FormData();
  1237. formData.append('lid', node.id);
  1238. formData.append('size', filesize);
  1239. formData.append('file', file.files[0]);
  1240. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/upload/file', formData, function (data) {
  1241. $('#upload').modal('hide');
  1242. // 插入到attData中
  1243. attData.unshift(data);
  1244. // 重新生成LIst
  1245. getAllList();
  1246. getNodeList(node.id);
  1247. }, function () {
  1248. toast('附件上传失败', 'error');
  1249. });
  1250. $('#upload-file').val('');
  1251. });
  1252. // 获取附件信息
  1253. $('body').on('click', '.list-table a', function () {
  1254. const fid = $(this).attr('file-id');
  1255. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1256. return;
  1257. }
  1258. const att = attData.find(function (item) {
  1259. return item.id === parseInt(fid);
  1260. });
  1261. $('#edit-att').hide();
  1262. $('#show-att').show();
  1263. if (att !== undefined) {
  1264. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1265. const name = att.code !== null && att.code !== '' ? att.code : att.b_code;
  1266. $('#show-att tr').eq(1).children('td').text(name + ' ' + att.lname);
  1267. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/download/file/' + att.id);
  1268. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  1269. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  1270. $('#show-att tr').eq(4).children('td').text(att.remark);
  1271. if (parseInt(userID) === att.uid) {
  1272. $('#btn-att').show();
  1273. $('#btn-att a').eq(1).show();
  1274. $('#btn-att a').eq(0).hide();
  1275. $('#btn-att a').eq(2).hide();
  1276. $('#btn-att a').eq(3).hide();
  1277. } else {
  1278. $('#btn-att').hide();
  1279. $('#btn-att a').eq(1).hide();
  1280. $('#btn-att a').eq(0).hide();
  1281. $('#btn-att a').eq(2).hide();
  1282. $('#btn-att a').eq(3).hide();
  1283. }
  1284. $('#showAttachment').attr('file-id', fid);
  1285. $('#showAttachment').show();
  1286. } else {
  1287. $('#showAttachment').hide();
  1288. $('#showAttachment').attr('file-id', '');
  1289. toast('附件信息获取失败', 'error');
  1290. }
  1291. });
  1292. $('body').on('click', '#btn-att a', function () {
  1293. const content = $(this).attr('content');
  1294. const fid = $('#showAttachment').attr('file-id');
  1295. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1296. if (content === 'edit') {
  1297. $('#btn-att a').eq(1).hide();
  1298. $('#btn-att a').eq(0).show();
  1299. $('#btn-att a').eq(2).show();
  1300. $('#btn-att a').eq(3).show();
  1301. $('#show-att').hide();
  1302. $('#edit-att').show();
  1303. const att = attData.find(function (item) {
  1304. return item.id === parseInt(fid);
  1305. });
  1306. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  1307. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  1308. const name = att.code !== null && att.code !== '' ? att.code : att.b_code;
  1309. $('#edit-att .form-group').eq(1).find('input').val(name + ' ' + att.lname);
  1310. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  1311. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  1312. } else if (content === 'cancel') {
  1313. $('#show-att').show();
  1314. $('#edit-att').hide();
  1315. $('#btn-att a').eq(1).show();
  1316. $('#btn-att a').eq(0).hide();
  1317. $('#btn-att a').eq(2).hide();
  1318. $('#btn-att a').eq(3).hide();
  1319. } else if (content === 'save') {
  1320. const formData = new FormData();
  1321. formData.append('id', fid);
  1322. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  1323. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  1324. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  1325. const file = $('#change-att-btn')[0];
  1326. if (file.files[0] !== undefined) {
  1327. const filesize = file.files[0].size;
  1328. formData.append('size', filesize);
  1329. formData.append('file', file.files[0]);
  1330. }
  1331. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/save/file', formData, function (data) {
  1332. // 替换到attData中
  1333. const att_index = attData.findIndex(function (item) {
  1334. return item.id === parseInt(fid);
  1335. });
  1336. attData.splice(att_index, 1, data);
  1337. // 重新生成List
  1338. getAllList(parseInt($('#currentPage').text()));
  1339. getNodeList(node.id);
  1340. $('#show-att').show();
  1341. $('#edit-att').hide();
  1342. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  1343. const name = data.code !== null && data.code !== '' ? data.code : data.b_code;
  1344. $('#show-att tr').eq(1).children('td').text(name + ' ' + data.lname);
  1345. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/download/file/' + data.id);
  1346. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  1347. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  1348. $('#show-att tr').eq(4).children('td').text(data.remark);
  1349. $('#btn-att a').eq(1).show();
  1350. $('#btn-att a').eq(0).hide();
  1351. $('#btn-att a').eq(2).hide();
  1352. $('#btn-att a').eq(3).hide();
  1353. }, function () {
  1354. toast('附件上传失败', 'error');
  1355. });
  1356. $('#change-att-btn').val('');
  1357. } else if (content === 'del') {
  1358. const data = {id: fid};
  1359. postData('/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/delete/file', data, function (result) {
  1360. // 删除到attData中
  1361. const att_index = attData.findIndex(function (item) {
  1362. return item.id === parseInt(fid);
  1363. });
  1364. attData.splice(att_index, 1);
  1365. // 重新生成List
  1366. getAllList();
  1367. getNodeList(node.id);
  1368. $('#showAttachment').hide();
  1369. $('#showAttachment').attr('file-id', '');
  1370. });
  1371. }
  1372. });
  1373. // 替换附件
  1374. $('#change-att-btn').on('change', function () {
  1375. const file = $('#change-att-btn')[0].files[0];
  1376. const name = file.name;
  1377. const filename = name.substring(0, name.lastIndexOf("."));
  1378. const fileext = name.substr(name.indexOf("."));
  1379. const filesize = file.size;
  1380. if (filesize > 10 * 1024 * 1024) {
  1381. toast('文件大小过大!', 'error');
  1382. $('#change-att-btn').val('');
  1383. return false;
  1384. }
  1385. if (whiteList.indexOf(fileext) === -1) {
  1386. toast('只能上传指定格式的附件!', 'error');
  1387. $('#change-att-btn').val('');
  1388. return false;
  1389. }
  1390. $('#edit-att .form-group').eq(0).find('input').val(filename);
  1391. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  1392. });
  1393. // 切换页数
  1394. $('.page-select').on('click', function () {
  1395. const totalPageNum = $('#totalPage').text();
  1396. const lastPageNum = $('#currentPage').text();
  1397. const status = $(this).attr('content');
  1398. if (status === 'pre' && lastPageNum > 1) {
  1399. getAllList(parseInt(lastPageNum)-1);
  1400. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1401. getAllList(parseInt(lastPageNum)+1);
  1402. }
  1403. });
  1404. // 显示层次
  1405. (function (select, sheet) {
  1406. if (!sheet.zh_tree) return;
  1407. $(select).click(function () {
  1408. const tag = $(this).attr('tag');
  1409. const tree = sheet.zh_tree;
  1410. switch (tag) {
  1411. case "1":
  1412. case "2":
  1413. case "3":
  1414. case "4":
  1415. case "5":
  1416. tree.expandByLevel(parseInt(tag));
  1417. SpreadJsObj.refreshTreeRowVisible(sheet);
  1418. break;
  1419. case "last":
  1420. tree.expandByCustom(() => { return true; });
  1421. SpreadJsObj.refreshTreeRowVisible(sheet);
  1422. break;
  1423. case "leafXmj":
  1424. tree.expandToLeafXmj();
  1425. SpreadJsObj.refreshTreeRowVisible(sheet);
  1426. break;
  1427. case "curMeasure":
  1428. tree.expandByCustom(function (node) {
  1429. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1430. if (node[field]) {
  1431. return true;
  1432. }
  1433. }
  1434. return false;
  1435. });
  1436. SpreadJsObj.refreshTreeRowVisible(sheet);
  1437. break;
  1438. }
  1439. });
  1440. })('a[name=showLevel]', slSpread.getActiveSheet());
  1441. });