wente
2023-11-22 4a24c7fdeeb3c4979608dd9af80855ce66b8c58d
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<template>
  <div>
    <el-collapse class="config-uploader" v-model="activeNames" v-if="oss && oss.groups.length>1">
      <el-collapse-item name="1" v-for="group in (oss.groups || [])" :key="group.busiFieldGroup">
        <template slot="title">
          <el-tag v-if="!image">{{group.busiFieldGroup}}</el-tag>
        </template>
        <!-- <zt-form-item :label="field.busiFieldName" :prop="field.busiField" v-for="field in group.fields"
                       :key="field.busiField" :rules="field.isRequired ? 'required':''" style="width: 100%;">
           <zt-uploader v-model="dataForm[field.busiField]" multiple :limit="field.fileLimit" :file-type="field.fileType"
                        :accept="field.accept" :file-size="field.fileSize" @input="change(field.busiField)"/>
         </zt-form-item>-->
        <el-table :data="group.fields" :show-header="false">
          <el-table-column width="250" style="text-align: left;white-space:nowrap;">
            <template slot-scope="scope">
              <span v-html="scope.row.busiFieldName"></span>
            </template>
          </el-table-column>
          <el-table-column align="left">
            <template slot-scope="scope">
              <zt-uploader :image="image" v-model="dataForm[scope.row.busiField]" multiple :limit="scope.row.fileLimit" :file-type="scope.row.fileType"
                           :accept="scope.row.accept" :file-size="scope.row.fileSize" @getUploaderImg="getUploaderImg" @input="change(scope.row.busiField)"/>
            </template>
          </el-table-column>
        </el-table>
      </el-collapse-item>
    </el-collapse>
    <div v-else class="config-uploader" v-model="activeNames" >
      <div v-for="group in (oss.groups || [])" :key="group.busiFieldGroup">
        <!-- <zt-form-item :label="field.busiFieldName" :prop="field.busiField" v-for="field in group.fields"
                       :key="field.busiField" :rules="field.isRequired ? 'required':''" style="width: 100%;">
           <zt-uploader v-model="dataForm[field.busiField]" multiple :limit="field.fileLimit" :file-type="field.fileType"
                        :accept="field.accept" :file-size="field.fileSize" @input="change(field.busiField)"/>
         </zt-form-item>-->
        <el-table :data="group.fields" :show-header="false">
          <el-table-column width="250" style="text-align: left;white-space:nowrap;">
            <template slot-scope="scope">
              <span v-html="scope.row.busiFieldName"></span>
            </template>
          </el-table-column>
          <el-table-column align="left">
            <template slot-scope="scope">
              <zt-uploader :image="image" v-model="dataForm[scope.row.busiField]" multiple :limit="scope.row.fileLimit" :file-type="scope.row.fileType"
                           :accept="scope.row.accept" :file-size="scope.row.fileSize" @getUploaderImg="getUploaderImg" @input="change(scope.row.busiField)"/>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
 
</template>
<script>
 
  export default {
    name: 'ConfigUploader',
    components: {},
    props: {
      value: Object,
      dataForm: Object,
      image:false,
      busiType: String // 业务类型
    },
    data() {
      return {
        activeNames: ['1'],
        oss: null
      }
    },
    computed: {
      fields() {
        let arr = []
        if (this.dataForm.files && this.dataForm.files.groups) {
          this.dataForm.files.groups.forEach(group => {
            group.fields.forEach(field => arr.push(field))
          })
        }
        return arr
      }
    },
    watch: {
      value(val, oldval) {
        if (JSON.stringify(val) !== JSON.stringify(oldval)) {
          this.oss = {
            ...this.getOss(),
            ...(val || {})
          }
          // this.dataForm.files = this.oss
          this.$set(this.dataForm, 'files', this.oss)
 
          // 分解到每个字段给dataForm赋值
          this.fields.forEach(field => {
            // this.dataForm[field.busiField] = field.files
            this.$set(this.dataForm, field.busiField, field.files)
          })
        }
      }
    },
    mounted() {
      this.oss = this.getOss()
      if (this.oss) {
        this.oss.groups.forEach(group => {
          this.activeNames.push(group.busiFieldGroup)
        })
        // this.dataForm.files = this.oss
        this.$set(this.dataForm, 'files', this.oss)
      }
    },
    methods: {
      getOss() {
        let arr = (this.$store.state.oss.configs || []).filter(config => config.busiType === this.busiType)
        if (arr.length > 0) {
          return JSON.parse(JSON.stringify(arr[0]))
        }
        return null
      },
      change(busiField) {
        console.log(busiField,'busiField busiField')
        this.fields.forEach(field => {
          if (field.busiField === busiField) {
            field.files.length = 0
            this.dataForm[busiField].forEach(file => field.files.push(file))
          }
        })
      },
      getUploaderImg(list){
        // this.imageList = list
        if(list[0].url){
          this.$emit('getImageUrl',list[0].url)
        }
 
      }
    }
  }
</script>
<style>
  .config-uploader label {
    width: 260px !important;
  }
   .zt .el-upload-list__item .el-progress{
    top:15px !important;
  }
</style>