setting_tender.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. $(document).ready(() => {
  2. autoFlashHeight();
  3. const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]);
  4. const xmjSheet = xmjSpread.getActiveSheet();
  5. const limitItems = limits.map(l => {
  6. return { value: l.limit_id, text: l.name };
  7. });
  8. limitItems.unshift({ value: '', text: '' });
  9. const setting = {
  10. cols: [
  11. { title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 180, formatter: '@', cellType: 'tree', readOnly: true, },
  12. { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 360, formatter: '@', readOnly: true, },
  13. { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit', readOnly: true, },
  14. { title: '联动计量配置', colSpan: '1', rowSpan: '2', field: 'multi_limit', hAlign: 0, width: 150, cellType: 'customizeCombo', comboItems: limitItems },
  15. ],
  16. emptyRows: 0,
  17. headRows: 2,
  18. headRowHeight: [25, 25],
  19. defaultRowHeight: 21,
  20. headerFont: '12px 微软雅黑',
  21. font: '12px 微软雅黑',
  22. };
  23. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  24. SpreadJsObj.initSheet(xmjSheet, setting);
  25. const xmjTree = createNewPathTree('ledger', {
  26. id: 'ledger_id',
  27. pid: 'ledger_pid',
  28. order: 'order',
  29. level: 'level',
  30. rootId: -1,
  31. keys: ['id', 'tender_id', 'ledger_id'],
  32. autoExpand: 3,
  33. });
  34. const xmjTreeObj = {
  35. /**
  36. * 编辑单元格响应事件
  37. * @param {Object} e
  38. * @param {Object} info
  39. */
  40. editEnded: function (e, info) {
  41. if (!info.sheet.zh_setting) return;
  42. const col = info.sheet.zh_setting.cols[info.col];
  43. if (col.field !== 'multi_limit') return;
  44. const node = SpreadJsObj.getSelectObject(info.sheet);
  45. const updateData = { id: node.id, multi_limit: info.editingText || '' };
  46. if (updateData.multi_limit === node.multi_limit || (!updateData.multi_limit && !node.multi_limit)) return;
  47. // 更新至服务器
  48. postData(window.location.pathname + '/update', updateData, function (result) {
  49. const xmj = xmjTree.nodes.find(x => { return x.id === result.id });
  50. if (xmj) xmj.multi_limit = result.multi_limit;
  51. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  52. }, function() {
  53. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  54. });
  55. },
  56. };
  57. xmjSpread.bind(spreadNS.Events.EditEnded, xmjTreeObj.editEnded);
  58. postData(window.location.pathname + '/load', {filter: 'xmj;limit'}, function(result) {
  59. result.limit.forEach(l => {
  60. const rx = result.xmj.find(x => { return x.id === l.id; });
  61. if (rx) rx.multi_limit = l.multi_limit;
  62. });
  63. xmjTree.loadDatas(result.xmj);
  64. SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Tree, xmjTree);
  65. });
  66. });