AgriculturalDynamics.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="agricultural-dynamics">
  3. <!-- 标题 -->
  4. <div class="title">农情动态</div>
  5. <!-- 标签页导航 -->
  6. <div class="tab-nav">
  7. <div
  8. v-for="tab in tabs"
  9. :key="tab.value"
  10. class="tab-item"
  11. :class="{ active: activeTab === tab.value }"
  12. @click="handleTabClick(tab.value)"
  13. >
  14. {{ tab.label }}
  15. </div>
  16. </div>
  17. <!-- 内容区域 -->
  18. <div class="content-area">
  19. <!-- 气象预警内容/农事预警内容 -->
  20. <div v-if="activeTab !== 4" class="content-list">
  21. <div v-for="(item, index) in warningList" :key="index" class="content-item" @click="handleItem(item)">
  22. <div class="item-image">
  23. <img :src="item.media[0]" />
  24. </div>
  25. <div class="item-content">
  26. <div class="item-text van-multi-ellipsis--l2">{{ item.title }}</div>
  27. <div class="item-date">{{ item.createTime.slice(0, 10) }}</div>
  28. </div>
  29. </div>
  30. </div>
  31. <!-- 专家问答内容 -->
  32. <div v-else class="content-list expert-qa">
  33. <div v-for="(item, index) in expertQAList" :key="index" class="qa-item" @click="handleItem(item)">
  34. <div class="question-header">
  35. <img class="question-icon" src="@/assets/img/home/ask-icon.png" alt="" />
  36. <div class="question-title">{{ item.title }}</div>
  37. </div>
  38. <div class="expert-info">
  39. <el-avatar class="expert-avatar" :size="16" :src="item.icon" />
  40. <div class="expert-details">
  41. <span class="expert-name">{{ item.name }}</span>
  42. <span class="expert-title">{{ item.belongEnterprise }}</span>
  43. <span class="qa-date">{{ item.createTime.slice(0, 10) }}</span>
  44. </div>
  45. </div>
  46. <div class="answer-content" v-html="item.content"></div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </template>
  52. <script setup>
  53. import { ref, onMounted } from "vue";
  54. import { useRouter } from "vue-router";
  55. const router = useRouter();
  56. const activeTab = ref(2);
  57. const tabs = [
  58. { label: "气象预警", value: 2 },
  59. { label: "农事预警", value: 3 },
  60. { label: "专家问答", value: 4 },
  61. ];
  62. // 气象/农事预警数据
  63. const warningList = ref([]);
  64. // 专家问答数据
  65. const expertQAList = ref([]);
  66. const handleTabClick = (value) => {
  67. activeTab.value = value;
  68. getWarningList();
  69. };
  70. const handleItem = (item) => {
  71. if (activeTab.value === 4) {
  72. router.push("/expert_detail?id=" + item.id);
  73. } else {
  74. router.push("/warning_detail?id=" + item.id);
  75. }
  76. };
  77. onMounted(() => {
  78. getWarningList();
  79. });
  80. const getWarningList = () => {
  81. const params = {
  82. page: 1,
  83. limit: 10,
  84. topicId: activeTab.value,
  85. };
  86. VE_API.home.warningPageList(params).then((res) => {
  87. if(activeTab.value === 4){
  88. expertQAList.value = res.data || [];
  89. }else{
  90. warningList.value = res.data || [];
  91. }
  92. });
  93. };
  94. </script>
  95. <style scoped lang="scss">
  96. .agricultural-dynamics {
  97. padding: 0 10px;
  98. .title {
  99. font-size: 16px;
  100. font-weight: bold;
  101. color: #1d2129;
  102. margin-bottom: 16px;
  103. }
  104. .tab-nav {
  105. display: flex;
  106. margin-bottom: 16px;
  107. .tab-item {
  108. margin-right: 20px;
  109. padding-bottom: 6px;
  110. &.active {
  111. color: #2199f8;
  112. border-bottom: 2px solid #2199f8;
  113. }
  114. }
  115. }
  116. .content-area {
  117. .content-list {
  118. .content-item {
  119. display: flex;
  120. align-items: center;
  121. overflow-x: hidden;
  122. .item-image {
  123. width: 114px;
  124. height: 74px;
  125. margin-right: 12px;
  126. flex-shrink: 0;
  127. img {
  128. width: 100%;
  129. height: 100%;
  130. object-fit: cover;
  131. border-radius: 8px;
  132. }
  133. }
  134. .item-content {
  135. flex: 1;
  136. display: flex;
  137. flex-direction: column;
  138. justify-content: space-between;
  139. height: 68px;
  140. max-width: calc(100% - 130px);
  141. .item-text {
  142. color: #1d2129;
  143. ::v-deep {
  144. p{
  145. margin: 0;
  146. }
  147. }
  148. }
  149. .item-date {
  150. color: #86909c;
  151. font-size: 13px;
  152. }
  153. }
  154. }
  155. .content-item + .content-item {
  156. margin-top: 12px;
  157. }
  158. // 专家问答样式
  159. &.expert-qa {
  160. .qa-item {
  161. padding: 0 12px;
  162. .question-header {
  163. display: flex;
  164. align-items: center;
  165. margin-bottom: 6px;
  166. gap: 8px;
  167. .question-icon {
  168. width: 20px;
  169. height: 20px;
  170. }
  171. .question-title {
  172. font-size: 16px;
  173. font-weight: 600;
  174. }
  175. }
  176. .expert-info {
  177. display: flex;
  178. align-items: center;
  179. gap: 6px;
  180. margin-bottom: 8px;
  181. .expert-details {
  182. display: flex;
  183. align-items: center;
  184. gap: 6px;
  185. font-size: 13px;
  186. color: #666666;
  187. }
  188. }
  189. .answer-content {
  190. color: #333333;
  191. .font-bold {
  192. font-weight: 500;
  193. }
  194. }
  195. }
  196. .qa-item + .qa-item {
  197. margin-top: 16px;
  198. }
  199. }
  200. }
  201. }
  202. }
  203. </style>