import {
  getOrderDetailDataAPI,
  getSettlementDataAPI,
  getLogisticsDataAPI,
  getOrderStatusDataAPI
} from "../services/api";

export default {
  namespace: "orderListDetail",

  state: {},

  effects: {
    // 根据主键获取订单明细
    *getOrderDetailData({ payload }, { call, put }) {
      const response = yield call(getOrderDetailDataAPI, payload);
      yield put({
        type: "orderDetailData",
        orderDetailData: response
      });
    },
    // 请求物流方式
    *getLogisticsData({ payload }, { call, put }) {
      const response = yield call(getLogisticsDataAPI, payload);
      yield put({
        type: "logisticsData",
        logisticsData: response
      });
    },
    // 请求结算方式
    *getSettlementData({ payload }, { call, put }) {
      const response = yield call(getSettlementDataAPI, payload);
      yield put({
        type: "settlementData",
        settlementData: response
      });
    },
    // 请求订单状态
    *getOrderStatusData({ payload }, { call, put }) {
      // const response = yield call(getOrderStatusDataAPI, payload);
      yield put({
        type: "orderStatusData",
        orderStatusData: [{}] // response.data
      });
    }
  },

  reducers: {
    orderDetailData(state, payload) {
      return {
        ...state,
        orderDetailData: payload.orderDetailData
      };
    },
    logisticsData(state, payload) {
      return {
        ...state,
        logisticsData: payload.logisticsData
      };
    },
    settlementData(state, payload) {
      return {
        ...state,
        settlementData: payload.settlementData
      };
    },
    orderStatusData(state, payload) {
      return {
        ...state,
        orderStatusData: payload.orderStatusData
      };
    }
  }
};
