actions.js 4.54 KB
import * as Types from './types';
import {first, get, flatten} from 'lodash';

export default {
  /**
   * 获取商品详细信息及尺码列表信息
   * @param commit
   * @param productId
   * @param page
   * @param refresh
   * @param pageSize
   * @returns {Promise<void>}
   */
  async fetchProduct({commit}, {productId, page = 1, pageSize = 50, refresh = false}) {
    commit(Types.FETCH_ORDER_PRODUCT_REQUEST);

    let result;

    if (refresh) {
      const results = await Promise.all(Array.from(new Array(page)).map((v, i) => {
        return this.$api.get('/api/ufo/seller/entryGoodsSizeList', {
          productId,
          page: i + 1,
          limit: pageSize
        });
      }));

      result = {
        code: 200,
        data: {
          productInfo: get(first(results), 'data.productInfo'),
          data: flatten(results.map(r => get(r, 'data.data', [])))
        }
      };
    } else {
      result = await this.$api.get('/api/ufo/seller/entryGoodsSizeList', {
        productId,
        page,
        limit: pageSize
      });
    }

    console.log(result);

    if (result && result.code === 200) {
      commit(Types.FETCH_ORDER_PRODUCT_SUCCESS, {
        order: result.data,
        refresh
      });
    } else {
      commit(Types.FETCH_ORDER_PRODUCT_FAILED);
    }
    return result;
  },

  /**
   * 获取未入驻商家出售的商品详情
   * @param commit
   * @param orderCode
   * @returns {Promise<void>}
   */
  async fetchOrder({commit}, {orderCode}) {
    commit(Types.FETCH_NOENTRY_ORDER_PRODUCT_REQUEST);

    let result;

    result = await this.$api.get('/api/order/detail', {
      orderCode,
      tabType: 'sell'
    });

    // console.log('fetchOrder= ', result.data);

    if (result && result.code === 200) {
      commit(Types.FETCH_NOENTRY_ORDER_PRODUCT_SUCCESS, {
        order: result
      });
    } else {
      /*commit(Types.FETCH_NOENTRY_ORDER_PRODUCT_SUCCESS, {
        order: result
      });*/

      commit(Types.FETCH_NOENTRY_ORDER_PRODUCT_FAILED);
    }
  },

  /**
   * 不卖了
   * @param commit
   * @param payload
   * @returns {Promise<void>}
   */
  async postNoSale({commit}, payload) {
    commit(Types.POST_NOSALE_REQUEST);
    const result = await this.$api.get('/api/ufo/sellerOrder/batchDownShelf', payload);

    // console.log('下架=', result);
    if (result && result.code === 200) {
      commit(Types.POST_NOSALE_SUCCESS, {
        order: result.data
      });
    } else {
      commit(Types.POST_CALCPRICE_FAILED);
    }

    return result || {};
  },

  /**
   * 入驻商家试算调价
   * @param commit
   * @param payload
   * @returns {Promise<*|{}>}
   */
  async postCalcPrice({commit}, payload) {
    commit(Types.POST_CALCPRICE_REQUEST);
    const result = await this.$api.get('/api/ufo/sellerOrder/computeAdjustPrice', payload);

    if (result && result.code === 200) {
      commit(Types.POST_CALCPRICE_SUCCESS, {
        order: result.data
      });
    } else {
      commit(Types.POST_CALCPRICE_FAILED);
    }

    return result || {};
  },

  /**
   * 未入驻商家试算调价
   * @param commit
   * @param payload
   * @returns {Promise<{}>}
   */
  async postNoEntryCalcPrice({commit}, payload) {
    commit(Types.POST_NOENTRY_CALCPRICE_REQUEST);

    const result = await this.$api.get('/api/ufo/notEntrySeller/computeChangePrice', payload);

    if (result && result.code === 200) {
      commit(Types.POST_NOENTRY_CALCPRICE_SUCCESS, {
        order: result.data
      });
    } else {
      commit(Types.POST_NOENTRY_CALCPRICE_FAILED);
    }

    return result || {};
  },

  /**
   * 调价
   * @param commit
   * @param payload
   * @returns {Promise<*|{}>}
   */
  async postChangePrice({commit}, payload) {
    commit(Types.POST_CHANGE_PRICE_REQUEST);
    const result = await this.$api.get('/api/ufo/sellerOrder/batchAdjustPrice', payload);

    if (result && result.code === 200) {
      commit(Types.POST_CHANGEPRICE_SUCCESS, {
        order: result.data
      });
    } else {
      commit(Types.POST_CHANGEPRICE_FAILED);
    }

    return result || {};
  },

  /**
   * 未入驻商家调价
   * @param commit
   * @param payload
   * @returns {Promise<*|{}>}
   */
  async postNoEntryChangePrice({commit}, payload) {
    commit(Types.POST_NOENTRY_CHANGE_PRICE_REQUEST);
    const result = await this.$api.get('/api/ufo/notEntrySeller/changePrice', payload);

    if (result && result.code === 200) {
      commit(Types.POST_NOENTRY_CHANGE_PRICE_SUCCESS, {
        order: result.data
      });
    } else {
      commit(Types.POST_NOENTRY_CHANGE_PRICE_FAILED);
    }

    return result || {};
  }
};