import { getDeliveryDetailAPI, signConfirmAPI } from "../services/api";

export default {
  namespace: "orderSignListDetail",

  state: {},

  effects: {
    // 根据主键获取发货单明细
    *getDeliveryDetail({ payload }, { call, put }) {
      const response = yield call(getDeliveryDetailAPI, payload);
      // const response = {
      //   billCode: "2018062202",
      //   billDate: Date.now(),
      //   totalAssistNum: 30,
      //   saleOutOrderItemInfoDtos: [
      //     {
      //       goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //       goodsDisplayName: "商品A",
      //       goodsCode: "G001",
      //       reqOrderCodes: "REQ20180003",
      //       assistNum: 10,
      //       signNum: 10
      //     },
      //     {
      //       goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //       goodsDisplayName: "商品B",
      //       goodsCode: "G002",
      //       reqOrderCodes: "REQ20180004",
      //       assistNum: 20,
      //       signNum: 20
      //     },
      //     {
      //       goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //       reqOrderCodes: "REQ20180005",
      //       goodsDisplayName: "商品B",
      //       goodsCode: "G002",
      //       assistNum: 30,
      //       signNum: 30
      //     },
      //     {
      //       goodsImg: "/g1/M00/00/02/rBQPwFsrbnqAHWa5AACHUftT22Y174.jpg",
      //       reqOrderCodes: "REQ20180006",
      //       goodsDisplayName: "商品B",
      //       goodsCode: "G002",
      //       assistNum: 40,
      //       signNum: 40
      //     }
      //   ]
      // };
      yield put({
        type: "deliveryDetailData",
        deliveryDetailData: response || {}
      });
    },
    // 签收确认
    *signConfirm({ payload }, { call, put }) {
      const response = yield call(signConfirmAPI, payload);
      yield put({
        type: "returnData",
        returnData: response
      });
    }
  },

  reducers: {
    deliveryDetailData(state, payload) {
      return {
        ...state,
        deliveryDetailData: payload.deliveryDetailData
      };
    },
    returnData(state, payload) {
      return {
        ...state,
        returnData: payload.returnData
      };
    }
  }
};
