|
@@ -1,23 +1,23 @@
|
|
|
import React, { Component } from 'react';
|
|
import React, { Component } from 'react';
|
|
|
-import { Checkbox, Card, WhiteSpace } from 'antd-mobile';
|
|
|
|
|
|
|
+import { Checkbox, WhiteSpace } from 'antd-mobile';
|
|
|
|
|
+import classNames from 'classnames'
|
|
|
|
|
|
|
|
import './index.css'
|
|
import './index.css'
|
|
|
|
|
|
|
|
-export class Tab3 extends Component {
|
|
|
|
|
|
|
+export class CartItem extends Component {
|
|
|
constructor(props){
|
|
constructor(props){
|
|
|
super(props);
|
|
super(props);
|
|
|
this.state={
|
|
this.state={
|
|
|
arr:[],
|
|
arr:[],
|
|
|
sum_price:0
|
|
sum_price:0
|
|
|
};
|
|
};
|
|
|
- console.log(props)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//获取数据
|
|
//获取数据
|
|
|
componentWillMount(){
|
|
componentWillMount(){
|
|
|
const arr = [
|
|
const arr = [
|
|
|
- {name:'test1',num:1,img:'',new_price:10},
|
|
|
|
|
- {name:'test2',num:2,img:'',new_price:20}
|
|
|
|
|
|
|
+ {id:'1',name:'test1',num:1,img:'',new_price:10},
|
|
|
|
|
+ {id:'2',name:'test2',num:2,img:'',new_price:20}
|
|
|
];
|
|
];
|
|
|
this.setState({
|
|
this.setState({
|
|
|
arr
|
|
arr
|
|
@@ -37,7 +37,7 @@ export class Tab3 extends Component {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
});
|
|
});
|
|
|
- this.SumPrice();
|
|
|
|
|
|
|
+ this.sumPrice();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 增加
|
|
// 增加
|
|
@@ -52,7 +52,7 @@ export class Tab3 extends Component {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
});
|
|
});
|
|
|
- this.SumPrice()
|
|
|
|
|
|
|
+ this.sumPrice()
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 减少
|
|
// 减少
|
|
@@ -67,7 +67,7 @@ export class Tab3 extends Component {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
});
|
|
});
|
|
|
- this.SumPrice();
|
|
|
|
|
|
|
+ this.sumPrice();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
//删除
|
|
//删除
|
|
@@ -82,12 +82,12 @@ export class Tab3 extends Component {
|
|
|
})
|
|
})
|
|
|
});
|
|
});
|
|
|
setTimeout(()=>{
|
|
setTimeout(()=>{
|
|
|
- this.SumPrice()
|
|
|
|
|
|
|
+ this.sumPrice()
|
|
|
},1)
|
|
},1)
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 实现全选与反选的操作
|
|
// 实现全选与反选的操作
|
|
|
- CheckAllorNoAll=(e,i)=>{
|
|
|
|
|
|
|
+ checkAllorNotAll=(e,i)=>{
|
|
|
this.setState({
|
|
this.setState({
|
|
|
arr:this.state.arr.map((ele,index)=>{
|
|
arr:this.state.arr.map((ele,index)=>{
|
|
|
if(index===i){
|
|
if(index===i){
|
|
@@ -97,24 +97,12 @@ export class Tab3 extends Component {
|
|
|
})
|
|
})
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- let flag=this.state.arr.every((ele,index)=>{
|
|
|
|
|
- if(ele.checked===false) {
|
|
|
|
|
- return false
|
|
|
|
|
- }else {
|
|
|
|
|
- return true
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- if(flag===true){
|
|
|
|
|
- this.refs.checkALL.checked=true
|
|
|
|
|
- }else {
|
|
|
|
|
- this.refs.checkALL.checked=false
|
|
|
|
|
- }
|
|
|
|
|
- this.SumPrice();
|
|
|
|
|
|
|
+ this.sumPrice();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
//全选全不选,判断全选状态
|
|
//全选全不选,判断全选状态
|
|
|
- CheckedAll=(e)=>{
|
|
|
|
|
|
|
+ checkedAll=(e)=>{
|
|
|
|
|
+ // console.log('CheckedAll e',e);
|
|
|
if(e.target.checked===true){
|
|
if(e.target.checked===true){
|
|
|
this.setState({
|
|
this.setState({
|
|
|
arr:this.state.arr.map((ele,index)=>{
|
|
arr:this.state.arr.map((ele,index)=>{
|
|
@@ -130,11 +118,11 @@ export class Tab3 extends Component {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
- this.SumPrice();
|
|
|
|
|
|
|
+ this.sumPrice();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
//计算总合计
|
|
//计算总合计
|
|
|
- SumPrice=()=>{
|
|
|
|
|
|
|
+ sumPrice=()=>{
|
|
|
let sum=0;
|
|
let sum=0;
|
|
|
this.state.arr.forEach((ele,index)=>{
|
|
this.state.arr.forEach((ele,index)=>{
|
|
|
if(ele.checked===true){
|
|
if(ele.checked===true){
|
|
@@ -147,7 +135,7 @@ export class Tab3 extends Component {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
//结算传值
|
|
//结算传值
|
|
|
- SettleAccounts=()=>{
|
|
|
|
|
|
|
+ settleAccounts=()=>{
|
|
|
let shopping=[];
|
|
let shopping=[];
|
|
|
this.state.arr.forEach((ele,index)=>{
|
|
this.state.arr.forEach((ele,index)=>{
|
|
|
if(ele.checked===true){
|
|
if(ele.checked===true){
|
|
@@ -157,7 +145,7 @@ export class Tab3 extends Component {
|
|
|
console.log('shopping',shopping);
|
|
console.log('shopping',shopping);
|
|
|
window.localStorage.setItem("shopping",JSON.stringify(shopping));
|
|
window.localStorage.setItem("shopping",JSON.stringify(shopping));
|
|
|
window.localStorage.setItem("sumprice",JSON.stringify(this.state.sum_price));
|
|
window.localStorage.setItem("sumprice",JSON.stringify(this.state.sum_price));
|
|
|
- this.props.history.push('/tab4')
|
|
|
|
|
|
|
+ this.props.history.push('/jiesuan')
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
@@ -167,81 +155,56 @@ export class Tab3 extends Component {
|
|
|
{
|
|
{
|
|
|
this.state.arr.map((ele,index)=>{
|
|
this.state.arr.map((ele,index)=>{
|
|
|
return(
|
|
return(
|
|
|
- <div className="G_list" key={index}>
|
|
|
|
|
- <div className="G_Checked">
|
|
|
|
|
- <input type="checkbox" checked={ele.checked} onChange={
|
|
|
|
|
- (e)=>{
|
|
|
|
|
- this.CheckAllorNoAll(e,index)
|
|
|
|
|
- }
|
|
|
|
|
- }/>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div className="G_img">
|
|
|
|
|
- <img src={ele.img} alt=""/>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div className="G_Content">
|
|
|
|
|
- <div className="G_selected">
|
|
|
|
|
- <button onClick={
|
|
|
|
|
- (e)=>{
|
|
|
|
|
- this.augment(e,index)
|
|
|
|
|
- }
|
|
|
|
|
- }>+</button>
|
|
|
|
|
- <input type="text" ref="nums" value={ele.num} onChange={
|
|
|
|
|
- (e)=>{
|
|
|
|
|
- this.getInputText(e,index)
|
|
|
|
|
- }
|
|
|
|
|
- }/>
|
|
|
|
|
- <button onClick={
|
|
|
|
|
- (e)=>{
|
|
|
|
|
- this.reduce(e,index)
|
|
|
|
|
- }
|
|
|
|
|
- }>-</button>
|
|
|
|
|
|
|
+ <div key={index}>
|
|
|
|
|
+ <div className="cart-list">
|
|
|
|
|
+ <div className="cart-list-checkbox">
|
|
|
|
|
+ <Checkbox
|
|
|
|
|
+ style={{marginLeft:15}}
|
|
|
|
|
+ checked={ele.checked}
|
|
|
|
|
+ onChange={(e)=>{this.checkAllorNotAll(e,index)}}
|
|
|
|
|
+ />
|
|
|
</div>
|
|
</div>
|
|
|
- <div className="G_text">
|
|
|
|
|
- <p>{ele.name}</p>
|
|
|
|
|
- <p>
|
|
|
|
|
- 单价:<span>{ele.new_price}</span>
|
|
|
|
|
- 小计:<span>{ele.num*ele.new_price}</span>
|
|
|
|
|
- </p>
|
|
|
|
|
|
|
+ <div className="cart-list-image">
|
|
|
|
|
+ <img src={ele.img || "https://gw.alipayobjects.com/zos/rmsportal/nywPmnTAvTmLusPxHPSu.png"} alt=""/>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="cart-list-intro">
|
|
|
|
|
+ <div>{ele.name}</div>
|
|
|
|
|
+ <div>颜色尺码等</div>
|
|
|
|
|
+ <div>¥ {ele.new_price}</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="cart-list-num">
|
|
|
|
|
+ <div className="selected">
|
|
|
|
|
+ <button
|
|
|
|
|
+ className={classNames({
|
|
|
|
|
+ 'selected_button': true,
|
|
|
|
|
+ 'selected_button-disabled': ele.num <= 1
|
|
|
|
|
+ })}
|
|
|
|
|
+ disabled={ele.num <= 1}
|
|
|
|
|
+ onClick={(e)=>{this.reduce(e,index)}}
|
|
|
|
|
+ >-</button>
|
|
|
|
|
+ <input className="selected_input" type="number" ref="nums" value={ele.num} onChange={(e)=>{this.getInputText(e,index)}}/>
|
|
|
|
|
+ <button className="selected_button" onClick={(e)=>{this.augment(e,index)}}>+</button>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
- <div className="G_del">
|
|
|
|
|
- <button onClick={
|
|
|
|
|
- (e)=>{
|
|
|
|
|
- this.del(e,index)
|
|
|
|
|
- }
|
|
|
|
|
- }>删除</button>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <WhiteSpace size="md" />
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
</div>
|
|
</div>
|
|
|
- <div>
|
|
|
|
|
- <WhiteSpace size="lg" />
|
|
|
|
|
- <Card full>
|
|
|
|
|
- <Card.Header
|
|
|
|
|
- title="This is title"
|
|
|
|
|
- thumb="https://gw.alipayobjects.com/zos/rmsportal/MRhHctKOineMbKAZslML.jpg"
|
|
|
|
|
- extra={<span>this is extra</span>}
|
|
|
|
|
- />
|
|
|
|
|
- <Card.Body>
|
|
|
|
|
- <div>This is content of `Card`</div>
|
|
|
|
|
- </Card.Body>
|
|
|
|
|
- <Card.Footer content="footer content" extra={<div>extra footer content</div>} />
|
|
|
|
|
- </Card>
|
|
|
|
|
- </div>
|
|
|
|
|
<div className="footer">
|
|
<div className="footer">
|
|
|
<div className="jiesuan">
|
|
<div className="jiesuan">
|
|
|
<div className="jiesuan-checkbox">
|
|
<div className="jiesuan-checkbox">
|
|
|
- <Checkbox onChange={(e)=>{this.CheckedAll(e)}} style={{marginLeft:15}}/>,
|
|
|
|
|
|
|
+ <Checkbox onChange={(e)=>{this.checkedAll(e)}} style={{marginLeft:15}}/>,
|
|
|
<span className="jiesuan-checkbox_label">全选</span>
|
|
<span className="jiesuan-checkbox_label">全选</span>
|
|
|
</div>
|
|
</div>
|
|
|
<div className="jiesuan-total">
|
|
<div className="jiesuan-total">
|
|
|
<span>合计:</span>
|
|
<span>合计:</span>
|
|
|
<span className="jiesuan-total_price">¥ {this.state.sum_price}</span>
|
|
<span className="jiesuan-total_price">¥ {this.state.sum_price}</span>
|
|
|
</div>
|
|
</div>
|
|
|
- <button className="jiesuan-button" onClick={()=>{this.SettleAccounts()}}>
|
|
|
|
|
- <span>提交订单</span>
|
|
|
|
|
|
|
+ <button className="jiesuan-button" onClick={()=>{this.settleAccounts()}}>
|
|
|
|
|
+ <span>结算</span>
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|