|
|
@@ -1,5 +1,5 @@
|
|
|
import React from 'react'
|
|
|
-import { Icon, Grid } from 'antd-mobile';
|
|
|
+import {ActivityIndicator} from 'antd-mobile';
|
|
|
import {PageContext} from '../../context/context'
|
|
|
import OrderCard from './OrderCard'
|
|
|
|
|
|
@@ -12,10 +12,15 @@ import {getAddressByProps} from '../../api/graphql/address'
|
|
|
import {createOrders,createOrderProducts} from '../../api/graphql/order'
|
|
|
import {getShopCarByProps,deleteCarByProps} from '../../api/graphql/shopCar'
|
|
|
|
|
|
-import {successToast,failToast} from '../Toast/Toast'
|
|
|
+import {successToast,failToast} from '../Common/Toast'
|
|
|
+import {dialog} from '../Common/Alert'
|
|
|
import './OrederPage.css'
|
|
|
import { concatSeries } from 'async';
|
|
|
|
|
|
+import { List } from 'antd-mobile';
|
|
|
+const Item = List.Item;
|
|
|
+const Brief = Item.Brief;
|
|
|
+
|
|
|
class OrderPage extends React.Component{
|
|
|
constructor(props){
|
|
|
super(props)
|
|
|
@@ -25,10 +30,12 @@ class OrderPage extends React.Component{
|
|
|
address:{},
|
|
|
products:[],
|
|
|
shopCarList:[],
|
|
|
- sumPrice:''
|
|
|
+ sumPrice:'',
|
|
|
+ loading:true
|
|
|
}
|
|
|
//this.toPay=this.toPay.bind(this)
|
|
|
this.createOrder=this.createOrder.bind(this)
|
|
|
+ this.toPay=this.toPay.bind(this)
|
|
|
|
|
|
}
|
|
|
//获取数据
|
|
|
@@ -52,7 +59,8 @@ class OrderPage extends React.Component{
|
|
|
console.log('getProductByIds',e.productbyid)
|
|
|
this.setState({
|
|
|
products:[e.productbyid],
|
|
|
- sumPrice:this.props.num*e.productbyid.price
|
|
|
+ sumPrice:this.props.num*e.productbyid.price,
|
|
|
+ loading:false
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
@@ -67,7 +75,6 @@ class OrderPage extends React.Component{
|
|
|
graphqls(getShopCarByProps,{user_id}).then((response)=>{
|
|
|
let sumPrice=0,num=0;
|
|
|
//如果請求失敗,默认空数组
|
|
|
-
|
|
|
(response.userCartbyprops||[]).map((item)=>{
|
|
|
sumPrice+=item.count*item.product_id.price
|
|
|
num+=item.count
|
|
|
@@ -78,61 +85,104 @@ class OrderPage extends React.Component{
|
|
|
this.setState({
|
|
|
shopCarList:response.userCartbyprops,
|
|
|
sumPrice,
|
|
|
- num
|
|
|
+ num,
|
|
|
+ loading:false
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ deleteCarById(id){
|
|
|
+ //console.log(id)
|
|
|
+ graphqls(deleteCarByProps,{id}).then((e)=>{
|
|
|
+ console.log('删除了shopcar',e)
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- createOrder(){
|
|
|
+ deleteAllShopCar(){
|
|
|
+ const shopcarList=this.state.shopCarList||[],that=this;
|
|
|
+ shopcarList.map((item)=>{
|
|
|
+ that.deleteCarById(item.id)
|
|
|
+ return 0
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ toCreateOrder(status){
|
|
|
+ const payTime=new Date().toLocaleString('chinese', { hour12: false })
|
|
|
+ this.createOrder(status,payTime)
|
|
|
+
|
|
|
+ //console.log('status',status)
|
|
|
+ }
|
|
|
+ createOrder(orderStatus,payTime){
|
|
|
console.log('創造order')
|
|
|
- let that =this,
|
|
|
- orderStatus=1,
|
|
|
- sumPrice=this.state.num*this.state.product.price,
|
|
|
- payTime="2019/12/31 12:30:56"
|
|
|
+ console.log('this.state',this.state)
|
|
|
+ let that =this
|
|
|
//{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),
|
|
|
+ "createdAt": new Date().toLocaleString('chinese', { hour12: false }),
|
|
|
"deliveryTime": "",
|
|
|
"id": id,
|
|
|
"orderLogistics_id": "",
|
|
|
"orderPay_id": "",
|
|
|
"orderShipFee": 0,
|
|
|
"orderStatus": orderStatus,
|
|
|
- "orderTotalPay": sumPrice,
|
|
|
+ "orderTotalPay": this.state.sumPrice,//-优惠
|
|
|
"payTime": payTime,
|
|
|
- "productTotalPay": sumPrice,
|
|
|
+ "productTotalPay": this.state.sumPrice,
|
|
|
"updatedAt": "",
|
|
|
"userAddress_id": that.state.address.id,
|
|
|
"user_id": openid
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ const fromShopCar= this.props.fromShopCar
|
|
|
graphqls(createOrders,orderData).then((e) => {
|
|
|
console.log('order创建订单成功', e)
|
|
|
- that.createProductOrder(id)
|
|
|
-
|
|
|
+ that.deleteAllShopCar()
|
|
|
+ let products=that.state.products||[]
|
|
|
+ let shopCarList=that.state.shopCarList||[]
|
|
|
+ //从购物车页面跳转而来(多个产品)
|
|
|
+ if(fromShopCar){
|
|
|
+ console.log('来自shopcar')
|
|
|
+ //console.log('shopList----',shopCarList)
|
|
|
+ let i=1
|
|
|
+ shopCarList.map((item)=>{
|
|
|
+ console.log(item)
|
|
|
+ that.createProductOrder(id,item.count,item.product_id)
|
|
|
+ i++;
|
|
|
+ if(i===shopCarList.length){
|
|
|
+ //订单创建成功,删除购物车里面的所有产品
|
|
|
+ that.deleteAllShopCar()
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+ })
|
|
|
+ }else{//从产品详情页面跳转而来(一个产品)
|
|
|
+ console.log('来自detail')
|
|
|
+ products.map((item)=>{
|
|
|
+ that.createProductOrder(id,that.state.num,item)
|
|
|
+ return 0
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
- createProductOrder(order_id){
|
|
|
-
|
|
|
+ createProductOrder(order_id,count,product){
|
|
|
+ console.log('product-----------',product)
|
|
|
let that=this,openid=sessionStorage.getItem('openid')
|
|
|
let data={
|
|
|
- "count": that.state.num,
|
|
|
- "createdAt": new Date().toLocaleDateString()+' '+new Date().toLocaleTimeString().slice(2),
|
|
|
+ "count": count,
|
|
|
+ "createdAt": new Date().toLocaleString('chinese', { hour12: false }),
|
|
|
"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,
|
|
|
+ "productPay": product.price * count,
|
|
|
+ "product_id": product.id,
|
|
|
+ "remark": "that.state.remark",
|
|
|
"unit": "100",
|
|
|
"updatedAt": "",
|
|
|
"user_id": openid
|
|
|
@@ -144,9 +194,18 @@ class OrderPage extends React.Component{
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- // toPay(){
|
|
|
- // this.createOrder()
|
|
|
- // }
|
|
|
+ toPay(){
|
|
|
+ dialog('¥'+this.state.sumPrice,'确认支付吗?').then(
|
|
|
+ (e)=>{
|
|
|
+ //console.log('ok ',e)
|
|
|
+ this.toCreateOrder(1)
|
|
|
+ },(e)=>{
|
|
|
+ //console.log('fail ',e)
|
|
|
+ this.toCreateOrder(0)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
renderCardList(){
|
|
|
if(this.props.fromShopCar){
|
|
|
return(
|
|
|
@@ -165,22 +224,28 @@ class OrderPage extends React.Component{
|
|
|
|
|
|
render(){
|
|
|
const address=this.state.address
|
|
|
- const product=this.state.product
|
|
|
const num =this.state.num
|
|
|
return(
|
|
|
<div className="orderWrap">
|
|
|
- <div className="addressWrap" onClick={()=>{
|
|
|
- this.props.changePage('addressPage')
|
|
|
- this.props.triggerAddress(true)
|
|
|
- }}>
|
|
|
- <span></span>
|
|
|
- <span>{address.username+address.telephone+address.province+address.city+address.area+address.address}</span>
|
|
|
- <span></span>
|
|
|
+ <ActivityIndicator toast text="loading" animating={this.state.loading}/>
|
|
|
+ <div className="addressWrap">
|
|
|
+ <List>
|
|
|
+ <Item
|
|
|
+ thumb="https://wly-1254337200.cos.ap-guangzhou.myqcloud.com/positioning.svg"
|
|
|
+ arrow="horizontal"
|
|
|
+ wrap
|
|
|
+ multipleLine
|
|
|
+ onClick={() => {
|
|
|
+ this.props.changePage('addressPage')
|
|
|
+ this.props.triggerAddress(true)
|
|
|
+ }}
|
|
|
+ >{address.username+address.telephone+address.province+address.city+address.area+address.address}</Item>
|
|
|
+ </List>
|
|
|
</div>
|
|
|
<div className="cardList">{this.renderCardList()}</div>
|
|
|
<div className="payResult">
|
|
|
<div>共计{num}件商品;合计 ¥ {this.state.sumPrice}</div>
|
|
|
- <div onClick={this.createOrder}>立即支付</div>
|
|
|
+ <div onClick={this.toPay}>立即支付</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|