liding
4 天以前 359f69135b571c8e7b6d046bc849655abfe7075d
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
144
145
146
147
148
149
<template>
  <div>
    <div class="acea-row" v-if="multiple">
      <div
        v-for="(item,index) in imageList"
        :key="index"
        class="pictrue"
        draggable="false"
        @dragstart="handleDragStart($event, item)"
        @dragover.prevent="handleDragOver($event, item)"
        @dragenter="handleDragEnter($event, item)"
        @dragend="handleDragEnd($event, item)"
      >
        <img :src="item.sattDir">
        <i class="el-icon-error btndel" @click="handleRemove(index)" />
      </div>
      <div class="upLoadPicBox" @click="modalPicTap('2')" v-show="imageList.length<20">
        <div class="upLoad">
          <i class="el-icon-camera cameraIconfont" />
        </div>
      </div>
    </div>
    <div class="upLoadPicBox" @click="modalPicTap('1')" v-else>
      <div v-if="image" class="pictrue"><img :src="image"></div>
      <div v-else class="upLoad">
        <i class="el-icon-camera cameraIconfont" />
      </div>
    </div>
    <el-dialog
      title="上传图片"
      :visible.sync="visible"
      width="896px"
      :before-close="handleClose"
       :modal="false"
    >
      <upload-index v-if="visible" :checkedMore="imageList" :isMore="isMore" @getImage="getImage" />
    </el-dialog>
  </div>
</template>
 
<script>
import UploadIndex from '@/components/uploadPicture/index.vue'
export default {
  name: 'UploadFroms',
  components: { UploadIndex },
  props:{
    value:{},
    multiple:{
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      image:"",
      visible: false,
      callback: function() {},
      isMore: '',
      imageList: []
    }
  },
  beforeMount(){
    if( this.multiple ){
      // 接收 v-model 数据
      if(this.value){
        this.imageList = JSON.parse(this.value)
      }
    }else{
      // 接收 v-model 数据
      if(this.value){
        this.image = this.value
      }
    }
    // 处理多选
    this.isMore = this.multiple ? '2':'1'
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    getImage(img) {
      if (this.multiple) {
        let obj = {};
        this.imageList = img.reduce((cur,next) => {
          obj[next.attId] ? "" : obj[next.attId] = true && cur.push(next);
          return cur;
        },[])
        this.$emit('input', JSON.stringify(this.imageList))
      } else {
        this.image = img[0].sattDir
        this.$emit('input', this.image)
      }
      this.visible = false
    },
    // 点击商品图
    modalPicTap (tit, num, i) {
      this.visible = true
    },
    handleRemove (i) {
      this.imageList.splice(i, 1)
      this.$emit('input', JSON.stringify(this.imageList))
    },
    // 移动
    handleDragStart (e, item) {
      this.dragging = item;
    },
    handleDragEnd (e, item) {
      this.dragging = null
    },
    handleDragOver (e) {
      e.dataTransfer.dropEffect = 'move'
    },
    handleDragEnter (e, item) {
      e.dataTransfer.effectAllowed = 'move'
      if (item === this.dragging) {
        return
      }
      const newItems = [...this.imageList]
      const src = newItems.indexOf(this.dragging)
      const dst = newItems.indexOf(item)
      newItems.splice(dst, 0, ...newItems.splice(src, 1))
      this.imageList = newItems;
    }
  }
}
</script>
 
<style scoped lang="scss">
  .btndel{
    position: absolute;
    z-index: 1;
    width :20px !important;
    height: 20px !important;
    left: 46px;
    top: -4px;
  }
  .pictrue{
    width: 60px;
    height: 60px;
    border: 1px dotted rgba(0,0,0,0.1);
    margin-right: 10px;
    position: relative;
    cursor: pointer;
    img{
      width: 100%;
      height: 100%;
    }
  }
</style>