123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- 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<action.state.pages;
- return newState;
- }
- if (action.type === CHANGE_VISIBLE) {
- const newState = Object.assign({}, state);
- newState.visible = action.bool;
- return newState;
- }
- if (action.type === SHOW_MESSAGE) {
- const newState = Object.assign({}, state);
- newState.showMsg = action.bool;
- return newState;
- }
- if (action.type === TAB_CHANGE) {
- const newState = Object.assign({}, state);
- newState.activeId = action.idx;
- return newState;
- }
- if (action.type === CHANGE_TITLE) {
- const newState = Object.assign({}, state);
- let tempArr = newState.items;
- for (let i = 0; i < tempArr.length; i++) {
- if (tempArr[i].id == action.obj.id) {
- tempArr[i].name = action.obj.title
- }
- }
- newState.items = [...tempArr];
- return newState;
- }
- if (action.type === CKECK_ITEMS) {
- const newState = Object.assign({}, state);
- if (newState.checkItems.indexOf(action.id) == -1) {
- let tempArr = newState.checkItems;
- tempArr.push(action.id);
- newState.checkItems = [...tempArr]
- } else {
- let tempArr = newState.checkItems;
- tempArr.splice(tempArr.findIndex(item => 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;
- }
|