Commit 926f9624 authored by ziyu's avatar ziyu

improvement: 接口

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