
const stateData = {
    overlay:{
        show:false,
        data:{
            title:'默认'
        }
    },
    members: [] as any,
    loading: 0,
    requestCount: 0,
    type: 1,
    res: '',       // 提交失败信息
    text: '',      // 提交提示
    text1: '',     // 提交提示1
    address: '',   // 用户地址
    form: {}       // 发起表单
}
interface overlayData {
    title:string
}
interface memberItem {
    name: string;
    addr: string
}
export type AppType = typeof stateData
export const appStore = {
    namespaced: true,
        state: () => ({
            ...stateData
        }),
    getter: {
      getAddress(state: {address: string}) {
        return state.address
      }
    },
    mutations: {
        TOGGLE_STATUS(state:AppType){
            state.overlay.show = !state.overlay.show
        },
        SET_OVERLAY(state:AppType,payload:overlayData){
            Object.assign(state.overlay.data,payload)
        },
        ADD_MEMBER(state:AppType, member: memberItem) {
            state.members.push(member)
        },
        EDIT_MEMBER(state:AppType, o: any) {
            state.members.splice(o.num, 1, o.params)
        },
        REMOVE_MEMBER(state:AppType, i: number) {
            state.members.splice(i, 1)
        },
        SET_MEMBER(state:AppType, o: any) {
            state.members = o
        },
        CLEAR_MEMBER(state:AppType) {
            state.members = [] as any
        },
        SHOW_LOADING(state:AppType) {
            state.loading = 1
        },
        HIDE_LOADING(state:AppType) {
            state.loading = 0
        },
        SET_WAIT(state: AppType) {
            state.loading = 2
        },
        SET_RES(state: AppType) {
            state.loading = 3
        },
        SET_ERROR(state: AppType) {
            state.loading = 4
        },
        SET_TYPE(state: AppType, i: number) {
            state.type = i
        },
        SET_RESULT(state: AppType, s: string) {
            state.res = s
        },
        SET_TEXT(state: AppType, s: string) {
            state.text = s
        },
        SET_TEXT1(state: AppType, s: string) {
            state.text1 = s
        },
        SET_ADDRESS(state: AppType, s: string) {
            state.address = s
        },
        CLEAR_ADDRESS(state: AppType) {
            state.address = ''
        },
        SET_FORM(state: AppType, s: any) {
            state.form = s
        },
        CLEAR_FORM(state: AppType) {
            state.form = {}
        },
        ADD_REQUEST(state: AppType) {
            state.requestCount++
        },
        DEC_REQUEST(state: AppType) {
            state.requestCount--
        },
    },
    actions: {

    },
    getters: {
        loadingStatus: (state: AppType) => state.loading
    }
  };
  
