order.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view class="body" v-if="list">
  3. <shadow-card :list="list">
  4. <view class="flex-column flex-center pb-48">
  5. <view class="fw-500 color-000">
  6. <text class="fs-40 mr-8">¥</text>
  7. <text class="fs-60 lh-60">{{ price }}</text>
  8. </view>
  9. <view class="fs-26 mt-8" style="color: rgba(0, 0, 0, 0.4)"
  10. >实付金额</view
  11. >
  12. </view>
  13. </shadow-card>
  14. </view>
  15. </template>
  16. <script setup lang="ts">
  17. import { fetchOrder } from "../../api/user";
  18. import { onLoad } from "@dcloudio/uni-app";
  19. import { ref } from "vue";
  20. const list = ref<any[]>();
  21. const price = ref();
  22. onLoad((options: any) => {
  23. fetchOrder(options.id)
  24. .then((res) => {
  25. const totalMoney = (res.totalMoney / 100).toFixed(2);
  26. const discountAmount = (res.discountAmount / 100).toFixed(2);
  27. const discountAmountText = "TODO";
  28. const reg = new RegExp("\B(?=(\d{3})+(?!\d))", "g");
  29. const start = new Date(res.startTime.replace(/-/g, "/"));
  30. const end = new Date(res.endTime.replace(/-/g, "/"));
  31. const diff = parseInt(`${(end.getTime() - start.getTime()) / 1000}`);
  32. const min = parseInt(`${diff / 60}`);
  33. const time =
  34. min >= 60
  35. ? `${parseInt(`${min / 60}`)}小时${parseInt(
  36. `${min - parseInt(`${min / 60}`) * 60}`
  37. )}分钟`
  38. : `${parseInt(`${diff / 60}`)}分钟`;
  39. list.value = [
  40. {
  41. label: "累计充电量",
  42. value: `${res.totalPower}度`,
  43. },
  44. {
  45. label: "订单金额",
  46. value: `${totalMoney.replace(reg, ",")}元`,
  47. },
  48. {
  49. label: "优惠金额",
  50. value: `${
  51. Number(discountAmount) <= 0 ? "" : "-"
  52. }${discountAmount}元${discountAmountText}`,
  53. color: "#F43636",
  54. },
  55. {
  56. label: "开始时间",
  57. value: res.startTime,
  58. },
  59. {
  60. label: "结束时间",
  61. value: res.endTime,
  62. },
  63. {
  64. label: "充电用时",
  65. value: time,
  66. },
  67. ];
  68. price.value = (res.payAmount / 100).toFixed(2);
  69. })
  70. .catch(() => {
  71. uni.showModal({
  72. content: "出现错误,请退出重进",
  73. success() {
  74. uni.navigateBack();
  75. },
  76. });
  77. });
  78. });
  79. </script>
  80. <style lang="scss">
  81. .body {
  82. padding: 30rpx 60rpx;
  83. }
  84. </style>