import { ScenePackageSource } from "@queenjs-modules/queditor/module/objects/scenePack"; import { queenApi } from "queenjs"; import { CollocationModule } from "../.."; export const designAction = CollocationModule.action({ async delDesign(item: IStyle) { const result = await queenApi.showConfirm({ title: "删除提示", content: `删除后不可恢复,是否删除${item.name}?`, type: "danger", }); if (!result) return; const res = await this.https.deleteStyle(item._id); if (res.errorNo != 200) return; this.controls.listCtrl.fresh(); }, async saveDesign() { const { _id, matMatchs, scenePack, prodMatchs } = this.store.designDetail; await this.https.updateStyle({ _id, matMatchs, prodMatchs, scenePack }); }, async addDesign(values) { const styleItem = { ...values }; if (!styleItem.scenePack.source) { queenApi.messageError("所选数据错误!"); return; } const packSource: ScenePackageSource = styleItem.scenePack.source; const scenes = packSource.scenes || []; const prodCompMap = new Map(); scenes.forEach((c) => { const sprods = c.products || []; //场景里面的单品 sprods.forEach((sp) => { if (!sp.visible) return; //当前单品是隐藏的,忽略 const prod = packSource.products.find((item) => item.id == sp.prodId); if (!prod) return; const comps = prod?.components || []; //单品的材质配置 comps.forEach((comp) => { if (!comp.visible) return; //当前部件是隐藏的,忽略 //获取单品部件配置 if (!prodCompMap.get(prod.id)) { prodCompMap.set(prod.id, new Map()); } const compMap = prodCompMap.get(prod.id); if (!compMap.get(comp.name)) { compMap[comp.name] = { index: 0, name: comp.name, matIds: [], sceneProId: sp.id, visible: comp.visible, }; } const currComp = compMap[comp.name]; if (comp.matId && currComp.matIds.indexOf(comp.matId) < 0) { currComp.matIds.push(comp.matId); } }); }); }); const matMatchs: MatsMatchComp[] = []; const CompMaps: any = {}; for (const [key, value] of prodCompMap.entries()) { const prodConf = value; for (const compKey in prodConf) { if (!CompMaps[compKey]) { CompMaps[compKey] = prodConf[compKey]; CompMaps[compKey].productId = key; continue; } const compConf = CompMaps[compKey]; const conf = prodConf[compKey]; conf.matIds.forEach((e: any) => { if (compConf.matIds.indexOf(e) < 0) { compConf.matIds.push(e); } }); } } for (const k in CompMaps) { matMatchs.push(CompMaps[k]); } styleItem.matMatchs = matMatchs; styleItem.prodMatchs = [ { index: -1, category: "product", group: "", productIds: [], }, ]; await this.https.createStyle(styleItem); queenApi.messageSuccess("添加成功"); this.controls.listCtrl.fresh(); return true; }, });