Authored by 陈林

增加拼团列表跳转参数调整和拼团详情页商品列表接口调整。review by 孙凯。

... ... @@ -8,7 +8,7 @@ import appInitialState from './reducers/app/appInitialState';
import groupPurchaseInitialState from './reducers/groupPurchase/groupPurchaseInitialState';
import GroupPurchaseContainer from './containers/GroupPurchaseContainer';
import {setHost, setPlatform, setServiceHost, getUid, getUnionType} from './reducers/app/appActions';
import {setActivityId} from './reducers/groupPurchase/groupPurchaseActions';
import {setActivityId, setGroupListParams} from './reducers/groupPurchase/groupPurchaseActions';
import createReactClass from 'create-react-class';
import GroupPurchaseDetailContainer from './containers/GroupPurchaseDetailContainer';
import {setDetailActivityId,setGroupNo} from './reducers/groupPurchaseDetail/groupPurchaseDetailActions';
... ... @@ -30,14 +30,21 @@ export default function native(platform) {
render() {
const store = configureStore(getInitialState());
store.dispatch(setPlatform(platform));
store.dispatch(setHost(this.props.host));
store.dispatch(setServiceHost(this.props.serviceHost));
store.dispatch(setActivityId(this.props.activityId));
// 将activityId的判断逻辑从原生移至RN处理
let activityId = this.props.activityId;
if(!activityId && this.props.template_id){
activityId = this.props.template_id
}
store.dispatch(setActivityId(activityId));
store.dispatch(setGroupNo(this.props.groupNo));
store.dispatch(setDetailActivityId(this.props.activityId));
store.dispatch(setDetailActivityId(activityId));
store.dispatch(getUid());
store.dispatch(getUnionType());
store.dispatch(setGroupListParams(this.props))
let type = this.props.type;
if (type === 'List') {
... ...
... ... @@ -6,6 +6,7 @@ export default keyMirror({
SET_HOST: null,
SET_SERVICE_HOST: null,
SET_ACTIVITY_ID: null,
SET_GROUPLIST_PARAMS: null,
PRODUCT_LIST_REQUEST: null,
PRODUCT_LIST_SUCCESS: null,
PRODUCT_LIST_FAILURE: null,
... ...
... ... @@ -61,7 +61,7 @@ class GroupPurchaseDetailContainer extends Component {
}
async componentDidMount() {
this.props.actions.getProductList();
this.props.actions.getProductList(false, true);
this.props.actions.fetchActivityGroupDetail(this.props.FP_NAME, this.props.FP_PARAM);
// this.props.actions.fetchResourceInfo();
}
... ... @@ -190,7 +190,7 @@ class GroupPurchaseDetailContainer extends Component {
}
_onEndReached() {
this.props.actions.getProductList();
this.props.actions.getProductList(false, true);
}
render() {
... ...
... ... @@ -7,6 +7,7 @@ const Platform = require('Platform');
const {
SET_ACTIVITY_ID,
SET_GROUPLIST_PARAMS,
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_FAILURE,
... ... @@ -42,6 +43,13 @@ export function setActivityId(activityId) {
}
}
export function setGroupListParams(params) {
return {
type: SET_GROUPLIST_PARAMS,
payload: params,
}
}
export function productListRequest() {
return {
type: PRODUCT_LIST_REQUEST,
... ... @@ -97,10 +105,10 @@ export function fetchResourceInfo() {
};
}
export function getProductList(reload=false) {
export function getProductList(reload=false, fromDetail=false) {
return (dispatch, getState) => {
let {app, groupPurchase} = getState();
let {productList,activityId} = groupPurchase;
let {productList,activityId, groupListParams} = groupPurchase;
if (reload) {
} else {
... ... @@ -114,7 +122,9 @@ export function getProductList(reload=false) {
let fromPage = Platform.OS === 'android' ? 'aFP_GroupPurchaseList' : 'iFP_GroupPurchaseList';
dispatch(productListRequest());
return new GroupPurchaseService(app.host).fetchProductList(activityId, page, limit,fromPage)
if(fromDetail){
return new GroupPurchaseService(app.host).fetchGroupDetailProductList(activityId, page, limit,fromPage)
.then(json => {
json.endReached = json.page == json.page_total;
if (json.page > 1) {
... ... @@ -127,9 +137,55 @@ export function getProductList(reload=false) {
.catch(error => {
dispatch(productListFailure(error));
});
}else{
//处理拼团列表参数
let listParams = excludeParams(groupListParams);
return new GroupPurchaseService(app.host).fetchGroupProductList(activityId, page, limit,fromPage, listParams)
.then(json => {
json.endReached = json.page == json.page_total;
if (json.page > 1) {
let oldList = productList.list.toJS();
let list = [...oldList, ...json.collageProductVoList];
json.collageProductVoList = list;
}
dispatch(productListSuccess(json));
})
.catch(error => {
dispatch(productListFailure(error));
});
}
};
}
function excludeParams(groupParams){
let newParams = {};
try{
let params = groupParams.toJS();
for(let key in params){
if(params[key]){
newParams[key] = params[key]
}
}
//gender 需要进行空处理,防止原生会添加默认值
if(!newParams["gender"]){
newParams["gender"] = "";
}
//size因为字段是关键字,使用了g_size替换
if(newParams["g_size"]){
newParams["size"] = newParams["g_size"];
delete newParams["g_size"]
}
}catch(e){
}
return newParams;
}
export function shareCodeInfoRequest() {
return {
type: SHARECODEINFO_REQUEST,
... ...
... ... @@ -6,6 +6,24 @@ let InitialState = Record({
activityId: 0,
showShareView: false,
showSnapshootShare: false,
groupListParams: new (Record({
collageTopSkn: '',
sort: '',
gender: '',
order: '',
p_d: '',
color: '',
brand: '',
price: '',
g_size: '',
msort: '',
misort: '',
age_level: '',
style: '',
from: '',
showType: '',
})),
productList: new (Record({
isFetching: false,
error: null,
... ...
... ... @@ -5,6 +5,7 @@ import Immutable from 'immutable';
const {
SET_ACTIVITY_ID,
SET_GROUPLIST_PARAMS,
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_FAILURE,
... ... @@ -36,6 +37,24 @@ export default function couponReducer(state = initialState, action) {
case SET_ACTIVITY_ID: {
return state.set('activityId', action.payload);
}
case SET_GROUPLIST_PARAMS: {
let params = action.payload;
return state.setIn(['groupListParams', 'collageTopSkn'], params.collageTopSkn ? params.collageTopSkn : "")
.setIn(['groupListParams', 'sort'], params.sort ? params.sort : '')
.setIn(['groupListParams', 'gender'], params.gender ? params.gender : '')
.setIn(['groupListParams', 'order'], params.order ? params.order : '')
.setIn(['groupListParams', 'p_d'], params.p_d ? params.p_d : '')
.setIn(['groupListParams', 'color'], params.color ? params.color : '')
.setIn(['groupListParams', 'brand'], params.brand ? params.brand : '')
.setIn(['groupListParams', 'price'], params.price ? params.price : '')
.setIn(['groupListParams', 'g_size'], params.size ? params.size : '')
.setIn(['groupListParams', 'msort'], params.msort ? params.msort : '')
.setIn(['groupListParams', 'misort'], params.misort ? params.misort : '')
.setIn(['groupListParams', 'age_level'], params.age_level ? params.age_level : '')
.setIn(['groupListParams', 'style'], params.style ? params.style : '')
.setIn(['groupListParams', 'from'], params.from ? params.from : '')
.setIn(['groupListParams', 'showType'], params.showType ? params.showType : '');
}
case PRODUCT_LIST_REQUEST: {
return state.setIn(['productList', 'isFetching'], true)
.setIn(['productList', 'error'], null);
... ...
... ... @@ -13,11 +13,33 @@ export default class groupPurchaseService {
this.api = new Request(baseURL);
}
async fetchProductList(activityId,page=1, limit=20,fromPage) {
async fetchGroupProductList(activityId, page=1, limit=20, fromPage, listParams) {
return await this.api.get({
url: '',
body: {
method: 'app.collage.productList.page',
...listParams,
page,
limit,
activityId,
fromPage,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async fetchGroupDetailProductList(activityId,page=1, limit=20,fromPage) {
return await this.api.get({
url: '',
body: {
method: 'app.collage.productList.detail',
page,
limit,
activityId,
... ...