index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <view class="">
  3. <view class="lottery" v-if="lotteryShow && loading">
  4. <image class="lottery-header" :src="image" mode=""></image>
  5. <view class="grids">
  6. <image class="grids-bag" src="../../static/lottery-bag.png" mode=""></image>
  7. <view class="grids-top">
  8. <image src="../../static/font-left.png" mode=""></image>
  9. <view class="grids-title">
  10. <view>获得</view>
  11. <view class="grids-frequency">{{lottery_num}}次</view>
  12. <view>抽奖机会</view>
  13. </view>
  14. <image src="../../static/font-right.png" mode=""></image>
  15. </view>
  16. <view class="winning-tips-list" v-if="userList.data.length">
  17. <text class="iconfont icon-huabanfuben"></text>
  18. <noticeBar :showMsg="userList.data"></noticeBar>
  19. </view>
  20. <view class="grids-box">
  21. <gridsLottery class="" :prizeData="prize" @get_winingIndex='getWiningIndex'
  22. @luck_draw_finish='luck_draw_finish'>
  23. </gridsLottery>
  24. </view>
  25. </view>
  26. <!-- #ifdef H5 -->
  27. <view class="invite-people" v-if="factor == 5" @click="H5ShareBox=true">
  28. <view class="invite">
  29. 邀请好友
  30. </view>
  31. </view>
  32. <!-- #endif -->
  33. <showBox v-if="userList.data.length && is_all_record" :showMsg="userList"></showBox>
  34. <showBox v-if="htmlData.data && is_content" :showMsg="htmlData"></showBox>
  35. <showBox v-if="myList.data.length && is_personal_record" :showMsg="myList"></showBox>
  36. <lotteryAleart :aleartStatus="aleartStatus" @close="closeLottery" :alData="alData" :aleartType="aleartType">
  37. </lotteryAleart>
  38. <view class="mask" v-if="aleartStatus || addressModel" @click="lotteryAleartClose"></view>
  39. <userAddress :aleartStatus="addressModel" @getAddress="getAddress" @close="()=>{addressModel = false}">
  40. </userAddress>
  41. <!-- #ifdef H5 -->
  42. <!-- 分享-->
  43. <view class="share-box" v-if="H5ShareBox">
  44. <image :src="imgHost + '/statics/images/share-info.png'" @click="H5ShareBox = false"></image>
  45. </view>
  46. <!-- #endif -->
  47. <!-- #ifdef H5 -->
  48. <view class="followCode" v-if="followCode">
  49. <view class="pictrue">
  50. <view class="code-bg"><img class="imgs" :src="codeSrc" /></view>
  51. </view>
  52. <view class="mask" @click="closeFollowCode"></view>
  53. </view>
  54. <zb-code ref="qrcode" v-show="false" :show="codeShow" :cid="cid" :val="val" :onval="onval"
  55. :loadMake="loadMake" @result="qrR" />
  56. <!-- #endif -->
  57. </view>
  58. <view class="no-lottery" v-else-if="!lotteryShow && loading">
  59. <image :src="imgHost + '/statics/images/no-thing.png'" mode=""></image>
  60. <text>商家暂未上架活动哦~</text>
  61. </view>
  62. <home v-if="navigation"></home>
  63. </view>
  64. </template>
  65. <script>
  66. import {
  67. getLotteryData,
  68. startLottery,
  69. receiveLottery
  70. } from '@/api/lottery.js'
  71. import {
  72. getUserInfo
  73. } from '@/api/user.js';
  74. import colors from '@/mixins/color.js'
  75. import zbCode from '@/components/zb-code/zb-code.vue'
  76. import gridsLottery from '../../components/lottery/index.vue'
  77. import showBox from '../components/showbox.vue'
  78. import noticeBar from '../components/noticeBar.vue'
  79. import lotteryAleart from '../../components/lotteryAleart/index.vue'
  80. import userAddress from '../../components/userAddress/index.vue'
  81. import home from '@/components/home';
  82. import {
  83. toLogin
  84. } from '@/libs/login.js';
  85. import {
  86. mapGetters
  87. } from "vuex";
  88. import {HTTP_REQUEST_URL} from '@/config/app';
  89. const app = getApp();
  90. export default {
  91. components: {
  92. gridsLottery,
  93. showBox,
  94. noticeBar,
  95. lotteryAleart,
  96. userAddress,
  97. zbCode,
  98. home
  99. },
  100. mixins:[colors],
  101. data() {
  102. return {
  103. lotteryShow: true,
  104. loading: false,
  105. H5ShareBox: false,
  106. // #ifdef H5
  107. isWeixin: this.$wechat.isWeixin(),
  108. // #endif
  109. addressModel: false,
  110. lottery_num: 0,
  111. aleartType: 0,
  112. aleartStatus: false,
  113. lottery_draw_param: {
  114. startIndex: 3, //开始抽奖位置,从0开始
  115. totalCount: 3, //一共要转的圈数
  116. winingIndex: 1, //中奖的位置,从0开始
  117. speed: 100 //抽奖动画的速度 [数字越大越慢,默认100]
  118. },
  119. userList: {
  120. type: 'user',
  121. data: []
  122. },
  123. myList: {
  124. type: 'me',
  125. data: []
  126. },
  127. htmlData: {
  128. type: 'html',
  129. data: ''
  130. },
  131. prize: [],
  132. factor_num: 0,
  133. id: 0,
  134. alData: {},
  135. type: '',
  136. followCode: false,
  137. //二维码参数
  138. codeShow: false,
  139. cid: '1',
  140. ifShow: true,
  141. val: "", // 要生成的二维码值
  142. lv: 3, // 二维码容错级别 , 一般不用设置,默认就行
  143. onval: true, // val值变化时自动重新生成二维码
  144. loadMake: true, // 组件加载完成后自动生成二维码
  145. src: '', // 二维码生成后的图片地址或base64
  146. codeSrc: "",
  147. image: "", //上部背景图
  148. is_content: 0,
  149. is_all_record: 0,
  150. is_personal_record: 0,
  151. factor: 0,
  152. imgHost:HTTP_REQUEST_URL,
  153. }
  154. },
  155. computed: mapGetters(['isLogin']),
  156. watch: {
  157. isLogin: {
  158. handler: function(newV, oldV) {
  159. if (newV) {
  160. this.getLotteryData(this.type)
  161. }
  162. },
  163. deep: true
  164. }
  165. },
  166. onLoad(option) {
  167. this.type = option.type;
  168. if (this.isLogin) {
  169. this.getLotteryData(this.type)
  170. } else {
  171. toLogin();
  172. }
  173. },
  174. onShow(){
  175. uni.removeStorageSync('form_type_cart');
  176. },
  177. methods: {
  178. //#ifdef H5
  179. ShareInfo(data) {
  180. let href = location.href;
  181. if (this.$wechat.isWeixin()) {
  182. getUserInfo().then(res => {
  183. href = href.indexOf('?') === -1 ? href + '?spread=' + res.data.uid : href + '&spread=' +
  184. res.data.uid;
  185. let configAppMessage = {
  186. desc: data.name,
  187. title: data.name,
  188. link: href,
  189. imgUrl: data.image
  190. };
  191. this.$wechat
  192. .wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData',
  193. 'onMenuShareAppMessage',
  194. 'onMenuShareTimeline'
  195. ], configAppMessage)
  196. .then(res => {})
  197. .catch(err => {});
  198. });
  199. }
  200. },
  201. //#endif
  202. getLotteryData(type) {
  203. uni.showLoading({
  204. title: '获取抽奖信息'
  205. });
  206. getLotteryData(type).then(res => {
  207. this.loading = true
  208. this.factor_num = res.data.lottery.factor_num
  209. this.id = res.data.lottery.id
  210. this.image = res.data.lottery.image
  211. this.prize = res.data.lottery.prize
  212. this.lottery_num = res.data.lottery_num
  213. this.htmlData.data = res.data.lottery.content
  214. this.is_content = res.data.lottery.is_content
  215. this.is_personal_record = res.data.lottery.is_personal_record
  216. this.is_all_record = res.data.lottery.is_all_record
  217. this.factor = res.data.lottery.factor
  218. this.userList.data = res.data.all_record
  219. this.myList.data = res.data.user_record
  220. this.prize.push({})
  221. // #ifdef H5
  222. if (this.isLogin) {
  223. this.ShareInfo(res.data.lottery);
  224. }
  225. // #endif
  226. uni.hideLoading();
  227. }).catch(err => {
  228. uni.hideLoading();
  229. this.lotteryShow = false
  230. this.loading = true
  231. this.$util.Tips({
  232. title: err
  233. });
  234. })
  235. },
  236. closeLottery(status) {
  237. this.aleartStatus = false
  238. this.getLotteryData(this.type)
  239. if (this.alData.type === 6) {
  240. this.addressModel = true
  241. }
  242. },
  243. getAddress(data) {
  244. let addData = data
  245. addData.id = this.alData.lottery_record_id
  246. addData.address = data.address.province + data.address.city + data.address.district + data.detail
  247. receiveLottery(addData).then(res => {
  248. this.$util.Tips({
  249. title: '领取成功'
  250. });
  251. this.addressModel = false
  252. }).catch(err => {
  253. this.$util.Tips({
  254. title: err
  255. });
  256. })
  257. },
  258. getWiningIndex(callback) {
  259. this.aleartType = 0
  260. let that = this
  261. startLottery({
  262. id: this.id,
  263. type: this.type
  264. }).then(res => {
  265. if (res.data.code === 'subscribe') {
  266. that.$set(that, 'followCode', true);
  267. this.codeSrc = res.data.url
  268. return;
  269. }
  270. this.prize.forEach((item, index) => {
  271. if (res.data.id === item.id) {
  272. this.alData = res.data
  273. this.lottery_draw_param.winingIndex = index;
  274. callback(this.lottery_draw_param);
  275. }
  276. })
  277. }).catch(err => {
  278. this.$util.Tips({
  279. title: err
  280. });
  281. })
  282. // //props修改在小程序和APP端不成功,所以在这里使用回调函数传参,
  283. },
  284. // 抽奖完成
  285. luck_draw_finish(param) {
  286. this.aleartType = 2
  287. this.aleartStatus = true
  288. // console.log(`抽到第${param+1}个方格的奖品`)
  289. },
  290. qrR(res) {
  291. this.codeSrc = res
  292. },
  293. }
  294. }
  295. </script>
  296. <style lang="scss" scoped>
  297. page{
  298. background-color: #E74435;
  299. }
  300. .lottery {
  301. background-color: #E74435;
  302. min-height: 100vh;
  303. padding: 0 0 20rpx 0;
  304. .lottery-header {
  305. width: 100%;
  306. height: 580rpx;
  307. margin: 0;
  308. }
  309. .grids {
  310. width: 100%;
  311. height: 800rpx;
  312. display: flex;
  313. flex-direction: column;
  314. justify-content: center;
  315. align-items: center;
  316. margin-top: -200rpx;
  317. position: relative;
  318. padding: 30rpx;
  319. .grids-bag {
  320. position: absolute;
  321. top: 0;
  322. left: 0;
  323. width: 100%;
  324. height: 100%;
  325. }
  326. .grids-box {
  327. width: 560rpx;
  328. height: 560rpx;
  329. // z-index: 10000;
  330. }
  331. .grids-top {
  332. display: flex;
  333. image {
  334. width: 40rpx;
  335. height: 40rpx;
  336. }
  337. .grids-title {
  338. display: flex;
  339. justify-content: center;
  340. width: 100%;
  341. font-size: 20px;
  342. color: #fff;
  343. z-index: 999;
  344. padding: 0 14rpx;
  345. .grids-frequency {
  346. color: #FFD68E;
  347. }
  348. }
  349. }
  350. .winning-tips-list {
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. width: 50%;
  355. font-size: 20rpx;
  356. line-height: 40rpx;
  357. height: 40rpx;
  358. font-weight: 400;
  359. color: #FFF8F8;
  360. margin: 20rpx 0;
  361. z-index: 999;
  362. background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.3) 51%, rgba(255, 255, 255, 0) 100%);
  363. .iconfont {
  364. font-size: 20rpx;
  365. margin-right: 10rpx;
  366. }
  367. }
  368. }
  369. .invite-people {
  370. display: flex;
  371. justify-content: center;
  372. .invite {
  373. display: flex;
  374. justify-content: center;
  375. align-items: center;
  376. width: 558rpx;
  377. height: 76rpx;
  378. font-size: 32rpx;
  379. font-weight: 600;
  380. color: #E74435;
  381. background: #FFD68E;
  382. box-shadow: 0px 6px 0px 0px rgba(185, 16, 0, 0.3);
  383. border-radius: 38px;
  384. margin: 76rpx;
  385. }
  386. }
  387. }
  388. .mask {
  389. position: fixed;
  390. top: 0;
  391. left: 0;
  392. right: 0;
  393. bottom: 0;
  394. background-color: rgba(0, 0, 0, 0.8);
  395. z-index: 9;
  396. }
  397. .share-box {
  398. z-index: 1300;
  399. position: fixed;
  400. left: 0;
  401. top: 0;
  402. width: 100%;
  403. height: 100%;
  404. image {
  405. width: 100%;
  406. height: 100%;
  407. }
  408. }
  409. .followCode {
  410. .pictrue {
  411. width: 500rpx;
  412. height: 530rpx;
  413. border-radius: 12px;
  414. left: 50%;
  415. top: 50%;
  416. margin-left: -250rpx;
  417. margin-top: -360rpx;
  418. position: fixed;
  419. z-index: 10000;
  420. .code-bg {
  421. display: flex;
  422. justify-content: center;
  423. width: 100%;
  424. height: 100%;
  425. background-image: url('~@/static/images/code-bg.png');
  426. background-size: 100% 100%;
  427. }
  428. .imgs {
  429. width: 310rpx;
  430. height: 310rpx;
  431. margin-top: 92rpx;
  432. }
  433. }
  434. .mask {
  435. z-index: 9999;
  436. }
  437. }
  438. .no-lottery {
  439. display: flex;
  440. justify-content: center;
  441. flex-direction: column;
  442. align-items: center;
  443. font-size: 28rpx;
  444. color: #ccc;
  445. }
  446. [v-cloak] {
  447. display: none;
  448. }
  449. </style>