Quellcode durchsuchen

修复shopCarPage children 不能嵌套对象的bug

wly vor 7 Jahren
Ursprung
Commit
893c5abbd4

+ 2 - 2
src/case/ShopApp/src/components/AddressPage/EditAddress.jsx

@@ -20,8 +20,8 @@ export default class EditAddress extends Component {
   //创建用户地址
 
   createUserAddress(data){
-    //graphqls(createAddress,data)
-    console.log('---------',data)
+    graphqls(createAddress,data).then(e=>console.log(e))
+    //console.log('---------',data)
   }
   render() {
     return (

+ 8 - 0
src/case/ShopApp/src/components/AddressPage/FormAddress.css

@@ -23,4 +23,12 @@ div.am-picker-popup-wrap ,div.am-picker-popup-wrap{
     height: 293px;
 }
 
+div.am-list-item div.am-input-label.am-input-label-5 ,div.am-list-item .am-input-control input,div.am-list-item .am-list-line .am-list-extra{
+    font-size: 12px;
+}
+
 
+.am-button-primary {
+    margin-top: 20px;
+    font-size: 14px;
+}

+ 15 - 11
src/case/ShopApp/src/components/AddressPage/FormAddress.jsx

@@ -64,7 +64,9 @@ export default class FormAddress extends Component {
     console.log('e',e)
     console.log(district)
 
-    let provinceCode=e[0],cityCode=e[0],areCode=e[0]
+    let provinceCode=e[0],cityCode=e[1],areaCode=e[2]
+    
+  
     let province='',city='',area=''
 
     district.map((item)=>{
@@ -75,8 +77,8 @@ export default class FormAddress extends Component {
           if(item.value===cityCode){
             console.log('city',item)
             city=item.label
-            item.children((item)=>{
-              if(item.value===areCode){
+            item.children.map((item)=>{
+              if(item.value===areaCode){
                 console.log('area',item)
                 area=item.label
               }
@@ -89,20 +91,22 @@ export default class FormAddress extends Component {
       return 0
     })
 
-    console.log(province+city+area)
-
-
+    this.setState({
+      province,
+      city,
+      area
+    })
   }
 
   submit(){
     let data={
       "address": this.state.detail,
-      "area": "",
-      "city": "",
+      "area": this.state.area,
+      "city": this.state.city,
       "default":0,
       "id": new Date().getTime()+parseInt(Math.random(),10),
       "postcode": this.state.code,
-      "province": "",
+      "province": this.state.province,
       "telephone": this.state.phone,
       "updatedAt": "",
       "user_id": APPID,
@@ -137,7 +141,7 @@ export default class FormAddress extends Component {
 
             <div className='pickerWrap' style={this.state.areaShow ? {}:{display:""}}>
               <List style={{ backgroundColor: 'white' }} className="picker-list">
-                <Picker extra="请选择(可选)"
+                <Picker extra={this.state.province+this.state.city+this.state.area}
                   data={district}
                   title="Areas"
                   onOk={e => console.log('ok', e)}
@@ -145,7 +149,7 @@ export default class FormAddress extends Component {
                   onPickerChange={e=> this.areaChange(e)}
                   indicatorStyle={{position:"absolute",bottom:"0",left:"0"}}
                 >
-                  <List.Item arrow="horizontal">点击选择地区:{this.state.area}</List.Item>
+                  <List.Item arrow="horizontal">点击选择地区</List.Item>
                 </Picker>
               </List>
             </div>

+ 24 - 17
src/case/ShopApp/src/components/ShopCarPage/ShopCarCard.jsx

@@ -4,26 +4,33 @@ import './ShopCarCard.css'
 
 export default class ShopCarCard extends Component {
   render() {
-    const car=this.props.car
+    const shopCarList=this.props.shopCarList
+    const deleteCarById=this.props.deleteCarById
     return (
       <div>
-        <WhiteSpace size="lg" />
-          <Card full>
-            <Card.Body>
-              <div className="cardWrap">
-                <img src={car.product_id.img} alt="img" width="100px" height="100px"/>
-                <div className="middle">
-                  <div>{car.product_id.name}</div>
-                  <div>{car.product_id.intro}</div>
+        {shopCarList.map((item)=>{
+          return (
+            <div key={item.id}>
+            <WhiteSpace size="lg" />
+            <Card full>
+              <Card.Body>
+                <div className="cardWrap">
+                  <img src={item.product_id.img} alt="img" width="100px" height="100px"/>
+                  <div className="middle">
+                    <div>{item.product_id.name}</div>
+                    <div>{item.product_id.intro}</div>
+                  </div>
+                  <div className="right">
+                    <div>¥{item.product_id.price}</div>
+                    <div>x {item.count}</div>
+                   <button onClick={()=>{deleteCarById(item.id)}}>刪除</button>
+                  </div>
                 </div>
-                <div className="right">
-                  <div>¥{car.product_id.price}</div>
-                  <div>x {car.count}</div>
-                 <button onClick={()=>{this.props.deleteCarById(car.id)}}>刪除</button>
-                </div>
-              </div>
-            </Card.Body>
-        </Card>
+              </Card.Body>
+          </Card>
+            </div>
+          )
+        })}
       </div>
     )
   }

+ 11 - 12
src/case/ShopApp/src/components/ShopCarPage/ShopCarPage.jsx

@@ -15,7 +15,7 @@ class ShopCarPage extends Component{
             shopCarCount:0,
             loading:true
         }
-        this.renderShopCarList=this.renderShopCarList.bind(this)
+        //this.renderShopCarList=this.renderShopCarList.bind(this)
         this.deleteCarById=this.deleteCarById.bind(this)
         //this.deleteAllShopCar=this.deleteAllShopCar.bind(this)
     }
@@ -40,7 +40,7 @@ class ShopCarPage extends Component{
             console.log('getShopCarByProps',response.userCartbyprops)
             
             this.setState({
-                /*shopCarList:response.userCartbyprops,*/
+                shopCarList:response.userCartbyprops,
                 sumPrice,
                 shopCarCount,
                 loading:false
@@ -58,22 +58,21 @@ class ShopCarPage extends Component{
     }
 
     
-    renderShopCarList(){
-        return this.state.shopCarList||[].map((item,index)=>{
-
-            return <ShopCarCard car={item} key={item.id} deleteCarById={this.deleteCarById}/>
-            
-        })
-    }
+    // renderShopCarList(){
+    //     return this.state.shopCarList||[].map((item)=>{
+    //         return (<div>
+    //             <ShopCarCard car={item} key={item.id} deleteCarById={this.deleteCarById}/>
+    //             </div>)
+    //     })
+    // }
     
     render(){
         return(
             <div className="shopCarPage">
                 <ActivityIndicator toast text="loading" animating={this.state.loading}/>
                 <div className="ShopCarList">
-                   
-                    {this.renderShopCarList()} 
-
+                    {/*this.renderShopCarList()*/}
+                    <ShopCarCard shopCarList={this.state.shopCarList} deleteCarById={this.deleteCarById}/>
                 </div>
                 <div className="footer">
                     <div className="message">合计: ¥{this.state.sumPrice}</div>