Skip to content

Commit 0e98e65

Browse files
author
suibingyue
committed
修改util
1 parent c271c3e commit 0e98e65

File tree

10 files changed

+484
-54
lines changed

10 files changed

+484
-54
lines changed

app/network/api.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
var API_ADDRESS = 'http://lsy.api.bqmart.cn';
2+
var API_ADDRESS = 'http://test.api.bqmart.cn';
33
// var API_ADDRESS='https://api.bqmart.cn';
44
var DEBUG = true;
55
// public static final String SERVERURL = "https://api.bqmart.cn";
@@ -9,13 +9,15 @@ var API = {
99
getSmsCode:function (type) {
1010
return API_ADDRESS+'/sms/sendcode'
1111
},
12+
HOST: API_ADDRESS,
1213
LOGIN: API_ADDRESS + '/login/verifiycode',
1314
CATEGORYLIST: API_ADDRESS + '/stores/assortment',
1415
GOODSLIST: API_ADDRESS + '/goods/goodslist',
1516
CARTLIST: API_ADDRESS + '/cart/cartlists',
1617
ADDRESSLIST: API_ADDRESS + '/user/address',
1718
ORDERLIST: API_ADDRESS + '/user/order',
1819
COUPONLIST: API_ADDRESS + '/coupon/lists',
19-
};
20+
GOODSDETAIL: API_ADDRESS + '/goods/goodsdetail',
21+
};
2022

2123
module.exports = API;

app/page/goodsdetail.js

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/**
2+
*
3+
* @authors Your Name ([email protected])
4+
* @date 2015-10-18 14:38:47
5+
* @version $Id$
6+
*/
7+
'use strict';
8+
var React = require('react-native');
9+
10+
11+
var Global = require('../util/global');
12+
var API = require('../network/api');
13+
var Util = require('../util/util');
14+
var Loading = require('./loading');
15+
var HTMLView = require('react-native-htmlview');
16+
17+
var {
18+
StyleSheet,
19+
View,
20+
Text,
21+
Image,
22+
TouchableHighlight,
23+
ScrollView,
24+
} = React;
25+
26+
var resultsCache = {
27+
dataForOrder: [],
28+
nextPageNumberForQuery: {},
29+
totalForQuery: {},
30+
pageIndex:1,
31+
};
32+
33+
var GoodsDetail = React.createClass({
34+
getInitialState: function() {
35+
return {
36+
goods:null,
37+
};
38+
},
39+
40+
componentDidMount: function() {
41+
var intent = this.props.intent;
42+
this.setState({
43+
goods: intent,
44+
});
45+
this._fetchGoods(intent.spec_id);
46+
},
47+
48+
_fetchGoods:function (spec_id) {
49+
50+
var thiz = this;
51+
Util.post(API.GOODSDETAIL,{'spec_id':spec_id},function (ret){
52+
if(ret.code==0){
53+
thiz.setState({
54+
goods: ret.data,
55+
});
56+
}else{
57+
alert(ret.msg);
58+
}
59+
});
60+
},
61+
render: function() {
62+
var goods = this.state.goods;
63+
if(!goods){
64+
return <Loading loadingtext='正在加载商品...'/>
65+
}
66+
var htmlContent = goods.description||"";
67+
return (
68+
<ScrollView>
69+
<View style={styles.container}>
70+
<Image
71+
style={{width:Util.size.width,height:490}}
72+
source={{uri: goods.default_image}}
73+
/>
74+
<Text style={[styles.textprimary,styles.paddingLeftRight,styles.marginTop10]}>商品名称:{goods.goods_name}</Text>
75+
<Text style={[styles.textPrice,styles.paddingLeftRight,styles.marginTop10]}>倍全价:{goods.shichang}</Text>
76+
<View style={[styles.line1,styles.marginTop10]}/>
77+
<Text style={[styles.textsecond,styles.paddingLeftRight,styles.marginTop10]}>品牌:{goods.brand}</Text>
78+
<View style={[styles.line10,styles.marginTop10]}/>
79+
<Text style={[styles.textprimary,styles.paddingLeftRight,styles.marginTop10]}>商品图文详情</Text>
80+
<Text style={[styles.textprimary,styles.paddingLeftRight,styles.marginTop10]}>{htmlContent}</Text>
81+
<HTMLView
82+
value={htmlContent}
83+
style={styles.container}
84+
/>
85+
</View>
86+
</ScrollView>
87+
);
88+
},
89+
});
90+
91+
92+
var styles = StyleSheet.create({
93+
container: {
94+
flex: 1,
95+
backgroundColor:'#f9f9f9',
96+
marginBottom:100,
97+
},
98+
thumb: {
99+
width: 60,
100+
height: 60,
101+
marginRight: 10
102+
},
103+
line1:{
104+
height:1,
105+
backgroundColor:'#dadce2'
106+
},
107+
line10:{
108+
height:10,
109+
backgroundColor:'#ebeef1'
110+
},
111+
textprimary:{
112+
fontSize:18,
113+
color:'#4a4d52',
114+
},
115+
textsecond:{
116+
fontSize:18,
117+
color:'#929aa2',
118+
},
119+
textPrice:{
120+
fontSize:18,
121+
color:'#fb7e00',
122+
},
123+
marginTop10:{
124+
marginTop:15,
125+
},
126+
paddingLeftRight:{
127+
paddingLeft:10,
128+
paddingRight:10,
129+
},
130+
scrollSpinner: {
131+
marginVertical: 20,
132+
},
133+
rowSeparator: {
134+
backgroundColor: 'rgba(0, 0, 0, 0.1)',
135+
height: 10,
136+
},
137+
rowSeparatorHide: {
138+
opacity: 0.0,
139+
},
140+
line:{
141+
height:1,
142+
backgroundColor: '#eef0f3',
143+
},
144+
row: {
145+
flexDirection: 'row',
146+
},
147+
});
148+
149+
module.exports = GoodsDetail;

