stage.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  258. }
  259. }
  260. // 提交数据到后端
  261. postData(window.location.pathname + '/use-change', data, function(result) {
  262. if (result.pos) {
  263. stagePos.loadCurStageData(result.pos);
  264. }
  265. const nodes = stageTree.loadPostStageData(result.bills);
  266. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  267. stagePosSpreadObj.loadCurPosData();
  268. self.obj.modal('hide');
  269. });
  270. })
  271. }
  272. _calculateAmount() {
  273. for (const c of this.changes) {
  274. c.bamount = _.toNumber(c.b_amount);
  275. c.vamount = _.round(_.subtract(c.bamount, c.used_amount), 6);
  276. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  277. if (uc) {
  278. c.uamount = uc.qty;
  279. c.vamount = _.round(_.add(c.vamount, c.uamount), 6);
  280. }
  281. }
  282. }
  283. _loadChangeDetail(change) {
  284. if (change) {
  285. if (change.cid === this.curChangeId) { return; }
  286. this.curChangeId = change.cid;
  287. const inputs = $('input[type!=checkbox]', this.obj);
  288. for (const i of inputs) {
  289. const field = $(i).attr('name');
  290. const text = (field && change[field]) ? change[field] : '';
  291. $(i).val(text);
  292. }
  293. const textareas = $('textarea', this.obj);
  294. for (const ta of textareas) {
  295. const field = $(ta).attr('name');
  296. const text = (field && change[field]) ? change[field] : '';
  297. ta.innerText = text;
  298. }
  299. const html = [];
  300. for (const a of change.attachments) {
  301. html.push('<tr>');
  302. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  303. html.push('<td>', a.u_name, '</td>');
  304. html.push('</tr>');
  305. }
  306. // 变更类型
  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. $('select[name=class]').val(change.class);
  314. // 变更性质
  315. $('select[name=quality]').val(change.quality);
  316. // 变更单位
  317. $('select[name=company]').html('<option>' + change.company + '</option>');
  318. // 费用承担方
  319. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  320. // 附件
  321. $('#attachment').html(html.join(''));
  322. } else {
  323. const inputs = $('input', this.obj);
  324. for (const i of inputs) {
  325. $(i).val('');
  326. }
  327. const textareas = $('textarea', this.obj);
  328. for (const ta of textareas) {
  329. ta.innerText = '';
  330. }
  331. $('#attachment').html('');
  332. }
  333. }
  334. _viewChanges() {
  335. const sheet = this.spread.getActiveSheet();
  336. if (this.changes) {
  337. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, this.changes);
  338. sheet.setSelection(0, 0, 1, 1);
  339. this._loadChangeDetail(this.changes[0]);
  340. this._filterEmptyChange(!$('#customCheckDisabled')[0].checked);
  341. } else {
  342. toast('查询变更令有误,请刷新页面后重试', 'warning');
  343. }
  344. }
  345. _filterEmptyChange(isFilter) {
  346. for (const c of this.changes) {
  347. c.visible = isFilter ? (c.vamount && !checkZero(c.vamount)) : true;
  348. }
  349. SpreadJsObj.refreshTreeRowVisible(this.spread.getActiveSheet());
  350. }
  351. loadChanges(data, code) {
  352. this.callData = data;
  353. const self = this;
  354. $('#b-code-hint').text('当前变更清单:' + code);
  355. postData(window.location.pathname + '/valid-change', data, function (result) {
  356. self.changes = result.changes;
  357. self.useChanges = result.useChanges;
  358. self._calculateAmount();
  359. self._viewChanges();
  360. self.obj.modal('show');
  361. });
  362. }
  363. }
  364. const changesObj = new Changes($('#use-bg'));
  365. // 初始化 台账 spread
  366. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  367. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  368. // 数量变更列,添加按钮
  369. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  370. col.readOnly = true;
  371. col.cellType = 'imageBtn';
  372. col.hoverImg = '#ellipsis-icon';
  373. col.indent = 5;
  374. col.showImage = function (data) {
  375. if (!data || (data.children && data.children.length > 0)) {
  376. return false;
  377. } else {
  378. const nodePos = stagePos.getLedgerPos(data.id);
  379. return !(nodePos && nodePos.length > 0);
  380. }
  381. };
  382. ledgerSpreadSetting.imageClick = function (data) {
  383. changesObj.loadChanges({bills: data}, data.b_code);
  384. };
  385. //
  386. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  387. stageTree.loadDatas(ledgerData);
  388. stageTree.loadCurStageData(curStageData);
  389. stageTree.loadPreStageData(preStageData);
  390. // 根据设置 计算 台账树结构
  391. treeCalc.calculateAll(stageTree);
  392. // 绘制界面
  393. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  394. // 初始化 部位明细 Spread
  395. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  396. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  397. spCol.readOnly = true;
  398. spCol.cellType = 'imageBtn';
  399. spCol.hoverImg = '#ellipsis-icon';
  400. spCol.indent = 5;
  401. spCol.showImage = function (data) {
  402. return data;
  403. };
  404. posSpreadSetting.imageClick = function (data) {
  405. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  406. changesObj.loadChanges({pos: data}, node.b_code);
  407. };
  408. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  409. const stageTreeSpreadObj = {
  410. refreshTreeNodes: function (sheet, nodes) {
  411. const tree = sheet.zh_tree;
  412. if (!tree) { return }
  413. const rows = [];
  414. for (const node of nodes) {
  415. rows.push(tree.nodes.indexOf(node));
  416. }
  417. SpreadJsObj.reLoadRowsData(sheet, rows);
  418. },
  419. editEnded: function (e, info) {
  420. if (info.sheet.zh_setting) {
  421. const col = info.sheet.zh_setting.cols[info.col];
  422. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  423. const node = sortData[info.row];
  424. if (node.children && node.children.length > 0) {
  425. toast('清单父项不可计量', 'error');
  426. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  427. return;
  428. } else {
  429. const nodePos = stagePos.getLedgerPos(node.id);
  430. if (nodePos && nodePos.length > 0) {
  431. toast('该清单有部位明细,请在部位明细处计量', 'error');
  432. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  433. return;
  434. }
  435. }
  436. const billsData = {
  437. lid: node.id
  438. };
  439. billsData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  440. postData(window.location.href + '/update', { bills: billsData }, function (data) {
  441. const nodes = stageTree.loadPostStageData(data.bills);
  442. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  443. });
  444. }
  445. },
  446. selectionChanged: function (e, info) {
  447. stagePosSpreadObj.loadCurPosData();
  448. },
  449. deletePress(sheet) {
  450. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  451. const tree = sheet.zh_tree;
  452. if (!tree) { return; }
  453. const sel = sheet.getSelections()[0];
  454. const validCols = [];
  455. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  456. if (!sheet.zh_setting.cols[iCol].readOnly) {
  457. validCols.push(iCol);
  458. }
  459. }
  460. if (validCols.length === 0) { return; }
  461. const sortData = sheet.zh_tree.nodes;
  462. const datas = [];
  463. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  464. const node = sortData[iRow];
  465. if (node) {
  466. if (node.children && node.children.length > 0) { continue; }
  467. const nodePos = stagePos.getLedgerPos(node.id);
  468. if (nodePos && nodePos.length > 0) { continue; }
  469. const data = { lid: node.id };
  470. for (const iCol of validCols) {
  471. const colSetting = sheet.zh_setting.cols[iCol];
  472. data[colSetting.field] = null;
  473. }
  474. datas.push(data);
  475. }
  476. }
  477. if (datas.length > 0) {
  478. postData(window.location.href + '/update', {bills: datas}, function (result) {
  479. const nodes = stageTree.loadPostStageData(result.bills);
  480. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  481. });
  482. }
  483. }
  484. },
  485. clipboardPasting(e, info) {
  486. if (info.sheet.zh_setting) {
  487. const sortData = info.sheet.zh_data;
  488. const range = info.cellRange;
  489. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  490. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  491. const col = info.sheet.zh_setting.cols[iCol];
  492. if (validField.indexOf(col.field) === -1) {
  493. toast('不可修改此数据', 'error');
  494. info.cancel = true;
  495. return;
  496. }
  497. }
  498. }
  499. },
  500. clipboardPasted(e, info) {
  501. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  502. const sheet = info.sheet;
  503. const filterNodes = [], datas = [];
  504. console.log(info.cellRange);
  505. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  506. const curRow = iRow + info.cellRange.row;
  507. const node = sheet.zh_tree.getItemsByIndex(curRow);
  508. if (node.children && node.children.length > 0) {
  509. filterNodes.push(node);
  510. continue;
  511. }
  512. const nodePos = stagePos.getLedgerPos(node.id);
  513. if (nodePos && nodePos.length > 0) {
  514. filterNodes.push(node);
  515. continue;
  516. }
  517. const data = {lid: node.id};
  518. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  519. const curCol = info.cellRange.col + iCol;
  520. const col = info.sheet.zh_setting.cols[curCol];
  521. data[col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  522. }
  523. datas.push(data);
  524. }
  525. console.log(datas);
  526. if (datas.length > 0) {
  527. postData(window.location.href + '/update', { bills: datas }, function (data) {
  528. const nodes = stageTree.loadPostStageData(data.bills);
  529. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  530. });
  531. } else {
  532. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  533. }
  534. }
  535. }
  536. };
  537. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  538. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  539. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  540. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  541. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  542. const stagePosSpreadObj = {
  543. /**
  544. * 加载部位明细 根据当前台账选择节点
  545. */
  546. loadCurPosData: function () {
  547. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  548. if (node) {
  549. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  550. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  551. } else {
  552. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  553. }
  554. },
  555. editEnded: function (e, info) {
  556. if (info.sheet.zh_setting) {
  557. // 未改变过,则直接跳过
  558. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  559. const col = info.sheet.zh_setting.cols[info.col];
  560. const orgText = posData ? posData[col.field] : null;
  561. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  562. return;
  563. }
  564. // 台账模式下,不可新增
  565. if (checkTzMeasureType() && !posData) {
  566. toast('台账模式不可新增部位明细数据', 'error');
  567. info.cancel = true;
  568. return ;
  569. }
  570. // 不同节点下,部位明细检查输入
  571. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  572. if (!node) {
  573. toast('数据错误, 请刷新页面后再试', 'warning');
  574. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  575. return;
  576. } else if (info.editingText !== '' && node.children && node.children > 0) {
  577. toast('父节点不可插入部位明细', 'error');
  578. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  579. return;
  580. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  581. toast('项目节不可插入部位明细', 'error');
  582. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  583. return;
  584. }
  585. // 生成提交数据
  586. const data = {};
  587. if (col.field === 'name') {
  588. if (info.editingText === '' && pos) {
  589. toast('部位名称不可为空', 'error', 'exclamation-circle');
  590. info.cancel = true;
  591. return;
  592. } else if (!pos) {
  593. if (info.editingText !== '') {
  594. data.updateType = 'add';
  595. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
  596. } else {
  597. return;
  598. }
  599. } else {
  600. data.updateType = 'update';
  601. data.updateData = {id: posData.id, name: info.editingText};
  602. }
  603. } else if (!posData) {
  604. toast('新增部位请先输入名称', 'warning');
  605. } else {
  606. data.updateType = 'update';
  607. data.updateData = {pid: posData.id, lid: posData.lid};
  608. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  609. }
  610. // 提交数据到服务器
  611. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  612. if (result.pos) {
  613. stagePos.updateDatas(result.pos.pos);
  614. stagePos.loadCurStageData(result.pos.curStageData);
  615. }
  616. const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
  617. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  618. stagePosSpreadObj.loadCurPosData();
  619. }, function () {
  620. stagePosSpreadObj.loadCurPosData();
  621. });
  622. }
  623. },
  624. clipboardPasting: function (e, info) {
  625. if (info.sheet.zh_setting) {
  626. const sortData = info.sheet.zh_data;
  627. const range = info.cellRange;
  628. const validField = ['contract_qty', 'qc_qty', 'postil'];
  629. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  630. const col = info.sheet.zh_setting.cols[iCol];
  631. if (validField.indexOf(col.field) === -1) {
  632. if (checkTzMeasureType()) {
  633. toast('不可修改此数据', 'error');
  634. info.cancel = true;
  635. return;
  636. } else {
  637. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  638. const pos = sortData(iRow);
  639. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  640. toast('不可修改此数据', 'error');
  641. info.cancel = true;
  642. return;
  643. }
  644. }
  645. }
  646. }
  647. }
  648. }
  649. },
  650. clipboardPasted: function (e, info) {
  651. const self = this;
  652. if (info.sheet.zh_setting) {
  653. const data = { updateType: '', updateData: [], };
  654. const sortData = info.sheet.zh_data;
  655. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  656. if (sortData && (info.cellRange.row >= sortData.length)) {
  657. data.updateType = 'add';
  658. if (info.cellRange.col !== 0) {
  659. toast('新增部位请先输入名称', 'warning');
  660. self.loadCurPosData();
  661. return;
  662. }
  663. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  664. const curRow = info.cellRange.row + iRow;
  665. const newData = {lid: node.id};
  666. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  667. const curCol = info.cellRange.col + iCol;
  668. const colSetting = info.sheet.zh_setting.cols[curCol];
  669. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  670. if (colSetting.type === 'Number') {
  671. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  672. }
  673. }
  674. data.updateData.push(newData);
  675. }
  676. } else {
  677. data.updateType = 'update';
  678. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  679. const curRow = info.cellRange.row + iRow;
  680. const curPos = sortData[curRow];
  681. if (curPos) {
  682. const newData = {pid: curPos.id, lid: curPos.lid};
  683. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  684. const curCol = info.cellRange.col + iCol;
  685. const colSetting = info.sheet.zh_setting.cols[curCol];
  686. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  687. if (colSetting.type === 'Number') {
  688. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  689. }
  690. }
  691. data.updateData.push(newData);
  692. }
  693. }
  694. }
  695. console.log(data);
  696. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  697. if (result.pos) {
  698. stagePos.updateDatas(result.pos.pos);
  699. stagePos.loadCurStageData(result.pos.curStageData);
  700. }
  701. const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
  702. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  703. stagePosSpreadObj.loadCurPosData();
  704. }, function () {
  705. stagePosSpreadObj.loadCurPosData();
  706. });
  707. }
  708. },
  709. deletePress: function (sheet) {
  710. if (sheet.zh_setting && sheet.zh_data) {
  711. const sortData = sheet.zh_data;
  712. if (!sortData || sortData.length === 0) { return; }
  713. const sel = sheet.getSelections()[0];
  714. const validCols = [];
  715. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  716. if (!sheet.zh_setting.cols[iCol].readOnly) {
  717. validCols.push(iCol);
  718. }
  719. }
  720. if (validCols.length === 0) { return; }
  721. const datas = [], posSelects = [];
  722. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  723. const node = sortData[iRow];
  724. if (node) {
  725. const data = {pid: node.id, lid: node.lid};
  726. for (const iCol of validCols) {
  727. const colSetting = sheet.zh_setting.cols[iCol];
  728. if (colSetting.field === 'name') {
  729. toast('部位名称不能为空', 'error');
  730. return;
  731. }
  732. data[colSetting.field] = null;
  733. }
  734. datas.push(data);
  735. posSelects.push(node);
  736. }
  737. }
  738. if (datas.length > 0) {
  739. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  740. if (result.pos) {
  741. stagePos.updateDatas(result.pos.pos);
  742. stagePos.loadCurStageData(result.pos.curStageData);
  743. }
  744. const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
  745. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  746. // todo 只加载改变项
  747. stagePosSpreadObj.loadCurPosData();
  748. });
  749. }
  750. }
  751. },
  752. };
  753. // 加载上下窗口resizer
  754. $.divResizer({
  755. select: '#main-resize',
  756. callback: function () {
  757. slSpread.refresh();
  758. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  759. $(".sp-wrap").height(bcontent-40);
  760. spSpread.refresh();
  761. }
  762. });
  763. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  764. postData(window.location.pathname + '/pos', null, function (result) {
  765. stagePos.loadDatas(result.pos);
  766. if (result.curStageData) {
  767. stagePos.loadCurStageData(result.curStageData);
  768. }
  769. if (result.preStageData) {
  770. stagePos.loadPreStageData(result.preStageData);
  771. }
  772. stagePos.calculateAll();
  773. stagePosSpreadObj.loadCurPosData();
  774. });
  775. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  776. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  777. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  778. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  779. $('#row-view').on('show.bs.modal', function () {
  780. const html = [], customDisplay = customColDisplay();
  781. for (const cd of customDisplay) {
  782. html.push('<tr>');
  783. html.push('<td>', cd.title, '</td>');
  784. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  785. html.push('</tr>');
  786. }
  787. $('#row-view-list').html(html.join(''));
  788. });
  789. $('#row-view-ok').click(function () {
  790. const customDisplay = customColDisplay();
  791. const cvl = $('#row-view-list').children();
  792. for (const cv of cvl) {
  793. const title = $(cv).children()[0].innerHTML;
  794. const check = $('input', cv)[0].checked;
  795. const cd = customDisplay.find(function (c) {
  796. return c.title === title;
  797. });
  798. cd.visible = check;
  799. }
  800. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  801. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  802. Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
  803. $('#row-view').modal('hide');
  804. });
  805. // 展开收起附件
  806. $('#fujianTab').click(function () {
  807. const obj = $(this), main = $('#main-view'), tool = $('#tools-view'), fujian = $('#fujian');
  808. if (obj.hasClass('active')) {
  809. main.attr('class', 'c-body col-12');
  810. tool.hide();
  811. slSpread.refresh();
  812. spSpread.refresh();
  813. obj.removeClass('active');
  814. fujian.removeClass('active');
  815. } else {
  816. main.attr('class', 'c-body col-8');
  817. tool.show();
  818. slSpread.refresh();
  819. spSpread.refresh();
  820. obj.addClass('active');
  821. fujian.addClass('active');
  822. }
  823. });
  824. });