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

export default {
  /**
   * 获取商品详细信息及尺码列表信息
   * @param commit
   * @param productId
   * @param page
   * @param refresh
   * @returns {Promise<void>}
   */
  async fetchProduct({commit}, {productId, page = 1, 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
        });
      }));

      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
      });
    }

    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);
    }
  },

  /**
   * 获取未入驻商家出售的商品详情
   * @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);

    if (result && result.code === 200) {
      commit(Types.FETCH_NOENTRY_ORDER_PRODUCT_SUCCESS, {
        order: result
      });
    } else {
      result = { alg: 'SALT_MD5',
        code: 200,
        data:
          { attributes: 1,
            bankTransferFee: '-¥0.09',
            bidType: 0,
            buttons: [ [Object], [Object] ],
            createTime: '2019-09-29 10:54:00',
            earnestMoney: 0.36,
            earnestMoneyStr: '¥0.36',
            goodsInfo:
              { batchNo: 1226211663688,
                bidType: 0,
                colorName: '黑色',
                entryFlag: false,
                goodImg:
                  'http://img11.static.yhbimg.com/goodsimg/2019/02/25/10/018b0d26a7e4bc0b39a93c329dd8c13d8e.jpg?imageMogr2/thumbnail/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
                goodPrice: '9.00',
                leastPrice: 9,
                leastPriceOfSkuTips: '最低现货价¥9',
                price: 9,
                productId: 10001266,
                productName: 'Air Jordan 1 复刻黑绿脚趾  范闲',
                sizeName: '37',
                skup: 19168,
                storageId: 10090816 },
            income: '¥8.47',
            isAdvance: 'N',
            isPaid: 1,
            orderCode: 1226211663688,
            payment: 2,
            paymentStr: '支付宝',
            platformFee:
              { amount: '-¥0.44',
                appraiseFee: '¥0.01',
                goodsPaymentRatePercent: '4.70%',
                packageFee: '¥0.01',
                payChannelPercentage: '1.00%',
                serviceFee: '¥0.42' },
            secendLevelCreateTime: 1569725640,
            statusDetail:
              { detailDesc: '商品出售中,待买家购买',
                expressShow: false,
                paymentTips: '交易成功后自动退还',
                statuStr: '出售中',
                status: 1 },
            submitOrderTimeStr: '2019-09-29 10:54:00',
            uid: 349709,
            userAddress:
              { address: '嘉陵江东街18号南京国家广告产****17楼',
                address_id: 2396242,
                area: '江苏省 南京市 建邺区 建邺区新城科技园',
                areaCode: '320105400',
                consignee: '*骏',
                isUpdate: 'N',
                mobile: '138****0257',
                phone: '',
                zipCode: '' } },
        md5: 'aa8b0d59cf55a6266304ac1edf6dbd43',
        message: '订单详情' };
      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 || {};
  }
};