|
|
@@ -47,7 +47,7 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
<view class="show-item">
|
|
|
- <input class="input-money" maxlength="4" placeholder="请输入金额(1-200)" v-model:value="inputMoney"
|
|
|
+ <input type="number" class="input-money" maxlength="4" placeholder="请输入金额(1-200)" v-model:value="inputMoney"
|
|
|
placeholder-class="#B3B3B3" @input="onInput" @blur="onBlur" />
|
|
|
</view>
|
|
|
<view class="submit-item">
|
|
|
@@ -79,55 +79,19 @@
|
|
|
sub_appid: '', //商户号
|
|
|
pay_info: '',
|
|
|
xiaofei_items: '', // 消费记录
|
|
|
- test: getApp().globalData.test
|
|
|
+ ceshi: 'code',
|
|
|
+ dorm_number: '',
|
|
|
+ compus: '',
|
|
|
+ test: this.$store.state.test
|
|
|
}
|
|
|
},
|
|
|
- onLoad: function(options) {
|
|
|
- let item_tmp = decodeURIComponent(options.item)
|
|
|
- //将字符串解密转换成对象
|
|
|
- let item = JSON.parse(item_tmp);
|
|
|
+ onLoad: function() {
|
|
|
+ // 初始化参数
|
|
|
+ this.$store.state.building.roomSelect = '';
|
|
|
+ this.$store.state.building.add_class = 0;
|
|
|
+ this.$store.state.building.dom = '';
|
|
|
|
|
|
- // 请求选定的月份消费记录
|
|
|
- // this.request_consumption_records()
|
|
|
- try {
|
|
|
- // 获取存储的用户数据
|
|
|
- const value = uni.getStorageSync('userinfo_storage_key')
|
|
|
- // console.log(item)
|
|
|
- if (item_tmp == '{}') { // 如果没有用户信息,返回首页
|
|
|
- uni.redirectTo({
|
|
|
- url: '../index/index'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- // 如果是选择宿舍号返回
|
|
|
- if (options.o == 'index') {
|
|
|
- this.$store.state.building.roomSelect = '';
|
|
|
- this.$store.state.building.add_class = 0;
|
|
|
- this.$store.state.building.dom = '';
|
|
|
-
|
|
|
- this.userinfo = item;
|
|
|
- // 更新存储的用户信息
|
|
|
- uni.setStorageSync('userinfo_storage_key', this.userinfo)
|
|
|
- this.roomSelect = this.campus + this.dom
|
|
|
- } else if (JSON.stringify(value) !== '{}') {
|
|
|
- this.userinfo = value;
|
|
|
- }
|
|
|
- this.campus = this.userinfo.campus
|
|
|
- this.dom = this.userinfo.dorm_number
|
|
|
- this.sub_appid = this.userinfo.sub_appid
|
|
|
-
|
|
|
- this.add_class = 1
|
|
|
- } catch (e) {
|
|
|
- console.log(e)
|
|
|
- }
|
|
|
-
|
|
|
- //将缓存中的卡号进行获取
|
|
|
- this.card_number = this.userinfo.card_number
|
|
|
-
|
|
|
- if (this.$store.state.hasUserInfo == false) {
|
|
|
- // 获取应用有效凭证
|
|
|
- this.get_valid_credentials()
|
|
|
- }
|
|
|
+ this.getCode()
|
|
|
},
|
|
|
onShow() {
|
|
|
if (this.$store.state.building.roomSelect != '') {
|
|
|
@@ -143,207 +107,109 @@
|
|
|
},
|
|
|
methods: {
|
|
|
/**
|
|
|
- * 取得电费额度
|
|
|
+ * 获得code
|
|
|
*/
|
|
|
- async getDianLiang() {
|
|
|
- let res;
|
|
|
- if (this.test) { // 测试环境
|
|
|
- res = await this.$myRequest({
|
|
|
- host: 'ceshi',
|
|
|
- url: 'http://tdqdjt.natappfree.cc/HotWaters/buildoverElec.action',
|
|
|
- method: 'POST',
|
|
|
- header: {
|
|
|
- 'content-type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- data: {
|
|
|
- 'roomSelect': this.roomSelect
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- res = await this.$myRequest({
|
|
|
- host: 'code',
|
|
|
- url: '/HotWater/buildoverElec.action',
|
|
|
- method: 'POST',
|
|
|
- header: {
|
|
|
- 'content-type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- data: {
|
|
|
- 'roomSelect': this.roomSelect
|
|
|
+ getCode(param) {
|
|
|
+ uni.login({
|
|
|
+ success: (res) => {
|
|
|
+ console.log('jiaofei', res);
|
|
|
+ if (res.code) {
|
|
|
+ this.code = res.code
|
|
|
+ // 请求服务器,获得openid
|
|
|
+ if (param == 'comfirm')
|
|
|
+ this.jsapi()
|
|
|
+ else
|
|
|
+ this.getOpenId()
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.errMsg,
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
- console.log(res.data.amount);
|
|
|
- if (res.mess != '请选择房间号!') {
|
|
|
- setTimeout(() => {
|
|
|
- this.remainElec = res.data.amount.toFixed(2)
|
|
|
- }, 300);
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: '获取电量失败!',
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- /**
|
|
|
- * 获取应用有效凭证
|
|
|
- */
|
|
|
- async get_valid_credentials() {
|
|
|
- const value = uni.getStorageSync('userinfo_storage_key')
|
|
|
- // console.log(value)
|
|
|
- const res = await this.$myRequest({
|
|
|
- host: 'wecard',
|
|
|
- url: '/cgi-bin/oauth2/token',
|
|
|
- method: 'POST',
|
|
|
- header: {
|
|
|
- 'content-type': 'application/json'
|
|
|
- },
|
|
|
- data: {
|
|
|
- 'app_key': value.appkey,
|
|
|
- 'app_secret': value.app_secret,
|
|
|
- 'grant_type': 'client_credentials',
|
|
|
- 'scope': 'base',
|
|
|
- 'ocode': value.ocode
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
- if (typeof(res.data.access_token) != 'undefined') {
|
|
|
- // 获取到应用有效凭证,保存到页面变量中
|
|
|
- this.access_token = res.data.access_token
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: '获取凭证失败',
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- // 查询用户信息
|
|
|
- this.select_user_info()
|
|
|
+ })
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
- * 查询用户信息
|
|
|
+ * 请求服务器,获得openid
|
|
|
*/
|
|
|
- async select_user_info() {
|
|
|
+ async getOpenId() {
|
|
|
const res = await this.$myRequest({
|
|
|
- host: 'code',
|
|
|
- url: '/HotWater/userget_stu.action',
|
|
|
+ host: this.ceshi,
|
|
|
+ url: '/HotWaters/wpget_stu.action',
|
|
|
method: 'POST',
|
|
|
header: {
|
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
|
},
|
|
|
data: {
|
|
|
- card_number: this.userinfo.card_number
|
|
|
+ code: this.code
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
- // console.log(res, 'select_user_info');
|
|
|
- if (res.data.info) {
|
|
|
- let cnumber = this.userinfo.card_number
|
|
|
-
|
|
|
- if (cnumber == null || cnumber == undefined || cnumber == '') {
|
|
|
- // 之前未绑定用户信息,现在去绑定用户信息
|
|
|
- this.send_save_user_info()
|
|
|
- }
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- icon: 'success',
|
|
|
- title: '获取用户信息失败'
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
+ })
|
|
|
|
|
|
- /**
|
|
|
- * 请求选定的月份消费记录
|
|
|
- */
|
|
|
- async request_consumption_records() {
|
|
|
- const userinfo = uni.getStorageInfoSync('userinfo_storage_key')
|
|
|
- this.card_number = userinfo.card_number
|
|
|
+ // console.log(res);
|
|
|
+ if (res.data.mess == '返回成功') {
|
|
|
+ this.$store.state.stu_number = res.data.info[0].stu_number
|
|
|
+ this.amount = res.data.info[0].balance
|
|
|
+ // 宿舍号
|
|
|
+ this.dorm_number = res.data.info[0].build + res.data.info[0].dom
|
|
|
+ // 校区
|
|
|
+ this.compus = res.data.info[0].campus
|
|
|
+ // 填充校区楼栋号
|
|
|
+ this.roomSelect = this.compus + this.dorm_number.split('栋')[1]
|
|
|
+ this.$store.state.building.roomSelect = this.roomSelect
|
|
|
+ this.add_class = 1
|
|
|
+
|
|
|
+ // 请求选定的月份消费记录
|
|
|
+ this.getDianLiang()
|
|
|
|
|
|
- if (this.card_number != '') {
|
|
|
- this.xiaofei_items = []
|
|
|
- const res = await this.$myRequest({
|
|
|
- host: 'code',
|
|
|
- url: '/HotWater/wxpayqueryConsume.action',
|
|
|
- method: 'POST',
|
|
|
- header: {
|
|
|
- 'content-type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- data: {
|
|
|
- card_number: this.card_number,
|
|
|
- begin_time: this.date
|
|
|
- }
|
|
|
+ } else if (res.data.mess == '未查询到用户信息') {
|
|
|
+ uni.redirectTo({
|
|
|
+ url: '../index/index'
|
|
|
});
|
|
|
-
|
|
|
- // console.log(res.data.mess, 'request_consumption_records');
|
|
|
- if (typeof(res.data.mess) != 'undefined') {
|
|
|
- let items = res.data.mess
|
|
|
- // 按时间倒序排列
|
|
|
- // items.sort((a, b) => {
|
|
|
- // return a.begin_time < b.begin_time ? 1 : -1;
|
|
|
- // })
|
|
|
- for (var i = 0; i < items.length; i++) {
|
|
|
- // 过滤掉为0的记录,只显示消费大于0的记录
|
|
|
- // if (items[i].use_amount > 0.00) {
|
|
|
- this.xiaofei_items.push(items[i])
|
|
|
- // }
|
|
|
- }
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- icon: 'success',
|
|
|
- title: '该月无消费记录'
|
|
|
- })
|
|
|
- }
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- icon: 'success',
|
|
|
- title: '用户卡号为空'
|
|
|
- })
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
- * 绑定用户信息
|
|
|
+ * 取得电费额度
|
|
|
*/
|
|
|
- async send_save_user_info() {
|
|
|
- const res = await this.$myRequest({
|
|
|
+ async getDianLiang() {
|
|
|
+ let res;
|
|
|
+ res = await this.$myRequest({
|
|
|
host: 'code',
|
|
|
- url: '/HotWater/userstu_info.action',
|
|
|
+ url: '/HotWaters/buildoverElec.action',
|
|
|
method: 'POST',
|
|
|
header: {
|
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
|
},
|
|
|
data: {
|
|
|
- user: JSON.stringify(this.userinfo)
|
|
|
+ 'roomSelect': this.roomSelect
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
|
|
|
- // console.log('send_save_user_info:', res)
|
|
|
- let error = res.data.erro;
|
|
|
- if (error == '未获取到数据!') {
|
|
|
- uni.showToast({
|
|
|
- title: '绑定用户失败',
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
+ // console.log(res);
|
|
|
+ if (res.data.mess == '0') {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.remainElec = res.data.amount.toFixed(2)
|
|
|
+ }, 30);
|
|
|
} else {
|
|
|
- uni.showToast({
|
|
|
- icon: 'success',
|
|
|
- title: '绑定用户成功',
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
+ this.remainElec = 0.00.toFixed(2)
|
|
|
+ // uni.showToast({
|
|
|
+ // // 未获取到户号
|
|
|
+ // title: res.data.mess,
|
|
|
+ // duration: 2000
|
|
|
+ // })
|
|
|
}
|
|
|
},
|
|
|
|
|
|
//跳转到选择页面
|
|
|
navigateToSelect() {
|
|
|
uni.navigateTo({
|
|
|
- url: '../select/select?roomSelect=' + this.roomSelect,
|
|
|
+ url: '../select/select',
|
|
|
});
|
|
|
},
|
|
|
|
|
|
//跳转到台账页面
|
|
|
navigateToShow(e) {
|
|
|
uni.navigateTo({
|
|
|
- url: '../show/show?card_number=' + this.card_number,
|
|
|
+ url: '../show/show',
|
|
|
});
|
|
|
},
|
|
|
|
|
|
@@ -354,12 +220,15 @@
|
|
|
|
|
|
this.confirm_room('add_money')
|
|
|
},
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 确认宿舍号
|
|
|
+ * @param {Object} op
|
|
|
+ */
|
|
|
confirm_room(op) {
|
|
|
// 检查房间号
|
|
|
if (this.roomSelect == '') {
|
|
|
uni.showToast({
|
|
|
- title: '请选择房间号',
|
|
|
+ title: '请选择宿舍号',
|
|
|
icon: 'success'
|
|
|
})
|
|
|
return
|
|
|
@@ -377,7 +246,7 @@
|
|
|
|
|
|
if (isNaN(this.inputMoney)) {
|
|
|
uni.showToast({
|
|
|
- title: '请输入数值',
|
|
|
+ title: '请输入正确金额',
|
|
|
duration: 2000
|
|
|
})
|
|
|
return
|
|
|
@@ -398,6 +267,7 @@
|
|
|
// 确认充值对话框
|
|
|
this.confirm_dialog()
|
|
|
},
|
|
|
+
|
|
|
// 确认充值对话框
|
|
|
confirm_dialog() {
|
|
|
uni.showModal({
|
|
|
@@ -405,9 +275,10 @@
|
|
|
title: '确定充值' + this.addMoney + '元',
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
- this.jsapi()
|
|
|
+ // 获取code
|
|
|
+ this.getCode('comfirm')
|
|
|
} else if (res.cancel) {
|
|
|
- console.log('用户点击取消');
|
|
|
+ // console.log('用户点击取消');
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -417,73 +288,59 @@
|
|
|
// console.log(e)
|
|
|
this.confirm_room('input_money')
|
|
|
},
|
|
|
-
|
|
|
- //准备支付
|
|
|
+ /**
|
|
|
+ * 请求服务器,获取支付参数,并支付
|
|
|
+ */
|
|
|
async jsapi() {
|
|
|
const res = await this.$myRequest({
|
|
|
- host: 'wecard',
|
|
|
- url: "/cgi-bin/pay/app/mppay",
|
|
|
+ host: this.ceshi,
|
|
|
+ url: '/HotWaters/wpPay.action',
|
|
|
method: 'POST',
|
|
|
header: {
|
|
|
- 'content-type': 'application/json'
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded'
|
|
|
},
|
|
|
data: {
|
|
|
- 'access_token': this.access_token,
|
|
|
- 'sub_appid': this.sub_appid,
|
|
|
- 'user_id': this.card_number,
|
|
|
- "order_id": this.order_id = this.$getOrderId('dianfei'),
|
|
|
- "amount": this.addMoney * 100,
|
|
|
- 'order_type': 1,
|
|
|
- 'callback_url': ''
|
|
|
+ code: this.code,
|
|
|
+ num: this.amount,
|
|
|
+ ip: this.IP
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
- if (res.data.code == 0) {
|
|
|
- this.pay_info = res.data.data.pay_info
|
|
|
- // 发起支付
|
|
|
- this.pay_amount()
|
|
|
- } else {
|
|
|
+ console.log(res);
|
|
|
+ if (res.data.pay == 'error') {
|
|
|
uni.showToast({
|
|
|
- icon: 'none',
|
|
|
- title: res.data.message,
|
|
|
+ title: '未获得支付参数',
|
|
|
+ icon: 'success',
|
|
|
duration: 3000
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- // 调起支付
|
|
|
- pay_amount() {
|
|
|
- var OpenMidas = require("@/static/openMidas.js"); // 引入小程序目录下的SDK文件
|
|
|
-
|
|
|
- // 设置支付配置
|
|
|
- wx['OpenMidasConfig'] = {
|
|
|
- apiCommonConf: {
|
|
|
- version: "weixiao"
|
|
|
- },
|
|
|
- cgiDomain: {
|
|
|
- test: "midas.weixiao.qq.com/api", // 私有化参数联系微卡客服进行获取
|
|
|
- },
|
|
|
- webDomain: "https://midas.weixiao.qq.com/h5", // 私有化参数联系微卡客服进行获取
|
|
|
- sandboxWebDomain: "https://midas.weixiao.qq.com/h5" // 私有化参数联系微卡客服进行获取
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ wx.requestPayment({
|
|
|
+ timeStamp: res.data.pay.timeStamp,
|
|
|
+ nonceStr: res.data.pay.nonceStr,
|
|
|
+ package: 'prepay_id=' + res.data.pay.prepay_id,
|
|
|
+ signType: res.data.pay.signType,
|
|
|
+ paySign: res.data.pay.paySign,
|
|
|
+ success: res => {
|
|
|
+ if (res.errMsg == 'requestPayment:ok') {
|
|
|
+ uni.showToast({
|
|
|
+ title: '支付成功',
|
|
|
+ icon: 'success'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (res) => {
|
|
|
+ if (res.errMsg == 'requestPayment:fail cancel') {
|
|
|
+ uni.showToast({
|
|
|
+ title: '取消支付',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ complete: (res) => {
|
|
|
+ console.log(res);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
- var payInfo = this.pay_info; // 请求mppay接口返回的数据
|
|
|
- // console.log(payInfo)
|
|
|
- var appMetaData = "app=test&version=1.1"; // 自定义回调数据
|
|
|
-
|
|
|
- OpenMidas.init("test");
|
|
|
- OpenMidas.pay(
|
|
|
- payInfo,
|
|
|
- function(resultCode, innerCode, resultMsg, appMetaData) {
|
|
|
- console.log(resultCode); // 支付响应状态码
|
|
|
- console.log(innerCode); // 支付响应内部错误码
|
|
|
- console.log(resultMsg); // 支付响应说明
|
|
|
- console.log(appMetaData); // 自定义回调数据
|
|
|
-
|
|
|
- // todo:处理业务逻辑
|
|
|
- },
|
|
|
- appMetaData
|
|
|
- );
|
|
|
},
|
|
|
/**
|
|
|
* 输入充值金额
|