index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <div class="support-wrap">
  3. <div class="list">
  4. <div
  5. v-for="(item, index) in list"
  6. :key="index"
  7. class="item"
  8. @click="startPay(item)"
  9. >
  10. <div
  11. class="left"
  12. :style="{ backgroundImage: `url(${item.cover})` }"
  13. >
  14. <div
  15. v-if="item.badge"
  16. class="badge"
  17. :style="{ backgroundColor: item.badge_bg }"
  18. >
  19. <div class="txt">{{ item.badge }}</div>
  20. </div>
  21. </div>
  22. <div class="right">
  23. <div class="title">{{ item.name }}</div>
  24. <div class="info">100%好评</div>
  25. <div class="desc">{{ item.desc }}</div>
  26. <div class="price-wrap">
  27. <span class="price">¥{{ item.price }}</span>
  28. <del
  29. v-if="item.price !== item.original_price"
  30. class="original-price"
  31. >
  32. {{ item.original_price }}
  33. </del>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. <QrPayCpt
  39. v-if="showQrPay"
  40. :money="goodsInfo.money"
  41. :goods-id="goodsInfo.goodsId"
  42. :live-room-id="goodsInfo.liveRoomId"
  43. ></QrPayCpt>
  44. </div>
  45. </template>
  46. <script lang="ts" setup>
  47. import { nextTick, onMounted, reactive, ref } from 'vue';
  48. import { fetchGoodsList } from '@/api/goods';
  49. import QrPayCpt from '@/components/QrPay/index.vue';
  50. import { GoodsTypeEnum, IGoods } from '@/interface';
  51. const list = ref<IGoods[]>([]);
  52. const showQrPay = ref(false);
  53. const goodsInfo = reactive({
  54. money: '0.00',
  55. goodsId: -1,
  56. liveRoomId: -1,
  57. });
  58. async function getGoodsList() {
  59. const res = await fetchGoodsList({
  60. type: GoodsTypeEnum.support,
  61. orderName: 'created_at',
  62. orderBy: 'desc',
  63. });
  64. if (res.code === 200) {
  65. console.log(res.data);
  66. list.value = res.data.rows;
  67. }
  68. }
  69. onMounted(() => {
  70. getGoodsList();
  71. });
  72. function startPay(item: IGoods) {
  73. showQrPay.value = false;
  74. nextTick(() => {
  75. goodsInfo.money = item.price!;
  76. goodsInfo.goodsId = item.id!;
  77. showQrPay.value = true;
  78. });
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. .support-wrap {
  83. margin-top: 30px;
  84. padding: 0 20px;
  85. .list {
  86. display: flex;
  87. .item {
  88. display: flex;
  89. margin-right: 20px;
  90. padding: 10px;
  91. border-radius: 10px;
  92. box-shadow: 0 4px 30px 0 rgba(238, 242, 245, 0.8);
  93. cursor: pointer;
  94. transition: box-shadow 0.2s linear;
  95. &:hover {
  96. box-shadow: 4px 4px 20px 0 rgba(205, 216, 228, 0.6);
  97. }
  98. .left {
  99. position: relative;
  100. margin-right: 10px;
  101. width: 100px;
  102. height: 100px;
  103. background-position: center center;
  104. background-size: cover;
  105. background-repeat: no-repeat;
  106. .badge {
  107. position: absolute;
  108. top: -10px;
  109. right: -10px;
  110. display: flex;
  111. align-items: center;
  112. justify-content: center;
  113. border-radius: 2px;
  114. padding: 2px;
  115. color: white;
  116. .txt {
  117. display: inline-block;
  118. transform-origin: center !important;
  119. line-height: 1;
  120. @include minFont(10);
  121. }
  122. }
  123. }
  124. .right {
  125. .title {
  126. font-size: 22px;
  127. }
  128. .info {
  129. }
  130. .price-wrap {
  131. display: flex;
  132. align-items: center;
  133. .price {
  134. color: gold;
  135. font-size: 22px;
  136. }
  137. .original-price {
  138. margin-left: 5px;
  139. color: #666;
  140. font-size: 14px;
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. </style>