Pay.vue
<template> <!--视频信息--> <div> <div class="info"> <p class="info_title">商品信息</p> <div class="box"> <div class="imgdiv"> <img :src="videoinfo.cover_img" alt="课程照片" /> </div> <div class="txtdiv"> <p class="c_title">{{videoinfo.title}}</p> <p class="price">¥: {{(videoinfo.price/100).toFixed(2)}}</p> </div> </div> </div> <!--底部支付--> <div class="footer"> <p class="money">实付 {{(videoinfo.price/100).toFixed(2)}}</p> <p class="submit" @click="pay">立刻支付</p> </div> </div> </template> <script> import { getVideoDetail, saveOrder } from "@/api/getData.js"; export default { data() { return { videoinfo: {} }; }, methods: { //获取视频详情 async getDetail(vid) { try { const result = await getVideoDetail(vid); if (result.data.code == 0) { this.videoinfo = result.data.data; } } catch (err) { console.log(err); } }, //下单 async pay() { try { const result = await saveOrder( this.$store.state.token, this.$route.query.video_id ); if (result.data.code == 0) { const toast = this.$createToast({ txt: "购买成功", type: "correct", time: 2000, onTimeout: () => { this.$router.push({ path: "/order" }); } }); toast.show(); }else{ const toast = this.$createToast({ txt: `${result.data.msg}`, type: "correct", time: 2000 }); toast.show(); } } catch (err) { console.log(err); } } }, mounted() { this.getDetail(this.$route.query.video_id); } }; </script> <style lang="scss" scoped> // 视频标题 .info_title { padding: 10px 20px; background-color: #fff; border-bottom: 1px solid #d9dde1; } .box { background-color: #fff; box-sizing: border-box; padding: 20px; display: flex; margin-bottom: 15px; .imgdiv { 105px; height: 59px; flex-shrink: 0; img { 100%; height: 100%; } } .textdiv { margin-left: 20px; height: 59px; flex-grow: 1; display: flex; flex-direction: column; justify-content: space-between; .price { flex-shrink: 0; } } } //底部 .footer { position: fixed; bottom: 0; 100%; height: 50px; background-color: #fff; display: flex; justify-content: space-between; box-shadow: 0 -2px 4px 0 rgba(0, 0, 0, 0.1); font-size: 16px; .money { height: 50px; line-height: 50px; flex: 2; text-align: center; background-color: #fff; } .submit { height: 50px; line-height: 50px; flex: 1; text-align: center; background-color: #ff2d50; color: #fff; } } </style>