Files
console-dev/app/pages/products/[id].vue
T
2026-11-07 08:27:36 +08:00

478 lines
19 KiB
Vue

<script>
/**
* 商品详情/购物车编辑入口:校验商品与编辑位置,按服务端模块选择配置器;下单结果交给公共支付弹窗处理。
*/
import { definePageMeta } from "#imports";
import "~/assets/styles/MfDcimConfig.BhC_eZ0V.css";
import "~/assets/styles/MfCloudConfig.DbgUu8qr.css";
import "~/assets/styles/KkyEcsConfig.BFaAwQPZ.css";
import "~/assets/styles/ConfigResourceOption.Dj4VopnA.css";
import "~/assets/styles/ConfigDiskAdd.C92e9ZuF.css";
import "~/assets/styles/ConfigBandwidth.CWSH1WJZ.css";
import "~/assets/styles/JyCloudConfig.kGfttaHi.css";
import "~/assets/styles/FinanceConfig.CLwX1CC8.css";
import "~/assets/styles/ConfigDiskCard.Dx9IqqQ_.css";
import "~/assets/styles/PromoCodeField.qFEkB6Hm.css";
import "~/assets/styles/ProductCustomFields.B2QMnPil.css";
import "~/assets/styles/OsIcon.CAi4Iz2S.css";
import "~/assets/styles/CommonConfig.Cfik-oMe.css";
import "~/assets/styles/PaymentDialog.BNFKQF1U.css";
import "~/assets/styles/_id_.CSXsMADH.css";
definePageMeta({
key: (e) => e.fullPath,
});
import { toDisplayString } from "vue";
import { onMounted } from "vue";
import { onScopeDispose } 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 { useRoute } from "#app";
import { useRouter } from "#app";
import { NuxtLink } from "#components";
import { useApi } from "~/lib/auth.js";
import button from "openvue/button";
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
import message from "openvue/message";
import { n as product_name_n } from "~/lib/product-name.js";
import PaymentDialog from "~/components/PaymentDialog.vue";
import { t as product_order_module_t } from "~/lib/product-order-module.js";
import ConfigLoadingShell from "~/components/config/ConfigLoadingShell.vue";
import { n as cart_edit_n } from "~/lib/cart-edit.js";
import { requireCartRevision } from "~/lib/cart-edit.js";
import CommonConfig from "~/components/config/CommonConfig.vue";
import FinanceConfig from "~/components/config/FinanceConfig.vue";
import JyCloudConfig from "~/components/config/JyCloudConfig.vue";
import KkyEcsConfig from "~/components/config/KkyEcsConfig.vue";
import MfCloudConfig from "~/components/config/MfCloudConfig.vue";
import { r as order_image_continuation_r } from "~/lib/order-image-continuation.js";
import MfDcimConfig from "~/components/config/MfDcimConfig.vue";
import { t as composables_t } from "~/lib/composables-2.js";
import { t as product_description_data_t } from "~/lib/product-description-data.js";
import { productId } from "~/lib/product-id.js";
var j = {
class: `page product-order-page`,
},
M = {
class: `product-head`,
},
N = {
class: `product-links`,
"aria-label": `订购导航`,
},
P = {
key: 1,
class: `panel config-load-error`,
},
F = {
key: 6,
class: `panel`,
},
I = _plugin_vue_export_helper_t(
defineComponent({
__name: `[id]`,
setup(f) {
let b = useRoute(),
I = useRouter(),
L = useApi(),
R = b.params.id ?? b.query.id ?? b.query.product_id ?? ``,
z = order_image_continuation_r(b.query.order_image),
B = b.fullPath;
composables_t({
key: (e) => e.fullPath,
});
// 返回商品目录时仅保留有效的一、二级分类 ID,避免携带任意查询值。
function V() {
let e = {},
t = b.query.g ?? b.query.first_group_id,
n = b.query.sg ?? b.query.second_group_id;
return (
typeof t == `string` && /^[1-9]\d*$/.test(t) && (e.g = t),
typeof n == `string` && /^[1-9]\d*$/.test(n) && (e.sg = n),
{
path: `/products`,
query: e,
}
);
}
let H = ref(null),
U = ref(null),
W = ref(!0),
G = ref(``),
K = computed(() => {
let e = b.query.edit_position;
if (typeof e != `string` || !/^\d+$/.test(e)) return null;
let t = Number(e);
return Number.isInteger(t) && t >= 0 ? t : null;
}),
q = computed(() => {
if (K.value !== null && U.value)
return {
position: K.value,
item: U.value.item,
revision: U.value.revision,
};
return undefined;
}),
J = ref(!1),
Y = ref(null),
X = ref(``),
Z = 0;
onScopeDispose(() => {
Z++;
});
// 依次确认商品可售、购物车位置仍匹配、模块可用;请求序号防止旧详情或描述覆盖新页面。
async function Q() {
let e = ++Z;
((W.value = !0), (G.value = ``), (H.value = null), (U.value = null));
try {
if (productId(R) === null) throw Error(`商品编号无效`);
let t = await L.get(`/product/${R}`);
if (e !== Z) return;
let n = t?.product ?? t;
if (
!n ||
typeof n != `object` ||
!n.id ||
Number(n.id) !== Number(R)
)
throw Error(`商品不存在或已下架`);
let r = n;
if (r.order_allowed === !1)
throw Error(r.order_block_reason || `该产品已停止订购`);
if (K.value !== null) {
let t = await L.get(`/cart`),
item = t?.list?.[K.value];
if (!item || Number(item.product_id) !== Number(R))
throw Error(`购物车商品已变化,请返回购物车重新编辑`);
if (e !== Z) return;
U.value = {
item: cart_edit_n(item),
revision: requireCartRevision(t),
};
}
let i = await product_order_module_t(L, r);
if (e !== Z) return;
((H.value = {
...r,
module: i,
}),
product_description_data_t(L, r).then((t) => {
e === Z && H.value && (H.value.description = t);
}));
} catch (t) {
e === Z &&
(G.value = t instanceof Error ? t.message : `加载商品失败`);
} finally {
e === Z && (W.value = !1);
}
}
// 接收配置器返回的订单 ID 与金额,打开支付而不在此页重新创建订单。
function $(e) {
((Y.value = e.order_id), (X.value = e.amount), (J.value = !0));
}
// 支付完成后进入订单列表,后续状态由订单页确认。
function se() {
I.push(`/orders`);
}
return (
onMounted(Q),
// 商品模块决定实际配置组件;加载、不可售和模块错误先显示提示,配置器返回订单后才打开支付。
(t, n) => {
let i = NuxtLink,
o = ConfigLoadingShell,
f = message,
h = button,
g = MfCloudConfig,
v = MfDcimConfig,
b = CommonConfig,
C = FinanceConfig,
T = KkyEcsConfig,
O = PaymentDialog;
return (
openBlock(),
createElementBlock(`div`, j, [
createElementVNode(`header`, M, [
createElementVNode(`div`, null, [
createElementVNode(
`h1`,
null,
toDisplayString(
unref(product_name_n)(unref(H)?.name) || `配置产品`,
),
1,
),
createElementVNode(
`p`,
null,
toDisplayString(
unref(q)
? `编辑购物车商品配置,保存后返回购物车结算。`
: `选择所需资源,确认配置与费用后购买。`,
),
1,
),
]),
createElementVNode(`nav`, N, [
createVNode(
i,
{
to: V(),
class: `back`,
},
{
default: withCtx(() => [
...(n[1] ||= [
createElementVNode(
`i`,
{
class: `pi pi-angle-left`,
"aria-hidden": `true`,
},
null,
-1,
),
createTextVNode(`返回产品列表`, -1),
]),
]),
_: 1,
},
8,
[`to`],
),
createVNode(
i,
{
to: `/cart`,
class: `cart-link`,
},
{
default: withCtx(() => [
...(n[2] ||= [
createElementVNode(
`i`,
{
class: `pi pi-shopping-cart`,
"aria-hidden": `true`,
},
null,
-1,
),
createTextVNode(`购物车`, -1),
]),
]),
_: 1,
},
),
]),
]),
unref(W)
? (openBlock(),
createBlock(o, {
key: 0,
}))
: unref(G) && !unref(H)
? (openBlock(),
createElementBlock(`div`, P, [
createVNode(
f,
{
severity: `error`,
closable: !1,
},
{
default: withCtx(() => [
createTextVNode(toDisplayString(unref(G)), 1),
]),
_: 1,
},
),
createVNode(h, {
label: `重新加载商品`,
icon: `pi pi-refresh`,
severity: `secondary`,
text: ``,
onClick: Q,
}),
]))
: unref(H)
? (openBlock(),
createElementBlock(
Fragment,
{
key: 2,
},
[
unref(H).module === `mf_cloud` ||
unref(H).module === `remf_cloud`
? (openBlock(),
createBlock(
g,
{
key: 0,
"product-id": unref(R),
module: unref(H).module,
"initial-image-id": unref(z),
"continuation-path": unref(B),
"initial-product": unref(H),
edit: unref(q),
onSettled: $,
},
null,
8,
[
`product-id`,
`module`,
`initial-image-id`,
`continuation-path`,
`initial-product`,
`edit`,
],
))
: unref(H).module === `mf_dcim` ||
unref(H).module === `remf_dcim`
? (openBlock(),
createBlock(
v,
{
key: 1,
"product-id": unref(R),
module: unref(H).module,
"initial-product": unref(H),
edit: unref(q),
onSettled: $,
},
null,
8,
[
`product-id`,
`module`,
`initial-product`,
`edit`,
],
))
: unref(H).module === `jy_cloud` ||
unref(H).module === `jy_dcim`
? (openBlock(),
createBlock(
JyCloudConfig,
{
key: 2,
"product-id": unref(R),
module: unref(H).module,
edit: unref(q),
onSettled: $,
},
null,
8,
[`product-id`, `module`, `edit`],
))
: unref(H).module === `idcsmart_common`
? (openBlock(),
createBlock(
b,
{
key: 3,
"product-id": unref(R),
edit: unref(q),
onSettled: $,
},
null,
8,
[`product-id`, `edit`],
))
: [
`remf_finance`,
`remf_finance_dcim`,
`remf_finance_common`,
].includes(unref(H).module || ``)
? (openBlock(),
createBlock(
C,
{
key: 4,
"product-id": unref(R),
module: unref(H).module,
edit: unref(q),
onSettled: $,
},
null,
8,
[`product-id`, `module`, `edit`],
))
: unref(H).module === `kky_ecs`
? (openBlock(),
createBlock(
T,
{
key: 5,
"product-id": unref(R),
edit: unref(q),
onSettled: $,
},
null,
8,
[`product-id`, `edit`],
))
: (openBlock(),
createElementBlock(`div`, F, [
createVNode(
f,
{
severity: `warn`,
closable: !1,
},
{
default: withCtx(() => [
...(n[3] ||= [
createTextVNode(
` 该商品暂不支持在线配置,请联系客服下单。 `,
-1,
),
]),
]),
_: 1,
},
),
])),
],
64,
))
: createCommentVNode(``, !0),
createVNode(
O,
{
modelValue: unref(J),
"onUpdate:modelValue": (n[0] ||= (e) =>
isRef(J) ? (J.value = e) : null),
"order-id": unref(Y),
amount: unref(X),
onSuccess: se,
},
null,
8,
[`modelValue`, `order-id`, `amount`],
),
])
);
}
);
},
}),
[[`__scopeId`, `data-v-49461ec8`]],
);
export {};
export default I;
</script>