index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <page :nav="false" ref="pageRef">
  3. <view class="wrapper-p" :class="[num <= 10 ? 'flex-column-align' : 'paddingT30']">
  4. <view class="lotteryTitle">
  5. <image class="lotteryTitleimage" :src="ossurl.box.lotteryTitle" mode="aspectFit" />
  6. </view>
  7. <view class="content" v-if="tableData && tableData.length > 0">
  8. <view class="flex-wrap flex-align-center">
  9. <view
  10. class="flex-column-align-center marginB18 paddingX3"
  11. v-for="(item, index) in tableData"
  12. :key="item.id"
  13. >
  14. <card
  15. v-if="num == 1"
  16. :data="item"
  17. :animal="animal"
  18. :rotate="false"
  19. :size="{ width: 164, height: 250 }"
  20. :cover-size="{ width: 134, height: 169, top: 15 }"
  21. :text-size="{ width: 107, height: 48, bottom: 16 }"
  22. @show-detail="showDetail"
  23. :show-add="!!periodQuantity"
  24. />
  25. <card
  26. v-else-if="num == 5"
  27. :data="item"
  28. :animal="animal"
  29. :rotate="false"
  30. :size="{ width: 164, height: 250 }"
  31. :cover-size="{ width: 134, height: 169, top: 15 }"
  32. :text-size="{ width: 107, height: 48, bottom: 16 }"
  33. @show-detail="showDetail"
  34. :show-add="!!periodQuantity"
  35. />
  36. <card
  37. v-else-if="num >= 10"
  38. :data="item"
  39. :animal="animal"
  40. :rotate="false"
  41. :size="{ width: 164, height: 250 }"
  42. :cover-size="{ width: 134, height: 169, top: 15 }"
  43. :text-size="{ width: 107, height: 48, bottom: 16 }"
  44. @show-detail="showDetail"
  45. :show-add="!!periodQuantity"
  46. />
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <view v-if="roll && roll > 0" class="roll translateX flex-align-center">
  52. 骰子 + {{ roll }}
  53. </view>
  54. <view v-if="showResult">
  55. <view class="bottom-btns flex-align-center">
  56. <view v-if="!!total && showDh && hide" class="relative dhBtn" @click="dhAll">
  57. <view>全部兑换</view>
  58. <view class="btnText">共兑换源石 {{ total }}</view>
  59. </view>
  60. <view class="relative agianBtn" @click="$router.back()">再来一发</view>
  61. </view>
  62. <view class="flex-align-center paddingT12 showStore" @click="$router.replace('store')">
  63. <view>
  64. 前往
  65. <span class="color-theme storeText">仓库</span>
  66. 查看
  67. </view>
  68. </view>
  69. </view>
  70. <goods-detail ref="goodsDetailRef" />
  71. <king ref="kingRef" />
  72. <hiddenTask ref="hiddenTaskRef" @refresh="init(true)" />
  73. </page>
  74. </template>
  75. <script>
  76. import card from './card'
  77. import ossurl from '@/utils/ossurl'
  78. import { LEVEL_MAP } from '@/utils/config'
  79. import { throttle, message } from '@/utils'
  80. import goodsDetail from './../store/goods_detail'
  81. import king from './../lottery/king'
  82. import store from '@/store'
  83. import hiddenTask from '../hidden_activity/hidden_task_dialog.vue'
  84. export default {
  85. components: { card, goodsDetail, king, hiddenTask },
  86. data() {
  87. return {
  88. LEVEL_MAP,
  89. ossurl,
  90. num: 1,
  91. animal: false,
  92. tableData: null,
  93. total: '-',
  94. showDh: false,
  95. showResult: false,
  96. periodQuantity: null,
  97. roll: 0
  98. }
  99. },
  100. computed: {
  101. hide() {
  102. return !this.$store.state.hide
  103. }
  104. },
  105. onLoad(options) {
  106. this.num = options.num
  107. this.tradeNo = options.tradeNo
  108. },
  109. mounted() {
  110. this.initData(0, true)
  111. },
  112. methods: {
  113. async initData(count, loading) {
  114. loading && this.$message.showLoading()
  115. setTimeout(async () => {
  116. await this.getData()
  117. if (this.tableData && this.tableData.length > 0) {
  118. const closeVibrator = store.getters.closeVibrator
  119. if (!closeVibrator) {
  120. wx.vibrateLong()
  121. }
  122. this.$message.hideLoading()
  123. } else {
  124. if (count < 3) {
  125. this.initData(count + 1)
  126. } else {
  127. this.$message.hideLoading()
  128. this.$message.confirm(
  129. '购买结果请至订单详情查看',
  130. () => {
  131. this.$router.replace('order_award')
  132. },
  133. '',
  134. ['去查看', '返回'],
  135. () => this.$router.back()
  136. )
  137. }
  138. }
  139. }, 400)
  140. },
  141. async getData() {
  142. const res = await this.$service.award.applyResult(this.tradeNo)
  143. if (res && res.inventoryList) {
  144. let array = res.inventoryList
  145. if (res.magicFireworksList && res.magicFireworksList.length > 0) {
  146. array = [...res.magicFireworksList, ...res.inventoryList]
  147. }
  148. this.tableData = array
  149. this.cacuTotal()
  150. if (res.kingRealtime && res.kingRealtime.periodQuantity) {
  151. this.periodQuantity = res.kingRealtime.periodQuantity
  152. }
  153. if (res.richmanTicketRealtime && res.richmanTicketRealtime.changeTicket) {
  154. this.roll = res.richmanTicketRealtime.changeTicket
  155. setTimeout(() => {
  156. this.roll = 0
  157. }, 2000)
  158. } else {
  159. this.roll = 0
  160. }
  161. this.$nextTick(() => {
  162. this.animal = true
  163. setTimeout(() => {
  164. this.showDh = this.tableData.every(
  165. (item) => item.level !== 'B' && item.level !== 'A'
  166. )
  167. this.showResult = true
  168. }, 900)
  169. })
  170. }
  171. const spuIds = res.inventoryList.map((item) => item.spu.id)
  172. const hideRes = await this.$service.award.hideTaskStart(JSON.stringify(spuIds))
  173. if (hideRes === 1 || hideRes === 2) {
  174. this.$refs.hiddenTaskRef.show(hideRes)
  175. }
  176. return true
  177. },
  178. async cacuTotal() {
  179. let total = 0
  180. this.tableData.forEach((item) => {
  181. total += item.magicAmount
  182. })
  183. this.total = total
  184. },
  185. async dhAll() {
  186. if (!this.total) return
  187. throttle.call(() => {
  188. this.realDh()
  189. })
  190. },
  191. async dh(item) {
  192. if (!item.magicAmount) return
  193. throttle.call(() => {
  194. this.realDh(item)
  195. })
  196. },
  197. async realDh(item) {
  198. let ids = []
  199. if (item) {
  200. ids = [item.id]
  201. } else {
  202. this.tableData.forEach((item) => {
  203. if (item.magicAmount) {
  204. ids.push(item.id)
  205. }
  206. })
  207. }
  208. const res = await this.$service.award.convertApply(ids)
  209. if (res) {
  210. if (item) {
  211. this.$set(item, 'magicAmount', 0)
  212. } else {
  213. this.tableData.forEach((item) => {
  214. item.magicAmount = 0
  215. })
  216. this.tableData = [...this.tableData]
  217. }
  218. this.cacuTotal()
  219. if (this.total === 0) {
  220. this.$router.back()
  221. setTimeout(() => {
  222. message.success('兑换成功')
  223. }, 200)
  224. } else {
  225. message.success('兑换成功')
  226. }
  227. }
  228. },
  229. showDetail(item) {
  230. this.$refs.goodsDetailRef.show(item.spu)
  231. }
  232. }
  233. }
  234. </script>
  235. <style></style>
  236. <style lang="scss" scoped>
  237. .bg {
  238. position: fixed;
  239. z-index: -1;
  240. left: 0;
  241. right: 0;
  242. top: 0;
  243. width: 100%;
  244. height: 1624rpx;
  245. }
  246. .wrapper-p {
  247. height: calc(100vh - 90rpx - 128rpx - 70rpx);
  248. position: relative;
  249. overflow: scroll;
  250. }
  251. .guang {
  252. position: absolute;
  253. width: 750rpx;
  254. height: 744rpx;
  255. z-index: -1;
  256. }
  257. .padding-bottom-num {
  258. padding-bottom: 238rpx;
  259. }
  260. .content {
  261. position: relative;
  262. height: 60vh;
  263. overflow: auto;
  264. .dh-wrapper {
  265. position: relative;
  266. margin-top: 20rpx;
  267. width: 164rpx;
  268. height: 46rpx;
  269. image {
  270. position: absolute;
  271. left: 0;
  272. bottom: 0;
  273. width: 100%;
  274. height: 100%;
  275. z-index: -1;
  276. }
  277. .text {
  278. font-size: 20rpx;
  279. color: #fff;
  280. }
  281. }
  282. }
  283. .bottom-btns {
  284. padding: 40rpx 20rpx 00rpx 20rpx;
  285. .text {
  286. width: 100%;
  287. text-align: center;
  288. position: absolute;
  289. bottom: 30rpx;
  290. font-size: 24rpx;
  291. color: #fff;
  292. }
  293. .image {
  294. height: 128rpx;
  295. // width: 100%;
  296. width: 356rpx;
  297. }
  298. }
  299. .link {
  300. text-shadow: 0px 0px 20rpx #a76ef4;
  301. font-weight: 600;
  302. color: #a76ef4;
  303. font-size: 32rpx;
  304. padding-bottom: 100rpx;
  305. text-align: center;
  306. }
  307. .prince-value {
  308. width: 374rpx;
  309. height: 52rpx;
  310. position: relative;
  311. .image {
  312. position: absolute;
  313. left: 0;
  314. top: 0;
  315. width: 374rpx;
  316. height: 52rpx;
  317. }
  318. .text {
  319. color: white;
  320. font-size: 30rpx;
  321. position: relative;
  322. }
  323. }
  324. .roll {
  325. position: absolute;
  326. opacity: 1;
  327. bottom: 55%;
  328. width: 250rpx;
  329. height: 70rpx;
  330. background: linear-gradient(270deg, #6c6fff, #a948ff);
  331. z-index: 2000;
  332. font-size: 40rpx;
  333. color: #fff;
  334. }
  335. .dhBtn {
  336. background: #fff7e3;
  337. border-radius: 40rpx;
  338. text-align: center;
  339. height: 80rpx;
  340. padding: 0 36rpx;
  341. padding-top: 8rpx;
  342. font-size: 28rpx;
  343. font-family: Source Han Sans, Source Han Sans;
  344. font-weight: 350;
  345. color: #000000;
  346. margin-right: 20rpx;
  347. .btnText {
  348. font-size: 20rpx;
  349. font-family: Source Han Sans, Source Han Sans;
  350. font-weight: 350;
  351. color: #735200;
  352. }
  353. }
  354. .agianBtn {
  355. height: 80rpx;
  356. line-height: 80rpx;
  357. text-align: center;
  358. padding: 0 50rpx;
  359. background: #fec433;
  360. border-radius: 40rpx;
  361. }
  362. .showStore {
  363. font-size: 24rpx;
  364. }
  365. .storeText {
  366. display: inline-block;
  367. font-size: 24rpx;
  368. }
  369. .lotteryTitle {
  370. padding-top: 80rpx;
  371. text-align: center;
  372. padding-bottom: 30rpx;
  373. .lotteryTitleimage {
  374. width: 400rpx;
  375. height: 80rpx;
  376. }
  377. }
  378. </style>