210 lines
7.8 KiB
JavaScript
210 lines
7.8 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const pages_oldmanindex_api = require("./api.js");
|
||
const _sfc_main = {
|
||
__name: "account",
|
||
setup(__props) {
|
||
const goBack = () => {
|
||
common_vendor.index.navigateBack();
|
||
};
|
||
const item = common_vendor.ref({});
|
||
const payurl = common_vendor.ref("");
|
||
common_vendor.onLoad(() => {
|
||
item.value = common_vendor.index.getStorageSync("payaccount");
|
||
pages_oldmanindex_api.getAccount(item.value.orgCode).then((res) => {
|
||
payurl.value = res.result.url;
|
||
});
|
||
});
|
||
const initiatePayment = async () => {
|
||
var _a, _b;
|
||
try {
|
||
const urlpost = `${payurl.value}/weiXinPay/nuBindPay`;
|
||
const payload = {
|
||
title: "护理单元绑定",
|
||
openId: common_vendor.index.getStorageSync("openid") || "",
|
||
amountPrice: item.value.payableAmount,
|
||
orgCode: item.value.nuId.substring(4, 7),
|
||
nursingUnit: item.value.nuId,
|
||
orderDesc: `用户绑定护理单元${(_a = item.value) == null ? void 0 : _a.nuId},充值${(_b = item.value) == null ? void 0 : _b.payableAmount}元`,
|
||
// customerId: '顾客id',
|
||
orderType: "binding_nu",
|
||
price: item.value.payableAmount,
|
||
count: 1,
|
||
unit: "间",
|
||
customerId: common_vendor.index.getStorageSync("allinfo").id
|
||
};
|
||
common_vendor.index.__f__("log", "at pages/oldmanindex/account.vue:139", "AAAAAAA", payload);
|
||
common_vendor.index.showLoading({
|
||
title: "正在请求支付..."
|
||
});
|
||
const res = await new Promise((resolve, reject) => {
|
||
common_vendor.index.request({
|
||
url: urlpost,
|
||
method: "POST",
|
||
header: {
|
||
"Content-Type": "application/json"
|
||
},
|
||
data: payload,
|
||
success: (r) => resolve(r),
|
||
fail: (e) => reject(e)
|
||
});
|
||
});
|
||
common_vendor.index.hideLoading();
|
||
const data = res && res.data ? res.data : res;
|
||
common_vendor.index.__f__("log", "at pages/oldmanindex/account.vue:165", "data", data);
|
||
if (data.nuFailType == "ORG_PAYMENT_DISABLED") {
|
||
common_vendor.index.showToast({
|
||
title: "机构已经关闭微信支付功能",
|
||
icon: "none"
|
||
});
|
||
setTimeout(() => {
|
||
common_vendor.index.reLaunch({
|
||
url: "/pages/oldmanindex/index"
|
||
});
|
||
}, 1e3);
|
||
} else if (data.nuFailType == "NU_HAS_BEEN_BOUND") {
|
||
common_vendor.index.showToast({
|
||
title: "护理单元已被其他用户绑定",
|
||
icon: "none"
|
||
});
|
||
setTimeout(() => {
|
||
common_vendor.index.reLaunch({
|
||
url: "/pages/oldmanindex/index"
|
||
});
|
||
}, 1e3);
|
||
}
|
||
if (!data) {
|
||
common_vendor.index.showToast({
|
||
title: "服务器无响应",
|
||
icon: "error"
|
||
});
|
||
return;
|
||
}
|
||
if (data.appId || data.timeStamp || data.package || data.paySign) {
|
||
await callWeixinPay(data);
|
||
} else {
|
||
common_vendor.index.showToast({
|
||
title: "支付信息获取失败",
|
||
icon: "error"
|
||
});
|
||
common_vendor.index.__f__("error", "at pages/oldmanindex/account.vue:208", "支付返回:", data);
|
||
}
|
||
} catch (err) {
|
||
common_vendor.index.hideLoading();
|
||
common_vendor.index.__f__("error", "at pages/oldmanindex/account.vue:212", "请求失败:", err);
|
||
common_vendor.index.showToast({
|
||
title: "请求失败",
|
||
icon: "error"
|
||
});
|
||
}
|
||
};
|
||
function callWeixinPay(data) {
|
||
common_vendor.index.__f__("log", "at pages/oldmanindex/account.vue:222", "????", data);
|
||
return new Promise((resolve, reject) => {
|
||
const isH5 = typeof window !== "undefined" && typeof navigator !== "undefined";
|
||
const ua = isH5 ? navigator.userAgent || "" : "";
|
||
const isWeixinBrowser = /MicroMessenger/i.test(ua);
|
||
if (isH5 && isWeixinBrowser) {
|
||
const invokePay = () => {
|
||
try {
|
||
window.WeixinJSBridge.invoke(
|
||
"getBrandWCPayRequest",
|
||
{
|
||
appId: data.appId,
|
||
timeStamp: String(data.timeStamp),
|
||
// 字符串
|
||
nonceStr: data.nonceStr,
|
||
package: data.package,
|
||
// 注意字段名:package
|
||
signType: data.signType || "MD5",
|
||
paySign: data.paySign
|
||
},
|
||
function(res) {
|
||
if (res && (res.err_msg === "get_brand_wcpay_request:ok" || res.err_msg === "get_brand_wcpay_request:ok")) {
|
||
common_vendor.index.showToast({
|
||
title: "支付成功"
|
||
});
|
||
common_vendor.index.reLaunch({
|
||
url: "/pages/oldmanindex/paysuccess"
|
||
});
|
||
} else {
|
||
common_vendor.index.showToast({
|
||
title: "支付失败或取消",
|
||
icon: "none"
|
||
});
|
||
}
|
||
}
|
||
);
|
||
} catch (e) {
|
||
common_vendor.index.__f__("error", "at pages/oldmanindex/account.vue:267", "WeixinJSBridge 调用异常", e);
|
||
common_vendor.index.showToast({
|
||
title: "支付调用失败",
|
||
icon: "error"
|
||
});
|
||
reject(e);
|
||
}
|
||
};
|
||
if (typeof window.WeixinJSBridge === "undefined") {
|
||
document.addEventListener("WeixinJSBridgeReady", invokePay, false);
|
||
} else {
|
||
invokePay();
|
||
}
|
||
return;
|
||
}
|
||
try {
|
||
common_vendor.index.requestPayment({
|
||
provider: "wxpay",
|
||
timeStamp: String(data.timeStamp || data.timeStampStr || ""),
|
||
// 小程序需要字符串
|
||
nonceStr: data.nonceStr || "",
|
||
package: data.package || data.packageStr || "",
|
||
// e.g. 'prepay_id=xxx'
|
||
signType: data.signType || "MD5",
|
||
paySign: data.paySign || "",
|
||
success: (res) => {
|
||
common_vendor.index.showToast({
|
||
title: "支付成功"
|
||
});
|
||
common_vendor.index.reLaunch({
|
||
url: "/pages/oldmanindex/paysuccess"
|
||
});
|
||
resolve(res);
|
||
},
|
||
fail: (err) => {
|
||
common_vendor.index.__f__("error", "at pages/oldmanindex/account.vue:306", "小程序支付失败或取消", err);
|
||
common_vendor.index.showToast({
|
||
title: "支付失败或取消",
|
||
icon: "none"
|
||
});
|
||
reject(err);
|
||
}
|
||
});
|
||
} catch (e) {
|
||
common_vendor.index.__f__("error", "at pages/oldmanindex/account.vue:315", "uni.requestPayment 调用异常", e);
|
||
common_vendor.index.showToast({
|
||
title: "支付调用失败",
|
||
icon: "error"
|
||
});
|
||
reject(e);
|
||
}
|
||
return;
|
||
});
|
||
}
|
||
return (_ctx, _cache) => {
|
||
return {
|
||
a: common_vendor.o(goBack),
|
||
b: `${common_vendor.index.getStorageSync("moveHeight") + 40}px`,
|
||
c: `${common_vendor.index.getStorageSync("moveHeight") + 30}px`,
|
||
d: common_vendor.t(item.value.departName),
|
||
e: common_vendor.t(item.value.nuName),
|
||
f: common_vendor.t(item.value.payableAmount),
|
||
g: common_vendor.o(goBack),
|
||
h: common_vendor.o(initiatePayment)
|
||
};
|
||
};
|
||
}
|
||
};
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-09ac646e"]]);
|
||
wx.createPage(MiniProgramPage);
|
||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/oldmanindex/account.js.map
|