美文网首页
订单成功页面功能实现

订单成功页面功能实现

作者: 飞飞廉 | 来源:发表于2018-01-05 17:10 被阅读0次
image.png

1、获取订单详情

首先从页面的url中获取orderId(上个页面传过来的),然后将orderId的参数传过去,然后从后端获取订单详情的orderTotal

 mounted(){
          this.orderId=this.$route.query.orderId;
          axios.get('users/orderDetail',{
            params:{
              orderId:this.orderId
            }
          }).then((response)=>{
            let res=response.data;
            if(res.status=='0'){
              this.orderId=res.result.orderId;
              this.orderTotal=res.result.orderTotal;
            }
          })
        }

后端订单详情:
找到用户信息后,遍历orderList的订单列表,找到对应orderId的订单,将此订单的orderTotal记录下来,传到前端去,做了很多逻辑判断,严谨一下。

router.get('/orderDetail',(req,res,next)=>{
    let userId=req.cookies.userId;
    let orderId=req.param("orderId");
    let orderTotal=0;
    User.findOne({userId:userId},(err,doc)=>{
        if(err){
            res.json({
                status:'1',
                msg:err.message,
                result:''
            })
        }else{
            if(doc.orderList<1){
                res.json({
                    status:'100001',
                    msg:'未找到订单',
                    result:''
                })
            }else{
                doc.orderList.forEach((item)=>{
                    if(item.orderId==orderId){
                        orderTotal=item.orderTotal;
                    }
                })
                if(orderTotal==0){
                    res.json({
                        status:'1000002',
                        msg:'订单金额为0',
                        result:''
                    })
                }else{
                    res.json({
                        status:'0',
                        msg:'suc',
                        result:{
                            orderId:orderId,
                            orderTotal:orderTotal
                        }
                    })
                }
            }
        }
        
    })
})

相关文章

网友评论

      本文标题:订单成功页面功能实现

      本文链接:https://www.haomeiwen.com/subject/jwysnxtx.html