dhjilu.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <div>
  3. <!-- 导航栏 -->
  4. <div class="nav-bar">
  5. <div class="back-btn" @click="$router.back()">
  6. <i class="arrow-left"></i>
  7. </div>
  8. <div class="title">兑换记录</div>
  9. </div>
  10. <!-- 主容器 -->
  11. <div class="dhjilu-container">
  12. <div class="content-wrapper">
  13. <!-- 记录列表 -->
  14. <div v-if="exchangeRecords.length > 0" class="record-list">
  15. <div class="record-card" v-for="item in exchangeRecords" :key="item.id">
  16. <div class="row main-row">
  17. <span class="label">商品名称:</span>
  18. <span class="value name">{{ item.prize_name }}</span>
  19. </div>
  20. <div class="row">
  21. <span class="label">兑换时间:</span>
  22. <span class="value">{{ formatTime(item.create_time) }}</span>
  23. </div>
  24. <div class="row">
  25. <span class="label">发货状态:</span>
  26. <span class="value status" :class="'status-' + item.status">{{ getStatusText(item.status) }}</span>
  27. </div>
  28. <div class="row">
  29. <span class="label">快递单号:</span>
  30. <span class="value">{{ item.tranumber || '-' }}</span>
  31. </div>
  32. <div class="row">
  33. <span class="label">收货人:</span>
  34. <span class="value">{{ item.name || '-' }}</span>
  35. </div>
  36. <div class="row">
  37. <span class="label">电话:</span>
  38. <span class="value">{{ item.phone || '-' }}</span>
  39. </div>
  40. <div class="row">
  41. <span class="label">地址:</span>
  42. <span class="value">{{ item.address || '-' }}</span>
  43. </div>
  44. </div>
  45. </div>
  46. <div v-else class="empty-state">
  47. <div class="icon">😕</div>
  48. <div class="text">暂无记录</div>
  49. </div>
  50. </div>
  51. </div>
  52. <!-- Toast 提示 -->
  53. <Toast ref="toast" />
  54. </div>
  55. </template>
  56. <script>
  57. import Toast from '@/components/Toast.vue';
  58. import { getLotteryRecord } from '@/api/profile';
  59. export default {
  60. name: 'DhjiluPage',
  61. components: {
  62. Toast
  63. },
  64. data() {
  65. return {
  66. exchangeRecords: []
  67. }
  68. },
  69. mounted() {
  70. this.loadExchangeRecords();
  71. },
  72. methods: {
  73. // 加载兑换记录
  74. async loadExchangeRecords() {
  75. try {
  76. const res = await getLotteryRecord();
  77. console.log('res:', res);
  78. this.exchangeRecords = Array.isArray(res.data) ? res.data : [];
  79. console.log('records:', this.exchangeRecords);
  80. } catch (error) {
  81. this.exchangeRecords = [];
  82. this.$refs.toast && this.$refs.toast.show('加载记录失败', 'error');
  83. }
  84. },
  85. // 状态文本
  86. getStatusText(status) {
  87. const map = {
  88. '0': '备货中',
  89. '1': '已发货'
  90. };
  91. return map[String(status)] || status || '-';
  92. },
  93. // 时间格式化
  94. formatTime(ts) {
  95. if (!ts) return '-';
  96. // 支持时间戳(秒/毫秒)或字符串
  97. let date;
  98. if (typeof ts === 'number' || /^\d+$/.test(ts)) {
  99. if (String(ts).length === 10) date = new Date(ts * 1000);
  100. else date = new Date(Number(ts));
  101. } else {
  102. date = new Date(ts);
  103. }
  104. if (isNaN(date.getTime())) return '-';
  105. const y = date.getFullYear();
  106. const m = String(date.getMonth() + 1).padStart(2, '0');
  107. const d = String(date.getDate()).padStart(2, '0');
  108. const h = String(date.getHours()).padStart(2, '0');
  109. const min = String(date.getMinutes()).padStart(2, '0');
  110. const s = String(date.getSeconds()).padStart(2, '0');
  111. return `${y}-${m}-${d} ${h}:${min}:${s}`;
  112. }
  113. }
  114. }
  115. </script>
  116. <style scoped>
  117. /* 导航栏样式 */
  118. .nav-bar {
  119. height: 44px;
  120. background-color: #fff;
  121. color: #000;
  122. display: flex;
  123. align-items: center;
  124. position: relative;
  125. padding: 0 15px;
  126. font-weight: bold;
  127. box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  128. }
  129. .back-btn {
  130. width: 24px;
  131. height: 44px;
  132. display: flex;
  133. align-items: center;
  134. cursor: pointer;
  135. }
  136. .arrow-left {
  137. width: 12px;
  138. height: 12px;
  139. border-left: 2px solid #000;
  140. border-bottom: 2px solid #000;
  141. transform: rotate(45deg);
  142. }
  143. .title {
  144. position: absolute;
  145. left: 50%;
  146. transform: translateX(-50%);
  147. font-size: 16px;
  148. }
  149. /* 主容器 */
  150. .dhjilu-container {
  151. min-height: calc(100vh - 44px);
  152. background: linear-gradient(135deg, #c94545 0%, #b43a39 100%);
  153. padding: 20px;
  154. padding-bottom: 100px;
  155. }
  156. .content-wrapper {
  157. background: white;
  158. border-radius: 12px;
  159. padding: 15px;
  160. box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  161. }
  162. /* 记录列表 */
  163. .record-list {
  164. display: flex;
  165. flex-direction: column;
  166. gap: 18px;
  167. }
  168. .record-card {
  169. background: #fff0f0;
  170. border-radius: 14px;
  171. padding: 18px 16px;
  172. box-shadow: 0 2px 8px rgba(180,58,57,0.08);
  173. margin-bottom: 0;
  174. }
  175. .row {
  176. display: flex;
  177. align-items: center;
  178. margin-bottom: 7px;
  179. font-size: 15px;
  180. }
  181. .row:last-child {
  182. margin-bottom: 0;
  183. }
  184. .label {
  185. color: #b43a39;
  186. font-weight: 600;
  187. min-width: 80px;
  188. }
  189. .value {
  190. color: #333;
  191. font-weight: 500;
  192. word-break: break-all;
  193. }
  194. .value.name {
  195. font-size: 16px;
  196. font-weight: bold;
  197. }
  198. .value.status {
  199. font-weight: bold;
  200. }
  201. .status-0 {
  202. color: #e67c00;
  203. }
  204. .status-1 {
  205. color: #1bbf1b;
  206. }
  207. .main-row {
  208. margin-bottom: 10px;
  209. }
  210. /* 响应式优化 */
  211. @media screen and (max-width: 375px) {
  212. .dhjilu-container {
  213. padding: 15px;
  214. }
  215. .record-card {
  216. padding: 12px 8px;
  217. }
  218. .label {
  219. min-width: 60px;
  220. font-size: 14px;
  221. }
  222. .value {
  223. font-size: 14px;
  224. }
  225. }
  226. @media screen and (max-width: 320px) {
  227. .label {
  228. min-width: 80px;
  229. }
  230. .value {
  231. font-size: 13px;
  232. }
  233. }
  234. /* 空状态 */
  235. .empty-state {
  236. text-align: center;
  237. padding: 60px 20px;
  238. color: #999;
  239. }
  240. .empty-state .icon {
  241. font-size: 48px;
  242. margin-bottom: 15px;
  243. color: #ddd;
  244. }
  245. .empty-state .text {
  246. font-size: 16px;
  247. line-height: 1.5;
  248. }
  249. </style>