ImageList.vue
2.48 KB
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
<template>
<div class="image_list_page">
<template v-if="imgList && imgList.length">
<div
class="image_cell"
v-for="(item, index) in imgList"
:key="`img_upload_${index}`"
>
<image-upload
:value="item"
:status="status"
:limit="1"
@change="onChange('imgList')"
></image-upload>
<div class="image_name" :title="item.originName">
{{ item.originName || item.name }}
</div>
</div>
</template>
<ImageOtherUpload
v-model="otherList"
:limit="limit"
:status="status"
@change="onChange('otherList')"
></ImageOtherUpload>
</div>
</template>
<script>
import ImageUpload from "./image.vue";
import ImageOtherUpload from "./otherImage.vue";
export default {
name: "ImageList",
components: {
ImageUpload,
ImageOtherUpload,
},
props: {
value: {
type: Array,
default: function () {
return [];
},
},
type: {
type: [String, Number],
default: 1, //
},
status: {
//1:查看工单,不可编辑 2:编辑工单 3:激活工单 4:审核工单 5: 单独编辑图片
type: [String, Number],
default: "",
},
},
watch: {
value: {
handler: function (n, o) {
let m = [];
let _other = [];
n.map((k) => {
// 固定位置
if (k.source == "bhg") {
m.push(k);
} else {
_other.push(k);
}
});
let len = m.length;
if (len <= 20) {
this.limit = 20 - len;
} else {
this.limit = 1;
}
console.log(this.limit);
this.imgList = m;
this.otherList = _other;
},
immediate: true,
},
},
data() {
return {
imgList: [], // 固定位置
otherList: [], // 其他
limit: 1,
};
},
methods: {
// 监听图片组件删除、上传更新
onChange(id) {
console.log(id);
let _list = this.imgList.concat(this.otherList);
console.log(_list);
this.$emit("input", _list);
},
},
};
</script>
<style lang="scss" scoped>
.image_list_page {
display: flex;
flex-wrap: wrap;
.image_cell {
width: 120px;
margin: 0 10px 10px 0;
}
.image_name {
height: 30px;
width: 100%;
text-align: center;
overflow: hidden;
white-space: nowrap;
word-break: break-all;
text-overflow: ellipsis;
line-height: 30px;
}
}
</style>