266 lines
7.3 KiB
Vue
Raw Normal View History

2021-05-13 10:56:04 +08:00
<template>
<div class="wrapper">
<!-- 拖拽栏 展示栏 -->
<div class="model-view">
<div class="model-view-menu">
<draggable
class="model-view-menu-item"
:list="modelData"
:move="handleMove"
v-bind="{
group: { name: 'model', pull: 'clone', put: false, animation: 150 },
sort: false,
ghostClass: 'ghost',
}"
>
<li
v-for="(model, index) in modelData"
2022-04-18 09:49:09 +08:00
v-if="!model.drawer && !model.drawerPromotions"
2021-05-13 10:56:04 +08:00
:key="index"
class="model-item"
>
<img src alt />
<span>{{ model.name }}</span>
</li>
</draggable>
</div>
<div class="model-view-content">
<div class="content">
<div class="wap-title">首页</div>
<draggable
class="draggable"
group="model"
ghostClass="ghost"
@add="handleContentlAdd"
@end="handleContentlEnd"
v-model="contentData.list"
>
<div
class="list"
v-for="(element, index) in contentData.list"
:key="element.key"
>
<component
class="component"
:class="{ active: selected == index }"
@click.native="handleComponent(element, index)"
:is="templates[element.type]"
:res="element.options"
></component>
<Icon
v-if="selected == index"
@click="closeComponent(index)"
color="#e1251b"
size="25"
class="close"
type="ios-close-circle"
/>
</div>
</draggable>
</div>
</div>
<!-- 右侧栏 -->
<div class="model-config">
<decorate
@handleDrawer="handleDrawer"
v-if="decorateData"
:res="decorateData"
></decorate>
</div>
</div>
</div>
</template>
<script>
import templates from "./template/index";
import Draggable from "vuedraggable";
import { modelData } from "./config";
import decorate from "./decorate";
2022-04-18 09:49:09 +08:00
import * as API_Other from "@/api/other";
import * as API_Promotions from "@/api/promotion";
2021-05-13 10:56:04 +08:00
export default {
components: {
Draggable,
decorate,
},
data() {
return {
2021-05-13 18:09:36 +08:00
templates, // 模板类型
modelData, // 装修模型
qrcode: "", // 二维码
selected: 0, // 已选下标
2022-04-18 09:49:09 +08:00
contentData: {
// 总数据
2021-05-13 10:56:04 +08:00
list: [],
},
2021-05-13 18:09:36 +08:00
decorateData: "", // 装修数据
2022-04-18 09:49:09 +08:00
decoratePromotionsData: "", // 装修数据
2021-05-13 10:56:04 +08:00
};
},
watch: {
contentData: {
handler(val) {
this.$store.state.styleStore = val;
},
deep: true,
},
},
mounted() {
this.init();
},
methods: {
// 初始化数据
2021-05-13 10:56:04 +08:00
init() {
if (!this.$route.query.id) return false;
2022-04-18 09:49:09 +08:00
API_Other.getHomeData(this.$route.query.id).then((res) => {
this.contentData = JSON.parse(res.result.pageData);
2021-05-13 10:56:04 +08:00
2022-04-18 09:49:09 +08:00
this.handleComponent(this.contentData.list[0], 0);
});
2021-05-13 10:56:04 +08:00
},
// 中间组件拖动,右侧数据绑定不变
handleContentlEnd(evt) {
const { newIndex } = evt;
this.handleComponent(this.contentData.list[newIndex], newIndex);
},
// 关闭楼层装修
closeComponent(index) {
this.$nextTick(() => {
this.decorateData = "";
// 如果当前楼层不为一
if (this.contentData.list.length > 1) {
// 如果当前最底层 给下一层赋值
if (index - 1 == -1) {
this.handleComponent(this.contentData.list[index], index);
} else {
// 如果不是最底层给上一层赋值
this.handleComponent(this.contentData.list[index - 1], index - 1);
}
this.contentData.list.splice(index, 1);
} else {
this.contentData.list.splice(index, 1);
}
});
},
// 点击楼层装修
handleComponent(val, index) {
this.selected = index;
this.$set(this, "decorateData", val);
},
// 右侧栏回调
2021-05-13 10:56:04 +08:00
handleDrawer(val) {
let newIndex = this.selected;
2022-04-18 09:49:09 +08:00
if (val.promotionsType) {
if (this.contentData.list[newIndex].options.list.length >= 2) {
this.$Message.error("最多只能展示两个活动");
return;
}
if (val.promotionsType === "LIVE") {
API_Promotions.getLiveList({
status: "START",
pageSize: 1,
}).then((res) => {
if (res.success && res.result.size > 0) {
API_Promotions.getLiveInfo(res.result.records[0].id).then(
(res) => {
if (res.success) {
this.contentData.list[newIndex].options.list.push({
type: val.promotionsType,
title: val.name,
title1: val.subName,
color1: val.subColor,
bk_color: val.subBkColor,
data: res.result.commodityList
2022-09-01 17:36:24 +08:00
? res.result.commodityList.splice(0, 2)
2022-04-18 09:49:09 +08:00
: [],
});
}
}
);
}
});
} else {
API_Promotions.getAllPromotion().then((res) => {
let exist = this.contentData.list[newIndex].options.list.find(
(i) => i.type === val.promotionsType
);
2021-05-13 10:56:04 +08:00
2022-04-18 09:49:09 +08:00
if (res.success && !exist) {
this.contentData.list[newIndex].options.list.push({
data: res.result[val.promotionsType]
2022-04-21 14:57:33 +08:00
? res.result[val.promotionsType].splice(0,2)
2022-04-18 09:49:09 +08:00
: [],
type: val.promotionsType,
title1: val.subName,
color1: val.subColor,
bk_color: val.subBkColor,
title: val.name,
});
}
});
}
this.$set(this.contentData.list, newIndex, {
...val,
options: {
...this.contentData.list[newIndex].options,
},
// 绑定键值
model: val.type,
});
} else {
this.decorateData = "";
2021-05-13 10:56:04 +08:00
2022-04-18 09:49:09 +08:00
this.$set(this.contentData.list, newIndex, {
...val,
options: {
...val.options,
},
2021-05-13 10:56:04 +08:00
2022-04-18 09:49:09 +08:00
// 绑定键值
model: val.type,
});
this.contentData.list = JSON.parse(
JSON.stringify(this.contentData.list)
);
this.$set(this, "decorateData", this.contentData.list[newIndex]);
}
2021-05-13 10:56:04 +08:00
},
// 封装拖拽参数
package(val, newIndex) {
this.contentData.list[newIndex] = "";
val = JSON.parse(JSON.stringify(val));
this.$set(this.contentData.list, newIndex, {
...val,
options: {
...val.options,
},
// 绑定键值
model: val.type,
});
},
// 拖动
handleContentlAdd(evt) {
const { newIndex } = evt;
this.package(this.contentData.list[newIndex], newIndex);
this.handleComponent(this.contentData.list[newIndex], newIndex);
},
handleMove() {
return true;
},
},
};
</script>
<style scoped lang="scss">
@import "./style.scss";
</style>