index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // pages/storedValue/index.js
  2. import {
  3. get,
  4. post
  5. } from '../../utils/http'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. selectRe: 0,
  12. agree: true,
  13. // 自定义金额
  14. money: null,
  15. // 控制自定义金额显示
  16. isShow: 1,
  17. },
  18. // 获取输入的自定义金额
  19. getInput(e) {
  20. this.setData({
  21. money: e.detail.value
  22. })
  23. },
  24. agree() {
  25. this.setData({
  26. agree: !this.data.agree
  27. })
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. this.getRecharge()
  34. this.getAmount()
  35. },
  36. submitRe() {
  37. if (!this.data.agree) {
  38. wx.showToast({
  39. title: '请先勾选同意jolijoli充值协议',
  40. icon: 'none'
  41. })
  42. return
  43. }
  44. let that = this
  45. let storeId = wx.getStorageSync('store_id')
  46. post('api/recharge/add', {
  47. amount: this.data.money||this.data.reChargeList[this.data.selectRe].amount,
  48. store_id: storeId
  49. }, (res) => {
  50. if (res.data) {
  51. wx.requestPayment({
  52. timeStamp: res.data.pay_data.timeStamp,
  53. nonceStr: res.data.pay_data.nonceStr,
  54. package: res.data.pay_data.package,
  55. signType: res.data.pay_data.signType,
  56. paySign: res.data.pay_data.paySign,
  57. success(res) {
  58. if (res.errMsg == 'requestPayment:ok') {
  59. wx.showToast({
  60. title: '支付成功',
  61. icon: 'success'
  62. })
  63. that.getAmount()
  64. }
  65. },
  66. fail(res) {
  67. wx.showToast({
  68. title: '支付失败',
  69. icon: 'error'
  70. })
  71. },
  72. complete:(res)=>{
  73. this.setData({
  74. money:null
  75. })
  76. }
  77. })
  78. }
  79. })
  80. },
  81. selectRe(e) {
  82. this.setData({
  83. selectRe: e.currentTarget.dataset.index
  84. })
  85. },
  86. /**
  87. * 获取我的储值
  88. * api/user
  89. */
  90. getAmount() {
  91. get('api/user/amount', {}, (res) => {
  92. if (res.data) {
  93. this.setData({
  94. inserllAmount: res.data.amount
  95. })
  96. }
  97. })
  98. },
  99. /**
  100. * 获取充值列表
  101. *
  102. */
  103. getRecharge() {
  104. let storeId = wx.getStorageSync('store_id')
  105. get('api/recharge/list', {
  106. store_id: storeId
  107. }, (res) => {
  108. if (res.data) {
  109. this.setData({
  110. reChargeList: res.data.list
  111. })
  112. //控制显示自定义金额
  113. this.setData({
  114. isShow: this.data.isShow == res.data.allow_custom ? true : false
  115. })
  116. }
  117. })
  118. },
  119. /**
  120. * 生命周期函数--监听页面初次渲染完成
  121. */
  122. onReady: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面显示
  126. */
  127. onShow: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面隐藏
  131. */
  132. onHide: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面卸载
  136. */
  137. onUnload: function () {
  138. },
  139. /**
  140. * 页面相关事件处理函数--监听用户下拉动作
  141. */
  142. onPullDownRefresh: function () {
  143. },
  144. /**
  145. * 页面上拉触底事件的处理函数
  146. */
  147. onReachBottom: function () {
  148. },
  149. /**
  150. * 用户点击右上角分享
  151. */
  152. onShareAppMessage: function () {
  153. }
  154. })