index.vue 14 KB

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