first commit
This commit is contained in:
commit
db5762abd4
687 files changed
+171307
No files matched your search
@@ -0,0 +1,340 @@
|
||||
<script>
|
||||
import "~/assets/styles/LegacyProductUpgrade.dzWGwGgY.css";
|
||||
import { toDisplayString } from "vue";
|
||||
import { onMounted } from "vue";
|
||||
import { onBeforeUnmount } from "vue";
|
||||
import { watch } from "vue";
|
||||
import { createBlock } from "vue";
|
||||
import { ref } from "vue";
|
||||
import { withCtx } from "vue";
|
||||
import { createCommentVNode } from "vue";
|
||||
import { computed } from "vue";
|
||||
import { isRef } from "vue";
|
||||
import { createElementBlock } from "vue";
|
||||
import { Fragment } from "vue";
|
||||
import { createElementVNode } from "vue";
|
||||
import { createTextVNode } from "vue";
|
||||
import { unref } from "vue";
|
||||
import { defineComponent } from "vue";
|
||||
import { createVNode } from "vue";
|
||||
import { openBlock } from "vue";
|
||||
import { useApi } from "~/lib/auth.js";
|
||||
import button from "primevue/button";
|
||||
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
|
||||
import message from "primevue/message";
|
||||
import select from "primevue/select";
|
||||
var C = {
|
||||
key: 0,
|
||||
class: `product-upgrade`,
|
||||
},
|
||||
w = {
|
||||
key: 2,
|
||||
},
|
||||
T = {
|
||||
key: 0,
|
||||
},
|
||||
E = Object.assign(
|
||||
_plugin_vue_export_helper_t(
|
||||
defineComponent({
|
||||
__name: `LegacyProductUpgrade`,
|
||||
props: {
|
||||
hostId: {},
|
||||
module: {
|
||||
default: `remf_finance`,
|
||||
},
|
||||
upgradeAllowed: {
|
||||
type: Boolean,
|
||||
default: !0,
|
||||
},
|
||||
},
|
||||
emits: [`pay`],
|
||||
setup(h, { expose: b, emit: E }) {
|
||||
let D = h,
|
||||
O = E,
|
||||
k = useApi(),
|
||||
A = ref([]),
|
||||
j = ref(null),
|
||||
M = ref(``),
|
||||
N = ref(!1),
|
||||
P = ref(!1),
|
||||
F = ref(!1),
|
||||
I = ref(``),
|
||||
L = ref(``),
|
||||
R = computed(() => A.value.find((e) => e.pid === j.value)),
|
||||
z = computed(() =>
|
||||
JSON.stringify([D.hostId, D.module, j.value, M.value]),
|
||||
),
|
||||
B = 0,
|
||||
V = 0,
|
||||
H = !1,
|
||||
U = ``;
|
||||
function W() {
|
||||
(B++, (L.value = ``), (U = ``), (P.value = !1), (I.value = ``));
|
||||
}
|
||||
async function G() {
|
||||
if (D.upgradeAllowed === !1 || H) return;
|
||||
let e = ++V;
|
||||
((N.value = !0), (I.value = ``), W());
|
||||
try {
|
||||
let t = await k.get(`/${D.module}/${D.hostId}/upgrade_product`);
|
||||
if (H || e !== V) return;
|
||||
if (!Array.isArray(t.host))
|
||||
throw Error(`可升级商品列表无效,请重试`);
|
||||
((A.value = t.host.filter(
|
||||
(e) =>
|
||||
/^[1-9]\d*$/.test(String(e.pid)) && Array.isArray(e.cycle),
|
||||
)),
|
||||
(j.value = null),
|
||||
(M.value = ``));
|
||||
} catch (t) {
|
||||
!H &&
|
||||
e === V &&
|
||||
(I.value = t instanceof Error ? t.message : `升级商品加载失败`);
|
||||
} finally {
|
||||
e === V && (N.value = !1);
|
||||
}
|
||||
}
|
||||
async function K() {
|
||||
if (
|
||||
D.upgradeAllowed === !1 ||
|
||||
F.value ||
|
||||
!R.value?.cycle.some((e) => e.billingcycle === M.value)
|
||||
)
|
||||
return;
|
||||
let e = ++B,
|
||||
t = z.value;
|
||||
((P.value = !0), (L.value = ``), (I.value = ``), (U = ``));
|
||||
try {
|
||||
let n = await k.post(
|
||||
`/${D.module}/${D.hostId}/sync_upgrade_product_price`,
|
||||
{
|
||||
product_id: j.value,
|
||||
cycle: M.value,
|
||||
},
|
||||
);
|
||||
if (H || e !== B || t !== z.value) return;
|
||||
if (
|
||||
n.price === null ||
|
||||
n.price === void 0 ||
|
||||
String(n.price).trim() === `` ||
|
||||
!Number.isFinite(Number(n.price))
|
||||
)
|
||||
throw Error(`升级报价无效,请重试`);
|
||||
((L.value = String(n.price)), (U = t));
|
||||
} catch (t) {
|
||||
!H &&
|
||||
e === B &&
|
||||
(I.value = t instanceof Error ? t.message : `升级询价失败`);
|
||||
} finally {
|
||||
e === B && (P.value = !1);
|
||||
}
|
||||
}
|
||||
async function q() {
|
||||
if (
|
||||
D.upgradeAllowed === !1 ||
|
||||
F.value ||
|
||||
P.value ||
|
||||
!L.value ||
|
||||
U !== z.value ||
|
||||
H
|
||||
)
|
||||
return;
|
||||
let e = z.value,
|
||||
t = L.value,
|
||||
n = {
|
||||
product_id: j.value,
|
||||
cycle: M.value,
|
||||
};
|
||||
((F.value = !0), (I.value = ``));
|
||||
try {
|
||||
let r = await k.post(
|
||||
`/${D.module}/${D.hostId}/upgrade_product`,
|
||||
n,
|
||||
);
|
||||
if (H || e !== z.value) return;
|
||||
if (!/^[1-9]\d*$/.test(String(r.id)))
|
||||
throw Error(`升级订单无效,请重试`);
|
||||
(W(),
|
||||
O(`pay`, {
|
||||
order_id: r.id,
|
||||
amount: t,
|
||||
}));
|
||||
} catch (t) {
|
||||
!H &&
|
||||
e === z.value &&
|
||||
(I.value = t instanceof Error ? t.message : `升级订单创建失败`);
|
||||
} finally {
|
||||
H || (F.value = !1);
|
||||
}
|
||||
}
|
||||
return (
|
||||
watch(
|
||||
j,
|
||||
() => {
|
||||
((M.value = ``), W());
|
||||
},
|
||||
{
|
||||
flush: `sync`,
|
||||
},
|
||||
),
|
||||
watch(M, W, {
|
||||
flush: `sync`,
|
||||
}),
|
||||
watch(
|
||||
[() => D.hostId, () => D.module, () => D.upgradeAllowed],
|
||||
() => {
|
||||
(W(), (A.value = []), (j.value = null), G());
|
||||
},
|
||||
{
|
||||
flush: `sync`,
|
||||
},
|
||||
),
|
||||
onMounted(G),
|
||||
onBeforeUnmount(() => {
|
||||
((H = !0), B++, V++);
|
||||
}),
|
||||
b({
|
||||
busy: F,
|
||||
}),
|
||||
(t, n) => {
|
||||
let r = message,
|
||||
a = button,
|
||||
c = select;
|
||||
return h.upgradeAllowed === !1
|
||||
? createCommentVNode(``, !0)
|
||||
: (openBlock(),
|
||||
createElementBlock(`section`, C, [
|
||||
(n[2] ||= createElementVNode(`h4`, null, `变更商品`, -1)),
|
||||
unref(I)
|
||||
? (openBlock(),
|
||||
createBlock(
|
||||
r,
|
||||
{
|
||||
key: 0,
|
||||
severity: `error`,
|
||||
closable: !1,
|
||||
},
|
||||
{
|
||||
default: withCtx(() => [
|
||||
createTextVNode(toDisplayString(unref(I)), 1),
|
||||
]),
|
||||
_: 1,
|
||||
},
|
||||
))
|
||||
: createCommentVNode(``, !0),
|
||||
unref(A).length
|
||||
? createCommentVNode(``, !0)
|
||||
: (openBlock(),
|
||||
createBlock(
|
||||
a,
|
||||
{
|
||||
key: 1,
|
||||
label: unref(N)
|
||||
? `正在加载可升级商品`
|
||||
: `刷新可升级商品`,
|
||||
text: ``,
|
||||
loading: unref(N),
|
||||
onClick: G,
|
||||
},
|
||||
null,
|
||||
8,
|
||||
[`label`, `loading`],
|
||||
)),
|
||||
!unref(N) && !unref(I) && !unref(A).length
|
||||
? (openBlock(),
|
||||
createElementBlock(`p`, w, `当前暂无可升级商品。`))
|
||||
: createCommentVNode(``, !0),
|
||||
unref(A).length
|
||||
? (openBlock(),
|
||||
createElementBlock(
|
||||
Fragment,
|
||||
{
|
||||
key: 3,
|
||||
},
|
||||
[
|
||||
createVNode(
|
||||
c,
|
||||
{
|
||||
modelValue: unref(j),
|
||||
"onUpdate:modelValue": (n[0] ||= (e) =>
|
||||
isRef(j) ? (j.value = e) : null),
|
||||
"aria-label": `升级目标商品`,
|
||||
options: unref(A),
|
||||
"option-label": `host`,
|
||||
"option-value": `pid`,
|
||||
placeholder: `选择目标商品`,
|
||||
disabled: unref(F),
|
||||
},
|
||||
null,
|
||||
8,
|
||||
[`modelValue`, `options`, `disabled`],
|
||||
),
|
||||
createVNode(
|
||||
c,
|
||||
{
|
||||
modelValue: unref(M),
|
||||
"onUpdate:modelValue": (n[1] ||= (e) =>
|
||||
isRef(M) ? (M.value = e) : null),
|
||||
"aria-label": `升级计费周期`,
|
||||
options: unref(R)?.cycle ?? [],
|
||||
"option-label": `billingcycle_zh`,
|
||||
"option-value": `billingcycle`,
|
||||
placeholder: `选择计费周期`,
|
||||
disabled: unref(F) || !unref(R),
|
||||
},
|
||||
null,
|
||||
8,
|
||||
[`modelValue`, `options`, `disabled`],
|
||||
),
|
||||
createVNode(
|
||||
a,
|
||||
{
|
||||
label: `计算变更费用`,
|
||||
outlined: ``,
|
||||
loading: unref(P),
|
||||
disabled: unref(F) || !unref(M),
|
||||
onClick: K,
|
||||
},
|
||||
null,
|
||||
8,
|
||||
[`loading`, `disabled`],
|
||||
),
|
||||
unref(L) === ``
|
||||
? createCommentVNode(``, !0)
|
||||
: (openBlock(),
|
||||
createElementBlock(
|
||||
`p`,
|
||||
T,
|
||||
`变更费用:¥` + toDisplayString(unref(L)),
|
||||
1,
|
||||
)),
|
||||
createVNode(
|
||||
a,
|
||||
{
|
||||
label: `确认生成升级订单`,
|
||||
loading: unref(F),
|
||||
disabled: unref(L) === `` || unref(P),
|
||||
onClick: q,
|
||||
},
|
||||
null,
|
||||
8,
|
||||
[`loading`, `disabled`],
|
||||
),
|
||||
],
|
||||
64,
|
||||
))
|
||||
: createCommentVNode(``, !0),
|
||||
]));
|
||||
}
|
||||
);
|
||||
},
|
||||
}),
|
||||
[[`__scopeId`, `data-v-3bd25322`]],
|
||||
),
|
||||
{
|
||||
__name: `LegacyProductUpgrade`,
|
||||
},
|
||||
);
|
||||
export {};
|
||||
export default E;
|
||||
</script>
|
||||
Reference in new issue
Block a user