...
|
...
|
@@ -35,6 +35,14 @@ const { |
|
|
HOME_BOTTOM_BANNER_SUCCESS,
|
|
|
HOME_BOTTOM_BANNER_FAILURE,
|
|
|
|
|
|
SHOP_FAV_ADD_REQUEST,
|
|
|
SHOP_FAV_ADD_SUCCESS,
|
|
|
SHOP_FAV_ADD_FAILURE,
|
|
|
|
|
|
SHOP_FAV_CANCEL_REQUEST,
|
|
|
SHOP_FAV_CANCEL_SUCCESS,
|
|
|
SHOP_FAV_CANCEL_FAILURE,
|
|
|
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -399,6 +407,128 @@ function fetchShopInfo(data, channel) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
export function favoriteOperation(shopId) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, home} = getState();
|
|
|
let channelStr = channelTransfer.number2String(app.channel);
|
|
|
let shopState = home[channelStr].shop.get('list');
|
|
|
let state = shopState.get(shopId, '');
|
|
|
if (!state) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let resultNumber = parseInt(state.get('collectionNum', 0));
|
|
|
if (state.get('favorite')) {
|
|
|
resultNumber = resultNumber > 0 ? (resultNumber - 1) : 0;
|
|
|
dispatch(cancelFavorite(shopId, resultNumber));
|
|
|
} else {
|
|
|
resultNumber = resultNumber + 1;
|
|
|
dispatch(addFavorite(shopId, resultNumber));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function addFavoritRequest(channelStr) {
|
|
|
return {
|
|
|
type: SHOP_FAV_ADD_REQUEST,
|
|
|
payload: channelStr
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addFavoritSuccess(channelStr, resultNumber, shopId, collected) {
|
|
|
return {
|
|
|
type: SHOP_FAV_ADD_SUCCESS,
|
|
|
payload: {channelStr, resultNumber, shopId, collected}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addFavoritFailure(error, channelStr) {
|
|
|
return {
|
|
|
type: SHOP_FAV_ADD_FAILURE,
|
|
|
payload: {channelStr, error}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function addFavorite(shopId, resultNumber) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, home} = getState();
|
|
|
|
|
|
let channelStr = channelTransfer.number2String(app.channel);
|
|
|
|
|
|
let favoriteRequest = (shopId, uid) => {
|
|
|
dispatch(addFavoritRequest(channelStr));
|
|
|
dispatch(addFavoritSuccess(channelStr, resultNumber, shopId, true));
|
|
|
return new HomeService(app.host).addFavorite(shopId, uid)
|
|
|
.then(json => {
|
|
|
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(addFavoritFailure(error, channelStr));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
favoriteRequest(shopId, uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
favoriteRequest(shopId, uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function cancelFavoritRequest(channelStr) {
|
|
|
return {
|
|
|
type: SHOP_FAV_ADD_REQUEST,
|
|
|
payload: channelStr
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function cancelFavoritSuccess(channelStr, resultNumber, shopId, collected) {
|
|
|
return {
|
|
|
type: SHOP_FAV_ADD_SUCCESS,
|
|
|
payload: {channelStr, resultNumber, shopId, collected}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function cancelFavoritFailure(error, channelStr) {
|
|
|
return {
|
|
|
type: SHOP_FAV_ADD_FAILURE,
|
|
|
payload: {channelStr, error}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function cancelFavorite(shopId, resultNumber) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, home} = getState();
|
|
|
|
|
|
let channelStr = channelTransfer.number2String(app.channel);
|
|
|
|
|
|
dispatch(cancelFavoritRequest(channelStr));
|
|
|
dispatch(cancelFavoritSuccess(channelStr, resultNumber, shopId, false));
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
return new HomeService(app.host).cancelFavorite(shopId, uid)
|
|
|
.then(json => {
|
|
|
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(cancelFavoritFailure(error, channelStr));
|
|
|
});
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/******** 首页楼层 *********/
|
|
|
// 开始请求
|
|
|
export function fetchFloorRequest(channelStr) {
|
...
|
...
|
|