vippage.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. let util = require('../../../utils/util.js');
  2. var that
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. newcount: 5,
  9. vipcount: 5
  10. },
  11. freshvipprice() {
  12. this.setData({
  13. vipprice: parseFloat(this.data.vipp.currentPrice * this.data.vipcount).toFixed(2),
  14. vipall: parseFloat(this.data.vipp.originalPrice * this.data.vipcount).toFixed(2)
  15. })
  16. },
  17. setvipcount(e) {
  18. this.setData({
  19. vipcount: e.detail.value
  20. })
  21. this.freshvipprice()
  22. },
  23. vipbuynow() {
  24. if (this.data.vipcount === 0 || this.data.vipcount === '0' || this.data.vipcount === '') {
  25. util.showToast('请输入正确人数')
  26. return
  27. }
  28. wx.navigateTo({
  29. url: '/pages/myinfo/pay/pay?num=' + this.data.vipcount + '&year=1&pid=' + this.data.vipp.id + '&name=新增记账人数&currentPrice=' + this.data.vipp.currentPrice + '&originalPrice=' + this.data.vipp.originalPrice
  30. })
  31. },
  32. gettips() {
  33. util.query('/memberAndService/wxapi/getInfo', {}, function(e) {
  34. that.setData({
  35. fntitle: e.data.title,
  36. fncontent: e.data.content.replace('\\n', '\n'),
  37. fetitle: e.data.freeTitle,
  38. fecontent: e.data.freeContent.replace('\\n', '\n')
  39. })
  40. })
  41. },
  42. freshnewprice() {
  43. this.setData({
  44. newprice: parseFloat(this.data.newp.currentPrice * this.data.newcount).toFixed(2),
  45. newall: parseFloat(this.data.newp.originalPrice * this.data.newcount).toFixed(2)
  46. })
  47. },
  48. tcbuy(e) {
  49. wx.showModal({
  50. title: '确认',
  51. content: '是否确定购买套餐',
  52. success(res) {
  53. if (res.confirm) {
  54. util.query("memberOrder/wxapi/create", {
  55. packageYears: e.currentTarget.dataset.year,
  56. memberPackage: {
  57. id: e.currentTarget.dataset.id
  58. }
  59. }, function(d) {
  60. if (d.code == 10000) {
  61. wx.requestPayment({
  62. 'timeStamp': d.data.timeStamp + "",
  63. 'nonceStr': d.data.nonceStr,
  64. 'package': d.data.packageValue,
  65. 'signType': 'MD5',
  66. 'paySign': d.data.paySign,
  67. 'success': function(res) {
  68. console.log(res);
  69. if (res.errMsg == "requestPayment:ok") {
  70. util.showToast('支付成功')
  71. that.freshmyinfo()
  72. setTimeout(function() {
  73. wx.switchTab({
  74. url: '/pages/myinfo/myinfo/myinfo',
  75. })
  76. }, 2000)
  77. }
  78. },
  79. 'fail': function(res) {
  80. util.showToast('支付失败')
  81. },
  82. 'completev': function(res) {
  83. // if (res.requestPayment == "cancel") {
  84. // common.showToast('支付取消1')
  85. // }
  86. }
  87. })
  88. } else {
  89. }
  90. }, "POST")
  91. } else if (res.cancel) {
  92. }
  93. }
  94. })
  95. },
  96. freshmyinfo() {
  97. util.query('userinfo/wxapi/findbyid', {
  98. id: this.data.user.id
  99. },
  100. function(e) {
  101. wx.setStorage({
  102. key: 'userinfo',
  103. data: e.data,
  104. })
  105. })
  106. },
  107. setnewcount(e) {
  108. this.setData({
  109. newcount: e.detail.value
  110. })
  111. this.freshnewprice()
  112. },
  113. newbuynow() {
  114. if (this.data.newcount === 0 || this.data.newcount === '0' || this.data.newcount === '') {
  115. util.showToast('请输入正确人数')
  116. return
  117. }
  118. wx.navigateTo({
  119. url: '/pages/myinfo/pay/pay?num=' + this.data.newcount + '&year=1&pid=' + this.data.newp.id + '&name=新用户购买&currentPrice=' + this.data.newp.currentPrice + '&originalPrice=' + this.data.newp.originalPrice
  120. })
  121. },
  122. /**
  123. * 生命周期函数--监听页面加载
  124. */
  125. onLoad: function(options) {
  126. that = this
  127. util.checklogin(
  128. function() {
  129. var ui = wx.getStorageSync('userinfo')
  130. if (ui) {
  131. ui.validityTime = ui.validityTime ? ui.validityTime.split(' ')[0] : ''
  132. // ui.isvip = 2
  133. that.setData({
  134. user: ui
  135. })
  136. that.getList()
  137. that.gettips()
  138. }
  139. }
  140. )
  141. },
  142. getList() {
  143. util.query('memberPackage/wxapi/listpage', {}, function(res) {
  144. if (res.code === 10000) {
  145. var newp, vipp, ps = []
  146. res.data.content.forEach(function(e) {
  147. if (e.packageType === 2) {
  148. if (e.forNewMember === 1) {
  149. newp = e
  150. } else {
  151. vipp = e
  152. }
  153. } else {
  154. ps.push(e)
  155. }
  156. })
  157. that.setData({
  158. data: ps,
  159. newp: newp,
  160. vipp: vipp
  161. })
  162. that.freshnewprice()
  163. that.freshvipprice()
  164. }
  165. })
  166. },
  167. pay(e) {
  168. },
  169. /**
  170. * 生命周期函数--监听页面初次渲染完成
  171. */
  172. onReady: function() {
  173. },
  174. /**
  175. * 生命周期函数--监听页面显示
  176. */
  177. onShow: function() {
  178. },
  179. /**
  180. * 生命周期函数--监听页面隐藏
  181. */
  182. onHide: function() {
  183. },
  184. /**
  185. * 生命周期函数--监听页面卸载
  186. */
  187. onUnload: function() {
  188. },
  189. /**
  190. * 页面相关事件处理函数--监听用户下拉动作
  191. */
  192. onPullDownRefresh: function() {
  193. },
  194. /**
  195. * 页面上拉触底事件的处理函数
  196. */
  197. onReachBottom: function() {
  198. },
  199. /**
  200. * 用户点击右上角分享
  201. */
  202. onShareAppMessage: function() {
  203. }
  204. })