favorite.js 1.24 KB
import { get, set } from 'lodash';
import { getImgUrl } from '../../common/utils';
import Vue from 'vue';
const uid = '500031170';

export default function() {
  return {
    namespaced: true,
    state: {
      page: 1,
      pageTotal: 0,
      recId: '',
      favoriteProductList: {
        list:[]
      },
      isShowEmpty: false,
    },
    mutations: {
      addList(state, { data }) {
        console.log(data)
        if(data && data.product_list){
          // data.product_list.
            let { page, product_list = [] } = res;
            state.isShowEmpty = page === 1 && product_list === 0;
            let list = state.favoriteProductList.list.concat(product_list);
            Vue.set(state.favoriteProductList, "list", list);
        }else {
          state.isShowEmpty = true;
        }

      },
      errorData(state){
        state.isShowEmpty = true;
      }
     
    },
    actions: {
      async fetchFavoriteList({ commit }) {
        const result = await this.$api.get('/api/ufo/home/favoriteProduct', {uid});
        if (result.code === 200) {
            let data =result.data;
          commit('addList', { data:data });
        }else {
          commit('error');
        }
        return result.data || [];
      },
    },
  };
}