Browse Source

select同步上期修改

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

74
src/components/GuipSelect.vue

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