| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- <template>
- <view class="container">
- <view class="line"></view>
- <view class="top">
- <view class="it">
- <view class="nv">
- <image src="../static/images/ye.png" mode=""></image>
- <view class="title">账户余额</view>
- <view class="bal">¥{{balance.toFixed(2)}}</view>
- </view>
- </view>
- <view class="it">
- <navigator class="nv" url="/pagesAir/rechargeRecord/rechargeRecord">
- <image src="../static/images/jl.png" mode=""></image>
- <view class="title">充值记录</view>
- </navigator>
- </view>
- </view>
- <view class="line"></view>
- <view class="middle-title">
- <image src="../static/images/cz.png" mode=""></image>
- <view class="txt">充值</view>
- </view>
- <view class="line"></view>
- <view class="middle-balance">
- <view class="balance" @tap="Recharge(10)" :class="{balanceborder: amount == 10}">10元</view>
- <view class="balance" @tap="Recharge(20)" :class="{balanceborder: amount == 20}">20元</view>
- <view class=" balance" @tap="Recharge(30)" :class="{balanceborder: amount == 30}">30元</view>
- <view class=" balance" @tap="Recharge(40)" :class="{balanceborder: amount == 40}">40元</view>
- <view class=" balance" @tap="Recharge(50)" :class="{balanceborder: amount == 50}">50元</view>
- <view class=" balance" @tap="Recharge(60)" :class="{balanceborder: amount == 60}">60元</view>
- </view>
- <view class=" line"></view>
- <input class="input-balance" type="text" v-model="amount" @input="onInput" @blur="onBlur" placeholder="请输入充值金额,金额大于10" placeholder-class="pc"
- maxlength="4" />
- <view class="line"></view>
- <view class="btn-pay">
- <button class="btn" url="/pagesAir/rechargeRecord/rechargeRecord" @tap="btn_click">
- <text class="">立即付款</text>
- </button>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- ceshi: 'air',
- id_card: '',
- appkey: '3183DC96A6DABA8D', // 商户appkey
- ocode: '1015730314', // 获取用户信息
- app_secret: '05742955578EC5BD29B7BC4CAC5AFACA', // 获取用户信息
- balance: 0.00, // 余额
- amount: '', // 充值金额
- IP: '',
- test: this.$store.state.test
- }
- },
- onLoad(options) {
- // 系统正在维护...
- if (this.test == 'weihuzhong') {
- uni.redirectTo({
- url: '../../pages/index/index'
- })
- return;
- }
- // 测试环境
- if (this.test) {
- this.amount = 0.01
- }
- // 获取身份证号
- this.get_base_info(options)
- },
- methods: {
- /**
- * 打开页面时提示
- */
- tip() {
- uni.showModal({
- title: '提示',
- content: '目前只针对墨轩湖校区【公共区域】进行充值,不包含宿舍区域!请知晓!',
- showCancel: false,
- confirmText: '我已知晓',
- confirmColor: '#F00',
- success: function(res) {
- if (res.confirm) {
- // console.log('用户点击确定');
- }
- }
- });
- },
- /**
- * 获取身份证号
- */
- get_base_info(options) {
- try {
- if (this.id_card == '' || typeof(this.id_card) == 'undefined') {
- const userinfo = uni.getStorageSync('userinfo_storage_key')
- if (userinfo) {
- this.id_card = userinfo.id_card
- } else {
- uni.navigateTo({
- url: '../../pages/index/index?from=' + options.from
- })
- uni.showToast({
- icon: 'none',
- title: '身份证号为空,请进行授权',
- duration: 3000
- });
- return
- }
- }
- } catch (e) {
- console.log('获取基本信息:' + e.message);
- }
- // 请求服务器,获得余额
- this.getBalance();
-
- this.tip();
- },
- /**
- * 请求服务器,获得余额
- */
- async getBalance() {
- const res = await this.$myRequest({
- host: this.ceshi,
- url: '/airManage/usersqueryYu.action',
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data: {
- // sfzh: '3602123654'
- sfzh: this.id_card
- }
- })
- // console.log(res.data);
- let data = res.data
- if (data.code === 200) {
- if (typeof data.data != 'undefined' && data.data != '' && JSON.stringify(data.data) != '{}') {
- this.balance = data.data.balance
- } else {
- uni.showToast({
- title: '未查询到余额!',
- icon: 'success'
- });
- }
- } else {
- uni.showToast({
- title: data.data.message
- })
- }
- },
- /**
- * 选择了充值金额
- * @param {Object} param
- */
- Recharge(param) {
- this.amount = param
- },
- /**
- * 获得code
- */
- getCode() {
- uni.login({
- success: (res) => {
- // console.log('recharge', res);
- if (res.code) {
- // 发起支付
- this.jsapi(res.code)
- } else {
- uni.showToast({
- title: res.errMsg,
- icon: 'none'
- });
- }
- }
- })
- },
- /**
- * 请求服务器,获取支付参数,并支付
- */
- async jsapi(param_code) {
- if (param_code == '' || this.amount == '' || this.id_card == '') {
- uni.showToast({
- icon: 'none',
- title: 'code、充值金额 或 身份证号为空',
- duration: 3000
- });
- return
- }
- const res = await this.$myRequest({
- host: this.ceshi,
- url: '/airManage/rechargepay_ns.action',
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data: {
- sfzh: this.id_card,
- code: param_code,
- num: this.amount
- }
- })
- // console.log(res);
- if (res.statusCode !== 200) {
- uni.showToast({
- title: '未获得支付参数',
- icon: 'success',
- duration: 3000
- });
- } else {
- if (res.data.code === 205) {
- uni.showToast({
- title: '服务器返回:' + res.data.message,
- icon: 'none',
- duration: 3000
- });
- return
- }
- // 调起微信支付
- wx.requestPayment({
- timeStamp: res.data.timeStamp,
- nonceStr: res.data.nonceStr,
- package: res.data.package,
- signType: res.data.signType,
- paySign: res.data.paySign,
- success: (res) => {
- if (res.errMsg == 'requestPayment:ok') {
- let _this = this;
- // 提示用户支付成功
- uni.showToast({
- title: '支付成功',
- icon: 'success',
- duration: 2000,
- success() {
- // 请求服务器,获得余额
- _this.getBalance()
- }
- });
- }
- },
- fail: (res) => {
- if (res.errMsg == 'requestPayment:fail cancel') {
- // 提示用户已经取消支付了
- uni.showToast({
- title: '支付已取消',
- icon: 'success',
- duration: 2000
- });
- }
- },
- complete: (res) => {
- // console.log(res);
- }
- });
- }
- },
- /**
- * 输入充值金额
- */
- onInput(e) {
- if (this.test) { // 测试环境
- return
- }
- const v = e.detail.value
- const zero = /^(0{1,})|[^0-9]/g
- let final = 0
- if (!v) {
- final = 0
- } else {
- final = v.toString().replace(zero, (v) => {
- return 0
- })
- if (final.split('')[0] * 1 === 0) {
- final = final.slice(1) - 0 || 0
- }
- if (final > 100) {
- final = 100
- }
- }
- this.$nextTick(() => {
- if (final.toString() == '0') {
- this.amount = ''
- } else {
- this.amount = final.toString() || '0'
- }
- })
- },
- /**
- * 输入框,失去焦点时
- */
- onBlur() {
- if (this.test) { // 测试环境
- return
- }
- if (this.amount < 10) {
- this.amount = 10
- }
- },
- /**
- * 立即付款
- */
- btn_click() {
- // console.log(this.amount);
- if (isNaN(this.amount)) {
- uni.showToast({
- title: '请输入正确金额',
- duration: 2000
- })
- return
- }
- // 测试环境下执行
- if (this.test) { // 测试环境
- uni.showModal({
- title: '提示',
- content: '您选择了充值:¥' + this.amount + ' 元',
- cancelText: '算了',
- confirmText: '充值',
- success: (res) => {
- if (res.confirm) {
- // 获取code
- this.getCode()
- } else if (res.cancel) {
- return
- }
- }
- })
- return
- }
- // 生产环境
- if (this.amount < 10 || this.amount > 100) {
- uni.showToast({
- icon: 'none',
- title: '最少充值10元,最多充值100元!',
- mask: true,
- duration: 3000
- })
- return
- }
- // 确认
- uni.showModal({
- title: '提示',
- content: '您选择了充值:¥' + this.amount + ' 元',
- cancelText: '算了',
- confirmText: '充值',
- success: (res) => {
- if (res.confirm) {
- // 获取code
- this.getCode()
- } else if (res.cancel) {
- return
- }
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .container {
- display: flex;
- flex-direction: column;
- font-size: 28rpx;
- font-family: "Microsoft YaHei-3970(82674968)";
- width: 730rpx;
- padding: 10rpx;
- .line {
- height: 20rpx;
- }
- .top {
- display: flex;
- justify-content: space-around;
- height: 220rpx;
- border-radius: 10rpx;
- padding-top: 30rpx;
- background-color: #EFF2F9;
- .it {
- display: flex;
- flex-direction: column;
- align-items: center;
- .nv {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 18rpx;
- border-radius: 10rpx;
- }
- image {
- width: 60rpx;
- height: 60rpx;
- margin-bottom: 14rpx;
- }
- .title {
- font-size: 36upx;
- }
- .bal {
- font-size: 26upx;
- color: #666666;
- }
- }
- }
- .middle-title {
- display: flex;
- align-items: center;
- image {
- width: 36rpx;
- height: 36rpx;
- margin-right: 10rpx;
- }
- .txt {
- font-size: 32upx;
- }
- }
- .middle-balance {
- display: flex;
- justify-content: space-around;
- align-items: center;
- flex-wrap: wrap;
- height: 280rpx;
- .balance {
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 36upx;
- font-family: Microsoft YaHei-3970(82674968);
- font-weight: bold;
- color: #333333;
- padding: 36rpx 0;
- width: 220rpx;
- background-color: #EFF2F9;
- border-radius: 6rpx;
- }
- .balanceborder {
- border: 1px solid #3869FC;
- width: 218rpx;
- padding: 34rpx 0;
- }
- }
- .input-balance {
- font-size: 40upx;
- height: 80rpx;
- background-color: #F2F2F2;
- border-radius: 6rpx;
- margin: 0 10rpx;
- padding: 10rpx 20rpx;
- }
- .pc {
- color: #B3B3B3;
- }
- .btn-pay {
- display: flex;
- justify-content: center;
- align-items: center;
- .btn {
- display: flex;
- justify-content: center;
- align-items: center;
- margin: 30rpx;
- width: 280rpx;
- height: 100rpx;
- background: #3869FC;
- border-radius: 6px;
- font-size: 36upx;
- font-family: Microsoft YaHei-3970(82674968);
- font-weight: 400;
- color: #FFFFFF;
- }
- }
- }
- </style>
|