You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.8 KiB

4 years ago
<template>
<div>
<el-radio-group
v-if="!multiple"
v-model="selectValue"
4 years ago
>
<div v-for="option in options" :key="option.value" class="img-radio-item">
<el-image
:preview-src-list="[option.image]"
4 years ago
:src="option.image"
class="image"
4 years ago
fit="scale-down"
>
<div slot="error" class="image-slot">
<i class="el-icon-picture-outline" />
</div>
</el-image>
4 years ago
<el-radio :label="option.value">{{ option.label }}</el-radio>
</div>
</el-radio-group>
<el-checkbox-group
v-else
v-model="selectValue"
4 years ago
>
<div v-for="option in options" :key="option.value" class="img-radio-item">
<el-image
:preview-src-list="[option.image]"
4 years ago
:src="option.image"
class="image"
4 years ago
fit="scale-down"
>
<div slot="error" class="image-slot">
<i class="el-icon-picture-outline" />
</div>
</el-image>
4 years ago
<el-checkbox :label="option.value">{{ option.label }}</el-checkbox>
</div>
</el-checkbox-group>
</div>
</template>
<script>
export default {
name: 'ImageSelect',
props: {
value: {
type: Number,
default: 1
},
4 years ago
options: {
type: Array,
default: function() {
return []
},
required: true
},
multiple: {
type: Boolean,
default: false
}
},
data() {
return {
selectValue: this.value
4 years ago
}
},
watch: {
selectValue(val) {
this.$emit('input', val)
},
value(val) {
this.selectValue = val
}
},
methods: {
4 years ago
}
}
</script>
<style lang="scss" scoped>
::v-deep .el-radio-button__inner,
.el-radio-group,
.el-checkbox-group {
display: flex !important;
}
.img-radio-item {
display: flex;
flex-direction: column !important;
align-content: center !important;
align-items: center !important;
border: 1px solid rgba(0, 0, 0, 0.1) !important;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1) !important;
margin: 3px !important;
background-color: #fff;
4 years ago
.image {
width: 100px;
height: 100px;
margin: 2px 15px 4px 15px;
}
.el-radio {
margin: 4px;
}
}
::v-deep .image-slot {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
//background: #f5f7fa;
color: #909399;
font-size: 30px;
}
4 years ago
</style>