activeUploadPopup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <popup
  3. class="active-upload-popup"
  4. v-model:show="show"
  5. closeable
  6. teleport="body"
  7. :overlay-style="{ 'z-index': 9999 }"
  8. :close-on-click-overlay="false"
  9. @closed="handleClosed"
  10. >
  11. <div class="header" v-if="selectCurrentPhenology">
  12. <div class="title">
  13. <span class="required">*</span>
  14. 当前物候期
  15. </div>
  16. <div class="date-input">
  17. <el-select popper-class="custom-select-dropdown" v-model="currentPhenologyId" size="large" placeholder="请选择当前物候期">
  18. <el-option
  19. v-for="item in phenologyList"
  20. :key="item.id"
  21. :label="item.name"
  22. :value="item.id"
  23. ></el-option>
  24. </el-select>
  25. </div>
  26. </div>
  27. <div class="header">
  28. <div class="title">
  29. <span class="required">*</span>
  30. {{ problemTitle }}
  31. </div>
  32. <div class="date-input">
  33. <el-date-picker
  34. v-model="uploadDate"
  35. size="large"
  36. popper-class="custom-select-dropdown"
  37. style="width: 100%"
  38. type="date"
  39. placeholder="请选择日期"
  40. :editable="false"
  41. />
  42. </div>
  43. </div>
  44. <div v-if="needExecutor">
  45. <div class="header">
  46. <div class="title">
  47. <span class="required">*</span>
  48. 请确认执行人
  49. </div>
  50. <div class="date-input">
  51. <el-select popper-class="custom-select-dropdown" size="large" v-model="executorId" placeholder="请选择执行人">
  52. <el-option
  53. v-for="(item, index) in executorList"
  54. :key="index"
  55. :label="item.name"
  56. :value="item.miniUserId"
  57. />
  58. </el-select>
  59. </div>
  60. </div>
  61. <div class="header flex-header">
  62. <div class="title">
  63. <span class="required">*</span>
  64. 是否需要复核?
  65. </div>
  66. <div class="date-input">
  67. <el-radio-group v-model="needReview">
  68. <el-radio :value="1">需要</el-radio>
  69. <el-radio :value="0">不需要</el-radio>
  70. </el-radio-group>
  71. </div>
  72. </div>
  73. <div class="header" v-if="needReview">
  74. <div class="title">
  75. <span class="required">*</span>
  76. 请选择复核时间
  77. </div>
  78. <div class="date-input review-day-input">
  79. <el-input size="large" v-model="reviewDay" type="number" step="0.01">
  80. <template #append>天后</template>
  81. </el-input>
  82. </div>
  83. </div>
  84. </div>
  85. <div class="tips-text img-desc" v-if="imgDesc"><span class="required">*</span>{{ imgDesc }}</div>
  86. <div class="tips-text" v-else>上传照片,诊断更准确哦~</div>
  87. <upload :textShow="true" class="upload-wrap" exampleImg>
  88. <img class="example" src="@/assets/img/home/example-4.png" alt="" />
  89. <img class="example" src="@/assets/img/home/plus.png" alt="" />
  90. </upload>
  91. <div class="btn" :class="{ disabled: isUploading }" @click="handleUpload">
  92. {{ isUploading ? "提交中..." : "确认" }}
  93. </div>
  94. </popup>
  95. <!-- 上传成功提示弹窗 -->
  96. <popup class="success-popup" v-model:show="successShow" :close-on-click-overlay="false">
  97. <div class="success-wrap">
  98. <img class="success-icon" src="@/assets/img/home/right.png" alt="" />
  99. <div class="success-title">好的,感谢您的配合</div>
  100. <div class="success-sub">请您耐心等待农事确认</div>
  101. <div class="btn" @click="successShow = false">我知道了</div>
  102. </div>
  103. </popup>
  104. </template>
  105. <script setup>
  106. import { Popup } from "vant";
  107. import { onMounted, onUnmounted, ref } from "vue";
  108. import upload from "@/components/upload";
  109. import eventBus from "@/api/eventBus";
  110. import { ElMessage } from "element-plus";
  111. const show = ref(false);
  112. const gardenId = ref(null);
  113. const images = ref([]);
  114. const uploadDate = ref("");
  115. const problemTitle = ref("请选择问题");
  116. const successShow = ref(false);
  117. const isUploading = ref(false); // 标记是否正在上传中
  118. onMounted(() => {
  119. eventBus.off("upload:changeArr", uploadChange);
  120. eventBus.on("upload:changeArr", uploadChange);
  121. eventBus.on("activeUpload:show", handleShow);
  122. eventBus.on("activeUpload:success", handleSuccess);
  123. });
  124. function uploadChange(arr) {
  125. images.value = arr;
  126. }
  127. function formatDate(date) {
  128. let year = date.getFullYear();
  129. let month = String(date.getMonth() + 1).padStart(2, "0");
  130. let day = String(date.getDate()).padStart(2, "0");
  131. return `${year}-${month}-${day}`;
  132. }
  133. const type = ref(null);
  134. const arrangeId = ref(null);
  135. // 选择执行人
  136. const needExecutor = ref(false);
  137. const executorList = ref([]);
  138. const executorId = ref(null);
  139. const needReview = ref(false);
  140. const reviewDay = ref(null);
  141. // 选择当前物候期
  142. const currentPhenologyId = ref(null);
  143. const phenologyList = ref([]);
  144. const selectCurrentPhenology = ref(false);
  145. // 图片上传标题描述
  146. const imgDesc = ref(null);
  147. function handleShow({
  148. gardenIdVal,
  149. problemTitleVal,
  150. typeVal,
  151. arrangeIdVal,
  152. executorListVal,
  153. imgDescVal,
  154. needExecutorVal,
  155. selectCurrentPhenologyVal,
  156. phenologyListVal,
  157. }) {
  158. images.value = [];
  159. gardenId.value = gardenIdVal;
  160. problemTitle.value = problemTitleVal || "请选择问题";
  161. uploadDate.value = new Date();
  162. show.value = true;
  163. type.value = typeVal;
  164. arrangeId.value = arrangeIdVal;
  165. executorList.value = executorListVal;
  166. imgDesc.value = imgDescVal;
  167. needExecutor.value = needExecutorVal;
  168. selectCurrentPhenology.value = selectCurrentPhenologyVal ? true : false;
  169. phenologyList.value = phenologyListVal;
  170. // 重置上传状态
  171. isUploading.value = false;
  172. // 如果没有报价信息,则跳转去完善报价信息
  173. }
  174. function handleSuccess() {
  175. successShow.value = true;
  176. }
  177. const emit = defineEmits(["handleUploadSuccess"]);
  178. const handleUpload = () => {
  179. // 如果正在上传中,直接返回,防止重复调用
  180. if (isUploading.value) return;
  181. if (images.value.length === 0) return ElMessage.warning("请上传图片");
  182. let paramsObj = {
  183. farmId: gardenId.value,
  184. arrangeId: arrangeId.value,
  185. executeDate: formatDate(uploadDate.value),
  186. imagePaths: images.value,
  187. };
  188. if (needExecutor.value) {
  189. paramsObj = {
  190. ...paramsObj,
  191. executeDeadlineDate: formatDate(uploadDate.value),
  192. executeDate: null,
  193. executorUserId: executorId.value,
  194. needReview: needReview.value,
  195. reviewIntervalDays: reviewDay.value,
  196. };
  197. }
  198. if (type.value === "question") {
  199. show.value = false;
  200. emit("handleUploadSuccess", paramsObj);
  201. return;
  202. }
  203. triggerFarmWork(paramsObj, true);
  204. };
  205. function triggerFarmWork(paramsObj, showSuccess) {
  206. // 如果正在上传中,直接返回,防止重复调用
  207. if (isUploading.value) return;
  208. // 设置上传状态为 true
  209. isUploading.value = true;
  210. VE_API.monitor
  211. .triggerFarmWork(paramsObj)
  212. .then((res) => {
  213. if (res.code === 0) {
  214. if (showSuccess) {
  215. show.value = false;
  216. // successShow.value = true;
  217. ElMessage.success("农事已转入成功");
  218. emit("handleUploadSuccess", paramsObj);
  219. }
  220. }
  221. })
  222. .catch((error) => {
  223. console.error("触发农事失败:", error);
  224. })
  225. .finally(() => {
  226. // 无论成功或失败,都重置上传状态
  227. isUploading.value = false;
  228. });
  229. }
  230. function showPopup(data) {
  231. handleShow(data);
  232. }
  233. defineExpose({
  234. triggerFarmWork,
  235. showPopup,
  236. });
  237. function handleClosed() {
  238. eventBus.emit("upload:reset");
  239. }
  240. onUnmounted(() => {
  241. eventBus.off("activeUpload:show", handleShow);
  242. eventBus.off("activeUpload:success", handleSuccess);
  243. eventBus.off("upload:changeArr", uploadChange);
  244. show.value = false;
  245. });
  246. </script>
  247. <style lang="scss" scoped>
  248. .active-upload-popup {
  249. z-index: 9999 !important;
  250. width: 90%;
  251. box-sizing: border-box;
  252. padding: 24px 18px 20px;
  253. background: linear-gradient(0deg, #ffffff 70%, #d1ebff 100%);
  254. border-radius: 10px;
  255. ::v-deep {
  256. .van-popup__close-icon {
  257. color: #000;
  258. }
  259. }
  260. .header {
  261. .title {
  262. font-size: 16px;
  263. font-weight: 500;
  264. display: flex;
  265. }
  266. align-items: center;
  267. .date-input {
  268. margin: 12px 0;
  269. ::v-deep {
  270. .el-input__inner {
  271. caret-color: transparent;
  272. }
  273. }
  274. }
  275. .review-day-input {
  276. border: 1px solid #dcdcdc;
  277. border-radius: 3px;
  278. ::v-deep {
  279. .el-input__wrapper {
  280. width: 40px;
  281. flex: none;
  282. box-shadow: none;
  283. }
  284. .el-input-group__append {
  285. box-shadow: none;
  286. background: none;
  287. }
  288. }
  289. }
  290. }
  291. .flex-header {
  292. display: flex;
  293. align-items: center;
  294. justify-content: space-between;
  295. margin-bottom: 12px;
  296. .date-input {
  297. margin: 0;
  298. }
  299. }
  300. .required {
  301. color: #ff4d4f;
  302. margin-right: 4px;
  303. }
  304. .tips-text {
  305. font-weight: 500;
  306. &.img-desc {
  307. font-size: 16px;
  308. }
  309. }
  310. .upload-wrap {
  311. margin: 12px 0 24px;
  312. }
  313. .example {
  314. width: 80px;
  315. height: 80px;
  316. }
  317. .example + .example {
  318. margin-left: 12px;
  319. }
  320. }
  321. .btn {
  322. padding: 8px;
  323. background: #2199f8;
  324. border-radius: 25px;
  325. color: #fff;
  326. font-size: 16px;
  327. text-align: center;
  328. cursor: pointer;
  329. transition: opacity 0.3s;
  330. &.disabled {
  331. opacity: 0.6;
  332. cursor: not-allowed;
  333. pointer-events: none;
  334. }
  335. }
  336. .success-popup {
  337. width: 300px;
  338. border-radius: 14px;
  339. padding: 28px 15px 20px;
  340. box-sizing: border-box;
  341. .success-wrap {
  342. text-align: center;
  343. }
  344. .success-icon {
  345. width: 68px;
  346. height: 68px;
  347. }
  348. .success-title {
  349. font-size: 24px;
  350. margin-top: 12px;
  351. }
  352. .success-sub {
  353. margin: 8px 0 32px;
  354. }
  355. }
  356. </style>
  357. <style lang="scss">
  358. // 全局样式,用于设置下拉框的 z-index(不受 scoped 限制)
  359. .custom-select-dropdown {
  360. z-index: 10000 !important;
  361. }
  362. </style>