|
|
@@ -1,5 +1,6 @@
|
|
|
import React, {Component} from 'react'
|
|
|
import {withRouter} from 'react-router-dom'
|
|
|
+import {message} from 'antd'
|
|
|
import {NavBar, Icon, List, Picker, ActivityIndicator, InputItem} from 'antd-mobile'
|
|
|
import classNames from 'classnames'
|
|
|
import {Query, Mutation} from "react-apollo"
|
|
|
@@ -75,107 +76,112 @@ class CartOrders extends Component {
|
|
|
}
|
|
|
|
|
|
onSubmitOrderAndProduct = (user_id,create_order,create_order_product) => {
|
|
|
- let {totalCount, totalPrice, remark, delivery} = this.state
|
|
|
- let createdAt = moment().format('YYYY-MM-DD HH:mm:ss')
|
|
|
let ordersAddress = JSON.parse(sessionStorage.getItem('ordersAddress'))
|
|
|
- let {id:userAddress_id, telephone, username, province, city, area, address} = ordersAddress
|
|
|
- let addressData = String(province + city + area + address)
|
|
|
- let tag = telephone ? telephone.replace(/[^0-9]/ig, "").slice(-4) : Math.random().toString(10).substr(2,4)
|
|
|
- const orderId = createdAt.replace(/[^0-9]/ig, "").substr(2) + tag
|
|
|
- let orderLogisticsId = idGen('deliver')
|
|
|
|
|
|
- const orderContent = {
|
|
|
- remark,
|
|
|
- updatedAt: "",
|
|
|
- orderLogistics_id: orderLogisticsId,
|
|
|
- orderTotalPay: totalPrice,
|
|
|
- createdAt,
|
|
|
- orderStatus: "0",
|
|
|
- userAddress_id,
|
|
|
- id:orderId,
|
|
|
- count: totalCount,
|
|
|
- user_id,
|
|
|
- productTotalPay: totalPrice,
|
|
|
- orderPay_id: "",
|
|
|
- deleteId:[]
|
|
|
- }
|
|
|
-
|
|
|
- const orderLogistics = {
|
|
|
- updatedAt: "",
|
|
|
- deliveryTime: "",
|
|
|
- serviceStore: "",
|
|
|
- expressName:delivery[0],
|
|
|
- logisticsFee: 0.0,
|
|
|
- expressId: "",
|
|
|
- createdAt,
|
|
|
- order_id: orderId,
|
|
|
- consigneeTel: telephone,
|
|
|
- orderLogisticsId,
|
|
|
- consignAddress: addressData,
|
|
|
- LogisticsStatus: "0",
|
|
|
- user_id,
|
|
|
- consigneeName: username
|
|
|
- }
|
|
|
-
|
|
|
- let type = this.props.history.location.state.dataType
|
|
|
- let shopping = JSON.parse(sessionStorage.getItem(type))
|
|
|
- if(type === 'cartSelected') orderContent.deleteId = shopping.map(item => item.id)
|
|
|
-
|
|
|
- // console.log('createOrder orderContent',orderContent)
|
|
|
-
|
|
|
- let createOrder = create_order({variables:{...orderContent, ...orderLogistics}})
|
|
|
-
|
|
|
- let createOrderProduct = shopping.map((item,index) => {
|
|
|
+ if(ordersAddress){
|
|
|
+ let {totalCount, totalPrice, remark, delivery} = this.state
|
|
|
let createdAt = moment().format('YYYY-MM-DD HH:mm:ss')
|
|
|
- let orderProductId = createdAt.replace(/[^0-9]/ig, "").substr(2) + tag +index
|
|
|
- let {count, product_id:productData, specificationStock_id:specData} = item
|
|
|
- let {id:product_id, img, name, price, unit} = productData
|
|
|
- let {id:specId, color, size} = specData
|
|
|
- // console.log('product',index,item,product_id)
|
|
|
+ let {id:userAddress_id, telephone, username, province, city, area, address} = ordersAddress
|
|
|
+ let addressData = String(province + city + area + address)
|
|
|
+ let tag = telephone ? telephone.replace(/[^0-9]/ig, "").slice(-4) : Math.random().toString(10).substr(2,4)
|
|
|
+ const orderId = createdAt.replace(/[^0-9]/ig, "").substr(2) + tag
|
|
|
+ let orderLogisticsId = idGen('deliver')
|
|
|
|
|
|
- const orderProduct = {
|
|
|
+ const orderContent = {
|
|
|
+ remark,
|
|
|
updatedAt: "",
|
|
|
- productColor: color,
|
|
|
- unit,
|
|
|
- product_id,
|
|
|
- specificationStock_id:specId,
|
|
|
- productSize:size,
|
|
|
- orderPay: price,
|
|
|
+ orderLogistics_id: orderLogisticsId,
|
|
|
+ orderTotalPay: totalPrice,
|
|
|
createdAt,
|
|
|
- productImg:img,
|
|
|
- productName: name,
|
|
|
- order_id: orderId,
|
|
|
- productPrice:price,
|
|
|
- id:orderProductId,
|
|
|
+ orderStatus: "0",
|
|
|
+ userAddress_id,
|
|
|
+ id:orderId,
|
|
|
+ count: totalCount,
|
|
|
user_id,
|
|
|
- count,
|
|
|
- productPay: price,
|
|
|
+ productTotalPay: totalPrice,
|
|
|
orderPay_id: "",
|
|
|
+ deleteId:[]
|
|
|
+ }
|
|
|
+
|
|
|
+ const orderLogistics = {
|
|
|
+ updatedAt: "",
|
|
|
+ deliveryTime: "",
|
|
|
+ serviceStore: "",
|
|
|
+ expressName:delivery[0],
|
|
|
+ logisticsFee: 0.0,
|
|
|
+ expressId: "",
|
|
|
+ createdAt,
|
|
|
+ order_id: orderId,
|
|
|
+ consigneeTel: telephone,
|
|
|
+ orderLogisticsId,
|
|
|
+ consignAddress: addressData,
|
|
|
+ LogisticsStatus: "0",
|
|
|
+ user_id,
|
|
|
+ consigneeName: username
|
|
|
}
|
|
|
- console.log(`orderProduct${index}`,orderProduct)
|
|
|
|
|
|
- return create_order_product({variables:orderProduct}).then((data)=>{
|
|
|
- console.log('ok data',index,data)
|
|
|
- return data.data
|
|
|
+ let type = this.props.history.location.state.dataType
|
|
|
+ let shopping = JSON.parse(sessionStorage.getItem(type))
|
|
|
+ if(type === 'cartSelected') orderContent.deleteId = shopping.map(item => item.id)
|
|
|
+
|
|
|
+ // console.log('createOrder orderContent',orderContent)
|
|
|
+
|
|
|
+ let createOrder = create_order({variables:{...orderContent, ...orderLogistics}})
|
|
|
+
|
|
|
+ let createOrderProduct = shopping.map((item,index) => {
|
|
|
+ let createdAt = moment().format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ let orderProductId = createdAt.replace(/[^0-9]/ig, "").substr(2) + tag +index
|
|
|
+ let {count, product_id:productData, specificationStock_id:specData} = item
|
|
|
+ let {id:product_id, img, name, price, unit} = productData
|
|
|
+ let {id:specId, color, size} = specData
|
|
|
+ // console.log('product',index,item,product_id)
|
|
|
+
|
|
|
+ const orderProduct = {
|
|
|
+ updatedAt: "",
|
|
|
+ productColor: color,
|
|
|
+ unit,
|
|
|
+ product_id,
|
|
|
+ specificationStock_id:specId,
|
|
|
+ productSize:size,
|
|
|
+ orderPay: price,
|
|
|
+ createdAt,
|
|
|
+ productImg:img,
|
|
|
+ productName: name,
|
|
|
+ order_id: orderId,
|
|
|
+ productPrice:price,
|
|
|
+ id:orderProductId,
|
|
|
+ user_id,
|
|
|
+ count,
|
|
|
+ productPay: price,
|
|
|
+ orderPay_id: "",
|
|
|
+ }
|
|
|
+ console.log(`orderProduct${index}`,orderProduct)
|
|
|
+
|
|
|
+ return create_order_product({variables:orderProduct}).then((data)=>{
|
|
|
+ console.log('ok data',index,data)
|
|
|
+ return data.data
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
|
|
|
- Promise.all([createOrder, createOrderProduct]).then((data)=> {
|
|
|
- console.log('onSubmitOrderAndProduct data',data)
|
|
|
- sessionStorage.setItem('payOrder',JSON.stringify(orderContent))
|
|
|
- if(type === 'cartSelected'){
|
|
|
- let cartCount = JSON.parse(localStorage.getItem("cartCount")) - totalCount
|
|
|
- localStorage.setItem("cartCount",JSON.stringify(cartCount))
|
|
|
- localStorage.removeItem("cartList")
|
|
|
- }
|
|
|
+ Promise.all([createOrder, createOrderProduct]).then((data)=> {
|
|
|
+ console.log('onSubmitOrderAndProduct data',data)
|
|
|
+ sessionStorage.setItem('payOrder',JSON.stringify(orderContent))
|
|
|
+ if(type === 'cartSelected'){
|
|
|
+ let cartCount = JSON.parse(localStorage.getItem("cartCount")) - totalCount
|
|
|
+ localStorage.setItem("cartCount",JSON.stringify(cartCount))
|
|
|
+ localStorage.removeItem("cartList")
|
|
|
+ }
|
|
|
|
|
|
- this.props.history.push({
|
|
|
- pathname:'/cart/pay',
|
|
|
- state:{}
|
|
|
+ this.props.history.push({
|
|
|
+ pathname:'/cart/pay',
|
|
|
+ state:{}
|
|
|
+ })
|
|
|
+ }).catch((err)=>{
|
|
|
+ console.log('submit error',err)
|
|
|
})
|
|
|
- }).catch((err)=>{
|
|
|
- console.log('submit error',err)
|
|
|
- })
|
|
|
+ }else {
|
|
|
+ message.warning('请添加收货地址')
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|