index.js 1.32 KB
import actions from './actions';
import mutations from './mutations';

function handleNum(n) {
  return n > 99 ? '99+' : n;
}

export default function() {
  return {
    namespaced: true,
    state: {
      fetching: false,
      yohoList: {
        notuse: {
          couponList: [],
          pageNum: 0,
          pageSize: 10,
          total: 0,
          page: 0,
          filterId: 0,
        },
        use: {
          couponList: [],
          pageNum: 0,
          pageSize: 10,
          total: 0,
          page: 0,
          filterId: 0,
        },
        overtime: {
          couponList: [],
          pageNum: 0,
          pageSize: 10,
          total: 0,
          page: 0,
          filterId: 0,
        },
      },
      num: {
        notuse: 0,
        use: 0,
        overtime: 0,
      },
      ufoList: [],
      filterList: [],
    },
    actions,
    mutations,
    getters: {
      getNum(state) {
        return [
          handleNum(state.num.notuse),
          handleNum(state.num.use),
          handleNum(state.num.overtime),
        ];
      },
      getNotUseList(state) {
        return state.yohoList.notuse.couponList;
      },
      getUseList(state) {
        return state.yohoList.use.couponList;
      },
      getOvertimeList(state) {
        return state.yohoList.overtime.couponList;
      },
    },
  };
}