import { getOrderSignDataAPI } from "../services/api";
import { getCustomer } from "@/utils/request.js";

export default {
  namespace: "orderSignList",
  state: {},

  effects: {
    *getOrderSignData({ payload }, { call, put }) {
      payload[`search_EQ_customerId`] = getCustomer().id;
      const response = yield call(getOrderSignDataAPI, payload);
      // const response = {
      //   totalElements: 2,
      //   size: 10,
      //   content: [
      //   {
      //     id: "pk100001",
      //     billCode: "2018062201",
      //     billDate: Date.now(),
      //     totalAssistNum: 20,
      //     saleOutOrderItemInfoDtos: [
      //       {
      //         goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //         reqOrderCodes: "REQ20180001"
      //       },
      //       {
      //         goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //         reqOrderCodes: "REQ20180002"
      //       }
      //     ]
      //   },
      //   {
      //     billCode: "2018062202",
      //     billDate: Date.now(),
      //     totalAssistNum: 30,
      //     signNum: 1,
      //     id: "pk100001",
      //     saleOutOrderItemInfoDtos: [
      //       {
      //         goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //         reqOrderCodes: "REQ20180003",
      //         signNum: 2
      //       },
      //       {
      //         goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //         reqOrderCodes: "REQ20180004"
      //       },
      //       {
      //         goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //         reqOrderCodes: "REQ20180005"
      //       },
      //       {
      //         goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //         reqOrderCodes: "REQ20180006"
      //       }
      //     ]
      //   },
      //   {
      //     billCode: "2018062203",
      //     billDate: Date.now(),
      //     totalAssistNum: 50,
      //     id: "pk100001",
      //     saleOutOrderItemInfoDtos: [
      //       {
      //         goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //         reqOrderCodes: "REQ20180006"
      //       }
      //     ]
      //   },
      // ]
      // };
      yield put({
        type: "orderSignData",
        orderSignData: response || {}
      });
    },
    *getOrderSignStatus({ payload }, { call, put }) {
      // const respose = yield call(API, payload);
      const orderSignStatusData = [
        {
          name: "未签收",
          code: "01"
        },
        {
          name: "已签收",
          code: "02"
        }
      ];
      yield put({
        type: "orderSignStatus",
        orderSignStatusData: orderSignStatusData // response.data
      });
    }
  },
  reducers: {
    orderSignData(state, payload) {
      return {
        ...state,
        orderSignData: payload.orderSignData
      };
    },
    orderSignStatus(state, payload) {
      return {
        ...state,
        orderSignStatusData: payload.orderSignStatusData
      };
    }
  }
};
