ts_aimz_uni/pages/pay/payment/payment.vue

571 lines
14 KiB
Vue
Raw Normal View History

2025-04-17 17:44:39 +08:00
<template>
2025-05-15 16:54:07 +08:00
<view class="page-container">
2025-04-17 17:44:39 +08:00
<swiper indicator-dots style="height: 120rpx;" autoplay indicator-active-color="#fff">
<swiper-item>
<image src="/static/images/banner_1.png" style="width: 100vw;height: 120rpx;"></image>
</swiper-item>
<swiper-item>
<image src="/static/images/banner_2.png" style="width: 100vw;height: 120rpx;"></image>
</swiper-item>
</swiper>
<!-- 充值金额输入 -->
<view class="card-box sum-input-box mt-20">
2025-04-17 17:44:39 +08:00
<view class="mt-20">充值金额</view>
<view class="sum-input mt-20">
<text style="font-size: 12px;margin-bottom: 6px;">¥</text>
<input class="input-money" type="digit" placeholder-style="font-size:23px;" placeholder="请输入金额"
@input="obMoney" :value="payMoney" />
</view>
<scroll-view scroll-x class="mt-20">
<view class="list-tabs">
<block v-for="(item,index) in paySumOptions" :key="index">
<view :class="currentTab==index? 'tab-select' :'tab-normal'" class="item-margin"
@click="doChangePayMoney" :data-value="item" :data-index="index">
<text>{{item}}</text>
</view>
</block>
</view>
</scroll-view>
</view>
<!-- 付款方式 -->
<view class="card-box mt-20">
2025-04-17 17:44:39 +08:00
<view>付款方式</view>
<radio-group class="form-radio_wrap">
<view class="pay-option-item mt-20" @click="doChangePayWay" data-value="1">
<view class="option-type">
<view class="icon icon-bd"></view>
<!-- #ifdef MP-BAIDU -->
<view>百度支付</view>
<!-- #endif -->
<!-- #ifdef MP-TOUTIAO -->
<view>抖音支付</view>
<!-- #endif -->
2025-04-17 17:44:39 +08:00
</view>
<radio :checked="payWay==1" value="1"></radio>
2025-04-17 17:44:39 +08:00
</view>
<view class="pay-option-item" @click="doChangePayWay" data-value="2">
<view class="option-type">
<view class="icon icon-card"></view>
<view>对公转账</view>
</view>
<radio :checked="payWay==2" value="2"></radio>
2025-04-17 17:44:39 +08:00
</view>
</radio-group>
</view>
<!-- 套餐包 -->
<view class="card-box mt-20">
2025-04-17 17:44:39 +08:00
<view class="bag-box">
<view :class="currentBagTab=='MATERIAL'?'bag-select':'bag-normal'" class="border-left"
@click="doChangeBagTab" data-value="MATERIAL">写材料套餐包</view>
<view :class="currentBagTab=='ALL'?'bag-select':'bag-normal'" class="border-right"
@click="doChangeBagTab" data-value="ALL">全托管套餐包</view>
</view>
<ContainerLoading style="min-height: 40vh;" :loadingVisible="listLoading" @doRefresh="doRefreshList">
<view class="bag-list" style="min-height: 40vh;">
<!-- 列表 -->
<block v-for="(item,index) in bagList" :key="index">
<view class="bag-item">
<view class="bag-item-title-box">
<view class="bag-title">{{item.packageName}}</view>
<view class="bag-desc">{{item.packageDescription}}</view>
2025-04-17 17:44:39 +08:00
</view>
<view class="bag-item-desc-box">
<rich-text :nodes="moneyTxt(10,14,item.packageMoney/100)"></rich-text>
<view class="bag-btn" @click="chooseBag" :data-value="item">选购</view>
2025-04-17 17:44:39 +08:00
</view>
</view>
</block>
</view>
</ContainerLoading>
</view>
2025-05-15 16:54:07 +08:00
<view class="bottom-fixed-footer">
<view class="bottom-btn-green" @click="doPay">确认充值</view>
2025-04-17 17:44:39 +08:00
</view>
</view>
<view>
<uni-popup type="message" ref="msg">
<uni-popup-message :type="msgType" :message="msgTxt" :duration="2000"></uni-popup-message>
</uni-popup>
</view>
</template>
<script>
import ContainerLoading from '@/components/container-loading.vue';
2025-04-18 18:04:07 +08:00
import PayService from '@/common/js/net/payApi.js';
2025-05-19 17:47:21 +08:00
import {
inject
} from 'vue';
import {
moneyTxt
} from '@/common/js/conver.js'
2025-04-17 17:44:39 +08:00
export default {
components: {
ContainerLoading
},
2025-05-19 17:47:21 +08:00
setup() {
const globalData = inject('globalData')
return {
globalData
}
},
2025-04-17 17:44:39 +08:00
data() {
return {
paySumOptions: [100, 300, 500, 1000, 2000, 5000],
currentTab: 0, //充值金额选项
payMoney: 100, //支付金额
currentBagTab: 'MATERIAL', //当前套餐包tab
bagList: [], //套餐包列表
payWay: 1, //支付方式 1微信 2对公
showError: false,
errorHint: '',
showSuccess: false,
successHint: '',
listLoading: 'loading',
selectBag: {}, //选中的套餐包
msgType: 'info',
msgTxt: '',
2025-05-19 17:47:21 +08:00
primaryColor: this.globalData.primaryColor
2025-04-17 17:44:39 +08:00
}
},
onLoad() {
const _self = this
uni.setNavigationBarTitle({
title: 'AI喵著'
})
uni.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
_self.doGetPackageList(_self.currentBagTab)
},
methods: {
moneyTxt,
2025-04-17 17:44:39 +08:00
doRefreshList() {
this.doGetPackageList(this.currentBagTab)
},
//获取可以购买的套餐包
doGetPackageList(path) {
const _self = this
_self.listLoading = 'loading'
const data = {
page: 1,
rows: 20
}
PayService.doGetBuyPackageList(path, data)
.then(res => {
console.log(res)
_self.listLoading = res.rows && res.rows.length > 0 ? 'success' : 'empty'
_self.bagList = res.rows
})
.catch(err => {
console.log(err)
_self.listLoading = 'error'
_self.msgType = 'error'
_self.msgTxt = '不好意思,没能获取到套餐数据。请您再试一次,相信马上就能看到啦。'
_self.$refs.msg.open()
})
},
//监听充值金额选项
doChangePayMoney(e) {
this.payMoney = e.currentTarget.dataset.value
this.selectBag = {}
this.currentTab = e.currentTarget.dataset.index
},
//监听充值金额变化
obMoney(e) {
var _self = this
const inputValue = e.detail.value
const regex = /^[+-]?(\d+(\.\d*)?|\.\d+)$/;
if (inputValue != '') {
if (regex.test(inputValue)) {
//数字
_self.payMoney = e.detail.value
_self.selectBag = {}
_self.currentTab = -1
} else {
_self.msgTxt = '请输入数字'
_self.msgType = 'error'
_self.$refs.msg.open()
setTimeout(() => {
_self.payMoney = 100
_self.selectBag = {}
}, 1000);
}
}
},
//切换套餐包
doChangeBagTab(e) {
this.currentBagTab = e.currentTarget.dataset.value
this.doGetPackageList(this.currentBagTab)
},
//切换支付方式
doChangePayWay(e) {
this.payWay = e.currentTarget.dataset.value
},
//选中套餐包
chooseBag(e) {
const _self = this
const selItem = e.currentTarget.dataset.value
_self.payMoney = selItem.packageMoney / 100
_self.currentTab = -1
_self.selectBag = selItem
uni.pageScrollTo({
scrollTop: 0,
duration: 300
})
},
//调用微信支付
toWeChatPay() {
const _self = this
const data = {
rechargeMoney: _self.payMoney,
packageInfoId: _self.selectBag.packageInfoId ? _self.selectBag.packageInfoId : ''
}
2025-05-30 17:38:28 +08:00
// #ifdef MP-BAIDU
_self.doPayBd(data)
// #endif
},
doPayBd(data) {
const _self = this
uni.showLoading({
title: '支付中...',
})
PayService.doGetBdPayParams(data)
2025-04-17 17:44:39 +08:00
.then(res => {
uni.hideLoading()
console.log('获取支付参数成功', res)
2025-05-30 17:38:28 +08:00
if (res && res.tpOrderId) {
const orderInfoRes = {
dealId: res.dealId,
appKey: res.appKey,
totalAmount: res.totalAmount,
tpOrderId: res.tpOrderId,
dealTitle: res.dealTitle,
signFieldsRange: res.signFieldsRange,
rsaSign: res.rsaSign,
notifyUrl: res.notifyUrl
}
2025-04-17 17:44:39 +08:00
uni.requestPayment({
2025-05-30 17:38:28 +08:00
provider: 'baidu',
orderInfo: orderInfoRes,
success: succRes => {
console.log('支付成功', succRes)
_self.msgTxt = '恭喜,您的充值已成功到账!'
_self.msgType = 'success'
_self.$refs.msg.open()
setTimeout(() => {
uni.navigateBack()
}, 1800);
2025-04-17 17:44:39 +08:00
},
2025-05-30 17:38:28 +08:00
fail: failErr => {
console.log('调用支付函数失败', failErr)
2025-04-17 17:44:39 +08:00
var hint = '很抱歉,本次充值失败,可能是网络不稳定或支付信息有误,请检查后重试。'
2025-05-30 17:38:28 +08:00
_self.msgTxt = failErr.errMsg ? failErr.errMsg :
'很抱歉,本次充值失败,可能是网络不稳定或支付信息有误,请检查后重试。'
2025-04-17 17:44:39 +08:00
_self.msgType = 'error'
_self.$refs.msg.open()
}
})
} else {
console.log('获取支付参数失败', res)
2025-04-17 17:44:39 +08:00
_self.msgType = 'error'
_self.msgTxt = err.msg ? err.msg : '很抱歉,本次充值失败,可能是网络不稳定或支付信息有误,请检查后重试。'
_self.$refs.msg.open()
}
})
.catch(err => {
uni.hideLoading()
console.log('获取支付参数失败Fail', err)
2025-04-17 17:44:39 +08:00
_self.msgType = 'error'
_self.msgTxt = err.msg ? err.msg : '很抱歉,本次充值失败,可能是网络不稳定或支付信息有误,请检查后重试。'
_self.$refs.msg.open()
})
},
//去支付
doPay() {
const _self = this
//判断钱大于0
if (_self.payMoney > 0) {
if (_self.payWay == '1') {
//微信
_self.toWeChatPay()
} else {
//对公 需要传递参数 选中套餐 or 直接冲钱
const id = _self.selectBag.packageInfoId
const name = _self.selectBag.packageName
uni.redirectTo({
url: `/pages/pay/publicPay/publicPay?packageId=${id}&name=${name}&money=${_self.payMoney}`,
})
}
} else {
//显示输入金额提示
_self.msgTxt = '请输入要充值的金额'
_self.msgType = 'error'
_self.$refs.msg.open()
}
}
}
}
</script>
2025-04-18 18:04:07 +08:00
<style lang="scss">
2025-04-17 17:44:39 +08:00
.input-money {
font-size: 48rpx;
font-weight: bold;
height: 24px;
line-height: 24px;
text-align: left;
}
.input-money-placeholder {
font-size: 24px;
font-weight: bold;
height: 24px;
line-height: 24px;
text-align: left;
}
.card-box {
border-radius: 10rpx;
display: flex;
padding: 30rpx;
flex-direction: column;
2025-04-17 17:44:39 +08:00
background-color: white;
border: 1rpx solid #F5F5F5;
}
.sum-input-box {
font-size: 28rpx;
}
.sum-input-box .title {
font-size: 12px;
color: black;
}
.sum-input-box input {
font-size: 42rpx;
color: black;
padding: 20rpx 10rpx;
flex: 1;
}
.sum-input {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: baseline;
border-bottom: 1rpx solid #dbdada;
font-weight: bold;
}
.pay-option-item {
display: flex;
flex-direction: row;
align-items: center;
2025-04-17 17:44:39 +08:00
}
.pay-option-item .option-type {
display: flex;
flex-direction: row;
align-items: center;
flex: 1;
2025-05-30 17:38:28 +08:00
margin: 20rpx 0rpx;
font-size: 28rpx;
2025-04-17 17:44:39 +08:00
}
.option-type .icon {
2025-05-30 17:38:28 +08:00
width: 42rpx;
height: 42rpx;
2025-04-17 17:44:39 +08:00
padding-right: 20rpx;
}
.list-tabs {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
padding: 10rpx 0rpx;
2025-04-17 17:44:39 +08:00
}
.bag-box {
display: flex;
flex-direction: row;
font-size: 28rpx;
}
.bag-select {
flex: 1;
text-align: center;
background-color: $primary-color;
2025-04-17 17:44:39 +08:00
color: white;
padding: 20rpx;
align-self: center;
2025-04-17 17:44:39 +08:00
}
.bag-normal {
flex: 1;
text-align: center;
background-color: transparent;
color: $primary-color;
border: 1rpx solid $primary-color;
2025-04-17 17:44:39 +08:00
padding: 20rpx;
}
.tab-select {
font-size: 20rpx;
color: black;
background-color: #FAE9D0;
text-align: center;
padding: 5rpx 30rpx;
white-space: nowrap;
}
.item-margin {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.item-margin:nth-of-type(n+2) {
margin-left: 20rpx;
}
.tab-normal {
font-size: 20rpx;
color: #F4CC92;
background: #FFFFFF;
border: 1rpx solid #F4CC92;
text-align: center;
padding: 5rpx 30rpx;
white-space: nowrap;
}
.bottom-btn-box {
position: fixed;
left: 0;
bottom: 0;
text-align: center;
width: 100vw;
line-height: 100rpx;
border-radius: 20rpx;
background-color: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 80px;
}
.green-bottom-btn {
background-color: #37AD46;
color: white;
text-align: center;
height: 42px;
width: 90vw;
line-height: 42px;
border-radius: 20rpx;
margin-bottom: 20px;
}
.green-bottom-btn:active {
background-color: #7ef58e;
color: white;
}
.bag-list {
display: flex;
flex-direction: column;
margin-top: 20rpx;
margin-bottom: 110rpx;
width: 86vw;
}
.bag-item {
display: flex;
flex-direction: row;
2025-04-17 17:44:39 +08:00
border: 1rpx solid rgba(239, 239, 239, 1);
padding: 20rpx;
}
.bag-item:nth-of-type(n+2) {
border-top: none;
border-left: 1rpx solid rgba(239, 239, 239, 1);
border-right: 1rpx solid rgba(239, 239, 239, 1);
border-bottom: 1rpx solid rgba(239, 239, 239, 1);
}
.bag-item-title-box {
display: flex;
flex-direction: column;
align-items: flex-start;
2025-04-17 17:44:39 +08:00
justify-content: space-between;
flex: 1;
2025-04-17 17:44:39 +08:00
}
.bag-title {
font-size: 28rpx;
color: $text-color;
font-weight: bold;
2025-04-17 17:44:39 +08:00
}
.bag-desc {
2025-04-17 17:44:39 +08:00
font-size: 24rpx;
color: $text-gray-hint-color;
margin-top: 20rpx;
2025-04-17 17:44:39 +08:00
}
.bag-item-desc-box {
display: flex;
flex-direction: column;
2025-04-17 17:44:39 +08:00
justify-content: space-between;
align-items: center;
}
.bag-num {}
2025-04-17 17:44:39 +08:00
.bag-btn {
padding: 5rpx 30rpx;
color: $white-color;
border-radius: 20rpx;
background-color: $primary-color;
2025-04-17 17:44:39 +08:00
color: rgba(255, 255, 255, 1);
font-size: 24rpx;
margin-top: 20rpx;
2025-04-17 17:44:39 +08:00
text-align: center;
white-space: nowrap;
2025-04-17 17:44:39 +08:00
}
// .p-title {
// }
// .bag-item-title-box .title {
// font-size: 40rpx;
// color: black;
// font-weight: 500;
// }
// .bag-item-title-box .sum {
// font-size: 14px;
// color: black;
// font-weight: 400;
// }
// .bag-item-desc-box .num {
// }
// .bag-item-desc-box .btn {
// }
2025-04-17 17:44:39 +08:00
</style>