vip.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. loading: false,
  8. isvip:false,
  9. price:0,
  10. ucode:''
  11. },
  12. /**
  13. * 每次显示重新载入
  14. */
  15. onShow: function () {
  16. this.getCard();
  17. },
  18. /**
  19. * 获取会员卡信息
  20. */
  21. getCard:function(){
  22. let that = this;
  23. app.api().Get('api/v3/fastshop/bank/isvip', function (rel) {
  24. if (rel.code == 200){
  25. that.setData({
  26. isvip:true,
  27. ucode:app.globalData.loginuser.ucode
  28. })
  29. }else{
  30. var price = rel.data;
  31. that.setData({
  32. price: price.toFixed(2)
  33. })
  34. }
  35. })
  36. },
  37. /**
  38. * 判断是微信IOS还是Android
  39. */
  40. openVip: function (res) {
  41. let that = this;
  42. wx.getSystemInfo({
  43. success: function (res) {
  44. that.setData({
  45. systemInfo: res,
  46. })
  47. if (res.platform == "ios") {
  48. wx.showModal({
  49. content: '十分抱歉,由于相关规定,暂不支苹果用户开通会员.',
  50. })
  51. } else {
  52. that.doPay();
  53. }
  54. }
  55. })
  56. },
  57. //唤启支付
  58. doPay:function(){
  59. let that = this;
  60. wx.showLoading({title:'请稍后',mask: true})
  61. app.api().Post('api/v3/fastshop/bank/openVip', function (rel) {
  62. if (rel.code == 200) {
  63. if (rel.data.type == 1) {
  64. that.setData({
  65. chickPayBtn: true,
  66. orderParams: rel.data.order
  67. })
  68. } else {
  69. app.doWechatPay(rel.data.order, function (res) {
  70. that.getCard();
  71. }, function (res) {
  72. wx.showModal({
  73. content: '支付失败或取消',
  74. showCancel: false
  75. })
  76. })
  77. }
  78. }
  79. })
  80. },
  81. /**
  82. * 服务协议
  83. */
  84. contract: function () {
  85. let that = this;
  86. let config = app.globalData.wechat_config;
  87. wx.navigateTo({
  88. url: '/pages/helper/webview?src=' + app.api_root + '/api-' + config.app_id + '/v3/fastshop/webview/contract'
  89. })
  90. },
  91. /**
  92. * 开通会员特权
  93. */
  94. service: function () {
  95. let that = this;
  96. let config = app.globalData.wechat_config;
  97. wx.navigateTo({
  98. url: '/pages/helper/webview?src=' + app.api_root + '/api-' + config.app_id + '/v3/fastshop/webview/service'
  99. })
  100. },
  101. /**
  102. * 支付成功的事件处理函数
  103. * res.detail 为 payjs 小程序返回的订单信息
  104. * 可通过 res.detail.payjsOrderId 拿到 payjs 订单号
  105. * 可通过 res.detail.responseData 拿到详细支付信息
  106. */
  107. goodPaySuccess: function (res) {
  108. if (res.detail.return_code = "SUCCESS") {
  109. this.getCard();
  110. }
  111. },
  112. /**
  113. * 支付失败的事件处理函数
  114. * res.detail.error 为 true 代表传入小组件的参数存在问题
  115. * res.detail.navigateSuccess 代表了是否成功跳转到 PAYJS 小程序
  116. * res.detail.event 可能存有失败的原因
  117. * 如果下单成功但是用户取消支付则 res.detail.event.return_code == FAIL
  118. */
  119. goodPayFail: function (res) {
  120. this.setData({
  121. chickPayBtn: false,
  122. })
  123. },
  124. /**
  125. * 支付完毕的事件处理函数
  126. * 无论支付成功或失败均会执行
  127. */
  128. goodPayComplete: function () {
  129. this.setData({
  130. chickPayBtn: false,
  131. })
  132. },
  133. /**
  134. * 组件内部数据被修改时的事件
  135. * 当用户跳转到 云收银台 小程序并等待返回的过程中 chickOnPay 值为 true
  136. */
  137. goodPayChange(res) {
  138. if (res.detail.chickOnPay) {
  139. this.setData({
  140. chickOnPay: res.detail.chickOnPay
  141. })
  142. }
  143. }
  144. })