index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <layout-page>
  3. <view class="box defaultBgc">
  4. <scroll-view class="scrollBox" scroll-y="true" @scrolltolower="loadingMore">
  5. <view>
  6. <view class="panel">
  7. <view>
  8. <uni-icons color="#f30" type="icon-renminbi1688" size="16" custom-prefix="iconfont"></uni-icons>
  9. <text class="text">{{ balance.point }}</text>
  10. </view>
  11. <view>
  12. <button class="btn" @tap="handleUse">使用积分</button>
  13. </view>
  14. </view>
  15. <view class="list">
  16. <uni-list>
  17. <uni-list-item
  18. v-for="item in items"
  19. :key="item.id"
  20. :title="item.description"
  21. :rightText="item._createTime"
  22. />
  23. </uni-list>
  24. <uni-load-more :status="more" />
  25. </view>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. </layout-page>
  30. </template>
  31. <!-- balance 余额 -->
  32. <script setup>
  33. import { ref } from 'vue'
  34. import {
  35. getUserAccount,
  36. getEnterpriseAccountRecordPage
  37. } from '@/api/sign'
  38. import { timesTampChange } from '@/utils/date'
  39. const balance = ref({})
  40. const items = ref([])
  41. const pageInfo = ref({
  42. pageNo: 1,
  43. pageSize: 20
  44. })
  45. const total = ref(0)
  46. const more = ref('more')
  47. getBalance()
  48. getList()
  49. // 获取积分余额
  50. async function getBalance() {
  51. const { data } = await getUserAccount()
  52. if (!data) {
  53. return
  54. }
  55. balance.value = data
  56. }
  57. async function getList () {
  58. try {
  59. const { data } = await getEnterpriseAccountRecordPage({ ...pageInfo.value, type: 0 })
  60. if (!data || !data.list) {
  61. if (pageInfo.value.pageNo === 1) {
  62. return
  63. }
  64. pageInfo.value.pageNo--
  65. more.value = 'more'
  66. return
  67. }
  68. const _data = data.list.map(e => {
  69. return {
  70. ...e,
  71. _createTime: timesTampChange(e.createTime)
  72. }
  73. })
  74. items.value.push(..._data)
  75. total.value = +data.total
  76. more.value = total.value <= items.value.length ? 'noMore' : 'more'
  77. } catch (error) {
  78. if (pageInfo.value.pageNo === 1) {
  79. return
  80. }
  81. pageInfo.value.pageNo--
  82. more.value = 'more'
  83. }
  84. }
  85. function loadingMore () {
  86. if (more.value === 'noMore') {
  87. return
  88. }
  89. more.value = 'loading'
  90. pageInfo.value.pageNo++
  91. getList()
  92. }
  93. function handleUse () {
  94. wx.navigateToMiniProgram({
  95. appId: 'wx6decdf12f9e7a061', // 目标小程序的 appId
  96. envVersion: 'develop',
  97. success(res) {
  98. // 打开成功
  99. console.log('成功跳转至小程序:', res);
  100. },
  101. fail(err) {
  102. // 打开失败
  103. uni.showToast({
  104. title: '打开商城失败',
  105. icon: 'none'
  106. })
  107. }
  108. })
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .box {
  113. height: 100vh;
  114. }
  115. .scrollBox {
  116. width: 100vw;
  117. // padding: 20rpx;
  118. box-sizing: border-box;
  119. .panel {
  120. position: sticky;
  121. z-index: 2;
  122. top: 0;
  123. width: 100%;
  124. padding: 20rpx;
  125. margin-bottom: 20rpx;
  126. box-sizing: border-box;
  127. background: #FFF;
  128. display: flex;
  129. justify-content: space-between;
  130. align-items: flex-end;
  131. box-shadow: 0px 0px 10px 0px rgb(0, 0, 0, 0.25);
  132. .text {
  133. color: #F30;
  134. font-size: 54rpx;
  135. }
  136. .btn {
  137. width: 180rpx;
  138. height: 60rpx;
  139. line-height: 60rpx;
  140. font-size: 28rpx;
  141. text-align: center;
  142. background: #00897B;
  143. color: #FFF;
  144. border-radius: 30rpx;
  145. }
  146. }
  147. .list {
  148. // padding: 20rpx;
  149. }
  150. }
  151. </style>