index.vue 14 KB

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