index.vue 15 KB

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