index.vue 7.7 KB

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