activeUploadPopup.vue 14 KB

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