diff --git a/App.js b/App.js index 0d351af..6123477 100644 --- a/App.js +++ b/App.js @@ -17,9 +17,9 @@ import DeviceInfo from "react-native-device-info"; import * as Animatable from 'react-native-animatable'; contentItemDefault = { - coverImg:'', qrcode:[], target:{ + coverImg:'', title:'', subTitle:'', priceStr:'', @@ -34,6 +34,8 @@ baseInfoDefault = { imgQrcodeWemp:'' } +curAdIndex = 0; + export default class MyPage extends Component { constructor(props) { @@ -41,9 +43,9 @@ export default class MyPage extends Component { this.state = { baseInfo: baseInfoDefault, adDataList:[], - contentItem1:contentItemDefault, - contentItem2:contentItemDefault, - contentItem3:contentItemDefault, + contentItem0:null, + contentItem1:null, + contentItem2:null, contentDisplayStatus:true, @@ -96,14 +98,31 @@ codePushStatusDidChange(syncStatus) { this.setState({ progress }); } + updateContent() { + if (curAdIndex >= this.state.adDataList.length) { + curAdIndex = 0 + } + + this.setState({contentItem0:this.state.adDataList[curAdIndex]}); + + if (curAdIndex + 1 < this.state.adDataList.length) + this.setState({contentItem1:this.state.adDataList[curAdIndex+1]}); + else + this.setState({contentItem1:null}); + + if (curAdIndex + 2 < this.state.adDataList.length) + this.setState({contentItem2:this.state.adDataList[curAdIndex+2]}); + else + this.setState({contentItem2:null}); + + curAdIndex+=3 + } + getAdDataList() { - HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/list?deviceId=11%3AAA%3A33%3ABB%3A44&pageNum=1&pageSize=5') + HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/list?deviceId=11%3AAA%3A33%3ABB%3A44&pageNum=1&pageSize=30') .then(result => { - this.setState({ - adDataList : result.data.list}); - if (this.state.adDataList.length > 0) - this.setState({ - contentItem1 : this.state.adDataList[0]}); + this.setState({adDataList : result.data.list}); + this.updateContent(); }) .catch(error => console.error(error)) } @@ -139,13 +158,96 @@ componentDidMount() { setInterval( ()=>{ this.setState({ contentDisplayStatus: false}) - + this.updateContent(); this.setState({ contentDisplayStatus: true}) }, - 5000, + 1000 * 10, //10秒更新一下页面 + ); + setInterval( + ()=>{ + this.setState({ contentDisplayStatus: false}) + this.updateContent(); + this.setState({ contentDisplayStatus: true}) + }, + 1000*60*60, //1小时一次 ); } +getContentViewItemUplayer(contentItem) { + if (contentItem.target.type == 8) + return ( ) + else if (contentItem.target.type == 9) + return ( ) +} + +getContentViewItem(contentItem, annomation) { + if (!contentItem) + return ( + + + ) + actionText = '扫码领取'; + + if (contentItem.target.type == 8) + actionText = '扫码砍价'; + else if (contentItem.target.type == 9) + actionText = '扫码拼团'; + + merchantName = ""; + if (contentItem.target.merchantVoList.length > 1) + merchantName = '多商户通用'; + else + merchantName = contentItem.target.merchantVoList[0].merchantName; + + return ( + + + + + + + + {contentItem.target.title} + {contentItem.target.remark} + + + {contentItem.target.priceStr} + + + + {contentItem.target.salePriceStr}元 + + + + + + + + {merchantName} + + {actionText} + + + + + {this.getContentViewItemUplayer(contentItem)} + + + ) +} + +getContentView() { + if (this.state.contentDisplayStatus) { + return ( + {this.getContentViewItem(this.state.contentItem0,"slideInDown")} + {this.getContentViewItem(this.state.contentItem1,"slideInLeft")} + {this.getContentViewItem(this.state.contentItem2,"slideInRight")} + ) + }else{ + return ( + ) + } +} render() { @@ -164,112 +266,6 @@ render() { ); } - if (this.state.contentDisplayStatus) { - var content = ( - - - - - - - - - {this.state.contentItem1.target.title} - {this.state.contentItem1.target.remark} - - - {this.state.contentItem1.target.priceStr} - - - - {this.state.contentItem1.target.salePriceStr}元 - - - - - - - - 肯德基 - - 扫码领取 - - - - - - - - - - - - - - - - {this.state.contentItem1.target.title} - {this.state.contentItem1.target.remark} - - - {this.state.contentItem1.target.priceStr} - - - - {this.state.contentItem1.target.salePriceStr}元 - - - - - - - - - 肯德基 - - 扫码领取 - - - - - - - - - - - - - - {this.state.contentItem1.target.title} - {this.state.contentItem1.target.remark} - - - {this.state.contentItem1.target.priceStr} - - - - {this.state.contentItem1.target.salePriceStr}元 - - - - - - - - - 肯德基 - - 扫码领取 - - - - - - ) - }else{ - var content = - } return ( @@ -279,28 +275,33 @@ render() { - + - {content} + {this.getContentView()} - - + + + 小程序 + + + + 公众号 + {this.state.versionInfo} - ); - - } + ); + } } const styles = StyleSheet.create({ @@ -390,8 +391,8 @@ render() { bottomLogoBackground: { flex: 3, borderRadius:10, - marginTop: 12, - marginBottom: 12, + marginTop: 10, + marginBottom: 10, backgroundColor:'white' }, bottomLogo: { @@ -400,20 +401,60 @@ render() { borderRadius:10, backgroundColor:'transparent' }, - bottomQrcode1: { + bottomQrcode1Background : { flex: 1, width:'100%', height:'100%', marginLeft: 8, + paddingTop: 10, + paddingBottom: 4, + flexDirection: 'column', backgroundColor:'transparent' }, - bottomQrcode2: { + + bottomQrcode2Background : { flex: 1, width:'100%', height:'100%', marginLeft: 8, + paddingTop: 10, + paddingBottom: 4, + flexDirection: 'column', + backgroundColor:'transparent' + }, + + bottomQrcode1: { + flex: 2, + width:'100%', + height:'100%', backgroundColor:'transparent' }, + + bottomQrcode2: { + flex: 2, + width:'100%', + height:'100%', + backgroundColor:'transparent' + }, + + bottomQrcode1Str: { + flex: 1, + textAlign :'center', + textAlignVertical:'center', + fontSize: 6, + color : 'black', + backgroundColor:'transparent' + }, + + bottomQrcode2Str: { + flex: 1, + textAlign :'center', + textAlignVertical:'center', + fontSize: 6, + color : 'black', + backgroundColor:'transparent' + }, + bottomPlacehold: { flex: 8, width:'100%', @@ -482,6 +523,7 @@ render() { borderRadius:10, backgroundColor:'transparent' }, + contentItemTopDetail:{ flex: 6, width:'100%', @@ -491,6 +533,7 @@ render() { alignItems: 'center', backgroundColor:'transparent' }, + contentItemTopQrcode:{ flex: 5, width:'100%', diff --git a/image/groupbuy.png b/image/groupbuy.png new file mode 100644 index 0000000..c1e689e Binary files /dev/null and b/image/groupbuy.png differ