plan.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. <template>
  2. <div class="plan-page">
  3. <custom-header :name="pageType === 'plant' ? '种植方案' : '农事规划'"></custom-header>
  4. <div class="plan-content">
  5. <div class="plan-content-header" v-if="pageType === 'plant'">
  6. <el-select class="select-item" v-model="value" placeholder="选择品类">
  7. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
  8. </el-select>
  9. <tab-list type="light" v-model="active" :tabs="tabs" @change="handleTabChange" />
  10. </div>
  11. <div
  12. class="timeline-container"
  13. ref="timelineContainerRef"
  14. :class="{ 'timeline-container-plant': pageType === 'plant' }"
  15. >
  16. <div class="timeline-list" :style="getListStyle">
  17. <div class="timeline-middle-line"></div>
  18. <!-- 物候期覆盖条(progress 为起点,progress2 为终点,单位 %) -->
  19. <div
  20. v-for="(p, idx) in phenologyList"
  21. :key="p.id ?? idx"
  22. class="phenology-bar"
  23. :style="getPhenologyBarStyle(p)"
  24. >
  25. <div class="reproductive-list">
  26. <div
  27. v-for="(r, rIdx) in Array.isArray(p.reproductiveList) ? p.reproductiveList : []"
  28. :key="r.id ?? rIdx"
  29. class="reproductive-item"
  30. :class="{
  31. 'horizontal-text': getReproductiveItemHeight(p) < 30,
  32. 'vertical-lr-text': getReproductiveItemHeight(p) >= 30,
  33. }"
  34. :style="
  35. getReproductiveItemHeight(p) < 30
  36. ? { '--item-height': `${getReproductiveItemHeight(p)}px` }
  37. : {}
  38. "
  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-card"
  48. :class="getArrangeStatusClass(fw)"
  49. @click="handleRowClick(fw)"
  50. >
  51. <div class="card-header">
  52. <div class="header-left">
  53. <span class="farm-work-name">{{ fw.farmWorkName || "农事名称" }}</span>
  54. <span class="tag-standard">标准农事</span>
  55. </div>
  56. <div class="header-right">托管农事</div>
  57. </div>
  58. <div class="card-content">
  59. <span>{{ fw.warmReminder || "暂无提示" }}</span>
  60. <span class="edit-link" @click.stop="handleEdit(fw)">点击编辑</span>
  61. </div>
  62. <div
  63. v-if="
  64. getArrangeStatusClass(fw) === 'status-complete' ||
  65. getArrangeStatusClass(fw) === 'status-warning'
  66. "
  67. class="status-icon"
  68. :class="getArrangeStatusClass(fw)"
  69. >
  70. <el-icon
  71. v-if="getArrangeStatusClass(fw) === 'status-complete'"
  72. size="16"
  73. color="#1CA900"
  74. >
  75. <SuccessFilled />
  76. </el-icon>
  77. <el-icon v-else size="18" color="#FF953D">
  78. <WarnTriangleFilled />
  79. </el-icon>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. <div v-for="t in solarTerms" :key="t.id" class="timeline-term" :style="getTermStyle(t)">
  87. <span class="term-name">{{ t.displayName }}</span>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. <div class="custom-bottom-fixed-btns">
  93. <div class="bottom-btn-group">
  94. <div class="bottom-btn secondary-btn" @click="handlePhenologySetting">物候期设置</div>
  95. <div class="bottom-btn secondary-btn" v-if="pageType === 'plant'" @click="openCopyPlanPopup">
  96. {{ active === 1 ? "复制方案" : "方案设置" }}
  97. </div>
  98. </div>
  99. <div class="bottom-btn primary-btn" @click="addNewTask">新增农事</div>
  100. </div>
  101. </div>
  102. <!-- 农事信息弹窗 -->
  103. <detail-dialog ref="detailDialogRef" @triggerFarmWork="triggerFarmWork"></detail-dialog>
  104. <!-- 互动设置弹窗 -->
  105. <interact-popup
  106. ref="interactPopupRef"
  107. @handleSaveSuccess="getFarmWorkPlan"
  108. @handleDeleteInteract="handleDeleteInteract"
  109. ></interact-popup>
  110. <!-- 复制方案弹窗 -->
  111. <Popup v-model:show="showCopyPlan" class="copy-plan-popup" round closeable :close-on-click-overlay="false">
  112. <div class="copy-plan-content">
  113. <div class="label">{{ active === 1 ? "复制为" : "方案名称" }}</div>
  114. <el-input v-model="copyPlanName" size="large" placeholder="请输入方案名称" class="copy-plan-input" />
  115. </div>
  116. <div class="copy-plan-footer">
  117. <div class="btn btn-cancel" @click="handleCancelCopyPlan">{{ active === 1 ? "取消复制" : "删除方案" }}</div>
  118. <div class="btn btn-confirm" @click="handleConfirmCopyPlan">
  119. {{ active === 1 ? "确定复制" : "确定设置" }}
  120. </div>
  121. </div>
  122. </Popup>
  123. <!-- 物候期设置弹窗 -->
  124. <Popup
  125. v-model:show="showPhenologySetting"
  126. class="copy-plan-popup phenology-popup"
  127. round
  128. closeable
  129. :close-on-click-overlay="false"
  130. >
  131. <div class="phenology-header">物候期时间设置</div>
  132. <div class="phenology-list">
  133. <div
  134. class="phenology-item"
  135. v-for="(item, index) in mergedReproductiveList"
  136. :key="item.id || index"
  137. >
  138. <div class="item-label">
  139. <span class="label-text">{{ item.name }}</span>
  140. <span>起始时间</span>
  141. </div>
  142. <div class="item-value">
  143. <el-date-picker
  144. style="width: 100%"
  145. size="large"
  146. value-format="YYYY-MM-DD"
  147. v-model="item.startDate"
  148. type="date"
  149. placeholder="选择日期"
  150. />
  151. </div>
  152. </div>
  153. </div>
  154. <div class="phenology-footer" @click="handleConfirmPhenologySetting">确认设置</div>
  155. </Popup>
  156. </template>
  157. <script setup>
  158. import { ref, onMounted, computed, nextTick } from "vue";
  159. import { Popup } from "vant";
  160. import customHeader from "@/components/customHeader.vue";
  161. import tabList from "@/components/pageComponents/TabList.vue";
  162. import { useRouter, useRoute } from "vue-router";
  163. import detailDialog from "@/components/detailDialog.vue";
  164. import eventBus from "@/api/eventBus";
  165. import interactPopup from "@/components/popup/interactPopup.vue";
  166. import { ElMessage } from "element-plus";
  167. const router = useRouter();
  168. const route = useRoute();
  169. const solarTerms = ref([]);
  170. const phenologyList = ref([]);
  171. // 获取当前季节
  172. const getCurrentSeason = () => {
  173. const month = new Date().getMonth() + 1; // 1-12
  174. if (month >= 3 && month <= 5) {
  175. return "spring"; // 春季:3-5月
  176. } else if (month >= 6 && month <= 8) {
  177. return "summer"; // 夏季:6-8月
  178. } else if (month >= 9 && month <= 10) {
  179. return "autumn"; // 秋季:9-10月
  180. } else {
  181. return "winter"; // 冬季:12-2月
  182. }
  183. };
  184. const active = ref(1);
  185. const tabs = ref([
  186. {
  187. id: 1,
  188. name: "标准化方案",
  189. },
  190. {
  191. id: 2,
  192. name: "全托管方案",
  193. },
  194. {
  195. id: 3,
  196. name: "半托管方案",
  197. },
  198. ]);
  199. const handleTabChange = (id, item) => {
  200. active.value = id;
  201. console.log(id, item);
  202. };
  203. const value = ref("1");
  204. const options = ref([
  205. {
  206. value: "1",
  207. label: "荔枝",
  208. },
  209. {
  210. value: "2",
  211. label: "全托管方案",
  212. },
  213. ]);
  214. const pageType = ref("");
  215. onMounted(() => {
  216. pageType.value = route.query.pageType || "";
  217. getFarmWorkPlan();
  218. });
  219. const mergedReproductiveList = ref([])
  220. const getPhenologyList = async (containerSpaceTimeId) => {
  221. const res = await VE_API.monitor.listPhenology({ containerSpaceTimeId ,farmId: route.query.farmId });
  222. if (res.code === 0) {
  223. mergedReproductiveList.value = res.data || [];
  224. }
  225. };
  226. // 复制方案弹窗相关
  227. const showCopyPlan = ref(false);
  228. const showPhenologySetting = ref(false);
  229. const copyPlanName = ref("");
  230. const openCopyPlanPopup = () => {
  231. copyPlanName.value = "";
  232. showCopyPlan.value = true;
  233. };
  234. // 物候期设置弹窗
  235. const handlePhenologySetting = () => {
  236. showPhenologySetting.value = true;
  237. };
  238. /**
  239. * 确认物候期设置
  240. */
  241. const handleConfirmPhenologySetting = async () => {
  242. console.log(mergedReproductiveList.value);
  243. const params = {
  244. farmId: route.query.farmId,
  245. items: mergedReproductiveList.value.map(item => ({
  246. phenologyId: item.id,
  247. startDate: item.startDate,
  248. })),
  249. };
  250. const res = await VE_API.monitor.batchSaveFarmPhenologyTime(params);
  251. if (res.code === 0) {
  252. ElMessage.success("设置成功");
  253. showPhenologySetting.value = false;
  254. getFarmWorkPlan();
  255. }
  256. };
  257. // 取消复制方案
  258. const handleCancelCopyPlan = () => {
  259. showCopyPlan.value = false;
  260. };
  261. // 确定复制方案
  262. const handleConfirmCopyPlan = () => {
  263. if (!copyPlanName.value.trim()) {
  264. ElMessage.warning("请输入方案名称");
  265. return;
  266. }
  267. // TODO: 在此处调用复制方案的接口
  268. ElMessage.success("复制成功");
  269. showCopyPlan.value = false;
  270. };
  271. const getFarmWorkPlan = () => {
  272. // 如果不是首次加载,保存当前滚动位置
  273. let savedScrollTop = 0;
  274. if (!isInitialLoad.value && timelineContainerRef.value) {
  275. savedScrollTop = timelineContainerRef.value.scrollTop || 0;
  276. }
  277. VE_API.monitor
  278. .farmWorkPlan({ farmId: route.query.farmId })
  279. .then(({ data, code }) => {
  280. if (code === 0) {
  281. const list = Array.isArray(data?.solarTermsList) ? data.solarTermsList : [];
  282. getPhenologyList(data.phenologyList[0]?.containerSpaceTimeId)
  283. const filtered = list
  284. .filter((t) => t && t.type === 1)
  285. .map((t) => ({
  286. id:
  287. t.id ??
  288. t.solarTermsId ??
  289. t.termId ??
  290. `${t.name || t.solarTermsName || t.termName || "term"}-${t.createDate || ""}`,
  291. displayName: t.name || t.solarTermsName || t.termName || "节气",
  292. createDate: t.createDate || null,
  293. progress: Number(t.progress) || 0,
  294. }));
  295. solarTerms.value = filtered;
  296. // 物候期数据
  297. phenologyList.value = Array.isArray(data?.phenologyList)
  298. ? data.phenologyList.map((it) => {
  299. const reproductiveList = Array.isArray(it.reproductiveList)
  300. ? it.reproductiveList.map((r) => {
  301. const farmWorkArrangeList = Array.isArray(r.farmWorkArrangeList)
  302. ? r.farmWorkArrangeList.map((fw) => ({
  303. ...fw,
  304. containerSpaceTimeId: it.containerSpaceTimeId,
  305. }))
  306. : [];
  307. return {
  308. ...r,
  309. farmWorkArrangeList,
  310. };
  311. })
  312. : [];
  313. return {
  314. id: it.id ?? it.phenologyId ?? it.name ?? `${it.progress}-${it.progress2}`,
  315. progress: Number(it.progress) || 0, // 起点 %
  316. progress2: Number(it.progress2) || 0, // 终点 %
  317. // 兼容多种可能的开始时间字段
  318. startTimeMs: safeParseDate(
  319. it.startDate || it.beginDate || it.startTime || it.start || it.start_at
  320. ),
  321. reproductiveList,
  322. };
  323. })
  324. : [];
  325. // 等待 DOM 更新后处理滚动
  326. nextTick(() => {
  327. if (isInitialLoad.value) {
  328. // 首次加载:设置默认季节为当前季节,并自动滚动到对应位置
  329. const currentSeason = getCurrentSeason();
  330. handleSeasonClick(currentSeason);
  331. isInitialLoad.value = false;
  332. } else {
  333. // 非首次加载:恢复之前的滚动位置
  334. if (timelineContainerRef.value && savedScrollTop > 0) {
  335. timelineContainerRef.value.scrollTop = savedScrollTop;
  336. }
  337. }
  338. });
  339. }
  340. })
  341. .catch((error) => {
  342. console.error("获取农事规划数据失败:", error);
  343. });
  344. };
  345. // 新增农事
  346. const addNewTask = () => {
  347. ElMessage.warning("该功能正在升级中,敬请期待");
  348. };
  349. const triggerFarmWork = () => {
  350. eventBus.emit("activeUpload:show", {
  351. gardenIdVal: route.query.farmId,
  352. problemTitleVal: "请选择您出现" + curFarmObj.value.farmWorkName + "的时间",
  353. arrangeIdVal: curFarmObj.value.id,
  354. needExecutorVal: true,
  355. });
  356. };
  357. const curFarmObj = ref({});
  358. const handleRowClick = (item) => {
  359. curFarmObj.value = item;
  360. router.push({
  361. path: "/modify",
  362. query: { id: item.id, farmId: route.query.farmId, farmWorkId: item.farmWorkId, containerSpaceTimeId: item.containerSpaceTimeId, agriculturalStoreId: route.query.agriculturalStoreId },
  363. });
  364. };
  365. const interactPopupRef = ref(null);
  366. const handleEdit = (item) => {
  367. console.log(item);
  368. if (interactPopupRef.value) {
  369. interactPopupRef.value.showPopup(item);
  370. }
  371. };
  372. const handleDeleteInteract = (params) => {
  373. getFarmWorkPlan();
  374. };
  375. const timelineContainerRef = ref(null);
  376. // 标记是否为首次加载
  377. const isInitialLoad = ref(true);
  378. // 安全解析时间到时间戳(ms)
  379. const safeParseDate = (val) => {
  380. if (!val) return NaN;
  381. if (val instanceof Date) return val.getTime();
  382. if (typeof val === "number") return val;
  383. if (typeof val === "string") {
  384. // 兼容 "YYYY-MM-DD HH:mm:ss" -> Safari
  385. const s = val.replace(/-/g, "/").replace("T", " ");
  386. const d = new Date(s);
  387. return isNaN(d.getTime()) ? NaN : d.getTime();
  388. }
  389. return NaN;
  390. };
  391. // 计算最小progress值(第一个节气的progress)
  392. const minProgress = computed(() => {
  393. if (!solarTerms.value || solarTerms.value.length === 0) return 0;
  394. const progresses = solarTerms.value.map((t) => Number(t?.progress) || 0).filter((p) => !isNaN(p));
  395. return progresses.length > 0 ? Math.min(...progresses) : 0;
  396. });
  397. // 计算最大progress值
  398. const maxProgress = computed(() => {
  399. if (!solarTerms.value || solarTerms.value.length === 0) return 100;
  400. const progresses = solarTerms.value.map((t) => Number(t?.progress) || 0).filter((p) => !isNaN(p));
  401. return progresses.length > 0 ? Math.max(...progresses) : 100;
  402. });
  403. // 计算节气列表容器高度与项位置
  404. const getListStyle = computed(() => {
  405. const minP = minProgress.value;
  406. const maxP = maxProgress.value;
  407. const range = Math.max(1, maxP - minP); // 避免除0
  408. const total = (solarTerms.value?.length || 0) * 1200;
  409. const minH = total; // 无上下留白
  410. return { minHeight: `${minH}px` };
  411. });
  412. const getTermStyle = (t) => {
  413. const p = Math.max(0, Math.min(100, Number(t?.progress) || 0));
  414. const minP = minProgress.value;
  415. const maxP = maxProgress.value;
  416. const range = Math.max(1, maxP - minP); // 避免除0
  417. const total = (solarTerms.value?.length || 0) * 1200;
  418. // 将progress映射到0开始的位置,最小progress对应top: 0
  419. const normalizedP = range > 0 ? ((p - minP) / range) * 100 : 0;
  420. const top = (normalizedP / 100) * total;
  421. return {
  422. position: "absolute",
  423. top: `${top}px`,
  424. left: 0,
  425. width: "30px",
  426. height: "20px",
  427. display: "flex",
  428. alignItems: "flex-start",
  429. };
  430. };
  431. // 点击季节 → 滚动到对应节气(立春/立夏/立秋/立冬)
  432. const handleSeasonClick = (seasonValue) => {
  433. const mapping = {
  434. spring: "立春",
  435. summer: "立夏",
  436. autumn: "立秋",
  437. winter: "立冬",
  438. };
  439. const targetName = mapping[seasonValue];
  440. if (!targetName) return;
  441. const target = (solarTerms.value || []).find((t) => (t?.displayName || "") === targetName);
  442. if (!target) return;
  443. const p = Math.max(0, Math.min(100, Number(target.progress) || 0));
  444. const minP = minProgress.value;
  445. const maxP = maxProgress.value;
  446. const range = Math.max(1, maxP - minP);
  447. const total = (solarTerms.value?.length || 0) * 1200;
  448. const normalizedP = range > 0 ? ((p - minP) / range) * 100 : 0;
  449. const targetTop = (normalizedP / 100) * total; // 内容内的像素位置
  450. const wrap = timelineContainerRef.value;
  451. if (!wrap) return;
  452. const viewH = wrap.clientHeight || 0;
  453. const maxScroll = Math.max(0, wrap.scrollHeight - viewH);
  454. // 将目标位置稍微靠上(使用 0.35 视口高度做偏移)
  455. let scrollTop = Math.max(0, targetTop - viewH * 0.1);
  456. if (scrollTop > maxScroll) scrollTop = maxScroll;
  457. wrap.scrollTo({ top: scrollTop, behavior: "smooth" });
  458. };
  459. // 物候期覆盖条样式(使用像素计算,避免 100% 高度为 0 的问题)
  460. const getPhenologyBarStyle = (item) => {
  461. const p1 = Math.max(0, Math.min(100, Number(item?.progress) || 0));
  462. const p2 = Math.max(0, Math.min(100, Number(item?.progress2) || 0));
  463. const start = Math.min(p1, p2);
  464. const end = Math.max(p1, p2);
  465. const minP = minProgress.value;
  466. const maxP = maxProgress.value;
  467. const range = Math.max(1, maxP - minP);
  468. const total = (solarTerms.value?.length || 0) * 1200; // 有效绘制区高度(px)
  469. // 将progress映射到0开始的位置
  470. const normalizedStart = range > 0 ? ((start - minP) / range) * 100 : 0;
  471. const normalizedEnd = range > 0 ? ((end - minP) / range) * 100 : 0;
  472. let topPx = (normalizedStart / 100) * total;
  473. let heightPx = Math.max(2, ((normalizedEnd - normalizedStart) / 100) * total);
  474. // 计算第一个节气的位置(minProgress对应的位置,应该是0)
  475. const firstTermTop = 0; // 第一个节气在top: 0
  476. // 节气文字高度为46px,"小"字大约在文字的上半部分,约在15px位置
  477. // 让蓝色条的顶部对齐到"小"字的位置(firstTermTop + 15px)
  478. const minTop = firstTermTop + 10; // 对齐到"小"字位置(文字高度的约33%)
  479. if (topPx < minTop) {
  480. // 如果顶部小于最小位置,调整top和height
  481. const diff = minTop - topPx;
  482. topPx = minTop;
  483. heightPx = Math.max(2, heightPx - diff);
  484. }
  485. // 计算最后一个节气的位置(maxProgress对应的位置)
  486. const lastTermTop = (100 / 100) * total; // 因为normalizedEnd最大是100
  487. // 节气文字高度为46px,"至"字大约在文字的下半部分,约在30px位置
  488. // 让蓝色条的底部对齐到"至"字的位置(lastTermTop + 30px)
  489. const maxBottom = lastTermTop + 35; // 对齐到"至"字位置(文字高度的约65%)
  490. const barBottom = topPx + heightPx;
  491. if (barBottom > maxBottom) {
  492. heightPx = Math.max(2, maxBottom - topPx);
  493. }
  494. const now = Date.now();
  495. const isFuture = Number.isFinite(item?.startTimeMs) ? item.startTimeMs > now : start > 0; // 无开始时间时按起点>0近似
  496. // 反转:大于当前时间用灰色,小于等于当前时间用蓝色
  497. const barColor = isFuture ? "rgba(145, 145, 145, 0.1)" : "#2199F8";
  498. const beforeBg = isFuture ? "rgba(145, 145, 145, 0.1)" : "rgba(33, 153, 248, 0.1)";
  499. return {
  500. position: "absolute",
  501. left: "46px",
  502. width: "25px",
  503. top: `${topPx}px`,
  504. height: `${heightPx}px`,
  505. background: barColor,
  506. color: isFuture ? "#747778" : "#fff",
  507. "--bar-before-bg": beforeBg,
  508. zIndex: 2,
  509. };
  510. };
  511. // 农事状态样式映射(0:默认,1-4:正常,5:完成,6:预警)
  512. const getArrangeStatusClass = (fw) => {
  513. const t = fw?.flowStatus;
  514. if (t == null) return "status-default";
  515. if (t >= 0 && t <= 4) return "status-normal";
  516. if (t === 5) return "status-complete";
  517. if (t === 6) return "status-warning";
  518. return "status-default";
  519. };
  520. // 计算 phenology-bar 的高度(px)
  521. const getPhenologyBarHeight = (item) => {
  522. const p1 = Math.max(0, Math.min(100, Number(item?.progress) || 0));
  523. const p2 = Math.max(0, Math.min(100, Number(item?.progress2) || 0));
  524. const start = Math.min(p1, p2);
  525. const end = Math.max(p1, p2);
  526. const minP = minProgress.value;
  527. const maxP = maxProgress.value;
  528. const range = Math.max(1, maxP - minP);
  529. const total = (solarTerms.value?.length || 0) * 1200;
  530. // 将progress映射到0开始的位置
  531. const normalizedStart = range > 0 ? ((start - minP) / range) * 100 : 0;
  532. const normalizedEnd = range > 0 ? ((end - minP) / range) * 100 : 0;
  533. const heightPx = Math.max(2, ((normalizedEnd - normalizedStart) / 100) * total);
  534. return heightPx;
  535. };
  536. // 计算 reproductive-item 的高度(px)
  537. // 由于 reproductive-list 使用 grid-auto-rows: 1fr,每个 item 会等分 phenology-bar 的高度
  538. const getReproductiveItemHeight = (phenologyItem) => {
  539. const barHeight = getPhenologyBarHeight(phenologyItem);
  540. const listLength = Array.isArray(phenologyItem?.reproductiveList) ? phenologyItem.reproductiveList.length : 1;
  541. // 如果列表为空,返回 barHeight;否则等分
  542. return listLength > 0 ? barHeight / listLength : barHeight;
  543. };
  544. </script>
  545. <style scoped lang="scss">
  546. .plan-page {
  547. width: 100%;
  548. height: 100vh;
  549. background: #f5f7fb;
  550. .plan-content {
  551. padding: 12px 0;
  552. .plan-content-header {
  553. display: flex;
  554. align-items: center;
  555. gap: 12px;
  556. margin-bottom: 10px;
  557. margin-left: 12px;
  558. .select-item {
  559. width: 82px;
  560. ::v-deep {
  561. .el-select__wrapper {
  562. box-shadow: none;
  563. border-radius: 25px;
  564. border: 0.5px solid rgba(153, 153, 153, 0.5);
  565. }
  566. }
  567. }
  568. }
  569. .timeline-container {
  570. height: calc(100vh - 40px - 73px);
  571. overflow: auto;
  572. position: relative;
  573. box-sizing: border-box;
  574. padding: 0 12px;
  575. &.timeline-container-plant {
  576. height: calc(100vh - 40px - 73px - 38px);
  577. }
  578. .timeline-list {
  579. position: relative;
  580. }
  581. .timeline-middle-line {
  582. position: absolute;
  583. left: 15px; /* 位于节气文字列中间(列宽约30px) */
  584. top: 0;
  585. bottom: 0;
  586. width: 2px;
  587. background: #e8e8e8;
  588. z-index: 1;
  589. }
  590. .phenology-bar {
  591. display: flex;
  592. align-items: stretch;
  593. justify-content: center;
  594. box-sizing: border-box;
  595. .reproductive-list {
  596. display: grid;
  597. grid-auto-rows: 1fr; /* 子项等高,整体等分父高度 */
  598. align-items: stretch;
  599. justify-items: center; /* 子项居中 */
  600. width: 100%;
  601. height: 100%;
  602. box-sizing: border-box;
  603. }
  604. .reproductive-item {
  605. font-size: 12px;
  606. text-align: center;
  607. word-break: break-all;
  608. writing-mode: vertical-rl;
  609. text-orientation: upright;
  610. letter-spacing: 3px;
  611. width: 100%;
  612. line-height: 23px;
  613. color: inherit;
  614. position: relative;
  615. &.horizontal-text {
  616. writing-mode: horizontal-tb;
  617. text-orientation: mixed;
  618. letter-spacing: normal;
  619. line-height: calc(var(--item-height, 15px) - 3px);
  620. }
  621. &.vertical-lr-text {
  622. writing-mode: vertical-lr;
  623. text-orientation: upright;
  624. letter-spacing: 3px;
  625. line-height: 26px;
  626. }
  627. .arranges {
  628. position: absolute;
  629. left: 40px; /* 列与中线右侧一段距离 */
  630. top: 0;
  631. z-index: 3;
  632. display: flex;
  633. max-width: calc(100vw - 100px);
  634. gap: 12px;
  635. letter-spacing: 0px;
  636. .arrange-card {
  637. width: 97%;
  638. border: 0.5px solid #2199f8;
  639. border-radius: 8px;
  640. background: #fff;
  641. box-sizing: border-box;
  642. position: relative;
  643. padding: 8px;
  644. writing-mode: horizontal-tb;
  645. .card-header {
  646. display: flex;
  647. justify-content: space-between;
  648. align-items: center;
  649. .header-left {
  650. display: flex;
  651. align-items: center;
  652. gap: 8px;
  653. .farm-work-name {
  654. font-size: 14px;
  655. font-weight: 500;
  656. color: #1d2129;
  657. }
  658. .tag-standard {
  659. padding: 0 8px;
  660. background: rgba(119, 119, 119, 0.1);
  661. border-radius: 25px;
  662. font-weight: 400;
  663. font-size: 12px;
  664. color: #000;
  665. }
  666. }
  667. .header-right {
  668. font-size: 12px;
  669. color: #808080;
  670. padding: 0 8px;
  671. border-radius: 25px;
  672. }
  673. }
  674. .card-content {
  675. color: #909090;
  676. text-align: left;
  677. line-height: 1.55;
  678. margin: 4px 0 2px 0;
  679. .edit-link {
  680. color: #2199f8;
  681. margin-left: 5px;
  682. }
  683. }
  684. .status-icon {
  685. position: absolute;
  686. right: -8px;
  687. bottom: -8px;
  688. z-index: 3;
  689. }
  690. &::before {
  691. content: "";
  692. position: absolute;
  693. left: -6px;
  694. top: 50%;
  695. transform: translateY(-50%);
  696. width: 0;
  697. height: 0;
  698. border-top: 5px solid transparent;
  699. border-bottom: 5px solid transparent;
  700. border-right: 5px solid #2199f8;
  701. }
  702. }
  703. .arrange-card.status-warning {
  704. border-color: #ff953d;
  705. &::before {
  706. border-right-color: #ff953d;
  707. }
  708. }
  709. .arrange-card.status-complete {
  710. border-color: #1ca900;
  711. &::before {
  712. border-right-color: #1ca900;
  713. }
  714. }
  715. .arrange-card.status-normal {
  716. border-color: #2199f8;
  717. &::before {
  718. border-right-color: #2199f8;
  719. }
  720. }
  721. }
  722. }
  723. }
  724. .reproductive-item + .reproductive-item {
  725. border-top: 2px solid #fff;
  726. }
  727. .phenology-bar + .phenology-bar {
  728. border-top: 2px solid #fff;
  729. }
  730. .timeline-term {
  731. position: absolute;
  732. width: 30px;
  733. padding-right: 16px;
  734. display: flex;
  735. align-items: flex-start;
  736. z-index: 2; /* 置于中线之上 */
  737. .term-name {
  738. display: inline-block;
  739. width: 100%;
  740. height: 46px;
  741. line-height: 30px;
  742. background: #f5f7fb;
  743. font-size: 13px;
  744. word-break: break-all;
  745. writing-mode: vertical-rl;
  746. text-orientation: upright;
  747. color: rgba(174, 174, 174, 0.6);
  748. text-align: center;
  749. }
  750. }
  751. }
  752. }
  753. // 控制区域样式
  754. .custom-bottom-fixed-btns {
  755. .bottom-btn-group {
  756. display: flex;
  757. gap: 12px;
  758. }
  759. }
  760. }
  761. .copy-plan-popup {
  762. width: 100%;
  763. padding: 50px 12px 20px 12px;
  764. &::before {
  765. content: "";
  766. position: absolute;
  767. top: 0;
  768. left: 0;
  769. width: 100%;
  770. height: 136px;
  771. background: url("@/assets/img/monitor/popup-header-bg.png") no-repeat center center / 100% 100%;
  772. }
  773. .copy-plan-content {
  774. display: flex;
  775. align-items: center;
  776. gap: 12px;
  777. .label {
  778. font-size: 16px;
  779. font-weight: 500;
  780. }
  781. .copy-plan-input {
  782. width: calc(100% - 80px);
  783. }
  784. }
  785. .copy-plan-footer {
  786. display: flex;
  787. gap: 12px;
  788. margin-top: 20px;
  789. .btn {
  790. flex: 1;
  791. color: #666666;
  792. border: 1px solid #999999;
  793. border-radius: 25px;
  794. padding: 10px 0;
  795. font-size: 16px;
  796. text-align: center;
  797. &.btn-confirm {
  798. color: #fff;
  799. border: 1px solid #2199f8;
  800. background: #2199f8;
  801. }
  802. }
  803. }
  804. }
  805. .phenology-popup {
  806. padding: 28px 20px 20px;
  807. .phenology-header {
  808. font-size: 24px;
  809. text-align: center;
  810. margin-bottom: 20px;
  811. font-family: "PangMenZhengDao";
  812. }
  813. .phenology-list {
  814. width: 100%;
  815. .phenology-item {
  816. width: 100%;
  817. display: flex;
  818. align-items: center;
  819. justify-content: space-between;
  820. .item-label {
  821. display: flex;
  822. align-items: center;
  823. gap: 4px;
  824. font-size: 15px;
  825. color: rgba(0, 0, 0, 0.4);
  826. .label-text {
  827. color: #000;
  828. font-size: 16px;
  829. font-weight: 500;
  830. }
  831. }
  832. .item-value {
  833. width: calc(100% - 156px);
  834. }
  835. }
  836. .phenology-item + .phenology-item {
  837. margin-top: 10px;
  838. }
  839. }
  840. .phenology-footer{
  841. width: 100%;
  842. text-align: center;
  843. font-size: 16px;
  844. margin-top: 20px;
  845. color: #fff;
  846. background: #2199f8;
  847. border-radius: 25px;
  848. padding: 10px 0;
  849. }
  850. }
  851. </style>