fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<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>