order-detail.js 1.14 KB
export const Types = {
  FETCH_ORDER_DETAIL_REQUEST: 'FETCH_ORDER_DETAIL_REQUEST',
  FETCH_ORDER_DETAIL_FAIL: 'FETCH_ORDER_DETAIL_FAIL',
  FETCH_ORDER_DETAIL_SUCCESS: 'FETCH_ORDER_DETAIL_SUCCESS'
};

export default function() {
  return {
    namespaced: true,
    state: {
      orderDetail: {},
      fetchOrderDetail: false
    },
    mutations: {
      [Types.FETCH_ORDER_DETAIL_REQUEST](state) {
        state.fetchOrderDetail = true;
      },
      [Types.FETCH_ORDER_DETAIL_SUCCESS](state, data) {
        state.fetchOrderDetail = false;
        state.orderDetail = data;
      },
      [Types.FETCH_ORDER_DETAIL_FAIL](state) {
        state.fetchOrderDetail = false;
      }
    },
    actions: {
      async fetchOrderDetail({ commit }, { tabType = 'sell', orderCode } = {}) {
        commit(Types.FETCH_ORDER_DETAIL_REQUEST);

        const result = await this.$api.post('', {
          tabType,
          orderCode: orderCode
        });

        if (result.code !== 200) {
          commit(Types.FETCH_ORDER_DETAIL_FAIL);
          return;
        }

        commit(Types.FETCH_ORDER_DETAIL_SUCCESS, result.data);
      }
    },
    getters: {},
  };
}