index.vue 13 KB

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