You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

150 lines
11 KiB

import { _ as __nuxt_component_0 } from './AccountCredentialDialog-D37zgaXm.mjs';
import { defineComponent, ref, reactive, computed, unref, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrRenderStyle, ssrRenderList, ssrInterpolate, ssrRenderAttr, ssrIncludeBooleanAttr, ssrLooseContain, ssrLooseEqual, ssrRenderComponent } from 'vue/server-renderer';
import { u as useApi } from './useApi-BNSkSrat.mjs';
import { u as useToast } from './useToast-MBvLaNjH.mjs';
import { a as useAuthStore } from './server.mjs';
import '../nitro/nitro.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'unhead/server';
import 'devalue';
import 'unhead/utils';
import 'pinia';
import 'perfect-debounce';
const PLATFORM_MAIL = "358030594@qq.com";
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "factory",
__ssrInlineRender: true,
setup(__props) {
useApi();
useToast();
const auth = useAuthStore();
const view = ref("list");
const rows = ref([]);
const providers = ref([]);
const loading = ref(false);
const submitting = ref(false);
const isEditing = ref(false);
const emails = ref([]);
const newEmail = ref("");
const form = reactive({
id: 0,
brand: "",
providerid: 0,
description: "",
sharepct: 0,
// 仅新增时用:官方渠道名称 + 顺手开一个品牌商账号
officialChannelName: "",
createAccount: false,
accountUsername: "",
accountPassword: "",
accountRemark: ""
});
const defaultOfficialName = computed(() => (form.brand.trim() || "品牌") + "官方渠道");
const credentialMails = computed(
() => emails.value.filter((e) => e.toLowerCase() !== PLATFORM_MAIL)
);
const cred = ref(null);
function ratePct(rate) {
return ((Number(rate) || 0) / 100).toFixed(2) + "%";
}
function hexId(id) {
return id ? Number(id).toString(16).toUpperCase() : "";
}
function mailList(s) {
return (s || "").split(",").map((e) => e.trim()).filter(Boolean);
}
function providerName(pid) {
if (!pid) return "-";
const p = providers.value.find((x) => x.id === pid);
return p ? p.name : "方案商#" + pid;
}
return (_ctx, _push, _parent, _attrs) => {
const _component_AccountCredentialDialog = __nuxt_component_0;
_push(`<div${ssrRenderAttrs(_attrs)}><div style="${ssrRenderStyle(view.value === "list" ? null : { display: "none" })}"><div class="flex items-center justify-between mb-5"><h2 class="text-lg font-semibold text-slate-800">品牌商列表</h2><button class="btn btn-primary btn-sm text-white">+ 新增品牌商</button></div><div class="bg-white rounded-xl shadow-sm border border-slate-100"><div class="overflow-x-auto"><table class="table table-zebra"><thead><tr><th>ID</th><th>品牌名称</th><th>归属方案商</th><th>分成比例</th><th>联系邮箱</th><th>产品</th><th>操作</th></tr></thead><tbody>`);
if (loading.value) {
_push(`<tr><td colspan="7" class="text-center py-8"><span class="loading loading-spinner loading-sm"></span></td></tr>`);
} else if (!rows.value.length) {
_push(`<tr><td colspan="7" class="text-center text-slate-400 py-8">暂无数据</td></tr>`);
} else {
_push(`<!---->`);
}
_push(`<!--[-->`);
ssrRenderList(rows.value, (b) => {
_push(`<tr><td class="font-mono text-sm">${ssrInterpolate(hexId(b.id))}</td><td class="font-medium">${ssrInterpolate(b.brand)}</td><td><span class="badge badge-ghost badge-sm">${ssrInterpolate(providerName(b.providerid))}</span></td><td class="text-sm">${ssrInterpolate(ratePct(b.sharerate))}</td><td class="text-sm">`);
if (mailList(b.contactmails).length) {
_push(`<!--[-->`);
ssrRenderList(mailList(b.contactmails), (e, i) => {
_push(`<span class="badge badge-ghost badge-sm mr-1">${ssrInterpolate(e)}</span>`);
});
_push(`<!--]-->`);
} else {
_push(`<span class="text-slate-300">-</span>`);
}
_push(`</td><td class="text-sm text-slate-500">${ssrInterpolate(b.productlists || "")}</td><td><div class="flex gap-1"><button class="btn btn-ghost btn-xs">编辑</button><button class="btn btn-ghost btn-xs text-red-500">删除</button></div></td></tr>`);
});
_push(`<!--]--></tbody></table></div></div></div><div style="${ssrRenderStyle(view.value === "form" ? null : { display: "none" })}"><div class="flex items-center gap-3 mb-5"><button class="btn btn-ghost btn-sm">← 返回列表</button><h2 class="text-lg font-semibold text-slate-800">${ssrInterpolate(isEditing.value ? "编辑品牌商" : "新增品牌商")}</h2></div><div class="bg-white rounded-xl shadow-sm border border-slate-100 p-6 max-w-2xl"><form><div class="form-control mb-4"><label class="label"><span class="label-text font-medium">品牌名称 *</span></label><input${ssrRenderAttr("value", form.brand)} type="text" class="input input-bordered w-full" required></div><div class="form-control mb-4"><label class="label"><span class="label-text font-medium">归属方案商</span></label><select class="select select-bordered w-full"><option${ssrRenderAttr("value", 0)}${ssrIncludeBooleanAttr(Array.isArray(form.providerid) ? ssrLooseContain(form.providerid, 0) : ssrLooseEqual(form.providerid, 0)) ? " selected" : ""}>请选择方案商</option><!--[-->`);
ssrRenderList(providers.value, (p) => {
_push(`<option${ssrRenderAttr("value", p.id)}${ssrIncludeBooleanAttr(Array.isArray(form.providerid) ? ssrLooseContain(form.providerid, p.id) : ssrLooseEqual(form.providerid, p.id)) ? " selected" : ""}>${ssrInterpolate(p.name)}</option>`);
});
_push(`<!--]--></select></div><div class="form-control mb-4"><label class="label"><span class="label-text font-medium">分成比例(%)</span></label><input${ssrRenderAttr("value", form.sharepct)} type="number" step="0.01" min="0" max="100" class="input input-bordered w-full"><span class="label-text-alt text-slate-400 mt-1">平台从订单实付里分给该品牌商的总提成;其名下渠道商再从这份里切自己的比例。</span></div><div class="form-control mb-4"><label class="label"><span class="label-text font-medium">描述</span></label><textarea class="textarea textarea-bordered w-full" rows="3">${ssrInterpolate(form.description)}</textarea></div><div class="form-control mb-6"><label class="label"><span class="label-text font-medium">联系邮箱</span></label><div class="space-y-2">`);
if (!emails.value.length) {
_push(`<p class="text-xs text-slate-400">暂无邮箱</p>`);
} else {
_push(`<!---->`);
}
_push(`<!--[-->`);
ssrRenderList(emails.value, (e, i) => {
_push(`<div class="flex items-center gap-2"><span class="badge badge-lg gap-1 bg-slate-100 border-slate-200"><svg class="h-3 w-3 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg> ${ssrInterpolate(e)}</span><button type="button" class="btn btn-ghost btn-xs text-red-400 hover:text-red-600">×</button></div>`);
});
_push(`<!--]--></div><div class="flex gap-2 mt-2"><input${ssrRenderAttr("value", newEmail.value)} type="email" class="input input-bordered input-sm flex-1" placeholder="输入邮箱地址"><button type="button" class="btn btn-outline btn-sm btn-primary">添加</button></div></div>`);
if (!isEditing.value) {
_push(`<div class="form-control mb-6 border-t border-slate-100 pt-4"><label class="label"><span class="label-text font-medium">品牌官方渠道</span></label><input${ssrRenderAttr("value", form.officialChannelName)} type="text" class="input input-bordered w-full"${ssrRenderAttr("placeholder", defaultOfficialName.value)}><span class="label-text-alt text-slate-400 mt-1"> 新建品牌商时自动创建一条该品牌自己的渠道(直接启用、分成 0%、不创建渠道账号),用于品牌直销的授权码归属;留空则叫「${ssrInterpolate(defaultOfficialName.value)}」。 </span></div>`);
} else {
_push(`<!---->`);
}
if (!isEditing.value && unref(auth).isAdmin) {
_push(`<div class="form-control mb-6 border-t border-slate-100 pt-4"><label class="flex items-center gap-2 cursor-pointer"><input${ssrIncludeBooleanAttr(Array.isArray(form.createAccount) ? ssrLooseContain(form.createAccount, null) : form.createAccount) ? " checked" : ""} type="checkbox" class="checkbox checkbox-sm checkbox-primary"><span class="label-text font-medium">同时创建品牌账号</span></label><span class="label-text-alt text-slate-400 mt-1"> 建一个绑定本品牌商的「品牌商」角色登录账号,可见本品牌及名下全部渠道商的数据。 用户名/密码留空则自动生成,创建后凭据会邮件发给上面填的品牌商联系邮箱。 </span>`);
if (form.createAccount) {
_push(`<div class="grid grid-cols-2 gap-3 mt-3"><div><label class="text-xs text-slate-500">登录用户名</label><input${ssrRenderAttr("value", form.accountUsername)} type="text" class="input input-bordered input-sm w-full" placeholder="留空自动生成,如 Brand-A001" autocomplete="off"></div><div><label class="text-xs text-slate-500">登录密码</label><input${ssrRenderAttr("value", form.accountPassword)} type="text" class="input input-bordered input-sm w-full font-mono" placeholder="留空自动生成 12 位随机密码" autocomplete="off"></div><div class="col-span-2"><label class="text-xs text-slate-500">备注</label><input${ssrRenderAttr("value", form.accountRemark)} type="text" class="input input-bordered input-sm w-full" placeholder="可选"></div>`);
if (!credentialMails.value.length) {
_push(`<p class="col-span-2 text-xs text-amber-600"> 当前没有填品牌商自己的联系邮箱(平台默认邮箱不算),凭据将无法邮件送达,只会在创建后弹窗显示一次。 </p>`);
} else {
_push(`<!---->`);
}
_push(`</div>`);
} else {
_push(`<!---->`);
}
_push(`</div>`);
} else {
_push(`<!---->`);
}
_push(`<div class="flex gap-3"><button type="button" class="btn btn-ghost">取消</button><button type="submit" class="btn btn-primary text-white"${ssrIncludeBooleanAttr(submitting.value) ? " disabled" : ""}>保存</button></div></form></div></div>`);
_push(ssrRenderComponent(_component_AccountCredentialDialog, {
info: cred.value,
onClose: ($event) => cred.value = null
}, null, _parent));
_push(`</div>`);
};
}
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
const ssrContext = useSSRContext();
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/factory.vue");
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
export { _sfc_main as default };
//# sourceMappingURL=factory-CAOmR9O2.mjs.map