renew.js 7.43 KB
"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_api = require("../../../common/api.js");
require("../../../common/request.js");
require("../../../config.js");
require("../../../common/login.js");
if (!Array) {
  const _easycom_uni_popup_dialog2 = common_vendor.resolveComponent("uni-popup-dialog");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_popup_dialog2 + _easycom_uni_popup2)();
}
const _easycom_uni_popup_dialog = () => "../../../uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.js";
const _easycom_uni_popup = () => "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (_easycom_uni_popup_dialog + _easycom_uni_popup)();
}
const _sfc_main = {
  __name: "renew",
  setup(__props) {
    const app = getApp();
    const vTypeImg = common_vendor.ref("/static/v1.png");
    const card = common_vendor.ref({});
    const orderId = common_vendor.ref("");
    const telNo = common_vendor.ref("");
    const userName = common_vendor.ref("");
    const alertPayOk = common_vendor.ref(null);
    const isActive = common_vendor.ref(null);
    const amount = common_vendor.ref(0);
    const myAmount = common_vendor.ref(null);
    const priceList = common_vendor.ref(["500", "1000", "2000", "3000", "5000", "10000"]);
    const popNotice = common_vendor.ref(false);
    const content = common_vendor.ref("");
    common_vendor.onLoad(() => {
      content.value = app.globalData.venue.rechargeNotice;
      popNotice.value = true;
    });
    common_vendor.onShow(() => {
      common_api.getOwnMemberInfo().then((res) => {
        card.value = res.data;
        if (card.value.isVip) {
          telNo.value = card.value.info.memberTelno;
          userName.value = card.value.info.memberName;
        } else {
          telNo.value = common_vendor.index.getStorageSync("currUser").realTelno;
          userName.value = "";
        }
      });
    });
    function closepopNotice() {
      popNotice.value = false;
    }
    function goPay() {
      if (!telNo.value) {
        common_vendor.index.showToast({
          title: `请填写充值手机号`,
          icon: "none"
        });
        return;
      }
      if (!userName.value) {
        common_vendor.index.showToast({
          title: `请填写姓名`,
          icon: "none"
        });
        return;
      }
      if (myAmount.value) {
        amount.value = myAmount.value;
      }
      if (amount.value == 0) {
        common_vendor.index.showToast({
          title: `请选择或填写充值金额`,
          icon: "none"
        });
        return;
      }
      common_api.getMemberLevelTip(telNo.value, amount.value).then((res) => {
        console.log(res);
        if (res.data.name != card.value.vipInfo.name) {
          if (res.data.discountPercent < card.value.vipInfo.discountPercent) {
            var changeDis = "降级";
          } else {
            var changeDis = "升级";
          }
          common_vendor.index.showModal({
            title: "温馨提示",
            content: `充值成功后,您将${changeDis}${res.data.name},新的会员折扣为${(100 - res.data.discountPercent) / 10}折`,
            success: function(res2) {
              if (res2.confirm) {
                goRecharge();
              } else if (res2.cancel) {
                console.log("取消充值");
              }
            }
          });
        } else {
          goRecharge();
        }
      });
    }
    function goRecharge() {
      common_vendor.index.getStorageSync("currUser");
      common_api.rechargeCard({
        telNo: telNo.value,
        amount: amount.value,
        userName: userName.value
      }).then((res) => {
        wePay(res.data.weixinData);
        orderId.value = res.data.orderId;
      });
    }
    function wePay(configdata) {
      console.log(configdata);
      common_vendor.index.requestPayment({
        "provider": "wxpay",
        "appId": configdata.appId,
        "nonceStr": configdata.nonceStr,
        "package": configdata.packageValue,
        // 随机字符串
        "timeStamp": configdata.timeStamp,
        // 时间戳(单位:秒)
        "signType": configdata.signType,
        // 签名,这里用的 MD5/RSA 签名
        "paySign": configdata.paySign,
        success(res) {
          console.log(res);
          common_api.maRechargeConfirm({
            orderId: orderId.value,
            successFlag: true
          }).then((response) => {
            console.log(response);
          });
          alertPayOk.value.open();
        },
        fail(e) {
          console.log(e);
          common_vendor.index.showToast({
            title: "支付取消",
            icon: "none"
          });
          common_api.maRechargeConfirm({
            orderId: orderId.value,
            successFlag: false
          }).then((response) => {
            console.log(response);
          });
        }
      });
    }
    function goCardDetail() {
      common_vendor.index.redirectTo({
        url: `/pages/usercenter/mycard/mycard`
      });
    }
    function changePrice(item, index) {
      if (isActive.value == index) {
        isActive.value = null;
        amount.value = 0;
      } else {
        isActive.value = index;
        amount.value = item;
      }
      myAmount.value = null;
    }
    function changeMyAmount(val) {
      if (myAmount.value) {
        isActive.value = -1;
      }
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: telNo.value,
        b: common_vendor.o(($event) => telNo.value = $event.detail.value),
        c: userName.value,
        d: common_vendor.o(($event) => userName.value = $event.detail.value),
        e: common_vendor.f(priceList.value, (p, index, i0) => {
          return {
            a: common_vendor.t(p),
            b: index,
            c: common_vendor.n(isActive.value == index ? "active" : ""),
            d: common_vendor.o(($event) => changePrice(p, index), index)
          };
        }),
        f: common_vendor.o(changeMyAmount),
        g: myAmount.value,
        h: common_vendor.o(($event) => myAmount.value = $event.detail.value),
        i: card.value.isVip
      }, card.value.isVip ? {
        j: vTypeImg.value,
        k: common_vendor.t(card.value.vipInfo.name),
        l: common_vendor.t(card.value.info.cardCode),
        m: common_vendor.t(card.value.info.balance),
        n: common_vendor.t((100 - card.value.info.discountPercent) / 10),
        o: common_vendor.t(card.value.info.expirationTime)
      } : {}, {
        p: common_vendor.o((...args) => _ctx.payChange && _ctx.payChange(...args)),
        q: card.value.isVip
      }, card.value.isVip ? {
        r: common_vendor.o(goPay)
      } : {
        s: common_vendor.o(goPay)
      }, {
        t: common_vendor.o(goCardDetail),
        v: common_vendor.p({
          type: "success",
          confirmText: "查看会员卡",
          content: "充值成功"
        }),
        w: common_vendor.sr(alertPayOk, "bfa1fab8-0", {
          "k": "alertPayOk"
        }),
        x: common_vendor.p({
          type: "dialog"
        }),
        y: popNotice.value
      }, popNotice.value ? {
        z: common_vendor.t(content.value),
        A: common_vendor.o(closepopNotice)
      } : {});
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-bfa1fab8"], ["__file", "/Users/yangyang/project/j-mini/Venue/pages/usercenter/mycard/renew.vue"]]);
wx.createPage(MiniProgramPage);