|
@@ -1,7 +1,16 @@
|
|
|
+import { ScenePackageSource } from "@queenjs-modules/queditor/module/objects/scenePack";
|
|
|
import { queenApi } from "queenjs";
|
|
|
import { CollocationModule } from "../..";
|
|
|
+import { details } from "../stores/data";
|
|
|
|
|
|
export const designAction = CollocationModule.action({
|
|
|
+ async queryStyleDetail(id: string) {
|
|
|
+ // const res = await this.https.getStyleDetail(id);
|
|
|
+ // this.store.setDesignDetail(res.result);
|
|
|
+ const res = details;
|
|
|
+ this.store.setDesignDetail(res);
|
|
|
+ },
|
|
|
+
|
|
|
async delDesign(item: IStyle) {
|
|
|
const result = await queenApi.showConfirm({
|
|
|
title: "删除提示",
|
|
@@ -14,4 +23,94 @@ export const designAction = CollocationModule.action({
|
|
|
if (res.errorNo != 200) return;
|
|
|
this.controls.listCtrl.fresh();
|
|
|
},
|
|
|
+
|
|
|
+ async saveDesign() {
|
|
|
+ const { _id, matMatchs, prodMatchs } = this.store.designDetail;
|
|
|
+ await this.https.updateStyle({ _id, matMatchs, prodMatchs });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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 = [];
|
|
|
+
|
|
|
+ await this.https.createStyle(styleItem);
|
|
|
+ queenApi.messageSuccess("添加成功");
|
|
|
+ this.controls.listCtrl.fresh();
|
|
|
+ return true;
|
|
|
+ },
|
|
|
});
|