敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
5.0 KiB

1 month ago
  1. <template>
  2. <view class="assets-page">
  3. <!-- 导航栏 -->
  4. <navbar title="资产明细" leftClick @leftClick="$utils.navigateBack" bgColor="#019245" color="#fff" />
  5. <!-- diy的tab栏 -->
  6. <uv-sticky>
  7. <view class="tab-container">
  8. <view class="tab-wrapper">
  9. <view
  10. v-for="(item, index) in list"
  11. :key="index"
  12. class="tab-item"
  13. :class="{ active: currentTab === index }"
  14. @click="switchTab(index)"
  15. >
  16. {{ item.name }}
  17. </view>
  18. <!-- 滑块 -->
  19. <view class="tab-slider" :style="{ left: currentTab * 50 + '%' }" />
  20. </view>
  21. </view>
  22. </uv-sticky>
  23. <!-- 交易记录列表 -->
  24. <view class="transaction-list">
  25. <view class="transaction-item" v-for="item in incomeList" :key="item.id">
  26. <!-- 左侧图标和类型 -->
  27. <view class="item-left">
  28. <view class="icon-container">
  29. <uv-icon name="empty-coupon" color="#019245" size="44"></uv-icon>
  30. </view>
  31. <view class="item-info">
  32. <view class="item-type">{{ item.type }}</view>
  33. <view class="item-time">{{ item.time }}</view>
  34. </view>
  35. </view>
  36. <!-- 右侧金额 -->
  37. <view class="item-amount income">¥{{ item.amount }}</view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import navbar from '@/components/base/navbar.vue'
  44. import { assetsData, assetsDataForHead } from '@/static/js/mockAssets.js'
  45. export default {
  46. components: {
  47. navbar
  48. },
  49. data() {
  50. return {
  51. currentTab: 0, // 0-收入明细 1-支出明细
  52. incomeList: [],
  53. expenseList: [],
  54. list: [
  55. {
  56. name: '收入明细',
  57. },
  58. {
  59. name: '支出明细',
  60. }
  61. ],
  62. Data: []
  63. }
  64. },
  65. onLoad() {
  66. const identity = uni.getStorageSync('identity')
  67. if (identity) {
  68. // 从mock数据获取收入和支出明细
  69. this.Data = assetsDataForHead
  70. } else {
  71. // 从mock数据获取收入和支出明细
  72. this.Data = assetsData
  73. }
  74. this.switchTab(0)
  75. },
  76. methods: {
  77. // 切换标签
  78. switchTab(index) {
  79. this.currentTab = index
  80. // 切换显示的列表
  81. if (index === 0) {
  82. this.incomeList = this.Data.incomeList
  83. } else {
  84. this.incomeList = this.Data.expenseList
  85. }
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .assets-page {
  92. // min-height: 100vh;
  93. // background-color: #f5f5f5;
  94. }
  95. .transaction-list {
  96. padding: 0 20rpx;
  97. // background-color: #fff;
  98. }
  99. .transaction-item {
  100. display: flex;
  101. justify-content: space-between;
  102. align-items: center;
  103. padding: 30rpx 10rpx;
  104. border-bottom: 1rpx solid #E0E0E0;
  105. &:last-child {
  106. border-bottom: none;
  107. }
  108. .item-left {
  109. display: flex;
  110. align-items: center;
  111. .icon-container {
  112. width: 70rpx;
  113. height: 70rpx;
  114. border-radius: 50%;
  115. // background-color: rgba(1, 146, 69, 0.1);
  116. display: flex;
  117. justify-content: center;
  118. align-items: center;
  119. margin-right: 20rpx;
  120. border: 4rpx solid $uni-color ;
  121. }
  122. .item-info {
  123. .item-type {
  124. font-size: 30rpx;
  125. color: #333;
  126. margin-bottom: 6rpx;
  127. font-weight: 600;
  128. }
  129. .item-time {
  130. font-size: 24rpx;
  131. color: #949494;
  132. }
  133. }
  134. }
  135. .item-amount {
  136. font-size: 32rpx;
  137. font-weight: 500;
  138. &.income {
  139. color: $uni-color-second;
  140. }
  141. &.expense {
  142. color: #333;
  143. }
  144. }
  145. }
  146. // 添加tab样式
  147. .tab-container {
  148. width: 100%;
  149. // background-color: #fff;
  150. padding: 30rpx 0;
  151. }
  152. .tab-wrapper {
  153. display: flex;
  154. position: relative;
  155. width: 90%;
  156. height: 68rpx;
  157. margin: 0 auto;
  158. background-color: #cfcfcf;
  159. border-radius: 42rpx;
  160. overflow: hidden;
  161. margin-bottom: 20rpx;
  162. }
  163. .tab-item {
  164. flex: 1;
  165. display: flex;
  166. justify-content: center;
  167. align-items: center;
  168. height: 100%;
  169. font-size: 28rpx;
  170. color: #333;
  171. position: relative;
  172. z-index: 1;
  173. transition: color 0.3s;
  174. &.active {
  175. color: #fff;
  176. font-weight: 500;
  177. }
  178. }
  179. .tab-slider {
  180. position: absolute;
  181. width: 50%;
  182. height: 100%;
  183. background-color: $uni-color;
  184. border-radius: 42rpx;
  185. top: 0;
  186. transition: left 0.3s cubic-bezier(0.35, 0, 0.25, 1);
  187. z-index: 0;
  188. }
  189. </style>