stage.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. function checkTzMeasureType () {
  10. return tender.measure_type === measureType.tz.value;
  11. }
  12. /**
  13. * 从cookie中读取缓存的列显示设置,没有则取默认
  14. * @returns {*[]}
  15. */
  16. function customColDisplay () {
  17. const defaultSetting = [
  18. { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
  19. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  20. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  21. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  22. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  23. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  24. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp'], visible: true },
  25. { title: '图册号', fields: ['drawing_code'], visible: true },
  26. { title: '累计完成率(%)', fields: ['percent'], visible: true },
  27. { title: '备注', fields: ['memo'], visible: true },
  28. ];
  29. const settingStr = Cookies.get('stage-col-visible-1.0.0');
  30. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  31. }
  32. /**
  33. * 根据列显示设置,调整setting中的列是否显示
  34. * @param setting
  35. * @param customDisplay
  36. */
  37. function customizeStageTreeSetting(setting, customDisplay) {
  38. for (const cd of customDisplay) {
  39. for (const c of setting.cols) {
  40. if (cd.fields.indexOf(c.field) !== -1) {
  41. c.visible = cd.visible;
  42. }
  43. }
  44. }
  45. }
  46. /**
  47. * 初始化 树结构 列事件
  48. * @param setting
  49. */
  50. function initTreeColSettingEvents(setting) {
  51. const Events = {
  52. readOnly: {
  53. measureData: function (node) {
  54. return node.children && node.children.length > 0;
  55. },
  56. },
  57. };
  58. const getEvent = function (eventName) {
  59. const names = eventName.split('.');
  60. let event = Events;
  61. for (let name of names) {
  62. if (event[name]) {
  63. event = event[name];
  64. } else {
  65. return null;
  66. }
  67. }
  68. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  69. return null;
  70. } else {
  71. return event;
  72. }
  73. };
  74. for (const col of setting.cols) {
  75. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  76. col.readOnly = getEvent(col.readOnly);
  77. }
  78. }
  79. }
  80. $(document).ready(() => {
  81. // 界面布局
  82. autoFlashHeight();
  83. // 初始化 台账树结构 数据结构
  84. const stageTreeSetting = {
  85. id: 'ledger_id',
  86. pid: 'ledger_pid',
  87. order: 'order',
  88. level: 'level',
  89. rootId: -1,
  90. keys: ['id', 'tender_id', 'ledger_id'],
  91. stageId: 'id',
  92. };
  93. // 台账树结构计算相关设置
  94. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'];
  95. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  96. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  97. stageTreeSetting.calcFun = function (node) {
  98. if (node.children && node.children.length === 0) {
  99. node.pre_gather_qty = ZhCalc.plus(node.pre_contract_qty, node.pre_qc_qty);
  100. node.gather_qty = ZhCalc.plus(node.contract_qty, node.qc_qty);
  101. node.end_contract_qty = ZhCalc.plus(node.pre_contract_qty, node.contract_qty);
  102. node.end_qc_qty = ZhCalc.plus(node.pre_qc_qty, node.qc_qty);
  103. node.end_gather_qty = ZhCalc.plus(node.pre_gather_qty, node.gather_qty);
  104. }
  105. node.pre_gather_tp = ZhCalc.plus(node.pre_contract_tp, node.pre_qc_tp);
  106. node.gather_tp = ZhCalc.plus(node.contract_tp, node.qc_tp);
  107. node.end_contract_tp = ZhCalc.plus(node.pre_contract_tp, node.contract_tp);
  108. node.end_qc_tp = ZhCalc.plus(node.pre_qc_tp, node.qc_tp);
  109. node.end_gather_tp = ZhCalc.plus(node.pre_gather_tp, node.gather_tp);
  110. node.dgn_price = ZhCalc.round(ZhCalc.divide(node.total_price, node.dgn_qty1), tenderInfo.decimal.up);
  111. };
  112. const stageTree = createNewPathTree('stage', stageTreeSetting);
  113. // 初始化 部位明细 数据结构
  114. const stagePosSetting = {
  115. id: 'id', ledgerId: 'lid',
  116. updateFields: ['contract_qty', 'qc_qty', 'postil'],
  117. };
  118. stagePosSetting.calcFun = function (pos) {
  119. pos.pre_gather_qty = ZhCalc.plus(pos.pre_contract_qty, pos.pre_qc_qty);
  120. pos.gather_qty = ZhCalc.plus(pos.contract_qty, pos.qc_qty);
  121. pos.end_contract_qty = ZhCalc.plus(pos.pre_contract_qty, pos.contract_qty);
  122. pos.end_qc_qty = ZhCalc.plus(pos.pre_qc_qty, pos.qc_qty);
  123. pos.end_gather_qty = ZhCalc.plus(pos.pre_gather_qty, pos.gather_qty);
  124. };
  125. const stagePos = new StagePosData(stagePosSetting);
  126. class Changes {
  127. constructor(obj) {
  128. const self = this;
  129. this.obj = obj;
  130. // 初始化 清单编号窗口 参数
  131. this.spreadSetting = {
  132. cols: [
  133. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  134. if (data.uamount && !checkZero(data.uamount)) {
  135. return $('#icon-ok')[0];
  136. } else {
  137. return null;
  138. }
  139. }},
  140. {title: '变更令号', field: 'code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  141. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  142. {title: '总数量', field: 'b_amount', width: 60, formatter: '@', readOnly: true, hAlign: 2, },
  143. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, },
  144. {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, type: 'Number', },
  145. ],
  146. emptyRows: 0,
  147. headRows: 1,
  148. headRowHeight: [40],
  149. getColor: function (data, col, defaultColor) {
  150. if (col.field === 'uamount') {
  151. if (!data.vamount) {
  152. return data.uamount ? '#ff6f5c' : defaultColor;
  153. } else if (data.uamount) {
  154. return data.uamount > data.vamount ? '#ff6f5c' : defaultColor;
  155. } else {
  156. return defaultColor;
  157. }
  158. } else {
  159. return defaultColor;
  160. }
  161. }
  162. };
  163. this.curChangeId = '';
  164. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  165. this.firstView = true;
  166. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  167. // 初次显示,需刷新spread界面,保证界面绘制正确
  168. this.obj.bind('shown.bs.modal', function () {
  169. if (self.firstView) {
  170. self.firstView = false;
  171. self.spread.refresh();
  172. }
  173. });
  174. // 切换变更令,加载右侧明细数据
  175. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  176. const change = SpreadJsObj.getSelectObject(info.sheet);
  177. self._loadChangeDetail(change);
  178. });
  179. // 填写本期计量
  180. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  181. if (info.sheet.zh_setting) {
  182. const col = info.sheet.zh_setting.cols[info.col];
  183. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  184. const node = sortData[info.row];
  185. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  186. // 刷新界面
  187. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  188. }
  189. });
  190. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  191. if (info.sheet.zh_setting) {
  192. const sortData = SpreadJsObj.getSortData(info.sheet);
  193. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  194. const curRow = iRow + info.cellRange.row;
  195. const curCol = info.cellRange.col;
  196. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  197. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  198. }
  199. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  200. }
  201. });
  202. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  203. if (sheet.zh_setting) {
  204. const sel = sheet.getSelections()[0];
  205. const sortData = SpreadJsObj.getSortData(sheet);
  206. // 仅本期计量可删除
  207. if (sel.col === 5 || sel.colCount === 1) {
  208. const col = sheet.zh_setting.cols[sel.col];
  209. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  210. const data = sortData[iRow];
  211. data[col.field] = null;
  212. }
  213. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  214. }
  215. }
  216. });
  217. // 过滤可变更数量为0
  218. $('#filterEmpty').click(function () {
  219. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  220. });
  221. // 匹配编号
  222. $('#matchPos').click(function () {
  223. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  224. });
  225. // 展开收起 变更令详细信息
  226. $('#show-bgl-detail').bind('click', function () {
  227. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  228. if (detail.hasClass('col-4')) {
  229. detail.attr('class', 'col').hide();
  230. bgl.attr('class', 'col-12');
  231. $('a', obj).attr('title', '展开侧栏');
  232. $('i', obj).attr('class', 'fa fa-chevron-left');
  233. self.spread.refresh();
  234. } else {
  235. detail.attr('class', 'col-4').show();
  236. bgl.attr('class', 'col-8');
  237. $('a', obj).attr('title', '收起侧栏');
  238. $('i', obj).attr('class', 'fa fa-chevron-right');
  239. self.spread.refresh();
  240. }
  241. });
  242. // 添加调用变更令
  243. $('#usg-bg-ok').click(function () {
  244. const data = { target: self.callData, change: [] };
  245. for (const c of self.changes) {
  246. if (c.uamount) {
  247. if (!c.vamount || checkZero(c.vamount)) {
  248. toast('变更令:' + c.code + ' 当前不可使用', 'error');
  249. return;
  250. } else {
  251. if (c.uamount > c.vamount) {
  252. toast('变更令:' + c.code + ' 超计,请修改本期计量后,再提交', 'error');
  253. return;
  254. }
  255. }
  256. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  257. }
  258. }
  259. // 提交数据到后端
  260. postData(window.location.pathname + '/use-change', data, function(result) {
  261. if (result.pos) {
  262. stagePos.loadCurStageData(result.pos);
  263. }
  264. const nodes = stageTree.loadPostStageData(result.bills);
  265. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  266. stagePosSpreadObj.loadCurPosData();
  267. self.obj.modal('hide');
  268. });
  269. })
  270. }
  271. _calculateAmount() {
  272. for (const c of this.changes) {
  273. c.bamount = _.toNumber(c.b_amount);
  274. c.vamount = ZhCalc.minus(c.bamount, c.used_amount);
  275. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  276. if (uc) {
  277. c.uamount = uc.qty;
  278. c.vamount = ZhCalc.plus(c.vamount, c.uamount);
  279. }
  280. }
  281. }
  282. _loadChangeDetail(change) {
  283. if (change) {
  284. if (change.cid === this.curChangeId) { return; }
  285. this.curChangeId = change.cid;
  286. const inputs = $('input[type!=checkbox]', this.obj);
  287. for (const i of inputs) {
  288. const field = $(i).attr('name');
  289. const text = (field && change[field]) ? change[field] : '';
  290. $(i).val(text);
  291. }
  292. const textareas = $('textarea', this.obj);
  293. for (const ta of textareas) {
  294. const field = $(ta).attr('name');
  295. const text = (field && change[field]) ? change[field] : '';
  296. ta.innerText = text;
  297. }
  298. const html = [];
  299. for (const a of change.attachments) {
  300. html.push('<tr>');
  301. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  302. html.push('<td>', a.u_name, '</td>');
  303. html.push('</tr>');
  304. }
  305. // 变更类型
  306. if (change.type) {
  307. const cType = change.type.split(',');
  308. $('input[name="type"]').prop("checked", false);
  309. for (const c of cType) {
  310. $('input[name="type"][value='+ c +']').prop("checked", true);
  311. }
  312. }
  313. // 变更类别
  314. $('select[name=class]').val(change.class);
  315. // 变更性质
  316. $('select[name=quality]').val(change.quality);
  317. // 变更单位
  318. $('select[name=company]').html('<option>' + change.company + '</option>');
  319. // 费用承担方
  320. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  321. // 附件
  322. $('#attachment').html(html.join(''));
  323. } else {
  324. const inputs = $('input', this.obj);
  325. for (const i of inputs) {
  326. $(i).val('');
  327. }
  328. const textareas = $('textarea', this.obj);
  329. for (const ta of textareas) {
  330. ta.innerText = '';
  331. }
  332. $('#attachment').html('');
  333. }
  334. }
  335. _viewChanges() {
  336. const sheet = this.spread.getActiveSheet();
  337. if (this.changes) {
  338. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, this.changes);
  339. sheet.setSelection(0, 0, 1, 1);
  340. this._loadChangeDetail(this.changes[0]);
  341. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  342. } else {
  343. toast('查询变更令有误,请刷新页面后重试', 'warning');
  344. }
  345. }
  346. _filterChange(filterEmpty, matchPosName) {
  347. for (const c of this.changes) {
  348. const filterVisible = filterEmpty ? (c.vamount && !checkZero(c.vamount)) : true;
  349. const matchVisible = matchPosName && this.callData.pos ? c.b_detail === this.callData.pos.name : true;
  350. c.visible = filterVisible && matchVisible;
  351. }
  352. SpreadJsObj.refreshTreeRowVisible(this.spread.getActiveSheet());
  353. }
  354. loadChanges(data) {
  355. this.callData = data;
  356. if (this.callData.pos) {
  357. $('#matchPos').parent().show();
  358. } else {
  359. $('#matchPos').parent().hide();
  360. }
  361. const self = this;
  362. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  363. postData(window.location.pathname + '/valid-change', data, function (result) {
  364. self.changes = result.changes;
  365. self.useChanges = result.useChanges;
  366. self._calculateAmount();
  367. self._viewChanges();
  368. self.obj.modal('show');
  369. });
  370. }
  371. }
  372. const changesObj = new Changes($('#use-bg'));
  373. // 初始化 台账 spread
  374. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  375. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  376. // 数量变更列,添加按钮
  377. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  378. col.readOnly = true;
  379. col.cellType = 'imageBtn';
  380. col.hoverImg = '#ellipsis-icon';
  381. col.indent = 5;
  382. col.showImage = function (data) {
  383. if (!data || (data.children && data.children.length > 0)) {
  384. return false;
  385. } else {
  386. const nodePos = stagePos.getLedgerPos(data.id);
  387. return !(nodePos && nodePos.length > 0);
  388. }
  389. };
  390. ledgerSpreadSetting.imageClick = function (data) {
  391. changesObj.loadChanges({bills: data});
  392. };
  393. //
  394. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  395. stageTree.loadDatas(ledgerData);
  396. stageTree.loadCurStageData(curStageData);
  397. stageTree.loadPreStageData(preStageData);
  398. // 根据设置 计算 台账树结构
  399. treeCalc.calculateAll(stageTree);
  400. // 绘制界面
  401. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  402. // 初始化 部位明细 Spread
  403. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  404. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  405. spCol.readOnly = true;
  406. spCol.cellType = 'imageBtn';
  407. spCol.hoverImg = '#ellipsis-icon';
  408. spCol.indent = 5;
  409. spCol.showImage = function (data) {
  410. return data;
  411. };
  412. posSpreadSetting.imageClick = function (data) {
  413. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  414. changesObj.loadChanges({bills: node, pos: data});
  415. };
  416. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  417. const stageTreeSpreadObj = {
  418. refreshTreeNodes: function (sheet, nodes) {
  419. const tree = sheet.zh_tree;
  420. if (!tree) { return }
  421. const rows = [];
  422. for (const node of nodes) {
  423. rows.push(tree.nodes.indexOf(node));
  424. }
  425. SpreadJsObj.reLoadRowsData(sheet, rows);
  426. },
  427. editEnded: function (e, info) {
  428. if (info.sheet.zh_setting) {
  429. const col = info.sheet.zh_setting.cols[info.col];
  430. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  431. const node = sortData[info.row];
  432. if (col.field !== 'postil') {
  433. if (node.children && node.children.length > 0) {
  434. toast('清单父项不可计量', 'error');
  435. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  436. return;
  437. } else {
  438. const nodePos = stagePos.getLedgerPos(node.id);
  439. if (nodePos && nodePos.length > 0) {
  440. toast('该清单有部位明细,请在部位明细处计量', 'error');
  441. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  442. return;
  443. }
  444. }
  445. }
  446. const billsData = {
  447. lid: node.id
  448. };
  449. billsData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  450. postData(window.location.href + '/update', { bills: billsData }, function (data) {
  451. const nodes = stageTree.loadPostStageData(data);
  452. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  453. });
  454. }
  455. },
  456. selectionChanged: function (e, info) {
  457. stagePosSpreadObj.loadCurPosData();
  458. },
  459. deletePress(sheet) {
  460. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  461. const tree = sheet.zh_tree;
  462. if (!tree) { return; }
  463. const sel = sheet.getSelections()[0];
  464. const validCols = [];
  465. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  466. if (!sheet.zh_setting.cols[iCol].readOnly) {
  467. validCols.push(iCol);
  468. }
  469. }
  470. if (validCols.length === 0) { return; }
  471. const sortData = sheet.zh_tree.nodes;
  472. const datas = [];
  473. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  474. const node = sortData[iRow];
  475. if (node) {
  476. const data = { lid: node.id };
  477. let filter = true;
  478. for (const iCol of validCols) {
  479. const colSetting = sheet.zh_setting.cols[iCol];
  480. if (colSetting.field !== 'postil') {
  481. if (node.children && node.children.length > 0) { continue; }
  482. const nodePos = stagePos.getLedgerPos(node.id);
  483. if (nodePos && nodePos.length > 0) { continue; }
  484. }
  485. data[colSetting.field] = null;
  486. filter = false;
  487. }
  488. if (!filter) {
  489. datas.push(data);
  490. }
  491. }
  492. }
  493. if (datas.length > 0) {
  494. postData(window.location.href + '/update', {bills: datas}, function (result) {
  495. const nodes = stageTree.loadPostStageData(result);
  496. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  497. });
  498. }
  499. }
  500. },
  501. clipboardPasting(e, info) {
  502. if (info.sheet.zh_setting) {
  503. const sortData = info.sheet.zh_data;
  504. const range = info.cellRange;
  505. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  506. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  507. const col = info.sheet.zh_setting.cols[iCol];
  508. if (validField.indexOf(col.field) === -1) {
  509. toast('不可修改此数据', 'error');
  510. info.cancel = true;
  511. return;
  512. }
  513. }
  514. }
  515. },
  516. clipboardPasted(e, info) {
  517. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  518. const sheet = info.sheet;
  519. const filterNodes = [], datas = [];
  520. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  521. const curRow = iRow + info.cellRange.row;
  522. const node = sheet.zh_tree.getItemsByIndex(curRow);
  523. const data = {lid: node.id};
  524. let filter = true;
  525. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  526. const curCol = info.cellRange.col + iCol;
  527. const col = info.sheet.zh_setting.cols[curCol];
  528. if (col.field !== 'postil') {
  529. if (node.children && node.children.length > 0) {
  530. continue;
  531. }
  532. const nodePos = stagePos.getLedgerPos(node.id);
  533. if (nodePos && nodePos.length > 0) {
  534. continue;
  535. }
  536. }
  537. data[col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  538. filter = false;
  539. }
  540. if (filter) {
  541. filterNodes.push(node);
  542. } else {
  543. datas.push(data);
  544. }
  545. }
  546. if (datas.length > 0) {
  547. postData(window.location.href + '/update', { bills: datas }, function (data) {
  548. const nodes = stageTree.loadPostStageData(data);
  549. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  550. });
  551. } else {
  552. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  553. }
  554. }
  555. }
  556. };
  557. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  558. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  559. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  560. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  561. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  562. const stagePosSpreadObj = {
  563. /**
  564. * 加载部位明细 根据当前台账选择节点
  565. */
  566. loadCurPosData: function () {
  567. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  568. if (node) {
  569. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  570. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  571. } else {
  572. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  573. }
  574. },
  575. editEnded: function (e, info) {
  576. if (info.sheet.zh_setting) {
  577. // 未改变过,则直接跳过
  578. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  579. const col = info.sheet.zh_setting.cols[info.col];
  580. const orgText = posData ? posData[col.field] : null;
  581. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  582. return;
  583. }
  584. // 台账模式下,不可新增
  585. if (checkTzMeasureType() && !posData) {
  586. toast('台账模式不可新增部位明细数据', 'error');
  587. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  588. info.cancel = true;
  589. return ;
  590. }
  591. // 不同节点下,部位明细检查输入
  592. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  593. const node = stagePosSpreadObj.stageTreeNode;
  594. if (!node) {
  595. toast('数据错误, 请刷新页面后再试', 'warning');
  596. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  597. return;
  598. } else if (info.editingText !== '' && node.children && node.children > 0) {
  599. toast('父节点不可插入部位明细', 'error');
  600. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  601. return;
  602. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  603. toast('项目节不可插入部位明细', 'error');
  604. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  605. return;
  606. }
  607. // 生成提交数据
  608. const data = {};
  609. if (col.field === 'name') {
  610. if (info.editingText === '' && pos) {
  611. toast('部位名称不可为空', 'error', 'exclamation-circle');
  612. info.cancel = true;
  613. return;
  614. } else if (!posData) {
  615. if (info.editingText !== '') {
  616. data.updateType = 'add';
  617. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
  618. } else {
  619. return;
  620. }
  621. } else {
  622. data.updateType = 'update';
  623. data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
  624. }
  625. } else if (!posData) {
  626. toast('新增部位请先输入名称', 'warning');
  627. } else {
  628. data.updateType = 'update';
  629. data.updateData = {pid: posData.id, lid: posData.lid};
  630. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  631. }
  632. // 提交数据到服务器
  633. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  634. if (result.pos) {
  635. stagePos.updateDatas(result.pos.pos);
  636. stagePos.loadCurStageData(result.pos.curStageData);
  637. }
  638. const refreshData = stageTree.loadPostStageData(result.ledger);
  639. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  640. stagePosSpreadObj.loadCurPosData();
  641. }, function () {
  642. stagePosSpreadObj.loadCurPosData();
  643. });
  644. }
  645. },
  646. editStarting: function (e, info) {
  647. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  648. },
  649. clipboardPasting: function (e, info) {
  650. if (info.sheet.zh_setting) {
  651. const sortData = info.sheet.zh_data;
  652. const range = info.cellRange;
  653. const validField = ['contract_qty', 'qc_qty', 'postil'];
  654. if (!checkTzMeasureType()) {
  655. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
  656. }
  657. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  658. const col = info.sheet.zh_setting.cols[iCol];
  659. if (validField.indexOf(col.field) === -1) {
  660. if (checkTzMeasureType()) {
  661. toast('不可修改此数据', 'error');
  662. info.cancel = true;
  663. return;
  664. } else {
  665. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  666. const pos = sortData(iRow);
  667. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  668. toast('不可修改此数据', 'error');
  669. info.cancel = true;
  670. return;
  671. }
  672. }
  673. }
  674. }
  675. }
  676. }
  677. },
  678. clipboardPasted: function (e, info) {
  679. const self = this;
  680. if (info.sheet.zh_setting) {
  681. const data = { updateType: '', updateData: [], };
  682. const sortData = info.sheet.zh_data;
  683. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  684. if (sortData && (info.cellRange.row >= sortData.length)) {
  685. data.updateType = 'add';
  686. if (info.cellRange.col !== 0) {
  687. toast('新增部位请先输入名称', 'warning');
  688. self.loadCurPosData();
  689. return;
  690. }
  691. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  692. const curRow = info.cellRange.row + iRow;
  693. const newData = {lid: node.id};
  694. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  695. const curCol = info.cellRange.col + iCol;
  696. const colSetting = info.sheet.zh_setting.cols[curCol];
  697. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  698. if (colSetting.type === 'Number') {
  699. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  700. }
  701. }
  702. data.updateData.push(newData);
  703. }
  704. } else {
  705. data.updateType = 'update';
  706. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  707. const curRow = info.cellRange.row + iRow;
  708. const curPos = sortData[curRow];
  709. if (curPos) {
  710. const newData = {pid: curPos.id, lid: curPos.lid};
  711. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  712. const curCol = info.cellRange.col + iCol;
  713. const colSetting = info.sheet.zh_setting.cols[curCol];
  714. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  715. if (colSetting.type === 'Number') {
  716. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  717. }
  718. }
  719. data.updateData.push(newData);
  720. }
  721. }
  722. }
  723. console.log(data);
  724. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  725. if (result.pos) {
  726. stagePos.updateDatas(result.pos.pos);
  727. stagePos.loadCurStageData(result.pos.curStageData);
  728. }
  729. const nodes = stageTree.loadPostStageData(result.ledger);
  730. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  731. stagePosSpreadObj.loadCurPosData();
  732. }, function () {
  733. stagePosSpreadObj.loadCurPosData();
  734. });
  735. }
  736. },
  737. deletePress: function (sheet) {
  738. if (sheet.zh_setting && sheet.zh_data) {
  739. const sortData = sheet.zh_data;
  740. if (!sortData || sortData.length === 0) { return; }
  741. const sel = sheet.getSelections()[0];
  742. const validCols = [];
  743. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  744. if (!sheet.zh_setting.cols[iCol].readOnly) {
  745. validCols.push(iCol);
  746. }
  747. }
  748. if (validCols.length === 0) { return; }
  749. const datas = [], posSelects = [];
  750. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  751. const node = sortData[iRow];
  752. if (node) {
  753. const data = {pid: node.id, lid: node.lid};
  754. for (const iCol of validCols) {
  755. const colSetting = sheet.zh_setting.cols[iCol];
  756. if (colSetting.field === 'name') {
  757. toast('部位名称不能为空', 'error');
  758. return;
  759. }
  760. data[colSetting.field] = null;
  761. }
  762. datas.push(data);
  763. posSelects.push(node);
  764. }
  765. }
  766. if (datas.length > 0) {
  767. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  768. if (result.pos) {
  769. stagePos.updateDatas(result.pos.pos);
  770. stagePos.loadCurStageData(result.pos.curStageData);
  771. }
  772. const nodes = stageTree.loadPostStageData(result.ledger);
  773. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  774. // todo 只加载改变项
  775. stagePosSpreadObj.loadCurPosData();
  776. });
  777. }
  778. }
  779. },
  780. leaveCell: function (e, info) {
  781. console.log(1);
  782. },
  783. };
  784. // 加载上下窗口resizer
  785. $.divResizer({
  786. select: '#main-resize',
  787. callback: function () {
  788. slSpread.refresh();
  789. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  790. $(".sp-wrap").height(bcontent-40);
  791. spSpread.refresh();
  792. }
  793. });
  794. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  795. postData(window.location.pathname + '/pos', null, function (result) {
  796. stagePos.loadDatas(result.pos);
  797. if (result.curStageData) {
  798. stagePos.loadCurStageData(result.curStageData);
  799. }
  800. if (result.preStageData) {
  801. stagePos.loadPreStageData(result.preStageData);
  802. }
  803. stagePos.calculateAll();
  804. stagePosSpreadObj.loadCurPosData();
  805. });
  806. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  807. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  808. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  809. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  810. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  811. if (!checkTzMeasureType()) {
  812. }
  813. $('#row-view').on('show.bs.modal', function () {
  814. const html = [], customDisplay = customColDisplay();
  815. for (const cd of customDisplay) {
  816. html.push('<tr>');
  817. html.push('<td>', cd.title, '</td>');
  818. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  819. html.push('</tr>');
  820. }
  821. $('#row-view-list').html(html.join(''));
  822. });
  823. $('#row-view-ok').click(function () {
  824. const customDisplay = customColDisplay();
  825. const cvl = $('#row-view-list').children();
  826. for (const cv of cvl) {
  827. const title = $(cv).children()[0].innerHTML;
  828. const check = $('input', cv)[0].checked;
  829. const cd = customDisplay.find(function (c) {
  830. return c.title === title;
  831. });
  832. cd.visible = check;
  833. }
  834. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  835. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  836. Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
  837. $('#row-view').modal('hide');
  838. });
  839. // 展开收起附件
  840. $('#fujianTab').click(function () {
  841. const obj = $(this), main = $('#main-view'), tool = $('#tools-view'), fujian = $('#fujian');
  842. if (obj.hasClass('active')) {
  843. main.attr('class', 'c-body col-12');
  844. tool.hide();
  845. slSpread.refresh();
  846. spSpread.refresh();
  847. obj.removeClass('active');
  848. fujian.removeClass('active');
  849. } else {
  850. main.attr('class', 'c-body col-8');
  851. tool.show();
  852. slSpread.refresh();
  853. spSpread.refresh();
  854. obj.addClass('active');
  855. fujian.addClass('active');
  856. }
  857. });
  858. });