order-timeline.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="demo-timeline">
  3. <div v-if="loading" v-loading="loading" style="height: 180px"></div>
  4. <template v-else>
  5. <div v-if="records.length" style="margin-bottom: 10px">{{ title }}</div>
  6. <el-timeline v-if="records.length">
  7. <el-timeline-item
  8. v-for="(item, index) in records"
  9. :key="index"
  10. :timestamp="item.createTime"
  11. :color="item.label"
  12. >
  13. <div style="display: flex; align-items: center; flex-wrap: wrap">
  14. <el-icon :size="14" :color="item.label">
  15. <Flag />
  16. </el-icon>
  17. <span>{{ item.createName }}:</span>
  18. <span>{{ item.remark }}</span>
  19. </div>
  20. </el-timeline-item>
  21. </el-timeline>
  22. <el-empty v-else description="暂无数据" :image-size="80"></el-empty>
  23. </template>
  24. </div>
  25. </template>
  26. <script setup>
  27. import { watch, ref, onMounted } from 'vue';
  28. import request from '@/utils/request';
  29. import { Flag } from '@element-plus/icons-vue';
  30. const props = defineProps({
  31. orderId: {
  32. type: [String, Number],
  33. default: ''
  34. },
  35. title: {
  36. type: String,
  37. default: ''
  38. }
  39. });
  40. const records = ref([]);
  41. const loading = ref(false);
  42. //获取备注
  43. const getRemarks = async () => {
  44. if (!props.orderId || loading.value) return;
  45. loading.value = true;
  46. try {
  47. const res = await request.get(
  48. `/order/remark/list?orderId=${props.orderId}`
  49. );
  50. records.value = res.data.data;
  51. } catch (error) {
  52. console.error('Failed to fetch remarks:', error);
  53. } finally {
  54. loading.value = false;
  55. }
  56. };
  57. watch(
  58. () => props.orderId,
  59. (newVal, oldVal) => {
  60. if (newVal && newVal !== oldVal) {
  61. records.value = [];
  62. getRemarks();
  63. }
  64. },
  65. { immediate: true }
  66. );
  67. </script>