actions.js 1.88 KB
import * as Types from './types';

export default {
  /*
   * @ description: 获取商品详情
   * @ author: huzhiming
   * @ date: 2019-11-22 10:15:13
   * @ version: v1.0.0
  */
  async fetchDetailById({ commit, state }, { skup = null }) {
    let { data: info = null } = await this.$api.post('/api/ufo/secondhand/productDetail', { skup });

    // console.log('[store/actions/fetchDetailById]:', info);
    commit(Types.UPDATE_PRODUCT_DETAIL, {info});
  },

  /*
   * @ description: 获取相同尺寸二手列表
   * @ author: huzhiming
   * @ date: 2019-11-22 17:05:04
   * @ version: v1.0.0
  */
  async fetchSameSizeSecondList({ commit, state }, { isReset, storage_id, second_type = null, sort = null }) {
    let page = 1;

    if (isReset) {
      page = 1;
    } else {
      page = state.page;
    }

    let pageSize = 10;

    const { data, code } = await this.$api.get('/api/ufo/secondhand/list', { page, pageSize, storage_id: storage_id, second_type, sort });

    // console.log(page, pageSize, storage_id, second_type, sort);
    // console.log('[store/actions/fetchSameSizeSecondList]:', data);

    if (code === 200) {
      commit(Types.UPDATE_PRODUCT_LIST, { data, isReset });
    } else {
      commit(Types.UPDATE_PRODUCT_LIST, { error: true, data, isReset });
    }
    return data || [];
  },

  /*
   * @ description: 获取筛选数据
   * @ author: huzhiming
   * @ date: 2019-11-22 14:32:46
   * @ version: v1.0.0
  */
  async fetchFilterData({ commit, state }, { storage_id = null }) {
    let { data: { filter = [] } } = await this.$api.post('/api/ufo/secondhand/filter', { storage_id });

    // console.log('[store/actions/fetchFilterData]:', JSON.stringify(filter));
    commit(Types.UPDATE_PRODUCT_FILTER, { filter });
    return filter;
  },

  fetchStorageCount(ctx, { storageId }) {
    return this.$api.post('/api/ufo/secondhand/storageCount', { storage_id: storageId });
  }
};