Commit 926f9624 authored by ziyu's avatar ziyu

improvement: 接口

parent 101ca0a1
...@@ -27,5 +27,23 @@ module.exports = { ...@@ -27,5 +27,23 @@ module.exports = {
}, },
getPrizeList(params) { getPrizeList(params) {
return http.post('/api/prize/list', params, { 'content-type': 'application/json' }); return http.post('/api/prize/list', params, { 'content-type': 'application/json' });
},
getRaffles() {
return http.post('/api/user/join/list');
},
getOneRaffle(params) {
return http.post('/api/user/join/list',params);
},
getUserPhone() {
return http.post('/api/user/get/phone');
},
confirmRaffle(params) {
return http.post('/api/user/join/confirm',params);
},
updateUserPhone(params) {
return http.post('/api/user/update/phone',params);
},
getPrize(params){
return http.post('/api/user/price/receive',params);
} }
}; };
...@@ -12,7 +12,6 @@ const request = async (url, options) => { ...@@ -12,7 +12,6 @@ const request = async (url, options) => {
url = baseUrl + url; url = baseUrl + url;
const isConnected = wx.getStorageSync('onNetworkStatusChange'); const isConnected = wx.getStorageSync('onNetworkStatusChange');
console.log('isConnected', isConnected);
if (!isConnected) { if (!isConnected) {
wx.showToast({ wx.showToast({
title: '无网络', title: '无网络',
...@@ -32,6 +31,7 @@ const request = async (url, options) => { ...@@ -32,6 +31,7 @@ const request = async (url, options) => {
if (res.data.code === 2000) { if (res.data.code === 2000) {
return res.data.data; return res.data.data;
} }
} }
Notify({ message: res.data.detail || '请求异常,请稍后重试', background: '#FF5D15', safeAreaInsetTop: true }); Notify({ message: res.data.detail || '请求异常,请稍后重试', background: '#FF5D15', safeAreaInsetTop: true });
}).catch(res => { }).catch(res => {
......
...@@ -194,7 +194,7 @@ ...@@ -194,7 +194,7 @@
</swiper> </swiper>
</view> </view>
</view> </view>
<view class="footer"> <!--<view class="footer">
<swiper <swiper
class="footswiper" class="footswiper"
display-multiple-items="{{swiperItem}}" display-multiple-items="{{swiperItem}}"
...@@ -206,8 +206,8 @@ ...@@ -206,8 +206,8 @@
next-margin="120rpx" next-margin="120rpx"
catch:touchmove catch:touchmove
> >
<!--bindtouchstart="touchStart"--> bindtouchstart="touchStart"
<!--bindtouchend="touchEnd"--> bindtouchend="touchEnd"
<swiper-item wx:for="{{list}}" wx:key="index"> <swiper-item wx:for="{{list}}" wx:key="index">
<view <view
data-itemid="{{index}}" data-itemid="{{index}}"
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</view> </view>
</swiper-item> </swiper-item>
</swiper> </swiper>
</view> </view>-->
<view class="authmodal" v-show="authmodal"> <view class="authmodal" v-show="authmodal">
<view class="wrap"> <view class="wrap">
<view class="text">来到lukii,再平凡的人,<br>也有幸运的权利!</view> <view class="text">来到lukii,再平凡的人,<br>也有幸运的权利!</view>
...@@ -533,7 +533,7 @@ ...@@ -533,7 +533,7 @@
}, },
getAwards: function() { getAwards: function() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/raffle?id=1&progress=70&chance=1/780&corn=50000&imgsrc=/static/images/test2.png&goods=Nintendo Switch任天堂游戏机任天堂游戏机' url: '/pages/raffle?batchId=1&progress=70&chance=1/780&quantity=50000&photoUrl=/static/images/test2.png&name=Nintendo Switch任天堂游戏机任天堂游戏机'
}); });
// this.awards = !this.awards; // this.awards = !this.awards;
}, },
......
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
.item-corn{ .item-corn{
color:#FF5D15; color:#FF5D15;
font-size: 28rpx; font-size: 28rpx;
margin-top: 45rpx; position: absolute;
bottom:30rpx;
} }
.item-status { .item-status {
position: absolute; position: absolute;
...@@ -86,7 +87,7 @@ ...@@ -86,7 +87,7 @@
<view class="item-corn">花费: {{item.quantity}}克币</view> <view class="item-corn">花费: {{item.quantity}}克币</view>
<view class="item-status"> <view class="item-status">
<button data-id="{{item.id}}" class="item-button" bindtap="goprize" v-if="item.status.value==3">领取</button> <button data-id="{{item.id}}" class="item-button" bindtap="goprize" v-if="item.status.value==3">领取</button>
<text class="{{prize.computClass(item.status)}}" v-else>{{item.status.name}}</text> <text class="{{prize.computClass(item.status)}}" v-else>{{fonts[item.status.value]}}</text>
</view> </view>
</view> </view>
</view> </view>
...@@ -94,9 +95,11 @@ ...@@ -94,9 +95,11 @@
</template> </template>
<script> <script>
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import { getRaffles } from '../common/api'
wepy.page({ wepy.page({
data: { data: {
list:[] list:[],
fonts:['','待开奖','未中奖','待领取','未发货','已发货'],
}, },
methods: { methods: {
goprize(event) { goprize(event) {
...@@ -106,13 +109,9 @@ ...@@ -106,13 +109,9 @@
} }
}, },
onLoad () { onLoad () {
this.list = [ getRaffles().then(res=>{
{id:1,status:{name:'待开奖',value:1},quantity:500,prize:{name:'Nintendo Switch任天堂游戏机任天堂游戏机',photoUrl:'/static/images/test1.jpg'}}, this.list = res || [];
{id:2,status:{name:'未中奖',value:2},quantity:200,prize:{name:'Nintendo Switch任天堂游戏机任天堂游戏机',photoUrl:'/static/images/test1.jpg'}}, });
{id:3,status:{name:'待领取',value:3},quantity:300,prize:{name:'Nintendo Switch任天堂游戏机任天堂游戏机',photoUrl:'/static/images/test1.jpg'}},
{id:4,status:{name:'未发货',value:4},quantity:400,prize:{name:'Nintendo Switch任天堂游戏机任天堂游戏机',photoUrl:'/static/images/test1.jpg'}},
{id:5,status:{name:'已发货',value:5},quantity:500,prize:{name:'Nintendo Switch任天堂游戏机任天堂游戏机',photoUrl:'/static/images/test1.jpg'}},
];
}, },
}); });
</script> </script>
......
...@@ -98,6 +98,7 @@ ...@@ -98,6 +98,7 @@
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import Dialog from '../components/vant/dialog/dialog'; import Dialog from '../components/vant/dialog/dialog';
import Notify from '../components/vant/notify/notify'; import Notify from '../components/vant/notify/notify';
import { getOneRaffle, getUserPhone, getPrize } from '../common/api'
var raffle = require('../common/raffleProbability'); var raffle = require('../common/raffleProbability');
var area = require('../components/custom/china.js'); var area = require('../components/custom/china.js');
wepy.page({ wepy.page({
...@@ -141,14 +142,26 @@ ...@@ -141,14 +142,26 @@
return; return;
} }
} }
let params = {
joinRecordId:this.joinRecordId,
name:this.name,
phone:this.phone,
province:this.province,
city:this.city,
country:this.country,
address:this.address,
};
let message = '您所领取的奖品我们将在3到5个工作日内寄出,请您耐心等待,感谢您的参与!';
let cashmeg = '您所领取的奖品我们将会在几分钟内发出,请您耐心等待,感谢您的参与!';
let that = this;
getPrize(params).then(()=>{
Dialog.alert({ Dialog.alert({
title: '领取成功', title: '领取成功',
message: '您所领取的奖品我们将在3到5个工作日内寄出,请您耐心等待,感谢您的参与!', message: that.prize.cash?cashmeg:message,
}).then(() => { }).then(() => {
wx.reLaunch({url:'/pages/index'}) wx.reLaunch({url:'/pages/index'})
// on confirm
}); });
console.log(this.name,this.phone,this.address); });
}, },
onClose() { onClose() {
this.showAddress = !this.showAddress; this.showAddress = !this.showAddress;
...@@ -175,10 +188,19 @@ ...@@ -175,10 +188,19 @@
this.joinRecordId = joinRecordId; this.joinRecordId = joinRecordId;
if(!joinRecordId) Notify({message: '缺少参数错误!', background:'#FF5D15'}); if(!joinRecordId) Notify({message: '缺少参数错误!', background:'#FF5D15'});
//请求接口得到数据 //请求接口得到数据
this.prize = {cash:false,name:'Nintendo Switch任天堂游戏机Nintendo Switch任天堂游戏机',photoUrl:'/static/images/test2.png',coinQuantity:5000}; getOneRaffle({joinRecordId:joinRecordId}).then(data=>{
this.quantity = 300; let dat = data[0];
this.prize = dat.prize;
this.quantity = dat.quantity;
this.chance = raffle.getProbability(dat.quantity,dat.prize.coinQuantity);
});
getUserPhone().then(data=>{
this.phone = data.phone;
});
this.areaList = area.areaList; this.areaList = area.areaList;
this.chance = raffle.getProbability(this.quantity,this.prize.coinQuantity); /*this.prize = {cash:false,name:'Nintendo Switch任天堂游戏机Nintendo Switch任天堂游戏机',photoUrl:'/static/images/test2.png',coinQuantity:5000};
this.quantity = 300;
this.chance = raffle.getProbability(this.quantity,this.prize.coinQuantity);*/
}, },
}); });
</script> </script>
......
...@@ -132,33 +132,57 @@ ...@@ -132,33 +132,57 @@
</view> </view>
<button class="joinin" open-type="{{opentype}}" bindtap="joinin" bindgetphonenumber="getPhoneNumber" >立即参与</button> <button class="joinin" open-type="{{opentype}}" bindtap="joinin" bindgetphonenumber="getPhoneNumber" >立即参与</button>
<van-notify id="van-notify" /> <van-notify id="van-notify" />
<van-dialog id="van-dialog" confirmButtonColor="#FF5D15"/>
</view> </view>
</template> </template>
<script> <script>
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import Notify from '../components/vant/notify/notify'; import Notify from '../components/vant/notify/notify';
import Dialog from '../components/vant/dialog/dialog';
import { updateUserPhone, confirmRaffle } from '../common/api'
wepy.page({ wepy.page({
data: { data: {
progress: 0, progress: 0,
progressStyle: '', progressStyle: '',
isCheck: false, isCheck: false,
id: null, batchId: null,
quantity: '', quantity: '',
name: '', name: '',
chance: '', chance: '',
photoUrl: '', photoUrl: '',
batchId:null,
}, },
methods: { methods: {
check() { check() {
this.isCheck = !this.isCheck; this.isCheck = !this.isCheck;
}, },
getPhoneNumber(e) { async getPhoneNumber(e) {
let that = this;
let title = ['参与成功!','参与失败!','参与失败!'];
let message = ['','当前抽奖已结束。','当前奖品已经没有库存了。']
let detail = e.$wx.detail || {}; let detail = e.$wx.detail || {};
//调用接口将加密数据传给后端,e.$wx.detail整体都传过去
//如果数据得到了就跳转
if(detail.encryptedData) { if(detail.encryptedData) {
Notify({message: '恭喜您参与成功!',background:'#FF5D15'}) wx.checkSession({
success () {
updateUserPhone(detail).then(()=>{
confirmRaffle({batchId:that.batchId}).then(data=>{
let code = data[0].joinCode;
Dialog.alert({
title: title[code],
message: message[code],
}).then(() => {
wx.reLaunch({url:'/pages/index'})
});
}).catch(()=>{
Notify({message: '参与失败,请重新点击参与!',background:'#FF5D15'})
})
}).catch(()=>{
Notify({message: '参与失败,请重新点击参与!',background:'#FF5D15'})
});
},
fail () {
wx.login();
}
});
}else { }else {
Notify({message: '参与失败,请重新授权!',background:'#FF5D15'}) Notify({message: '参与失败,请重新授权!',background:'#FF5D15'})
} }
...@@ -166,6 +190,7 @@ ...@@ -166,6 +190,7 @@
joinin() { joinin() {
if(!this.isCheck) { if(!this.isCheck) {
Notify({message: '请先勾选!', background:'#FF5D15'}) Notify({message: '请先勾选!', background:'#FF5D15'})
return;
} }
} }
}, },
...@@ -188,17 +213,16 @@ ...@@ -188,17 +213,16 @@
} }
}, },
onLoad (query) { onLoad (query) {
this.batchId = query.batchId; let {batchId, quantity, name, chance, photoUrl, progress} = query;
let {id, corn, goods, chance, imgsrc, progress} = query;
if (progress) { if (progress) {
this.progress = progress; this.progress = progress;
this.progressStyle = 'width:' + progress + '%'; this.progressStyle = 'width:' + progress + '%';
} }
this.id = id; this.batchId = batchId;
this.quantity = corn; this.quantity = quantity;
this.name = goods; this.name = name;
this.chance = chance; this.chance = chance;
this.photoUrl = imgsrc; this.photoUrl = photoUrl;
} }
}); });
</script> </script>
...@@ -209,6 +233,7 @@ ...@@ -209,6 +233,7 @@
"van-notify": "../components/vant/notify/index", "van-notify": "../components/vant/notify/index",
"van-image": "../components/vant/image/index", "van-image": "../components/vant/image/index",
"van-loading": "../components/vant/loading/index", "van-loading": "../components/vant/loading/index",
"van-dialog": "../components/vant/dialog/index",
} }
} }
</config> </config>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment