index.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import React, {Component} from 'react'
  2. import {withRouter} from 'react-router-dom'
  3. import {NavBar, Icon, List, Picker} from 'antd-mobile'
  4. import classNames from 'classnames'
  5. import './index.css'
  6. const Item = List.Item
  7. const Brief = Item.Brief
  8. const delivery = [
  9. {
  10. label: "快递配送",
  11. value: "快递配送",
  12. },
  13. {
  14. label: "门店自提",
  15. value: "门店自提",
  16. }
  17. ]
  18. class CartOrders extends Component {
  19. constructor(props) {
  20. super(props)
  21. // console.log('shopping',JSON.parse(window.localStorage.getItem("shopping")))
  22. this.state = {
  23. cartList: [],
  24. unfoldList: [],
  25. totalPrice: JSON.parse(window.localStorage.getItem('totalPrice')),
  26. delivery: ["快递配送"],
  27. height: '100%',
  28. unfoldStatus: true,
  29. foldStatus: false,
  30. }
  31. }
  32. componentWillMount() {
  33. let cartList = JSON.parse(window.localStorage.getItem("shopping"))
  34. if (cartList.length > 3) {
  35. let cartList1 = cartList.slice(0, 3)
  36. let unfoldList = cartList.slice(3)
  37. this.setState({
  38. cartList: cartList1,
  39. unfoldList
  40. })
  41. } else {
  42. this.setState({
  43. cartList
  44. })
  45. }
  46. }
  47. onChangeDelivery = (val) => {
  48. this.setState({
  49. delivery: val,
  50. })
  51. }
  52. onChangeHeight = (height, unfoldStatus, foldStatus) => {
  53. this.setState({
  54. height,
  55. unfoldStatus,
  56. foldStatus
  57. })
  58. }
  59. render() {
  60. let {cartList, unfoldList, height, unfoldStatus, foldStatus, totalPrice} = this.state
  61. return (
  62. <div className='orders-wrap'>
  63. <div className='orders-navbar-wrap navbar'>
  64. <NavBar
  65. className='orders-navbar'
  66. mode="light"
  67. icon={<Icon type="left"/>}
  68. onLeftClick={() => {
  69. this.props.history.goBack()
  70. }}
  71. >订单确认</NavBar>
  72. </div>
  73. <div className='orders-content-wrap content-wrap'>
  74. <div className='orders-address'>
  75. <List>
  76. <Item
  77. arrow="horizontal"
  78. multipleLine
  79. onClick={() => {
  80. this.props.history.push({
  81. pathname:'/my/tools',
  82. state: {page: 'address'}})
  83. }}>
  84. <div>
  85. <span>承叶子</span>&nbsp;&nbsp;
  86. <span>18726202125</span>
  87. </div>
  88. <Brief style={{fontSize: 13}}>安徽省合肥市蜀山区青阳路彩虹家园1栋1601</Brief>
  89. </Item>
  90. </List>
  91. </div>
  92. <div className='orders-detail'>
  93. <div className='cart-content'>
  94. {
  95. cartList.map((ele, index) => {
  96. return (
  97. <div key={index}>
  98. <div className="cart-list">
  99. <div className="cart-list-image">
  100. <img
  101. src={ele.product_id.img || "https://gw.alipayobjects.com/zos/rmsportal/nywPmnTAvTmLusPxHPSu.png"}
  102. alt=""/>
  103. </div>
  104. <div className="cart-orders-intro">
  105. <div>{ele.product_id.name}</div>
  106. <div>颜色尺码等</div>
  107. <div>¥ {ele.product_id.price}</div>
  108. </div>
  109. <div className="cart-orders-count">
  110. x {ele.count}
  111. </div>
  112. </div>
  113. </div>
  114. )
  115. })
  116. }
  117. <div className={classNames({'packup': !unfoldList.length, 'packup-unfold': true})}
  118. style={{height: height}}>
  119. {
  120. unfoldStatus ?
  121. <div onClick={() => {
  122. this.onChangeHeight(96 * unfoldList.length + 42, false, true)
  123. }}>
  124. <div className='packup-title'>展开全部商品</div>
  125. <div>∨</div>
  126. </div>
  127. : ''
  128. }
  129. {
  130. foldStatus ?
  131. <div onClick={() => {
  132. this.onChangeHeight('100%', true, false)
  133. }}>
  134. {
  135. unfoldList.map((ele, index) => {
  136. return (
  137. <div key={index}>
  138. <div className="cart-list">
  139. <div className="cart-list-image">
  140. <img src={ele.product_id.img} alt=""/>
  141. </div>
  142. <div className="cart-orders-intro">
  143. <div>{ele.product_id.name}</div>
  144. <div>颜色尺码等</div>
  145. <div>¥ {ele.product_id.price}</div>
  146. </div>
  147. <div className="cart-orders-count">
  148. x {ele.count}
  149. </div>
  150. </div>
  151. </div>
  152. )
  153. })
  154. }
  155. <div className='packup-title'>收起</div>
  156. <div>∧</div>
  157. </div> : ''
  158. }
  159. </div>
  160. </div>
  161. </div>
  162. <div className='orders-delivery'>
  163. <div>
  164. <Picker
  165. data={delivery}
  166. value={this.state.delivery}
  167. cols={1}
  168. onChange={this.onChangeDelivery}
  169. >
  170. <List.Item arrow="horizontal">配送方式</List.Item>
  171. </Picker>
  172. </div>
  173. <div className="orders-message">
  174. <div className='orders-message-title'>买家留言</div>
  175. <div className='orders-message-textarea'>
  176. <textarea rows="1" cols="50" maxLength="50" placeholder="输入留言内容(50字以内)"
  177. className="message-textarea">
  178. </textarea>
  179. </div>
  180. </div>
  181. </div>
  182. <div className='orders-price'>
  183. <div>商品金额
  184. <span>¥ {totalPrice}</span>
  185. </div>
  186. <div>运费
  187. <span>¥ 0.00</span>
  188. </div>
  189. </div>
  190. </div>
  191. <div className="orders-footer">
  192. <div className="jiesuan">
  193. <div className='jiesuan-total'>
  194. <span>合计:</span>
  195. <span className="jiesuan-total_price">¥ {totalPrice}</span>
  196. </div>
  197. <button className="jiesuan-button"
  198. onClick={()=>{
  199. this.props.history.push({
  200. pathname:'/cart/pay',
  201. state:{}
  202. })
  203. }}>
  204. <span>提交订单</span>
  205. </button>
  206. </div>
  207. </div>
  208. </div>
  209. )
  210. }
  211. }
  212. export default withRouter(CartOrders)