account.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // pages/my/account/account.js
  2. const app=getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. show: false,
  9. recharge: [{
  10. tit: '充600元',
  11. tips: '赠送300元',
  12. value: 600
  13. },
  14. {
  15. tit: '充300元',
  16. tips: '赠送100元',
  17. value: 300
  18. },
  19. {
  20. tit: '充100元',
  21. tips: '赠送20元',
  22. value: 100
  23. }],
  24. active: 0,
  25. value: 0,
  26. balance:false,
  27. amount:0,
  28. is_online:1
  29. },
  30. amountList:[],
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. this.setData({
  36. is_online: wx.getStorageSync('is_online')
  37. })
  38. this.getwallet();
  39. },
  40. showPopup() {
  41. console.log(this.data.recharge[0])
  42. this.setData({
  43. show: !this.data.show,
  44. active: 0,
  45. // value: this.data.recharge[0].price
  46. value: this.data.recharge.length>0?[0].price : 0
  47. });
  48. this.getrecharge();
  49. },
  50. showBalance(){
  51. this.setData({
  52. balance:!this.data.balance
  53. })
  54. },
  55. toDrtail(e) {
  56. var id=e.currentTarget.dataset.id
  57. wx.navigateTo({
  58. url: '/pages/my/account/detail/detail?id='+id,
  59. })
  60. },
  61. changeCurrent(e) {
  62. let { index, value } = e.currentTarget.dataset
  63. this.setData({
  64. active: index,
  65. value
  66. })
  67. },
  68. inputChange(e) {
  69. let { value } = e.detail
  70. console.log(value);
  71. this.setData({
  72. value: value ? value : 0,
  73. active: -1
  74. })
  75. },
  76. getwallet() {
  77. var that = this;
  78. app.api.useApi(app.globalData.baseAppUrl + "api/wallet", {
  79. }, "get").then(function (res) {
  80. if (res.code != 200) {
  81. wx.showLoading({
  82. title: res.message.msg,
  83. })
  84. setTimeout(function () {
  85. wx.hideLoading({
  86. success: (res) => { },
  87. })
  88. }, 2000);
  89. } else {
  90. console.log(res.message.data);
  91. that.setData({
  92. amount: res.message.data.balance,
  93. amountList:res.message.data.wallets.data
  94. })
  95. }
  96. }).catch(function (err) {
  97. console.log(222);
  98. })
  99. },
  100. getrecharge() {
  101. var that = this;
  102. app.api.useApi(app.globalData.baseAppUrl + "api/recharge", {
  103. }, "get").then(function (res) {
  104. if (res.code != 200) {
  105. wx.showLoading({
  106. title: res.message.msg,
  107. })
  108. setTimeout(function () {
  109. wx.hideLoading({
  110. success: (res) => { },
  111. })
  112. }, 2000);
  113. } else {
  114. console.log(res.message.data);
  115. that.setData({
  116. recharge:res.message.data
  117. })
  118. }
  119. }).catch(function (err) {
  120. console.log(222);
  121. })
  122. },
  123. wxPay(){
  124. var that=this;
  125. var no=that.data.value
  126. app.api.useApi(app.globalData.baseAppUrl + "api/recharge/charge", {
  127. price: no,
  128. }, "post").then(function (res) {
  129. console.log(res)
  130. if (res.code != 200) {
  131. wx.showLoading({
  132. title: res.message.msg,
  133. })
  134. setTimeout(function () {
  135. wx.hideLoading({
  136. success: (res) => { },
  137. })
  138. }, 1000);
  139. } else {
  140. var paydata=res.message.data
  141. wx.requestPayment({
  142. timeStamp: paydata.timeStamp,
  143. nonceStr: paydata.nonceStr,
  144. package: paydata.package,
  145. signType: paydata.signType,
  146. paySign: paydata.paySign,
  147. success (res) {
  148. console.log(res);
  149. if(res.errMsg=="requestPayment:ok"){
  150. that.getwallet();
  151. wx.showLoading({
  152. title:"支付成功。",
  153. })
  154. setTimeout(function () {
  155. wx.hideLoading({
  156. success: (res) => { },
  157. })
  158. }, 1000);
  159. // this. getwallet();
  160. }
  161. },
  162. fail (res) {
  163. wx.showLoading({
  164. title: "失败,请重试!",
  165. })
  166. setTimeout(function () {
  167. wx.hideLoading({
  168. success: (res) => { },
  169. })
  170. }, 1000);
  171. console.log(res)}
  172. })
  173. }
  174. }).catch(function (err) {console.log(err)})
  175. }
  176. })