transaction.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <view class="page-container">
  3. <!-- 顶部导航栏 -->
  4. <view class="custom-navbar">
  5. <view class="navbar-back" @click="handleBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <view class="navbar-title">
  9. <text class="title-text">订阅记录</text>
  10. </view>
  11. <view class="navbar-placeholder"></view>
  12. </view>
  13. <!-- 订阅记录列表 -->
  14. <scroll-view class="scroll-view" scroll-y>
  15. <view class="subscription-list">
  16. <!-- 订阅记录项 -->
  17. <view
  18. v-for="(item, index) in subscriptions"
  19. :key="index"
  20. class="subscription-item"
  21. >
  22. <view class="item-header">
  23. <view class="pool-info">
  24. <text class="pool-icon">{{ item.poolType === 'pool' ? '⚡' : '📈' }}</text>
  25. <text class="pool-name">{{ item.poolName }}</text>
  26. </view>
  27. <view :class="['status-badge', item.isActive ? 'status-active' : 'status-expired']">
  28. <text class="status-text">{{ item.isActive ? '生效中' : '已过期' }}</text>
  29. </view>
  30. </view>
  31. <view class="item-body">
  32. <view class="info-row">
  33. <text class="info-label">订阅方案:</text>
  34. <text class="info-value">{{ item.planName }}</text>
  35. </view>
  36. <view class="info-row">
  37. <text class="info-label">订阅金额:</text>
  38. <text class="info-value price">¥{{ item.amount }}</text>
  39. </view>
  40. <view class="info-row">
  41. <text class="info-label">购买时间:</text>
  42. <text class="info-value">{{ formatDateTime(item.purchaseTime) }}</text>
  43. </view>
  44. <view class="info-row">
  45. <text class="info-label">到期时间:</text>
  46. <text class="info-value">{{ formatDateTime(item.expireTime) }}</text>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- 空状态 -->
  51. <view v-if="subscriptions.length === 0" class="empty-state">
  52. <text class="empty-icon">📋</text>
  53. <text class="empty-text">暂无订阅记录</text>
  54. <text class="empty-desc">前往超短池或强势池订阅服务</text>
  55. </view>
  56. <!-- 底部安全区域 -->
  57. <view class="bottom-safe-area"></view>
  58. </view>
  59. </scroll-view>
  60. </view>
  61. </template>
  62. <script setup>
  63. import { ref, onMounted } from 'vue'
  64. import { onLoad, onShow } from '@dcloudio/uni-app'
  65. import { isLoggedIn as checkLoginStatus } from '../../utils/auth.js'
  66. const subscriptions = ref([])
  67. const isLoggedIn = ref(false)
  68. // 检查登录状态
  69. const checkLogin = () => {
  70. isLoggedIn.value = checkLoginStatus()
  71. console.log('[订阅记录] 登录状态:', isLoggedIn.value)
  72. }
  73. // 返回上一页
  74. const handleBack = () => {
  75. const pages = getCurrentPages()
  76. if (pages.length > 1) {
  77. // 有上一页,返回
  78. uni.navigateBack()
  79. } else {
  80. // 没有上一页,跳转到个人中心
  81. uni.switchTab({
  82. url: '/pages/mine/mine'
  83. })
  84. }
  85. }
  86. // 格式化日期时间
  87. const formatDateTime = (timestamp) => {
  88. const date = new Date(timestamp)
  89. const year = date.getFullYear()
  90. const month = String(date.getMonth() + 1).padStart(2, '0')
  91. const day = String(date.getDate()).padStart(2, '0')
  92. const hours = String(date.getHours()).padStart(2, '0')
  93. const minutes = String(date.getMinutes()).padStart(2, '0')
  94. return `${year}-${month}-${day} ${hours}:${minutes}`
  95. }
  96. // 加载订阅记录
  97. const loadSubscriptions = () => {
  98. try {
  99. const now = Date.now()
  100. const allSubscriptions = []
  101. // 加载超短池订阅记录
  102. const poolPurchase = uni.getStorageSync('pool_purchase')
  103. if (poolPurchase) {
  104. allSubscriptions.push({
  105. poolType: 'pool',
  106. poolName: '超短精选池',
  107. planName: poolPurchase.plan === 'daily' ? '日订阅' : '周套餐',
  108. amount: poolPurchase.plan === 'daily' ? '18' : '98',
  109. purchaseTime: poolPurchase.purchaseTime,
  110. expireTime: poolPurchase.expireTime,
  111. isActive: now < poolPurchase.expireTime
  112. })
  113. }
  114. // 加载强势池订阅记录
  115. const strongPurchase = uni.getStorageSync('strong_pool_purchase')
  116. if (strongPurchase) {
  117. allSubscriptions.push({
  118. poolType: 'strong',
  119. poolName: '强势趋势池',
  120. planName: '年订阅',
  121. amount: '98',
  122. purchaseTime: strongPurchase.purchaseTime,
  123. expireTime: strongPurchase.expireTime,
  124. isActive: now < strongPurchase.expireTime
  125. })
  126. }
  127. // 按购买时间倒序排列
  128. subscriptions.value = allSubscriptions.sort((a, b) => b.purchaseTime - a.purchaseTime)
  129. } catch (e) {
  130. console.error('加载订阅记录失败:', e)
  131. subscriptions.value = []
  132. }
  133. }
  134. onLoad(() => {
  135. checkLogin()
  136. })
  137. onMounted(() => {
  138. loadSubscriptions()
  139. })
  140. onShow(() => {
  141. checkLogin()
  142. loadSubscriptions()
  143. })
  144. </script>
  145. <style scoped>
  146. .page-container {
  147. min-height: 100vh;
  148. background: #f5f6fb;
  149. display: flex;
  150. flex-direction: column;
  151. }
  152. /* 自定义导航栏 */
  153. .custom-navbar {
  154. background: #ffffff;
  155. display: flex;
  156. align-items: center;
  157. justify-content: space-between;
  158. padding: 80rpx 32rpx 30rpx;
  159. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
  160. position: relative;
  161. }
  162. .navbar-back {
  163. width: 80rpx;
  164. height: 60rpx;
  165. display: flex;
  166. align-items: center;
  167. justify-content: flex-start;
  168. }
  169. .back-icon {
  170. font-size: 40rpx;
  171. color: #222222;
  172. font-weight: bold;
  173. }
  174. .navbar-title {
  175. position: absolute;
  176. left: 50%;
  177. transform: translateX(-50%);
  178. }
  179. .title-text {
  180. font-size: 36rpx;
  181. font-weight: 600;
  182. color: #222222;
  183. }
  184. .navbar-placeholder {
  185. width: 80rpx;
  186. }
  187. /* 订阅记录列表 */
  188. .scroll-view {
  189. flex: 1;
  190. height: 0;
  191. }
  192. .subscription-list {
  193. padding: 32rpx;
  194. }
  195. .subscription-item {
  196. background: #ffffff;
  197. border-radius: 24rpx;
  198. padding: 32rpx;
  199. margin-bottom: 24rpx;
  200. box-shadow: 0 8rpx 24rpx rgba(37, 52, 94, 0.08);
  201. }
  202. .item-header {
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. margin-bottom: 24rpx;
  207. padding-bottom: 24rpx;
  208. border-bottom: 1rpx solid #f1f2f6;
  209. }
  210. .pool-info {
  211. display: flex;
  212. align-items: center;
  213. }
  214. .pool-icon {
  215. font-size: 32rpx;
  216. margin-right: 12rpx;
  217. }
  218. .pool-name {
  219. font-size: 30rpx;
  220. font-weight: 600;
  221. color: #222222;
  222. }
  223. .status-badge {
  224. padding: 8rpx 20rpx;
  225. border-radius: 20rpx;
  226. font-size: 24rpx;
  227. }
  228. .status-active {
  229. background: #e7f7ef;
  230. color: #3abf81;
  231. }
  232. .status-expired {
  233. background: #f5f5f5;
  234. color: #999999;
  235. }
  236. .status-text {
  237. font-weight: 500;
  238. }
  239. .item-body {
  240. display: flex;
  241. flex-direction: column;
  242. gap: 16rpx;
  243. }
  244. .info-row {
  245. display: flex;
  246. align-items: center;
  247. font-size: 26rpx;
  248. }
  249. .info-label {
  250. color: #666a7f;
  251. min-width: 160rpx;
  252. }
  253. .info-value {
  254. color: #222222;
  255. font-weight: 500;
  256. }
  257. .info-value.price {
  258. color: #f16565;
  259. font-weight: 700;
  260. font-size: 28rpx;
  261. }
  262. /* 空状态 */
  263. .empty-state {
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. justify-content: center;
  268. padding: 200rpx 60rpx;
  269. }
  270. .empty-icon {
  271. font-size: 120rpx;
  272. margin-bottom: 32rpx;
  273. }
  274. .empty-text {
  275. font-size: 32rpx;
  276. font-weight: 600;
  277. color: #333333;
  278. margin-bottom: 16rpx;
  279. }
  280. .empty-desc {
  281. font-size: 26rpx;
  282. color: #999999;
  283. text-align: center;
  284. line-height: 1.6;
  285. }
  286. .bottom-safe-area {
  287. height: 80rpx;
  288. }
  289. </style>