index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <div class="p-gift-card">
  3. <div>
  4. <h3 class="ptc-title bg-gray">My gift card</h3>
  5. <div class="tabs border-bottom">
  6. <div class="tab" :class="{ active: type === 0 }" @click="type = 0">
  7. <span>NOT USED</span>
  8. <span class="num">{{ stat.unused }}</span>
  9. </div>
  10. <div class="tab" :class="{ active: type === 1 }" @click="type = 1">
  11. <span>USED</span>
  12. <span class="num">{{ stat.used }}</span>
  13. </div>
  14. <div class="tab" :class="{ active: type === 2 }" @click="type = 2">
  15. <span>EXPIRED</span>
  16. <span class="num">{{ stat.expired }}</span>
  17. </div>
  18. </div>
  19. </div>
  20. <div :class="{ 'ptc-loading': loading }">
  21. <div class="card-list-wrap">
  22. <div v-if="!list.length" class="ptc-empty">
  23. <i class="ptc-empty-img"></i>
  24. <p class="ptc-empty-txt">No gift card yet</p>
  25. </div>
  26. <div v-else class="card-list">
  27. <div
  28. v-for="(item, index) of list"
  29. :key="index"
  30. class="card"
  31. :class="{
  32. 'card-a': item.status == 0 && !item.gift_card_threshold,
  33. 'card-b': item.status == 0 && item.gift_card_threshold,
  34. 'card-c': item.status == 1 && !item.gift_card_threshold,
  35. 'card-d': item.status == 1 && item.gift_card_threshold,
  36. 'card-e': item.status == 2,
  37. }"
  38. >
  39. <p class="card-title">{{ item.title }}</p>
  40. <p class="card-period">
  41. Validity: {{ item.used_at }}-{{ item.expired_at }}
  42. </p>
  43. <p class="card-value">
  44. - {{ item.gift_card_amount }}
  45. <span v-if="item.gift_card_threshold" class="sub"
  46. >{{ item.gift_card_threshold }} available</span
  47. >
  48. </p>
  49. <p class="card-desc">PTC offline store use</p>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. import { defineComponent } from 'vue'
  58. import { getGiftCardList } from '@/service/order'
  59. export default defineComponent({
  60. async beforeRouteEnter(to, from, next) {
  61. const { results } = await getGiftCardList(0)
  62. next(vm => {
  63. vm.list = results.items
  64. vm.stat = results.stat
  65. })
  66. },
  67. data() {
  68. return {
  69. type: 0,
  70. /** @type {any[]} */
  71. list: [],
  72. /** @type {any} */
  73. stat: {},
  74. loading: false,
  75. }
  76. },
  77. watch: {
  78. async type(val) {
  79. this.loading = true
  80. try {
  81. const { results } = await getGiftCardList(val)
  82. this.list = results.items
  83. } catch {}
  84. this.loading = false
  85. },
  86. },
  87. })
  88. </script>
  89. <style lang="scss">
  90. .p-gift-card {
  91. .fixed {
  92. position: fixed;
  93. top: var(--nav-bar-height);
  94. left: 0;
  95. right: 0;
  96. }
  97. .tabs {
  98. display: flex;
  99. @include media-breakpoint-down(md) {
  100. justify-content: space-around;
  101. }
  102. line-height: 104px;
  103. background: #fff;
  104. }
  105. .tab {
  106. position: relative;
  107. font-size: 32px;
  108. font-weight: 500;
  109. color: #666;
  110. cursor: pointer;
  111. @include media-breakpoint-up(md) {
  112. margin-left: 140px;
  113. }
  114. &.active {
  115. font-weight: bold;
  116. color: $primary-color;
  117. &::after {
  118. content: '';
  119. position: absolute;
  120. bottom: 0;
  121. left: 50%;
  122. transform: translateX(-50%);
  123. width: 92px;
  124. height: 4px;
  125. background: #193059;
  126. border-radius: 2px;
  127. }
  128. }
  129. .num {
  130. position: absolute;
  131. top: 22px;
  132. right: -4px;
  133. transform: translateX(100%);
  134. font-size: 24px;
  135. line-height: 1;
  136. }
  137. }
  138. .card-list-wrap {
  139. padding: 50px 34px 0;
  140. background: #fff;
  141. @include media-breakpoint-up(md) {
  142. height: 1000px;
  143. overflow: auto;
  144. }
  145. }
  146. .card-list {
  147. margin: auto;
  148. display: flex;
  149. flex-wrap: wrap;
  150. justify-content: space-between;
  151. @include media-breakpoint-up(md) {
  152. width: 680px * 2 + 52px;
  153. }
  154. }
  155. .card {
  156. margin-bottom: 48px;
  157. // width: 680px;
  158. width: 100%;
  159. height: 296px;
  160. text-align: center;
  161. font-weight: bold;
  162. background-size: 100% 100%;
  163. line-height: 1;
  164. overflow: hidden;
  165. @include media-breakpoint-up(md) {
  166. width: 680px;
  167. }
  168. &-title {
  169. margin: 32px 0 16px;
  170. font-size: 32px;
  171. }
  172. &-period,
  173. &-desc {
  174. font-size: 28px;
  175. }
  176. &-value {
  177. margin: 40px 0 32px;
  178. font-size: 56px;
  179. .sub {
  180. font-size: 40px;
  181. }
  182. }
  183. &-a {
  184. background-image: url(@img/coupon0.png);
  185. .card-title,
  186. .card-value {
  187. color: $primary-color;
  188. }
  189. .card-period,
  190. .card-desc {
  191. color: #9aa8c5;
  192. }
  193. }
  194. &-b {
  195. background-image: url(@img/coupon1.png);
  196. .card-title,
  197. .card-value {
  198. color: #cb2927;
  199. }
  200. .card-period,
  201. .card-desc {
  202. color: #f8a7a6;
  203. }
  204. }
  205. &-c {
  206. background-image: url(@img/coupon2.png);
  207. color: #9aa8c5;
  208. }
  209. &-d {
  210. background-image: url(@img/coupon3.png);
  211. color: #f8a7a6;
  212. }
  213. &-e {
  214. background-image: url(@img/coupon4.png);
  215. color: #999;
  216. }
  217. }
  218. }
  219. </style>