import {
  getReturnOrderStatusDataAPI,
  getReturnOrderListDataAPI,
  deleteOrderListAPI,
  confirmReturnAPI
} from "../services/api";
import { getCustomer } from "@/utils/request.js";

export default {
  namespace: "returnOrderList",

  state: {},

  effects: {
    // 请求收货人地址
    *getOrderStatusData({ payload }, { call, put }) {
      // const response = yield call(getReturnOrderListDataAPI, payload);
      const response = {
        data: [
          // {
          //   name: "暂存",
          //   code: "01"
          // },
          {
            name: "待审核",
            code: "02"
          },
          {
            name: "退货中",
            code: "07"
          },
          {
            name: "已完成",
            code: "05"
          },
          {
            name: "驳回",
            code: "06"
          }
        ]
      };
      yield put({
        type: "orderStatusData",
        orderStatusData: response.data
      });
    },
    // 请求订单列表
    *getOrderListData({ payload }, { call, put }) {
      payload[`search_EQ_customerId`] = getCustomer().id;
      const response = yield call(getReturnOrderListDataAPI, payload);
      yield put({
        type: "orderListData",
        orderListData: response
      });
    },
    *deleteOrderById({ payload }, { call }) {
      yield call(deleteOrderListAPI, payload);
    },
    *confrimReturnById({ payload }, { call }) {
      yield call(confirmReturnAPI, payload);
    }
  },

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