import {
  getOrderStatusDataAPI,
  getOrderListDataAPI,
  deleteOrderListAPI
} from "../services/api";
import { getCustomer } from "@/utils/request.js";
export default {
  namespace: "orderList",

  state: {},

  effects: {
    // 请求 订单状态
    *getOrderStatusData({ payload }, { call, put }) {
      // const response = yield call(getOrderStatusDataAPI, payload);
      const response = {
        data: [
          {
            name: "暂存",
            code: "01"
          },
          {
            name: "待审核",
            code: "02"
          },
          {
            name: "待发货",
            code: "03"
          },
          {
            name: "待签收",
            code: "04"
          },
          {
            name: "已完成",
            code: "05"
          },
          {
            name: "驳回",
            code: "06"
          }
        ]
      };
      yield put({
        type: "orderStatusData",
        orderStatusData: response.data
      });
    },
    // 请求订单列表
    *getOrderListData({ payload }, { call, put }) {
      payload[`search_EQ_customer`] = getCustomer().id;
      const response = yield call(getOrderListDataAPI, payload);
      yield put({
        type: "orderListData",
        orderListData: response
      });
    },
    *deleteOrderById({ payload }, { call }) {
      yield call(deleteOrderListAPI, payload);
    }
  },

  reducers: {
    orderStatusData(state, payload) {
      return {
        ...state,
        orderStatusData: payload.orderStatusData
      };
    },
    orderListData(state, payload) {
      return {
        ...state,
        orderListData: payload.orderListData
      };
    }
  }
};
