index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. const App = getApp();
  2. // 枚举类:充值类型
  3. import RechargeTypeEnum from '../../../utils/enum/recharge/order/RechargeType.js';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userInfo: {}, // 用户信息
  10. setting: {}, // 充值设置
  11. // recharge_type: '', // 充值类型
  12. selectedPlanId: 0, // 当前选中的套餐id
  13. inputValue: '', // 自定义金额
  14. disabled: false, //按钮禁用
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad(options) {
  20. },
  21. /**
  22. * 生命周期函数--监听页面显示
  23. */
  24. onShow() {
  25. let _this = this;
  26. // 获取充值中心数据
  27. _this.getRechargeIndex();
  28. },
  29. /**
  30. * 获取充值中心数据
  31. */
  32. getRechargeIndex() {
  33. let _this = this;
  34. App._get('recharge/index', {}, function(result) {
  35. _this.setData(result.data);
  36. });
  37. },
  38. /**
  39. * 选择充值套餐
  40. */
  41. onSelectPlan(e) {
  42. let _this = this;
  43. _this.setData({
  44. selectedPlanId: e.currentTarget.dataset.id,
  45. inputValue: ''
  46. });
  47. },
  48. /**
  49. * 绑定金额输入框
  50. */
  51. bindMoneyInput(e) {
  52. let _this = this;
  53. _this.setData({
  54. inputValue: e.detail.value,
  55. selectedPlanId: 0
  56. })
  57. },
  58. /**
  59. * 立即充值
  60. */
  61. onSubmit(e) {
  62. let _this = this;
  63. // 按钮禁用
  64. _this.setData({
  65. disabled: true
  66. });
  67. // 提交到后端
  68. App._post_form('recharge/submit', {
  69. planId: _this.data.selectedPlanId,
  70. customMoney: _this.data.inputValue
  71. }, (result) => {
  72. // 发起微信支付
  73. App.wxPayment({
  74. payment: result.data.payment,
  75. success() {
  76. App.showSuccess(result.msg.success, () => {
  77. wx.navigateBack();
  78. });
  79. },
  80. fail(res) {
  81. App.showError(result.msg.error);
  82. },
  83. complete(res) {
  84. }
  85. });
  86. }, false, () => {
  87. // 解除禁用
  88. _this.setData({
  89. disabled: false
  90. });
  91. });
  92. },
  93. })