index.vue 7.6 KB

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