Browse Source

select同步上期修改

couponManage-zq-1209
zq 12 hours ago
parent
commit
7de386e142
  1. 74
      src/components/GuipSelect.vue

74
src/components/GuipSelect.vue

@ -1,24 +1,41 @@
<template>
<el-form-item :style="{ ...style, height: height, ...styleObject }" :required="required"
:class="[{ 'column': column }, { 'w510': addClass == 'w510' }, { 'w388': addClass == 'w388' }, 'form-item']"
:label="label" :prop="prop" :rules="rules">
:class="[{ 'column': column }, { 'w510': addClass == 'w510' }, { 'w388': addClass == 'w388' }, { 'client-form-flex': clientFormFlex }, 'form-item']"
:label="clientFormFlex ? '' : label" :prop="prop" :rules="rules">
<p v-if="desc" class="desc_right">{{ desc }}</p>
<el-select :style="{ width: width }" :placeholder="placeholder1" @change="handleChange" v-model="selectedValue"
v-bind="$attrs">
<el-option v-for="item in processedOptions" :key="getItemValue(item)" :label="getItemLabel(item)"
:disabled="item.disabled" :value="getItemValue(item)">
</el-option>
</el-select>
<!-- 特殊样式布局 -->
<div v-if="clientFormFlex" class="client-form-flex-wrapper">
<div class="flex-label">
<div class="label-text">{{ clientFormLabel || label }}</div>
<span class="colon"></span>
</div>
<div class="flex-input">
<el-select :style="{ width: width }" :placeholder="placeholder1" @change="handleChange" v-model="selectedValue"
v-bind="$attrs">
<el-option v-for="item in processedOptions" :key="getItemValue(item)" :label="getItemLabel(item)"
:disabled="item.disabled" :value="getItemValue(item)">
</el-option>
</el-select>
</div>
</div>
<!-- 原有结构 -->
<template v-else>
<el-select :style="{ width: width }" :placeholder="placeholder1" @change="handleChange" v-model="selectedValue"
v-bind="$attrs">
<el-option v-for="item in processedOptions" :key="getItemValue(item)" :label="getItemLabel(item)"
:disabled="item.disabled" :value="getItemValue(item)">
</el-option>
</el-select>
</template>
</el-form-item>
</template>
<script>
export default {
name: 'GuipSelect',
props: {
value: [String, Number, Array],
options: {
type: [Array,Object],
type: [Array, Object],
default: () => []
},
//
@ -30,7 +47,7 @@ export default {
type: String,
default: 'label'
},
//
//
extraItem: {
type: Object,
default: null
@ -48,7 +65,17 @@ export default {
rules: [Object, Array],
column: Boolean,
addClass: String,
desc: String
desc: String,
//
clientFormFlex: {
type: Boolean,
default: false
},
//
clientFormLabel: {
type: String,
default: ''
}
},
data() {
return {
@ -60,17 +87,14 @@ export default {
computed: {
processedOptions() {
// options
// let options = [1,5,3] || [];
let newOptions = null
let options = this.options || [];
// [1,12,22]
// [1,12,22]
if (Array.isArray(options) && options.length > 0 && options.every(item => typeof item !== 'object')) {
newOptions = options.map((item, index) => ({
[this.valueKey]: index,
options = options.map((item, index) => ({
[this.valueKey]: index, // 使 item value index
[this.labelKey]: item
}));
}
//
if (options && !Array.isArray(options)) {
options = Object.keys(options).map(key => ({
@ -78,18 +102,22 @@ export default {
[this.labelKey]: options[key]
}));
}
// options
if (!Array.isArray(options)) {
options = [];
}
// extraItemoptions
if (this.extraItem && Object.keys(this.extraItem).length > 0) {
newOptions = [
options = [
{
[this.labelKey]: this.extraItem.label || '',
[this.valueKey]: this.extraItem.value || '',
disabled: this.extraItem.disabled || false
},
...newOptions
...options
];
}
return newOptions;
return options;
}
},
watch: {
@ -123,7 +151,6 @@ export default {
item.onmouseout = function () {
item.classList.remove("hoverclass")
}
})
})
},
@ -164,5 +191,4 @@ export default {
// .el-select {
// width: 100%;
// }
// }
</style>
// }</style>
Loading…
Cancel
Save