< template >
< view class = "container" v-if ="userInfo.user_id" >
<!-- < view class = "account-panel dis-flex flex-y-center" >
< view class = "panel-lable" >
< text > 账户余额 < / text >
< / view >
< view class = "panel-balance flex-box" >
< text > ¥ { { userInfo . balance } } < / text >
< / view >
< / view > -- >
< view class = "recharge-panel" >
< view class = "recharge-label" >
< text > 礼品卡兑换 < / text >
< / view >
<!-- < view class = "recharge-plan clearfix" >
< block v-for ="(item, index) in planList" :key ="index" >
< view class = "recharge-plan_item" : class = "{ active: selectedPlanId == item.plan_id }" @click ="onSelectPlan(item.plan_id)" >
< view class = "plan_money" >
< text > { { item . money } } < / text >
< / view >
< view class = "plan_gift" v-if ="item.gift_money > 0" >
< text > 送 { { item . gift _money } } < / text >
< / view >
< / view >
< / block >
< / view > -- >
< view class = "btnContainer" >
< view : class = "activeIndex==index?'btnItem active':'btnItem'" @click ="getPrizeItem(item)" v-for ="(item,index) in btnList" :key ="index" > {{ item.name }} < / view >
< / view >
<!-- 手动充值输入框 -- >
< view class = "recharge-input" >
< input type = "text" placeholder = "请输入礼品卡CDKEY" v -model = " inputValue " @input ="onChangeMoney" / >
< / view >
<!-- 确认按钮 -- >
< view class = "recharge-submit btn-submit" >
< form @submit ="onSubmit" >
< button class = "button" formType = "submit" :disabled ="disabled" > 立即兑换 < / button >
< / form >
< / view >
< / view >
<!-- 充值描述 -- >
< view class = "recharge-describe" >
< view class = "recharge-label" >
< text > 礼品卡说明 < / text >
< / view >
< view class = "content" >
<!-- < text space = "ensp" > { { setting . describe } } < / text > -- >
< text space = "ensp" > 1 、 一张卡只能兑换一次 < / text >
< / view >
< view class = "content" >
<!-- < text space = "ensp" > { { setting . describe } } < / text > -- >
< text space = "ensp" > 2 、 禁止用于非法交易或其他用途 < / text >
< / view >
< view class = "content" >
< text space = "ensp" > 3 、 CDKEY区分大小写 , 请严格输入 < / text >
< / view >
< / view >
< u -toast ref = "uToast" / >
< / view >
< / template >
< script >
import * as UserApi from '@/api/user'
import * as cdkeyApi from '@/api/cdkey'
import * as PlanApi from '@/api/recharge/plan'
import SettingModel from '@/common/model/Setting'
import SettingKeyEnum from '@/common/enum/setting/Key'
import { wxPayment } from '@/core/app'
export default {
data ( ) {
return {
// 正在加载
isLoading : true ,
// 会员信息
userInfo : { } ,
// 充值设置
setting : { } ,
// 充值方案列表
planList : [ ] ,
// 按钮禁用
disabled : false ,
// 当前选中的套餐id
selectedPlanId : 0 ,
// 自定义金额
inputValue : '' ,
remark : '牛肉' ,
btnList : [
{ name : '牦牛肉礼盒' , value : 0 } ,
{ name : '藏羊肉礼盒' , value : 1 } ,
] ,
activeIndex : 0
}
} ,
/ * *
* 生命周期函数 -- 监听页面加载
* /
onLoad ( options ) {
// 获取页面数据
this . getPageData ( )
} ,
methods : {
// 金额输入框
onChangeMoney ( e ) {
this . inputValue = e . target . value
this . selectedPlanId = 0
} ,
// 获取页面数据
getPageData ( ) {
const app = this
app . isLoading = true
//Promise.all([app.getUserInfo(), app.getSetting(), app.getPlanList()])
Promise . all ( [ app . getUserInfo ( ) ] )
. then ( ( ) => app . isLoading = false )
} ,
// 获取会员信息
getUserInfo ( ) {
const app = this
return new Promise ( ( resolve , reject ) => {
UserApi . info ( )
. then ( result => {
app . userInfo = result . data . userInfo
resolve ( app . userInfo )
} )
} )
} ,
// 立即充值
onSubmit ( e ) {
const app = this
// 按钮禁用
app . disabled = true
// 提交到后端
cdkeyApi . submit ( { cdkey : app . inputValue , remark : app . remark } )
. then ( result => {
console . log ( result )
// app.$toast('兑换成功')
// app.$toast(result.message),
app . getPageData ( )
app . $refs . uToast . show ( {
title : '兑换成功'
} )
} ) . finally ( ( ) => app . disabled = false )
} ,
getPrizeItem ( item ) {
this . activeIndex = item . value ;
if ( item . value == 0 ) {
this . remark = '牛肉'
} else {
this . remark = '羊肉'
}
}
}
}
< / script >
< style lang = "scss" scoped >
page ,
. container {
background : # fff ;
}
. container {
padding - bottom : 70 rpx ;
}
/* 账户面板 */
. account - panel {
width : 650 rpx ;
height : 180 rpx ;
margin : 50 rpx auto ;
padding : 0 60 rpx ;
box - sizing : border - box ;
border - radius : 12 rpx ;
color : # fff ;
// background: linear-gradient(-125deg, #a46bff, #786cff);
background : # 17 C161 ;
box - shadow : 0 5 px 22 px 0 rgba ( 0 , 0 , 0 , 0.26 ) ;
}
. panel - lable {
font - size : 32 rpx ;
}
. recharge - label {
color : rgb ( 51 , 51 , 51 ) ;
font - size : 28 rpx ;
margin - bottom : 25 rpx ;
}
. panel - balance {
text - align : right ;
font - size : 46 rpx ;
}
. recharge - panel {
padding - top : 100 rpx ;
padding : 0 60 rpx ;
}
/* 充值套餐 */
. recharge - plan {
. recharge - plan _item {
width : 192 rpx ;
padding : 15 rpx 0 ;
float : left ;
text - align : center ;
color : # 888 ;
border : 1 rpx solid rgb ( 228 , 228 , 228 ) ;
border - radius : 10 rpx ;
margin : 0 20 rpx 20 rpx 0 ;
& : nth - child ( 3 n + 0 ) {
margin - right : 0 ;
}
& . active {
color : # 786 cff ;
border : 1 rpx solid # 786 cff ;
. plan _money {
color : # 786 cff ;
}
}
}
}
. plan _money {
font - size : 32 rpx ;
color : rgb ( 82 , 82 , 82 ) ;
}
. plan _gift {
font - size : 25 rpx ;
}
. recharge - input {
margin - top : 25 rpx ;
input {
border : 1 rpx solid rgb ( 228 , 228 , 228 ) ;
border - radius : 10 rpx ;
padding : 15 rpx 16 rpx ;
font - size : 26 rpx ;
}
}
/* 立即充值 */
. recharge - submit {
margin - top : 70 rpx ;
}
. btn - submit {
. button {
font - size : 30 rpx ;
background : # 17 C161 ;
border : none ;
color : white ;
border - radius : 50 rpx ;
padding : 0 120 rpx ;
line - height : 3 ;
}
. button [ disabled ] {
background : # 17 C161 ;
border - color : # 17 C161 ;
color : white ;
}
}
/* 充值说明 */
. recharge - describe {
margin - top : 50 rpx ;
padding : 0 60 rpx ;
. content {
font - size : 26 rpx ;
line - height : 1.6 ;
color : # 888 ;
}
}
. btnContainer {
display : flex ;
align - items : center ;
. btnItem {
flex : 1 ;
border : 1 px solid # eaeaea ;
background - color : # ffffff ;
color : # 000000 ;
font - size : 28 rpx ;
border - radius : 10 rpx ;
padding : 20 rpx 0 ;
text - align : center ;
margin : 0 10 rpx ;
}
. active {
background - color : # 17 C161 ;
border : 1 px solid # 17 C161 ;
color : # ffffff ;
}
}
< / style >