index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. var app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. needAuth: false,
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad: function (options) {
  13. },
  14. authSuccess: function() {
  15. this.setData({ showAuthModal: false, needAuth: false });
  16. },
  17. formSubmit(e) {
  18. console.log('form发生了submit事件,携带数据为:', e.detail.value)
  19. let code_sn = e.detail.value.code_sn || "";
  20. if(!code_sn) {
  21. wx.showToast({
  22. title: '请输入卡密',
  23. icon: "none"
  24. })
  25. return;
  26. }
  27. wx.showLoading();
  28. let token = wx.getStorageSync('token');
  29. app.util.ProReq('virtualcard.subOfflineCode', {
  30. token,
  31. code_sn
  32. }).then(res => {
  33. wx.hideLoading();
  34. wx.showModal({
  35. title: "提示",
  36. content: "您已成功充值"+res.money+"元",
  37. showCancel: false
  38. })
  39. }).catch(err => {
  40. wx.hideLoading();
  41. if(err.code==1) {
  42. //未登录
  43. this.setData({ showAuthModal: !this.data.showAuthModal, needAuth: true });
  44. } else {
  45. wx.showModal({
  46. title: "提示",
  47. content: err.message || "充值失败,请重试",
  48. showCancel: false
  49. })
  50. }
  51. })
  52. },
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow: function () {
  57. }
  58. })