index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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" 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" :class="{ 'no-report': !hasReport }">
  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 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], activeVariety.value)
  98. if(isShowPopup) {
  99. agriExecutePopupRef.value.showPopup(varietyTabs.value[activeVariety.value].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. }
  119. };
  120. const date = ref(new Date());
  121. const showSelectRegionPopup = ref(false);
  122. const handleAddVariety = () => {
  123. router.push("/interaction?addVariety=true&subjectId=" + gardenId.value);
  124. };
  125. const handleSkipSelectRegion = () => {
  126. VE_API.basic_farm.updateLastViewTime({
  127. regionId: currentVariety.value.regionId,
  128. }).then(() => {
  129. showSelectRegionPopup.value = false;
  130. getVarietyTabs(false);
  131. });
  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. const hasReport = ref(false);
  149. onActivated(() => {
  150. sessionStorage.removeItem('interactionListScrollTop');
  151. // 用来接收我的农场跳转过来的农场详情逻辑
  152. if (route.query.isHeaderShow) {
  153. isHeaderShow.value = true;
  154. defaultGardenId.value = route.query.farmId;
  155. // 统一转换为布尔值
  156. isDefaultFarm.value = route.query.defaultFarm === "true" || route.query.defaultFarm === true;
  157. }
  158. getReport();
  159. });
  160. const store = useStore();
  161. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  162. const router = useRouter();
  163. const route = useRoute();
  164. const handleLockClick = () => {
  165. wx.miniProgram.navigateTo({
  166. url: '/pages/subPages/phone_auth/index',
  167. });
  168. // wx.miniProgram.navigateTo({
  169. // url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=sharePage`,
  170. // });
  171. }
  172. // 实时播报数据
  173. const broadcastList = ref([]);
  174. const finished = ref(false);
  175. const currentPage = ref(1);
  176. // 播报相关事件
  177. const isSpeaking = ref(false);
  178. const speechSynthesis = window.speechSynthesis;
  179. // 组件卸载时停止语音播放
  180. onDeactivated(() => {
  181. showFarmPopup.value = false;
  182. isDefaultFarm.value = false;
  183. if (isSpeaking.value) {
  184. speechSynthesis.cancel();
  185. isSpeaking.value = false;
  186. }
  187. });
  188. const isExpanded = ref(false);
  189. const weatherExpanded = (isExpandedValue) => {
  190. isExpanded.value = isExpandedValue;
  191. };
  192. // 点击遮罩时收起天气
  193. const handleMaskClick = () => {
  194. if (weatherInfoRef.value && weatherInfoRef.value.toggleExpand) {
  195. weatherInfoRef.value.toggleExpand();
  196. }
  197. };
  198. const gardenId = ref(store.state.home.gardenId);
  199. // 初始化加载数据
  200. onMounted(() => {
  201. if (gardenId.value) {
  202. getVarietyTabs();
  203. }
  204. });
  205. const changeGarden = ({ id }) => {
  206. gardenId.value = id;
  207. // 更新 store 中的状态
  208. store.commit("home/SET_GARDEN_ID", id);
  209. getReport();
  210. getVarietyTabs();
  211. startInteractPopupRef.value.getPhenologyInitOrConfirmStatus();
  212. };
  213. function handleReportClick() {
  214. router.push({
  215. path: "/growth_report",
  216. query: { farmId: gardenId.value },
  217. });
  218. }
  219. const getReport = () => {
  220. VE_API.farm.growthReportBySubject({ subjectId: gardenId.value, limit: 20 }).then(({ data }) => {
  221. if (data && data.length > 0) {
  222. hasReport.value = true;
  223. } else {
  224. hasReport.value = false;
  225. }
  226. });
  227. }
  228. </script>
  229. <style scoped lang="scss">
  230. .monitor-index {
  231. width: 100%;
  232. height: 100%;
  233. padding: 13px 10px;
  234. box-sizing: border-box;
  235. background: linear-gradient(180deg, #f9f9f9 0%, #f0f8ff 31.47%, #f9f9f9 46.81%, #f9f9f9 69.38%, #f9f9f9 100%);
  236. .weather-mask {
  237. position: fixed;
  238. top: 0;
  239. left: 0;
  240. width: 100%;
  241. height: 100%;
  242. background-color: rgba(0, 0, 0, 0.52);
  243. z-index: 11;
  244. }
  245. .lock-img {
  246. position: fixed;
  247. z-index: 10;
  248. top: 50%;
  249. left: 50%;
  250. transform: translate(-50%, -20%);
  251. width: 100%;
  252. display: flex;
  253. align-items: center;
  254. justify-content: center;
  255. flex-direction: column;
  256. gap: 16px;
  257. .lock-img-item {
  258. width: 57px;
  259. }
  260. .lock-text {
  261. font-size: 14px;
  262. color: #000;
  263. padding: 5px 64px;
  264. line-height: 21px;
  265. background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, #FFFFFF 50%, rgba(255, 255, 255, 0) 100%);
  266. }
  267. .lock-btn {
  268. width: 140px;
  269. height: 40px;
  270. line-height: 40px;
  271. text-align: center;
  272. background: linear-gradient(180deg, #76C3FF 0%, #2199F8 100%);
  273. border-radius: 25px;
  274. color: #fff;
  275. font-size: 16px;
  276. }
  277. }
  278. .example-img {
  279. width: 100%;
  280. height: 100%;
  281. object-fit: contain;
  282. }
  283. .weather-info {
  284. width: calc(100% - 20px);
  285. position: absolute;
  286. z-index: 12;
  287. }
  288. .archives-time-line {
  289. position: relative;
  290. margin-top: 96px;
  291. height: calc(100% - 90px);
  292. .archives-time-line-header {
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. .line-title {
  297. position: relative;
  298. padding-left: 14px;
  299. font-size: 16px;
  300. &::before {
  301. content: "";
  302. position: absolute;
  303. left: 5px;
  304. top: 50%;
  305. transform: translateY(-50%);
  306. width: 4px;
  307. height: 15px;
  308. background: #2199f8;
  309. border-radius: 20px;
  310. }
  311. }
  312. .header-right {
  313. display: flex;
  314. align-items: center;
  315. gap: 12px;
  316. .add-variety-btn {
  317. display: flex;
  318. align-items: center;
  319. gap: 3px;
  320. padding: 4px 10px;
  321. border: 1px solid #DCDCDC;
  322. border-radius: 3px;
  323. background: #fff;
  324. }
  325. }
  326. }
  327. .variety-tabs {
  328. display: flex;
  329. align-items: center;
  330. gap: 8px;
  331. margin: 10px 0;
  332. overflow-x: auto;
  333. overflow-y: hidden;
  334. flex-wrap: nowrap;
  335. -webkit-overflow-scrolling: touch;
  336. .variety-tab {
  337. padding: 4px 12px;
  338. border-radius: 2px;
  339. color: #767676;
  340. background: #fff;
  341. white-space: nowrap;
  342. flex-shrink: 0;
  343. }
  344. .variety-tab--active {
  345. background: #2199F8;
  346. color: #ffffff;
  347. }
  348. }
  349. .archives-time-line-content {
  350. margin-top: 10px;
  351. height: calc(100% - 70px);
  352. background: #fff;
  353. border-radius: 8px;
  354. padding: 10px;
  355. box-sizing: border-box;
  356. .report-box {
  357. background: linear-gradient(120deg, #eef8ff, #bbe3ff);
  358. border-radius: 4px;
  359. padding: 6px 0 0 16px;
  360. display: flex;
  361. align-items: center;
  362. justify-content: space-between;
  363. margin-bottom: 12px;
  364. .box-content {
  365. .box-title {
  366. font-size: 16px;
  367. color: #2199f8;
  368. font-weight: 500;
  369. margin-bottom: 4px;
  370. display: flex;
  371. align-items: center;
  372. }
  373. .box-text {
  374. color: #4e5969;
  375. }
  376. }
  377. .report-icon {
  378. width: 120px;
  379. height: 85px;
  380. }
  381. }
  382. .time-line {
  383. height: calc(100% - 100px);
  384. &.no-report {
  385. height: 100%;
  386. }
  387. }
  388. }
  389. }
  390. }
  391. </style>