import { DEL_ITEMS, INIT_ITEMS, TAB_CHANGE, CKECK_ITEMS, BATCH_DEL_ITEMS, ALL_CHECKED, CHANGE_TITLE, CHANGE_VISIBLE, SHOW_MESSAGE, KEEP_PUSH_DATA, ALL_CHECKED_SHOW, } from '../types/tabTemplate'; const initDataList = { activeId: '0', //点击的tab visible: false, //弹窗 showMsg: { //提示 show: false, content: '', type: '' }, items: [], allChecked: false, //全选反选 checkItems: [], //选中要删除的元素 activeItem: {}, //引用的模板 activeItemHis: {}, //引用的历史病例 allCheckShow: false, //全选反选是否显示 current:1,//当前页 hasMore:true,//是否显示更多 } export default (state = initDataList, action) => { if (action.type === DEL_ITEMS) { const newState = Object.assign({}, state); let tempArr = newState.items; tempArr.splice(tempArr.findIndex(item => item.id == action.id), 1) newState.items = [...tempArr]; // if(tempArr.length == 0){ // newState.allCheckShow = false // } return newState; } if (action.type === BATCH_DEL_ITEMS) { const newState = Object.assign({}, state); let tempArr = newState.items; for (let i = 0; i < action.ids.length; i++) { let currentId = action.ids[i]; tempArr.splice(tempArr.findIndex(item => item.id == currentId), 1) } newState.items = [...tempArr]; // if(tempArr.length == 0){ // newState.allCheckShow = false // } newState.checkItems = []; return newState; } if (action.type === INIT_ITEMS) { const newState = Object.assign({}, state); // let tmpItems = JSON.parse(JSON.stringify(newState.items)) // let tmpCurrent = JSON.parse(JSON.stringify(newState.current)) // console.log(action.state.flg,action.state.pages,tmpCurrent,45544) // if(action.state.current == 1&&!action.state.flg){//进入页面会调取分页相关先去掉 // newState.items = action.state.records // }else{ // newState.items = tmpItems.concat(action.state.records); // } newState.items = action.state.records newState.current = action.state.current; newState.hasMore = action.state.current item === action.id), 1) newState.checkItems = [...tempArr] } return newState; } if (action.type === KEEP_PUSH_DATA) { const newState = Object.assign({}, state); action.flg == 'his' ? (newState.activeItemHis = action.data) : (newState.activeItem = action.data); return newState; } if (action.type === ALL_CHECKED) { const newState = Object.assign({}, state); let tempArr = []; if (action.bool) { newState.items.forEach((val) => { tempArr.push(val.id) }) } else { tempArr = [] } newState.allChecked = action.bool; newState.checkItems = [...tempArr]; return newState; } if (action.type === ALL_CHECKED_SHOW) { const newState = Object.assign({}, state); newState.allCheckShow = action.bool; return newState; } return state; }