plan.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. <template>
  2. <div class="plan-page">
  3. <custom-header name="农事规划"></custom-header>
  4. <div class="plan-content">
  5. <div class="filter-wrap">
  6. <div class="season-tabs">
  7. <div
  8. v-for="s in seasons"
  9. :key="s.value"
  10. class="season-tab"
  11. :class="{ active: s.value === activeSeason }"
  12. @click="handleSeasonClick(s.value)"
  13. >
  14. {{ s.label }}
  15. </div>
  16. </div>
  17. <div class="status-filter">
  18. <div v-for="status in statusList" :key="status.value" class="status-item" :class="status.color">
  19. <div class="status-dot"></div>
  20. <span class="status-text">{{ status.label }}</span>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="timeline-container" ref="timelineContainerRef">
  25. <div class="timeline-list" :style="getListStyle">
  26. <div class="timeline-middle-line"></div>
  27. <!-- 物候期覆盖条(progress 为起点,progress2 为终点,单位 %) -->
  28. <div
  29. v-for="(p, idx) in phenologyList"
  30. :key="p.id ?? idx"
  31. class="phenology-bar"
  32. :style="getPhenologyBarStyle(p)"
  33. >
  34. <div class="reproductive-list">
  35. <div
  36. v-for="(r, rIdx) in Array.isArray(p.reproductiveList) ? p.reproductiveList : []"
  37. :key="r.id ?? rIdx"
  38. class="reproductive-item"
  39. >
  40. {{ r.name }}
  41. <div class="arranges">
  42. <div
  43. v-for="(fw, aIdx) in Array.isArray(r.farmWorkArrangeList)
  44. ? r.farmWorkArrangeList
  45. : []"
  46. :key="fw.id ?? aIdx"
  47. class="arrange-box"
  48. :class="getArrangeStatusClass(fw)"
  49. @click="handleRowClick(fw)"
  50. >
  51. <span class="arrange-text">{{ fw.farmWorkName }}</span>
  52. <div
  53. v-if="
  54. getArrangeStatusClass(fw) === 'status-complete' ||
  55. getArrangeStatusClass(fw) === 'status-warning'
  56. "
  57. class="status-icon"
  58. :class="getArrangeStatusClass(fw)"
  59. >
  60. <el-icon
  61. v-if="getArrangeStatusClass(fw) === 'status-complete'"
  62. size="16"
  63. color="#1CA900"
  64. >
  65. <SuccessFilled />
  66. </el-icon>
  67. <el-icon v-else size="18" color="#FF953D">
  68. <WarnTriangleFilled />
  69. </el-icon>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. <div v-for="t in solarTerms" :key="t.id" class="timeline-term" :style="getTermStyle(t)">
  77. <span class="term-name">{{ t.displayName }}</span>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="control-section">
  82. <div class="toggle-group">
  83. <el-switch v-model="isDefaultEnabled" />
  84. <span class="toggle-label">{{ isDefaultEnabled ? "默认" : "" }}发起农情需求</span>
  85. </div>
  86. <div class="add-button-group">
  87. <div class="add-button button" @click="addNewTask">新增农事</div>
  88. <div class="button" @click="manageTask">农事管理</div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <!-- 农事信息弹窗 -->
  94. <detail-dialog ref="detailDialogRef" @triggerFarmWork="triggerFarmWork"></detail-dialog>
  95. <!-- 新增:激活上传弹窗 -->
  96. <active-upload-popup @handleUploadSuccess="getFarmWorkPlan"></active-upload-popup>
  97. </template>
  98. <script setup>
  99. import { reactive, ref, onMounted, computed } from "vue";
  100. import customHeader from "@/components/customHeader.vue";
  101. import { useRouter, useRoute } from "vue-router";
  102. import detailDialog from "@/components/detailDialog.vue";
  103. import eventBus from "@/api/eventBus";
  104. import activeUploadPopup from "@/components/popup/activeUploadPopup.vue";
  105. import { SuccessFilled, WarningFilled } from "@element-plus/icons-vue";
  106. const router = useRouter();
  107. const route = useRoute();
  108. // 状态列表数据
  109. const seasons = reactive([
  110. { value: "spring", label: "春季" },
  111. { value: "summer", label: "夏季" },
  112. { value: "autumn", label: "秋季" },
  113. { value: "winter", label: "冬季" },
  114. ]);
  115. const activeSeason = ref("");
  116. const statusList = reactive([
  117. { value: "pending", label: "待触发", color: "gray" },
  118. { value: "executing", label: "待完成", color: "blue" },
  119. { value: "completed", label: "已完成", color: "green" },
  120. { value: "expired", label: "已过期", color: "orange" },
  121. ]);
  122. const solarTerms = ref([]);
  123. const phenologyList = ref([]);
  124. onMounted(() => {
  125. getFarmWorkPlan();
  126. });
  127. const getFarmWorkPlan = () => {
  128. VE_API.monitor
  129. .farmWorkPlan({ farmId: route.query.farmId })
  130. .then(({ data, code }) => {
  131. if (code === 0) {
  132. const list = Array.isArray(data?.solarTermsList) ? data.solarTermsList : [];
  133. const filtered = list
  134. .filter((t) => t && t.type === 1)
  135. .map((t) => ({
  136. id:
  137. t.id ??
  138. t.solarTermsId ??
  139. t.termId ??
  140. `${t.name || t.solarTermsName || t.termName || "term"}-${t.createDate || ""}`,
  141. displayName: t.name || t.solarTermsName || t.termName || "节气",
  142. createDate: t.createDate || null,
  143. progress: Number(t.progress) || 0,
  144. }));
  145. solarTerms.value = filtered;
  146. // 物候期数据
  147. phenologyList.value = Array.isArray(data?.phenologyList)
  148. ? data.phenologyList.map((it) => ({
  149. id: it.id ?? it.phenologyId ?? it.name ?? `${it.progress}-${it.progress2}`,
  150. progress: Number(it.progress) || 0, // 起点 %
  151. progress2: Number(it.progress2) || 0, // 终点 %
  152. // 兼容多种可能的开始时间字段
  153. startTimeMs: safeParseDate(
  154. it.startDate || it.beginDate || it.startTime || it.start || it.start_at
  155. ),
  156. reproductiveList: Array.isArray(it.reproductiveList) ? it.reproductiveList : [],
  157. }))
  158. : [];
  159. }
  160. })
  161. .catch((error) => {
  162. console.error("获取农事规划数据失败:", error);
  163. });
  164. };
  165. // 切换开关状态
  166. const isDefaultEnabled = ref(true);
  167. // 新增农事
  168. const addNewTask = () => {
  169. router.push({
  170. path: "/modify_work",
  171. query: { data: JSON.stringify(["生长异常"]), gardenId: 766, isAdd: true },
  172. });
  173. };
  174. const triggerFarmWork = () =>{
  175. eventBus.emit("activeUpload:show", {
  176. gardenIdVal: route.query.farmId,
  177. problemTitleVal: curFarmObj.value.farmWorkName,
  178. arrangeIdVal: curFarmObj.value.id,
  179. });
  180. }
  181. const curFarmObj = ref({});
  182. const handleRowClick = (item) => {
  183. curFarmObj.value = item;
  184. // 0:默认,1-4:正常,5:完成,6:预警
  185. if (item.flowStatus === 5) {
  186. router.push({
  187. path: "/review_work",
  188. query: {
  189. json: JSON.stringify({ id: item.farmWorkRecordId }),
  190. },
  191. });
  192. } else if (item.flowStatus === null) {
  193. detailDialogRef.value.showDialog(item.farmWorkId);
  194. } else if (item.flowStatus === 6 || (item.flowStatus < 5 && item.flowStatus >= 0)) {
  195. router.push({
  196. path: "/completed_work",
  197. query: {
  198. json: JSON.stringify({ id: item.farmWorkRecordId }),
  199. },
  200. });
  201. }
  202. };
  203. const manageTask = () => {
  204. router.push({
  205. path: "/agri_services_manage",
  206. query: {
  207. type: "manage",
  208. },
  209. });
  210. };
  211. const detailDialogRef = ref(null);
  212. const timelineContainerRef = ref(null);
  213. // 安全解析时间到时间戳(ms)
  214. const safeParseDate = (val) => {
  215. if (!val) return NaN;
  216. if (val instanceof Date) return val.getTime();
  217. if (typeof val === "number") return val;
  218. if (typeof val === "string") {
  219. // 兼容 "YYYY-MM-DD HH:mm:ss" -> Safari
  220. const s = val.replace(/-/g, "/").replace("T", " ");
  221. const d = new Date(s);
  222. return isNaN(d.getTime()) ? NaN : d.getTime();
  223. }
  224. return NaN;
  225. };
  226. // 计算节气列表容器高度与项位置
  227. const getListStyle = computed(() => {
  228. const total = (solarTerms.value?.length || 0) * 100;
  229. const minH = 50 + total + 50; // 上下各 50
  230. return { minHeight: `${minH}px` };
  231. });
  232. const getTermStyle = (t) => {
  233. const p = Math.max(0, Math.min(100, Number(t?.progress) || 0));
  234. const total = (solarTerms.value?.length || 0) * 100;
  235. const top = 50 + (p / 100) * total;
  236. return {
  237. position: "absolute",
  238. top: `${top}px`,
  239. left: 0,
  240. transform: "translateY(-50%)",
  241. width: "30px",
  242. height: "20px",
  243. display: "flex",
  244. alignItems: "center",
  245. };
  246. };
  247. // 点击季节 → 滚动到对应节气(立春/立夏/立秋/立冬)
  248. const handleSeasonClick = (seasonValue) => {
  249. activeSeason.value = seasonValue;
  250. const mapping = {
  251. spring: "立春",
  252. summer: "立夏",
  253. autumn: "立秋",
  254. winter: "立冬",
  255. };
  256. const targetName = mapping[seasonValue];
  257. if (!targetName) return;
  258. const target = (solarTerms.value || []).find((t) => (t?.displayName || "") === targetName);
  259. if (!target) return;
  260. const p = Math.max(0, Math.min(100, Number(target.progress) || 0));
  261. const total = (solarTerms.value?.length || 0) * 100;
  262. const targetTop = 50 + (p / 100) * total; // 内容内的像素位置
  263. const wrap = timelineContainerRef.value;
  264. if (!wrap) return;
  265. const viewH = wrap.clientHeight || 0;
  266. const maxScroll = Math.max(0, wrap.scrollHeight - viewH);
  267. // 将目标位置稍微靠上(使用 0.35 视口高度做偏移)
  268. let scrollTop = Math.max(0, targetTop - viewH * 0.1);
  269. if (scrollTop > maxScroll) scrollTop = maxScroll;
  270. wrap.scrollTo({ top: scrollTop, behavior: "smooth" });
  271. };
  272. // 物候期覆盖条样式(使用像素计算,避免 100% 高度为 0 的问题)
  273. const getPhenologyBarStyle = (item) => {
  274. const p1 = Math.max(0, Math.min(100, Number(item?.progress) || 0));
  275. const p2 = Math.max(0, Math.min(100, Number(item?.progress2) || 0));
  276. const start = Math.min(p1, p2);
  277. const end = Math.max(p1, p2);
  278. const total = (solarTerms.value?.length || 0) * 100; // 有效绘制区高度(px)
  279. const topPx = 50 + (start / 100) * total;
  280. const heightPx = Math.max(2, ((end - start) / 100) * total);
  281. const now = Date.now();
  282. const isFuture = Number.isFinite(item?.startTimeMs) ? item.startTimeMs > now : start > 0; // 无开始时间时按起点>0近似
  283. // 反转:大于当前时间用灰色,小于等于当前时间用蓝色
  284. const barColor = isFuture ? "rgba(145, 145, 145, 0.1)" : "#2199F8";
  285. const beforeBg = isFuture ? "rgba(145, 145, 145, 0.1)" : "rgba(33, 153, 248, 0.1)";
  286. return {
  287. position: "absolute",
  288. left: "46px",
  289. width: "25px",
  290. top: `${topPx}px`,
  291. height: `${heightPx}px`,
  292. background: barColor,
  293. color: isFuture ? "#747778" : "#fff",
  294. "--bar-before-bg": beforeBg,
  295. zIndex: 2,
  296. };
  297. };
  298. // 农事状态样式映射(0:默认,1-4:正常,5:完成,6:预警)
  299. const getArrangeStatusClass = (fw) => {
  300. const t = fw?.flowStatus;
  301. if (t == null) return "status-default";
  302. if (t >= 0 && t <= 4) return "status-normal";
  303. if (t === 5) return "status-complete";
  304. if (t === 6) return "status-warning";
  305. return "status-default";
  306. };
  307. </script>
  308. <style scoped lang="scss">
  309. .plan-page {
  310. width: 100%;
  311. height: 100vh;
  312. background: #fff;
  313. .plan-content {
  314. .filter-wrap {
  315. background: #fff;
  316. padding: 13px 12px;
  317. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  318. border-radius: 0 0 20px 20px;
  319. .status-filter {
  320. background: #fff;
  321. padding: 3px 17px;
  322. display: flex;
  323. align-items: center;
  324. gap: 16px;
  325. font-size: 12px;
  326. .status-item {
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. gap: 6px;
  331. flex: 1;
  332. &.gray {
  333. color: #c4c6c9;
  334. .status-dot {
  335. background-color: #c4c6c9;
  336. }
  337. }
  338. &.blue {
  339. color: #2199f8;
  340. .status-dot {
  341. background-color: #2199f8;
  342. }
  343. }
  344. &.green {
  345. color: #1ca900;
  346. .status-dot {
  347. background-color: #1ca900;
  348. }
  349. }
  350. &.orange {
  351. color: #ff953d;
  352. .status-dot {
  353. background-color: #ff953d;
  354. }
  355. }
  356. .status-dot {
  357. width: 6px;
  358. height: 6px;
  359. border-radius: 50%;
  360. }
  361. }
  362. }
  363. .season-tabs {
  364. display: flex;
  365. gap: 8px;
  366. margin-bottom: 12px;
  367. .season-tab {
  368. flex: 1;
  369. padding: 7px;
  370. text-align: center;
  371. background: #f3f3f3;
  372. color: #898a8a;
  373. border-radius: 3px;
  374. border: 1px solid transparent;
  375. font-size: 12px;
  376. }
  377. .season-tab.active {
  378. background: #ffffff;
  379. color: #2199f8;
  380. border-color: #2199f8;
  381. }
  382. }
  383. }
  384. .timeline-container {
  385. height: calc(100vh - 93px - 40px - 73px);
  386. overflow: auto;
  387. position: relative;
  388. box-sizing: border-box;
  389. padding: 0 12px;
  390. .timeline-list {
  391. position: relative;
  392. }
  393. .timeline-middle-line {
  394. position: absolute;
  395. left: 15px; /* 位于节气文字列中间(列宽约30px) */
  396. top: 50px;
  397. bottom: 50px;
  398. width: 2px;
  399. background: #e8e8e8;
  400. z-index: 1;
  401. }
  402. .phenology-bar {
  403. display: flex;
  404. align-items: stretch;
  405. justify-content: center;
  406. box-sizing: border-box;
  407. &::before {
  408. content: "";
  409. position: absolute;
  410. top: 0;
  411. left: 25px;
  412. width: calc(100vw - 100px);
  413. height: 100%;
  414. background: var(--bar-before-bg, rgba(201, 201, 201, 0.1));
  415. z-index: 1;
  416. }
  417. .reproductive-list {
  418. display: grid;
  419. grid-auto-rows: 1fr; /* 子项等高,整体等分父高度 */
  420. align-items: stretch;
  421. justify-items: center; /* 子项居中 */
  422. width: 100%;
  423. height: 100%;
  424. box-sizing: border-box;
  425. }
  426. .reproductive-item {
  427. font-size: 12px;
  428. text-align: center;
  429. word-break: break-all;
  430. writing-mode: vertical-rl;
  431. text-orientation: upright;
  432. letter-spacing: 3px;
  433. width: 100%;
  434. line-height: 23px;
  435. color: inherit;
  436. position: relative;
  437. .arranges {
  438. position: absolute;
  439. left: 48px; /* 列与中线右侧一段距离 */
  440. top: 50%;
  441. transform: translateY(-50%);
  442. z-index: 3;
  443. .arrange-box {
  444. width: 36px;
  445. height: 36px;
  446. border: 1px solid rgba(199, 199, 199, 0.6);
  447. border-radius: 2px;
  448. background: #fff;
  449. color: #a5a7a9;
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. box-sizing: border-box;
  454. position: relative;
  455. font-size: 12px;
  456. .arrange-text {
  457. writing-mode: horizontal-tb;
  458. line-height: 14px;
  459. text-align: center;
  460. padding-left: 3px;
  461. }
  462. .status-icon {
  463. position: absolute;
  464. right: -10px;
  465. bottom: -10px;
  466. z-index: 3;
  467. }
  468. &::before {
  469. content: "";
  470. position: absolute;
  471. left: -4px;
  472. top: 50%;
  473. transform: translateY(-50%);
  474. width: 0;
  475. height: 0;
  476. border-top: 4px solid transparent;
  477. border-bottom: 4px solid transparent;
  478. border-right: 4px solid currentColor; /* 与文字/边框颜色一致 */
  479. }
  480. }
  481. .arrange-box + .arrange-box {
  482. margin-right: 16px;
  483. }
  484. .arrange-box.status-warning {
  485. border-color: #ff953d;
  486. color: #ff953d;
  487. }
  488. .arrange-box.status-complete {
  489. border-color: #1ca900;
  490. color: #1ca900;
  491. }
  492. .arrange-box.status-normal {
  493. border-color: #2199f8;
  494. color: #2199f8;
  495. }
  496. }
  497. }
  498. }
  499. .reproductive-item + .reproductive-item {
  500. border-top: 2px solid #fff;
  501. }
  502. .phenology-bar + .phenology-bar {
  503. border-top: 2px solid #fff;
  504. }
  505. .timeline-term {
  506. position: absolute;
  507. width: 30px;
  508. padding-right: 16px;
  509. display: flex;
  510. align-items: center;
  511. z-index: 2; /* 置于中线之上 */
  512. .term-name {
  513. display: inline-block;
  514. width: 100%;
  515. height: 46px;
  516. line-height: 30px;
  517. background: #fff;
  518. font-size: 13px;
  519. word-break: break-all;
  520. writing-mode: vertical-rl;
  521. text-orientation: upright;
  522. color: rgba(174, 174, 174, 0.6);
  523. letter-spacing: 2px;
  524. text-align: center;
  525. }
  526. }
  527. }
  528. // 控制区域样式
  529. .control-section {
  530. position: fixed;
  531. width: 100%;
  532. left: 0;
  533. box-sizing: border-box;
  534. bottom: 0px;
  535. background: #fff;
  536. padding: 16px 12px;
  537. display: flex;
  538. justify-content: space-between;
  539. align-items: center;
  540. border-top: 1px solid #f0f0f0;
  541. .toggle-group {
  542. display: flex;
  543. align-items: center;
  544. gap: 8px;
  545. .toggle-label {
  546. font-size: 13px;
  547. color: #141414;
  548. }
  549. }
  550. .add-button-group {
  551. display: flex;
  552. align-items: center;
  553. gap: 8px;
  554. .button {
  555. color: #2199f8;
  556. border-radius: 25px;
  557. padding: 9px 15px;
  558. border: 1px solid #2199f8;
  559. }
  560. .add-button {
  561. background: linear-gradient(120deg, #76c3ff 0%, #2199f8 100%);
  562. color: white;
  563. border: 1px solid transparent;
  564. }
  565. }
  566. }
  567. }
  568. }
  569. </style>