index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <custom-header v-if="isHeaderShow" name="农场详情"></custom-header>
  3. <div class="monitor-index" :style="{ height: `calc(100vh - ${tabBarHeight}px)` }">
  4. <!-- 天气遮罩 -->
  5. <div class="weather-mask" v-show="isExpanded" @click="handleMaskClick"></div>
  6. <!-- 天气 -->
  7. <weather-info ref="weatherInfoRef" from="monitor" class="weather-info" @weatherExpanded="weatherExpanded"
  8. @changeGarden="changeGarden" :isGarden="true" :gardenId="defaultGardenId"></weather-info>
  9. <!-- 作物档案 -->
  10. <div class="archives-time-line">
  11. <div class="archives-time-line-header">
  12. <div class="line-title" @click="handlePage">农情档案</div>
  13. <div class="header-right">
  14. <div class="add-variety-btn" v-if="varietyTabs.length > 0" @click="handleAddVariety">
  15. <span>分区管理</span>
  16. </div>
  17. <el-date-picker style="width: 110px" v-model="date" type="year" placeholder="全部日期" />
  18. </div>
  19. </div>
  20. <!-- 品种选择 -->
  21. <div class="variety-tabs" v-if="varietyTabs.length > 0">
  22. <div v-for="(v, index) in varietyTabs" :key="index" class="variety-tab"
  23. :class="{ 'variety-tab--active': activeVariety === index }" @click="handleVarietyClick(v, index)">
  24. {{ v.regionName || v.problemZoneTypeName }}
  25. </div>
  26. </div>
  27. <template v-if="!varietyTabs.length">
  28. <div class="lock-img" @click="handleLockClick">
  29. <img src="@/assets/img/home/lock-blue.png" alt="" class="lock-img-item" />
  30. <div class="lock-text">
  31. 专属数字农场,种好卖好
  32. <div>点击解锁一键溯源增产</div>
  33. </div>
  34. <div class="lock-btn">点击解锁</div>
  35. </div>
  36. <img class="example-img" src="@/assets/img/monitor/example.png" alt="">
  37. </template>
  38. <div class="archives-time-line-content">
  39. <!-- <div class="report-box" v-if="hasReport">
  40. <div class="box-content">
  41. <div class="box-title" @click="handleReportClick">
  42. <span>农情互动报告</span>
  43. <el-icon>
  44. <CaretRight />
  45. </el-icon>
  46. </div>
  47. <span class="box-text">点击查看您的长势报告</span>
  48. </div>
  49. <img src="@/assets/img/monitor/report-icon.png" alt="" class="report-icon" />
  50. </div> -->
  51. <div class="time-line">
  52. <archives-farm-time-line :problemZoneId="currentVariety?.id" :farmId="farmIdData" :regionId="regionData"></archives-farm-time-line>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. <!-- 勾选区域引导弹窗 -->
  58. <select-region-popup v-model:show="showSelectRegionPopup" :title="titlePopup" @confirm="handleGoSelectRegion"
  59. @skip="handleSkipSelectRegion" />
  60. <!-- 农事执行弹窗(勾选区域引导弹窗显示时不展示) -->
  61. <agri-execute-popup v-if="!showSelectRegionPopup" ref="agriExecutePopupRef" />
  62. <start-interact-popup ref="startInteractPopupRef" />
  63. </template>
  64. <script setup>
  65. import { ref, computed, onActivated, onDeactivated, onMounted } from "vue";
  66. import customHeader from "@/components/customHeader.vue";
  67. import { useStore } from "vuex";
  68. import wx from "weixin-js-sdk";
  69. import weatherInfo from "@/components/weatherInfo.vue";
  70. import { useRouter, useRoute } from "vue-router";
  71. import selectRegionPopup from "@/components/popup/selectRegionPopup.vue";
  72. import { ElMessage, ElMessageBox } from "element-plus";
  73. import ArchivesFarmTimeLine from "@/components/pageComponents/ArchivesFarmTimeLine.vue";
  74. import agriExecutePopup from "@/components/popup/agriExecutePopup.vue";
  75. import startInteractPopup from "@/components/popup/startInteractPopup.vue";
  76. const startInteractPopupRef = ref(null);
  77. const handlePage = () => {
  78. // router.push("/interaction_list");
  79. }
  80. const agriExecutePopupRef = ref(null);
  81. // 品种选择(作物档案内)- 根据主体ID动态获取分区列表
  82. const varietyTabs = ref([]);
  83. const activeVariety = ref(0);
  84. const getVarietyTabs = async (isShowPopup = true) => {
  85. if (!gardenId.value) {
  86. return;
  87. }
  88. try {
  89. const res = await VE_API.basic_farm.fetchProblemZoneList({
  90. subjectId: gardenId.value,
  91. });
  92. // const res = await VE_API.monitor.listRegionsBySubjectId({
  93. // subjectId: gardenId.value,
  94. // });
  95. if(res.data && res.data.regionList && res.data.problemZones){
  96. varietyTabs.value = res.data.regionList.concat(res.data.problemZones)
  97. }
  98. if (varietyTabs.value.length > 0) {
  99. handleVarietyClick(varietyTabs.value[activeVariety.value || 0], activeVariety.value || 0)
  100. if (isShowPopup && !showSelectRegionPopup.value && agriExecutePopupRef.value) {
  101. agriExecutePopupRef.value.showPopup(varietyTabs.value[activeVariety.value || 0].farmId);
  102. }
  103. }
  104. } catch (error) {
  105. console.error("获取主体分区列表失败:", error);
  106. }
  107. };
  108. const farmIdData = ref(null);
  109. const regionData = ref(null);
  110. const titlePopup = ref("");
  111. const currentVariety = ref({});
  112. const handleVarietyClick = (tab, index) => {
  113. activeVariety.value = index;
  114. if(tab.regionId){
  115. farmIdData.value = tab.farmId;
  116. regionData.value = tab.regionId;
  117. }
  118. currentVariety.value = tab;
  119. if (tab.lastViewTime == null && tab.regionId) {
  120. titlePopup.value = `勾选 ${tab.regionName} 区域`;
  121. showSelectRegionPopup.value = true;
  122. VE_API.basic_farm.updateLastViewTime({
  123. regionId: tab.regionId,
  124. }).then(() => {
  125. getVarietyTabs(false);
  126. });
  127. }
  128. };
  129. const date = ref(new Date());
  130. const showSelectRegionPopup = ref(false);
  131. const handleAddVariety = () => {
  132. // router.push("/interaction?addVariety=true&subjectId=" + gardenId.value);
  133. router.push(`/draw_area?subjectId=${gardenId.value}&type=viewOnly`);
  134. };
  135. const handleSkipSelectRegion = () => {
  136. showSelectRegionPopup.value = false;
  137. };
  138. const handleGoSelectRegion = () => {
  139. showSelectRegionPopup.value = false;
  140. router.push({
  141. path: "/draw_area",
  142. query: {
  143. subjectId: gardenId.value,
  144. varietyId: currentVariety.value.typeId
  145. },
  146. });
  147. };
  148. const showFarmPopup = ref(false); // 农场领取成功弹窗
  149. const defaultGardenId = ref(null);
  150. const isHeaderShow = ref(false);
  151. const isDefaultFarm = ref(false);
  152. const weatherInfoRef = ref(null);
  153. onActivated(() => {
  154. sessionStorage.removeItem('interactionListScrollTop');
  155. // 用来接收我的农场跳转过来的农场详情逻辑
  156. if (route.query.isHeaderShow) {
  157. isHeaderShow.value = true;
  158. defaultGardenId.value = route.query.farmId;
  159. // 统一转换为布尔值
  160. isDefaultFarm.value = route.query.defaultFarm === "true" || route.query.defaultFarm === true;
  161. }
  162. });
  163. const store = useStore();
  164. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  165. const router = useRouter();
  166. const route = useRoute();
  167. const userInfo = localStorage.getItem("localUserInfo");
  168. const userInfoObj = userInfo ? JSON.parse(userInfo) : {};
  169. const handleLockClick = () => {
  170. if (gardenId.value) {
  171. router.push("/interaction?subjectId=" + localStorage.getItem("selectedFarmId"));
  172. return;
  173. }
  174. if (userInfoObj?.tel) {
  175. router.push(`/create_farm?from=growth_report&isReload=true`);
  176. return;
  177. }
  178. wx.miniProgram.navigateTo({
  179. url: '/pages/subPages/phone_auth/index',
  180. });
  181. }
  182. // 组件卸载时停止语音播放
  183. onDeactivated(() => {
  184. showFarmPopup.value = false;
  185. isDefaultFarm.value = false;
  186. regionData.value = null;
  187. });
  188. const isExpanded = ref(false);
  189. const weatherExpanded = (isExpandedValue) => {
  190. isExpanded.value = isExpandedValue;
  191. };
  192. // 点击遮罩时收起天气
  193. const handleMaskClick = () => {
  194. if (weatherInfoRef.value && weatherInfoRef.value.toggleExpand) {
  195. weatherInfoRef.value.toggleExpand();
  196. }
  197. };
  198. const gardenId = ref(store.state.home.gardenId);
  199. // 初始化加载数据
  200. onMounted(() => {
  201. if (gardenId.value) {
  202. getVarietyTabs();
  203. }
  204. });
  205. const changeGarden = ({ id }) => {
  206. gardenId.value = id;
  207. activeVariety.value = 0;
  208. // 更新 store 中的状态
  209. store.commit("home/SET_GARDEN_ID", id);
  210. getVarietyTabs();
  211. startInteractPopupRef.value.getPhenologyInitOrConfirmStatus();
  212. };
  213. function handleReportClick() {
  214. router.push({
  215. path: "/growth_report",
  216. query: { farmId: gardenId.value },
  217. });
  218. }
  219. </script>
  220. <style scoped lang="scss">
  221. .monitor-index {
  222. width: 100%;
  223. height: 100%;
  224. padding: 13px 10px;
  225. box-sizing: border-box;
  226. background: linear-gradient(180deg, #f9f9f9 0%, #f0f8ff 31.47%, #f9f9f9 46.81%, #f9f9f9 69.38%, #f9f9f9 100%);
  227. .weather-mask {
  228. position: fixed;
  229. top: 0;
  230. left: 0;
  231. width: 100%;
  232. height: 100%;
  233. background-color: rgba(0, 0, 0, 0.52);
  234. z-index: 11;
  235. }
  236. .lock-img {
  237. position: fixed;
  238. z-index: 10;
  239. top: 50%;
  240. left: 50%;
  241. transform: translate(-50%, -20%);
  242. width: 100%;
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. flex-direction: column;
  247. gap: 16px;
  248. .lock-img-item {
  249. width: 57px;
  250. }
  251. .lock-text {
  252. font-size: 14px;
  253. color: #000;
  254. padding: 5px 64px;
  255. line-height: 21px;
  256. background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, #FFFFFF 50%, rgba(255, 255, 255, 0) 100%);
  257. }
  258. .lock-btn {
  259. width: 140px;
  260. height: 40px;
  261. line-height: 40px;
  262. text-align: center;
  263. background: linear-gradient(180deg, #76C3FF 0%, #2199F8 100%);
  264. border-radius: 25px;
  265. color: #fff;
  266. font-size: 16px;
  267. }
  268. }
  269. .example-img {
  270. width: 100%;
  271. height: 100%;
  272. object-fit: contain;
  273. }
  274. .weather-info {
  275. width: calc(100% - 20px);
  276. position: absolute;
  277. z-index: 12;
  278. }
  279. .archives-time-line {
  280. position: relative;
  281. margin-top: 96px;
  282. height: calc(100% - 90px);
  283. display: flex;
  284. flex-direction: column;
  285. min-height: 0;
  286. .archives-time-line-header {
  287. flex-shrink: 0;
  288. display: flex;
  289. align-items: center;
  290. justify-content: space-between;
  291. .line-title {
  292. position: relative;
  293. padding-left: 14px;
  294. font-size: 16px;
  295. &::before {
  296. content: "";
  297. position: absolute;
  298. left: 5px;
  299. top: 50%;
  300. transform: translateY(-50%);
  301. width: 4px;
  302. height: 15px;
  303. background: #2199f8;
  304. border-radius: 20px;
  305. }
  306. }
  307. .header-right {
  308. display: flex;
  309. align-items: center;
  310. gap: 12px;
  311. .add-variety-btn {
  312. display: flex;
  313. align-items: center;
  314. gap: 3px;
  315. padding: 4px 10px;
  316. border: 1px solid #2199F8;
  317. border-radius: 2px;
  318. color: #2199F8;
  319. background: rgba(33, 153, 248, 0.1);
  320. }
  321. }
  322. }
  323. .variety-tabs {
  324. flex-shrink: 0;
  325. display: grid;
  326. grid-template-columns: repeat(4, 1fr);
  327. gap: 8px;
  328. margin: 10px 0;
  329. .variety-tab {
  330. box-sizing: border-box;
  331. padding: 4px;
  332. border-radius: 2px;
  333. color: #767676;
  334. background: #fff;
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. text-align: center;
  339. word-break: break-word;
  340. overflow-wrap: anywhere;
  341. }
  342. .variety-tab--active {
  343. background: #2199F8;
  344. color: #ffffff;
  345. }
  346. }
  347. .archives-time-line-content {
  348. flex: 1;
  349. min-height: 0;
  350. background: #fff;
  351. border-radius: 8px;
  352. padding: 10px;
  353. box-sizing: border-box;
  354. display: flex;
  355. flex-direction: column;
  356. .report-box {
  357. background: linear-gradient(120deg, #eef8ff, #bbe3ff);
  358. border-radius: 4px;
  359. padding: 6px 0 0 16px;
  360. display: flex;
  361. align-items: center;
  362. justify-content: space-between;
  363. margin-bottom: 12px;
  364. .box-content {
  365. .box-title {
  366. font-size: 16px;
  367. color: #2199f8;
  368. font-weight: 500;
  369. margin-bottom: 4px;
  370. display: flex;
  371. align-items: center;
  372. }
  373. .box-text {
  374. color: #4e5969;
  375. }
  376. }
  377. .report-icon {
  378. width: 120px;
  379. height: 85px;
  380. }
  381. }
  382. .time-line {
  383. flex: 1;
  384. min-height: 0;
  385. }
  386. }
  387. }
  388. }
  389. </style>