index.vue 13 KB

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