activeUploadPopup.vue 5.6 KB

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