app/page/home.js

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/**
2+
* Sample React Native App
3+
* https://github.com/facebook/react-native
4+
*/
5+
'use strict';
6+
7+
var React = require('react-native');
8+
var API = require('../network/api');
9+
var Util = require('../util/util');
10+
var Swiper = require('react-native-swiper');
11+
var ItemBlock = require('./serviceitem');
12+
var Global = require('../util/global');
13+
var Loading = require('./loading');
14+
var Web = require('./web');
15+
16+
var {
17+
AppRegistry,
18+
StyleSheet,
19+
Text,
20+
View,
21+
Image,
22+
ScrollView,
23+
ListView,
24+
TouchableHighlight,
25+
} = React;
26+
27+
//参数的传递使用props
28+
var Slider = React.createClass({
29+
30+
_loadWeb:function(title,loadurl){
31+
this.props.navigator.push({
32+
title: title,
33+
component: Web,
34+
passProps:{
35+
url: loadurl,
36+
}
37+
});
38+
},
39+
40+
render: function(){
41+
var thiz = this;
42+
return (
43+
<Swiper style={styles.wrapper} showsButtons={false} autoplay={true} height={125} showsPagination={false}>
44+
{this.props.banners.map(function(banner){
45+
return (
46+
<TouchableHighlight onPress={()=>thiz._loadWeb(banner.title,banner.url)}>
47+
<Image style={[styles.slide,]} source={{uri: banner.image_path}}></Image>
48+
</TouchableHighlight>
49+
);
50+
})}
51+
</Swiper>
52+
);
53+
}
54+
});
55+
56+
var Adviews = React.createClass({
57+
_loadWeb:function(title,loadurl){
58+
this.props.navigator.push({
59+
title: title,
60+
component: Web,
61+
passProps:{
62+
url: loadurl,
63+
}
64+
});
65+
},
66+
67+
render: function() {
68+
var advViews = [];
69+
var advs = this.props.advs;
70+
for(var i = 0; i < advs.length; i++){
71+
var ad = advs[i];
72+
advViews.push(
73+
<TouchableHighlight onPress={()=>this._loadWeb(ad.title,ad.url)}>
74+
<View>
75+
<View style={{height:10,backgroundColor:'#eef0f3'}} />
76+
<Image style={[styles.adv]} source={{uri:advs[i].image_path}} />
77+
</View>
78+
</TouchableHighlight>
79+
);
80+
};
81+
return (
82+
<View >
83+
{advViews}
84+
</View>
85+
);
86+
}
87+
});
88+
89+
var home = React.createClass({
90+
getInitialState: function() {
91+
var width = Math.floor(Util.size.width/3);
92+
return {
93+
store_id: 8805,
94+
loaded:false,
95+
banners:[],
96+
services:[],
97+
advs:[],
98+
dataSource: new ListView.DataSource({
99+
rowHasChanged: (row1, row2) => row1 !== row2,
100+
}),
101+
item_width:width,
102+
};
103+
},
104+
105+
componentDidMount: function() {
106+
this.getStoreMunu();
107+
},
108+
109+
getStoreMunu:function(){
110+
var store_id=this.state.store_id;
111+
var p9 = "app";
112+
var url ="http://test.api.bqmart.cn/stores/menu.json?store_id=8805&p9=app";
113+
fetch(url)
114+
.then((response) => response.json())
115+
.then((responseData) => {
116+
this.setState({
117+
banners: responseData.result.banners,
118+
services: responseData.result.services,
119+
advs:responseData.result.advs,
120+
loaded:true,
121+
});
122+
})
123+
.done()
124+
},
125+
126+
renderContent: function() {
127+
var service1 = [];
128+
var service2 = [];
129+
var services = this.state.services;
130+
//可以使用flex 布局
131+
for(var i = 0; i < 3; i++){
132+
service1.push(
133+
<ItemBlock key = {i} width={this.state.item_width} service={services[i]}/>
134+
);
135+
};
136+
137+
for(var i = 3; i < services.length; i++){
138+
service2.push(
139+
<ItemBlock key = {i} width={this.state.item_width} service={services[i]}/>
140+
);
141+
};
142+
143+
return (
144+
<ScrollView style={[styles.container]}>
145+
<Slider banners={this.state.banners} navigator={this.props.navigator}/>
146+
<View style={styles.itemRow}>
147+
{service1}
148+
</View>
149+
<View style={styles.itemRow}>
150+
{service2}
151+
</View>
152+
<Adviews advs={this.state.advs} navigator={this.props.navigator}/>
153+
</ScrollView>
154+
);
155+
},
156+
157+
render: function() {
158+
if(!this.state.loaded){
159+
return <Loading loadingtext='正在加载首页...'/>
160+
}
161+
return this.renderContent();
162+
},
163+
});
164+
165+
var styles = StyleSheet.create({
166+
container: {
167+
flex:1,
168+
paddingBottom:68,
169+
},
170+
//slider
171+
wrapper: {
172+
height:125,
173+
},
174+
slide: {
175+
height:125,
176+
resizeMode: Image.resizeMode.stretch,
177+
},
178+
adv: {
179+
height:175,
180+
resizeMode: Image.resizeMode.stretch,
181+
},
182+
container_bqservice:{
183+
padding:10,
184+
},
185+
inputRow:{
186+
flexDirection:'row',
187+
alignItems:'center',
188+
justifyContent: 'center',
189+
marginBottom:10,
190+
},
191+
welcome: {
192+
fontSize: 20,
193+
textAlign: 'center',
194+
margin: 10,
195+
},
196+
instructions: {
197+
textAlign: 'center',
198+
color: '#333333',
199+
marginBottom: 5,
200+
},
201+
itemRow:{
202+
flexDirection:'row',
203+
marginBottom:2,
204+
},
205+
206+
});
207+
208+
module.exports = home;

0 commit comments

Comments
 (0)