index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="sponsors-wrap">
  3. <h1 class="txt">
  4. 截止至{{ onMountedTime }},已收到:{{ receiveMoney / 100 }}元赞助~
  5. </h1>
  6. <div class="pay-list">
  7. <div
  8. v-for="(item, index) in payList"
  9. :key="index"
  10. class="item"
  11. >
  12. <div class="time">发起时间:{{ item.created_at }},</div>
  13. <div class="user">
  14. <template v-if="item.user">
  15. <img
  16. :src="item.user.avatar"
  17. class="avatar"
  18. alt=""
  19. />
  20. <span class="username">{{ item.user.username }}</span>
  21. </template>
  22. <span v-else>游客</span>,
  23. </div>
  24. <div class="account">支付宝账号:{{ item.buyer_logon_id }},</div>
  25. <div class="gift">
  26. 赞助了:{{ item.subject }}({{ item.total_amount }}元),
  27. </div>
  28. <div class="status">
  29. 状态:{{
  30. item.trade_status === PayStatusEnum.WAIT_BUYER_PAY
  31. ? '支付中'
  32. : '已支付'
  33. }},
  34. </div>
  35. <div class="time">支付时间:{{ item.send_pay_date || '-' }}</div>
  36. </div>
  37. </div>
  38. <h2>开始赞助(支付宝)</h2>
  39. <div class="gift-list">
  40. <div
  41. v-for="(item, index) in sponsorsGoodsList"
  42. :key="index"
  43. class="item"
  44. @click="startPay(item)"
  45. >
  46. {{ item.name }}({{ item.price }}元)
  47. </div>
  48. </div>
  49. <QrPayCpt
  50. v-if="showQrPay"
  51. :money="goodsInfo.money"
  52. :goods-id="goodsInfo.goodsId"
  53. :live-room-id="goodsInfo.liveRoomId"
  54. ></QrPayCpt>
  55. </div>
  56. </template>
  57. <script lang="ts" setup>
  58. import { nextTick, onMounted, onUnmounted, reactive, ref } from 'vue';
  59. import { fetchGoodsList } from '@/api/goods';
  60. import { fetchOrderList } from '@/api/order';
  61. import QrPayCpt from '@/components/QrPay/index.vue';
  62. import { GoodsTypeEnum, IGoods, IOrder, PayStatusEnum } from '@/interface';
  63. const onMountedTime = ref('');
  64. const payStatusTimer = ref();
  65. const downTimer = ref();
  66. const receiveMoney = ref(0);
  67. const showQrPay = ref(false);
  68. const goodsInfo = reactive({
  69. money: '0.00',
  70. goodsId: -1,
  71. liveRoomId: -1,
  72. });
  73. const payList = ref<IOrder[]>([]);
  74. const sponsorsGoodsList = ref<IGoods[]>([]);
  75. onUnmounted(() => {
  76. clearInterval(payStatusTimer.value);
  77. clearInterval(downTimer.value);
  78. });
  79. onMounted(() => {
  80. onMountedTime.value = new Date().toLocaleString();
  81. getPayList();
  82. getGoodsList();
  83. });
  84. async function getGoodsList() {
  85. const res = await fetchGoodsList({
  86. type: GoodsTypeEnum.sponsors,
  87. orderName: 'created_at',
  88. orderBy: 'desc',
  89. });
  90. if (res.code === 200) {
  91. sponsorsGoodsList.value = res.data.rows;
  92. }
  93. }
  94. async function getPayList() {
  95. try {
  96. const res = await fetchOrderList({
  97. trade_status: PayStatusEnum.TRADE_SUCCESS,
  98. });
  99. if (res.code === 200) {
  100. payList.value = res.data.rows;
  101. receiveMoney.value = payList.value.reduce(
  102. (pre, item) => pre + Number(item.total_amount) * 100,
  103. 0
  104. );
  105. }
  106. } catch (error) {
  107. console.log(error);
  108. }
  109. }
  110. function startPay(item: IGoods) {
  111. showQrPay.value = false;
  112. nextTick(() => {
  113. goodsInfo.money = item.price!;
  114. goodsInfo.goodsId = item.id!;
  115. showQrPay.value = true;
  116. });
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .sponsors-wrap {
  121. text-align: center;
  122. .pay-list {
  123. display: flex;
  124. overflow: scroll;
  125. align-items: center;
  126. flex-direction: column;
  127. box-sizing: border-box;
  128. margin-bottom: 20px;
  129. padding: 10px;
  130. width: 100%;
  131. height: 200px;
  132. background-color: papayawhip;
  133. .item {
  134. display: inline-flex;
  135. flex-wrap: wrap;
  136. justify-content: center;
  137. margin-bottom: 4px;
  138. width: 100%;
  139. text-align: left;
  140. .user {
  141. width: 120px;
  142. padding: 0 10px;
  143. display: flex;
  144. align-items: center;
  145. justify-content: center;
  146. .avatar {
  147. width: 30px;
  148. height: 30px;
  149. border-radius: 50%;
  150. }
  151. .username {
  152. @extend %singleEllipsis;
  153. }
  154. }
  155. .account {
  156. width: 250px;
  157. }
  158. .gift {
  159. width: 260px;
  160. }
  161. .status {
  162. width: 120px;
  163. text-align: left;
  164. }
  165. .time {
  166. width: 280px;
  167. }
  168. }
  169. }
  170. .gift-list {
  171. display: flex;
  172. align-items: center;
  173. flex-wrap: wrap;
  174. justify-content: center;
  175. .item {
  176. margin: 5px;
  177. padding: 5px 10px;
  178. border-radius: 4px;
  179. background-color: skyblue;
  180. cursor: pointer;
  181. }
  182. }
  183. }
  184. </style>