Sfoglia il codice sorgente

修改地址地区

Csy817 6 anni fa
parent
commit
a11dc94902

+ 1 - 0
package.json

@@ -9,6 +9,7 @@
     "@svgr/webpack": "4.1.0",
     "antd": "^3.13.5",
     "antd-mobile": "^2.2.9",
+    "antd-mobile-full-demo-data": "^0.2.1",
     "apollo-boost": "^0.1.28",
     "axios": "^0.18.0",
     "babel-core": "7.0.0-bridge.0",

+ 1 - 1
src/App.js

@@ -85,7 +85,7 @@ class App extends Component {
 
     oauthLogin = () => {
         let openid =  getCookie("openid")
-        setCookie("openid","obR_j5GbxDfGlOolvSeTdZUwfpKA")
+        // setCookie("openid","obR_j5GbxDfGlOolvSeTdZUwfpKA")
         let user_id =  getCookie("user_id")
         console.log('oauthLogin openid',openid)
 

+ 1 - 1
src/pages/cart/empty/index.js

@@ -11,7 +11,7 @@ class Empty extends Component {
     }
 
     render() {
-        let contentHeight = window.innerHeight - 95
+        let contentHeight = window.innerHeight - 50
 
         return (
             <div className="cart-empty" style={{height: contentHeight}}>

+ 93 - 87
src/pages/cart/orders/index.js

@@ -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('请添加收货地址')
+        }
 
     }
 

+ 1 - 2
src/pages/home/detail/index.css

@@ -74,7 +74,7 @@
     font-size: 16px;
     align-items: center;
     background-color: #fdfbfb;
-    border-top: 1px solid #f5f5f9;
+    /*border-top: 1px solid #f5f5f9;*/
     z-index: 3;
 }
 
@@ -90,7 +90,6 @@
     height: 14px;
     line-height: 14px;
     font-size: 10px;
-    padding: 0 4px;
 }
 
 .border-right {

+ 2 - 2
src/pages/home/kind/index.js

@@ -2,13 +2,13 @@ import React, {Component} from 'react'
 import {withRouter} from 'react-router-dom'
 import {Query} from "react-apollo"
 import gql from "graphql-tag"
-import {Input} from 'antd'
+// import {Input} from 'antd'
 import {NavBar, Icon, ActivityIndicator, Grid} from 'antd-mobile'
 
 import {productbyprops} from "../../../utils/gql"
 import './index.css'
 
-const Search = Input.Search
+// const Search = Input.Search
 
 class Kind extends Component {
     constructor(props) {

+ 81 - 120
src/pages/my/tools/address/singleaddress/index.js

@@ -1,94 +1,15 @@
 import React, {Component} from "react"
+import {message} from 'antd'
 import {InputItem, TextareaItem, Picker, Switch} from 'antd-mobile'
 import {Mutation} from "react-apollo"
 import gql from "graphql-tag"
 import moment from 'moment'
+import {district} from 'antd-mobile-full-demo-data';
 
-import {
-    create_update_userAddress,
-    update_userAddress,
-    userAddressbyprops
-} from "../../../../../utils/gql"
+import {create_update_userAddress, update_userAddress, userAddressbyprops} from "../../../../../utils/gql"
 import './index.css'
 import {idGen} from "../../../../../utils/func"
 
-const provinceAll = [
-    {
-        label: '江苏省',
-        value: '江苏省',
-    },
-    {
-        label: '河南省',
-        value: '河南省',
-    },
-    {
-        label: '安徽省',
-        value: '安徽省',
-        children: [
-            {
-                label: '合肥市',
-                value: '合肥市',
-                children: [
-                    {
-                        label: '蜀山区',
-                        value: '蜀山区',
-                    },
-                    {
-                        label: '瑶海区',
-                        value: '瑶海区',
-                    },
-                    {
-                        label: '包河区',
-                        value: '包河区',
-                    },
-                    {
-                        label: '庐阳区',
-                        value: '庐阳区',
-                    }
-                ],
-            },
-            {
-                label: '芜湖市',
-                value: '芜湖市',
-                children: [
-                    {
-                        label: '镜湖区',
-                        value: '镜湖区',
-                    },
-                    {
-                        label: '弋江区',
-                        value: '弋江区',
-                    },
-                ],
-            },
-            {
-                label: '六安市',
-                value: '六安市',
-            },
-            {
-                label: '淮南市',
-                value: '淮南市',
-            },
-            {
-                label: '马鞍山市',
-                value: '马鞍山市',
-            },
-            {
-                label: '黄山市',
-                value: '黄山市',
-            }
-        ]
-    },
-    {
-        label: '湖北省',
-        value: '湖北省',
-    },
-    {
-        label: '江西省',
-        value: '江西省',
-    },
-]
-
 class SingleAddress extends Component {
     constructor(props) {
         super(props)
@@ -109,53 +30,92 @@ class SingleAddress extends Component {
             let defaultStatus = default1 ? 1 : 0
             this.state = {...state, province, city, area, address, telephone, username, id, defaultStatus}
         }
+        this.handleDistrict()
+    }
+
+    handleDistrict = () => {
+        district.forEach((item)=>{
+            let {label} = item
+            item.value = label
+            if(item.children){
+                item.children.forEach((item)=>{
+                    let {label} = item
+                    item.value = label
+                    if(item.children){
+                        item.children.forEach((item)=>{
+                            let {label} = item
+                            item.value = label
+                        })
+                    }
+                })
+            }
+        })
     }
 
     saveAddress = (user_id, mutate) => {
         let createdAt = moment().format('YYYY-MM-DD HH:mm:ss')
         let {username, telephone, province, city, area, address, defaultStatus, id} = this.state
-        let addressId = id || idGen('address')
-
-        let defaultStatus1 = defaultStatus ? 1 : 0
-        const addressContent = {
-            address,
-            updatedAt: "",
-            telephone,
-            default: defaultStatus1,
-            city,
-            username,
-            postcode: "",
-            createdAt,
-            deletedAt: "",
-            id: addressId,
-            user_id,
-            area,
-            province
-        }
+        let areaAddress = province + city + area
+        const testPhoneNum = /^1[0-9]{10}$/;
+        let isPoneAvailable = testPhoneNum.test(telephone);
 
-        let {defaultAddress, addressID} = this.props
-        if(defaultAddress){
-            let {id} = defaultAddress
-            addressContent.updateID = id
-            addressContent.updateDefault = 0
-        }else {
-            addressContent.updateID = ''
-        }
-
-        mutate({variables:addressContent}).then((data)=>{
-            this.props.refetch()
-            let prePage = this.props.history.location.state.prePage
+        if(username && isPoneAvailable && areaAddress && address){
+            let addressId = id || idGen('address')
 
-            if(defaultStatus1){
-                sessionStorage.setItem('ordersAddress',JSON.stringify(addressContent))
+            let defaultStatus1 = defaultStatus ? 1 : 0
+            const addressContent = {
+                address,
+                updatedAt: "",
+                telephone,
+                default: defaultStatus1,
+                city,
+                username,
+                postcode: "",
+                createdAt,
+                deletedAt: "",
+                id: addressId,
+                user_id,
+                area,
+                province
             }
-            if(prePage && addressID !== 'add'){
-                sessionStorage.setItem('ordersAddress',JSON.stringify(addressContent))
-                this.props.history.go(-2)
+
+            let {defaultAddress, addressID} = this.props
+            if(defaultAddress){
+                let {id} = defaultAddress
+                addressContent.updateID = id
+                addressContent.updateDefault = 0
             }else {
-                this.props.changePage(false)
+                addressContent.updateID = ''
             }
-        })
+
+            mutate({variables:addressContent}).then((data)=>{
+                this.props.refetch()
+                let prePage = this.props.history.location.state.prePage
+
+                if(defaultStatus1){
+                    sessionStorage.setItem('ordersAddress',JSON.stringify(addressContent))
+                }
+                if(prePage && addressID !== 'add'){
+                    sessionStorage.setItem('ordersAddress',JSON.stringify(addressContent))
+                    this.props.history.go(-2)
+                }else {
+                    this.props.changePage(false)
+                }
+            })
+        }else if(!username){
+            message.warning('收货人不能为空',1)
+        }else if(!telephone){
+            message.warning('联系电话不能为空',1);
+        } else if(!isPoneAvailable){
+            message.warning('请输入11位有效手机号码',1)
+        }else if(!areaAddress){
+            message.warning('请选择地区',1)
+        }else if(!address){
+            message.warning('请输入详细地址,无需包含省市',1)
+        }else {
+            message.warning('收货地址暂未完善',2)
+        }
+
     }
 
     render() {
@@ -176,9 +136,10 @@ class SingleAddress extends Component {
                         <div>联系电话</div>
                     </InputItem>
                     <Picker
-                        data={provinceAll}
+                        data={district}
                         value={[province, city ? city : '', area ? area : '']}
                         onOk={(address) => {
+                            console.log('onOK address',address)
                             this.setState({province: address[0], city: address[1], area: address[2]})
                         }}
                     >