猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.1 KiB

  1. <template>
  2. <up-popup :show="show" mode="bottom" @close="close" :round="10" :closeable="true">
  3. <view class="popup-container">
  4. <view class="popup-title">宠物服务时间列表</view>
  5. <view class="service-list">
  6. <view class="service-item" v-for="(service, index) in serviceList" :key="index">
  7. <view class="service-date">{{ service.serviceDate }}</view>
  8. <view class="service-products">
  9. <view class="product-item" v-for="(product, pIndex) in service.products" :key="pIndex">
  10. <view class="product-name">{{ product.productName }}</view>
  11. <view class="product-price">{{ product.salePrice }}</view>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </up-popup>
  18. </template>
  19. <script setup>
  20. import { ref, defineProps, defineEmits } from 'vue';
  21. const props = defineProps({
  22. show: {
  23. type: Boolean,
  24. default: false
  25. },
  26. orderData: {
  27. type: Object,
  28. default: () => ({})
  29. }
  30. });
  31. const emit = defineEmits(['close']);
  32. const serviceList = ref([]);
  33. // 关闭弹窗
  34. const close = () => {
  35. emit('close');
  36. };
  37. // 处理数据,将订单数据转换为服务时间列表格式
  38. const processOrderData = (orderData) => {
  39. if (!orderData || !orderData.h5OrderVO) return [];
  40. const { orderServiceList, orderItemList } = orderData.h5OrderVO;
  41. if (!orderServiceList || !orderItemList) return [];
  42. // 按服务日期组织数据
  43. const serviceMap = {};
  44. // 遍历服务列表,创建日期映射
  45. orderServiceList.forEach(service => {
  46. const serviceId = service.id;
  47. const serviceDate = service.serviceDate;
  48. if (!serviceMap[serviceId]) {
  49. serviceMap[serviceId] = {
  50. serviceDate,
  51. products: []
  52. };
  53. }
  54. });
  55. // 遍历订单项,将产品添加到对应的服务日期中
  56. orderItemList.forEach(item => {
  57. const serviceId = item.orderServiceId;
  58. if (serviceMap[serviceId]) {
  59. serviceMap[serviceId].products.push({
  60. productName: item.productName,
  61. salePrice: item.salePrice,
  62. pic: item.pic,
  63. quantity: item.quantity,
  64. spData: item.spData ? JSON.parse(item.spData) : {}
  65. });
  66. }
  67. });
  68. // 转换为数组格式
  69. return Object.values(serviceMap);
  70. };
  71. // 监听orderData变化,处理数据
  72. const updateServiceList = () => {
  73. if (props.orderData && props.orderData.h5OrderVO) {
  74. serviceList.value = processOrderData(props.orderData);
  75. }
  76. };
  77. // 暴露方法给父组件
  78. defineExpose({
  79. updateServiceList
  80. });
  81. </script>
  82. <style scoped lang="scss">
  83. .popup-container {
  84. padding: 30rpx;
  85. max-height: 70vh;
  86. overflow-y: auto;
  87. }
  88. .popup-title {
  89. font-size: 32rpx;
  90. font-weight: bold;
  91. text-align: center;
  92. margin-bottom: 30rpx;
  93. }
  94. .service-list {
  95. .service-item {
  96. margin-bottom: 30rpx;
  97. background-color: #f8f8f8;
  98. border-radius: 12rpx;
  99. padding: 20rpx;
  100. .service-date {
  101. font-size: 28rpx;
  102. font-weight: bold;
  103. color: #333;
  104. margin-bottom: 20rpx;
  105. padding-bottom: 10rpx;
  106. border-bottom: 1px solid #eee;
  107. }
  108. .service-products {
  109. .product-item {
  110. display: flex;
  111. justify-content: space-between;
  112. padding: 10rpx 0;
  113. .product-name {
  114. font-size: 26rpx;
  115. color: #666;
  116. }
  117. .product-price {
  118. font-size: 26rpx;
  119. color: #FF530A;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. </style>