index.js 1.83 KB
import actions from './actions';
import mutations from './mutations';

export function defaultState() {
  return {
    product: {
      brand_name: '',
      canPublishSecondHand: false,
      gender: '通用',
      goods_list: [
        {
          canAddSize: false,
          color_name: '',
          goods_id: null,
          goods_name: '-',
          image_list: [
          ],
          size_list: [
          ]
        }
      ],
      least_price: null,
      max_price: null,
      max_sort_id: null,
      min_price: null,
      offer_price: null,
      product_code: null,
      product_id: null,
      product_name: null,
      sale_time: null,
      sellerCanPublish: true,
      series_name: null,
      shelve_status: null,
      resource: null,
      activity: [],
      recommend: [],
    },

    /**
     * 用户在商品详情页选择的交易信息
     * productId: 商品id
     * product: 商品详情
     * sizeId: 尺寸id
     * storageId: 库存id
     * size: 尺寸信息
     * tradeTypeId: 交易类型id
     * tradeType: 交易类型
     */
    selectedProductInfo: {
      productId: null,
      product: {},
      sizeId: null,
      storageId: null,
      size: {},
      tradeTypeId: null,
      tradeType: {},
    },
  };
}

export default function() {
  return {
    namespaced: true,
    state: defaultState(),
    mutations,
    actions,
    getters: {
      productDetail(state) {
        return state.product;
      },
      imageList(state) {
        return state.product.goods_list[0].image_list;
      },
      resource(state) {
        return state.product.resource;
      },
      activity(state) {
        return state.product.activity;
      },
      recommend(state) {
        return state.product.recommend;
      },
      selectedSize(state) {
        return state.selectedProductInfo.size;
      }
    }
  };
}