plan.vue 23 KB

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