activeUploadPopup.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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" v-if="userInfoObj?.agriculturalRole !== 1">*</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. import { useRouter } from "vue-router";
  112. const router = useRouter();
  113. const show = ref(false);
  114. const gardenId = ref(null);
  115. const images = ref([]);
  116. const uploadDate = ref("");
  117. const problemTitle = ref("请选择问题");
  118. const successShow = ref(false);
  119. const isUploading = ref(false); // 标记是否正在上传中
  120. onMounted(() => {
  121. eventBus.off("upload:changeArr", uploadChange);
  122. eventBus.on("upload:changeArr", uploadChange);
  123. eventBus.on("activeUpload:show", handleShow);
  124. eventBus.on("activeUpload:success", handleSuccess);
  125. });
  126. const userInfo = localStorage.getItem("localUserInfo");
  127. const userInfoObj = userInfo ? JSON.parse(userInfo) : {};
  128. function uploadChange(arr) {
  129. images.value = arr;
  130. }
  131. function formatDate(date) {
  132. let year = date.getFullYear();
  133. let month = String(date.getMonth() + 1).padStart(2, "0");
  134. let day = String(date.getDate()).padStart(2, "0");
  135. return `${year}-${month}-${day}`;
  136. }
  137. const type = ref(null);
  138. const arrangeId = ref(null);
  139. // 选择执行人
  140. const needExecutor = ref(false);
  141. const executorList = ref([]);
  142. const executorId = ref(null);
  143. const needReview = ref(false);
  144. const reviewDay = ref(null);
  145. // 选择当前物候期
  146. const currentPhenologyId = ref(null);
  147. const phenologyList = ref([]);
  148. const selectCurrentPhenology = ref(false);
  149. // 图片上传标题描述
  150. const imgDesc = ref(null);
  151. function handleShow({
  152. gardenIdVal,
  153. problemTitleVal,
  154. typeVal,
  155. arrangeIdVal,
  156. executorListVal,
  157. imgDescVal,
  158. needExecutorVal,
  159. selectCurrentPhenologyVal,
  160. phenologyListVal,
  161. farmWorkIdVal,
  162. schemeIdVal,
  163. }) {
  164. images.value = [];
  165. gardenId.value = gardenIdVal;
  166. problemTitle.value = problemTitleVal || "请选择问题";
  167. uploadDate.value = new Date();
  168. show.value = true;
  169. type.value = typeVal;
  170. arrangeId.value = arrangeIdVal;
  171. executorList.value = executorListVal;
  172. imgDesc.value = imgDescVal;
  173. needExecutor.value = needExecutorVal;
  174. selectCurrentPhenology.value = selectCurrentPhenologyVal ? true : false;
  175. phenologyList.value = phenologyListVal;
  176. // 重置上传状态
  177. isUploading.value = false;
  178. if(typeVal !== "question"){
  179. // 如果没有报价信息,则跳转去完善报价信息
  180. VE_API.monitor.validatePesticideFertilizerQuotes({ id: farmWorkIdVal, schemeId: schemeIdVal }).then((res) => {
  181. if (res.data === false) {
  182. ElMessage.warning("请先完善报价信息");
  183. setTimeout(() => {
  184. router.push(`/modify?farmWorkId=${farmWorkIdVal}&schemeId=${schemeIdVal}&farmId=${gardenIdVal}&onlyPrice=true&isEdit=true`);
  185. }, 1000);
  186. }
  187. });
  188. }
  189. }
  190. function handleSuccess() {
  191. successShow.value = true;
  192. }
  193. const emit = defineEmits(["handleUploadSuccess"]);
  194. const handleUpload = () => {
  195. // 如果正在上传中,直接返回,防止重复调用
  196. if (isUploading.value) return;
  197. if (userInfoObj?.agriculturalRole !== 1 && images.value.length === 0) return ElMessage.warning("请上传图片");
  198. let paramsObj = {
  199. farmId: gardenId.value,
  200. arrangeId: arrangeId.value,
  201. executeDate: formatDate(uploadDate.value),
  202. imagePaths: images.value,
  203. };
  204. if (needExecutor.value) {
  205. paramsObj = {
  206. ...paramsObj,
  207. executeDeadlineDate: formatDate(uploadDate.value),
  208. executeDate: null,
  209. executorUserId: executorId.value,
  210. needReview: needReview.value,
  211. reviewIntervalDays: reviewDay.value,
  212. };
  213. }
  214. if (type.value === "question") {
  215. show.value = false;
  216. emit("handleUploadSuccess", paramsObj);
  217. return;
  218. }
  219. triggerFarmWork(paramsObj, true);
  220. };
  221. function triggerFarmWork(paramsObj, showSuccess) {
  222. // 如果正在上传中,直接返回,防止重复调用
  223. if (isUploading.value) return;
  224. // 设置上传状态为 true
  225. isUploading.value = true;
  226. VE_API.monitor
  227. .triggerFarmWork(paramsObj)
  228. .then((res) => {
  229. if (res.code === 0) {
  230. if (showSuccess) {
  231. show.value = false;
  232. // successShow.value = true;
  233. ElMessage.success("农事已转入成功");
  234. emit("handleUploadSuccess", paramsObj);
  235. }
  236. }
  237. })
  238. .catch((error) => {
  239. console.error("触发农事失败:", error);
  240. })
  241. .finally(() => {
  242. // 无论成功或失败,都重置上传状态
  243. isUploading.value = false;
  244. });
  245. }
  246. function showPopup(data) {
  247. handleShow(data);
  248. }
  249. defineExpose({
  250. triggerFarmWork,
  251. showPopup,
  252. });
  253. function handleClosed() {
  254. eventBus.emit("upload:reset");
  255. // 清除所有数据
  256. images.value = [];
  257. uploadDate.value = "";
  258. executorId.value = null;
  259. needReview.value = false;
  260. reviewDay.value = null;
  261. currentPhenologyId.value = null;
  262. gardenId.value = null;
  263. problemTitle.value = "请选择问题";
  264. type.value = null;
  265. arrangeId.value = null;
  266. executorList.value = [];
  267. imgDesc.value = null;
  268. needExecutor.value = false;
  269. selectCurrentPhenology.value = false;
  270. phenologyList.value = [];
  271. isUploading.value = false;
  272. successShow.value = false;
  273. }
  274. onUnmounted(() => {
  275. eventBus.off("activeUpload:show", handleShow);
  276. eventBus.off("activeUpload:success", handleSuccess);
  277. eventBus.off("upload:changeArr", uploadChange);
  278. show.value = false;
  279. });
  280. </script>
  281. <style lang="scss" scoped>
  282. .active-upload-popup {
  283. z-index: 9999 !important;
  284. width: 90%;
  285. box-sizing: border-box;
  286. padding: 24px 18px 20px;
  287. background: linear-gradient(0deg, #ffffff 70%, #d1ebff 100%);
  288. border-radius: 10px;
  289. ::v-deep {
  290. .van-popup__close-icon {
  291. color: #000;
  292. }
  293. }
  294. .header {
  295. .title {
  296. font-size: 16px;
  297. font-weight: 500;
  298. display: flex;
  299. }
  300. align-items: center;
  301. .date-input {
  302. margin: 12px 0;
  303. ::v-deep {
  304. .el-input__inner {
  305. caret-color: transparent;
  306. }
  307. }
  308. }
  309. .review-day-input {
  310. border: 1px solid #dcdcdc;
  311. border-radius: 3px;
  312. ::v-deep {
  313. .el-input__wrapper {
  314. width: 40px;
  315. flex: none;
  316. box-shadow: none;
  317. }
  318. .el-input-group__append {
  319. box-shadow: none;
  320. background: none;
  321. }
  322. }
  323. }
  324. }
  325. .flex-header {
  326. display: flex;
  327. align-items: center;
  328. justify-content: space-between;
  329. margin-bottom: 12px;
  330. .date-input {
  331. margin: 0;
  332. }
  333. }
  334. .required {
  335. color: #ff4d4f;
  336. margin-right: 4px;
  337. }
  338. .tips-text {
  339. font-weight: 500;
  340. &.img-desc {
  341. font-size: 16px;
  342. }
  343. }
  344. .upload-wrap {
  345. margin: 12px 0 24px;
  346. }
  347. .example {
  348. width: 80px;
  349. height: 80px;
  350. }
  351. .example + .example {
  352. margin-left: 12px;
  353. }
  354. }
  355. .btn {
  356. padding: 8px;
  357. background: #2199f8;
  358. border-radius: 25px;
  359. color: #fff;
  360. font-size: 16px;
  361. text-align: center;
  362. cursor: pointer;
  363. transition: opacity 0.3s;
  364. &.disabled {
  365. opacity: 0.6;
  366. cursor: not-allowed;
  367. pointer-events: none;
  368. }
  369. }
  370. .success-popup {
  371. width: 300px;
  372. border-radius: 14px;
  373. padding: 28px 15px 20px;
  374. box-sizing: border-box;
  375. .success-wrap {
  376. text-align: center;
  377. }
  378. .success-icon {
  379. width: 68px;
  380. height: 68px;
  381. }
  382. .success-title {
  383. font-size: 24px;
  384. margin-top: 12px;
  385. }
  386. .success-sub {
  387. margin: 8px 0 32px;
  388. }
  389. }
  390. </style>
  391. <style lang="scss">
  392. // 全局样式,用于设置下拉框的 z-index(不受 scoped 限制)
  393. .custom-select-dropdown {
  394. z-index: 10000 !important;
  395. }
  396. </style>