1. 增加购买物品时填写收件人的功能;

This commit is contained in:
zhl 2019-03-01 15:02:47 +08:00
parent e8382f2774
commit 4e216409ae
4 changed files with 241 additions and 60 deletions

View File

@ -78,9 +78,11 @@ export default class extends wepy.app {
onShow(options) {
console.log('app.onShow');
console.log(options);
let params = options.query;
console.log(params.token);
this.globalData.gameToken = params.token;
if (options.scene === 1037) {
let params = options.query;
this.globalData.gameToken = params.token;
}
}
sleep (s) {
return new Promise((resolve, reject) => {

View File

@ -0,0 +1,104 @@
<!--购买时填写收货-->
<style lang="less">
.form-bg{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #000000;
opacity: 0.6;
z-index: 101;
}
.address-form {
position: fixed;
top: 20%;
left: 0;
right: 0;
z-index: 102;
background-color: #F9F9F9;
}
.doc-title {
font-size: 25px;
line-height: 25px;
color: #666;
padding: 15px 0;
margin: 20px 15px;
border-bottom: 1rpx solid #e5e5e5;
}
.form-action-bar {
margin-top: 20rpx;
padding: 10rpx;
}
.btn-white {
background-color: #fff;
}
.zan-btn {
border: 1rpx solid #e5e5e5;
margin-bottom: 8rpx;
}
</style>
<template>
<view class="form-bg {{ config.hide ? 'hidden' : ''}}" ></view>
<view class="address-form {{ config.hide ? 'hidden' : ''}}">
<view class="doc-title">填写收件人信息</view>
<view class="zan-form ">
<view class="zan-cell zan-form__item">
<text class="zan-form__title">收货人</text>
<input class="zan-form__input zan-cell__bd" placeholder="名字" @change="nameChange" value="{{addressInfo.name}}"/>
</view>
<view class="zan-cell zan-form__item">
<text class="zan-form__title">联系电话</text>
<input class="zan-form__input zan-cell__bd" type="number" maxlength="12" @change="mobileChange" value="{{addressInfo.mobile}}" placeholder="手机或固定电话" />
</view>
<view class="zan-cell zan-form__item">
<text class="zan-form__title">收货地址</text>
<input class="zan-form__input zan-cell__bd" type="text" maxlength="200" @change="addressChange" value="{{addressInfo.address}}" placeholder="收货地址" />
</view>
<view class="form-action-bar">
<button class="zan-btn zan-btn--large zan-btn--primary" @tap="confirmTap">确认付款</button>
<button class="zan-btn zan-btn--large btn-white" @tap="cancelTap">取消</button>
</view>
</view>
</view>
</template>
<script>
import wepy from 'wepy'
export default class addressForm extends wepy.component {
props = {
config: {
hide: true
},
addressInfo: {
mobile: '',
name: '',
address: ''
}
}
data = {
}
methods = {
cancelTap(e) {
this.$emit('cancelTap')
},
confirmTap(e) {
this.$emit('confirmTap', this.addressInfo);
},
nameChange(e) {
this.addressInfo.name = e.detail.value;
this.$apply()
},
mobileChange(e) {
this.addressInfo.mobile = e.detail.value;
this.$apply()
},
addressChange(e) {
this.addressInfo.address = e.detail.value;
this.$apply()
}
}
}
</script>

View File

@ -86,8 +86,11 @@
},
bottomSecondTap(e) {
console.log('bottomSecondTap');
let self = this;
wepy.navigateBackMiniProgram({
extraData: {
type: self.currentType,
event_type: 'pay_result',
success: false
}
})
@ -143,15 +146,17 @@
});
}
async queryOrder() {
let self = this;
try {
let res = await http.post('/api/emulated/query_order', {tid: this.tid});
if (res.errcode === 0 && res.result === 1) {
wepy.showToast({
title: '支付成功',
icon: 'none',
duration: 2000
wepy.navigateBackMiniProgram({
extraData: {
type: self.currentType,
event_type: 'pay_result',
success: true
}
})
jcEvent.emit(jcEvent.events.NEED_UPDATE_SCORE, {});
}
} catch (err) {
console.log(err);

View File

@ -7,18 +7,21 @@
<view class="container">
<image class="product_img" mode="widthFix" src="https://resource.kingsome.cn/voodoo/5c788d47486f49165aa057b6.jpeg"/>
</view>
<addressFrom :config.sync="formCfg" :addressInfo.sync="addressInfo" @cancelTap.user="formCancel" @confirmTap.user="formConfirm"/>
<gameBottomBar :config.sync="bottomActionCfg" @bottomMainTap.user="bottomMainTap"
@bottomSecondTap.user="bottomSecondTap"/>
</template>
<script>
import wepy from 'wepy';
import gameBottomBar from '../components/game-bottom-bar';
import addressFrom from '../components/address-form';
import http from '../utils/http';
import jcEvent from '../common/jc-event';
export default class ProductPage extends wepy.page {
components = {
gameBottomBar: gameBottomBar
gameBottomBar: gameBottomBar,
addressFrom: addressFrom
};
config = {
navigationBarTitleText: '购买产品'
@ -32,82 +35,149 @@
secondBtnIconClass: 'icon-forbid',
secondBtnTitle: '取消'
},
formCfg: {
hide: true
},
addressInfo: {
mobile: '',
name: '',
address: ''
},
tid: ''
};
methods = {
bottomMainTap(e) {
console.log('bottomMainTap');
let self = this;
wepy.showLoading({
title: '支付中'
})
http.post('/api/emulated/pre_pay', { gid: this.gid })
.then(res => {
console.log(res.data);
if (res.errcode === 0) {
let payResult = res.data;
self.tid = res.tid;
wx.requestPayment({
'timeStamp': payResult.timeStamp,
'nonceStr': payResult.nonceStr,
'package': payResult.package,
'signType': 'MD5',
'paySign': payResult.paySign,
complete: (res) => {
wepy.hideLoading();
if (res.errMsg === 'requestPayment:ok') {
console.log('支付成功')
self.queryOrder();
} else if (res.errMsg === 'requestPayment:fail cancel' || res.errMsg === 'requestPayment:cancel') {
wepy.showToast({
title: '用户取消支付',
icon: 'none',
duration: 2000
})
} else {
console.log('支付失败');
let msg = res.errMsg.replace('requestPayment:fail', '')
wepy.showToast({
title: msg,
icon: 'none',
duration: 2000
})
}
}
})
}
})
.catch(err => {
console.log('err update game history');
});
this.showBuyMenu();
},
bottomSecondTap(e) {
console.log('bottomSecondTap');
wepy.navigateBackMiniProgram({
extraData: {
event_type: 'pay_result',
type: 'item',
success: false
}
})
},
async formConfirm(data) {
this.addressInfo = data;
try {
await this.updateUserInfo();
this.buy();
} catch (err) {
}
},
formCancel() {
this.formCfg.hide = true;
this.$apply();
}
};
onLoad(params) {
this.gid = decodeURIComponent(params.gid);
console.log('product onload');
console.log('gid: ' + this.gid);
this.getUserInfo();
}
async showBuyMenu() {
let self = this;
try {
let res = await wepy.showActionSheet({
itemList: ['到店自取', '快递']
});
if (!res.cancel) {
if (res.tapIndex === 0) {
self.buy();
} else {
self.showAddressForm();
}
}
} catch (err) {
console.log('cancel select')
}
}
async getUserInfo() {
try {
let res = await http.post('/api/emulated/user_info', {type: 'all'});
console.log(res);
if (res.userInfo) {
this.addressInfo = res.userInfo.address_info || {mobile: '', name: '', address: ''};
}
this.$apply();
} catch (err) {
console.log('error get user info');
}
}
updateUserInfo() {
return http.post('/api/emulated/update_user_info', this.addressInfo);
}
buy() {
let self = this;
wepy.showLoading({
title: '支付中'
});
http.post('/api/emulated/pre_pay', { gid: this.gid })
.then(res => {
console.log(res.data);
if (res.errcode === 0) {
let payResult = res.data;
self.tid = res.tid;
wx.requestPayment({
'timeStamp': payResult.timeStamp,
'nonceStr': payResult.nonceStr,
'package': payResult.package,
'signType': 'MD5',
'paySign': payResult.paySign,
complete: (res) => {
wepy.hideLoading();
if (res.errMsg === 'requestPayment:ok') {
console.log('支付成功')
self.queryOrder();
} else if (res.errMsg === 'requestPayment:fail cancel' || res.errMsg === 'requestPayment:cancel') {
wepy.showToast({
title: '用户取消支付',
icon: 'none',
duration: 2000
})
} else {
console.log('支付失败');
let msg = res.errMsg.replace('requestPayment:fail', '')
wepy.showToast({
title: msg,
icon: 'none',
duration: 2000
})
}
}
})
}
})
.catch(err => {
console.log('err update game history');
});
}
showAddressForm() {
this.formCfg.hide = false;
this.$apply();
}
async queryOrder() {
try {
let self = this;
let res = await http.post('/api/emulated/query_order', {tid: this.tid});
if (res.errcode === 0 && res.result === 1) {
wepy.showToast({
title: '支付成功',
icon: 'none',
duration: 2000
})
// wepy.showToast({
// title: '支付成功',
// icon: 'none',
// duration: 2000
// })
wepy.navigateBackMiniProgram({
extraData: {
success: true
type: 'item',
event_type: 'pay_result',
success: true,
gid: self.gid
}
})
}