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
<!--
 * @Author: 张嘉彬
 * @Date: 2021-10-27 15:12:29
 * @Description:
-->
<template>
  <div class="basicSet">
    <div>
      <el-form-item label="专区名称:" :required="true">
        <el-input class="diyInput" v-model.trim="form.activityName" placeholder="请输入专区名称"
                  maxlength="15" show-word-limit></el-input>
      </el-form-item>
    </div>
    <div>
      <el-form-item label="背景图片:" :required="true">
        <custom-upload-img :limitNumber="999" @handle-success="handleBgSuccess"
                           @handle-remove="handleBgRemove" :fileList="fileBgList"
                           @handle-file-data="handleFileData" :multiple="true" :draggable="true">
        </custom-upload-img>
      </el-form-item>
    </div>
  </div>
</template>
 
<script>
import { mapMutations, mapState } from 'vuex'
export default {
  props: ['form'],
  data () {
    return {
      fileBgList: []
    }
  },
  watch: {
    diyListFirst: {
      handler (newValue, oldvalue) {
        this.form.activityName = newValue.activityName
        newValue.bgImg.forEach((item) => {
          this.fileBgList.push(item)
        })
      },
      immediate: true
    }
  },
  computed: {
    ...mapState(['diyList']),
    diyListFirst () {
      return this.diyList[0]
    }
  },
  methods: {
    ...mapMutations(['updateDiylistById']),
    // 数组更新时重新获取数据
    handleFileData (arr) {
      this.updateDiylistById({ id: 'basicSet', update: { bgImg: arr } })
      this.fileBgList = arr
    },
    // 移除文件数组
    removeFile (arr, data) {
      return arr.filter((v) => {
        return v.id !== data.id
      })
    },
    /**
     * 获取上传成功的图片
     */
    handleBgSuccess (data) {
      const arr = JSON.parse(JSON.stringify(this.diyList[0].bgImg))
      arr.push({
        id: data.id,
        url: data.url
      })
      this.updateDiylistById({ id: 'basicSet', update: { bgImg: arr } })
      this.fileBgList.push({
        url: data.url,
        id: data.id
      })
    },
    /**
     * 移除图片
     */
    handleBgRemove (data) {
      const arr = JSON.parse(JSON.stringify(this.diyList[0].bgImg))
      this.updateDiylistById({
        id: 'basicSet',
        update: {
          bgImg: this.removeFile(arr, data)
        }
      })
      this.fileBgList = this.removeFile(this.fileBgList, data)
    }
  }
}
</script>
 
<style lang='scss'>
.basicSet {
}
</style>