text: import modelExtend from 'dva-model-extend'
  import { config } from 'utils'
  import { query,update,remove,create } from 'services/gwconfig'
  import { pageModel } from './common'
  const { prefix } = config
  
  export default modelExtend(pageModel, {
    namespace: 'gwconfig',
  
    state: {
      currentItem: {},
      modalVisible: false,
      modalType: 'create',
      selectedRowKeys: [],
      isMotion: window.localStorage.getItem(`${prefix}userIsMotion`) === 'true'
    },
  
    subscriptions: {
      setup ({ dispatch, history }) {
        history.listen((location) => {
          if (location.pathname === '/gwconfig') {
            dispatch({
              type: 'query',
              payload: location.query,
            })
          }
        })
      },
    },
  
    effects: {
  
      * query ({ payload = {} }, { call, put }) {
        const data = yield call(query, payload)
        if (data) {
          console.log(payload)
          yield put({
            type: 'querySuccess',
            payload: {
              list: data.data,
              pagination: {
                current: Number(payload.page) || 1,
                pageSize: Number(payload.pageSize) || 10,
                total: data.total,
              },
            },
          })
        }
      },
  
      * delete ({ payload }, { call, put, select }) {
        const data = yield call(remove, { id: payload })
        const { selectedRowKeys } = yield select(_ => _.gwconfig)
        if (data.success) {
          yield put({ type: 'updateState', payload: { selectedRowKeys: selectedRowKeys.filter(_ => _ !== payload) } })
          yield put({ type: 'query' })
        } else {
          throw data
        }
      },
  
      * multiDelete ({ payload }, { call, put }) {
        console.log(payload)
        const data = yield call(remove, payload)
        if (data.success) {
          yield put({ type: 'updateState', payload: { selectedRowKeys: [] } })
          yield put({ type: 'query' })
        } else {
          throw data
        }
      },
  
      * create ({ payload }, { call, put ,select}) {
        const data = yield call(create, payload)
        if (data.success) {
          yield put({ type: 'hideModal' })
          yield put({ type: 'query' })
        } else {
          throw data
        }
      },
  
      * update ({ payload }, { select, call, put }) {
        const data = yield call(update, payload)
        if (data.success) {
          yield put({ type: 'hideModal' })
          yield put({ type: 'query' })
        } else {
          throw data
        }
      },
    },
  
    reducers: {
  
      showModal (state, { payload }) {
        return { ...state, ...payload, modalVisible: true }
      },
  
      hideModal (state) {
        return { ...state, modalVisible: false }
      },
  
      switchIsMotion (state) {
        window.localStorage.setItem(`${prefix}userIsMotion`, !state.isMotion)
        return { ...state, isMotion: !state.isMotion }
      },
  
    },
  })
  