stage.js 40 KB

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