score.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view class="score">
  3. <custom-nav :title="pageTitle"></custom-nav>
  4. <view class="content">
  5. <view class="score-type">
  6. <view class="score-type-item" :class="{ active: active == 0 }" @click="active = 0">上传成功</view>
  7. <view class="score-type-item" :class="{ active: active == 1 }" @click="active = 1">上传失败</view>
  8. </view>
  9. <view class="title">
  10. <text>时间</text>
  11. <text>类型</text>
  12. <text>学分</text>
  13. </view>
  14. <view class="list">
  15. <scroll-view v-if="list.length" scroll-y :style="{ height: scrollViewHeight + 'px' }" @scrolltolower="scrolltolower">
  16. <view class="item" v-for="(item, index) in list" :key="index" @tap="preview(index)">
  17. <view class="date">
  18. <text>{{ item.timestamp | getYear }}-{{ item.timestamp | getMonth }}-{{ item.timestamp | getDate }}</text>
  19. <text>{{ item.timestamp | getDay }}</text>
  20. </view>
  21. <view class="type">{{ item.type | type }}</view>
  22. <view class="num">{{ item.num > 0 ? '+ ' + item.num : item.num }}</view>
  23. <view class="tap" v-if="item.img">点击查看上传图片</view>
  24. </view>
  25. <custom-reach-bottom v-if="list.length" :nomore="nomore"></custom-reach-bottom>
  26. </scroll-view>
  27. <view v-else class="nomore">-暂无更多兑换记录-</view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import { api_getScoreList, api_upload_fail } from '../../api.js'
  34. import { formatTimestamp } from '../../common/js/utils.js'
  35. import customReachBottom from '../../components/custom-reach-bottom.vue'
  36. export default {
  37. components: {
  38. customReachBottom
  39. },
  40. data() {
  41. return {
  42. pageTitle: '学分账单',
  43. list: [], //账单列表
  44. scrollViewHeight: 0, //scrollview 高度
  45. page: 1, //页数
  46. nomore: false, //是否还有更多
  47. requesting: false, //是否正在网络请求 用于防抖
  48. active: 0
  49. };
  50. },
  51. computed: {
  52. userServerInfo () { //用户服务器信息
  53. return this.$store.state.userServerInfo
  54. },
  55. },
  56. filters: { //过滤器
  57. type (value) {
  58. if (+value === 1) {
  59. return '销售学分'
  60. } else if (+value === 2) {
  61. return '奖励学分'
  62. } else if (+value === 3) {
  63. return '竞猜成功学分'
  64. } else if (+value === 4) {
  65. return '挑战成功学分'
  66. } else if (+value === 5) {
  67. return '第一周上榜奖励'
  68. } else if (+value === 6) {
  69. return '第二周上榜奖励'
  70. } else if (+value === 7) {
  71. return '第三周上榜奖励'
  72. }
  73. }
  74. },
  75. watch: {
  76. active (n) {
  77. this.page = 1
  78. this.request()
  79. }
  80. },
  81. mounted() {
  82. this.$scrollViewHeight('.list') //设置页面内 scroll view 的高度
  83. this.request()
  84. },
  85. methods: {
  86. request() {
  87. uni.showLoading({ mask: true, title: '加载中' })
  88. this.$ajax.get(`${ this.active == 0 ? api_getScoreList : api_upload_fail }?page=1&season=${this.userServerInfo.season}`).then(([ , { data: res }]) => {
  89. uni.hideLoading()
  90. if (res.data.list.length < 20) {
  91. this.nomore = true
  92. } else {
  93. this.nomore = false
  94. }
  95. this.list = res.data.list
  96. // this.list = res.data.list.reverse()
  97. })
  98. },
  99. scrolltolower () { //下拉 scroll view 触底函数
  100. if (!this.nomore && !this.requesting) { //只有在有更多和没有网络请求时才触发请求
  101. this.requesting = true
  102. this.$ajax.get(`${ this.active == 0 ? api_getScoreList : api_upload_fail }?page=${this.page + 1}&season=${this.userServerInfo.season}`).then(([ , { data: res }]) => {
  103. this.requesting = false
  104. this.page ++
  105. if (res.data.list.length < 20) {
  106. this.nomore = true
  107. }
  108. this.list = [...this.list, ...res.data.list.reverse()]
  109. }, () => {
  110. this.requesting = false
  111. })
  112. }
  113. },
  114. preview(index) {
  115. if (this.list[index].img) {
  116. uni.previewImage({ urls: [this.list[index].img] })
  117. }
  118. return
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .score {
  125. @include page();
  126. .content {
  127. margin-top: $custom-nav-borderbot-height;
  128. background: $custom-nav-borderbot-color;
  129. display: flex;
  130. flex-direction: column;
  131. .title {
  132. display: flex;
  133. height: 70rpx;
  134. font-size: 32rpx;
  135. background: #FFFFFF;
  136. align-items: center;
  137. color: rgba(42,42,42,1);
  138. justify-content: space-around;
  139. border-bottom: 2rpx solid $custom-nav-borderbot-color;
  140. }
  141. .score-type {
  142. display: flex;
  143. height: 70rpx;
  144. font-size: 32rpx;
  145. background: #FFFFFF;
  146. color: rgba(42,42,42,1);
  147. border-bottom: 2rpx solid $custom-nav-borderbot-color;
  148. > view {
  149. flex: 1;
  150. height: 100%;
  151. display: flex;
  152. align-items: center;
  153. box-sizing: border-box;
  154. justify-content: center;
  155. border-bottom: 4rpx solid #FFFFFF;
  156. &.active {
  157. border-color: #F76353;
  158. }
  159. }
  160. }
  161. .list {
  162. flex: 1;
  163. scroll-view {
  164. .item {
  165. display: flex;
  166. height: 130rpx;
  167. position: relative;
  168. align-items: center;
  169. background: #FFFFFF;
  170. justify-content: space-around;
  171. border-bottom: 2rpx solid $custom-nav-borderbot-color;
  172. view {
  173. font-size: 26rpx;
  174. color: #2A2A2A;
  175. &.date, &.type, &.num {
  176. height: 100%;
  177. width: 33.3333%;
  178. float: left;
  179. display: flex;
  180. flex-direction: column;
  181. align-items: center;
  182. justify-content: center;
  183. }
  184. &.num {
  185. font-size: 40rpx;
  186. color: #FE6740;
  187. }
  188. &.tap {
  189. position: absolute;
  190. right: 30rpx;
  191. bottom: 10rpx;
  192. color: #999999;
  193. }
  194. }
  195. }
  196. }
  197. .nomore {
  198. font-size: 20rpx;
  199. color: #999999;
  200. margin: 42rpx auto;
  201. text-align: center;
  202. }
  203. }
  204. }
  205. }
  206. </style>