Prechádzať zdrojové kódy

get address and show on the page

wly 7 rokov pred
rodič
commit
1c5d21a8fe

+ 8 - 2
src/case/ShopApp/src/App.js

@@ -7,6 +7,9 @@ import TabBarBottom from './components/App/TabBarBottom'
 import ProductDetail from './components/ProductDetailPage/ProductDetail'
 import OrderPage from './components/OrderPage/OrederPage'
 
+import {graphqls} from './api/graphql_request'
+import {getProductById} from './api/graphql/product'
+
 class ShopApp extends Component {
   //showComponent
   constructor(props){
@@ -25,10 +28,13 @@ class ShopApp extends Component {
   setNum(num){
     this.setState({num})
   }
+
+  getProductByIds(){
+    return graphqls(getProductById,{id:this.state.product_id}).then(e=>e)
+  }
   
   renderPage(page=""){
     const setNum=this.setNum.bind(this)
-
     if(page==='detail'){
       return(
         <div className="pageWrap">
@@ -38,7 +44,7 @@ class ShopApp extends Component {
     }else if(page==='order'){
       return(
         <div className="pageWrap">
-        <OrderPage product_id={this.state.product_id} num={this.state.num}/>
+        <OrderPage product={this.getProductByIds()} num={this.state.num}/>
         </div>)
     }else{
       return(<div><TabBarBottom/></div>)

+ 14 - 16
src/case/ShopApp/src/components/OrderPage/OrederPage.jsx

@@ -6,7 +6,6 @@ import {getProductById} from '../../api/graphql/product'
 import {getAddressByProps} from '../../api/graphql/address'
 
 class OrderPage extends React.Component{
-
     constructor(props){
         super(props)
         this.state={
@@ -15,34 +14,33 @@ class OrderPage extends React.Component{
         }
     }
 
-    getProduct(){
-        graphqls(getProductById,{id:this.props.product_id}).then((e)=>{
-            console.log('productId',e.product_by_id)
-            this.setState({
-                product:e.product_by_id
-            })
-        })
-    }
     getAddress(){
         let user_id=sessionStorage.getItem('openid')
         console.log('user_id',user_id)
-        
         graphqls(getAddressByProps,{user_id}).then((e)=>{
-            console.log('getAddressByProps',e)
-            this.setState({
-                address:e
-            })
+            console.log('getAddressByProps',e.userAddressbyprops)
+            let address=e.userAddressbyprops.filter((item)=>{return item.default===1})[0]
+            this.setState({address})
         })
     }
 
     componentWillMount(){
-        this.getProduct()
         this.getAddress()
+        this.props.product.then((e)=>{
+            //console.log(e.productbyid)
+            this.setState({
+                product:e.productbyid
+            })
+        })
     }
     
     render(){
         console.log('props',this.props)
-        return(<div>orderpage</div>)
+        return(
+            <div className="orderWrap">
+                {this.state.address.address}
+            </div>
+            )
     }
 }