activeUploadPopup.vue 15 KB

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