order.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view class="body" v-if="list">
  3. <shadow-card :list="list"></shadow-card>
  4. </view>
  5. </template>
  6. <script setup lang="ts">
  7. import { fetchOrder } from "../../api/user";
  8. import { onLoad } from "@dcloudio/uni-app";
  9. import { ref } from "vue";
  10. const list = ref<any[]>();
  11. onLoad((options: any) => {
  12. fetchOrder(options.id)
  13. .then((res) => {
  14. const total_money = (res.totalMoney / 100).toFixed(2);
  15. const reg = new RegExp("\B(?=(\d{3})+(?!\d))", "g");
  16. const start = new Date(res.startTime.replace(/-/g, "/"));
  17. const end = new Date(res.endTime.replace(/-/g, "/"));
  18. const diff = parseInt(`${(end.getTime() - start.getTime()) / 1000}`);
  19. const min = parseInt(`${diff / 60}`);
  20. const time =
  21. min >= 60
  22. ? `${parseInt(`${min / 60}`)}小时${parseInt(
  23. `${min - parseInt(`${min / 60}`) * 60}`
  24. )}分钟`
  25. : `${parseInt(`${diff / 60}`)}分钟`;
  26. list.value = [
  27. {
  28. label: "累计充电量",
  29. value: `${res.totalPower}度`,
  30. },
  31. {
  32. label: "累计费用",
  33. value: `${total_money.replace(reg, ",")}元`,
  34. },
  35. {
  36. label: "开始时间",
  37. value: res.startTime,
  38. },
  39. {
  40. label: "结束时间",
  41. value: res.endTime,
  42. },
  43. {
  44. label: "累计用时",
  45. value: time,
  46. },
  47. ];
  48. })
  49. .catch(() => {
  50. uni.showModal({
  51. content: "出现错误,请退出重进",
  52. success() {
  53. uni.navigateBack();
  54. },
  55. });
  56. });
  57. });
  58. </script>
  59. <style lang="scss">
  60. .body {
  61. padding: 30rpx 60rpx;
  62. }
  63. </style>