import React from 'react' import Util from '../../../util/utils' const marketType = Util.marketType(); /*倒计时模板*/ class ShopTimer extends React.Component { constructor(props) { super(props); this.calcNum = this.calcNum.bind(this); this.calcTimer = this.calcTimer.bind(this); this.state = { vars: ['name', 'join', 'tip', 'time'], id: 'timer' + new Date().getTime() + Math.random() * 10000, remainTime: null } } componentDidMount(): void { let data = this.props.data; if (data.remainTime) { this.calcTimer(data.remainTime); this.setState({ remainTime: data.remainTime }) } } componentWillReceiveProps(nextProps: Readonly, nextContext: any): void { if (nextProps.data.remainTime != this.state.remainTime) { this.setState({ remainTime: nextProps.data.remainTime, // id: 'timer' + new Date().getTime() + Math.random() * 10000, }); this.calcTimer(nextProps.data.remainTime); } } lookMore() { this.props.lookMore(); } calcTimer(remainTime) { console.log(remainTime) Util.calcTimerNew(remainTime, this.state.id) } calcNum(num) { let numNum = Util.calcNum(num); return numNum; } render() { let data = this.props.data; let vars = data.vars ? data.vars : this.state.vars; let className = 'shop-small-timer-wrapper'; let timerType = data.timerType; if (timerType == 'big') { className = 'shop-big-timer-wrapper'; } if (data.limitTime == 1) { return (
{/*商品类型*/} { vars.indexOf('name') != -1 ? 拼团 : '' } {/*拼团商品类型后面跟的文字,如:5人团*/} { timerType == 'big' && data.cptCode == 9200 ? ({data.groupBuyNum}人团) : '' } {/*参与人数*/} { data.showPartNum == 1 && vars.indexOf('join') != -1 ? timerType == 'big' ? 已参与{this.calcNum(data.partNum)}人 : {this.calcNum(data.partNum)}人 : '' } {/*倒计时*/} { data.limitTime == 1 ? {/*倒计时提示语*/} { vars.indexOf('tip') != -1 ? {data.tipText ? data.tipText : '距活动结束仅剩'} : '' } {/*倒计时*/} { vars.indexOf('time') != -1 ? 00: 00: 00: 0 : '' } : '' }
); } else { return null; } } } export default ShopTimer;