bodyButtonClick.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { deepClone } from 'nc-lightapp-front';
  2. import { CARD_BUTTON, CARD, STATUS, CARD_DISABLED_BUTTON, PRIMARY_KEY } from '../../constant';
  3. /**
  4. * @description: 表体按钮点击事件
  5. * @param: key 当前触发按钮名称
  6. * @param: index 当前行序
  7. * @param: record 当前行信息
  8. */
  9. export function bodyButtonClick(props, key, text, record, index) {
  10. debugger;
  11. switch (key) {
  12. //肩 新增
  13. case CARD_BUTTON.addRow:
  14. props.cardTable.addRow(CARD.table_code);
  15. break;
  16. //肩 删除
  17. case CARD_BUTTON.deleteRow:
  18. let checkedRows = props.cardTable.getCheckedRows(CARD.table_code);
  19. let checkedIndex = checkedRows && checkedRows.map(item => item.index);
  20. if (checkedRows.length > 0) {
  21. props.cardTable.delRowsByIndex(CARD.table_code, checkedIndex);
  22. props.button.setButtonDisabled(CARD_DISABLED_BUTTON, true);
  23. }
  24. break;
  25. //行 展开
  26. case CARD_BUTTON.expand:
  27. debugger;
  28. props.cardTable.openTabModel(CARD.table_code, STATUS.edit, record, index);
  29. break;
  30. //行 展开(浏览态)
  31. case CARD_BUTTON.unfold:
  32. //行 收起
  33. case CARD_BUTTON.fold:
  34. debugger;
  35. props.cardTable.toggleTabRowView(CARD.table_code, record);
  36. break;
  37. //行 插行
  38. case CARD_BUTTON.insertRow:
  39. props.cardTable.addRow(CARD.table_code, index);
  40. break;
  41. //行 删行
  42. case CARD_BUTTON.delRow:
  43. props.cardTable.delRowsByIndex(CARD.table_code, index);
  44. break;
  45. //行 复制行
  46. case CARD_BUTTON.copyRow:
  47. props.cardTable.pasteRow(CARD.table_code, index, [PRIMARY_KEY.body_id]);
  48. break;
  49. //肩 复制行
  50. case CARD_BUTTON.copyRows:
  51. copyControl.call(this, props, true);
  52. break;
  53. //肩 取消复制
  54. case CARD_BUTTON.pasteCancel:
  55. copyControl.call(this, props, false);
  56. break;
  57. //肩 粘贴至末行
  58. case CARD_BUTTON.pasteTail:
  59. let lastIndex = props.cardTable.getNumberOfRows(CARD.table_code);
  60. props.cardTable.insertRowsAfterIndex(CARD.table_code, getPasteRows(props), lastIndex);
  61. copyControl.call(this, props, false);
  62. props.cardTable.selectAllRows(CARD.table_code, false);
  63. break;
  64. //行 粘贴至此
  65. case CARD_BUTTON.pasteHere:
  66. props.cardTable.insertRowsAfterIndex(CARD.table_code, getPasteRows(props), index);
  67. copyControl.call(this, props, false);
  68. props.cardTable.selectAllRows(CARD.table_code, false);
  69. break;
  70. }
  71. if (![CARD_BUTTON.unfold, CARD_BUTTON.fold].includes(key)) {
  72. debugger;
  73. props.cardTable.setStatus(CARD.table_code, STATUS.edit);
  74. }
  75. }
  76. //复制时的状态控制
  77. function copyControl(props, flag) {
  78. //肩部按钮显示控制
  79. props.button.setButtonVisible({
  80. [CARD_BUTTON.addRow]: !flag,
  81. [CARD_BUTTON.deleteRow]: !flag,
  82. [CARD_BUTTON.copyRows]: !flag,
  83. [CARD_BUTTON.pasteTail]: flag,
  84. [CARD_BUTTON.pasteCancel]: flag,
  85. });
  86. props.cardTable.setAllCheckboxAble(CARD.table_code, !flag);
  87. this.setState({ isPaste: flag });
  88. }
  89. /**
  90. * 获取粘贴行数据
  91. *
  92. * @returns 返回粘贴行数据
  93. */
  94. function getPasteRows(props) {
  95. let checkedRows = props.cardTable.getCheckedRows(CARD.table_code);
  96. let selectRowCopy = deepClone(checkedRows);
  97. let selectArr = selectRowCopy.map(item => {
  98. item.data.selected = false;
  99. item.data.values[PRIMARY_KEY.head_id] ? item.data.values[PRIMARY_KEY.head_id].value = null : null;
  100. item.data.values[PRIMARY_KEY.body_id] ? item.data.values[PRIMARY_KEY.body_id].value = null : null;
  101. return item.data;
  102. });
  103. return selectArr;
  104. }