index.vue 7.9 KB

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