CouponGiftList.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="gift-list">
  3. <SpecCard
  4. v-for="spec in giftList"
  5. :key="spec.id"
  6. :tipText="spec.tipText"
  7. :active="spec[activeType] === active"
  8. @onClick="clickSpec(spec)"
  9. >
  10. <div class="spec-c-label">{{ spec.name }}</div>
  11. <div class="spec-c-desc"></div>
  12. </SpecCard>
  13. </div>
  14. </template>
  15. <script>
  16. import SpecCard from '@/components/common/SpecCard.vue'
  17. import { getGiftList } from '@/api/modules/'
  18. export default {
  19. name: 'gift-list',
  20. components: {
  21. SpecCard
  22. },
  23. props: {
  24. productionId: [String, Number],
  25. activeType: {
  26. type: String,
  27. default: 'id'
  28. }
  29. },
  30. data() {
  31. return {
  32. active: '',
  33. token: '', // 用户无身份查询接口
  34. giftList: []
  35. }
  36. },
  37. watch: {
  38. productionId() {
  39. this.getGiftList()
  40. }
  41. },
  42. computed: {
  43. activeItem() {
  44. return this.getActiveItem()
  45. }
  46. },
  47. created() {
  48. this.getToken()
  49. },
  50. methods: {
  51. getToken() {
  52. const { token } = this.$route.query
  53. if (token) {
  54. this.token = token
  55. }
  56. },
  57. clickSpec(spec) {
  58. this.active = spec[this.activeType]
  59. this.$emit('change', spec)
  60. },
  61. getActiveItem() {
  62. return this.giftList.find((spec) => spec[this.activeType] === this.active)
  63. },
  64. async getGiftList() {
  65. var info = {
  66. useProduct: this.productionId,
  67. token: this.token,
  68. useProductType: 0
  69. }
  70. if (!info.useProduct) {
  71. return this.giftListLoaded(0)
  72. }
  73. this.giftList = []
  74. const { data } = await getGiftList(info)
  75. if (Array.isArray(data) && data.length > 0) {
  76. this.giftList = data.map((item) => {
  77. item.preStartTime =
  78. item.preheatingTime && item.preheatingTime.toString().length === 10
  79. ? item.preheatingTime * 1000
  80. : item.preheatingTime
  81. item.startTime =
  82. item.beginDate && item.beginDate.toString().length === 10
  83. ? item.beginDate * 1000
  84. : item.beginDate
  85. item.endTime =
  86. item.endDate && item.endDate.toString().length === 10
  87. ? item.endDate * 1000
  88. : item.endDate
  89. item.isReceive = item.IsReceive
  90. if (!item.stockNumber) {
  91. item.stockNumber = 0
  92. }
  93. const giftInfo = this.sortGiftInfo(item)
  94. return {
  95. ...item,
  96. giftInfo
  97. }
  98. })
  99. } else {
  100. this.giftList = []
  101. }
  102. this.giftListLoaded(this.giftList.length)
  103. },
  104. sortGiftInfo(gift) {
  105. const info = gift
  106. let timeType = ''
  107. if (info.timeType === 1) {
  108. timeType = '天'
  109. return `${info.time}${timeType}`
  110. } else if (info.timeType === 2) {
  111. timeType = '月'
  112. return `${info.time}个${timeType}`
  113. }
  114. return ''
  115. },
  116. giftListLoaded(length) {
  117. this.$emit('loaded', { data: length, list: this.giftList })
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .gift-list {
  124. display: flex;
  125. align-items: center;
  126. justify-content: space-between;
  127. ::v-deep {
  128. .spec-card {
  129. width: 240px;
  130. height: 120px;
  131. }
  132. .spec-card:not(:last-of-type) {
  133. margin-right: 16px;
  134. }
  135. }
  136. }
  137. </style>