acdr-ui/dist/dev/mp-weixin/modules/mall/pay/index.js

177 lines
6.3 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"use strict";
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const common_vendor = require("../../../common/vendor.js");
2024-10-01 09:15:35 +08:00
const modules_mall_sheep_index = require("../sheep/index.js");
const modules_mall_sheep_hooks_useGoods = require("../sheep/hooks/useGoods.js");
const modules_mall_sheep_api_pay_order = require("../sheep/api/pay/order.js");
const modules_mall_sheep_api_pay_channel = require("../sheep/api/pay/channel.js");
const modules_mall_sheep_platform_pay = require("../sheep/platform/pay.js");
2024-09-19 07:20:14 +08:00
if (!Array) {
const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
(_easycom_s_layout2 + _component_layout_default_uni)();
}
2024-10-01 09:15:35 +08:00
const _easycom_s_layout = () => "../sheep/components/s-layout/s-layout.js";
2024-09-19 07:20:14 +08:00
if (!Math) {
_easycom_s_layout();
}
const _sfc_main = {
__name: "index",
setup(__props) {
2024-10-01 09:15:35 +08:00
const userWallet = common_vendor.computed(() => modules_mall_sheep_index.sheep.$store("user").userWallet);
2024-09-19 07:20:14 +08:00
const state = common_vendor.reactive({
orderType: "goods",
// 订单类型; goods - 商品订单, recharge - 充值订单
orderInfo: {},
// 支付单信息
payStatus: 0,
// 0=检测支付环境, -2=未查询到支付单信息, -1=支付已过期, 1=待支付2=订单已支付
payMethods: [],
// 可选的支付方式
payment: ""
// 选中的支付方式
});
const onPay = () => {
if (state.payment === "") {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_index.sheep.$helper.toast("请选择支付方式");
2024-09-19 07:20:14 +08:00
return;
}
if (state.payment === "wallet") {
common_vendor.index.showModal({
title: "提示",
content: "确定要支付吗?",
success: function(res) {
if (res.confirm) {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_index.sheep.$platform.pay(state.payment, state.orderType, state.orderInfo.id);
2024-09-19 07:20:14 +08:00
}
}
});
} else {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_index.sheep.$platform.pay(state.payment, state.orderType, state.orderInfo.id);
2024-09-19 07:20:14 +08:00
}
};
const payDescText = common_vendor.computed(() => {
if (state.payStatus === 2) {
return "该订单已支付";
}
if (state.payStatus === 1) {
2024-10-01 09:15:35 +08:00
const time = modules_mall_sheep_hooks_useGoods.useDurationTime(state.orderInfo.expireTime);
2024-09-19 07:20:14 +08:00
if (time.ms <= 0) {
state.payStatus = -1;
return "";
}
return `剩余支付时间 ${time.h}:${time.m}:${time.s} `;
}
if (state.payStatus === -2) {
return "未查询到支付单信息";
}
return "";
});
function checkPayStatus() {
if (state.orderInfo.status === 10 || state.orderInfo.status === 20) {
state.payStatus = 2;
return;
}
if (state.orderInfo.status === 30) {
state.payStatus = -1;
return;
}
state.payStatus = 1;
}
function onTapPay(e) {
state.payment = e.detail.value;
}
function setOrder(id) {
return __async(this, null, function* () {
2024-10-01 09:15:35 +08:00
const { data, code } = yield modules_mall_sheep_api_pay_order.PayOrderApi.getOrder(id);
2024-09-19 07:20:14 +08:00
if (code !== 0 || !data) {
state.payStatus = -2;
return;
}
state.orderInfo = data;
yield setPayMethods();
checkPayStatus();
});
}
function setPayMethods() {
return __async(this, null, function* () {
2024-10-01 09:15:35 +08:00
const { data, code } = yield modules_mall_sheep_api_pay_channel.PayChannelApi.getEnableChannelCodeList(state.orderInfo.appId);
2024-09-19 07:20:14 +08:00
if (code !== 0) {
return;
}
2024-10-01 09:15:35 +08:00
state.payMethods = modules_mall_sheep_platform_pay.getPayMethods(data);
2024-09-19 07:20:14 +08:00
});
}
common_vendor.onLoad((options) => {
2024-10-01 09:15:35 +08:00
if (modules_mall_sheep_index.sheep.$platform.name === "WechatOfficialAccount" && modules_mall_sheep_index.sheep.$platform.os === "ios" && !modules_mall_sheep_index.sheep.$platform.landingPage.includes("pages/pay/index")) {
2024-09-19 07:20:14 +08:00
location.reload();
return;
}
const id = options.id;
if (options.orderType) {
state.orderType = options.orderType;
}
setOrder(id);
2024-10-01 09:15:35 +08:00
modules_mall_sheep_index.sheep.$store("user").getWallet();
2024-09-19 07:20:14 +08:00
});
return (_ctx, _cache) => {
return common_vendor.e({
2024-10-01 09:15:35 +08:00
a: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price)),
2024-09-19 07:20:14 +08:00
b: common_vendor.t(payDescText.value),
c: common_vendor.f(state.payMethods, (item, k0, i0) => {
return common_vendor.e({
a: item.disabled
}, item.disabled ? {
2024-10-01 09:15:35 +08:00
b: common_vendor.unref(modules_mall_sheep_index.sheep).$url.static("/static/img/shop/pay/cod_disabled.png")
2024-09-19 07:20:14 +08:00
} : {
2024-10-01 09:15:35 +08:00
c: common_vendor.unref(modules_mall_sheep_index.sheep).$url.static(item.icon)
2024-09-19 07:20:14 +08:00
}, {
d: common_vendor.t(item.title),
e: item.value === "wallet"
}, item.value === "wallet" ? {
2024-10-01 09:15:35 +08:00
f: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(userWallet.value.balance))
2024-09-19 07:20:14 +08:00
} : {}, {
g: item.value,
h: item.disabled,
i: state.payment === item.value,
j: item.disabled ? 1 : "",
k: item.title
});
}),
d: common_vendor.o(onTapPay),
e: state.payStatus === 0
}, state.payStatus === 0 ? {} : state.payStatus === -1 ? {} : {
g: common_vendor.o(onPay),
h: state.payStatus !== 1,
i: state.payStatus !== 1 ? 1 : ""
}, {
f: state.payStatus === -1,
j: common_vendor.p({
title: "收银台"
})
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f56060e4"]]);
wx.createPage(MiniProgramPage);