tabTemplate.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {
  2. DEL_ITEMS,
  3. INIT_ITEMS,
  4. TAB_CHANGE,
  5. CKECK_ITEMS,
  6. BATCH_DEL_ITEMS,
  7. ALL_CHECKED,
  8. CHANGE_TITLE,
  9. CHANGE_VISIBLE,
  10. SHOW_MESSAGE,
  11. KEEP_PUSH_DATA,
  12. ALL_CHECKED_SHOW,
  13. } from '../types/tabTemplate';
  14. const initDataList = {
  15. activeId: '0', //点击的tab
  16. visible: false, //弹窗
  17. showMsg: { //提示
  18. show: false,
  19. content: '',
  20. type: ''
  21. },
  22. items: [],
  23. allChecked: false, //全选反选
  24. checkItems: [], //选中要删除的元素
  25. activeItem: {}, //引用的模板
  26. activeItemHis: {}, //引用的历史病例
  27. allCheckShow: false, //全选反选是否显示
  28. current:1,//当前页
  29. hasMore:true,//是否显示更多
  30. }
  31. export default (state = initDataList, action) => {
  32. if (action.type === DEL_ITEMS) {
  33. const newState = Object.assign({}, state);
  34. let tempArr = newState.items;
  35. tempArr.splice(tempArr.findIndex(item => item.id == action.id), 1)
  36. newState.items = [...tempArr];
  37. // if(tempArr.length == 0){
  38. // newState.allCheckShow = false
  39. // }
  40. return newState;
  41. }
  42. if (action.type === BATCH_DEL_ITEMS) {
  43. const newState = Object.assign({}, state);
  44. let tempArr = newState.items;
  45. for (let i = 0; i < action.ids.length; i++) {
  46. let currentId = action.ids[i];
  47. tempArr.splice(tempArr.findIndex(item => item.id == currentId), 1)
  48. }
  49. newState.items = [...tempArr];
  50. // if(tempArr.length == 0){
  51. // newState.allCheckShow = false
  52. // }
  53. newState.checkItems = [];
  54. return newState;
  55. }
  56. if (action.type === INIT_ITEMS) {
  57. const newState = Object.assign({}, state);
  58. // let tmpItems = JSON.parse(JSON.stringify(newState.items))
  59. // let tmpCurrent = JSON.parse(JSON.stringify(newState.current))
  60. // console.log(action.state.flg,action.state.pages,tmpCurrent,45544)
  61. // if(action.state.current == 1&&!action.state.flg){//进入页面会调取分页相关先去掉
  62. // newState.items = action.state.records
  63. // }else{
  64. // newState.items = tmpItems.concat(action.state.records);
  65. // }
  66. newState.items = action.state.records
  67. newState.current = action.state.current;
  68. newState.hasMore = action.state.current<action.state.pages;
  69. return newState;
  70. }
  71. if (action.type === CHANGE_VISIBLE) {
  72. const newState = Object.assign({}, state);
  73. newState.visible = action.bool;
  74. return newState;
  75. }
  76. if (action.type === SHOW_MESSAGE) {
  77. const newState = Object.assign({}, state);
  78. newState.showMsg = action.bool;
  79. return newState;
  80. }
  81. if (action.type === TAB_CHANGE) {
  82. const newState = Object.assign({}, state);
  83. newState.activeId = action.idx;
  84. return newState;
  85. }
  86. if (action.type === CHANGE_TITLE) {
  87. const newState = Object.assign({}, state);
  88. let tempArr = newState.items;
  89. for (let i = 0; i < tempArr.length; i++) {
  90. if (tempArr[i].id == action.obj.id) {
  91. tempArr[i].name = action.obj.title
  92. }
  93. }
  94. newState.items = [...tempArr];
  95. return newState;
  96. }
  97. if (action.type === CKECK_ITEMS) {
  98. const newState = Object.assign({}, state);
  99. if (newState.checkItems.indexOf(action.id) == -1) {
  100. let tempArr = newState.checkItems;
  101. tempArr.push(action.id);
  102. newState.checkItems = [...tempArr]
  103. } else {
  104. let tempArr = newState.checkItems;
  105. tempArr.splice(tempArr.findIndex(item => item === action.id), 1)
  106. newState.checkItems = [...tempArr]
  107. }
  108. return newState;
  109. }
  110. if (action.type === KEEP_PUSH_DATA) {
  111. const newState = Object.assign({}, state);
  112. action.flg == 'his' ? (newState.activeItemHis = action.data) : (newState.activeItem = action.data);
  113. return newState;
  114. }
  115. if (action.type === ALL_CHECKED) {
  116. const newState = Object.assign({}, state);
  117. let tempArr = [];
  118. if (action.bool) {
  119. newState.items.forEach((val) => {
  120. tempArr.push(val.id)
  121. })
  122. } else {
  123. tempArr = []
  124. }
  125. newState.allChecked = action.bool;
  126. newState.checkItems = [...tempArr];
  127. return newState;
  128. }
  129. if (action.type === ALL_CHECKED_SHOW) {
  130. const newState = Object.assign({}, state);
  131. newState.allCheckShow = action.bool;
  132. return newState;
  133. }
  134. return state;
  135. }