InfoItem.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view :class="[isFirst ? 'no-border' : '', 'info-item-component']">
  3. <text class="label">{{ label }}</text>
  4. <template v-if="isImage">
  5. <view class="images-container">
  6. <image
  7. v-for="(src, index) in imageSources"
  8. :key="index"
  9. class="kqt-image"
  10. :src="src.url"
  11. @click="previewImage(src.url)"
  12. />
  13. </view>
  14. </template>
  15. <text v-else class="value">{{ value }}</text>
  16. </view>
  17. </template>
  18. <script setup>
  19. import { defineProps, computed, ref, watch } from "vue";
  20. import { getImageInfo } from "@/api/task";
  21. const props = defineProps({
  22. label: String,
  23. value: {
  24. type: [String, Array],
  25. default: "[]",
  26. },
  27. isFirst: Boolean,
  28. isImage: Boolean,
  29. });
  30. const imageSources = ref([]);
  31. // const getImageSources = async (props.) => {
  32. // imageSources.value = (await getImageInfo({ ids: JSON.parse(newVal) })).data;
  33. // };
  34. const previewImage = (url) => {
  35. uni.previewImage({
  36. urls: [url],
  37. });
  38. };
  39. watch(
  40. () => props.value,
  41. async (newVal) => {
  42. if (
  43. (props.label === "附件" ||
  44. props.label === "质检码单照片" ||
  45. props.label === "出库照片" ||
  46. props.label === "入库照片") &&
  47. newVal
  48. ) {
  49. // 打印newVal数据类型
  50. let ids = JSON.parse(newVal);
  51. if (ids.length === 0) {
  52. imageSources.value = [];
  53. return;
  54. } else {
  55. imageSources.value = (await getImageInfo({ ids })).data;
  56. }
  57. }
  58. },
  59. {
  60. // deep: true,
  61. immediate: true,
  62. }
  63. );
  64. </script>
  65. <style lang="scss" scoped>
  66. .info-item-component {
  67. display: flex;
  68. justify-content: space-between;
  69. align-items: center;
  70. padding: 30rpx 0;
  71. border-top: 1px solid #e5e9ed;
  72. &.no-border {
  73. border: none;
  74. }
  75. .label {
  76. font-weight: bold;
  77. color: #777777;
  78. }
  79. .value {
  80. flex: 1;
  81. text-align: right;
  82. color: #0f2239;
  83. font-weight: 600;
  84. }
  85. .images-container {
  86. max-width: 50%;
  87. display: flex;
  88. flex-direction: column;
  89. align-items: center;
  90. .kqt-image {
  91. max-width: 100%;
  92. margin-bottom: 10rpx;
  93. }
  94. }
  95. }
  96. </style>