<template>
|
<div>
|
<hot-area-box @handle-preview="handlePreview">
|
<template slot="hotContent">
|
<hot-content></hot-content>
|
</template>
|
</hot-area-box>
|
<preview ref="preview"></preview>
|
</div>
|
</template>
|
<script>
|
import { mapState, mapMutations } from 'vuex'
|
import { getDiyInfoById, editDiy, addDiy } from '@/api/diy.js'
|
import { useSceneMap } from './commonData'
|
import { submitValidate } from './submitValidate'
|
import hotAreaBox from '../../components/hotAreaBox/index.vue'
|
import hotContent from './components/hotContent.vue'
|
import preview from '../diy-form/components/preview.vue'
|
export default {
|
name: 'diy-index',
|
components: {
|
hotAreaBox,
|
hotContent,
|
preview
|
},
|
data () {
|
return {
|
useSceneMap
|
}
|
},
|
computed: {
|
...mapState(['diyList'])
|
},
|
methods: {
|
...mapMutations(['initDiyList', 'resetDiy']),
|
async _getDiyInfoById (params) {
|
const res = await getDiyInfoById(params)
|
if (res.code === '0' && res.data) {
|
this.initDiyList(JSON.parse(res.data.styleInfo))
|
}
|
},
|
async handlePreview () {
|
if (submitValidate(this.diyList, this.useSceneMap)) return // 表单验证
|
const id = this.$route.query.id
|
let res
|
if (id) {
|
res = await editDiy({
|
id,
|
styleInfo: JSON.stringify(this.diyList),
|
diyDes: this.diyList[0].activityName,
|
diyType: '2'
|
})
|
if (res.code === '0') {
|
const str = `${process.env.VUE_APP_H5_URL}/activityArea?id=${res.data.id}`
|
this.$refs.preview.show(str)
|
}
|
} else {
|
this.addDiy()
|
}
|
},
|
/**
|
* 新增diy
|
*/
|
async addDiy () {
|
const res = await addDiy({
|
diyDes: this.diyList[0].activityName,
|
styleInfo: JSON.stringify(this.diyList),
|
diyType: '2'
|
})
|
if (res.code === '0') {
|
this.$router.replace(`${this.$baseRouter}/activityCenter/edit?id=${res.data.id}`)
|
const str = `${process.env.VUE_APP_H5_URL}/activityArea?id=${res.data.id}`
|
this.$refs.preview.show(str)
|
}
|
}
|
},
|
created () {
|
if (this.$route.query.id) {
|
this._getDiyInfoById({ id: this.$route.query.id })
|
}
|
}
|
}
|
</script>
|
<style scoped lang="scss">
|
/* 设置滚动条的样式 */
|
.diy-aside::-webkit-scrollbar {
|
display: none;
|
width: 0;
|
}
|
|
.diy-aside {
|
overflow: hidden;
|
border: 1px solid #333;
|
height: 667px;
|
overflow-y: auto;
|
-ms-overflow-style:none;
|
overflow:-moz-scrollbars-none;
|
scrollbar-width: none;
|
}
|
.el_aside {
|
text-align: center;
|
}
|
.preview_btn {
|
margin-top: 10px;
|
}
|
</style>
|