activeUploadPopup.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <popup
  3. class="active-upload-popup"
  4. v-model:show="show"
  5. closeable
  6. :close-on-click-overlay="false"
  7. @closed="handleClosed"
  8. >
  9. <div class="header">
  10. <div class="title">
  11. <span class="required">*</span>
  12. {{ problemTitle }}
  13. </div>
  14. <div class="date-input">
  15. <el-date-picker v-model="uploadDate" size="large" style="width: 100%" type="date" placeholder="请选择日期" />
  16. </div>
  17. </div>
  18. <div class="tips-text">上传照片,诊断更准确哦~</div>
  19. <upload :textShow="true" class="upload-wrap" exampleImg>
  20. <img class="example" src="@/assets/img/home/example-4.png" alt="" />
  21. <img class="example" src="@/assets/img/home/plus.png" alt="">
  22. </upload>
  23. <div class="btn" @click="handleUpload">确认</div>
  24. </popup>
  25. <!-- 上传成功提示弹窗 -->
  26. <popup class="success-popup" v-model:show="successShow" :close-on-click-overlay="false">
  27. <div class="success-wrap">
  28. <img class="success-icon" src="@/assets/img/home/right.png" alt="" />
  29. <div class="success-title">好的,感谢您的配合</div>
  30. <div class="success-sub">请您耐心等待农事确认</div>
  31. <div class="btn" @click="successShow = false">我知道了</div>
  32. </div>
  33. </popup>
  34. </template>
  35. <script setup>
  36. import { Popup } from "vant";
  37. import { onMounted, onUnmounted, ref } from "vue";
  38. import upload from "@/components/upload";
  39. import eventBus from "@/api/eventBus";
  40. import { ElMessage } from "element-plus";
  41. const show = ref(false);
  42. const gardenId = ref(null);
  43. const images = ref([]);
  44. const uploadDate = ref("");
  45. const problemTitle = ref("请选择问题");
  46. const successShow = ref(false);
  47. onMounted(() => {
  48. eventBus.off("upload:changeArr", uploadChange);
  49. eventBus.on("upload:changeArr", uploadChange);
  50. eventBus.on("activeUpload:show", handleShow);
  51. eventBus.on("activeUpload:success", handleSuccess);
  52. });
  53. function uploadChange(arr) {
  54. images.value = arr;
  55. }
  56. function formatDate(date) {
  57. let year = date.getFullYear();
  58. let month = String(date.getMonth() + 1).padStart(2, "0");
  59. let day = String(date.getDate()).padStart(2, "0");
  60. return `${year}-${month}-${day}`;
  61. }
  62. const type = ref(null);
  63. function handleShow({ gardenIdVal, problemTitleVal,typeVal }) {
  64. images.value = [];
  65. gardenId.value = gardenIdVal;
  66. problemTitle.value = problemTitleVal || "请选择问题";
  67. uploadDate.value = formatDate(new Date());
  68. show.value = true;
  69. type.value = typeVal;
  70. }
  71. function handleSuccess() {
  72. successShow.value = true;
  73. }
  74. const emit = defineEmits(['handleUploadSuccess']);
  75. const handleUpload = () => {
  76. if (images.value.length === 0) return ElMessage.warning("请上传图片");
  77. const params = {
  78. gardenId: gardenId.value,
  79. images: images.value,
  80. uploadDate: uploadDate.value,
  81. };
  82. // 提交成功后的反馈弹窗(示例直接展示)
  83. if(type.value === 'question'){
  84. show.value = false;
  85. emit("handleUploadSuccess",params);
  86. }else{
  87. show.value = false;
  88. successShow.value = true;
  89. }
  90. // VE_API.ali.uploadImg(params).then((res) => {
  91. // if (res.success) {
  92. // show.value = false;
  93. // successShow.value = true;
  94. // }
  95. // });
  96. };
  97. function handleClosed() {
  98. eventBus.emit("upload:reset");
  99. }
  100. onUnmounted(() => {
  101. eventBus.off("activeUpload:show", handleShow);
  102. eventBus.off("activeUpload:success", handleSuccess);
  103. eventBus.off("upload:changeArr", uploadChange);
  104. show.value = false;
  105. });
  106. </script>
  107. <style lang="scss" scoped>
  108. .active-upload-popup {
  109. width: 90%;
  110. box-sizing: border-box;
  111. padding: 24px 18px 20px;
  112. background: linear-gradient(0deg, #ffffff 70%, #d1ebff 100%);
  113. border-radius: 10px;
  114. ::v-deep {
  115. .van-popup__close-icon {
  116. color: #000;
  117. }
  118. }
  119. .header {
  120. .title {
  121. font-size: 16px;
  122. font-weight: 500;
  123. display: flex;
  124. align-items: center;
  125. .required {
  126. color: #ff4d4f;
  127. margin-right: 4px;
  128. }
  129. }
  130. .date-input {
  131. margin: 12px 0;
  132. }
  133. }
  134. .tips-text {
  135. font-weight: 500;
  136. }
  137. .upload-wrap {
  138. margin: 12px 0 24px;
  139. }
  140. .example {
  141. width: 80px;
  142. height: 80px;
  143. }
  144. .example + .example {
  145. margin-left: 12px;
  146. }
  147. }
  148. .btn {
  149. padding: 8px;
  150. background: #2199f8;
  151. border-radius: 25px;
  152. color: #fff;
  153. font-size: 16px;
  154. text-align: center;
  155. }
  156. .success-popup {
  157. width: 300px;
  158. border-radius: 14px;
  159. padding: 28px 15px 20px;
  160. box-sizing: border-box;
  161. .success-wrap {
  162. text-align: center;
  163. }
  164. .success-icon {
  165. width: 68px;
  166. height: 68px;
  167. }
  168. .success-title {
  169. font-size: 24px;
  170. margin-top: 12px;
  171. }
  172. .success-sub {
  173. margin: 8px 0 32px;
  174. }
  175. }
  176. </style>