|
@@ -30,6 +30,9 @@
|
|
|
:class="{'bg-color':add_class1==1}">10元</button>
|
|
:class="{'bg-color':add_class1==1}">10元</button>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="add-money-button">
|
|
<view class="add-money-button">
|
|
|
|
|
+ <button class="select-submit" :data-item="20" @tap="add_money">20元</button>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <view class="add-money-button">
|
|
|
<button class="select-submit" :data-item="30" @tap="add_money">30元</button>
|
|
<button class="select-submit" :data-item="30" @tap="add_money">30元</button>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="add-money-button">
|
|
<view class="add-money-button">
|
|
@@ -41,14 +44,11 @@
|
|
|
<view class="add-money-button">
|
|
<view class="add-money-button">
|
|
|
<button class="select-submit" :data-item="200" @tap="add_money">200元</button>
|
|
<button class="select-submit" :data-item="200" @tap="add_money">200元</button>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="add-money-button">
|
|
|
|
|
- <button class="select-submit" :data-item="300" @tap="add_money">300元</button>
|
|
|
|
|
- </view>
|
|
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="show-item">
|
|
<view class="show-item">
|
|
|
- <input class="input-money" placeholder="请输入金额(1-1000)" v-model:value="inputMoney"
|
|
|
|
|
- placeholder-class="#B3B3B3" @input="onInput" />
|
|
|
|
|
|
|
+ <input class="input-money" maxlength="4" placeholder="请输入金额(1-200)" v-model:value="inputMoney"
|
|
|
|
|
+ placeholder-class="#B3B3B3" @input="onInput" @blur="onBlur" />
|
|
|
</view>
|
|
</view>
|
|
|
<view class="submit-item">
|
|
<view class="submit-item">
|
|
|
<button class="submit" :data-rooms='room' @tap="input_money">充值</button>
|
|
<button class="submit" :data-rooms='room' @tap="input_money">充值</button>
|
|
@@ -64,43 +64,34 @@
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
index: 0,
|
|
index: 0,
|
|
|
- roomSelect: '请选择房间号', //房间号
|
|
|
|
|
|
|
+ roomSelect: '', //房间号
|
|
|
remainElec: 80.1, //剩余电量
|
|
remainElec: 80.1, //剩余电量
|
|
|
add_class: '', //增加class属性
|
|
add_class: '', //增加class属性
|
|
|
add_class1: '',
|
|
add_class1: '',
|
|
|
inputMoney: '', //手动输入增加金额
|
|
inputMoney: '', //手动输入增加金额
|
|
|
addMoney: 0, //选择充值金额
|
|
addMoney: 0, //选择充值金额
|
|
|
- // add_class_money: '',
|
|
|
|
|
userinfo: {}, //用户信息
|
|
userinfo: {}, //用户信息
|
|
|
- card_number: 0, //用户卡号
|
|
|
|
|
|
|
+ order_id: '', // 订单号
|
|
|
|
|
+ card_number: '', //用户卡号
|
|
|
dom: '', //房间号
|
|
dom: '', //房间号
|
|
|
campus: '', //校区
|
|
campus: '', //校区
|
|
|
access_token: '',
|
|
access_token: '',
|
|
|
sub_appid: '', //商户号
|
|
sub_appid: '', //商户号
|
|
|
- order_id: '', //订单号
|
|
|
|
|
pay_info: '',
|
|
pay_info: '',
|
|
|
- item: {},
|
|
|
|
|
- // storage: {},
|
|
|
|
|
|
|
+ test: getApp().globalData.test
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
- onPullDownRefresh: function() {
|
|
|
|
|
- uni.navigateTo({
|
|
|
|
|
- url: '../jiaofei/jiaofei',
|
|
|
|
|
- });
|
|
|
|
|
- // console.log('触发了下拉刷新')
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
onLoad: function(options) {
|
|
onLoad: function(options) {
|
|
|
// console.log('item:' + options.item);
|
|
// console.log('item:' + options.item);
|
|
|
- // console.log(options.item.card_number)
|
|
|
|
|
try {
|
|
try {
|
|
|
// 获取存储的用户数据
|
|
// 获取存储的用户数据
|
|
|
- const value = uni.getStorageSync('userinfo_storage_key');
|
|
|
|
|
|
|
+ const value = uni.getStorageSync('userinfo_storage_key')
|
|
|
|
|
+ let item_tmp = decodeURIComponent(options.item)
|
|
|
|
|
+
|
|
|
//将字符串解密转换成对象
|
|
//将字符串解密转换成对象
|
|
|
- let item = JSON.parse(decodeURIComponent(options.item));
|
|
|
|
|
|
|
+ let item = JSON.parse(item_tmp);
|
|
|
// console.log(item)
|
|
// console.log(item)
|
|
|
- if (JSON.stringify(item) === '{}') { // 如果没有用户信息,返回首页
|
|
|
|
|
|
|
+ if (item_tmp == '{}') { // 如果没有用户信息,返回首页
|
|
|
uni.redirectTo({
|
|
uni.redirectTo({
|
|
|
url: '../index/index'
|
|
url: '../index/index'
|
|
|
});
|
|
});
|
|
@@ -108,14 +99,14 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//判断item是否存在
|
|
//判断item是否存在
|
|
|
- if (JSON.stringify(item) != '') {
|
|
|
|
|
|
|
+ if (item_tmp != '') {
|
|
|
//判断是哪个页面传入
|
|
//判断是哪个页面传入
|
|
|
if (typeof(item.roomSelect) != 'undefined') {
|
|
if (typeof(item.roomSelect) != 'undefined') {
|
|
|
// this.item = item;
|
|
// this.item = item;
|
|
|
this.roomSelect = item.roomSelect;
|
|
this.roomSelect = item.roomSelect;
|
|
|
this.add_class = 1;
|
|
this.add_class = 1;
|
|
|
this.dom = item.dom;
|
|
this.dom = item.dom;
|
|
|
- console.log(this.roomSelect)
|
|
|
|
|
|
|
+ // console.log(this.roomSelect)
|
|
|
} else {
|
|
} else {
|
|
|
// 处理JSON字符串
|
|
// 处理JSON字符串
|
|
|
// this.userinfo = options.item.replace(/"/g, "'");
|
|
// this.userinfo = options.item.replace(/"/g, "'");
|
|
@@ -123,13 +114,11 @@
|
|
|
// 更新存储的用户信息
|
|
// 更新存储的用户信息
|
|
|
uni.setStorageSync('userinfo_storage_key', this.userinfo)
|
|
uni.setStorageSync('userinfo_storage_key', this.userinfo)
|
|
|
// console.log(this.userinfo)
|
|
// console.log(this.userinfo)
|
|
|
- this.card_number = this.userinfo.card_number
|
|
|
|
|
this.campus = this.userinfo.campus
|
|
this.campus = this.userinfo.campus
|
|
|
this.dom = this.userinfo.dorm_number
|
|
this.dom = this.userinfo.dorm_number
|
|
|
|
|
+ this.sub_appid = this.userinfo.sub_appid
|
|
|
this.roomSelect = this.campus + this.dom
|
|
this.roomSelect = this.campus + this.dom
|
|
|
- this.add_class = 1;
|
|
|
|
|
- this.order_id = get_order_id();
|
|
|
|
|
- this.sub_appid = this.userinfo.sub_appid;
|
|
|
|
|
|
|
+ this.add_class = 1
|
|
|
}
|
|
}
|
|
|
} else if (value != '') {
|
|
} else if (value != '') {
|
|
|
// 处理JSON字符串
|
|
// 处理JSON字符串
|
|
@@ -141,17 +130,12 @@
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
console.log(e)
|
|
console.log(e)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//将缓存中的卡号进行获取
|
|
//将缓存中的卡号进行获取
|
|
|
this.card_number = this.userinfo.card_number
|
|
this.card_number = this.userinfo.card_number
|
|
|
|
|
|
|
|
// 查询用户信息
|
|
// 查询用户信息
|
|
|
this.get_valid_credentials()
|
|
this.get_valid_credentials()
|
|
|
-
|
|
|
|
|
- // console.log('房间号' + this.dom)
|
|
|
|
|
-
|
|
|
|
|
- //将缓存中的token码进行获取
|
|
|
|
|
- // this.access_token = uni.getStorageSync('userinfo_storage_key').access_token
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
methods: {
|
|
@@ -166,6 +150,8 @@
|
|
|
* 获取应用有效凭证
|
|
* 获取应用有效凭证
|
|
|
*/
|
|
*/
|
|
|
async get_valid_credentials() {
|
|
async get_valid_credentials() {
|
|
|
|
|
+ const value = uni.getStorageSync('userinfo_storage_key')
|
|
|
|
|
+ // console.log(value)
|
|
|
const res = await this.$myRequest({
|
|
const res = await this.$myRequest({
|
|
|
host: 'wecard',
|
|
host: 'wecard',
|
|
|
url: '/cgi-bin/oauth2/token',
|
|
url: '/cgi-bin/oauth2/token',
|
|
@@ -174,11 +160,11 @@
|
|
|
'content-type': 'application/json'
|
|
'content-type': 'application/json'
|
|
|
},
|
|
},
|
|
|
data: {
|
|
data: {
|
|
|
- 'app_key': this.userinfo.appkey,
|
|
|
|
|
- 'app_secret': this.userinfo.app_secret,
|
|
|
|
|
|
|
+ 'app_key': value.appkey,
|
|
|
|
|
+ 'app_secret': value.app_secret,
|
|
|
'grant_type': 'client_credentials',
|
|
'grant_type': 'client_credentials',
|
|
|
'scope': 'base',
|
|
'scope': 'base',
|
|
|
- 'ocode': this.userinfo.ocode
|
|
|
|
|
|
|
+ 'ocode': value.ocode
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -192,11 +178,11 @@
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//跳转到选择页面
|
|
//跳转到选择页面
|
|
|
navigateToSelect() {
|
|
navigateToSelect() {
|
|
|
uni.navigateTo({
|
|
uni.navigateTo({
|
|
|
- url: '../select/select',
|
|
|
|
|
|
|
+ url: '../select/select?roomSelect=' + this.roomSelect,
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -211,72 +197,75 @@
|
|
|
add_money(e) {
|
|
add_money(e) {
|
|
|
this.add_class1 = 0
|
|
this.add_class1 = 0
|
|
|
this.addMoney = e.currentTarget.dataset.item
|
|
this.addMoney = e.currentTarget.dataset.item
|
|
|
|
|
+
|
|
|
|
|
+ this.confirm_info()
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ confirm_info(num_money) {
|
|
|
|
|
+ if (this.roomSelect == '') {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '请选择房间号',
|
|
|
|
|
+ icon:'success'
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
uni.showModal({
|
|
uni.showModal({
|
|
|
// title: '确定充值'+this.inputMoney+'元',
|
|
// title: '确定充值'+this.inputMoney+'元',
|
|
|
title: '确定充值' + this.addMoney + '元',
|
|
title: '确定充值' + this.addMoney + '元',
|
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
if (res.confirm) {
|
|
|
- // console.log('用户点击确定');
|
|
|
|
|
- // console.log(this.addMoney);
|
|
|
|
|
this.pay_money_start()
|
|
this.pay_money_start()
|
|
|
- // console.log(this.access_token)
|
|
|
|
|
- // console.log('卡号' + this.card_number)
|
|
|
|
|
- // console.log(this.sub_appid)
|
|
|
|
|
- // console.log(this.order_id)
|
|
|
|
|
- // console.log(this.addMoney)
|
|
|
|
|
} else if (res.cancel) {
|
|
} else if (res.cancel) {
|
|
|
console.log('用户点击取消');
|
|
console.log('用户点击取消');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // this.pay_money_start()
|
|
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
//增加可变金额
|
|
//增加可变金额
|
|
|
input_money(e) {
|
|
input_money(e) {
|
|
|
-
|
|
|
|
|
// console.log(e)
|
|
// console.log(e)
|
|
|
//判断输入是否为空或不是数字
|
|
//判断输入是否为空或不是数字
|
|
|
if (this.inputMoney == '' || this.inputMoney == null) {
|
|
if (this.inputMoney == '' || this.inputMoney == null) {
|
|
|
uni.showToast({
|
|
uni.showToast({
|
|
|
- title: '请输入',
|
|
|
|
|
- duration: 2000
|
|
|
|
|
- });
|
|
|
|
|
- } else if (isNaN(this.inputMoney)) {
|
|
|
|
|
- uni.showToast({
|
|
|
|
|
- title: '输入错误',
|
|
|
|
|
|
|
+ title: '请输入充值金额',
|
|
|
duration: 2000
|
|
duration: 2000
|
|
|
- });
|
|
|
|
|
- } else if (this.inputMoney > 1000 || this.inputMoney < 0) {
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isNaN(this.inputMoney)) {
|
|
|
uni.showToast({
|
|
uni.showToast({
|
|
|
- title: '超出范围',
|
|
|
|
|
|
|
+ title: '请输入数值',
|
|
|
duration: 2000
|
|
duration: 2000
|
|
|
- });
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.test) {
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
- this.addMoney = this.inputMoney
|
|
|
|
|
- uni.showModal({
|
|
|
|
|
- // title: '确定充值'+this.inputMoney+'元',
|
|
|
|
|
- title: '确定充值' + this.addMoney + '元',
|
|
|
|
|
- success: (res) => {
|
|
|
|
|
- if (res.confirm) {
|
|
|
|
|
- // console.log('用户点击确定');
|
|
|
|
|
- // console.log(this.addMoney)
|
|
|
|
|
- this.pay_money_start()
|
|
|
|
|
- } else if (res.cancel) {
|
|
|
|
|
- console.log('用户点击取消');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (this.inputMoney > 200 || this.inputMoney < 10) {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '限额10~200元',
|
|
|
|
|
+ duration: 2000
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ this.addMoney = this.inputMoney
|
|
|
|
|
+
|
|
|
|
|
+ this.confirm_info()
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
//准备支付
|
|
//准备支付
|
|
|
async pay_money_start() {
|
|
async pay_money_start() {
|
|
|
const res = await this.$myRequest({
|
|
const res = await this.$myRequest({
|
|
|
- // ip: 'https://open.wecard.qq.com',
|
|
|
|
|
host: 'wecard',
|
|
host: 'wecard',
|
|
|
url: "/cgi-bin/pay/app/mppay",
|
|
url: "/cgi-bin/pay/app/mppay",
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
@@ -287,16 +276,11 @@
|
|
|
'access_token': this.access_token,
|
|
'access_token': this.access_token,
|
|
|
'sub_appid': this.sub_appid,
|
|
'sub_appid': this.sub_appid,
|
|
|
'user_id': this.card_number,
|
|
'user_id': this.card_number,
|
|
|
- "order_id": this.order_id,
|
|
|
|
|
|
|
+ "order_id": this.order_id = get_order_id('dianfei'),
|
|
|
"amount": this.addMoney * 100,
|
|
"amount": this.addMoney * 100,
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- console.log(this.access_token)
|
|
|
|
|
- console.log(this.sub_appid)
|
|
|
|
|
- console.log(this.card_number)
|
|
|
|
|
- console.log(this.order_id)
|
|
|
|
|
- console.log(this.addMoney)
|
|
|
|
|
- console.log(res.data)
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
if (res.data.code == 0) {
|
|
if (res.data.code == 0) {
|
|
|
this.pay_info = res.data.data.pay_info
|
|
this.pay_info = res.data.data.pay_info
|
|
|
// 发起支付
|
|
// 发起支付
|
|
@@ -348,6 +332,10 @@
|
|
|
* 输入充值金额
|
|
* 输入充值金额
|
|
|
*/
|
|
*/
|
|
|
onInput(e) {
|
|
onInput(e) {
|
|
|
|
|
+ if (this.test) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const v = e.detail.value
|
|
const v = e.detail.value
|
|
|
this.inputMoney = 10
|
|
this.inputMoney = 10
|
|
|
|
|
|
|
@@ -364,18 +352,30 @@
|
|
|
final = final.slice(1) - 0 || 0
|
|
final = final.slice(1) - 0 || 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (final > 1000) {
|
|
|
|
|
- final = 1000
|
|
|
|
|
|
|
+ if (final > 200) {
|
|
|
|
|
+ final = 200
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
|
this.inputMoney = final.toString() || '0'
|
|
this.inputMoney = final.toString() || '0'
|
|
|
})
|
|
})
|
|
|
|
|
+ },
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 失去焦点时
|
|
|
|
|
+ */
|
|
|
|
|
+ onBlur() {
|
|
|
|
|
+ if (this.test) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (this.inputMoney < 10) {
|
|
|
|
|
+ this.inputMoney = 10
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function get_order_id() {
|
|
|
|
|
|
|
+ function get_order_id(head) {
|
|
|
const date = new Date()
|
|
const date = new Date()
|
|
|
|
|
|
|
|
let year = date.getFullYear()
|
|
let year = date.getFullYear()
|
|
@@ -385,14 +385,20 @@
|
|
|
let minute = date.getMinutes()
|
|
let minute = date.getMinutes()
|
|
|
let second = date.getSeconds()
|
|
let second = date.getSeconds()
|
|
|
let millisecond = date.getMilliseconds()
|
|
let millisecond = date.getMilliseconds()
|
|
|
|
|
+ let len_mill = millisecond.length
|
|
|
|
|
|
|
|
month = month > 9 ? month : '0' + month
|
|
month = month > 9 ? month : '0' + month
|
|
|
day = day > 9 ? day : '0' + day
|
|
day = day > 9 ? day : '0' + day
|
|
|
second = second > 9 ? second : '0' + second
|
|
second = second > 9 ? second : '0' + second
|
|
|
- // 小于4位数,前补0
|
|
|
|
|
- millisecond = millisecond.length < 3 ? '0' + millisecond : millisecond
|
|
|
|
|
|
|
+ if (len_mill == 1) {
|
|
|
|
|
+ millisecond = '000' + millisecond
|
|
|
|
|
+ } else if (len_mill == 2) {
|
|
|
|
|
+ millisecond = '00'
|
|
|
|
|
+ } else if (len_mill == 3) {
|
|
|
|
|
+ millisecond = '0' + millisecond
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return `${year}${month}${day}${hour}${minute}${second}${millisecond}`
|
|
|
|
|
|
|
+ return `${head}${year}${month}${day}${hour}${minute}${second}${millisecond}`
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|