刮刮前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

479 lines
11 KiB

<template>
<view class="prizePage" :style="{'background-image':`url('${ticketInfo.bg_image}')`}">
<!-- <view class="bg" :style="{'background-image':`url('${ticketInfo.bg_image}')`}" v-if="gai"></view> -->
<view class="scratch">
<view class="box">
<!-- 刮奖结果图片 -->
<view :class="toDraw?'zIndex1':''" style="" class="result_img">
<view v-for="(item,index) in dataList" :key="index" class="img_row">
<view v-for="(lineItem, lineIndex) in item" :key="lineIndex" class="data_item">
<image :src="lineItem.image" mode=""></image>
<view class="">¥{{lineItem.amount}}</view>
</view>
</view>
</view>
<!-- 刮奖canvas容器 -->
<canvas v-if="!isWin && !isThank"
class="canvas-box"
canvas-id="guagua"
:disable-scroll="true"
@touchstart="touchStart"
@touchmove="touchMove"
@touchend="touchEnd"
></canvas>
<!-- 刮奖前提示消息,开始刮奖后隐藏 -->
<cover-view class="tip" v-if="!toDraw">
<!-- 开始刮奖按钮 -->
<cover-view class="btn" @tap="scratchStart()">
<cover-view class="text">立即刮奖</cover-view>
</cover-view>
</cover-view>
</view>
</view>
<view class="mask" v-if="showResult">
</view>
<view class="winPrize" v-if="isWin">
{{awards_amount}}元
<cover-view class="again" @click="again"></cover-view>
<view class="close" @click="close(1)"></view>
</view>
<view class="noPrize_box" v-if="isThank">
<cover-view class="noPrize" v-if="isThank"></cover-view>
<cover-view class="again" v-if="isThank"></cover-view>
<cover-view class="again_mask" @click="again" v-if="isThank"></cover-view>
<cover-view class="close" @click="close(2)" v-if="isThank"></cover-view>
</view>
</view>
</template>
<script>
import API from '@/common/js/api.js'
import Scratch from './scratch.js'
// import VConsole from './renderjs.js'
export default {
data () {
return {
id: '',
ticketInfo: {
bg_image: '../../static/home/4.jpg',
// bg_image: '',
price: '20',
content: `刮开覆盖膜,如果出现背书标志“1倍”、“2倍”、“5倍”、“10倍”、“20倍”、
“50倍”、“100倍”,既中得该标志下方所示的金额乘以该倍数;
如果在“全中”区出现标志“赢”,即中图刮开区内所示的20个金额之和。`
},
awards_amount: '20',
dataList: [
[
{image: '',amount:'100.00'},
{image: '',amount:'100.00'},
{image: '',amount:'100.00'}
],
[
{image: '',amount:'100.00'},
{image: '',amount:'100.00'},
{image: '',amount:'100.00'},
{image: '',amount:'100.00'}
],
[
{image: '',amount:'100.00'},
{image: '',amount:'100.00'},
{image: '',amount:'100.00'}
],
],
// dataList: [],
toDraw: false, // 是否开始刮奖
showResult: false, // 是否显示抽奖结果
isWin: false, // 是否中奖
scratchWidth: 330, // 绘制刮奖范围宽
scratchHeight: 250, // 绘制刮奖范围高
scratchSize: 10, // 触手大小
scratchScale: 0.6, // 需刮开百分比
prize_img: '', // 中奖图片
isScratching: false, // 是否正在刮奖,
isThank: false,
guaCanvas: null,
isShow: false,
c_r_id: '',
gai: true,
}
},
updated() {
// console.log(this.show);
},
watch: {
isShow(n, o){
console.log(n,o);
if(n && n!=o){
this.showResult = true;
this.gai = false;
this.doPrizeScratchTicketFun();
}
}
},
onLoad(e) {
uni.setNavigationBarTitle({
title: e.type,
// +'元专区'
})
this.id = e.id;
this.initInfo();
},
methods: {
initInfo(){
API.request('/zone/beginInitInfo', {zone_goods_id: this.id}, res=>{
this.ticketInfo = res.data.data;
})
let timer = setInterval(()=>{
if(this.guaCanvas && this.guaCanvas.show){
this.isShow = true;
clearInterval(timer);
}
}, 500)
},
initCanvas () {
// 刮奖初始化信息必须在onReady后,不然h5不支持(小程序可在onLoad执行)
this.guaCanvas = new Scratch(this, {
canvasId: 'guagua',
width: this.scratchWidth,
height: this.scratchHeight,
size: this.scratchSize,
scale: this.scratchScale,
bgImg: this.ticketInfo.bg_image
})
},
// 开始刮奖获取信息
beginLottery(){
API.beginLottery({zone_goods_id: this.id}, res=>{
this.c_r_id = res.data.c_r_id;
this.toDraw = true;
this.initCanvas();
this.dataList = res.data.list;
// console.log(this.dataList, 'dataList----');
})
},
// 请求刮奖结果
doPrizeScratchTicketFun () {
// this.isWin = true;
// this.isThank = true;
uni.showLoading({
title: '加载中'
})
API.endLottery({c_r_id: this.c_r_id}, res=>{
uni.hideLoading();
if(res.data.awards_amount){
this.awards_amount = res.data.awards_amount;
this.isWin = true;
this.guaCanvas = null;
}else{
this.isWin = false
this.isThank = true;
this.guaCanvas = null;
}
}, fail=>{
// this.isScratching = false
uni.hideLoading();
})
},
// 点击按钮开始刮奖
scratchStart () {
this.beginLottery()
},
// 再刮一次
again(){
this.isWin = false;
this.isThank = false;
this.toDraw = false;
this.showResult = false;
this.gai = true;
this.isScratching = false;
this.isShow = false;
// this.guaCanvas.show = false;
this.initInfo();
},
close(type){
if(type===1){
this.isWin = false;
}
if(type===2){
this.isThank = false;
}
this.showResult = false;
}
},
}
</script>
<style lang="scss">
.prizePage{
width: 750rpx;
min-height: calc(100vh - 88rpx - var(--status-bar-height));
background-repeat: no-repeat;
background-size: contain;
background-color: #fff;
// background-size: auto 100%;
// background-color: #fff;
// height: 590px;
// background-position: center top;
}
.bg{
position: fixed;
z-index: 2;
width: 750rpx;
min-height: calc(100vh - 88rpx - var(--status-bar-height));
background-repeat: no-repeat;
background-size: contain;
background-color: #fff;
}
.result_img {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
background-color: #dddddd;
display: flex;
flex-direction: column;
justify-content: space-around;
.img_row{
display: flex;
flex-wrap: wrap;
align-content: space-around;
}
&.zIndex1{
z-index: 1;
}
.data_item{
width: 25%;
text-align: center;
font-size: 14px;
font-weight: bold;
image{
width: 80rpx;
height: 60rpx;
// background-color: #000;
}
}
}
.scratch {
position: relative;
padding-top: 600rpx;
// padding-top: 280px;
width: 660rpx;
height: 500rpx;
margin: 0px auto;
.box {
width: 100%;
height: 100%;
background: transparent;
// border-radius: 20rpx;
position: relative;
overflow: hidden;
.canvas-box {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
// border-radius: 20rpx;
overflow: hidden;
z-index: 2;
}
.tip {
position: absolute;
left: 0;
right: 0;
width: 100%;
height: 100%;
z-index: 999;
text-align: center;
.text {
font-size: 30rpx;
font-weight: bold;
color: #444;
margin-top: 69rpx;
.text-tip {
display: inline-block;
vertical-align: middle;
}
.light {
// color: $red;
display: inline-block;
vertical-align: middle;
margin: 0 6rpx !important;
}
}
.btn {
width: 400rpx;
height: 88rpx;
border: none;
border-radius: 20rpx;
margin: 245rpx auto 0;
position: relative;
background: #E33838;
.text {
display: inline;
position: absolute;
text-align: center;
color: #fff;
font-size: 30rpx;
font-weight: bold;
margin: 0;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 1;
}
}
}
.award-box {
width: 100%;
height: 100%;
border-radius: 20rpx;
text-align: center;
line-height: 270rpx;
background: #FFF1B9;
.text {
font-size: 40rpx;
font-weight: bold;
color: #444;
}
}
}
}
.mask{
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.2);
position: fixed;
top: 0px;
left: 0px;
z-index: 2;
}
.winPrize{
width: 375px;
height: 575px;
background-image: url("../../static/home/prize.png");
background-size: contain;
position: fixed;
top: 50%;
left: 50%;
z-index: 30;
transform: translate(-50%, -50%);
text-align: center;
line-height: 550px;
color: #FFF1B9;
font-weight: bold;
font-size: 60px;
animation: showPrize 1s ease-in-out;
.again{
width: 300rpx;height: 200rpx;
position: absolute;left: 225rpx;top: 630rpx;
z-index: 31;
// background: rgba(0, 0, 0, 0.5);
}
.close{
width: 50px;
height: 50px;
background-image: url("../../static/home/close.png");
background-size: contain;
position: fixed;
left: 50%;
transform: translate(-50%, -50%);
z-index: 32;
}
}
.noPrize_box{
width: 100vw;
height: 100vh;
position: fixed;
top: 0px;
left: 0px;
text-align: center;
z-index: 30;
.noPrize{
width: 550rpx;
height: 550rpx;
background-image: url("../../static/home/noPrize.png");
background-size: contain;
background-repeat: no-repeat;
position: absolute;
top: 400rpx;
left: 100rpx;
z-index: 31;
text-align: center;
font-size: 14px;
animation: showNoPrize 1s ease-in-out;
}
.again{
width: 240rpx;
height: 66rpx;
line-height: 66rpx;
border-radius: 20px;
position: absolute;
left: 255rpx;
top: 650rpx;
color: #F05859;
background-image: url("../../static/home/btn_11.png");
background-size: 100% 100%;
z-index: 32;
animation: showNoPrize 1s ease-in-out;
}
.again_mask{
width: 340rpx;
height: 150rpx;
position: absolute;
left: 205rpx;
top: 610rpx;
z-index: 33;
// background: rgba(0, 0, 0, 0.5);
}
.close{
width: 100rpx;
height: 200rpx;
background-image: url("../../static/home/close.png");
background-size: contain;
position: absolute;
left: 325rpx;
top: 770rpx;
z-index: 32;
animation: showNoPrize 1s ease-in-out;
// background-color: rgba(255, 0, 0, 0.5);
background-repeat: no-repeat;
background-position: bottom;
}
}
@keyframes showPrize {
0%{
transform: translate(-50%, -50%) scale(0.4);
}
100%{
transform: translate(-50%, -50%) scale(1);
}
}
@keyframes showNoPrize {
0%{
transform: scale(0.4);
}
100%{
transform: scale(1);
}
}
</style>