Commit b22c9d5f authored by ziyu's avatar ziyu

feat: 接口联调

parent 032c7068
...@@ -45,6 +45,6 @@ module.exports = { ...@@ -45,6 +45,6 @@ module.exports = {
return http.post('/api/user/update/phone', params); return http.post('/api/user/update/phone', params);
}, },
getPrize(params){ getPrize(params){
return http.post('/api/user/price/receive', params); return http.post('/api/user/prize/receive', params, { 'content-type': 'application/json' });
} }
}; };
...@@ -189,7 +189,7 @@ ...@@ -189,7 +189,7 @@
if(!joinRecordId) Notify({message: '缺少参数错误!', background:'#FF5D15'}); if(!joinRecordId) Notify({message: '缺少参数错误!', background:'#FF5D15'});
//请求接口得到数据 //请求接口得到数据
getOneRaffle({joinRecordId:joinRecordId}).then(data=>{ getOneRaffle({joinRecordId:joinRecordId}).then(data=>{
let dat = data[0]; let dat = data|| {};
this.prize = dat.prize; this.prize = dat.prize;
this.quantity = dat.quantity; this.quantity = dat.quantity;
this.chance = raffle.getProbability(dat.quantity,dat.prize.coinQuantity); this.chance = raffle.getProbability(dat.quantity,dat.prize.coinQuantity);
......
...@@ -130,7 +130,7 @@ ...@@ -130,7 +130,7 @@
<image src="{{imgsrc}}" class="checkimg"></image> <image src="{{imgsrc}}" class="checkimg"></image>
<text class="checktext">我同意花费所有克币参与抽奖,并承诺购买的商品不再退货。</text> <text class="checktext">我同意花费所有克币参与抽奖,并承诺购买的商品不再退货。</text>
</view> </view>
<button class="joinin" open-type="{{opentype}}" bindtap="joinin" bindgetphonenumber="getPhoneNumber" >立即参与</button> <button class="joinin" open-type="{{opentype}}" bindtap="joinin" bindgetphonenumber="getPhoneNumber">{{btnfont}}</button>
<van-notify id="van-notify" /> <van-notify id="van-notify" />
<van-dialog id="van-dialog" confirmButtonColor="#FF5D15"/> <van-dialog id="van-dialog" confirmButtonColor="#FF5D15"/>
</view> </view>
...@@ -139,66 +139,86 @@ ...@@ -139,66 +139,86 @@
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 Dialog from '../components/vant/dialog/dialog';
import { updateUserPhone, confirmRaffle, register } from '../common/api' import { updateUserPhone, confirmRaffle, register,getUserPhone } from '../common/api'
import store from '../store'; import store from '../store';
wepy.page({ wepy.page({
store, store,
data: { data: {
progress: '0%', progress: '0%',
progressStyle: '', progressStyle: '',
isCheck: false, isCheck: true,
batchId: null, batchId: null,
quantity: '', quantity: '',
name: '', name: '',
chance: '', chance: '',
photoUrl: '', photoUrl: '',
btnfont:'立即参与',
hasPhone:false,
}, },
methods: { methods: {
check() { check() {
this.isCheck = !this.isCheck; this.isCheck = !this.isCheck;
}, },
async getPhoneNumber(e) { async getPhoneNumber(e) {
if(this.btnfont !== '立即参与') {return;}
let that = this; let that = this;
let title = ['参与成功!','参与失败!','参与失败!'];
let message = ['','当前抽奖已结束。','当前奖品已经没有库存了。']
let detail = e.$wx.detail || {}; let detail = e.$wx.detail || {};
let isRegister = wx.getStorageSync('isRegister'); function goprize() {
//如果用户还未注册 updateUserPhone(detail).then(()=>{
if(isRegister === false) { that.confirmRaff();
await register(store.state.userInfo); wx.setStorageSync('hasPhone',true);
that.hasPhone = true;
}).catch(()=>{
that.btnfont = '立即参与';
});
} }
this.btnfont = '提交中...';
if(detail.encryptedData) { if(detail.encryptedData) {
wx.checkSession({ wx.checkSession({
success () { success () {
updateUserPhone(detail).then(()=>{ goprize();
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 () { async fail () {
wx.login(); await wepy.wx.login();
goprize();
} }
}); });
}else { }else {
Notify({message: '参与失败,请重新授权!',background:'#FF5D15'}) Notify({message: '参与失败,请重新授权!',background:'#FF5D15'})
} }
}, },
async confirmRaff() {
let title = ['参与成功!','参与失败!','参与失败!'];
let message = ['参与成功,坐等开奖。','当前抽奖已结束。','当前奖品已经没有库存了。'];
//如果用户还未注册
let isRegister = wx.getStorageSync('isRegister');
if(isRegister === false) {
await register(store.state.userInfo);
wx.setStorageSync('isRegister', true);
}
this.btnfont = '提交中...';
confirmRaffle({batchId:this.batchId}).then(data=>{
this.btnfont = '立即参与';
let code = data.joinCode;
if(code === undefined) code = 3;
Dialog.alert({
title: title[code],
message: message[code],
}).then(() => {
wx.reLaunch({url:'/pages/index'})
});
}).catch(()=>{
this.btnfont = '立即参与';
})
},
joinin() { joinin() {
if(!this.isCheck) { if(!this.isCheck) {
Notify({message: '请先勾选!', background:'#FF5D15'}) Notify({message: '请先勾选!', background:'#FF5D15'})
return; return;
} }
if(this.hasPhone) {
this.confirmRaff();
}
} }
}, },
computed: { computed: {
...@@ -212,7 +232,7 @@ ...@@ -212,7 +232,7 @@
return imgsrc; return imgsrc;
}, },
opentype() { opentype() {
if (this.isCheck) { if (this.isCheck && !this.hasPhone) {
return 'getPhoneNumber'; return 'getPhoneNumber';
} else { } else {
return ''; return '';
...@@ -225,6 +245,7 @@ ...@@ -225,6 +245,7 @@
this.progress = progress; this.progress = progress;
this.progressStyle = 'width:' + progress; this.progressStyle = 'width:' + progress;
} }
this.hasPhone = wx.getStorageSync('hasPhone');
this.batchId = batchId; this.batchId = batchId;
this.quantity = quantity||''; this.quantity = quantity||'';
this.name = name; this.name = name;
......
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