|
|
@@ -3,9 +3,13 @@ import { Icon, Grid } from 'antd-mobile';
|
|
|
import {PageContext} from '../../context/context'
|
|
|
import OrderCard from './OrderCard'
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
import {graphqls} from '../../api/graphql_request'
|
|
|
import {getProductById} from '../../api/graphql/product'
|
|
|
import {getAddressByProps} from '../../api/graphql/address'
|
|
|
+import {createOrders,createOrderProducts} from '../../api/graphql/order'
|
|
|
|
|
|
import './OrederPage.css'
|
|
|
|
|
|
@@ -18,6 +22,9 @@ class OrderPage extends React.Component{
|
|
|
address:{},
|
|
|
product:{}
|
|
|
}
|
|
|
+ //this.toPay=this.toPay.bind(this)
|
|
|
+ this.createOrder=this.createOrder.bind(this)
|
|
|
+
|
|
|
}
|
|
|
//获取默认地址
|
|
|
getAddress(){
|
|
|
@@ -39,22 +46,93 @@ class OrderPage extends React.Component{
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+ createOrder(){
|
|
|
+ console.log('創造order')
|
|
|
+ let that =this,
|
|
|
+ orderStatus=1,
|
|
|
+ sumPrice=this.state.num*this.state.product.price,
|
|
|
+ payTime="2019/12/31 12:30:56"
|
|
|
+ //{orderStatus,payTime}=data
|
|
|
+
|
|
|
+ let id=new Date().getTime()+parseInt(Math.random(),10),
|
|
|
+ openid=sessionStorage.getItem('openid')
|
|
|
+ let orderData = {
|
|
|
+ "count": that.state.num,
|
|
|
+ "createdAt": new Date().toLocaleDateString()+' '+new Date().toLocaleTimeString().slice(2),
|
|
|
+ "deliveryTime": "",
|
|
|
+ "id": id,
|
|
|
+ "orderLogistics_id": "",
|
|
|
+ "orderPay_id": "",
|
|
|
+ "orderShipFee": 0,
|
|
|
+ "orderStatus": orderStatus,
|
|
|
+ "orderTotalPay": sumPrice,
|
|
|
+ "payTime": payTime,
|
|
|
+ "productTotalPay": sumPrice,
|
|
|
+ "updatedAt": "",
|
|
|
+ "userAddress_id": that.state.address.id,
|
|
|
+ "user_id": openid
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ graphqls(createOrders,orderData).then((e) => {
|
|
|
+ console.log('order创建订单成功', e)
|
|
|
+ that.createProductOrder(id)
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ createProductOrder(order_id){
|
|
|
+
|
|
|
+ let that=this,openid=sessionStorage.getItem('openid')
|
|
|
+ let data={
|
|
|
+ "count": that.state.num,
|
|
|
+ "createdAt": new Date().toLocaleDateString()+' '+new Date().toLocaleTimeString().slice(2),
|
|
|
+ "id": new Date().getTime()+parseInt(Math.random(),10),
|
|
|
+ "orderPay": 0,
|
|
|
+ "order_id": order_id,
|
|
|
+ "productPay": that.state.product.price * that.state.num,
|
|
|
+ "product_id": that.state.product.id,
|
|
|
+ "remark": that.state.remark,
|
|
|
+ "unit": "100",
|
|
|
+ "updatedAt": "",
|
|
|
+ "user_id": openid
|
|
|
+ }
|
|
|
+ graphqls(createOrderProducts,data).then((e)=>{
|
|
|
+ console.log('orderProduct创建成功',e)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ toPay(){
|
|
|
+ this.createOrder()
|
|
|
+ }
|
|
|
render(){
|
|
|
const address=this.state.address
|
|
|
const product=this.state.product
|
|
|
const num =this.state.num
|
|
|
return(
|
|
|
<div className="orderWrap">
|
|
|
- <div className="addressWrap">
|
|
|
- <span></span>
|
|
|
- <span>{address.username+address.telephone+address.province+address.city+address.area+address.address}</span>
|
|
|
- <span></span>
|
|
|
- </div>
|
|
|
+ <PageContext.Consumer>
|
|
|
+ {({changePage,triggerAddress})=>{
|
|
|
+ return(
|
|
|
+ <div className="addressWrap" onClick={()=>{
|
|
|
+ changePage('addressPage')
|
|
|
+ triggerAddress(true)
|
|
|
+ }}>
|
|
|
+ <span></span>
|
|
|
+ <span>{address.username+address.telephone+address.province+address.city+address.area+address.address}</span>
|
|
|
+ <span></span>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ </PageContext.Consumer>
|
|
|
+
|
|
|
<OrderCard state={{...this.state}}/>
|
|
|
<div className="payResult">
|
|
|
<div>共计{num}件商品;合计 ¥ {num*product.price}</div>
|
|
|
- <div>立即支付</div>
|
|
|
+ <div onClick={this.createOrder}>立即支付</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|