index.vue 5.2 KB

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