index.vue 11 KB

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