|
@@ -1,15 +1,92 @@
|
|
|
const app = getApp();
|
|
|
+import WxValidate from '../../../utils/wxValidate'
|
|
|
+
|
|
|
Page({
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
frameStyle: { useTop: true, name: '账号余额', leftArrow: true, useBar: false },
|
|
|
+ user: {},
|
|
|
+ list: [],
|
|
|
+ total: 0,
|
|
|
+ skip: 0,
|
|
|
+ limit: 6,
|
|
|
+ page: 0,
|
|
|
+ // dialog弹框
|
|
|
+ dialog: { title: '充值', show: false, type: '1' },
|
|
|
+ form: {},
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { money: { required: true }, }
|
|
|
+ // 验证字段的提示信息,若不传则调用默认的信息
|
|
|
+ const messages = { money: { required: '请输入充值金额', } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
},
|
|
|
// 跳转菜单
|
|
|
back(e) {
|
|
|
wx.navigateBack({ delta: 1 })
|
|
|
},
|
|
|
+ // 清空列表
|
|
|
+ clearPage() {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ list: [], skip: 0, limit: 6, page: 0 })
|
|
|
+ },
|
|
|
+ // 充值
|
|
|
+ toMoney(e) {
|
|
|
+ const that = this;
|
|
|
+ let { item } = e.currentTarget.dataset;
|
|
|
+ let user = that.data.user;
|
|
|
+ that.clearPage();
|
|
|
+ that.setData({ form: { openid: user.openid, student_id: item.student_id, school_id: item.school_id } })
|
|
|
+ that.setData({ dialog: { title: '充值', show: true, type: '1' } })
|
|
|
+ },
|
|
|
+ // 提交保存
|
|
|
+ onSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const params = e.detail.value;
|
|
|
+ if (!this.WxValidate.checkForm(params)) {
|
|
|
+ const error = this.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ params.money = parseFloat(params.money);
|
|
|
+ that.createMoney(params)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 充值
|
|
|
+ async createMoney(e) {
|
|
|
+ const that = this;
|
|
|
+ let res = await app.$post(`/payOrder/toCharge`, e);
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ // 调取支付窗口
|
|
|
+ let wxSign = res.data.wxSign;
|
|
|
+ wx.requestPayment({
|
|
|
+ timeStamp: wxSign.timestamp,
|
|
|
+ nonceStr: wxSign.nonceStr,
|
|
|
+ package: `prepay_id=${wxSign.prepay_id}`,
|
|
|
+ signType: wxSign.signType,
|
|
|
+ paySign: wxSign.paySign,
|
|
|
+ async success(payRes) {
|
|
|
+ wx.showToast({ title: '充值成功', icon: 'none' })
|
|
|
+ that.toClose();
|
|
|
+ },
|
|
|
+ async fail(payErr) {
|
|
|
+ console.log(payErr);
|
|
|
+ wx.showToast({ title: '充值不成功', icon: 'none' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: res.errmsg, icon: 'none' })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 关闭弹框
|
|
|
+ toClose: function () {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ form: {} })
|
|
|
+ that.setData({ dialog: { title: '充值', show: false, type: '1' } })
|
|
|
+ that.search()
|
|
|
+ },
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
@@ -27,12 +104,53 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
- onShow: function () {
|
|
|
+ onShow: async function () {
|
|
|
const that = this;
|
|
|
-
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
+ // 监听用户是否登录
|
|
|
+ await that.watchLogin();
|
|
|
+ },
|
|
|
+ watchLogin() {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'user',
|
|
|
+ success: async res => {
|
|
|
+ that.setData({ user: res.data });
|
|
|
+ // 查询列表
|
|
|
+ await that.search()
|
|
|
+ },
|
|
|
+ fail: async res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async search() {
|
|
|
+ const that = this;
|
|
|
+ let user = that.data.user;
|
|
|
+ let info = { skip: that.data.skip, limit: that.data.limit, student_id: user.info.id }
|
|
|
+ let res = await app.$get(`/rss`, { ...info });
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ let list = [...that.data.list, ...res.data];
|
|
|
+ that.setData({ list })
|
|
|
+ that.setData({ total: res.total })
|
|
|
+ } else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
|
|
|
+ },
|
|
|
+ // 分页
|
|
|
+ toPage: function () {
|
|
|
+ const that = this;
|
|
|
+ let list = that.data.list;
|
|
|
+ let limit = that.data.limit;
|
|
|
+ if (that.data.total > list.length) {
|
|
|
+ wx.showLoading({ title: '加载中', mask: true })
|
|
|
+ let page = that.data.page + 1;
|
|
|
+ that.setData({ page: page })
|
|
|
+ let skip = page * limit;
|
|
|
+ that.setData({ skip: skip })
|
|
|
+ that.search();
|
|
|
+ wx.hideLoading()
|
|
|
+ } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
|
|
|
},
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|