stage.js 40 KB

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