bookingList.vue 4.43 KB
<!--
 * @Date: 2024-01-16 11:37:10
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2024-01-19 21:55:03
 * @FilePath: /xysBooking/src/views/bookingList.vue
 * @Description: 文件描述
-->
<template>
  <div class="booking-list-page">
    <div @click="() => { go('/bookingDetail', { pay_id: item.pay_id }) }" v-for="(item, index) in bookingList" :key="index" class="booking-list-item">
      <div class="booking-list-item-header">
        <div>{{ item.booking_time }}</div>
        <div :class="[formatStatus(item.status)?.key, 'status']">{{ formatStatus(item.status)?.value }}</div>
      </div>
      <div class="booking-list-item-body">
        <div class="booking-num">
          <div class="num-body">预约人数:<span>{{ item.total_qty }} 人</span></div>
          <div><van-icon name="arrow" /></div>
        </div>
        <div class="booking-price">支付金额:<span>¥ {{ item.total_amt }}</span></div>
        <div class="booking-time">下单时间:<span>{{ item.order_time }}</span></div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useGo } from '@/hooks/useGo'
import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js'
//import { } from '@/utils/generateModules.js'
//import { } from '@/utils/generateIcons.js'
//import { } from '@/composables'
import { billListAPI } from '@/api/index'
const $route = useRoute();
const $router = useRouter();
useTitle($route.meta.title);

const go = useGo();

const bookingList = ref([]);

/**
 * 1=待支付(下单就立即支付,所以理论上不存在待支付的数据),
 * 2=支付中(支付前先把状态打成2;支付回调后应立即变更状态,支付中的状态不会持续很久),
 * 3=预约成功(已支付,且一个码都未被使用),
 * 5=已取消(用户手动取消成功,退款成功回调后打成5,否则打成3),
 * 7=已取消(支付超时或失败自动取消),
 * 9=已使用(明细里有一个码被使用),
 * 11=退款中(取消预约时先把状态打成11)
 */

const formatStatus = (status) => {
  switch (status) {
    case '1':
      return {
        key: 'cancel',
        value: '待支付'
      }
    case '2':
      return {
        key: 'success',
        value: '支付中'
      }
    case '3':
      return {
        key: 'success',
        value: '预约成功'
      }
    case '5':
      return {
        key: 'cancel',
        value: '已取消'
      }
    case '7':
      return {
        key: 'cancel',
        value: '已取消'
      }
    case '9':
      return {
        key: 'used',
        value: '已使用'
      }
    case '11':
      return {
        key: 'cancel',
        value: '退款中'
      }
  }
}

onMounted(async () => {
  const { code, data } = await billListAPI();
  if (code) {
    //
    data.forEach(item => {
      let begin_time = item.begin_time?.slice(0, -3);
      let end_time = item.end_time?.slice(0, -3);
      let str = begin_time + ' ' + end_time;
      item.booking_time = `${str.split(' ')[0]} ${str.split(' ')[1]}-${str.split(' ')[3]}`;
      item.order_time = item.created_time.slice(0, -3);
    });
    bookingList.value = data;
  }
})
</script>

<style lang="less" scoped>
.booking-list-page {
  padding: 1rem;
  .booking-list-item {
    background-color: #FFF;
    border-radius: 8px;
    margin-bottom: 1rem;
    .booking-list-item-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 1rem;
      border-bottom: 1px dashed #f0f0f0;
      .status {
        font-size: 0.75rem;
        padding: 5px 8px;
        border-radius: 5px;
      }
      .success {
        color: #A67939;
        background-color: #FBEEDC;
      }
      .cancel {
        color: #929292;
        background-color: #E6E6E6;
      }
      .used {
        color: #477F3D;
        background-color: #E5EFE3;
      }
    }
    .booking-list-item-body {
      padding: 1rem;
      line-height: 1.7;
      .booking-num {
        display: flex;
        justify-content: space-between;
        .num-body {
          color: #959595;
          span {
            color: #1E1E1E;
          }
        }
      }
      .booking-price {
        color: #959595;
        span {
          color: #1E1E1E;
        }
      }
      .booking-time {
        color: #959595;
        span {
          color: #1E1E1E;
        }
      }
    }
  }
}
</style>