index.vue 13 KB

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