...
|
...
|
@@ -3,9 +3,9 @@ import { get } from 'lodash'; |
|
|
import Vue from 'vue';
|
|
|
|
|
|
export default {
|
|
|
async fetchProductInfo({commit}, {productId}) {
|
|
|
async fetchProductInfo({ commit }, { productId }) {
|
|
|
const queryTasks = ['', '/resource', '/activity', '/recommend'].map(path => {
|
|
|
let params = {product_id: productId};
|
|
|
let params = { product_id: productId };
|
|
|
|
|
|
if (path === '/resource') {
|
|
|
params = {
|
...
|
...
|
@@ -31,7 +31,12 @@ export default { |
|
|
recommend: recommend && recommend.product_list || [],
|
|
|
}));
|
|
|
},
|
|
|
async fetchFav({commit, rootGetters}, {productId}) {
|
|
|
async fetchRecommendProduct({ commit }, { productId }) {
|
|
|
const result = await this.$api.get('/api/ufo/product/recommend', { product_id: productId })
|
|
|
|
|
|
return result?.data?.product_list ?? []
|
|
|
},
|
|
|
async fetchFav({ commit, rootGetters }, { productId }) {
|
|
|
let isLogin = rootGetters.getLogin;
|
|
|
|
|
|
if (!isLogin) {
|
...
|
...
|
@@ -44,7 +49,7 @@ export default { |
|
|
return false;
|
|
|
}
|
|
|
|
|
|
const isFav = await this.$api.get('/api/ufo/product/fav', {productId}).then(result => {
|
|
|
const isFav = await this.$api.get('/api/ufo/product/fav', { productId }).then(result => {
|
|
|
if (result.code === 200) {
|
|
|
return result.data;
|
|
|
} else {
|
...
|
...
|
@@ -52,27 +57,27 @@ export default { |
|
|
}
|
|
|
});
|
|
|
|
|
|
commit(Types.UPDATE_PRODUCT_FAV, {productId, isFav});
|
|
|
commit(Types.UPDATE_PRODUCT_FAV, { productId, isFav });
|
|
|
},
|
|
|
async fetchTop3({commit}, {productId}) {
|
|
|
const result = await this.$api.get('/api/ufo/product/top', {product_id: productId});
|
|
|
async fetchTop3({ commit }, { productId }) {
|
|
|
const result = await this.$api.get('/api/ufo/product/top', { product_id: productId });
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
const productList = result.data.product_list || [];
|
|
|
|
|
|
commit(Types.UPDATE_PRODUCT_TOP3, {productId, topList: productList.slice(0, 3)});
|
|
|
commit(Types.UPDATE_PRODUCT_TOP3, { productId, topList: productList.slice(0, 3) });
|
|
|
}
|
|
|
},
|
|
|
async toggleFav({commit}, {productId, isFav}) {
|
|
|
const result = await this.$api.get(`/api/ufo/product/favorite/${isFav ? 'add' : 'cancel'}`, {productId});
|
|
|
async toggleFav({ commit }, { productId, isFav }) {
|
|
|
const result = await this.$api.get(`/api/ufo/product/favorite/${isFav ? 'add' : 'cancel'}`, { productId });
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
commit(Types.UPDATE_PRODUCT_FAV, {productId, isFav});
|
|
|
commit(Types.UPDATE_PRODUCT_FAV, { productId, isFav });
|
|
|
}
|
|
|
},
|
|
|
async updateTradeInfo({commit, state}, {productId, sizeInfo}) {
|
|
|
async updateTradeInfo({ commit, state }, { productId, sizeInfo }) {
|
|
|
if (sizeInfo) {
|
|
|
commit(Types.UPDATE_SELECTED_PRODUCT_SIZE, {productId, sizeId: sizeInfo.size_id});
|
|
|
commit(Types.UPDATE_SELECTED_PRODUCT_SIZE, { productId, sizeId: sizeInfo.size_id });
|
|
|
}
|
|
|
|
|
|
return {
|
...
|
...
|
@@ -81,18 +86,18 @@ export default { |
|
|
storageId: state.selectedProductInfo.storageId,
|
|
|
};
|
|
|
},
|
|
|
async getSelectedTradeProduct({state, commit, dispatch}, {productId, storageId}) {
|
|
|
async getSelectedTradeProduct({ state, commit, dispatch }, { productId, storageId }) {
|
|
|
productId = parseInt(productId, 10);
|
|
|
storageId = parseInt(storageId, 10);
|
|
|
if (state.selectedProductInfo.productId !== productId && state.product.product_id !== productId) {
|
|
|
await dispatch('fetchProductInfo', {productId});
|
|
|
await dispatch('fetchProductInfo', { productId });
|
|
|
}
|
|
|
|
|
|
commit(Types.UPDATE_SELECTED_PRODUCT_SIZE, {productId, storageId});
|
|
|
commit(Types.UPDATE_SELECTED_PRODUCT_SIZE, { productId, storageId });
|
|
|
|
|
|
return state.selectedProductInfo;
|
|
|
},
|
|
|
async requestSize({state}, { sizeIds }) {
|
|
|
async requestSize({ state }, { sizeIds }) {
|
|
|
const selectedProduct = state.selectedProductInfo;
|
|
|
|
|
|
await this.$api.get('/api/ufo/product/addsize', {
|
...
|
...
|
@@ -103,7 +108,7 @@ export default { |
|
|
|
|
|
// 忽略错误
|
|
|
},
|
|
|
async payment(context, {skup}) {
|
|
|
return this.$api.post('/api/ufo/product/order/payment', {skup, api_version: 1});
|
|
|
async payment(context, { skup }) {
|
|
|
return this.$api.post('/api/ufo/product/order/payment', { skup, api_version: 1 });
|
|
|
},
|
|
|
}; |
...
|
...
|
|