index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view class="app-container">
  3. <view class="nav" :style="{'padding-top': statusBarHeight + 'px'}">
  4. <uni-icons type="back" style="font-size: 48rpx" @click="close" />
  5. <text class="title">积分抽奖</text>
  6. </view>
  7. <!-- 每次消耗多少积分 -->
  8. <view class="every">{{lotteryConsumePoint}}积分/次</view>
  9. <!-- 转盘 -->
  10. <LuckyWheel class="lucky" ref="lucky" width="568rpx" height="568rpx" :prizes="prizes" :buttons="buttons"
  11. :defaultStyle="defaultStyle" @start="startCallBack" @end="endCallBack" />
  12. <!-- 剩余抽奖次数和积分 -->
  13. <view class="tips">
  14. <view>今日剩余抽奖机会:{{ hasLotteryCount }}</view>
  15. <view>可用积分:{{ maySignPoint }}</view>
  16. </view>
  17. <!-- 活动规则 -->
  18. <view class="rules">
  19. <view class="title">活动规则</view>
  20. <view v-for="(item, index) in rule" :key="index">{{ item }}</view>
  21. </view>
  22. <!-- 弹窗 -->
  23. <uni-popup ref="popup" type="center">
  24. <view v-if="this.hasLotteryCount <= 0" class="popup" style="justify-content: space-around">
  25. <view>
  26. <view>很遗憾!</view>
  27. <view>今日抽奖次数已用光</view>
  28. </view>
  29. <img src="../../static/lottery/noChance.png" />
  30. </view>
  31. <view v-else class="popup">
  32. <view>{{ form.resultGoodName }}</view>
  33. <img :src="form.resultGoodPic" />
  34. <button v-if="form.resultGoodType === 4" @click="getSubmit">领取</button>
  35. <button v-if="form.resultGoodType === 5" @click="getAgain">再抽一次</button>
  36. <button v-if="form.resultGoodType === 3" @click="getDetail">填写收货信息</button>
  37. </view>
  38. </uni-popup>
  39. </view>
  40. </template>
  41. <script>
  42. import { page, result, receive } from '@/api/lottery.js'
  43. import LuckyWheel from '@lucky-canvas/uni/lucky-wheel'
  44. export default {
  45. components: {
  46. LuckyWheel
  47. },
  48. data() {
  49. return {
  50. // 状态栏
  51. statusBarHeight: getApp().globalData.statusBarHeight,
  52. // 转盘
  53. prizes: [],
  54. buttons: [{
  55. radius: '45%',
  56. background: '#ffffff40',
  57. imgs: [{
  58. src: '../../static/lottery/btn.png',
  59. top: '-75px',
  60. width: '96px',
  61. height: '124px'
  62. }]
  63. }],
  64. defaultStyle: {
  65. fontSize: '26rpx'
  66. },
  67. // 可用积分
  68. maySignPoint: 0,
  69. // 每次消耗积分
  70. lotteryConsumePoint: 0,
  71. // 今日剩余抽奖机会
  72. hasLotteryCount: 0,
  73. // 活动规则
  74. rule: '',
  75. // 表单
  76. form: {},
  77. // 防止连点
  78. disabled: true
  79. }
  80. },
  81. onLoad() {
  82. this.getList()
  83. },
  84. methods: {
  85. // 获取页面信息
  86. getList() {
  87. this.prizes = []
  88. page(getApp().globalData.userInfo).then(res => {
  89. if (res.data.code === 0) {
  90. const j = res.data.data
  91. // 可用积分
  92. this.maySignPoint = j.maySignPoint
  93. // 每次消耗积分
  94. this.lotteryConsumePoint = j.lotteryConsumePoint
  95. // 今日剩余抽奖机会
  96. this.hasLotteryCount = j.hasLotteryCount
  97. // 奖品列表
  98. j.userLotteryDatas.map(i => {
  99. this.prizes.push({
  100. background: i.sort % 2 === 0 ? '#fff7a6' : '#9cc6a5',
  101. fonts: [{
  102. text: i.name,
  103. fontColor: i.sort % 2 === 0 ? '#ff8831' : '#fff',
  104. top: '10%'
  105. }],
  106. imgs: [{
  107. src: i.pic,
  108. top: '30%',
  109. width: '108rpx',
  110. height: '108rpx'
  111. }]
  112. })
  113. })
  114. // 活动规则
  115. this.rule = j.rule.split('\n')
  116. }
  117. })
  118. },
  119. close() {
  120. closePage.postMessage('关闭页面')
  121. },
  122. // 点击抽奖按钮触发回调
  123. startCallBack() {
  124. if (this.hasLotteryCount > 0) {
  125. if (this.maySignPoint >= this.lotteryConsumePoint) {
  126. if (this.disabled) {
  127. this.$refs.lucky.play()
  128. this.disabled = false
  129. result(getApp().globalData.userInfo).then(res => {
  130. if (res.data.code === 0) {
  131. setTimeout(() => {
  132. this.$refs.lucky.stop(res.data.data.resultGoodSort - 1)
  133. this.form = res.data.data
  134. }, 3000)
  135. } else {
  136. this.$refs.lucky.stop()
  137. uni.showToast({
  138. icon: 'error',
  139. title: res.data.message
  140. })
  141. }
  142. })
  143. }
  144. } else {
  145. uni.showToast({
  146. icon: 'error',
  147. title: '可用积分不足'
  148. })
  149. }
  150. } else {
  151. this.$refs.popup.open()
  152. }
  153. },
  154. // 抽奖结束触发回调
  155. endCallBack() {
  156. this.$nextTick(() => {
  157. this.$refs.popup.open()
  158. this.disabled = true
  159. this.getList()
  160. })
  161. },
  162. // 再抽一次
  163. getAgain() {
  164. this.$refs.popup.close()
  165. this.startCallBack()
  166. },
  167. // 领取
  168. getSubmit() {
  169. if (this.disabled) {
  170. this.disabled = false
  171. receive(getApp().globalData.userInfo, {
  172. prizeId: this.form.resultGoodId,
  173. lotteryCode: this.form.lotteryCode
  174. }).then(res => {
  175. if (res.data.code === 0) {
  176. this.$refs.popup.close()
  177. uni.showToast({
  178. title: '领取成功!'
  179. })
  180. this.getList()
  181. setTimeout(() => {
  182. this.disabled = true
  183. }, 2000)
  184. }
  185. })
  186. }
  187. },
  188. // 填写收货信息
  189. getDetail() {
  190. uni.redirectTo({
  191. url: `/pages/lottery/detail?prizeId=${this.form.resultGoodId}&lotteryCode=` + encodeURIComponent(this.form.lotteryCode)
  192. })
  193. }
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. .app-container {
  199. position: relative;
  200. background: url('@/static/lottery/bg.png');
  201. background-size: cover;
  202. background-repeat: no-repeat;
  203. width: 100%;
  204. height: 1880rpx;
  205. padding: 0 32rpx 32rpx;
  206. .nav {
  207. height: 88rpx;
  208. display: flex;
  209. align-items: center;
  210. color: #333333;
  211. font-weight: bold;
  212. font-size: 36rpx;
  213. position: relative;
  214. box-sizing: content-box;
  215. .title {
  216. position: absolute;
  217. left: 50%;
  218. transform: translate(-50%);
  219. }
  220. }
  221. .every {
  222. position: absolute;
  223. left: 50%;
  224. top: 380rpx;
  225. transform: translate(-50%);
  226. color: #1a5509;
  227. font-weight: bold;
  228. }
  229. .lucky {
  230. position: absolute;
  231. top: 496rpx;
  232. left: 50%;
  233. transform: translate(-50%);
  234. }
  235. .tips {
  236. position: absolute;
  237. top: 62%;
  238. left: 50%;
  239. transform: translate(-50%);
  240. text-align: center;
  241. line-height: 50rpx;
  242. }
  243. .rules {
  244. width: 100%;
  245. position: absolute;
  246. left: 0;
  247. bottom: 40rpx;
  248. color: #192b24;
  249. padding: 0 64rpx;
  250. font-size: 28rpx;
  251. font-weight: bold;
  252. .title {
  253. font-weight: bold;
  254. font-size: 38rpx;
  255. text-align: center;
  256. margin-bottom: 32rpx;
  257. }
  258. view {
  259. margin-bottom: 20rpx;
  260. }
  261. }
  262. .popup {
  263. width: 576rpx;
  264. height: 600rpx;
  265. background: #fff;
  266. border-radius: 32rpx;
  267. color: #000;
  268. font-weight: bold;
  269. text-align: center;
  270. padding: 48rpx 0;
  271. display: flex;
  272. flex-direction: column;
  273. justify-content: space-between;
  274. align-items: center;
  275. img {
  276. width: 328rpx;
  277. height: 236rpx;
  278. }
  279. button {
  280. background: linear-gradient(180deg, #72cdae 0%, #599f82 100%);
  281. color: #fff;
  282. width: 320rpx;
  283. height: 80rpx;
  284. line-height: 80rpx;
  285. border-radius: 50rpx;
  286. font-size: 32rpx;
  287. }
  288. }
  289. }
  290. </style>