|
|
@@ -1,6 +1,9 @@
|
|
|
import React, { Component } from 'react';
|
|
|
import './App.css';
|
|
|
// import 'antd-mobile/dist/antd-mobile.css';
|
|
|
+import HomePage from './components/HomePage/HomePage'
|
|
|
+import ShopCar from './components/ShopCarPage/shopCar'
|
|
|
+import UserPage from './components/UserPage/userPage'
|
|
|
import {PageContext,NumContext} from './context/context'
|
|
|
import NavBars from './components/App/NavBar'
|
|
|
import TabBarBottom from './components/App/TabBarBottom'
|
|
|
@@ -8,7 +11,7 @@ import ProductDetail from './components/ProductDetailPage/ProductDetail'
|
|
|
import OrderPage from './components/OrderPage/OrederPage'
|
|
|
|
|
|
import {graphqls} from './api/graphql_request'
|
|
|
-import {getProductById} from './api/graphql/product'
|
|
|
+import {getProductById,getProductByProps} from './api/graphql/product'
|
|
|
import axious from './api/axious_request'
|
|
|
axious()
|
|
|
|
|
|
@@ -17,30 +20,54 @@ class ShopApp extends Component {
|
|
|
constructor(props){
|
|
|
super(props)
|
|
|
this.state={
|
|
|
- page:'',
|
|
|
+ page:'index',
|
|
|
product_id:'',
|
|
|
num:1
|
|
|
}
|
|
|
+ this.changePage=this.changePage.bind(this)
|
|
|
}
|
|
|
|
|
|
componentWillMount(){
|
|
|
sessionStorage.setItem("openid","ovtkn4zONC3IzhpykQ7cSLZ85YFg")
|
|
|
+ this.getGoods()
|
|
|
+ }
|
|
|
+
|
|
|
+ getGoods(variables={}){
|
|
|
+ return graphqls(getProductByProps,variables).then((data)=>{
|
|
|
+ console.log("data",data)
|
|
|
+ let products=data.productbyprops||[]
|
|
|
+ sessionStorage.setItem("products",JSON.stringify(products))
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
setNum(num){
|
|
|
+ console.log('num',num)
|
|
|
this.setState({num})
|
|
|
}
|
|
|
|
|
|
getProductByIds(){
|
|
|
return graphqls(getProductById,{id:this.state.product_id}).then(e=>e)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ changePage(page,product_id){
|
|
|
+ console.log("onAppPage",page)
|
|
|
+
|
|
|
+ if(product_id){
|
|
|
+ this.setState({page,product_id})
|
|
|
+ }else{
|
|
|
+ this.setState({page})
|
|
|
+ console.log('state.page',this.state.page)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
renderPage(page=""){
|
|
|
const setNum=this.setNum.bind(this)
|
|
|
if(page==='detail'){
|
|
|
return(
|
|
|
<div className="pageWrap">
|
|
|
- <ProductDetail product_id={this.state.product_id} setNum={setNum}/>
|
|
|
+ <ProductDetail product_id={this.state.product_id} setNum={setNum} />
|
|
|
</div>
|
|
|
)
|
|
|
}else if(page==='order'){
|
|
|
@@ -48,17 +75,44 @@ class ShopApp extends Component {
|
|
|
<div className="pageWrap">
|
|
|
<OrderPage product={this.getProductByIds()} num={this.state.num}/>
|
|
|
</div>)
|
|
|
- }else{
|
|
|
- return(<div><TabBarBottom/></div>)
|
|
|
+ }else if(page==='index'){
|
|
|
+ console.log('index 渲染了')
|
|
|
+ return(
|
|
|
+ <div>
|
|
|
+ <div className="pageWrap indexPage">
|
|
|
+ <HomePage changePage={this.changePage}/>
|
|
|
+ </div>
|
|
|
+ <TabBarBottom changePage={this.changePage}/>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
}
|
|
|
- }
|
|
|
+ else if(page==='shopCar'){
|
|
|
+ console.log('shopCar 渲染了')
|
|
|
+ return(
|
|
|
+ <div>
|
|
|
+ <div className="pageWrap">
|
|
|
+ <ShopCar />
|
|
|
+ </div>
|
|
|
+ <TabBarBottom changePage={this.changePage}/>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }else if(page==='user'){
|
|
|
+ console.log('user 渲染了')
|
|
|
+ return(
|
|
|
+ <div>
|
|
|
+ <div className="pageWrap">
|
|
|
+ <UserPage />
|
|
|
+ </div>
|
|
|
+ <TabBarBottom changePage={this.changePage}/>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }else{
|
|
|
|
|
|
- changePage(page='',product_id=this.state.product_id){
|
|
|
- this.setState({page,product_id})
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
- const changePage=this.changePage.bind(this)
|
|
|
+ const changePage=this.changePage
|
|
|
return (
|
|
|
<PageContext.Provider value={changePage}>
|
|
|
<div className="AppWrap">
|