stage.js 34 KB

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