CustomerConsumptionStore.js 1.85 KB
Newer Older
姜雷 committed
1
import { getConsumeOrderList } from '@/api/dashboard/dashboard';
2
// import initFiltersStore from '@/store/modules/filters';
姜雷 committed
3 4
import { getFilters, formatDate } from '@/utils/index';
const FETCH_CONSUME_LIST = 'FETCH_CONSUME_LIST';
5
const FETCH_DATA = 'FETCH_DATA';
姜雷 committed
6

7 8 9 10 11 12
// const initFilters = () => ({
//   operateId: undefined,
//   areaId: undefined,
//   timeType: 0, // 0 本日,1 本月, 2 本年
// });
// const filtersStore = initFiltersStore(initFilters);
姜雷 committed
13 14 15
const nowTime = new Date();

const state = () => ({
16
  loading: false,
姜雷 committed
17 18 19 20 21 22 23 24 25 26
  list: [],
  consumeCountVo: {
    payMen: 0,
    payableMoney: 0,
  },
});

const getters = {
  consumeList: state => state.list,
  consumeCount: state => state.consumeCountVo,
27
  loading: state => state.loading,
姜雷 committed
28 29 30
};

const actions = {
31
  getConsumeOrderList({ commit, rootGetters }) {
32
    commit(FETCH_DATA, true);
33
    let entity = getFilters(rootGetters['Dashboard/customerData/filters']);
姜雷 committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47
    switch (entity.timeType) {
      case 1:
        entity.month = formatDate(nowTime, 'yyyy-MM');
        break;
      case 2:
        entity.year = formatDate(nowTime, 'yyyy');
        break;
      case 0:
      default:
        entity.date = formatDate(nowTime, 'yyyy-MM-dd');
        break;
    }
    return getConsumeOrderList({
      data: entity,
姜雷 committed
48 49 50 51
    })
      .then(res => {
        const { data, consumeCountVo } = res;
        commit(FETCH_CONSUME_LIST, { list: data, consumeCountVo });
52
        commit(FETCH_DATA, false);
姜雷 committed
53 54 55
      })
      .catch(err => {
        console.error(err);
姜雷 committed
56
        commit(FETCH_DATA, false);
姜雷 committed
57
      });
姜雷 committed
58 59 60 61 62 63 64 65
  },
};

const mutations = {
  [FETCH_CONSUME_LIST](state, data) {
    state.list = data.list;
    state.consumeCountVo = data.consumeCountVo;
  },
66 67 68
  [FETCH_DATA](state, fetching) {
    state.loading = fetching;
  },
姜雷 committed
69 70 71 72
};

export default {
  namespaced: true,
73
  // modules: { filtersStore },
姜雷 committed
74 75 76 77 78
  state,
  getters,
  actions,
  mutations,
};