index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view class="active-list">
  3. <!-- 活动查询 -->
  4. <view class="active-list-search">
  5. <!-- 搜索框 -->
  6. <view class="search">
  7. <u-input placeholderStyle='color:#999' placeholder="输入活动名称或参赛项目" border='none' v-model="search"
  8. @input="searchText(isActive,items[isActive].id)">
  9. <template slot="suffix" style='margin-right:40rpx;'>
  10. <u-image :showLoading="true" :showError='true' src="/static/icon/search.png" width="40rpx"
  11. height="32rpx"></u-image>
  12. </template>
  13. </u-input>
  14. </view>
  15. <view class="tab_nav">
  16. <view class="navTitle" v-for="(item,index) in items" :key="index">
  17. <view :class="{'active':isActive === index}" @click="checked(index,item.id)">
  18. {{item.name}}
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="msg-null" v-if="List.length == 0">
  24. <image src="https://t9.9026.com/imgs/dataNull.png" style="width: 394rpx;height: 396rpx;" mode=""></image>
  25. <view class="msg-null-text">
  26. <text>暂无数据</text>
  27. </view>
  28. </view>
  29. <view class="List" v-if="List.length > 0">
  30. <template v-for="(item,index) in List">
  31. <view class="ListItem" v-if="item.show_status" :key="index" @click="activeDetail(item.id)">
  32. <image :src="item.banners?item.cover_img:'http://t9.9026.com/imgs/Kudosbg.png'"
  33. style="width: 640rpx;height:420rpx;border-radius: 12rpx;"></image>
  34. <view class="kudosicon" @click.stop="kudosActive(item.id,index)">
  35. <image src="/static/icon/Kudos.png" v-if="item.is_like==0"></image>
  36. <image src="/static/icon/Kudos(1).png" v-if="item.is_like==1"></image>
  37. </view>
  38. <view class="nav">
  39. <view class="events">
  40. <text>{{item.title}}</text>
  41. </view>
  42. <view class="voteStatus" style="width: 100rpx;">
  43. <text style="font-size: 30rpx;color: #999;" v-if="item.activity_status==1">未开始</text>
  44. <text style="font-size: 30rpx;color: #FF6503;" v-if="item.activity_status==2">进行中</text>
  45. <text style="font-size: 30rpx;color: #999;" v-if="item.activity_status==3">已结束</text>
  46. </view>
  47. </view>
  48. <view class="foot">
  49. <image src="/static/icon/data.png"></image>
  50. <text>{{item.end_time}} 结束</text>
  51. </view>
  52. </view>
  53. </template>
  54. </view>
  55. <!-- 触底 -->
  56. <view class="home-bottom" v-if="List.length > 0">
  57. <uni-load-more :status="status" color="#CCCCCC" :content-text="contentText" />
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import util from '@/utils/util.js'
  63. export default {
  64. data() {
  65. return {
  66. //活动分类categoryId
  67. categoryId: '',
  68. // 搜索
  69. search: '',
  70. //分段器
  71. items: [{
  72. name: '热门活动'
  73. },
  74. {
  75. name: '西区活动'
  76. }, {
  77. name: '酒店评选'
  78. },
  79. {
  80. name: '旅游推选'
  81. }
  82. ],
  83. //激活指定table菜单
  84. isActive: 0,
  85. contentText: {
  86. contentdown: '查看更多',
  87. contentrefresh: '加载中',
  88. contentnomore: '—— 已经到底啦 ——'
  89. },
  90. // 活动列表
  91. List: [],
  92. // 分页
  93. page: 1,
  94. pagesize: 15,
  95. totalElements: '',
  96. allListItem: '',
  97. // 组件uni-load-more
  98. status: 'noMore',
  99. }
  100. },
  101. onLoad() {
  102. // this.getList()
  103. this.getCategoryList()
  104. console.log(util, "until")
  105. },
  106. // 触底加载
  107. onReachBottom() {
  108. // 触底的时候请求数据,即为上拉加载更多
  109. var allTotal = this.page * this.pagesize
  110. console.log(allTotal, '----allTotal');
  111. //this.page为加载次数,this.pagesize为每一次加载的数据条数
  112. if (allTotal < this.totalElements) {
  113. //this.totalElements为请求数据的总条数。只要现有条数小于总条数就就执行一下代码
  114. this.allListItem = false;
  115. this.page++;
  116. //加载次数递加
  117. this.status = "loading"
  118. this.$api.active.getActiveList({ //请求更多数据列表
  119. page: this.page,
  120. category_id: this.categoryId,
  121. keyword: this.search
  122. }).then(res => {
  123. let ret = [...this.List, ...res.data.data]
  124. this.List = ret
  125. console.log(ret)
  126. })
  127. } else {
  128. this.allListItem = true;
  129. console.log('已加载全部数据')
  130. this.status = "noMore"
  131. }
  132. },
  133. methods: {
  134. // 获取活动列表
  135. getList(category_id) {
  136. this.$api.active.getActiveList({
  137. page: 0,
  138. keyword: '',
  139. category_id: `${category_id}`
  140. }).then(res => {
  141. console.log(res, '活动列表')
  142. if (res.code == 0) {
  143. this.List = res.data.data
  144. this.totalElements = res.data.total
  145. this.pagesize = res.data.per_page
  146. console.log(this.List, '--->this.List');
  147. }
  148. })
  149. },
  150. // 获取分类列表
  151. getCategoryList() {
  152. this.$api.category.getCategoryList({
  153. page: 1,
  154. type: 1
  155. }).then(res => {
  156. console.log(res, "活动分类列表")
  157. if (res.code == 0) {
  158. this.items = res.data.data
  159. this.categoryId = this.items[0].id
  160. console.log(this.categoryId, '--->this.categoryId');
  161. this.getList(this.categoryId)
  162. }
  163. })
  164. },
  165. // 点赞活动
  166. kudosActive(id, index) {
  167. let beforeLike = this.List[index].is_like
  168. this.$api.active.kudos({
  169. activity_id: id
  170. }).then(res => {
  171. console.log(res, '点赞')
  172. if (res.code == 0) {
  173. if (beforeLike == 1) {
  174. this.List[index].is_like = 0
  175. } else {
  176. this.List[index].is_like = 1
  177. }
  178. }
  179. })
  180. },
  181. //菜单index切换
  182. checked(index, id) {
  183. this.page = 1
  184. this.isActive = index
  185. this.categoryId = id
  186. this.getList(id)
  187. console.log(this.isActive, '---->this.isActive');
  188. },
  189. // 活动详情页
  190. activeDetail(id) {
  191. uni.navigateTo({
  192. url: '/pages/index/active-detail/index?id=' + id
  193. })
  194. },
  195. // 搜索防抖
  196. searchText: util.debounce(function(index, id) {
  197. this.goSearch(index, id)
  198. console.log(id, '---->id');
  199. }, 1000),
  200. //搜索
  201. goSearch(index, id) {
  202. uni.showLoading({
  203. title: '加载中'
  204. })
  205. this.$api.active.getActiveList({
  206. page: 1,
  207. keyword: this.search,
  208. category_id: id
  209. }).then(res => {
  210. if (res.code == 0) {
  211. uni.hideLoading()
  212. this.isActive = index
  213. this.List = res.data.data
  214. this.totalElements = res.data.total
  215. this.pagesize = res.data.per_page
  216. console.log(this.List, '--->this.list');
  217. }
  218. })
  219. },
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. $pageColor:#F9F9F9;
  225. $bgColor:#FFFFFF;
  226. @mixin flexlayout {
  227. display: flex;
  228. align-items: center;
  229. justify-content: center;
  230. }
  231. .active-list {
  232. height: 100%;
  233. background: #F9F9F9;
  234. }
  235. .msg-null {
  236. margin-top: 224rpx;
  237. display: flex;
  238. flex-direction: column;
  239. align-items: center;
  240. justify-content: center;
  241. padding-top: 60rpx;
  242. .msg-null-text {
  243. margin-top: 40rpx;
  244. font-size: 28rpx;
  245. color: #333;
  246. }
  247. }
  248. .home-bottom {
  249. background-color: #f9f9f9;
  250. padding-bottom: 84rpx;
  251. }
  252. .active-list-search {
  253. padding: 24rpx 30rpx 32rpx;
  254. height: 222rpx;
  255. background-color: #FFFFFF;
  256. width: 100%;
  257. position: fixed;
  258. top: 0;
  259. z-index: 99;
  260. // 搜索
  261. .search {
  262. ::v-deep .u-input {
  263. width: 690rpx !important;
  264. height: 68rpx !important;
  265. background: #F1F1F1;
  266. border-radius: 74rpx;
  267. }
  268. ::v-deep .u-input__content__field-wrapper {
  269. padding-left: 36rpx;
  270. }
  271. ::v-deep .u-input__content__field-wrapper__field {
  272. color: #999999 !important;
  273. font-size: 28rpx !important;
  274. }
  275. }
  276. //菜单切换
  277. .tab_nav {
  278. width: 100%;
  279. margin-top: 32rpx;
  280. display: flex;
  281. justify-content: space-between;
  282. align-items: center;
  283. font-family: PingFang-SC-Heavy, PingFang-SC;
  284. }
  285. .tab_nav .navTitle {
  286. width: 150rpx;
  287. flex: none;
  288. height: 28rpx;
  289. font-size: 32rpx;
  290. color: #666;
  291. position: relative;
  292. }
  293. .active {
  294. color: #D9A94D;
  295. font-weight: bold;
  296. &::after {
  297. display: inline-block;
  298. content: '';
  299. width: 48rpx;
  300. height: 12rpx;
  301. background: linear-gradient(90deg, #F3D69F 0%, #D9A94D 100%);
  302. border-radius: 6px;
  303. position: absolute;
  304. bottom: -36rpx;
  305. left: 40rpx;
  306. }
  307. }
  308. }
  309. .List {
  310. padding: 0 30rpx;
  311. box-sizing: border-box;
  312. padding-top: 20rpx;
  313. padding-bottom: 88rpx;
  314. background-color: #F9F9F9;
  315. margin-top: 222rpx;
  316. .ListItem {
  317. position: relative;
  318. margin-bottom: 24rpx;
  319. width: 100%;
  320. height: 562rpx;
  321. background: #F9F9F9;
  322. box-shadow: 0rpx 12rpx 40rpx 0rpx rgba(220, 222, 229, 0.4);
  323. border-radius: 24rpx;
  324. padding: 20rpx 26rpx 26rpx 24rpx;
  325. .kudosicon {
  326. width: 48rpx;
  327. height: 48rpx;
  328. position: absolute;
  329. top: 52rpx;
  330. right: 58rpx;
  331. border-radius: 50%;
  332. background: #FFFFFF;
  333. opacity: 0.84;
  334. @include flexlayout() image {
  335. width: 32rpx;
  336. height: 28rpx;
  337. }
  338. }
  339. .nav {
  340. display: flex;
  341. align-items: flex-start;
  342. justify-content: space-between;
  343. .events {
  344. text {
  345. font-size: 30rpx;
  346. font-family: PingFang-SC-Bold, PingFang-SC;
  347. font-weight: bold;
  348. color: #333333;
  349. }
  350. }
  351. .voteStatus {
  352. font-size: 30rpx;
  353. font-family: PingFang-SC-Medium, PingFang-SC;
  354. font-weight: 500;
  355. color: #999999;
  356. }
  357. }
  358. .foot {
  359. margin-top: 10rpx;
  360. display: flex;
  361. align-items: center;
  362. image {
  363. width: 28rpx;
  364. height: 28rpx;
  365. margin-right: 8rpx;
  366. }
  367. text {
  368. font-size: 24rpx;
  369. font-family: PingFang-SC-Medium, PingFang-SC;
  370. font-weight: 500;
  371. color: #999999;
  372. display: block;
  373. }
  374. }
  375. }
  376. }
  377. </style>