...
|
...
|
@@ -21,6 +21,7 @@ export default class SeckillTimeListView extends Component { |
|
|
this._renderRow = this._renderRow.bind(this);
|
|
|
this._renderSeparator = this._renderSeparator.bind(this);
|
|
|
this._scrollToFocusActivity = this._scrollToFocusActivity.bind(this);
|
|
|
this._caculateTimerState = this._caculateTimerState.bind(this);
|
|
|
|
|
|
this.dataSource = new ListView.DataSource({
|
|
|
rowHasChanged: (r1, r2) => r1.key != r2.key,
|
...
|
...
|
@@ -28,7 +29,6 @@ export default class SeckillTimeListView extends Component { |
|
|
this.curFocusActivity = Immutable.fromJS({});
|
|
|
this.secKillProductVoList = Immutable.fromJS([]);
|
|
|
this.state = {
|
|
|
selectedIndex: 0,
|
|
|
tickHour: '00',
|
|
|
tickMinute: '00',
|
|
|
tickSecond: '00',
|
...
|
...
|
@@ -55,8 +55,39 @@ export default class SeckillTimeListView extends Component { |
|
|
}
|
|
|
}
|
|
|
|
|
|
_caculateTimerState() {
|
|
|
let nowTime = Date.parse(new Date()) / 1000 + diffTime;
|
|
|
let time = this.curFocusActivity.has('now') ? this.curFocusActivity.get('endTime'): this.curFocusActivity.get('startTime') / 1000;
|
|
|
let offsetTime = time - nowTime;
|
|
|
let hour = parseInt(offsetTime / (60 * 60), 10);
|
|
|
let minute = parseInt(offsetTime % (60 * 60) / 60, 10);
|
|
|
let second = offsetTime % 60;
|
|
|
|
|
|
if (offsetTime <= 0) {
|
|
|
if (!this.state.tickTimeOut) {
|
|
|
this.setState({
|
|
|
tickHour: '',
|
|
|
tickMinute: '',
|
|
|
tickSecond: '',
|
|
|
tickTimeOut: true,
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
this.setState({
|
|
|
tickHour: hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : (hour > 99 ? 99 : hour)),
|
|
|
tickMinute: minute < 0 ? '00' : (minute < 10 ? ('0' + minute) : minute),
|
|
|
tickSecond: second < 0 ? '00' : (second < 10 ? ('0' + second) : second),
|
|
|
tickTimeOut: false,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
|
if (this.secKillProductVoList && this.secKillProductVoList.length > 0) {
|
|
|
this.curFocusActivity = this.secKillProductVoList.find(activityTimeItem => activityTimeItem.get('focus'));
|
|
|
}
|
|
|
|
|
|
let jumpToTimeoutActivity = () => {
|
|
|
this.secKillProductVoList.forEach((activityItem, i) => {
|
|
|
let nowTime = Date.parse(new Date()) / 1000 + diffTime;
|
...
|
...
|
@@ -73,31 +104,7 @@ export default class SeckillTimeListView extends Component { |
|
|
return;
|
|
|
}
|
|
|
jumpToTimeoutActivity();
|
|
|
let nowTime = Date.parse(new Date()) / 1000 + diffTime;
|
|
|
let time = this.curFocusActivity.has('now') ? this.curFocusActivity.get('endTime'): this.curFocusActivity.get('startTime') / 1000;
|
|
|
let offsetTime = time - nowTime;
|
|
|
let hour = parseInt(offsetTime / (60 * 60), 10);
|
|
|
let minute = parseInt(offsetTime % (60 * 60) / 60, 10);
|
|
|
let second = offsetTime % 60;
|
|
|
|
|
|
if (offsetTime <= 0) {
|
|
|
if (!this.state.tickTimeOut) {
|
|
|
this.props.onFocusToCurStartedActivity && this.props.onFocusToCurStartedActivity(this.curFocusActivity.toJS());
|
|
|
}
|
|
|
this.setState({
|
|
|
tickHour: '00',
|
|
|
tickMinute: '00',
|
|
|
tickSecond: '00',
|
|
|
tickTimeOut: true,
|
|
|
});
|
|
|
} else {
|
|
|
this.setState({
|
|
|
tickHour: hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : (hour > 99 ? 99 : hour)),
|
|
|
tickMinute: minute < 0 ? '00' : (minute < 10 ? ('0' + minute) : minute),
|
|
|
tickSecond: second < 0 ? '00' : (second < 10 ? ('0' + second) : second),
|
|
|
tickTimeOut: false,
|
|
|
});
|
|
|
}
|
|
|
this._caculateTimerState();
|
|
|
|
|
|
}.bind(this), 1000);
|
|
|
this._scrollToFocusActivity();
|
...
|
...
|
@@ -110,10 +117,10 @@ export default class SeckillTimeListView extends Component { |
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
if (nextProps.resource && nextProps.resource.length > 0) {
|
|
|
let focusActivity = nextProps.resource.find(activityTimeItem => activityTimeItem.get('focus'));
|
|
|
this.curFocusActivity = focusActivity;
|
|
|
this.curFocusActivity = nextProps.resource.find(activityTimeItem => activityTimeItem.get('focus'));
|
|
|
}
|
|
|
this._scrollToFocusActivity();
|
|
|
this._caculateTimerState();
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -198,10 +205,6 @@ export default class SeckillTimeListView extends Component { |
|
|
resource,
|
|
|
diff,
|
|
|
} = this.props;
|
|
|
if (resource && resource.length > 0) {
|
|
|
let focusActivity = resource.find(activityTimeItem => activityTimeItem.get('focus'));
|
|
|
this.curFocusActivity = focusActivity;
|
|
|
}
|
|
|
diffTime = diff;
|
|
|
this.secKillProductVoList = resource;
|
|
|
backgroundWidth = Math.max(rowContainerWidth * (resource.length - 1) + rowContainerFocusWidth, width);
|
...
|
...
|
|