index.vue 11 KB

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