123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <template>
- <div>
- <van-nav-bar title="订单信息" />
- <van-card class="my-card" v-for="(orderDetail, index) in orderDetails" :key="index" :num="orderDetail.productNumber"
- :price="orderDetail.price.toFixed(2)" :title="orderDetail.productName"
- :thumb="showSugarPhoto(orderDetail.productNo)" />
- <van-submit-bar :price="amount" button-color="#07c160" button-text="支付" @click="wxPay()" />
- </div>
- </template>
-
- <script>
- import { useRoute } from "vue-router";
- import { showFailToast, showSuccessToast, showToast, showDialog } from 'vant';
- import { getOrderBySn } from '@/service/popPayment';
- import { onMounted, ref } from "vue";
- export default {
- name: 'popPayment',
- setup() {
- const route = useRoute();
- const sn = route.query.sn;
- const status = route.query.status;
- const order = ref(null);
- const orderDetails = ref([]);
- const amount = ref();
- // const price = ref();
- onMounted(async () => {
- if (status == 1) {
- showDialog({
- message: '订单已支付',
- theme: 'round-button',
- confirmButtonColor: '#07c160',
- }).then(() => {
- if (typeof window.WeixinJSBridge !== 'undefined') {
- window.WeixinJSBridge.call('closeWindow');
- } else {
- window.close();
- }
- })
- } else {
- await getOrder();
- }
- });
- const getOrder = async () => {
- const { data } = await getOrderBySn({ sn: sn });
- if (data.code === '00000') {
- order.value = data.data;
- orderDetails.value = data.data.orderDetails;
- console.log("order", order.value);
- console.log("orderDetails", orderDetails.value[0]);
- amount.value = order.value.price * 100;
- // console.log(amount.value);
- // price.value = order.value.price.toFixed(2);
- } else { showFailToast(data.message); }
- };
- const showSugarPhoto = (no) => {
- if (no == 'A99') {
- return require(`../assets/order/spunSugar/goods/A30.png`);
- }
- return require(`../assets/order/spunSugar/goods/${no}.png`);
- };
- const wxPay = () => {
- WeixinJSBridge.invoke(
- 'getBrandWCPayRequest', {
- "appId": "wxcd5b1b2636c9f611", //公众号ID,由商户传入
- "timeStamp": route.query.timeStamp, //时间戳,自1970年以来的秒数
- "nonceStr": route.query.nonceStr, //随机串
- "package": route.query.package,
- "signType": "RSA", //微信签名方式:
- "paySign": route.query.paySign //微信签名
- },
- function (res) {
- if (res.err_msg == "get_brand_wcpay_request:ok") {
- console.log("支付成功");
- showSuccessToast('支付成功');
- } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
- console.log("取消支付");
- showToast('取消支付');
- } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
- console.log("支付失败");
- showFailToast('支付失败');
- }
- }
- )
- };
- return {
- wxPay,
- getOrder,
- orderDetails,
- showSugarPhoto,
- // price,
- amount
- };
- }
- };
- </script>
- <style>
- .van-image__img {
- object-fit: contain !important;
- }
- </style>
|