Browse Source

Add 完善下单功能

enilu 6 years ago
parent
commit
63d66c6e0b

+ 49 - 9
flash-waimai-api/src/main/java/cn/enilu/flash/api/controller/business/CartController.java

@@ -1,17 +1,19 @@
 package cn.enilu.flash.api.controller.business;
 
 import cn.enilu.flash.api.controller.BaseController;
-import cn.enilu.flash.bean.entity.front.Ids;
+import cn.enilu.flash.bean.entity.front.*;
 import cn.enilu.flash.bean.vo.front.Rets;
 import cn.enilu.flash.dao.MongoRepository;
 import cn.enilu.flash.service.front.IdsService;
+import cn.enilu.flash.utils.Lists;
+import cn.enilu.flash.utils.Maps;
+import org.nutz.json.Json;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -27,13 +29,51 @@ public class CartController extends BaseController {
     private IdsService idsService;
     @RequestMapping(value = "/v1/carts/checkout",method = RequestMethod.POST)
     public Object checkout(HttpServletRequest request){
+
         Map data = getRequestPayload(Map.class);
+        System.out.println(Json.toJson(data));
+        String from = data.get("geohash").toString();
+        Long restaurantId = Long.valueOf(data.get("restaurant_id").toString());
+        Carts carts = new Carts();
+        List<Payment> paymentList = mongoRepository.findAll(Payment.class);
+        Shop shop = mongoRepository.findOne(Shop.class,restaurantId);
+        String to =  shop.getLatitude()+","+shop.getLongitude();
+        carts.setId(idsService.getId(Ids.CART_ID));
+        carts.setPayments(paymentList);
+        carts.setSig(String.valueOf(Math.ceil(Math.random()*1000000)));
+        carts.setInvoice(Maps.newHashMap("status_text","不需要开发票","is_available",true));
+
+        Cart cart = new Cart();
+        cart.setId(carts.getId());
+        cart.setRestaurant_id(restaurantId);
+        cart.setRestaurant_info(shop);
+        cart.setDeliver_amount(4);
+        List<List> entities = (List<List>) data.get("entities");
+        List<List> groups = Lists.newArrayList(Lists.newArrayList());
+        BigDecimal total = new BigDecimal(0);
+        for(int i=0;i<entities.get(0).size();i++){
+            Map map = (Map) entities.get(0).get(i);
+            Map items = Maps.newHashMap();
+            items.put("id",Long.valueOf(map.get("id").toString()));
+            items.put("name",map.get("name"));
+            items.put("packing_fee",map.get("packing_fee"));
+            items.put("price",map.get("price"));
+            items.put("quantity",map.get("quantity"));
+
+            total = total.add(new BigDecimal(items.get("price").toString()).multiply(new BigDecimal(items.get("quantity").toString())));
+
+            groups.get(0).add(items);
+        }
+        cart.setTotal(total.toPlainString());
+        cart.setGroups(groups);
+        carts.setCart(cart);
         data.put("id",idsService.getId(Ids.CATEGORY_ID));
-        mongoRepository.save(data,"carts");
-        return  null;
+        //todo 暂时不保存,开发中
+//        mongoRepository.save(data,"carts");
+        return  Rets.success(carts);
     }
-    @RequestMapping(value = "v1/carts/${cart_id}/remarks",method = RequestMethod.GET)
-    public Object remarks(@PathVariable("cart_id")Long cartId){
+    @RequestMapping(value = "/v1/carts/{cart_id}/remarks",method = RequestMethod.GET)
+    public Object remarks(@PathVariable("cart_id")Long cartId, @RequestParam(value = "sig",required = false) String sig){
         return Rets.success(mongoRepository.findOne("remarks"));
     }
 }

+ 3 - 0
flash-waimai-api/src/main/resources/application-dev.properties

@@ -19,5 +19,8 @@ cfg.tencentkey=RLHBZ-WMPRP-Q3JDS-V2IQA-JNRFH-EJBHL
 cfg.tencentkey2=RRXBZ-WC6KF-ZQSJT-N2QU7-T5QIT-6KF5X
 cfg.tencentkey3=OHTBZ-7IFRG-JG2QF-IHFUK-XTTK6-VXFBN
 
+cfg.baidukey=fjke3YUipM9N64GdOIh1DNeK2APO2WcT
+cfg.baidukey2=fjke3YUipM9N64GdOIh1DNeK2APO2WcT
+
 ## api
 api.qq.map.url=https://apis.map.qq.com/ws/

+ 1 - 1
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/Address.java

@@ -10,7 +10,7 @@ import java.util.Date;
 /**
  * Created  on 2018/1/5 0005.
  *
- * @author zt
+ * @author enilu.cn
  */
 @Document(collection = "addresses")
 public class Address extends BaseMongoEntity{

+ 39 - 0
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/Cart.java

@@ -0,0 +1,39 @@
+package cn.enilu.flash.bean.entity.front;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author :enilu.cn
+ * @date :Created in 2019/10/18 22:46
+ */
+@Data
+public class Cart {
+    private Long id;
+    private List groups;
+    private List extra;
+    private Integer deliver_amount;
+    private String deliver_time;
+    private String discount_amount;
+    private String dist_info;
+    private Boolean is_address_too_far=false;
+    private Boolean is_deliver_by_fengniao;
+    private Integer is_online_paid=1;
+    private Integer is_ontime_available=0;
+    private Integer must_new_user=0;
+    private Integer must_pay_online=0;
+    private Integer ontime_status=0;
+    private String ontime_unavailable_reason;
+    private Integer original_total;
+    private String phone;
+    private Integer  promise_delivery_time=0;
+    private Long restaurant_id;
+    private Shop restaurant_info;
+    private Integer restaurant_minimum_order_amount;
+    private String restaurant_name_for_url;
+    private Integer restaurant_status=1;
+    private Integer service_fee_explanation=0;
+    private String total;
+    private Long user_id;
+}

+ 46 - 0
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/Carts.java

@@ -0,0 +1,46 @@
+package cn.enilu.flash.bean.entity.front;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author :enilu.cn
+ * @date :Created in 2019/10/18 22:40
+ */
+@Document(collection = "carts")
+@Data
+public class Carts extends BaseMongoEntity {
+    @Id
+    private String _id;
+    private Long id;
+    //到达时间
+    private String delivery_reach_time;
+    private String sig;
+    private Integer is_support_ninja=1;
+    private Boolean is_support_coupon = false;
+    private Cart cart;
+    //发票信息
+    private Map invoice;
+    private Map currrent_address;
+    private List<Payment> payments;
+
+
+
+
+    //必须在setget方法加上该注释,否则_id值会覆盖在id上
+    @JSONField(name="_id")
+    public String get_id() {
+        return _id;
+    }
+    @JSONField(name="_id")
+    public void set_id(String _id) {
+        this._id = _id;
+    }
+
+
+}

+ 37 - 0
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/Payment.java

@@ -0,0 +1,37 @@
+package cn.enilu.flash.bean.entity.front;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.List;
+
+/**
+ * @author :enilu.cn
+ * @date :Created in 2019/10/18 22:54
+ */
+@Document(collection = "payments")
+@Data
+public class Payment {
+    @Id
+    private String _id;
+    private String description;
+    private String disabled_reason;
+    private Long id;
+    private Boolean is_online_payment=true;
+    private String name;
+    private List promotion;
+    private Integer select_state;
+
+
+    @JSONField(name="_id")
+    public String get_id() {
+        return _id;
+    }
+    @JSONField(name="_id")
+    public void set_id(String _id) {
+        this._id = _id;
+    }
+
+}

+ 3 - 0
flash-waimai-core/src/main/java/cn/enilu/flash/service/front/PositionService.java

@@ -167,4 +167,7 @@ public class PositionService {
         return result;
     }
 
+    public void getDistance(String from,String to){
+
+    }
 }

+ 263 - 0
flash-waimai-mobile/src/page/confirmOrder/confirmOrder.scss

@@ -0,0 +1,263 @@
+@import 'src/style/mixin';
+
+.confirmOrderContainer{
+  padding-top: 1.95rem;
+  padding-bottom: 3rem;
+p, span{
+  font-family: Helvetica Neue,Tahoma,Arial;
+}
+}
+.container_style{
+  background-color: #fff;
+  margin-top: .4rem;
+  padding: 0 .7rem;
+}
+.address_container{
+  min-height: 3.5rem;
+@include fj;
+  align-items: center;
+  padding: 0 0.6rem;
+  background: url(../../images/address_bottom.png) left bottom repeat-x;
+  background-color: #fff;
+  background-size: auto .12rem;
+.address_empty_left{
+  display: flex;
+  align-items: center;
+.location_icon{
+@include wh(.8rem, .8rem);
+  fill: $blue;
+  margin-right: .2rem;
+}
+.add_address{
+@include sc(.7rem, #333);
+}
+.address_detail_container{
+  margin-left: .2rem;
+header{
+@include sc(.65rem, #333);
+span:nth-of-type(1){
+  font-size: .8rem;
+  font-weight: bold;
+}
+}
+.address_detail{
+  width: 100%;
+  display: flex;
+  align-items: center;
+span{
+@include sc(.5rem, #fff);
+  border-radius: .15rem;
+  background-color: #ff5722;
+  height: .6rem;
+  line-height: .6rem;
+  padding: 0 .2rem;
+  margin-right: .3rem;
+}
+p{
+@include sc(.55rem, #777);
+}
+}
+}
+}
+}
+.address_empty_right{
+@include wh(.6rem, .6rem);
+  fill: #999;
+}
+.delivery_model{
+  border-left: .2rem solid $blue;
+  min-height: 4rem;
+@include fj;
+  align-items: center;
+.deliver_text{
+@include sc(.8rem, #333);
+  font-weight: bold;
+  padding-left: .3rem;
+}
+.deliver_time{
+  display: flex;
+  flex-direction: column;
+  align-items: flex-end;
+p:nth-of-type(1){
+@include sc(.7rem, $blue);
+}
+p:nth-of-type(2){
+@include sc(.5rem, #fff);
+  background-color: $blue;
+  width: 2.4rem;
+  margin-top: .5rem;
+  text-align: center;
+  border-radius: 0.12rem;
+  padding: .1rem;
+}
+}
+}
+.pay_way{
+.header_style{
+@include fj;
+  line-height: 2rem;
+span:nth-of-type(1){
+@include sc(.7rem, #666);
+}
+.more_type{
+span:nth-of-type(1){
+@include sc(.6rem, #aaa);
+  width: 10rem;
+  display: inline-block;
+  text-align: right;
+  vertical-align: middle;
+}
+svg{
+@include wh(.5rem, .5rem);
+  fill: #ccc;
+}
+}
+}
+.hongbo{
+@include fj;
+  border-top: 0.025rem solid #f5f5f5;
+span{
+@include sc(.6rem, #aaa);
+  line-height: 2rem;
+svg{
+@include wh(.5rem, .5rem);
+  vertical-align: middle;
+  fill: #ccc;
+}
+}
+span:nth-of-type(2){
+  color: #aaa;
+}
+}
+.support_is_available{
+span{
+  color: #666;
+}
+}
+}
+.food_list{
+  background-color: #fff;
+  margin-top: .4rem;
+header{
+  padding: .7rem;
+  border-bottom: 0.025rem solid #f5f5f5;
+img{
+@include wh(1.2rem, 1.2rem);
+  vertical-align: middle;
+}
+span{
+@include sc(.8rem, #333);
+}
+}
+.food_list_ul{
+  padding-top: .5rem;
+}
+.food_item_style{
+@include fj;
+  line-height: 1.8rem;
+  padding: 0 .7rem;
+span,p{
+@include sc(.65rem, #666);
+}
+.food_name{
+  width: 11rem;
+}
+.num_price{
+  flex: 1;
+@include fj;
+  align-items: center;
+span:nth-of-type(1){
+  color: #f60;
+}
+}
+}
+.total_price{
+  border-top: 0.025rem solid #f5f5f5;
+}
+}
+.confrim_order{
+  display: flex;
+  position: fixed;
+  bottom: 0;
+  width: 100%;
+  height: 2rem;
+p{
+  line-height: 2rem;
+@include sc(.75rem, #fff);
+}
+p:nth-of-type(1){
+  background-color: #3c3c3c;
+  flex: 5;
+  padding-left: .7rem;
+}
+p:nth-of-type(2){
+  flex: 2;
+  background-color: #56d176;
+  text-align: center;
+}
+}
+.cover{
+  position: fixed;
+  top: 0;
+  bottom: 0;
+  left: 0;
+  right: 0;
+  background-color: rgba(0,0,0,.3);
+  z-index: 203;
+}
+.choose_type_Container{
+  min-height: 10rem;
+  background-color: #fff;
+  position: fixed;
+  bottom: 0;
+  width: 100%;
+  z-index: 204;
+header{
+  background-color: #fafafa;
+@include sc(.7rem, #333);
+  text-align: center;
+  line-height: 2rem;
+}
+ul{
+li{
+@include fj;
+  padding: 0 .7rem;
+  line-height: 2.5rem;
+  align-items: center;
+span{
+@include sc(.7rem, #ccc);
+}
+svg{
+@include wh(.8rem, .8rem);
+  fill: #eee;
+}
+}
+.choose{
+span{
+  color: #333;
+}
+svg{
+  fill: #4cd964;
+}
+}
+}
+}
+.fade-enter-active, .fade-leave-active {
+  transition: opacity .3s;
+}
+.fade-enter, .fade-leave-active {
+  opacity: 0;
+}
+.slid_up-enter-active, .slid_up-leave-active {
+  transition: all .3s;
+}
+.slid_up-enter, .slid_up-leave-active {
+  transform: translate3d(0,10rem,0)
+}
+.router-slid-enter-active, .router-slid-leave-active {
+  transition: all .4s;
+}
+.router-slid-enter, .router-slid-leave-active {
+  transform: translate3d(2rem, 0, 0);
+  opacity: 0;
+}

+ 2 - 437
flash-waimai-mobile/src/page/confirmOrder/confirmOrder.vue

@@ -130,440 +130,5 @@
     </div>
 </template>
 
-<script>
-    import {mapState, mapMutations} from 'vuex'
-    import headTop from 'src/components/header/head'
-    import alertTip from 'src/components/common/alertTip'
-    import loading from 'src/components/common/loading'
-    import {checkout, getAddress, placeOrders, getAddressList} from 'src/service/getData'
-    import {imgBaseUrl} from 'src/config/env'
-
-    export default {
-        data(){
-            return {
-                geohash: '', //geohash位置信息
-                shopId: null, //商店id值
-                showLoading: true, //显示加载动画
-                checkoutData: null,//数据返回值
-                shopCart: null,//购物车数据
-                imgBaseUrl, //图片域名
-                showPayWay: false,//显示付款方式
-                payWayId: 1, //付款方式
-                showAlert: false, //弹出框
-                alertText: null, //弹出框内容
-            }
-        },
-        created(){
-            //获取上个页面传递过来的geohash值
-            this.geohash = this.$route.query.geohash;
-            //获取上个页面传递过来的shopid值
-            this.shopId = this.$route.query.shopId;
-            this.INIT_BUYCART();
-            this.SAVE_SHOPID(this.shopId);
-            //获取当前商铺购物车信息
-            this.shopCart = this.cartList[this.shopId];
-        },
-        mounted(){
-            if (this.geohash) {
-                this.initData();
-                this.SAVE_GEOHASH(this.geohash);
-            }
-            if (!(this.userInfo && this.userInfo.user_id)) {
-                // this.showAlert = true;
-                // this.alertText = '您还没有登录';
-            }
-        },
-        components: {
-            headTop,
-            alertTip,
-            loading,
-        },
-        computed: {
-            ...mapState([
-                'cartList', 'remarkText', 'inputText', 'invoice', 'choosedAddress', 'userInfo'
-            ]),
-            //备注页返回的信息进行处理
-            remarklist: function (){
-                let str = new String;
-                if (this.remarkText) {
-                    Object.values(this.remarkText).forEach(item => {
-                        str += item[1] + ',';
-                    })
-                }
-                //是否有自定义备注,分开处理
-                if (this.inputText) {
-                    return str + this.inputText;
-                }else{
-                    return str.substr(0, str.lastIndexOf(',')) ;
-                }
-            },
-        },
-        methods: {
-            ...mapMutations([
-                'INIT_BUYCART', 'SAVE_GEOHASH', 'CHOOSE_ADDRESS', 'NEED_VALIDATION', 'SAVE_CART_ID_SIG', 'SAVE_ORDER_PARAM', 'ORDER_SUCCESS', 'SAVE_SHOPID'
-            ]),
-            //初始化数据
-            async initData(){
-                let newArr = new Array;
-                Object.values(this.shopCart).forEach(categoryItem => {
-                    Object.values(categoryItem).forEach(itemValue=> {
-                        Object.values(itemValue).forEach(item => {
-                            newArr.push({
-                                attrs: [],
-                                extra: {},
-                                id: item.id,
-                                name: item.name,
-                                packing_fee: item.packing_fee,
-                                price: item.price,
-                                quantity: item.num,
-                                sku_id: item.sku_id,
-                                specs: [item.specs],
-                                stock: item.stock,
-                            })
-                        })
-                    })
-                })
-                //检验订单是否满足条件
-                this.checkoutData = await checkout(this.geohash, [newArr], this.shopId);
-                this.SAVE_CART_ID_SIG({cart_id: this.checkoutData.cart.id, sig:  this.checkoutData.sig})
-                this.initAddress();
-                this.showLoading = false;
-            },
-            //获取地址信息,第一个地址为默认选择地址
-            async initAddress(){
-                if (this.userInfo && this.userInfo.user_id) {
-                    const addressRes = await getAddressList(this.userInfo.user_id);
-                    if (addressRes instanceof Array && addressRes.length) {
-                        this.CHOOSE_ADDRESS({address: addressRes[0], index: 0});
-                    }
-                }
-            },
-            //显示付款方式
-            showPayWayFun(){
-                this.showPayWay = !this.showPayWay;
-            },
-            //选择付款方式
-            choosePayWay(is_online_payment, id){
-                if (is_online_payment) {
-                    this.showPayWay = !this.showPayWay;
-                    this.payWayId = id;
-                }
-            },
-            //地址备注颜色
-            iconColor(name){
-                switch(name){
-                    case '公司': return '#4cd964';
-                    case '学校': return '#3190e8';
-                }
-            },
-            //确认订单
-            async confrimOrder(){
-                //用户未登录时弹出提示框
-                if (!(this.userInfo && this.userInfo.user_id)) {
-                    this.showAlert = true;
-                    this.alertText = '请登录';
-                    return
-                    //未选择地址则提示
-                }else if(!this.choosedAddress){
-                    this.showAlert = true;
-                    this.alertText = '请添加一个收货地址';
-                    return
-                }
-                //保存订单
-                this.SAVE_ORDER_PARAM({
-                    user_id: this.userInfo.user_id,
-                    cart_id: this.checkoutData.cart.id,
-                    address_id: this.choosedAddress.id,
-                    description: this.remarklist,
-                    entities: this.checkoutData.cart.groups,
-                    geohash: this.geohash,
-                    sig: this.checkoutData.sig,
-                });
-                //发送订单信息
-                let orderRes = await placeOrders(this.userInfo.user_id, this.checkoutData.cart.id, this.choosedAddress.id, this.remarklist, this.checkoutData.cart.groups, this.geohash, this.checkoutData.sig);
-                //第一次下单的手机号需要进行验证,否则直接下单成功
-                if (orderRes.need_validation) {
-                    this.NEED_VALIDATION(orderRes);
-                    this.$router.push('/confirmOrder/userValidation');
-                }else{
-                    this.ORDER_SUCCESS(orderRes);
-                    this.$router.push('/confirmOrder/payment');
-                }
-            },
-        },
-        watch: {
-            userInfo: function (value) {
-                if (value && value.user_id) {
-                    this.initAddress();
-                }
-            },
-        }
-    }
-
-</script>
-
-<style lang="scss" scoped>
-    @import 'src/style/mixin';
-
-    .confirmOrderContainer{
-        padding-top: 1.95rem;
-        padding-bottom: 3rem;
-        p, span{
-            font-family: Helvetica Neue,Tahoma,Arial;
-        }
-    }
-    .container_style{
-        background-color: #fff;
-        margin-top: .4rem;
-        padding: 0 .7rem;
-    }
-    .address_container{
-        min-height: 3.5rem;
-        @include fj;
-        align-items: center;
-        padding: 0 0.6rem;
-        background: url(../../images/address_bottom.png) left bottom repeat-x;
-        background-color: #fff;
-        background-size: auto .12rem;
-        .address_empty_left{
-            display: flex;
-            align-items: center;
-            .location_icon{
-                @include wh(.8rem, .8rem);
-                fill: $blue;
-                margin-right: .2rem;
-            }
-            .add_address{
-                @include sc(.7rem, #333);
-            }
-            .address_detail_container{
-                margin-left: .2rem;
-                header{
-                    @include sc(.65rem, #333);
-                    span:nth-of-type(1){
-                        font-size: .8rem;
-                        font-weight: bold;
-                    }
-                }
-                .address_detail{
-                    width: 100%;
-                    display: flex;
-                    align-items: center;
-                    span{
-                        @include sc(.5rem, #fff);
-                        border-radius: .15rem;
-                        background-color: #ff5722;
-                        height: .6rem;
-                        line-height: .6rem;
-                        padding: 0 .2rem;
-                        margin-right: .3rem;
-                    }
-                    p{
-                        @include sc(.55rem, #777);
-                    }
-                }
-            }
-        }
-    }
-    .address_empty_right{
-        @include wh(.6rem, .6rem);
-        fill: #999;
-    }
-    .delivery_model{
-        border-left: .2rem solid $blue;
-        min-height: 4rem;
-        @include fj;
-        align-items: center;
-        .deliver_text{
-            @include sc(.8rem, #333);
-            font-weight: bold;
-            padding-left: .3rem;
-        }
-        .deliver_time{
-            display: flex;
-            flex-direction: column;
-            align-items: flex-end;
-            p:nth-of-type(1){
-                @include sc(.7rem, $blue);
-            }
-            p:nth-of-type(2){
-                @include sc(.5rem, #fff);
-                background-color: $blue;
-                width: 2.4rem;
-                margin-top: .5rem;
-                text-align: center;
-                border-radius: 0.12rem;
-                padding: .1rem;
-            }
-        }
-    }
-    .pay_way{
-        .header_style{
-            @include fj;
-            line-height: 2rem;
-            span:nth-of-type(1){
-                @include sc(.7rem, #666);
-            }
-            .more_type{
-                span:nth-of-type(1){
-                    @include sc(.6rem, #aaa);
-                    width: 10rem;
-                    display: inline-block;
-                    text-align: right;
-                    vertical-align: middle;
-                }
-                svg{
-                    @include wh(.5rem, .5rem);
-                    fill: #ccc;
-                }
-            }
-        }
-        .hongbo{
-            @include fj;
-            border-top: 0.025rem solid #f5f5f5;
-            span{
-                @include sc(.6rem, #aaa);
-                line-height: 2rem;
-                svg{
-                    @include wh(.5rem, .5rem);
-                    vertical-align: middle;
-                    fill: #ccc;
-                }
-            }
-            span:nth-of-type(2){
-                color: #aaa;
-            }
-        }
-        .support_is_available{
-            span{
-                color: #666;
-            }
-        }
-    }
-    .food_list{
-        background-color: #fff;
-        margin-top: .4rem;
-        header{
-            padding: .7rem;
-            border-bottom: 0.025rem solid #f5f5f5;
-            img{
-                @include wh(1.2rem, 1.2rem);
-                vertical-align: middle;
-            }
-            span{
-                @include sc(.8rem, #333);
-            }
-        }
-        .food_list_ul{
-            padding-top: .5rem;
-        }
-        .food_item_style{
-            @include fj;
-            line-height: 1.8rem;
-            padding: 0 .7rem;
-            span,p{
-                @include sc(.65rem, #666);
-            }
-            .food_name{
-                width: 11rem;
-            }
-            .num_price{
-                flex: 1;
-                @include fj;
-                align-items: center;
-                span:nth-of-type(1){
-                    color: #f60;
-                }
-            }
-        }
-        .total_price{
-            border-top: 0.025rem solid #f5f5f5;
-        }
-    }
-    .confrim_order{
-        display: flex;
-        position: fixed;
-        bottom: 0;
-        width: 100%;
-        height: 2rem;
-        p{
-            line-height: 2rem;
-            @include sc(.75rem, #fff);
-        }
-        p:nth-of-type(1){
-            background-color: #3c3c3c;
-            flex: 5;
-            padding-left: .7rem;
-        }
-        p:nth-of-type(2){
-            flex: 2;
-            background-color: #56d176;
-            text-align: center;
-        }
-    }
-    .cover{
-        position: fixed;
-        top: 0;
-        bottom: 0;
-        left: 0;
-        right: 0;
-        background-color: rgba(0,0,0,.3);
-        z-index: 203;
-    }
-    .choose_type_Container{
-        min-height: 10rem;
-        background-color: #fff;
-        position: fixed;
-        bottom: 0;
-        width: 100%;
-        z-index: 204;
-        header{
-            background-color: #fafafa;
-            @include sc(.7rem, #333);
-            text-align: center;
-            line-height: 2rem;
-        }
-        ul{
-            li{
-                @include fj;
-                padding: 0 .7rem;
-                line-height: 2.5rem;
-                align-items: center;
-                span{
-                    @include sc(.7rem, #ccc);
-                }
-                svg{
-                    @include wh(.8rem, .8rem);
-                    fill: #eee;
-                }
-            }
-            .choose{
-                span{
-                    color: #333;
-                }
-                svg{
-                    fill: #4cd964;
-                }
-            }
-        }
-    }
-    .fade-enter-active, .fade-leave-active {
-        transition: opacity .3s;
-    }
-    .fade-enter, .fade-leave-active {
-        opacity: 0;
-    }
-    .slid_up-enter-active, .slid_up-leave-active {
-        transition: all .3s;
-    }
-    .slid_up-enter, .slid_up-leave-active {
-        transform: translate3d(0,10rem,0)
-    }
-    .router-slid-enter-active, .router-slid-leave-active {
-        transition: all .4s;
-    }
-    .router-slid-enter, .router-slid-leave-active {
-        transform: translate3d(2rem, 0, 0);
-        opacity: 0;
-    }
-</style>
+<script src="./index.js"></script>
+<style rel="stylesheet/scss" lang="scss" src="./confirmOrder.scss"></style>

+ 180 - 0
flash-waimai-mobile/src/page/confirmOrder/index.js

@@ -0,0 +1,180 @@
+
+import {mapState, mapMutations} from 'vuex'
+import headTop from 'src/components/header/head'
+import alertTip from 'src/components/common/alertTip'
+import loading from 'src/components/common/loading'
+import {checkout, getAddress, placeOrders, getAddressList} from 'src/service/getData'
+import {imgBaseUrl} from 'src/config/env'
+
+export default {
+  data(){
+    return {
+      geohash: '', //geohash位置信息
+      shopId: null, //商店id值
+      showLoading: true, //显示加载动画
+      checkoutData: null,//数据返回值
+      shopCart: null,//购物车数据
+      imgBaseUrl, //图片域名
+      showPayWay: false,//显示付款方式
+      payWayId: 1, //付款方式
+      showAlert: false, //弹出框
+      alertText: null, //弹出框内容
+    }
+  },
+  created(){
+    //获取上个页面传递过来的geohash值
+    this.geohash = this.$route.query.geohash;
+    //获取上个页面传递过来的shopid值
+    this.shopId = this.$route.query.shopId;
+    this.INIT_BUYCART();
+    this.SAVE_SHOPID(this.shopId);
+    //获取当前商铺购物车信息
+    this.shopCart = this.cartList[this.shopId];
+  },
+  mounted(){
+    if (this.geohash) {
+      this.initData();
+      this.SAVE_GEOHASH(this.geohash);
+    }
+    if (!(this.userInfo && this.userInfo.user_id)) {
+      // this.showAlert = true;
+      // this.alertText = '您还没有登录';
+    }
+  },
+  components: {
+    headTop,
+    alertTip,
+    loading,
+  },
+  computed: {
+    ...mapState([
+      'cartList', 'remarkText', 'inputText', 'invoice', 'choosedAddress', 'userInfo'
+    ]),
+    //备注页返回的信息进行处理
+    remarklist: function (){
+      let str = new String;
+      if (this.remarkText) {
+        Object.values(this.remarkText).forEach(item => {
+          str += item[1] + ',';
+        })
+      }
+      //是否有自定义备注,分开处理
+      if (this.inputText) {
+        return str + this.inputText;
+      }else{
+        return str.substr(0, str.lastIndexOf(',')) ;
+      }
+    },
+  },
+  methods: {
+    ...mapMutations([
+      'INIT_BUYCART', 'SAVE_GEOHASH', 'CHOOSE_ADDRESS', 'NEED_VALIDATION', 'SAVE_CART_ID_SIG', 'SAVE_ORDER_PARAM', 'ORDER_SUCCESS', 'SAVE_SHOPID'
+    ]),
+    //初始化数据
+    async initData(){
+      let newArr = new Array;
+      console.log('shopCart',this.shopCart)
+      Object.values(this.shopCart).forEach(categoryItem => {
+        console.log(1)
+        Object.values(categoryItem).forEach(itemValue=> {
+          console.log(2)
+          Object.values(itemValue).forEach(item => {
+            console.log(3)
+            newArr.push({
+              attrs: [],
+              extra: {},
+              id: item.id,
+              name: item.name,
+              packing_fee: item.packing_fee,
+              price: item.price,
+              quantity: item.num,
+              sku_id: item.sku_id,
+              specs: [item.specs],
+              stock: item.stock,
+            })
+            console.log(4,newArr)
+          })
+        })
+      })
+      console.log(5)
+      //检验订单是否满足条件
+
+      this.checkoutData = await checkout(this.geohash, [newArr], this.shopId);
+      console.log(7)
+      this.SAVE_CART_ID_SIG({cart_id: this.checkoutData.cart.id, sig:  this.checkoutData.sig})
+      console.log(8)
+      this.initAddress();
+      console.log(9)
+      this.showLoading = false;
+      console.log(10)
+    },
+    //获取地址信息,第一个地址为默认选择地址
+    async initAddress(){
+      if (this.userInfo && this.userInfo.user_id) {
+        const addressRes = await getAddressList(this.userInfo.user_id);
+        if (addressRes instanceof Array && addressRes.length) {
+          this.CHOOSE_ADDRESS({address: addressRes[0], index: 0});
+        }
+      }
+    },
+    //显示付款方式
+    showPayWayFun(){
+      this.showPayWay = !this.showPayWay;
+    },
+    //选择付款方式
+    choosePayWay(is_online_payment, id){
+      if (is_online_payment) {
+        this.showPayWay = !this.showPayWay;
+        this.payWayId = id;
+      }
+    },
+    //地址备注颜色
+    iconColor(name){
+      switch(name){
+        case '公司': return '#4cd964';
+        case '学校': return '#3190e8';
+      }
+    },
+    //确认订单
+    async confrimOrder(){
+      //用户未登录时弹出提示框
+      if (!(this.userInfo && this.userInfo.user_id)) {
+        this.showAlert = true;
+        this.alertText = '请登录';
+        return
+        //未选择地址则提示
+      }else if(!this.choosedAddress){
+        this.showAlert = true;
+        this.alertText = '请添加一个收货地址';
+        return
+      }
+      //保存订单
+      this.SAVE_ORDER_PARAM({
+        user_id: this.userInfo.user_id,
+        cart_id: this.checkoutData.cart.id,
+        address_id: this.choosedAddress.id,
+        description: this.remarklist,
+        entities: this.checkoutData.cart.groups,
+        geohash: this.geohash,
+        sig: this.checkoutData.sig,
+      });
+      //发送订单信息
+      let orderRes = await placeOrders(this.userInfo.user_id, this.checkoutData.cart.id, this.choosedAddress.id, this.remarklist, this.checkoutData.cart.groups, this.geohash, this.checkoutData.sig);
+      //第一次下单的手机号需要进行验证,否则直接下单成功
+      if (orderRes.need_validation) {
+        this.NEED_VALIDATION(orderRes);
+        this.$router.push('/confirmOrder/userValidation');
+      }else{
+        this.ORDER_SUCCESS(orderRes);
+        this.$router.push('/confirmOrder/payment');
+      }
+    },
+  },
+  watch: {
+    userInfo: function (value) {
+      if (value && value.user_id) {
+        this.initAddress();
+      }
+    },
+  }
+}

+ 0 - 5
flash-waimai-mobile/src/page/shop/index.js

@@ -115,19 +115,14 @@ export default {
       }
       //获取商铺信息
       this.shopDetailData = await shopDetails(this.shopId, this.latitude, this.longitude);
-      console.log('shopDetailData',this.shopDetailData)
       //获取商铺食品列表
       this.menuList = await foodMenu(this.shopId);
-      console.log('menuList',this.menuList)
       //评论列表
       this.ratingList = await getRatingList(this.shopId, this.ratingOffset);
-      console.log('ratingList',this.ratingList)
       //商铺评论详情
       this.ratingScoresData = await ratingScores(this.shopId);
-      console.log('ratingScoreData',this.ratingScoresData)
       //评论Tag列表
       this.ratingTagsList = await ratingTags(this.shopId);
-      console.log('ratingTagsList',this.ratingTagsList)
       this.RECORD_SHOPDETAIL(this.shopDetailData)
       //隐藏加载动画
       this.hideLoading();