index.vue 12 KB

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