|
|
|
@ -9,6 +9,7 @@ import book1 from "../../assets/images/book1.png"; |
|
|
|
|
import "./index.scss"; |
|
|
|
|
|
|
|
|
|
const maxDesktopSize = 1250; |
|
|
|
|
const maxMobileSize = 550; |
|
|
|
|
|
|
|
|
|
const fontSize = { |
|
|
|
|
desktop: { |
|
|
|
@ -20,11 +21,19 @@ const fontSize = { |
|
|
|
|
span: window.innerWidth > maxDesktopSize ? 10 : window.innerWidth / 95, |
|
|
|
|
}, |
|
|
|
|
mobile: { |
|
|
|
|
h1: window.innerWidth > maxDesktopSize ? 20 : window.innerWidth / 18, |
|
|
|
|
} |
|
|
|
|
h1: window.innerWidth > maxMobileSize ? 20 : window.innerWidth / 13, |
|
|
|
|
h2: window.innerWidth > maxMobileSize ? 16 : window.innerWidth / 24, |
|
|
|
|
h3: window.innerWidth > maxMobileSize ? 12 : window.innerWidth / 30, |
|
|
|
|
strong: window.innerWidth > maxMobileSize ? 12 : window.innerWidth / 30, |
|
|
|
|
span: window.innerWidth > maxMobileSize ? 10 : window.innerWidth / 34, |
|
|
|
|
p: window.innerWidth > maxMobileSize ? 12 : window.innerWidth / 32, |
|
|
|
|
input: window.innerWidth > maxMobileSize ? 16 : window.innerWidth / 20, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
export default class Cart extends Component { |
|
|
|
|
state = { |
|
|
|
|
selectedDelivery: { name : '', price : 0}, |
|
|
|
|
discount: 0, |
|
|
|
|
totalPrice: null, |
|
|
|
|
list: [ |
|
|
|
|
{ |
|
|
|
@ -79,9 +88,18 @@ export default class Cart extends Component { |
|
|
|
|
handleDelete = (id) => { |
|
|
|
|
let list = this.state.list.filter((item) => item.id !== id); |
|
|
|
|
this.setState({ |
|
|
|
|
list: list |
|
|
|
|
}) |
|
|
|
|
list: list, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
totalPrice = () => { |
|
|
|
|
let total = 0; |
|
|
|
|
for (let i = 0; i < this.state.list.length; i++) { |
|
|
|
|
total += this.state.list[i].price * this.state.list[i].number; |
|
|
|
|
} |
|
|
|
|
return total - this.state.discount + this.state.selectedDelivery.price; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
@ -98,30 +116,29 @@ export default class Cart extends Component { |
|
|
|
|
<thead> |
|
|
|
|
<tr> |
|
|
|
|
<div className="d-flex align-items-center"> |
|
|
|
|
<th style={{ flex: 3, textAlign: 'center'}}>1</th> |
|
|
|
|
<th style={{ flex: 1.5, textAlign: 'center' }}>2</th> |
|
|
|
|
<th style={{ flex: 1.5, textAlign: 'center'}}>3</th> |
|
|
|
|
<th style={{ flex: 1, textAlign: 'center'}}>4</th> |
|
|
|
|
<th style={{ flex: 3, textAlign: "center" }}>1</th> |
|
|
|
|
<th style={{ flex: 1.5, textAlign: "center" }}>2</th> |
|
|
|
|
<th style={{ flex: 1.5, textAlign: "center" }}>3</th> |
|
|
|
|
<th style={{ flex: 1, textAlign: "center" }}>4</th> |
|
|
|
|
</div> |
|
|
|
|
</tr> |
|
|
|
|
</thead> |
|
|
|
|
<tbody> |
|
|
|
|
|
|
|
|
|
{this.state.list.map((item, i) => ( |
|
|
|
|
<Item |
|
|
|
|
handleDelete={this.handleDelete} |
|
|
|
|
handleCounter={this.handleCounter} |
|
|
|
|
data={item} |
|
|
|
|
key={i} |
|
|
|
|
/> |
|
|
|
|
))} |
|
|
|
|
{this.state.list.map((item, i) => ( |
|
|
|
|
<Item |
|
|
|
|
handleDelete={this.handleDelete} |
|
|
|
|
handleCounter={this.handleCounter} |
|
|
|
|
data={item} |
|
|
|
|
key={i} |
|
|
|
|
/> |
|
|
|
|
))} |
|
|
|
|
</tbody> |
|
|
|
|
</table> |
|
|
|
|
{this.state.totalPrice ? ( |
|
|
|
|
<div className="cart__right--price d-flex justify-content-end"> |
|
|
|
|
<div className="d-flex ml-2">جمع کل سبد خرید</div> |
|
|
|
|
<div className="d-flex"> |
|
|
|
|
<strong>تومان {this.state.totalPrice}</strong> |
|
|
|
|
<strong>{this.state.totalPrice} تومان </strong> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
) : null} |
|
|
|
@ -133,7 +150,7 @@ export default class Cart extends Component { |
|
|
|
|
</h2> |
|
|
|
|
<div className="d-flex justify-content-between"> |
|
|
|
|
{this.props.payMethods.map((item, i) => ( |
|
|
|
|
<PayMethod data={item} key={i} /> |
|
|
|
|
<DeliveryMethod data={item} key={i} parent={this} /> |
|
|
|
|
))} |
|
|
|
|
</div> |
|
|
|
|
</header> |
|
|
|
@ -144,36 +161,195 @@ export default class Cart extends Component { |
|
|
|
|
<Footer /> |
|
|
|
|
</> |
|
|
|
|
) : null} |
|
|
|
|
{ |
|
|
|
|
window.innerWidth < 1000 ? |
|
|
|
|
{window.innerWidth < 1000 ? ( |
|
|
|
|
<div className="mobile-cart d-flex flex-column"> |
|
|
|
|
<Navbar /> |
|
|
|
|
<h1 style={{ fontSize: fontSize.mobile.h1 }}>سبد خرید</h1> |
|
|
|
|
<div className="d-flex"> |
|
|
|
|
<Table list={this.state.list} handleCounter={this.handleCounter} handleDelete={this.handleDelete} /> |
|
|
|
|
<Table |
|
|
|
|
list={this.state.list} |
|
|
|
|
handleCounter={this.handleCounter} |
|
|
|
|
handleDelete={this.handleDelete} |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
<div className="mobile-cart__payMethods d-flex flex-column"> |
|
|
|
|
<h2 style={{ fontSize: fontSize.mobile.h2 }}>روشهای ارسال</h2> |
|
|
|
|
<p style={{ fontSize: fontSize.mobile.p }}> |
|
|
|
|
با توجه به شرایط یکی از دو گزینه زیر را انتخاب کنید |
|
|
|
|
</p> |
|
|
|
|
|
|
|
|
|
<div className="d-flex justify-content-between"> |
|
|
|
|
{this.props.payMethods.map((item, i) => ( |
|
|
|
|
<DeliveryMethod data={item} key={i} parent={this} /> |
|
|
|
|
))} |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<DiscoutCode /> |
|
|
|
|
<Factor parent={this} /> |
|
|
|
|
<div className="mobile-cart__totalPrice d-flex align-items-center justify-content-center"> |
|
|
|
|
<h3 style={{ fontSize: fontSize.mobile.h2 }}> |
|
|
|
|
جمع کل |
|
|
|
|
<br /> |
|
|
|
|
سبد خرید |
|
|
|
|
</h3> |
|
|
|
|
<div className="d-flex align-items-center"> |
|
|
|
|
<strong style={{ fontSize: fontSize.mobile.h1 }}> |
|
|
|
|
{this.totalPrice()} |
|
|
|
|
</strong> |
|
|
|
|
<span style={{ fontSize: fontSize.mobile.h3 }}>تومان</span> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<div className="mobile-cart__payMethods d-flex flex-column"> |
|
|
|
|
<h2 style={{ fontSize: fontSize.mobile.h2 }}>روشهای ارسال</h2> |
|
|
|
|
<p style={{ fontSize: fontSize.mobile.p }}> |
|
|
|
|
با توجه به شرایط یکی از دو گزینه زیر را انتخاب کنید |
|
|
|
|
</p> |
|
|
|
|
|
|
|
|
|
</div> : null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
<div className="d-flex justify-content-between"> |
|
|
|
|
{this.props.payMethods.map((item, i) => ( |
|
|
|
|
<DeliveryMethod data={item} key={i} parent={this} /> |
|
|
|
|
))} |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<button className="mobile-cart__submit">پرداخت</button> |
|
|
|
|
</div> |
|
|
|
|
) : null} |
|
|
|
|
</> |
|
|
|
|
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const PayMethod = (props) => { |
|
|
|
|
const DeliveryMethod = (props) => { |
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
{window.innerWidth > 1000 ? ( |
|
|
|
|
<div |
|
|
|
|
className="delivery-methods d-flex justify-content-between align-items-center" |
|
|
|
|
style={{ |
|
|
|
|
background: |
|
|
|
|
props.parent.state.selectedDelivery === props.data |
|
|
|
|
? "#00ff00" |
|
|
|
|
: "white", |
|
|
|
|
}} |
|
|
|
|
onClick={() => |
|
|
|
|
props.parent.setState({ selectedDelivery: props.data }) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
<strong style={{ fontSize: fontSize.desktop.strong }}> |
|
|
|
|
{props.data.name} |
|
|
|
|
</strong> |
|
|
|
|
<div className="d-flex flex-column align-items-center"> |
|
|
|
|
<h3 style={{ fontSize: fontSize.desktop.h3 }}> |
|
|
|
|
{props.data.price} |
|
|
|
|
</h3> |
|
|
|
|
<span style={{ fontSize: fontSize.desktop.span }}>تومان</span> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
) : null} |
|
|
|
|
{window.innerWidth < 1000 ? ( |
|
|
|
|
<div |
|
|
|
|
className="mobile-delivery-methods d-flex justify-content-between align-items-center" |
|
|
|
|
style={{ |
|
|
|
|
background: |
|
|
|
|
props.parent.state.selectedDelivery === props.data |
|
|
|
|
? "#ccffcc" |
|
|
|
|
: "white", |
|
|
|
|
}} |
|
|
|
|
onClick={() => |
|
|
|
|
props.parent.setState({ selectedDelivery: props.data }) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
<strong style={{ fontSize: fontSize.mobile.strong }}> |
|
|
|
|
{props.data.name} |
|
|
|
|
</strong> |
|
|
|
|
<div className="d-flex flex-column align-items-center"> |
|
|
|
|
<h3 style={{ fontSize: fontSize.mobile.h3 }}>{props.data.price}</h3> |
|
|
|
|
<span style={{ fontSize: fontSize.mobile.span }}>تومان</span> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
) : null} |
|
|
|
|
</> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const DiscoutCode = (props) => { |
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
{window.innerWidth > 1000 ? ( |
|
|
|
|
<div |
|
|
|
|
className="delivery-methods d-flex justify-content-between align-items-center" |
|
|
|
|
style={{ |
|
|
|
|
background: |
|
|
|
|
props.parent.state.selectedDelivery === props.data |
|
|
|
|
? "#00ff00" |
|
|
|
|
: "white", |
|
|
|
|
}} |
|
|
|
|
onClick={() => |
|
|
|
|
props.parent.setState({ selectedDelivery: props.data }) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
<strong style={{ fontSize: fontSize.desktop.strong }}> |
|
|
|
|
{props.data.name} |
|
|
|
|
</strong> |
|
|
|
|
<div className="d-flex flex-column align-items-center"> |
|
|
|
|
<h3 style={{ fontSize: fontSize.desktop.h3 }}> |
|
|
|
|
{props.data.price} |
|
|
|
|
</h3> |
|
|
|
|
<span style={{ fontSize: fontSize.desktop.span }}>تومان</span> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
) : null} |
|
|
|
|
{window.innerWidth < 1000 ? ( |
|
|
|
|
<div className="mobile-discount-code d-flex flex-column"> |
|
|
|
|
<h2 style={{ fontSize: fontSize.mobile.h2 }}>کد تخفیف</h2> |
|
|
|
|
<p style={{ fontSize: fontSize.mobile.p }}> |
|
|
|
|
اگر کد تخفیفی دارید آن را در کادر زیر وارد نمائید و دکمه ثبت کد را |
|
|
|
|
بزنید |
|
|
|
|
</p> |
|
|
|
|
<div className="mobile-discount-code__box d-flex align-items-center"> |
|
|
|
|
<input style={{ fontSize: fontSize.mobile.input }} type="text" /> |
|
|
|
|
<button>ثبت کد</button> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
) : null} |
|
|
|
|
</> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const Factor = (props) => { |
|
|
|
|
const { list, parent } = props; |
|
|
|
|
|
|
|
|
|
const totalPrice = () => { |
|
|
|
|
let total = 0; |
|
|
|
|
for (let i = 0; i < parent.state.list.length; i++) { |
|
|
|
|
total += parent.state.list[i].price * parent.state.list[i].number; |
|
|
|
|
} |
|
|
|
|
return total; |
|
|
|
|
}; |
|
|
|
|
return ( |
|
|
|
|
<div className="payment-methods d-flex justify-content-between align-items-center"> |
|
|
|
|
<strong style={{ fontSize: fontSize.desktop.strong }}> |
|
|
|
|
{props.data.name} |
|
|
|
|
</strong> |
|
|
|
|
<div className="d-flex flex-column align-items-center"> |
|
|
|
|
<h3 style={{ fontSize: fontSize.desktop.h3 }}>{props.data.price}</h3> |
|
|
|
|
<span style={{ fontSize: fontSize.desktop.span }}>تومان</span> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<> |
|
|
|
|
{window.innerWidth < 1000 ? ( |
|
|
|
|
<div className="mobile-factor d-flex flex-column"> |
|
|
|
|
<h2 style={{ fontSize: fontSize.mobile.h2 }}>کد تخفیف</h2> |
|
|
|
|
<p style={{ fontSize: fontSize.mobile.p }}> |
|
|
|
|
اگر کد تخفیفی دارید آن را در کادر زیر وارد نمائید و دکمه ثبت کد را |
|
|
|
|
بزنید |
|
|
|
|
</p> |
|
|
|
|
<div className="d-flex justify-content-between"> |
|
|
|
|
<strong>مبلغ سبد خرید</strong> |
|
|
|
|
<span>{totalPrice()} تومان</span> |
|
|
|
|
</div> |
|
|
|
|
<div className="d-flex justify-content-between"> |
|
|
|
|
<strong>هزینه ارسال</strong> |
|
|
|
|
<span>{props.parent.state.selectedDelivery.price} تومان</span> |
|
|
|
|
</div> |
|
|
|
|
<div className="d-flex justify-content-between"> |
|
|
|
|
<strong>میزان تخفیف</strong> |
|
|
|
|
<span>{props.parent.state.discount} تومان</span> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
) : null} |
|
|
|
|
</> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|