| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const utils_api = require("../../utils/api.js");
- const _sfc_main = {
- data() {
- return {
- paymentAmount: 30,
- selectedMethod: 0,
- planName: "",
- planType: "month",
- planId: 0,
- isProcessing: false,
- paymentMethods: [
- {
- name: "微信支付",
- icon: "💬",
- iconBg: "#07C160",
- type: "wechat"
- },
- {
- name: "支付宝支付",
- icon: "💰",
- iconBg: "#1677FF",
- type: "alipay"
- },
- {
- name: "其他支付",
- icon: "💳",
- iconBg: "#999999",
- type: "other"
- }
- ]
- };
- },
- onLoad(options) {
- if (options.price) {
- this.paymentAmount = parseFloat(options.price);
- }
- if (options.planName) {
- this.planName = decodeURIComponent(options.planName);
- }
- if (options.planType) {
- this.planType = options.planType;
- }
- if (options.planId) {
- this.planId = parseInt(options.planId);
- }
- },
- methods: {
- goBack() {
- common_vendor.index.navigateBack();
- },
- selectPaymentMethod(index) {
- this.selectedMethod = index;
- },
- async confirmPayment() {
- const userInfo2 = common_vendor.index.getStorageSync("userInfo");
- if (!userInfo2 || !userInfo2.id) {
- common_vendor.index.showToast({
- title: "请先登录",
- icon: "none"
- });
- setTimeout(() => {
- common_vendor.index.navigateTo({
- url: "/pages/login/login"
- });
- }, 1500);
- return;
- }
- if (this.isProcessing) {
- return;
- }
- const method = this.paymentMethods[this.selectedMethod];
- common_vendor.index.showModal({
- title: "确认支付",
- content: `使用${method.name}支付 ¥${this.paymentAmount.toFixed(2)}?`,
- success: async (res) => {
- if (res.confirm) {
- await this.processPayment(method, userInfo2.id);
- }
- }
- });
- },
- async processPayment(method, userId) {
- this.isProcessing = true;
- common_vendor.index.showLoading({
- title: "支付中...",
- mask: true
- });
- try {
- const purchaseData = {
- userId,
- vipType: this.planType,
- vipName: this.planName,
- price: this.paymentAmount,
- paymentMethod: method.type
- };
- const res = await utils_api.purchaseVip(purchaseData);
- common_vendor.index.hideLoading();
- this.isProcessing = false;
- if (res && res.code === 200) {
- common_vendor.index.showToast({
- title: "支付成功",
- icon: "success"
- });
- if (userInfo) {
- userInfo.isVip = true;
- if (res.data && res.data.expireTime) {
- }
- common_vendor.index.setStorageSync("userInfo", userInfo);
- }
- setTimeout(() => {
- common_vendor.index.navigateBack({
- delta: 2
- // 返回VIP页面再返回上一页
- });
- }, 1500);
- } else {
- common_vendor.index.showToast({
- title: res.message || "支付失败,请重试",
- icon: "none"
- });
- }
- } catch (error) {
- common_vendor.index.hideLoading();
- this.isProcessing = false;
- common_vendor.index.__f__("error", "at pages/payment/payment.vue:186", "支付失败:", error);
- common_vendor.index.showToast({
- title: error.message || "支付失败,请重试",
- icon: "none"
- });
- }
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return {
- a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
- b: common_vendor.t($data.paymentAmount.toFixed(2)),
- c: common_vendor.f($data.paymentMethods, (method, index, i0) => {
- return common_vendor.e({
- a: common_vendor.t(method.icon),
- b: method.iconBg,
- c: common_vendor.t(method.name),
- d: $data.selectedMethod === index
- }, $data.selectedMethod === index ? {} : {}, {
- e: $data.selectedMethod === index ? 1 : "",
- f: index,
- g: common_vendor.o(($event) => $options.selectPaymentMethod(index), index)
- });
- }),
- d: common_vendor.o((...args) => $options.confirmPayment && $options.confirmPayment(...args))
- };
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-eade9ab2"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/payment/payment.js.map
|