index.vue 7.4 KB

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