stage.js 37 KB

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