Authored by 张丽霞

秒杀模块商品列表本地存储,倒计时间逻辑,review by redding

... ... @@ -28,6 +28,11 @@ import {
} from './reducers/app/appActions';
import {
setStartTime,
} from './reducers/seckill/seckillActions';
import {
setContentCode,
setHost,
} from './reducers/seckill/seckillActions';
... ... @@ -50,8 +55,8 @@ export default function native(platform) {
let url = this.props.url;
if (url) {
let queryUrl = queryString.parse(url);
if (queryUrl.startTime) {
store.dispatch(setStartTime(queryUrl.startTime));
if (queryUrl.time) {
store.dispatch(setStartTime(queryUrl.time));
}
}
if(this.props.contentCode){
... ...
... ... @@ -30,7 +30,6 @@ export default class ProductListView extends Component {
}
_renderRow(rowData, sectionID, rowID) {
rowData = rowData.toJS();
let brandIconUrl = SlicedImage.getSlicedUrl(rowData.defaultImages, 152, 203, 2);
let tipState='';
let btnBgColor = '#d30018';
... ...
... ... @@ -50,8 +50,10 @@ export default class Seckill extends Component {
}
componentWillReceiveProps(nextProps) {
if (nextProps.addCancelUserReminderTip && nextProps.addCancelUserReminderTip !== '') {
this._showToast && this._showToast(nextProps.addCancelUserReminderTip);
console.log('componentWillReceiveProps');
console.log(nextProps);
if (nextProps.tipMessage && nextProps.tipMessage !== '') {
this._showToast && this._showToast(nextProps.tipMessage);
}
}
... ... @@ -66,7 +68,7 @@ export default class Seckill extends Component {
this._toast.hide({
duration: 0,
animationEnd: () => {
this.props.onClearRemindTip && this.props.onClearRemindTip();
this.props.onClearTipMessage && this.props.onClearTipMessage();
}
})
},
... ... @@ -125,17 +127,24 @@ export default class Seckill extends Component {
error,
queryActivityInfo,
queryProductList,
addCancelUserReminderTip,
tipMessage,
ptr,
} = this.props;
this.isFetching = isFetching;
this.queryActivityInfo = queryActivityInfo;
diff = Math.round((queryActivityInfo.currentTime - Date.now()) / 1000);
let dataSource = {
ActivityProductList: [queryProductList.toArray()],
ActivityProductList: [queryProductList ? queryProductList : []],
};
let isPullToRefresh = ptr && isFetching;
console.log('isPullToRefresh')
console.log(isPullToRefresh)
console.log('isFetching');
console.log(isFetching);
console.log('ptr');
console.log(ptr);
return (
<View style={styles.container}>
{
... ... @@ -151,9 +160,6 @@ export default class Seckill extends Component {
isOnPullToRefresh={isPullToRefresh}
onRefreshData={() => {
//强制刷新数据
if (isFetching) {
return;
}
this.props.onRefresh && this.props.onRefresh();
}}
renderSectionHeader={this.renderSectionHeader}
... ... @@ -175,9 +181,6 @@ export default class Seckill extends Component {
refreshing={false}
onRefresh={() => {
//强制刷新数据
if (isFetching) {
return;
}
this.props.onRefresh && this.props.onRefresh();
}}
colors={['#000000', '#ff0000']}
... ... @@ -210,7 +213,7 @@ export default class Seckill extends Component {
}
<LoadingIndicator
isVisible={isFetching}
isVisible={isFetching && !ptr}
/>
<Toast
... ...
... ... @@ -28,6 +28,7 @@ export default class SeckillTimeListView extends Component {
});
this.curFocusActivity = Immutable.fromJS({});
this.secKillProductVoList = Immutable.fromJS([]);
this.curFocusIndex = 0;
this.state = {
tickHour: '00',
tickMinute: '00',
... ... @@ -56,8 +57,19 @@ export default class SeckillTimeListView extends Component {
}
_caculateTimerState() {
if (this.curFocusIndex == this.secKillProductVoList.length - 1 && this.curFocusActivity.has('now')) {
if (!this.state.tickTimeOut) {
this.setState({
tickHour: '',
tickMinute: '',
tickSecond: '',
tickTimeOut: true,
});
}
} else {
let nextActivity = this.secKillProductVoList[this.curFocusIndex + 1];
let nowTime = Date.parse(new Date()) / 1000 + diffTime;
let time = this.curFocusActivity.has('now') ? this.curFocusActivity.get('endTime'): this.curFocusActivity.get('startTime') / 1000;
let time = this.curFocusActivity.has('now') ? nextActivity.get('startTime')/1000: this.curFocusActivity.get('startTime') / 1000;
let offsetTime = time - nowTime;
let hour = parseInt(offsetTime / (60 * 60), 10);
let minute = parseInt(offsetTime % (60 * 60) / 60, 10);
... ... @@ -82,10 +94,17 @@ export default class SeckillTimeListView extends Component {
}
}
}
componentDidMount() {
if (this.secKillProductVoList && this.secKillProductVoList.length > 0) {
this.curFocusActivity = this.secKillProductVoList.find(activityTimeItem => activityTimeItem.get('focus'));
this.secKillProductVoList.forEach((activityItem, i) => {
if (activityItem.get('focus')) {
this.curFocusIndex = i;
this.curFocusActivity = activityItem;
}
});
}
let jumpToTimeoutActivity = () => {
... ... @@ -94,6 +113,9 @@ export default class SeckillTimeListView extends Component {
let startTime = activityItem.get('startTime') / 1000;
let offsetTime = nowTime - startTime;
if (activityItem.get('focus') == false && Math.abs(offsetTime) <= 2) {
this.curFocusActivity= activityItem;
this.curFocusIndex = i;
this._scrollToFocusActivity();
this.props.onFocusToCurStartedActivity && this.props.onFocusToCurStartedActivity(activityItem.toJS());
}
});
... ... @@ -117,9 +139,13 @@ export default class SeckillTimeListView extends Component {
componentWillReceiveProps(nextProps) {
if (nextProps.resource && nextProps.resource.length > 0) {
this.curFocusActivity = nextProps.resource.find(activityTimeItem => activityTimeItem.get('focus'));
nextProps.resource.forEach((activityItem, i) => {
if (activityItem.get('focus')) {
this.curFocusIndex = i;
this.curFocusActivity = activityItem;
}
});
}
this._scrollToFocusActivity();
this._caculateTimerState();
}
... ... @@ -134,6 +160,8 @@ export default class SeckillTimeListView extends Component {
}
rowData.focus = true;
this.curFocusActivity = Immutable.fromJS(rowData);//rowData;
this._scrollToFocusActivity();
this.props.onPressTimeItem && this.props.onPressTimeItem(rowData);
}}>
{rowData.focus ?
... ...
... ... @@ -21,10 +21,8 @@ export default keyMirror({
QUERY_PRODUCT_AND_REMIND_LIST_SUCCESS: null,
QUERY_PRODUCT_AND_REMIND_LIST_FAILURE: null,
ADD_CANCEL_USER_REMINDER_REQUEST: null,
ADD_CANCEL_USER_REMINDER_SUCCESS: null,
ADD_CANCEL_USER_REMINDER_FAILURE: null,
ADD_CANCEL_USER_REMINDER_CLEAR_TIP: null,
SHOW_TIP_MESSAGE: null,
CLEAR_TIP_MESSAGE: null,
UPDATE_SECKILL_PRODUCT_VO_LIST: null,
UPDATE_SECKILL_PRODUCT_LIST: null,
... ...
... ... @@ -11,7 +11,7 @@ import {
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import Immutable, {Map} from 'immutable';
import * as seckillActions from '../reducers/seckill/seckillActions';
import Seckill from '../components/seckill/Seckill';
... ... @@ -45,16 +45,14 @@ class SeckillContainer extends Component {
this._onPressProductItem = this._onPressProductItem.bind(this);
this._onPressRemindBtn = this._onPressRemindBtn.bind(this);
this._onRefresh = this._onRefresh.bind(this);
this._onClearRemindTip = this._onClearRemindTip.bind(this);
this._onClearTipMessage = this._onClearTipMessage.bind(this);
this._onFocusToCurStartedActivity = this._onFocusToCurStartedActivity.bind(this);
}
componentDidMount() {
this.props.actions.getSeckillQueryActivity();
this.curActivityId = 0;
}
_onPressTimeItem(activity) {
this.props.actions.clickActivityTimeItem(activity);
this.curActivityId = activity.activityId;
}
_onPressProductItem(product) {
... ... @@ -69,11 +67,12 @@ class SeckillContainer extends Component {
this.props.actions.refreshList();
}
_onClearRemindTip() {
this.props.actions.addCancelUserReminderClearTip();
_onClearTipMessage() {
this.props.actions.clearTipMessage();
}
_onFocusToCurStartedActivity(activity) {
this.curActivityId = activity.activityId;
this.props.actions.getSeckillQueryActivity(activity.startTime / 1000);
}
... ... @@ -85,9 +84,14 @@ class SeckillContainer extends Component {
queryActivityInfo,
queryProductList,
queryRemindList,
addCancelUserReminderTip,
tipMessage,
ptr,
curActivityId,
} = this.props.seckill;
if (queryProductList) {
queryProductList = queryProductList.toJS();
}
let productList = queryProductList[curActivityId];
return (
<Seckill
... ... @@ -95,14 +99,14 @@ class SeckillContainer extends Component {
error = {error}
ptr = {ptr}
queryActivityInfo = {queryActivityInfo}
queryProductList = {queryProductList}
queryProductList = {productList}
queryRemindList = {queryRemindList}
addCancelUserReminderTip = {addCancelUserReminderTip}
tipMessage = {tipMessage}
onPressTimeItem={this._onPressTimeItem}
onPressProductItem={this._onPressProductItem}
onPressRemindBtn={this._onPressRemindBtn}
onRefresh={this._onRefresh}
onClearRemindTip={this._onClearRemindTip}
onClearTipMessage={this._onClearTipMessage}
onFocusToCurStartedActivity={this._onFocusToCurStartedActivity}
/>
);
... ... @@ -115,5 +119,4 @@ let styles = StyleSheet.create({
},
});
export default connect(mapStateToProps, mapDispatchToProps)(SeckillContainer);
... ...
... ... @@ -22,16 +22,13 @@ const {
QUERY_PRODUCT_AND_REMIND_LIST_SUCCESS,
QUERY_PRODUCT_AND_REMIND_LIST_FAILURE,
ADD_CANCEL_USER_REMINDER_REQUEST,
ADD_CANCEL_USER_REMINDER_SUCCESS,
ADD_CANCEL_USER_REMINDER_FAILURE,
ADD_CANCEL_USER_REMINDER_CLEAR_TIP,
SHOW_TIP_MESSAGE,
CLEAR_TIP_MESSAGE,
UPDATE_SECKILL_PRODUCT_VO_LIST,
UPDATE_SECKILL_PRODUCT_LIST,
} = require('../../constants/actionTypes').default;
let curActivityId = 0;
/**
* [时间缺0补0]
*/
... ... @@ -66,9 +63,10 @@ export function queryActivityFailure(error) {
};
}
export function queryProductListRequest() {
export function queryProductListRequest(activityId) {
return {
type: QUERY_PRODUCT_LIST_REQUEST
type: QUERY_PRODUCT_LIST_REQUEST,
payload: activityId
}
}
... ... @@ -86,9 +84,10 @@ export function queryProductListFailure(error) {
}
}
export function queryProductAndRemindListRequest() {
export function queryProductAndRemindListRequest(activityId) {
return {
type: QUERY_PRODUCT_AND_REMIND_LIST_REQUEST
type: QUERY_PRODUCT_AND_REMIND_LIST_REQUEST,
payload: activityId
}
}
... ... @@ -106,29 +105,16 @@ export function queryProductAndRemindListFailure(error) {
}
}
export function addCancelUserReminderRequest() {
export function showTipMessage(message) {
return {
type: ADD_CANCEL_USER_REMINDER_REQUEST
}
}
export function addCancelUserReminderSuccess(message) {
return {
type: ADD_CANCEL_USER_REMINDER_SUCCESS,
payload: message
}
}
export function addCancelUserReminderFailure(message) {
return {
type: ADD_CANCEL_USER_REMINDER_FAILURE,
type: SHOW_TIP_MESSAGE,
payload: message
}
}
export function addCancelUserReminderClearTip() {
export function clearTipMessage() {
return {
type:ADD_CANCEL_USER_REMINDER_CLEAR_TIP,
type:CLEAR_TIP_MESSAGE,
}
}
... ... @@ -147,7 +133,10 @@ export function updateSecKillProductList(json) {
}
export function setStartTime(startTime) {
console.log('---startTime----');
console.log(startTime);
startTime = moment(startTime, 'YYYYMMDDHHmmss').unix();
console.log(startTime);
return {
type: SET_START_TIME,
payload: startTime,
... ... @@ -157,8 +146,15 @@ export function setStartTime(startTime) {
* 秒杀时间栏
*/
export function getSeckillQueryActivity(inStartTime = 0) {
console.log('00000000');
return (dispatch, getState) => {
let {app, seckill, startTime} = getState();
let {app, seckill} = getState();
let {startTime} = seckill;
console.log('aaaaa----aaaaa');
if (seckill.isFetching || seckill.tipMessage) {
return;
}
console.log('kkk---kkkk');
if (inStartTime) {
startTime = inStartTime;
}
... ... @@ -169,18 +165,19 @@ export function getSeckillQueryActivity(inStartTime = 0) {
let processedTimeInfo = parseActivityTimeLsit(json, startTime);
dispatch(queryActivitySuccess(processedTimeInfo.newQueryActivityInfo));
let focusActivity = processedTimeInfo.focusActivity;
curActivityId = focusActivity.activityId;
if (Date.now() < focusActivity.startTime) {
dispatch(getSeckillProductRemindList(curActivityId));
dispatch(getSeckillProductRemindList(focusActivity.activityId));
} else {
dispatch(getSeckillProductList(curActivityId));
dispatch(getSeckillProductList(focusActivity.activityId));
}
} else {
dispatch(queryActivityFailure({error:'来晚啦~秒杀已结束'}));
}
})
.catch(error => {
console.log('queryActivityFailure');
dispatch(queryActivityFailure(error));
dispatch(showTipMessage(error.message));
});
};
}
... ... @@ -188,12 +185,14 @@ export function getSeckillQueryActivity(inStartTime = 0) {
/*
* 秒杀商品列表
*/
export function getSeckillProductList(activityId = curActivityId) {
curActivityId = activityId;
export function getSeckillProductList(activityId = 0) {
return (dispatch, getState) => {
dispatch(queryProductListRequest());
let {app, seckill} = getState();
let {queryRemindList} = seckill;
let {queryRemindList, queryProductList, curActivityId} = seckill;
if (!activityId) {
activityId = curActivityId;
}
dispatch(queryProductListRequest(activityId));
queryRemindList = queryRemindList.toJS();
return new SeckillService(app.host).fetchQueryProductList(activityId)
.then(json => {
... ... @@ -203,7 +202,13 @@ export function getSeckillProductList(activityId = curActivityId) {
} else {
productList = productAddFlag(json);
}
dispatch(queryProductListSuccess(productList));
queryProductList = queryProductList.toJS();
console.log(queryProductList);
queryProductList[activityId] = productList;
console.log('-----------');
console.log(productList);
console.log(queryProductList);
dispatch(queryProductListSuccess(queryProductList));
})
.catch(error => {
dispatch(queryProductListFailure(error));
... ... @@ -214,11 +219,10 @@ export function getSeckillProductList(activityId = curActivityId) {
/*
* 秒杀商品列表
*/
export function getSeckillProductRemindList(activityId = curActivityId) {
curActivityId = activityId;
export function getSeckillProductRemindList(activityId = 0) {
return (dispatch, getState) => {
let queryProductRemindList = (activityId, uid) => {
dispatch(queryProductAndRemindListRequest());
dispatch(queryProductAndRemindListRequest(activityId));
let {app, seckill} = getState();
let {queryProductList} = seckill;
Promise.all([
... ... @@ -228,7 +232,16 @@ export function getSeckillProductRemindList(activityId = curActivityId) {
let productList = result[0];
let remindList = result[1];
productList = productAddFlag(productList, remindList);
dispatch(queryProductAndRemindListSuccess({productList,remindList}));
console.log('1111111111111');
console.log(queryProductList);
console.log(activityId);
console.log(productList);
queryProductList = queryProductList.toJS();
queryProductList[activityId] = productList;
console.log('7777777777');
console.log(queryProductList);
dispatch(queryProductAndRemindListSuccess({queryProductList,remindList}));
})
.catch(error => {
... ... @@ -249,8 +262,8 @@ export function getSeckillProductRemindList(activityId = curActivityId) {
export function addCancelUserReminder(method='app.seckill.addUserReminder', activityId=0, productSkn=0, uid=0, secKillId=0, okTip='', failTip='') {
return (dispatch, getState) => {
let {app, seckill} = getState();
let {queryProductList} = seckill;
dispatch(addCancelUserReminderRequest());
let {queryProductList, curActivityId} = seckill;
dispatch(clearTipMessage());
return new SeckillService(app.host).addCancelUserReminder(method,activityId,productSkn,uid,secKillId)
.then(json => {
//更新提醒状态
... ... @@ -262,23 +275,25 @@ export function addCancelUserReminder(method='app.seckill.addUserReminder', acti
}
queryProductList = queryProductList.toJS();
let curActivity = {};
queryProductList.forEach((productItem, i) => {
queryProductList[curActivityId].forEach((productItem, i) => {
if (productItem.id === secKillId) {
productItem.remindFlag = remindFlag;
}
});
dispatch(addCancelUserReminderSuccess(okTip));
dispatch(showTipMessage(okTip));
dispatch(updateSecKillProductList(queryProductList));
})
.catch(error => {
dispatch(addCancelUserReminderFailure(failTip));
dispatch(showTipMessage(failTip));
});
};
}
export function clickActivityTimeItem(activity) {
curActivityId = activity.activityId;
console.log('----5');
console.log(activity);
let curActivityId = activity.activityId;
return (dispatch, getState) => {
let {app, seckill} = getState();
let {queryActivityInfo} = seckill;
... ... @@ -292,7 +307,8 @@ export function clickActivityTimeItem(activity) {
activityTimeItem.focus = false;
}
});
dispatch(updateSecKillProductVoList(queryActivityInfo.secKillProductVoList));
let secKillProductVoList = queryActivityInfo.secKillProductVoList;
dispatch(updateSecKillProductVoList({secKillProductVoList, curActivityId}));
if (Date.now() < curActivity.startTime) {
dispatch(getSeckillProductRemindList(curActivityId));
} else {
... ... @@ -376,7 +392,7 @@ export function clickRemindBtn(product) {
dispatch(addCancelUserReminder(method, product.activityId, skn,uid, product.id, okTip, failTip));
})
.catch(error => {
dispatch(addCancelUserReminderFailure(error));
dispatch(showTipMessage(error));
});
};
... ... @@ -386,8 +402,10 @@ export function clickRemindBtn(product) {
export function refreshList() {
return (dispatch, getState) => {
let {app, seckill} = getState();
let {queryActivityInfo,queryProductList} = seckill;
let {queryActivityInfo,queryProductList,curActivityId} = seckill;
console.log('------refreshList');
console.log('------55');
console.log(curActivityId);
if (curActivityId !== 0 && queryActivityInfo.secKillProductVoList) {
queryActivityInfo.secKillProductVoList.forEach((activityInfo, i) => {
if (activityInfo.get('activityId') === curActivityId) {
... ...
... ... @@ -13,10 +13,11 @@ let InitialState = Record({
currentTime: 0,
secKillProductVoList: List(),
})),
queryProductList: List(),
curActivityId: 0,
queryProductList: Map(),
queryRemindList: List(),
addCancelUserReminderTip: '',
tipMessage: '',
});
export default InitialState;
... ...
... ... @@ -18,10 +18,8 @@ const {
QUERY_PRODUCT_AND_REMIND_LIST_SUCCESS,
QUERY_PRODUCT_AND_REMIND_LIST_FAILURE,
ADD_CANCEL_USER_REMINDER_REQUEST,
ADD_CANCEL_USER_REMINDER_SUCCESS,
ADD_CANCEL_USER_REMINDER_FAILURE,
ADD_CANCEL_USER_REMINDER_CLEAR_TIP,
SHOW_TIP_MESSAGE,
CLEAR_TIP_MESSAGE,
UPDATE_SECKILL_PRODUCT_VO_LIST,
UPDATE_SECKILL_PRODUCT_LIST,
... ... @@ -59,7 +57,7 @@ export default function seckillReducer(state=initialState, action) {
}
case QUERY_PRODUCT_LIST_REQUEST: {
return state.set('isFetching', true)
.set('queryProductList',Immutable.fromJS([]))
.set('curActivityId', action.payload)
.set('error', null);
}
case QUERY_PRODUCT_LIST_SUCCESS: {
... ... @@ -73,13 +71,12 @@ export default function seckillReducer(state=initialState, action) {
}
case QUERY_PRODUCT_AND_REMIND_LIST_REQUEST: {
return state.set('isFetching', true)
.set('queryProductList', Immutable.fromJS([]))
.set('queryRemindList', Immutable.fromJS([]))
.set('curActivityId', action.payload)
.set('error', null);
}
case QUERY_PRODUCT_AND_REMIND_LIST_SUCCESS: {
return state.set('isFetching', false)
.set('queryProductList', Immutable.fromJS(action.payload.productList))
.set('queryProductList', Immutable.fromJS(action.payload.queryProductList))
.set('queryRemindList', Immutable.fromJS(action.payload.remindList))
.set('error', null);
}
... ... @@ -87,20 +84,18 @@ export default function seckillReducer(state=initialState, action) {
return state.set('isFetching', false)
.set('error', action.payload);
}
case ADD_CANCEL_USER_REMINDER_REQUEST: {
return state.set('addCancelUserReminderTip', '');
case CLEAR_TIP_MESSAGE: {
return state.set('tipMessage', '');
}
case ADD_CANCEL_USER_REMINDER_SUCCESS: {
return state.set('addCancelUserReminderTip', Immutable.fromJS(action.payload));
case SHOW_TIP_MESSAGE: {
return state.set('tipMessage', Immutable.fromJS(action.payload));
}
case ADD_CANCEL_USER_REMINDER_FAILURE: {
return state.set('addCancelUserReminderTip', Immutable.fromJS(action.payload));
}
case ADD_CANCEL_USER_REMINDER_CLEAR_TIP: {
return state.set('addCancelUserReminderTip', '');
case CLEAR_TIP_MESSAGE: {
return state.set('tipMessage', '');
}
case UPDATE_SECKILL_PRODUCT_VO_LIST: {
return state.setIn(['queryActivityInfo', 'secKillProductVoList'], Immutable.fromJS(action.payload))
return state.setIn(['queryActivityInfo', 'secKillProductVoList'], Immutable.fromJS(action.payload.secKillProductVoList))
.set('curActivityId', Immutable.fromJS(action.payload.curActivityId))
.set('error', null);
}
case UPDATE_SECKILL_PRODUCT_LIST: {
... ...