reserveCard.vue 4.16 KB
<!--
 * @Date: 2024-01-24 16:38:13
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2024-01-30 15:19:44
 * @FilePath: /xyxBooking-weapp/src/components/reserveCard.vue
 * @Description: 预约记录卡组件
-->
<template>
  <view class="booking-list-item" @tap="goToDetail(reserve_info)">
    <view class="booking-list-item-header">
      <view>{{ reserve_info.booking_time }}</view>
      <view :class="[formatStatus(reserve_info.status)?.key, 'status']">{{ formatStatus(reserve_info.status)?.value }}</view>
    </view>
    <view class="booking-list-item-body">
      <view class="booking-num">
        <view class="num-body van-ellipsis">预约人数:<text>{{ reserve_info.total_qty }} 人</text>&nbsp;<text>({{ reserve_info.person_name }})</text></view>
        <view v-if="(reserve_info.status === CodeStatus.SUCCESS || reserve_info.status === CodeStatus.USED || reserve_info.status === CodeStatus.CANCEL)">
          <nut-icon name="rect-right" />
        </view>
      </view>
      <view class="booking-price">支付金额:<text>¥ {{ reserve_info.total_amt }}</text></view>
      <view class="booking-time">下单时间:<text>{{ reserve_info.order_time }}</text></view>
    </view>
    <view class="booking-list-item-footer">
      <!-- 倒计时逻辑省略,如果需要可添加 -->
    </view>
  </view>
</template>

<script setup>
import { computed } from 'vue'
import { useGo } from '@/hooks/useGo'

const go = useGo();

const props = defineProps({
  data: {
    type: Object,
    default: {},
  },
});

const reserve_info = computed(() => props.data);

const CodeStatus = {
  APPLY: '1',
  PAYING: '2',
  SUCCESS: '3',
  CANCEL: '5',
  CANCELED: '7',
  USED: '9',
  REFUNDING: '11'
}

const formatStatus = (status) => {
  switch (status) {
    case CodeStatus.APPLY:
      return {
        key: 'cancel',
        value: '待支付'
      }
    case CodeStatus.PAYING:
      return {
        key: 'success',
        value: '支付中'
      }
    case CodeStatus.SUCCESS:
      return {
        key: 'success',
        value: '预约成功'
      }
    case CodeStatus.CANCEL:
      return {
        key: 'cancel',
        value: '已取消'
      }
    case CodeStatus.CANCELED:
      return {
        key: 'cancel',
        value: '已取消'
      }
    case CodeStatus.USED:
      return {
        key: 'used',
        value: '已使用'
      }
    case CodeStatus.REFUNDING:
      return {
        key: 'cancel',
        value: '退款中'
      }
    default:
        return { key: '', value: '' }
  }
}

const goToDetail = (item) => {
    // 只有成功、已使用、已取消(退款成功)才跳转详情
  if (item.status === CodeStatus.SUCCESS || item.status === CodeStatus.USED || item.status === CodeStatus.CANCEL) {
    go('/bookingDetail', { pay_id: item.pay_id });
  }
}
</script>

<style lang="less">
.booking-list-item {
  background-color: #FFF;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0rem 0rem 0.92rem 0rem rgba(106,106,106,0.1);
  
  .booking-list-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed #E6E6E6;
    margin-bottom: 0.5rem;
    font-size: 1rem;
    font-weight: bold;
    color: #333;
    
    .status {
        font-size: 0.85rem;
        font-weight: normal;
        padding: 2px 6px;
        border-radius: 4px;
        
        &.success {
            color: #A67939;
            background-color: #FBEEDC;
        }
        &.cancel {
            color: #999;
            background-color: #EEE;
        }
        &.used {
            color: #477F3D;
            background-color: #E5EFE3;
        }
    }
  }
  
  .booking-list-item-body {
    .booking-num {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.5rem;
        color: #666;
        
        .num-body {
            span, text {
                color: #A67939;
                font-weight: bold;
            }
        }
    }
    .booking-price, .booking-time {
        color: #999;
        font-size: 0.9rem;
        margin-bottom: 0.3rem;
        text {
            color: #333;
        }
    }
  }
}
</style>