Commit e409bc2a authored by jyx's avatar jyx

代码优化

parent dd4daf8e
<template>
<uni-popup type="bottom" ref="coinPop" :maskClick="false" :safe-area='false' :isMaskClick="false">
<view class="body" style="width: 100%;height: 100%;background-color: white;">
<scroll-view scroll-y>
<view style="display: flex;flex-direction: column;align-items: flex-end;margin-bottom: 10rpx;">
......@@ -17,17 +14,12 @@
<view class="pack-item" :class="[{active: index==selectedIndex}]"
v-for='(item, index) in vipList' :key='index' @click="choosePack(item, index)">
<view style="display: flex;flex-direction: column;padding-left: 4rpx;">
<view class="price row">
{{item.firstPayPrice}}
</view>
<view class="name row" v-if="item.title!=null&&item.title!=''">
{{item.title}}
</view>
<view class="origin row" v-if="item.remarks!=null&&item.remarks!=''">
{{item.remarks}}
</view>
......@@ -131,6 +123,7 @@
handleShow() {
let that = this;
this.$refs.coinPop.open('bottom');
// 内容重置
if (this.vipList.length > 0) {
this.vipList = [];
......@@ -144,7 +137,6 @@
this.post({
url: '/vip/getVipProductsV1',
data: {
bookId: that.vedioId
},
......@@ -215,90 +207,40 @@
let that = this;
let vipBean = this.vipList[this.selectedIndex];
// 抖音支付
// 快手支付
this.post({
url: '/vip/getVipPayParams/douyin',
url: '/vip/getVipPayParams/kuaishou',
data: {
bookId: that.vedioId,
os: that.os,
vedioId: that.point <= 0 ? null : that.vedioId,
pid: vipBean.pid
},
showLoading: true,
success: ({
data
}) => {
that.ttPrePay(data, vipBean.largeType);
that.ksPay(data, vipBean.largeType);
}
});
},
ttPrePay(ttData, largeType) {
// if (!ks.canIUse('requestOrder')) {
// message.notify('请升级抖音APP版本.');
// return
// }
uni.showLoading({
title: '加载中...'
});
ksPay(ksData, largeType) {
let that = this;
ks.requestOrder({
data: ttData.params.data,
byteAuthorization: ttData.params.byteAuthorization,
success(res) {
that.ttPay(largeType, res.orderId, ttData);
ks.pay({
serviceId: ksData.params.serviceId,
orderInfo: ksData.params.orderInfo,
paymentChannel: ksData.params.paymentChannel,
success() {
that.queryOrderStatus(largeType, ksData.tidStr)
},
fail(res) {
uni.hideLoading();
console.log('ttPrePay', res.errMsg);
// message.notify(res.errMsg);
fail() {
message.notify('支付失败');
},
});
},
ttPay(largeType, oid, ttData) {
uni.hideLoading();
// if (!ks.canIUse('getOrderPayment')) {
// message.notify('请升级抖音APP版本!');
// return
// }
let that = this;
if (this.os == 'ios') {
// if (!ks.canIUse('getOrderPayment.object.imId')) {
// message.notify('请升级抖音APP版本~');
// return
// }
ks.getOrderPayment({
orderId: oid,
imId: ttData.imId,
success(res) {
that.queryOrderStatus(largeType, ttData.tidStr);
},
fail(res) {
console.log('ios pay', res.errMsg);
// message.notify(res.errMsg);
},
});
} else {
tt.getOrderPayment({
orderId: oid,
success(res) {
that.queryOrderStatus(largeType, ttData.tidStr);
},
fail(res) {
console.log('android pay', res.errMsg);
// message.notify(res.errMsg);
},
});
}
})
},
queryOrderStatus(largeType, tid) {
let that = this;
this.post({
data: {
tid: tid
tid
},
url: '/vip/queryVipOrder',
showLoading: true,
......
......@@ -8,7 +8,8 @@
</text>
<view style="display: flex;flex-direction: row;margin-top: 30rpx;">
<view style="font-size: 42rpx;color: #333232;margin-top: 18rpx;"></view>
<view style="font-size: 60rpx;color: #F32E2E;font-weight: 777;">{{vipBean2.firstPayPrice}}</view>
<view style="font-size: 60rpx;color: #F32E2E;font-weight: 777;">{{vipBean2.firstPayPrice}}
</view>
<view style="font-size: 42rpx;color: #333232;margin-top: 18rpx;"></view>
</view>
<text style="margin-top: 30rpx; font-size: 38rpx; color: #F32E2E">
......@@ -74,7 +75,7 @@
showdialog() {
this.$refs.vipback.open();
console.log('vipback-', this.vipBean);
if (tt.getSystemInfoSync().platform === 'ios') {
if (ks.getSystemInfoSync().platform === 'ios') {
this.os = 'ios';
}
},
......@@ -86,83 +87,34 @@
let that = this;
// 抖音支付
// 快手支付
this.post({
url: '/vip/getVipPayParams/douyin',
url: '/vip/getVipPayParams/kuaishou',
data: {
os: that.os,
pid: that.vipBean.pid
vedioId: that.point <= 0 ? null : that.vedioId,
pid: vipBean.pid
},
showLoading: true,
success: ({
data
}) => {
that.ttPrePay(data, that.vipBean.largeType);
that.ksPay(data, vipBean.largeType);
}
});
},
ttPrePay(ttData, largeType) {
if (!tt.canIUse('requestOrder')) {
message.notify('请升级抖音APP版本.');
return
}
tt.showLoading({
title: '加载中...'
});
ksPay(ksData, largeType) {
let that = this;
tt.requestOrder({
data: ttData.params.data,
byteAuthorization: ttData.params.byteAuthorization,
success(res) {
that.ttPay(largeType, res.orderId, ttData);
ks.pay({
serviceId: ksData.params.serviceId,
orderInfo: ksData.params.orderInfo,
paymentChannel: ksData.params.paymentChannel,
success() {
that.queryOrderStatus(largeType, ksData.tidStr)
},
fail(res) {
tt.hideLoading();
console.log('ttPrePay', res.errMsg);
// message.notify(res.errMsg);
fail() {
message.notify('支付失败');
},
});
},
ttPay(largeType, oid, ttData) {
tt.hideLoading();
if (!tt.canIUse('getOrderPayment')) {
message.notify('请升级抖音APP版本!');
return
}
let that = this;
if (this.os == 'ios') {
if (!tt.canIUse('getOrderPayment.object.imId')) {
message.notify('请升级抖音APP版本~');
return
}
tt.getOrderPayment({
orderId: oid,
imId: ttData.imId,
success(res) {
that.queryOrderStatus(largeType, ttData.tidStr);
},
fail(res) {
console.log('ios pay', res.errMsg);
// message.notify(res.errMsg);
},
});
} else {
tt.getOrderPayment({
orderId: oid,
success(res) {
that.queryOrderStatus(largeType, ttData.tidStr);
},
fail(res) {
console.log('android pay', res.errMsg);
// message.notify(res.errMsg);
},
});
}
})
},
queryOrderStatus(largeType, tid) {
let that = this;
......
......@@ -87,9 +87,7 @@
},
readyCategory() {
setTimeout(() => {
this.initHeight()
}, 300)
this.initHeight()
},
getCategoryData() {
getCategorys((success, data) => {
......
<template>
<uni-popup ref='beanpop' type="bottom" :is-mask-click='false' :safe-area='false' @maskClick='tapMask'>
<view class="setting-box">
<view class="section">
<view class="title">
充值书豆,订阅全本
</view>
<view class="pack-box">
<view class="pack-item" :class="[{active: index==selectedIndex}]" v-for='(item, index) in packData'
:key='index' @click="choosePack(item, index)">
<view class="name row">
{{item.title}}
</view>
<view class="price row">
{{item.price}}
</view>
<view class="cut-down" v-if='item.giveNumber'>
赠送 {{item.giveNumber}} 书豆
</view>
</view>
</view>
</view>
<view class="section">
<button class="c-button_clear c-button-size_lg c-button-width_full apply-button" :disabled="loading"
:loading="loading" @click="tapPay">立即购买</button>
</view>
<view class="safe-placeholder" :style="[safePlacehoderStyle]">
</view>
</view>
</uni-popup>
</template>
<script>
import SystemInfoMixin from "../../../../common/mixins/system-info-mixin.js";
import BookBeanPack from "../../../../common/models/BookBeanPack.js"
import {
getBookBeanPackData,
getOpenId,
getPayInfo,
ENUM_PAY_TYPE
} from "../../../../common/services/index.js";
import PayInfo from "../../../../common/models/PayInfo.js"
import {
watchUserInfoChange,
removeUserInfoChangeWatch,
showLoginView,
refreshUserInfo
} from "../../../../common/services/userServices.js"
import {
toastMessage
} from "../../../../common/utils/toastUtil.js";
import {
px2rpx
} from "../../../../common/utils/util.js";
export default {
mixins: [SystemInfoMixin],
props: {
show: {
type: Boolean,
default: false
}
},
data: function() {
return {
showPop: false,
userInfo: null,
packData: [],
selectedIndex: 0,
loading: false
}
},
computed: {
safePlacehoderStyle: function() {
let height = 0;
if (this.bottomSafeHeight) {
height = height + px2rpx(this.bottomSafeHeight)
}
return {
height: `${height}rpx`
}
},
beanCount: function() {
if (this.userInfo) return this.userInfo.bookLegumes;
return 0;
}
},
watch: {
show: function(n) {
this.showPop = n;
},
showPop: function(n, o) {
if (n == o) return;
if (n) {
this.open();
} else {
this.close();
}
}
},
onReady() {
watchUserInfoChange((info) => {
this.userInfo = info.userInfo;
}, this)
},
onUnload() {
removeUserInfoChangeWatch(this);
},
mounted() {
this.requestPackData();
},
methods: {
open() {
this.$refs.beanpop.open();
},
close() {
this.$emit('close')
this.$refs.beanpop.close();
},
tapMask() {
this.showPop = false;
},
requestPackData() {
getBookBeanPackData((success, data) => {
uni.stopPullDownRefresh()
if (success) {
this.packData = data.map(item => {
return new BookBeanPack(item)
})
}
})
},
choosePack(item, index) {
this.selectedIndex = index;
},
tapPay() {
let isIOS = uni.getSystemInfoSync().platform == "ios" && false
if (isIOS) {
uni.showModal({
title: "提示",
content: "由于相关规范,iOS功能暂不可用"
})
} else {
if (!this.userInfo) {
uni.showModal({
title: "登录",
content: "购买前请前往登录系统",
success: (res) => {
if (res.confirm) {
showLoginView()
}
}
})
return;
}
if (this.loading) return;
let pack = this.packData[this.selectedIndex];
this.loading = true;
let sysLoginFn = (successCB) => {
uni.login({
provider: "weixin",
onlyAuthorize: true,
success: (res) => {
if (res) {
if (typeof successCB == 'function') successCB(res);
} else {
this.loading = false;
}
},
fail: (error) => {
this.loading = false;
}
})
}
let getOpenIdFn = (code, successCB) => {
getOpenId(code, (success, data) => {
if (success) {
if (typeof successCB == 'function') successCB(data);
} else {
this.loading = false;
}
})
}
let getPayInfoFn = (openId, successCB) => {
getPayInfo(pack.id, pack.price, openId, (success, data) => {
if (success) {
if (typeof successCB == 'function') successCB(new PayInfo(data));
} else {
this.loading = false;
}
}, ENUM_PAY_TYPE.BEAN.value)
}
let payOrderFn = (payInfo, successCB) => {
// uni.requestPayment({
// timeStamp: payInfo.timeStamp,
// nonceStr: payInfo.nonceStr,
// package: payInfo.packageStr,
// signType: payInfo.signType,
// paySign: payInfo.paySign,
// success: (res) => {
// if (typeof successCB == 'function') successCB(res);
// },
// fail: (error) => {
// this.loading = false;
// }
// })
// 头条支付
if (!tt.canIUse('requestOrder')) {
toastMessage('请升级抖音APP版本!')
return
}
if (!tt.canIUse('getOrderPayment')) {
toastMessage('请升级抖音APP版本~')
return
}
tt.requestOrder({
data: payInfo.params.data,
byteAuthorization: payInfo.params.byteAuthorization,
success(res) {
tt.getOrderPayment({
orderId: res.oid,
success(res2) {
if (typeof successCB == 'function') successCB(res2);
},
fail(res2) {
console.log('android=ttPay res.errMsg', res2)
},
});
},
fail(res) {
console.log('requestOrder res.errMsg', res)
},
});
}
sysLoginFn((code) => {
getOpenIdFn(code.code, (openId) => {
getPayInfoFn(openId, (payInfo) => {
payOrderFn(payInfo, (data) => {
this.loading = false;
toastMessage('购买成功')
refreshUserInfo();
})
})
})
})
}
}
}
}
</script>
<style lang="scss" scoped>
.setting-box {
display: flex;
flex-direction: column;
background: #fff;
padding-top: 20rpx;
border-top-left-radius: 15rpx;
border-top-right-radius: 15rpx;
.section {
padding: 0 30rpx;
display: flex;
flex-direction: column;
background: #fff;
.title {
margin: 10rpx auto;
font-size: 32rpx;
font-weight: 700;
color: #333;
}
.pack-box {
margin-top: 25rpx;
margin-left: 40rpx;
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
.active {
border: 6rpx solid #fd5350 !important;
}
.pack-item {
margin-bottom: 25rpx;
margin-right: 40rpx;
width: calc(31% - 40rpx);
height: 200rpx;
display: flex;
flex-direction: column;
justify-content: space-around;
background: #f5f5f5;
border: 6rpx solid #f5f5f5;
border-radius: 10rpx;
position: relative;
.row {
margin: 8rpx 15rpx 0 15rpx;
}
.row:last-child {
margin-bottom: 8rpx;
}
.name {
font-size: 26rpx;
font-weight: 700;
color: #333;
}
.price {
font-size: 30rpx;
color: #fd5350;
font-weight: 700;
}
.origin {
font-size: 22rpx;
color: #333;
text-decoration: line-through;
}
.cut-down {
position: absolute;
top: 0;
right: 0;
color: #fff;
background: #ff502f;
font-size: 22rpx;
border-radius: 15rpx;
height: 30rpx;
line-height: 30rpx;
padding: 0 10rpx;
transform: translate(0, -50%);
}
}
}
.apply-button {
border-radius: 50rpx;
background: #e8c8ae;
color: #8d5a29;
margin: 30rpx auto;
}
}
}
</style>
\ No newline at end of file
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