farmInfoGroup.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <div class="farm-info-group">
  3. <!-- 顶部标题栏 -->
  4. <div class="info-header">
  5. <div class="back-btn" v-show="isBack" @click="handleBack">返回</div>
  6. <div class="title">
  7. <img class="title-icon" src="@/assets/images/common/chart-icon.png" alt="" />
  8. <span class="title-text">{{ !isBack ? "农场列表" : farmList[0].farmName }}</span>
  9. </div>
  10. </div>
  11. <!-- 主要内容区域 -->
  12. <div class="info-content" :style="{ overflowY: isBack ? 'hidden' : 'auto' }">
  13. <!-- 农场列表为空时显示暂无数据 -->
  14. <div v-if="!isBack && farmList.length === 0" class="empty-data">
  15. <div class="empty-text">暂无数据</div>
  16. </div>
  17. <div class="farm-info" v-for="item in farmList" :key="item" @click="handleFarmInfo(item)">
  18. <div class="lz-icon">
  19. <img src="@/assets/images/warningHome/lz-icon.png" alt="" />
  20. </div>
  21. <!-- 右侧信息区域 -->
  22. <div class="info-right">
  23. <div class="info-item farm-code">
  24. <span class="info-label">{{ isBack ? `农场编号:${item.farmCode}` : item.farmName }}</span>
  25. <div class="tags">
  26. <span class="tag">{{ item.speciesName }}</span>
  27. <span class="tag" v-show="item.varietyName">{{ item.varietyName }}</span>
  28. </div>
  29. </div>
  30. <div class="info-item">
  31. <span class="info-label">农场面积:</span>
  32. <span class="info-value">{{ item.area && item.area.toFixed(2) || 0 }}亩</span>
  33. </div>
  34. <div class="info-item">
  35. <span class="info-label">农场位置:</span>
  36. <span class="info-value">{{ item.location }}</span>
  37. </div>
  38. <div class="info-item">
  39. <span class="info-label">权属人:</span>
  40. <span class="info-value">{{ item.owner }}</span>
  41. </div>
  42. </div>
  43. </div>
  44. <template v-if="isBack">
  45. <div class="tabs">
  46. <div
  47. v-for="tab in tabs"
  48. :key="tab.key"
  49. class="tab-item"
  50. :class="{ active: activeTab === tab.key }"
  51. @click="activeTab = tab.key"
  52. >
  53. {{ tab.label }}
  54. </div>
  55. </div>
  56. <div class="tab-content">
  57. <div class="timeline" v-if="activeTab === 'crop'">
  58. <!-- 时间轴列表为空时显示暂无数据 -->
  59. <div v-if="timelineList.length === 0" class="empty-data">
  60. <div class="empty-text">暂无数据</div>
  61. </div>
  62. <div class="timeline-item" v-for="item in timelineList" :key="item.id">
  63. <div class="timeline-left">
  64. <div class="dot"></div>
  65. <div class="line"></div>
  66. </div>
  67. <div class="timeline-right">
  68. <div class="date">{{ item.recordTime && item.recordTime.slice(0, 10) || '' }}</div>
  69. <div class="text">{{ item.description }}</div>
  70. </div>
  71. </div>
  72. </div>
  73. <div v-else class="perception-content">
  74. <div class="perception-tabs">
  75. <div
  76. v-for="tab in perceptionTabs"
  77. :key="tab.key"
  78. class="perception-tab"
  79. :class="{ 'perception-tab--active': perceptionActive === tab.key }"
  80. @click="perceptionActive = tab.key"
  81. >
  82. <span class="label">{{ tab.label }}</span>
  83. <div class="underline"></div>
  84. </div>
  85. </div>
  86. <div class="perception-wrap">
  87. <equipment v-show="perceptionActive === 'device'" :farmId="currentFarmId"></equipment>
  88. <crop v-show="perceptionActive === 'crop'"></crop>
  89. </div>
  90. </div>
  91. </div>
  92. </template>
  93. </div>
  94. </div>
  95. </template>
  96. <script setup>
  97. import { ref, watch, onMounted, onUnmounted } from "vue";
  98. import equipment from "./equipment.vue";
  99. import crop from "./crop.vue";
  100. import eventBus from "@/api/eventBus";
  101. const props = defineProps({
  102. farmList: {
  103. type: Array,
  104. default: () => [],
  105. },
  106. });
  107. const defaultFarmList = ref([]);
  108. watch(() => props.farmList, (newVal) => {
  109. farmList.value = newVal;
  110. defaultFarmList.value = newVal;
  111. });
  112. const handleFarmClick = (farmData) => {
  113. farmList.value = [farmData];
  114. currentFarmId.value = farmData.farmId;
  115. isBack.value = true;
  116. if (currentFarmId.value) {
  117. fetchFarmPhenologyRecord(currentFarmId.value);
  118. }
  119. };
  120. onMounted(() => {
  121. // 在组件挂载时注册事件监听
  122. eventBus.on("distributionLayer:farmClick", handleFarmClick);
  123. });
  124. onUnmounted(() => {
  125. // 组件卸载时移除事件监听
  126. eventBus.off("distributionLayer:farmClick", handleFarmClick);
  127. });
  128. //查询农场物候记录
  129. const timelineList = ref([]);
  130. const fetchFarmPhenologyRecord = (farmId) => {
  131. VE_API.warning.fetchFarmPhenologyRecord({ farmId }).then(res => {
  132. timelineList.value = res.data || [];
  133. });
  134. };
  135. // 底部 tabs 配置
  136. const tabs = [
  137. { key: "crop", label: "作物档案" },
  138. { key: "perception", label: "感知记录" },
  139. ];
  140. // 感知类型 tabs
  141. const perceptionTabs = [
  142. { key: "device", label: "设备感知" },
  143. { key: "crop", label: "作物感知" },
  144. ];
  145. const activeTab = ref("crop"); // 默认选中感知记录
  146. const perceptionActive = ref("device"); // 默认选中设备感知
  147. const farmList = ref([]);
  148. const handleBack = () => {
  149. farmList.value = defaultFarmList.value;
  150. isBack.value = false;
  151. };
  152. const isBack = ref(false);
  153. const currentFarmId = ref(null);
  154. const handleFarmInfo = (item) => {
  155. currentFarmId.value = item.farmId;
  156. activeTab.value = "crop";
  157. perceptionActive.value = "device";
  158. farmList.value = [item];
  159. isBack.value = true;
  160. fetchFarmPhenologyRecord(item.farmId);
  161. };
  162. </script>
  163. <style lang="scss" scoped>
  164. .farm-info-group {
  165. position: absolute;
  166. top: 0px;
  167. right: 0;
  168. width: 376px;
  169. height: 100%;
  170. background: #232323;
  171. border-radius: 4px;
  172. box-sizing: border-box;
  173. border: 1px solid rgba(255, 255, 255, 0.16);
  174. .info-header {
  175. display: flex;
  176. align-items: center;
  177. padding: 6px 14px;
  178. border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  179. .back-btn {
  180. cursor: pointer;
  181. color: rgba(255, 255, 255, 0.55);
  182. }
  183. .title {
  184. flex: 1;
  185. display: flex;
  186. align-items: center;
  187. justify-content: center;
  188. gap: 8px;
  189. font-size: 18px;
  190. .title-icon {
  191. width: 19px;
  192. height: 13px;
  193. }
  194. }
  195. }
  196. .info-content {
  197. padding: 5px 10px;
  198. height: calc(100% - 50px);
  199. .farm-info + .farm-info {
  200. margin-top: 12px;
  201. }
  202. .farm-info {
  203. display: flex;
  204. align-items: flex-start;
  205. gap: 12px;
  206. .lz-icon {
  207. border-radius: 6px;
  208. background: rgba(70, 70, 70, 0.26);
  209. img {
  210. width: 65px;
  211. height: 65px;
  212. padding: 7px;
  213. }
  214. }
  215. .info-right {
  216. font-size: 12px;
  217. color: #9f9f9f;
  218. .info-item {
  219. display: flex;
  220. align-items: center;
  221. line-height: 18px;
  222. gap: 6px;
  223. cursor: pointer;
  224. &.farm-code {
  225. font-weight: 700;
  226. font-size: 16px;
  227. margin-bottom: 4px;
  228. color: #ffffff;
  229. }
  230. .tags {
  231. display: flex;
  232. gap: 4px;
  233. margin-left: auto;
  234. .tag {
  235. padding: 1px 6px;
  236. border: 1px solid #ffd489;
  237. border-radius: 2px;
  238. color: #ffd489;
  239. font-size: 12px;
  240. font-weight: 400;
  241. }
  242. }
  243. }
  244. }
  245. }
  246. .tabs {
  247. display: flex;
  248. gap: 10px;
  249. margin-top: 12px;
  250. .tab-item {
  251. padding: 6px 32px;
  252. text-align: center;
  253. border-radius: 4px;
  254. cursor: pointer;
  255. color: #ffffff;
  256. background: rgba(166, 166, 166, 0.08);
  257. border: 1px solid transparent;
  258. &.active {
  259. color: #ffd489;
  260. background: rgba(255, 212, 137, 0.2);
  261. border: 1px solid #ffd489;
  262. }
  263. }
  264. }
  265. .tab-content {
  266. margin: 12px 0;
  267. height: calc(100% - 145px);
  268. overflow-y: auto;
  269. .timeline {
  270. padding-right: 12px;
  271. .timeline-item {
  272. display: flex;
  273. align-items: flex-start;
  274. font-size: 14px;
  275. color: #ffffff;
  276. line-height: 22px;
  277. & + .timeline-item {
  278. margin-top: 24px;
  279. }
  280. .timeline-left {
  281. width: 24px;
  282. display: flex;
  283. flex-direction: column;
  284. align-items: center;
  285. .dot {
  286. width: 6px;
  287. height: 6px;
  288. border-radius: 50%;
  289. background: #ffd489;
  290. margin-top: 6px;
  291. }
  292. .line {
  293. border-left: 1px dashed rgba(255, 212, 137, 0.6);
  294. margin-top: 4px;
  295. height: 40px;
  296. }
  297. }
  298. .timeline-right {
  299. padding-left: 8px;
  300. .date {
  301. color: #ffd489;
  302. font-weight: 500;
  303. margin-bottom: 2px;
  304. }
  305. .text {
  306. color: #d7d7d7;
  307. }
  308. }
  309. }
  310. }
  311. .perception-content {
  312. height: 100%;
  313. .perception-tabs {
  314. display: flex;
  315. align-items: flex-end;
  316. gap: 20px;
  317. margin-bottom: 12px;
  318. .perception-tab {
  319. color: #ffffff;
  320. cursor: pointer;
  321. .underline {
  322. margin-top: 6px;
  323. width: 56px;
  324. height: 2px;
  325. background: transparent;
  326. border-radius: 2px;
  327. }
  328. &.perception-tab--active {
  329. color: #ffd489;
  330. .underline {
  331. background: #ffd489;
  332. }
  333. }
  334. }
  335. }
  336. .perception-wrap {
  337. height: calc(100% - 40px);
  338. overflow-y: auto;
  339. }
  340. }
  341. }
  342. .empty-data {
  343. display: flex;
  344. align-items: center;
  345. justify-content: center;
  346. height: 200px;
  347. .empty-text {
  348. color: rgba(255, 255, 255, 0.4);
  349. font-size: 14px;
  350. }
  351. }
  352. }
  353. }
  354. </style>