order-confirm.js 1.83 KB
import { get, find } from 'lodash';

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',
  FETCH_ORDER_ADDRESS: 'FETCH_ORDER_ADDRESS'
};

export default function() {
  return {
    namespaced: true,
    state: {
      orderDetail: {},
      fetchOrderDetail: false,
      detail: {},
      address: {}
    },
    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;
      },
      [Types.FETCH_ORDER_ADDRESS](state, data) {
        state.address = data;
      }
    },
    actions: {
      async fetchOrderDetail({ commit }, { tabType = 'sell', orderCode } = {}) {
        commit(Types.FETCH_ORDER_DETAIL_REQUEST);

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

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

        commit(Types.FETCH_ORDER_DETAIL_SUCCESS, result.data);
      },
      async fetchOrderAddress({ commit }, payload) {
        const orderCount = await this.$api.get('/api/order/confirm/count', payload);

        if (get(orderCount, 'data.cnt', 0)) {
          const addressInfo = await this.$api.get('/api/order/confirm/address');

          const address = find(get(addressInfo, 'data', []), { is_default: 'Y' });

          commit(Types.FETCH_ORDER_ADDRESS, address);
        }
      },

      async fetchOrderPrice({ commit }, payload) {

      }

    },
    getters: {},
  };
}