iot-ui-app/pages/intelligent/components/select/iots-select.vue

115 lines
2.4 KiB
Vue

<template>
<view class="iots-component-box">
<view class="attr-item-left">
<view class="iconfont" :class="icon"></view>
<view class="attr-name">{{name}}</view>
</view>
<view class="attr-item-right">
<view class="attr-value item-select" @click="changeSelect()">
<text
:style="{color:value?'#333':'#ccc'}">{{value!=null?getVlaue(value):'请选择'}}</text>
<view class="iconfont icon-xiangyou1"></view>
</view>
</view>
<u-select mode="single-column" :default-value="selectDefaultValue" v-model="selectShow" :list="selectList" @confirm="confirm"></u-select>
</view>
</template>
<script>
export default{
name: 'iots-select',
props:{
// 选择值或默认值
value: {
type: [String, Number],
default: ''
},
// 选择列表(处理后)
selectList:{
type: [Array],
default: [],
},
// 图标处理后
icon: {
type: [String],
default: 'icon-gongnengdingyi'
},
name: {
type: [String],
default: ''
}
},
data(){
return {
selectDefaultValue:[0],
selectShow: false,
}
},
methods:{
changeSelect() {
this.selectShow = true;
},
// 样式转换
getVlaue(value) {
console.log("this.selectList[value]",this.selectList,value)
for(let i=0; i<this.selectList.length;i++){
if(this.selectList[i].value == value){
return this.selectList[i].label;
}
}
},
confirm(e) {
console.log("当前选择",e,e[0].value)
this.$emit('input', e[0].value);
this.$emit('change',e[0]);
this.selectDefaultValue = [this.selectList.findIndex(item => item.value === e[0].value)] || [0];
},
}
}
</script>
<style lang="scss" scoped>
.iots-component-box{
padding: 20rpx 20rpx;
background: #fff;
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 20rpx;
border-radius: 10rpx;
.attr-item-left{
display: flex;
align-items: center;
font-size: 28rpx;
color: #000;
.iconfont{
margin-right: 20rpx;
font-size: 40rpx;
}
}
.attr-item-right{
flex: 1;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
.attr-value{
display: flex;
align-items: center;
justify-content: flex-end;
height: 70rpx;
flex: 1;
&.item-select {
padding: 0 20rpx;
display: flex;
align-items: center;
justify-content: flex-end;
color: #ccc;
.iconfont{
margin-left: 10rpx;
}
}
}
}
}
</style>