订单成功页面

2020-05-13  本文已影响0人  是新来的啊强呀

前端,src/views/OrderSuccess.vue

<template>
  <div>
...
    <div class="container">
      <div class="order-create">
        <div class="order-create-pic"><img src="/static/ok-2.png" alt=""></div>
        <div class="order-create-main">
          <h3>Congratulations! <br>Your order is under processing!</h3>
          <p>
            <span>Order ID:{{orderId}}</span>
            <span>Order total:{{orderTotal|currency('$')}}</span>
          </p>
          <div class="order-create-btn-wrap">
            <div class="btn-l-wrap">
              <router-link class="btn btn--m" to="/cart">Cart List</router-link>
            </div>
            <div class="btn-r-wrap">
              <router-link class="btn btn--m" to="/goods">Goods List</router-link>
            </div>
          </div>
        </div>
      </div>
    </div>
...
  </div>
</template>
<script>
  import NavHeader from './../components/NavHeader'
  import NavFooter from './../components/NavFooter'
  import NavBread from './../components/NavBread'
  import {currency} from './../util/currency'
  import axios from 'axios'
  export default{
    data(){
      return{
        orderId:'',
        orderTotal:0
      }
    },
    components:{
      NavHeader,
      NavFooter,
      NavBread
    },
    filters:{
      currency:currency
    },
    mounted(){
// 使用订单Id去获取订单总金额
      var orderId = this.$route.query.orderId;
      console.log("orderId:"+orderId);
      if(!orderId){
        return;
      }
      axios.get("/users/orderDetail",{
        params:{
          orderId:orderId
        }
      }).then((response)=>{
        let res = response.data;
        if(res.status=='0'){
          this.orderId = orderId;
          this.orderTotal = res.result.orderTotal;
        }
      });
    }
  }
</script>

后端,根据订单Id去查询订单信息接口

//根据订单Id查询订单信息
router.get("/orderDetail", function (req,res,next) {
  var userId = req.cookies.userId,orderId = req.param("orderId");
  User.findOne({userId:userId}, function (err,userInfo) {
    if(err){
      res.json({
        status:'1',
        msg:err.message,
        result:''
      });
    }else{
      var orderList = userInfo.orderList;
      if(orderList.length>0){
        var orderTotal = 0;
        orderList.forEach((item)=>{
          if(item.orderId == orderId){
            orderTotal = item.orderTotal;
          }
        });
        if(orderTotal>0){
          res.json({
            status:'0',
            msg:'',
            result:{
              orderId:orderId,
              orderTotal:orderTotal
            }
          })
        }else{
          res.json({
            status:'120002',
            msg:'无此订单',
            result:''
          });
        }
      }else{
        res.json({
          status:'120001',
          msg:'当前用户未创建订单',
          result:''
        });
      }
    }
  })
});
上一篇下一篇

猜你喜欢

热点阅读