actions.js 7.17 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.data);

    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.19",
          "bidType": 0,
          "buttons": [{
            "code": "not_sold",
            "confirmTips": "您确定不卖此商品么?取消后保证金将原路退还至您的账户",
            "name": "NOT_SOLD",
            "text": "不卖了"
          }, {
            "code": "not_entry_change_price",
            "name": "NOT_ENTRY_CHANGE_PRICE",
            "text": "调价"
          }],
          "createTime": "2019-10-09 18:01:23",
          "earnestMoney": 0.76,
          "earnestMoneyStr": "¥0.76",
          "goodsInfo": {
            "batchNo": 1233499619151,
            "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": "19.00",
            "leastPrice": 19.00,
            "leastPriceOfSkuTips": "最低现货价¥19",
            "price": 19.00,
            "productId": 10001266,
            "productName": "Air Jordan 1 复刻黑绿脚趾  范闲",
            "sizeName": "37",
            "skup": 19466,
            "storageId": 10090816
          },
          "income": "¥18.79",
          "isAdvance": "N",
          "isPaid": 1,
          "orderCode": 1233499619151,
          "payStartTime": 1570615283,
          "payment": 9,
          "paymentStr": "手机网站支付宝",
          "platformFee": {
            "amount": "-¥0.02",
            "appraiseFee": "¥0.01",
            "goodsPaymentRatePercent": "0.00%",
            "packageFee": "¥0.01",
            "payChannelPercentage": "1.00%",
            "serviceFee": "¥0.00"
          },
          "secendLevelCreateTime": 1570615283,
          "statusDetail": {
            "detailDesc": "商品出售中,待买家购买",
            "expressShow": false,
            "paymentTips": "交易成功后自动退还",
            "statuStr": "出售中",
            "status": 1
          },
          "submitOrderTimeStr": "2019-10-09 18:01:23",
          "uid": 349709,
          "userAddress": {
            "address": "嘉陵江东街18号南京国家广告产****17楼",
            "address_id": 2396242,
            "area": "江苏省 南京市 建邺区 建邺区新城科技园",
            "areaCode": "320105400",
            "consignee": "*骏",
            "isUpdate": "N",
            "mobile": "138****0257",
            "phone": "",
            "zipCode": ""
          }
        },
        "md5": "ab14db14196b6213d05d288179ecf9e2",
        "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 || {};
  }
};