...
|
...
|
@@ -4,9 +4,151 @@ import ReactNative from 'react-native'; |
|
|
import CouponService from '../../services/CouponService';
|
|
|
|
|
|
const {
|
|
|
COUPON_CENTER_REQUEST,
|
|
|
COUPON_CENTER_SUCCESS,
|
|
|
COUPON_CENTER_FAILURE,
|
|
|
JUMP_WITH_URL,
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
export function couponCenterRequest() {
|
|
|
return {
|
|
|
type: COUPON_CENTER_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function couponCenterSuccess(json) {
|
|
|
return {
|
|
|
type: COUPON_CENTER_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function couponCenterFailure(error) {
|
|
|
return {
|
|
|
type: COUPON_CENTER_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* index number 请求数据的index
|
|
|
* reload bool 是否需要强制重新请求数据,
|
|
|
*/
|
|
|
export function couponCenter(reload = false) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, coupon} = getState();
|
|
|
let {isFetching, floors, contentCode} = coupon;
|
|
|
if (reload) {
|
|
|
// 强制刷新数据
|
|
|
|
|
|
} else {
|
|
|
if (isFetching || floors.size > 0) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
let fetchCouponInfo = (contentCode, uid) => {
|
|
|
return new CouponService().fetchFloors(contentCode, uid)
|
|
|
.then(json => {
|
|
|
let payload = parseFloors(json);
|
|
|
dispatch(couponCenterSuccess(payload));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(couponCenterFailure(error));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
dispatch(couponCenterRequest());
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
fetchCouponInfo(contentCode, uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
fetchCouponInfo(contentCode, 0);
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function parseFloors(json) {
|
|
|
let carousel_banner = (data) => {
|
|
|
let images = [];
|
|
|
data && data.list && data.list.map((item, i) => {
|
|
|
let src = item.src ? item.src : '';
|
|
|
let url = item.url ? item.url : '';
|
|
|
images.push({src, url});
|
|
|
});
|
|
|
return images;
|
|
|
};
|
|
|
|
|
|
let focus = (data) => {
|
|
|
let images = [];
|
|
|
data && data.map((item, i) => {
|
|
|
let src = item.src ? item.src : '';
|
|
|
let url = item.url ? item.url : '';
|
|
|
images.push({src, url});
|
|
|
});
|
|
|
return images;
|
|
|
};
|
|
|
|
|
|
let text = (data) => {
|
|
|
let text = data && data.text ? data.text : '';
|
|
|
return text;
|
|
|
};
|
|
|
|
|
|
let single_image = (data) => {
|
|
|
let src = data && data[0] && data[0].src ? data[0].src : '';
|
|
|
let url = data && data[0] && data[0].url ? data[0].url : '';
|
|
|
return {src, url};
|
|
|
};
|
|
|
|
|
|
let getCoupon = (data) => {
|
|
|
let coupon = data && data[0] ? data[0] : {};
|
|
|
let text = coupon.text ? coupon.text : '';
|
|
|
let couponID = coupon.couponID ? coupon.couponID : '';
|
|
|
let image = {
|
|
|
src : coupon.image && coupon.image.src ? coupon.image.src : '',
|
|
|
url : coupon.image && coupon.image.url ? coupon.image.url : '',
|
|
|
};
|
|
|
let isShow = coupon.isShow;
|
|
|
let status = coupon.status;
|
|
|
return {
|
|
|
text,
|
|
|
couponID,
|
|
|
image,
|
|
|
isShow,
|
|
|
status,
|
|
|
};
|
|
|
};
|
|
|
|
|
|
let floors = [];
|
|
|
json && json.map((item, i) => {
|
|
|
let templateName = item.template_name;
|
|
|
if (!templateName) {
|
|
|
templateName = item.templateName;
|
|
|
}
|
|
|
|
|
|
let data;
|
|
|
if (templateName == 'carousel_banner') {
|
|
|
data = carousel_banner(item.data);
|
|
|
} else if (templateName == 'focus') {
|
|
|
data = focus(item.data)
|
|
|
} else if (templateName == 'text') {
|
|
|
data = text(item.data)
|
|
|
} else if (templateName == 'single_image') {
|
|
|
data = single_image(item.data)
|
|
|
} else if (templateName == 'getCoupon') {
|
|
|
data = getCoupon(item.data)
|
|
|
}
|
|
|
|
|
|
let floor = {
|
|
|
data,
|
|
|
templateName,
|
|
|
};
|
|
|
floors.push(floor);
|
|
|
});
|
|
|
|
|
|
return floors;
|
|
|
}
|
|
|
|
|
|
export function jumpWithUrl(url) {
|
|
|
if (!url) {
|
...
|
...
|
@@ -14,7 +156,7 @@ export function jumpWithUrl(url) { |
|
|
return;
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_PlustarHelper.jumpWithUrl(url);
|
|
|
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
|
|
|
return {
|
|
|
type: JUMP_WITH_URL,
|
|
|
payload: url
|
...
|
...
|
|