index.vue 7.6 KB

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