membership.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. const app = getApp()
  2. const api = require('../../../../request/api.js');
  3. const http = require('../../../../request/http.js');
  4. const utils = require('../../../../utils/util.js');
  5. const storeKeys = require('../../../../utils/storageKeys.js');
  6. Page({
  7. data: {
  8. isTop: false,
  9. isIphoneX: app.globalData.isIphoneX,
  10. isLoading: false,
  11. showUpperModal: false, //上限了提示弹窗
  12. hint: "", //上限了提示文案
  13. showJoinedModal: false, //显示联系人弹窗
  14. modalData:[],
  15. source: "", //上级页面来源 1:会员中心 2:商品详情
  16. detail:{}, //会员卡详情,
  17. joinPhone: "15920001908", //加盟电话
  18. postImgUrl: `${api.URL}/uploads/image/membership.jpg`
  19. },
  20. onLoad: function (options) {
  21. //上级页面来源 1:会员中心
  22. this.data.source = options && options.source || "";
  23. wx.setNavigationBarColor({
  24. frontColor: '#ffffff',
  25. backgroundColor: '#2E2321',
  26. })
  27. },
  28. onShow() {
  29. this.getDetail();
  30. },
  31. //监听页面滚动
  32. onPageScroll(e) {
  33. if (e.scrollTop < 120 && this.data.isTop) {
  34. this.data.isTop = false;
  35. wx.setNavigationBarColor({
  36. frontColor: '#ffffff',
  37. backgroundColor: '#2E2321',
  38. animation: {
  39. duration: 300,
  40. timingFunc: 'easeIn'
  41. }
  42. })
  43. } else if (e.scrollTop >= 120 && !this.data.isTop) {
  44. this.data.isTop = true;
  45. wx.setNavigationBarColor({
  46. frontColor: '#000000',
  47. backgroundColor: '#ffffff',
  48. animation: {
  49. duration: 300,
  50. timingFunc: 'easeIn'
  51. }
  52. })
  53. }
  54. },
  55. //获取页面详情
  56. getDetail() {
  57. // if (JSON.stringify(this.data.detail) == "{}") {
  58. // wx.showLoading({
  59. // title: "加载中",
  60. // mask: true
  61. // });
  62. // }
  63. // http.request({
  64. // method: 'GET',
  65. // url: api.URL + '/api/member/cardinfo',
  66. // token: utils.getStorageSync(storeKeys.TOKEN),
  67. // success: (res) => {
  68. // wx.hideLoading();
  69. // let detail = res.data.data.card || {};
  70. // // 会员价权益说明
  71. // detail.price_descList = this.splitString(detail.price_desc)
  72. // // 会员生日礼券权益说明
  73. // detail.birth_descList = this.splitString(detail.birth_desc)
  74. // // 会员返米粒权益说明
  75. // detail.rice_descList = this.splitString(detail.rice_desc)
  76. // // 会员专属券权益说明
  77. // detail.coupon_descList = this.splitString(detail.coupon_desc)
  78. // detail.expire_at = res.data.data.expire_at
  79. // detail.member_status = res.data.data.member_status
  80. // this.setData({
  81. // detail,
  82. // isLoading: false
  83. // })
  84. // },
  85. // error: (res) => {},
  86. // })
  87. },
  88. splitString(str, tag = '/') {
  89. if (!str) {
  90. return []
  91. }
  92. return str.split(tag)
  93. },
  94. //购买
  95. buy: utils.throttle(function (e) {
  96. if (!utils.getStorageSync(storeKeys.TOKEN)) {
  97. wx.navigateTo({
  98. url: "/pages/tabBar/login/login"
  99. })
  100. return;
  101. }
  102. wx.showLoading({
  103. title: "加载中",
  104. mask: true
  105. });
  106. //调接口是否可购买
  107. http.request({
  108. url: api.URL + '/api/member/cckexpire',
  109. method: 'GET',
  110. noToast: true,
  111. token: utils.getStorageSync(storeKeys.TOKEN),
  112. success: (res) => {
  113. this.confirmBuy();
  114. },
  115. error: (res) => {
  116. wx.hideLoading();
  117. if (res.data.status == 500) {
  118. this.setData({
  119. showUpperModal: true,
  120. hint: res.data.data.hint
  121. })
  122. }
  123. },
  124. })
  125. }),
  126. // 确认购买
  127. confirmBuy() {
  128. let data = {
  129. order_type: 400, //会员卡固定为400
  130. card_id: this.data.detail.id, //会员卡id
  131. }
  132. http.request({
  133. url: api.URL + '/api/pay/prepay',
  134. method: 'POST',
  135. token: utils.getStorageSync(storeKeys.TOKEN),
  136. data: data,
  137. success: (res) => {
  138. wx.hideLoading();
  139. if (res.data.data.pay_type == 20) {
  140. this.wxPayment(res.data.data.payment);
  141. }
  142. },
  143. error: (res) => {
  144. },
  145. })
  146. },
  147. //调起微信支付
  148. wxPayment(data) {
  149. let _this = this;
  150. wx.requestPayment({
  151. nonceStr: data.nonceStr,
  152. package: 'prepay_id=' + data.prepay_id,
  153. paySign: data.paySign,
  154. signType: "MD5",
  155. timeStamp: data.timeStamp,
  156. success(res) {
  157. if (res.errMsg == "requestPayment:ok") {
  158. utils.toast('支付成功');
  159. //source == 2 来源商品详情,支付成功后不弹窗直接返回上一页
  160. if(_this.data.source == 2){
  161. setTimeout(() => {
  162. wx.navigateBack({
  163. delta: 1
  164. });
  165. }, 1000)
  166. return;
  167. }
  168. // 会员开通礼优惠券列表弹窗数据
  169. http.request({
  170. method: 'GET',
  171. url: api.URL + '/api/member/couponlist',
  172. token: utils.getStorageSync(storeKeys.TOKEN),
  173. success: (res) => {
  174. console.log(res)
  175. _this.setData({
  176. showJoinedModal: true,
  177. modalData:res.data.data.list || []
  178. })
  179. },
  180. error: (res) => {},
  181. })
  182. }
  183. },
  184. fail(res) {
  185. if (res.errMsg == "requestPayment:fail cancel") {
  186. utils.toast('已取消支付');
  187. }
  188. }
  189. })
  190. },
  191. //关闭上限了提示弹窗
  192. hideUpperModal() {
  193. this.setData({
  194. showUpperModal: false
  195. })
  196. },
  197. // 暂不领取 进入会员专区
  198. goToMember: utils.throttle(function (e) {
  199. // source == 1 来源会员中心 执行返回上一页
  200. if (this.data.source == "1") {
  201. wx.navigateBack({
  202. delta: 1
  203. });
  204. } else {
  205. wx.redirectTo({
  206. url: "/pages/member/pages/memberCenter/memberCenter"
  207. })
  208. }
  209. }),
  210. // 一键领取
  211. oneReceive: utils.throttle(function (e) {
  212. wx.showLoading({
  213. title: "加载中",
  214. mask: true
  215. });
  216. http.request({
  217. method: 'POST',
  218. url: api.URL + '/api/member/receive',
  219. token: utils.getStorageSync(storeKeys.TOKEN),
  220. success: (res) => {
  221. console.log(res)
  222. wx.hideLoading();
  223. wx.redirectTo({
  224. url: "/pages/member/pages/receiveSuccess/receiveSuccess"
  225. })
  226. },
  227. error: (res) => {},
  228. })
  229. }),
  230. memberAgreement: utils.throttle(function (e) {
  231. wx.navigateTo({
  232. url: "/pages/public/pages/memberAgreement/memberAgreement"
  233. })
  234. }),
  235. clickJoin() {
  236. this.setData({
  237. showJoinedModal: true
  238. })
  239. },
  240. closeJoinedModal() {
  241. this.setData({
  242. showJoinedModal: false
  243. })
  244. },
  245. callToJoin() {
  246. wx.makePhoneCall({
  247. phoneNumber: this.data.joinPhone
  248. })
  249. }
  250. })