index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div class="wrap-outer">
  3. <div class="mob-wrap">
  4. <m-header/>
  5. <div v-if="token">
  6. <div v-if="mineGame.length > 0">
  7. <div style="padding:15px">
  8. <mob-list :gameLis="mineGame" :prefix="prefix">
  9. <template #custom-button="scope">
  10. <div>
  11. <van-button round color="#ed8c0f" @click="showGifts(scope.row)">查看礼包</van-button>
  12. </div>
  13. </template>
  14. </mob-list>
  15. </div>
  16. <div style="padding: 10px;background-color: #f7f7f7;"
  17. class="df aic jcc"
  18. v-if="params.page * params.pagesize <= mineGame.length">
  19. <el-button class="df aic jcc" plain @click="loadMore">更多</el-button>
  20. </div>
  21. <div v-else>
  22. <div class="df aic jcc" style="color: #999;height: 100px;font-size: 16px;">----- 没有更多数据了 -----
  23. </div>
  24. </div>
  25. </div>
  26. <van-empty v-else description="No Data" />
  27. </div>
  28. <div v-else :style="{ height: viewWidth + 'px' }" class="df fdc aic jcc">
  29. <van-empty>
  30. <van-button color="#ed8c0f" @click="goLogin">去登录 &gt;&gt;</van-button>
  31. </van-empty>
  32. </div>
  33. <van-dialog v-model:show="dialogVisible" title="查看礼包" confirm-button-text="关闭">
  34. <van-collapse v-if="giftData.length" v-model="activeNames">
  35. <van-collapse-item v-for="(item, index) in giftData" :key="index" :title="item.gift_name" :name="item.id">
  36. <template #value>
  37. <van-button :disabled="item.user_get_at !== ''" round color="#ed8c0f" @click="receiveGift(item.id)">领取礼包</van-button>
  38. </template>
  39. <van-cell-group>
  40. <van-cell value-class="value-length" center size="large" title="礼包内容:" :value="item.gift_content">
  41. <template #value>
  42. <div style="text-align: left;">
  43. {{ item.gift_content }}
  44. </div>
  45. </template>
  46. </van-cell>
  47. <van-cell value-class="value-length" center size="large" title="使用方法:" :value="item.usage">
  48. <template #value>
  49. <div style="text-align: left;">
  50. {{ item.usage }}
  51. </div>
  52. </template>
  53. </van-cell>
  54. <van-cell value-class="value-length" center size="large" title="有效期:" :value="item.start_at+'-'+item.end_at">
  55. <template #value>
  56. <div style="text-align: left;">
  57. {{ item.start_at+'-'+item.end_at }}
  58. </div>
  59. </template>
  60. </van-cell>
  61. </van-cell-group>
  62. </van-collapse-item>
  63. </van-collapse>
  64. <van-empty v-else description="暂无礼包" />
  65. </van-dialog>
  66. <van-back-top style="background-color: #ed8c0f;" />
  67. <!-- <m_footer></m_footer> -->
  68. </div>
  69. </div>
  70. </template>
  71. <script setup lang="ts">
  72. import { onMounted, ref, reactive } from 'vue'
  73. import { getMineGame, getGiftHttp, receiveGiftHttp } from '@/api/index'
  74. import { useRouter, useRoute } from 'vue-router'
  75. import MobList from '@/components/MobList.vue'
  76. import { useStore } from '@/store/index'
  77. import { showSuccessToast } from 'vant'
  78. const router = useRouter()
  79. const route = useRoute()
  80. const mineGame: any = ref([])
  81. const prefix = ref<string>('')
  82. const total = ref<number>(0)
  83. const isLoading = ref<boolean>(true)
  84. const viewWidth = ref<number>(document.documentElement.clientHeight - 100)
  85. const userAccount = ref<string | null>(localStorage.getItem('account'))
  86. const token = ref<string | null>(localStorage.getItem('token'))
  87. const user = useStore('user')
  88. interface Params {
  89. page: number,
  90. pagesize: number,
  91. account: string | null
  92. }
  93. const params = reactive<Params>({
  94. page: 1,
  95. pagesize: 10,
  96. account: userAccount.value
  97. })
  98. onMounted(() => {
  99. // 进入页面刷新一次
  100. if (token.value) {
  101. if (route.query.account || userAccount.value) {
  102. // if (location.href.indexOf("#reloaded") === -1) {
  103. // location.href = location.href + "#reloaded";
  104. // location.reload();
  105. // }
  106. getMyGame(params)
  107. } else {
  108. userAccount.value = ''
  109. }
  110. }
  111. user.getUserProfile()
  112. })
  113. const getMyGame = async(params) => {
  114. // console.log('params', params);
  115. await getMineGame(params).then(res => {
  116. // console.log('res========>', res);
  117. if (res.data.code === 200 && res.data.data) {
  118. mineGame.value = mineGame.value.concat(res.data.data.lists)
  119. prefix.value = res.data.data.prefix
  120. total.value = res.data.data.total
  121. isLoading.value = false
  122. }
  123. }).catch(err => {
  124. // Message.error(err.data)
  125. console.log(err.data)
  126. })
  127. }
  128. // 加载更多
  129. const loadMore = () => {
  130. params.page += 1
  131. getMyGame(params)
  132. }
  133. const goLogin = () => {
  134. router.push({ path: 'm_login' })
  135. }
  136. const giftData = ref<any[]>([])
  137. const activeNames = ref(['1'])
  138. const dialogVisible = ref<boolean>(false)
  139. const showGifts = async(row:any) => {
  140. await getGiftHttp({ game_id: row.game_id }).then((res) => {
  141. // console.log(res.data.data)
  142. giftData.value = res.data.data || []
  143. dialogVisible.value = true
  144. }).catch((error) => {
  145. console.log(error)
  146. showSuccessToast(error.data.msg)
  147. })
  148. }
  149. const receiveGift = async(id:number) => {
  150. await receiveGiftHttp({ id }).then((res) => {
  151. console.log(res)
  152. showSuccessToast(res.data.msg)
  153. dialogVisible.value = false
  154. }).catch((error) => {
  155. console.log(error)
  156. showSuccessToast(error.data.msg)
  157. })
  158. }
  159. </script>
  160. <style scoped lang="scss">
  161. .game_list {
  162. box-sizing: border-box;
  163. padding: 20px;
  164. background-color: #fff;
  165. margin: 0 auto 20px;
  166. h3 {
  167. font-size: 22px;
  168. font-weight: normal;
  169. height: 30px;
  170. }
  171. }
  172. .more {
  173. margin: 20px auto 0;
  174. height: 60px;
  175. background-color: #f7f7f7;
  176. .el-button {
  177. width: 100px;
  178. height: 40px;
  179. background-color: transparent;
  180. color: #323332;
  181. border: 1px solid #c7c7c7;
  182. }
  183. }
  184. </style>
  185. <style>
  186. .value-length{
  187. flex: 2!important;
  188. }
  189. </style>