<view class="content">
<text>余额:¥{{money}}</text>
<text>转账金额</text>
<view class="f-ac border-bottom">
<text style="font-size: 80rpx;">¥</text>
<input class="w-100" placeholder="输入金额" placeholder-style="color: #CFCFCF;" type="number" v-model="amount" />
</view>
<view class="w-100 f-jc">
<text class="btn-confirm" @click="openPay">转账</text>
</view>
</view>
<uni-popup ref="commandPopup" type="center">
<view class="command-use">
<image src="../../static/images/activity/closed.png" mode="" @tap="closePopup"></image> <!-- 右上角关闭的图片 -->
<view class="command-box flex1">
<view class="command-title">支付密码</view>
<view class="command-title" style="font-size: 28rpx;">扫码转账</view>
<view class="command-title" style="font-size: 48rpx;color: #434343;font-weight: 800;">¥ {{all}}</view>
</view>
<input type="password" v-model="payCode" placeholder="请输入支付密码" placeholder-class="placeholder-style"/>
<!-- <view class="command-btn"> -->
<!-- <view class="cancel" @tap="closePopup">取消</view> -->
<view class="confirm" @tap="commandSure">确定</view>
<!-- </view> -->
</view>
</uni-popup>
methods: {
openPay() {
if (!this.checkPrice(this.all)) { return false } //判断金额是否符合要求,all为输入的金额
this.$refs.commandPopup.open()
},
closePopup() {
this.payCode = ""
this.$refs.commandPopup.close()
},
commandSure(){
uni.request({
url: '接口地址',
method: 'POST',
data: {
'password': this.payCode
},
header: {
'Authorization': '自定义请求头信息'
},
success: (res) => {
let data = res.data
uni.showLoading({
title: '请求中...'
})
if (data.code == 1) {
this.handlePay()
}else if(data.code == 3012) {
uni.showModal({
content: "您还没设置支付密码!",
showCancel: false,
success: () => {
uni.hideLoading()
uni.navigateTo({
url:'../../mine/setting/changePayCode'
})
this.$refs.commandPopup.close()
}
});
} else {
uni.showModal({
content: data.msg,
showCancel: false,
success: () => {
uni.hideLoading()
}
});
return false
}
}
});
}
}
//判断输入金额的正则表达式
checkPrice(price) {
if (!/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(price) || price == 0) {
this.$util.modal({
title: '提示',
showCancel: false,
content: '请输入正确的金额'
})
return false
}
if (price < 1) {
this.$util.modal({
title: '提示',
showCancel: false,
content: '最低金额为1'
})
return false
}
return true
}
基本实现如下:
支付成功则跳转uni.navigateBack跳转上一级