account.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. this.setData({
  42. show: !this.data.show,
  43. active: 0,
  44. value: this.data.recharge[0].price
  45. });
  46. this.getrecharge();
  47. },
  48. showBalance(){
  49. this.setData({
  50. balance:!this.data.balance
  51. })
  52. },
  53. toDrtail(e) {
  54. var id=e.currentTarget.dataset.id
  55. wx.navigateTo({
  56. url: '/pages/my/account/detail/detail?id='+id,
  57. })
  58. },
  59. changeCurrent(e) {
  60. let { index, value } = e.currentTarget.dataset
  61. this.setData({
  62. active: index,
  63. value
  64. })
  65. },
  66. inputChange(e) {
  67. let { value } = e.detail
  68. console.log(value);
  69. this.setData({
  70. value: value ? value : 0,
  71. active: -1
  72. })
  73. },
  74. getwallet() {
  75. var that = this;
  76. app.api.useApi(app.globalData.baseAppUrl + "api/wallet", {
  77. }, "get").then(function (res) {
  78. if (res.code != 200) {
  79. wx.showLoading({
  80. title: res.message.msg,
  81. })
  82. setTimeout(function () {
  83. wx.hideLoading({
  84. success: (res) => { },
  85. })
  86. }, 2000);
  87. } else {
  88. console.log(res.message.data);
  89. that.setData({
  90. amount: res.message.data.balance,
  91. amountList:res.message.data.wallets.data
  92. })
  93. }
  94. }).catch(function (err) {
  95. console.log(222);
  96. })
  97. },
  98. getrecharge() {
  99. var that = this;
  100. app.api.useApi(app.globalData.baseAppUrl + "api/recharge", {
  101. }, "get").then(function (res) {
  102. if (res.code != 200) {
  103. wx.showLoading({
  104. title: res.message.msg,
  105. })
  106. setTimeout(function () {
  107. wx.hideLoading({
  108. success: (res) => { },
  109. })
  110. }, 2000);
  111. } else {
  112. console.log(res.message.data);
  113. that.setData({
  114. recharge:res.message.data
  115. })
  116. }
  117. }).catch(function (err) {
  118. console.log(222);
  119. })
  120. },
  121. wxPay(){
  122. var that=this;
  123. var no=that.data.value
  124. app.api.useApi(app.globalData.baseAppUrl + "api/recharge/charge", {
  125. price: no,
  126. }, "post").then(function (res) {
  127. console.log(res)
  128. if (res.code != 200) {
  129. wx.showLoading({
  130. title: res.message.msg,
  131. })
  132. setTimeout(function () {
  133. wx.hideLoading({
  134. success: (res) => { },
  135. })
  136. }, 1000);
  137. } else {
  138. var paydata=res.message.data
  139. wx.requestPayment({
  140. timeStamp: paydata.timeStamp,
  141. nonceStr: paydata.nonceStr,
  142. package: paydata.package,
  143. signType: paydata.signType,
  144. paySign: paydata.paySign,
  145. success (res) {
  146. console.log(res);
  147. if(res.errMsg=="requestPayment:ok"){
  148. that.getwallet();
  149. wx.showLoading({
  150. title:"支付成功。",
  151. })
  152. setTimeout(function () {
  153. wx.hideLoading({
  154. success: (res) => { },
  155. })
  156. }, 1000);
  157. // this. getwallet();
  158. }
  159. },
  160. fail (res) {
  161. wx.showLoading({
  162. title: "失败,请重试!",
  163. })
  164. setTimeout(function () {
  165. wx.hideLoading({
  166. success: (res) => { },
  167. })
  168. }, 1000);
  169. console.log(res)}
  170. })
  171. }
  172. }).catch(function (err) {console.log(err)})
  173. }
  174. })