123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- const app = getApp()
- const api = require('../../../../request/api.js');
- const http = require('../../../../request/http.js');
- const utils = require('../../../../utils/util.js');
- const storeKeys = require('../../../../utils/storageKeys.js');
- Page({
- data: {
- isTop: false,
- isIphoneX: app.globalData.isIphoneX,
- isLoading: false,
- showUpperModal: false, //上限了提示弹窗
- hint: "", //上限了提示文案
- showJoinedModal: false, //显示联系人弹窗
- modalData:[],
- source: "", //上级页面来源 1:会员中心 2:商品详情
- detail:{}, //会员卡详情,
- joinPhone: "15920001908", //加盟电话
- postImgUrl: `${api.URL}/uploads/image/membership.jpg`
- },
- onLoad: function (options) {
- //上级页面来源 1:会员中心
- this.data.source = options && options.source || "";
- wx.setNavigationBarColor({
- frontColor: '#ffffff',
- backgroundColor: '#2E2321',
- })
- },
- onShow() {
- this.getDetail();
- },
- //监听页面滚动
- onPageScroll(e) {
- if (e.scrollTop < 120 && this.data.isTop) {
- this.data.isTop = false;
- wx.setNavigationBarColor({
- frontColor: '#ffffff',
- backgroundColor: '#2E2321',
- animation: {
- duration: 300,
- timingFunc: 'easeIn'
- }
- })
- } else if (e.scrollTop >= 120 && !this.data.isTop) {
- this.data.isTop = true;
- wx.setNavigationBarColor({
- frontColor: '#000000',
- backgroundColor: '#ffffff',
- animation: {
- duration: 300,
- timingFunc: 'easeIn'
- }
- })
- }
- },
- //获取页面详情
- getDetail() {
- // if (JSON.stringify(this.data.detail) == "{}") {
- // wx.showLoading({
- // title: "加载中",
- // mask: true
- // });
- // }
- // http.request({
- // method: 'GET',
- // url: api.URL + '/api/member/cardinfo',
- // token: utils.getStorageSync(storeKeys.TOKEN),
- // success: (res) => {
- // wx.hideLoading();
- // let detail = res.data.data.card || {};
- // // 会员价权益说明
- // detail.price_descList = this.splitString(detail.price_desc)
- // // 会员生日礼券权益说明
- // detail.birth_descList = this.splitString(detail.birth_desc)
- // // 会员返米粒权益说明
- // detail.rice_descList = this.splitString(detail.rice_desc)
- // // 会员专属券权益说明
- // detail.coupon_descList = this.splitString(detail.coupon_desc)
- // detail.expire_at = res.data.data.expire_at
- // detail.member_status = res.data.data.member_status
- // this.setData({
- // detail,
- // isLoading: false
- // })
- // },
- // error: (res) => {},
- // })
- },
- splitString(str, tag = '/') {
- if (!str) {
- return []
- }
- return str.split(tag)
- },
- //购买
- buy: utils.throttle(function (e) {
- if (!utils.getStorageSync(storeKeys.TOKEN)) {
- wx.navigateTo({
- url: "/pages/tabBar/login/login"
- })
- return;
- }
- wx.showLoading({
- title: "加载中",
- mask: true
- });
- //调接口是否可购买
- http.request({
- url: api.URL + '/api/member/cckexpire',
- method: 'GET',
- noToast: true,
- token: utils.getStorageSync(storeKeys.TOKEN),
- success: (res) => {
- this.confirmBuy();
- },
- error: (res) => {
- wx.hideLoading();
- if (res.data.status == 500) {
- this.setData({
- showUpperModal: true,
- hint: res.data.data.hint
- })
- }
- },
- })
- }),
- // 确认购买
- confirmBuy() {
- let data = {
- order_type: 400, //会员卡固定为400
- card_id: this.data.detail.id, //会员卡id
- }
- http.request({
- url: api.URL + '/api/pay/prepay',
- method: 'POST',
- token: utils.getStorageSync(storeKeys.TOKEN),
- data: data,
- success: (res) => {
- wx.hideLoading();
- if (res.data.data.pay_type == 20) {
- this.wxPayment(res.data.data.payment);
- }
- },
- error: (res) => {
- },
- })
- },
- //调起微信支付
- wxPayment(data) {
- let _this = this;
- wx.requestPayment({
- nonceStr: data.nonceStr,
- package: 'prepay_id=' + data.prepay_id,
- paySign: data.paySign,
- signType: "MD5",
- timeStamp: data.timeStamp,
- success(res) {
- if (res.errMsg == "requestPayment:ok") {
- utils.toast('支付成功');
- //source == 2 来源商品详情,支付成功后不弹窗直接返回上一页
- if(_this.data.source == 2){
- setTimeout(() => {
- wx.navigateBack({
- delta: 1
- });
- }, 1000)
- return;
- }
- // 会员开通礼优惠券列表弹窗数据
- http.request({
- method: 'GET',
- url: api.URL + '/api/member/couponlist',
- token: utils.getStorageSync(storeKeys.TOKEN),
- success: (res) => {
- console.log(res)
- _this.setData({
- showJoinedModal: true,
- modalData:res.data.data.list || []
- })
- },
- error: (res) => {},
- })
- }
- },
- fail(res) {
- if (res.errMsg == "requestPayment:fail cancel") {
- utils.toast('已取消支付');
- }
- }
- })
- },
- //关闭上限了提示弹窗
- hideUpperModal() {
- this.setData({
- showUpperModal: false
- })
- },
- // 暂不领取 进入会员专区
- goToMember: utils.throttle(function (e) {
- // source == 1 来源会员中心 执行返回上一页
- if (this.data.source == "1") {
- wx.navigateBack({
- delta: 1
- });
- } else {
- wx.redirectTo({
- url: "/pages/member/pages/memberCenter/memberCenter"
- })
- }
- }),
- // 一键领取
- oneReceive: utils.throttle(function (e) {
- wx.showLoading({
- title: "加载中",
- mask: true
- });
- http.request({
- method: 'POST',
- url: api.URL + '/api/member/receive',
- token: utils.getStorageSync(storeKeys.TOKEN),
- success: (res) => {
- console.log(res)
- wx.hideLoading();
- wx.redirectTo({
- url: "/pages/member/pages/receiveSuccess/receiveSuccess"
- })
- },
- error: (res) => {},
- })
- }),
- memberAgreement: utils.throttle(function (e) {
- wx.navigateTo({
- url: "/pages/public/pages/memberAgreement/memberAgreement"
- })
- }),
- clickJoin() {
- this.setData({
- showJoinedModal: true
- })
- },
- closeJoinedModal() {
- this.setData({
- showJoinedModal: false
- })
- },
- callToJoin() {
- wx.makePhoneCall({
- phoneNumber: this.data.joinPhone
- })
- }
- })
|