Browse Source

组件名称与文件目录统一

Csy817 6 years ago
parent
commit
fda52a1682
2 changed files with 55 additions and 54 deletions
  1. 50 50
      src/pages/cart/all/detail/index.js
  2. 5 4
      src/pages/cart/all/index.js

+ 50 - 50
src/pages/cart/all/detail/index.js

@@ -1,18 +1,18 @@
-import React, { Component } from 'react';
-import { Checkbox, WhiteSpace  } from 'antd-mobile';
-import classNames from 'classnames';
+import React, { Component } from 'react' 
+import { Checkbox, WhiteSpace  } from 'antd-mobile' 
+import classNames from 'classnames' 
 
 import '../index.css'
 
-class CartItem extends Component {
+class CartDetail extends Component {
     constructor(props){
-        super(props);
+        super(props) 
         this.state={
             cartList:[],
             totalPrice:0,
             isSelectAll:true,
             selectedCount:0
-        };
+        } 
     }
 
     //获取数据
@@ -20,8 +20,8 @@ class CartItem extends Component {
         this.setState({
             cartList:this.props.cartList
         },()=>{
-            this.checkedAll('',true);
-        });
+            this.checkedAll('',true) 
+        }) 
 
     }
 
@@ -30,45 +30,45 @@ class CartItem extends Component {
         this.setState({
             cartList:this.state.cartList.map((ele,index)=>{
                 if(index===i){
-                    ele.count=e.target.value;
+                    ele.count=e.target.value 
                     return ele
                 }else {
                     return ele
                 }
             })
-        });
-        this.sumPrice();
-    };
+        }) 
+        this.sumPrice() 
+    } 
 
     // 增加
     augment=(e,i)=>{
         this.setState({
             cartList:this.state.cartList.map((ele,index)=>{
                 if(index===i){
-                    ele.count=ele.count*1+1;
+                    ele.count=ele.count*1+1 
                     return ele
                 }else {
                     return ele
                 }
             })
-        });
+        }) 
         this.sumPrice()
-    };
+    } 
 
     // 减少
     reduce=(e,i)=> {
         this.setState({
             cartList:this.state.cartList.map((ele,index)=>{
                 if(index===i){
-                    ele.count=ele.count*1-1;
+                    ele.count=ele.count*1-1 
                     return ele
                 }else {
                     return ele
                 }
             })
-        });
-        this.sumPrice();
-    };
+        }) 
+        this.sumPrice() 
+    } 
 
     //删除
     del=(e,i)=> {
@@ -80,11 +80,11 @@ class CartItem extends Component {
                     return false
                 }
             })
-        });
+        }) 
         setTimeout(()=>{
             this.sumPrice()
         },1)
-    };
+    } 
 
     // 改变选择
     changeCheckedStatus=(e,i)=>{
@@ -95,76 +95,76 @@ class CartItem extends Component {
                 }
                 return ele
             })
-        });
+        }) 
 
         let flag = this.state.cartList.every((ele,index)=>{
             if(ele.checked===false) {
-                return false;
+                return false 
             }else {
-                return true;
+                return true 
             }
-        });
+        }) 
 
         if(flag===true){
-            this.setState({isSelectAll:true});
+            this.setState({isSelectAll:true}) 
         }else {
-            this.setState({isSelectAll:false});
+            this.setState({isSelectAll:false}) 
         }
-        this.sumPrice();
-    };
+        this.sumPrice() 
+    } 
 
     //全选或全不选,判断全选状态
     checkedAll=(e,check)=>{
-        let checked = e.target ? e.target.checked : check;
+        let checked = e.target ? e.target.checked : check 
 
         if(checked===true){
             this.setState({
                 cartList:this.state.cartList.map((ele,index)=>{
-                    ele.checked=true;
+                    ele.checked=true 
                     return ele
                 }),
                 isSelectAll:true
-            });
+            }) 
         }else  if(checked===false){
             this.setState({
                 cartList:this.state.cartList.map((ele,index)=>{
-                    ele.checked=false;
+                    ele.checked=false 
                     return ele
                 }),
                 isSelectAll:false
-            });
+            }) 
         }
-        this.sumPrice();
-    };
+        this.sumPrice()
+    } 
 
     //计算总合计
     sumPrice=()=>{
-        let totalPrice=0,selectedCount=0;
+        let totalPrice=0,selectedCount=0 
         this.state.cartList.forEach((ele,index)=>{
             if(ele.checked===true){
-                totalPrice+=ele.count*ele.product_id.price;
-                selectedCount+=ele.count;
+                totalPrice+=ele.count*ele.product_id.price 
+                selectedCount+=ele.count 
             }
-        });
+        })
         this.setState({
             totalPrice,
             selectedCount
-        });
-    };
+        })
+    } 
 
     //结算传值
     settleAccounts=()=>{
-        let shopping=[];
+        let shopping=[] 
         this.state.cartList.forEach((ele,index)=>{
             if(ele.checked===true){
                 shopping.push(ele)
             }
-        });
-        console.log('shopping',shopping);
-        window.localStorage.setItem("shopping",JSON.stringify(shopping));
-        window.localStorage.setItem("sumprice",JSON.stringify(this.state.totalPrice));
+        }) 
+        console.log('shopping',shopping) 
+        window.localStorage.setItem("shopping",JSON.stringify(shopping)) 
+        window.localStorage.setItem("sumprice",JSON.stringify(this.state.totalPrice)) 
         this.props.history.push('/jiesuan')
-    };
+    } 
 
     render() {
         return (
@@ -241,8 +241,8 @@ class CartItem extends Component {
                     </div>
                 </div>
             </div>
-        );
+        ) 
     }
 }
 
-export default CartItem;
+export default CartDetail

+ 5 - 4
src/pages/cart/all/index.js

@@ -3,10 +3,11 @@ import {NavBar, ActivityIndicator} from 'antd-mobile'
 import {Query} from "react-apollo"
 import gql from "graphql-tag"
 
-import CartItem from "./detail"
+import CartDetail from "./detail"
 import CartEdit from "./edit"
 import Empty from "../empty"
 import './index.css'
+
 import {cart_by_userid} from "../../../utils/gql"
 
 class All extends Component {
@@ -26,7 +27,7 @@ class All extends Component {
     }
 
     getHash = () => {
-        // console.log('location',window.location.hash);
+        // console.log('location',window.location.hash)
         let hash = window.location.hash || '#tab=cart&page=detail'
         let page = 'detail'
         if (window.location.hash && hash.indexOf("&") > 0) {
@@ -49,7 +50,7 @@ class All extends Component {
 
         switch (page) {
             case 'detail':
-                return <CartItem cartList={data.cartList}/>
+                return <CartDetail cartList={data.cartList}/>
             case 'edit':
                 return <CartEdit cartList={data.cartList}/>
             default:
@@ -74,7 +75,7 @@ class All extends Component {
                         if (error) {
                             return 'error!'
                         }
-                        // console.log('cart data',data);
+                        // console.log('cart data',data)
 
                         return (
                             <div>