index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <div class="invite" @scroll="handleScroll">
  3. <div class="head">
  4. <img @click="back" src="@/assets/images/back.png" class="arrow_img" />
  5. <!-- <span>{{ $t('lang219') }}</span> -->
  6. <van-tabs class="tabs" v-model="navActive" color="#29B286" title-active-color="#29B286" title-inactive-color="#080808" @change="changeTab">
  7. <van-tab v-for="(item, index) in type" :key="index" :title="item.value"></van-tab>
  8. </van-tabs>
  9. </div>
  10. <van-field v-model="key" :placeholder="$t('lang454')" class="input" left-icon="search" @click-left-icon="search" @keyup.enter="search" />
  11. <van-tabs class="child_tabs" v-model="childActive" color="#29B286" title-active-color="#29B286" title-inactive-color="#080808" @change="changeChildTab" v-if="childType.length > 0">
  12. <!-- <van-tab key="0" title="全部"></van-tab> -->
  13. <van-tab v-for="(item, index) in childType" :name="item.id" :key="index" :title="item.name"></van-tab>
  14. </van-tabs>
  15. <div v-if="list.length > 0" class="notice_box">
  16. <div class="notice" v-for="(item, index) in list" :key="index" @click="navigatorTo('bulletinDetail', item.id)">
  17. <!-- <img class="notice_img" :src="item.img_url" alt="" v-if="item.img_url" /> -->
  18. <svg t="1748345661681" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8571" width="11" height="11" v-if="item.is_top == 1">
  19. <path
  20. d="M938.8032 640.256l-378.9312-503.2448c-17.408-25.8048-55.2448-26.4192-73.8816-1.1776l-398.7456 503.2448c-21.6064 30.0032-0.6144 72.0896 36.608 72.0896h187.392v233.6256c0 35.4304 28.8256 64.8704 64.8704 64.8704h270.848c35.4304 0 64.8704-28.8256 64.8704-64.8704V711.168h189.184c36.608-0.0512 58.2144-40.9088 37.7856-70.912z m0 0"
  21. p-id="8572"
  22. fill="#29b286"
  23. ></path>
  24. <path
  25. d="M126.8736 115.4048h768.6656c28.2112 0 51.0464-22.8352 51.0464-51.0464 0-28.2112-22.8352-51.0464-51.0464-51.0464H126.8736c-28.2112 0-51.0464 22.8352-51.0464 51.0464 0.0512 28.2112 22.8352 51.0464 51.0464 51.0464z m0 0"
  26. p-id="8573"
  27. fill="#29b286"
  28. ></path>
  29. </svg>
  30. <span class="title">{{ item.title }}</span>
  31. <div class="right">
  32. <div class="tag_box">
  33. <span class="tag" v-for="(it, idx) in item.sub_type_name" :key="idx" :style="{ color: it.color, backgroundColor: hexToRgbObject(it.color) }">{{ it.title }}</span>
  34. </div>
  35. <span class="time_text"><span class="new" v-if="isToday(new Date(item.createtime * 1000))">New</span>{{ dateFormatFn(item.createtime) }}</span>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="bare" v-else>
  40. <span>{{ $t('lang60') }}</span>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. import { homeApi } from '@/api/index';
  46. import { dateFormat } from '@/utils/formatTool.js';
  47. export default {
  48. data() {
  49. return {
  50. list: [],
  51. page: 1,
  52. loading: false,
  53. finished: false,
  54. total: 0,
  55. finishText: this.$t('lang200'),
  56. key: '',
  57. type: [],
  58. navActive: 0,
  59. childActive: 0,
  60. childType: [],
  61. };
  62. },
  63. mounted() {
  64. this.gettype();
  65. // window.addEventListener('scroll', this.scrollBottom);
  66. },
  67. destroyed() {
  68. // window.removeEventListener('scroll', this.scrollBottom);
  69. },
  70. computed: {},
  71. methods: {
  72. isToday(date) {
  73. const today = new Date();
  74. return date.getFullYear() === today.getFullYear() && date.getMonth() === today.getMonth() && date.getDate() === today.getDate();
  75. },
  76. hexToRgbObject(hex) {
  77. console.log(hex);
  78. hex = hex.replace('#', '');
  79. return `rgba(${parseInt(hex.slice(0, 2), 16)},
  80. ${parseInt(hex.slice(2, 4), 16)},
  81. ${parseInt(hex.slice(4, 6), 16)},0.2)`;
  82. },
  83. //返回上一页
  84. back() {
  85. this.$router.back();
  86. },
  87. handleScroll(event) {
  88. const container = event.target;
  89. const scrollTop = container.scrollTop; // 滚动距离
  90. const scrollHeight = container.scrollHeight; // 内容总高度
  91. const clientHeight = container.clientHeight; // 可视区域高度
  92. // 判断是否滑动到底部
  93. if (scrollTop + clientHeight >= scrollHeight - 10) {
  94. console.log('Bottom', this.page);
  95. if (this.page != -1) {
  96. this.page++; // 页数加 1
  97. this.getAnnouncement(); // 触发加载更多
  98. }
  99. }
  100. },
  101. gettype() {
  102. homeApi.gettype().then(res => {
  103. if (res.code == 200) {
  104. this.type = res.data;
  105. // console.log(this.type);
  106. // this.navActive = this.type[0].key;
  107. this.childType = Object.entries(this.type[0].sun_type_name).map(([id, name]) => ({ id, name }));
  108. if (this.childType.length > 0) {
  109. this.childType.unshift({
  110. id: 0,
  111. name: this.$t('lang201'),
  112. });
  113. }
  114. this.getAnnouncement();
  115. }
  116. });
  117. },
  118. search() {
  119. this.page = 1;
  120. this.list = [];
  121. this.getAnnouncement();
  122. },
  123. changeTab(e, i, d) {
  124. console.log(e, i, d);
  125. this.childType = Object.entries(this.type[this.navActive].sun_type_name).map(([id, name]) => ({ id, name }));
  126. if (this.childType.length > 0) {
  127. this.childType.unshift({
  128. id: 0,
  129. name: this.$t('lang201'),
  130. });
  131. }
  132. this.childActive = 0;
  133. this.search();
  134. },
  135. changeChildTab() {
  136. this.search();
  137. },
  138. navigatorTo(name, id) {
  139. this.$router.push({ name, query: { id: id } });
  140. },
  141. dateFormatFn(date) {
  142. return dateFormat(new Date(date * 1000), 'yyyy-MM-dd hh:mm:ss');
  143. },
  144. getAnnouncement() {
  145. let params = {
  146. page: this.page,
  147. query: {},
  148. type_id: this.type[this.navActive].key,
  149. sub_type_id: this.childActive,
  150. title: this.key,
  151. };
  152. homeApi.getAnnouncement(params).then(res => {
  153. if (res.code == 200) {
  154. if (this.list.length >= res.data.total) {
  155. this.page = -1; // 重置为 -1,表示没有更多数据
  156. } else {
  157. this.list = [...this.list, ...res.data.rows];
  158. if (this.list.length >= res.data.total) {
  159. this.page = -1; // 重置为 -1,表示没有更多数据
  160. }
  161. }
  162. } else {
  163. }
  164. });
  165. },
  166. // onLoad() {
  167. // this.page += 1;
  168. // this.getAnnouncement();
  169. // },
  170. },
  171. };
  172. </script>
  173. <style lang="less" scoped>
  174. .invite {
  175. padding: 56px 0;
  176. height: 100vh;
  177. overflow: auto;
  178. background: #fff;
  179. .head {
  180. position: fixed;
  181. top: 0;
  182. width: 100%;
  183. left: 0;
  184. display: flex;
  185. align-items: center;
  186. justify-content: center;
  187. color: rgba(#000, 0.8);
  188. letter-spacing: 1.5px;
  189. font-weight: 550;
  190. font-weight: 18px;
  191. padding: 4px 0;
  192. z-index: 99999;
  193. background: #fff;
  194. .arrow_img {
  195. position: absolute;
  196. left: 20px;
  197. width: 10px;
  198. height: 16px;
  199. z-index: 99;
  200. }
  201. .tabs {
  202. // width: 100vw;
  203. // padding: 0 50px 0 0;
  204. width: calc(100% - 90px);
  205. // padding: 0 45px;
  206. overflow: auto;
  207. display: flex;
  208. justify-content: center;
  209. }
  210. /deep/.van-tab {
  211. width: fit-content !important;
  212. flex: none;
  213. padding: 0 15px;
  214. }
  215. /deep/.van-tabs__nav {
  216. // justify-content: center !important;
  217. }
  218. /deep/.van-tab__text {
  219. // width: 100px !important;
  220. font-size: 16px;
  221. text-align: center !important;
  222. }
  223. /deep/.van-tab--active {
  224. font-weight: 550;
  225. }
  226. /deep/.van-tabs__wrap {
  227. overflow-x: auto;
  228. }
  229. // .van-tabs__wrap--scrollable .van-tab {
  230. // padding: 0;
  231. // }
  232. }
  233. /deep/.van-tabs__line {
  234. width: 20px !important;
  235. bottom: 20px !important;
  236. }
  237. .input {
  238. // height: 35px;
  239. // line-height: 35px;
  240. // border: 1px solid #29b286;
  241. width: calc(100% - 32px);
  242. margin: 0 auto;
  243. box-sizing: border-box;
  244. border-radius: 20px;
  245. background-color: #f5f5f5;
  246. ::v-deep .van-field__control {
  247. padding: 2px 0;
  248. }
  249. ::v-deep .van-icon-search {
  250. font-size: 18px;
  251. color: #a1a1a1;
  252. font-weight: bold;
  253. margin: 3px 8px;
  254. }
  255. }
  256. /deep/.van-tabs__nav--line.van-tabs__nav--complete {
  257. padding-left: 0 !important;
  258. }
  259. .child_tabs {
  260. border-bottom: 0.5px solid rgba(190, 190, 190, 0.3) !important;
  261. // ::v-deep.van-tab {
  262. // line-height: 0 !important;
  263. // }
  264. }
  265. .notice_box {
  266. padding: 16px;
  267. }
  268. .notice {
  269. position: relative;
  270. display: flex;
  271. flex-direction: column;
  272. color: #000;
  273. font-size: 14px;
  274. letter-spacing: 0.8px;
  275. padding-bottom: 10px;
  276. margin-bottom: 18px;
  277. border-bottom: 0.5px solid rgba(190, 190, 190, 0.3);
  278. // box-shadow: 4px 4px 15px 0px rgba(180, 212, 212, 0.59);
  279. // background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.3) 0, rgba(255, 255, 255, 0.3) 0, rgba(255, 255, 255, 0.3) 100%, rgba(255, 255, 255, 0.3) 100%);
  280. .title {
  281. font-weight: 600;
  282. min-height: 22px;
  283. }
  284. .right {
  285. display: flex;
  286. align-items: center;
  287. justify-content: space-between;
  288. padding-top: 10px;
  289. .tag_box {
  290. display: flex;
  291. align-items: center;
  292. flex-wrap: wrap;
  293. width: 56%;
  294. }
  295. .tag {
  296. font-size: 11px;
  297. // color: #3b98e4;
  298. padding: 1px 3px;
  299. border-radius: 4px;
  300. margin-left: 3px;
  301. margin-bottom: 3px;
  302. // background-color: rgba(#3b98e4, 0.2);
  303. }
  304. .time_text {
  305. color: #b4b4b4;
  306. font-weight: normal;
  307. font-size: 11px;
  308. margin-bottom: 3px;
  309. white-space: nowrap;
  310. }
  311. .new {
  312. color: #ec413e;
  313. letter-spacing: 0;
  314. font-weight: 600;
  315. font-size: 10px;
  316. padding-right: 6px;
  317. }
  318. }
  319. svg {
  320. position: absolute;
  321. left: -13px;
  322. top: 3px;
  323. }
  324. }
  325. .bare {
  326. text-align: center;
  327. font-size: 14px;
  328. padding: 60px 14px;
  329. color: #888;
  330. }
  331. }
  332. </style>