|
@@ -3,9 +3,12 @@
|
|
|
<view>
|
|
|
<view class="selList" v-for="(item, index) in list" :key="index">
|
|
|
<view class="radios" @click="chooseItem(item)">
|
|
|
- <radio v-if="types == 'radio'" :checked="item.checked" :value="item.id" />
|
|
|
- <checkbox v-if="types == 'checkbox'" :checked="item.checked" :value="item.id" />
|
|
|
- <text>{{ item[titleKeys] }}</text>
|
|
|
+ <view v-if="checkIconPositon=='right'" style="flex-grow: 1;" class="title">{{ item[titleKeys] }}</view>
|
|
|
+ <view>
|
|
|
+ <radio v-if="types == 'radio'" :checked="item.checked" :value="item.id" />
|
|
|
+ <checkbox v-if="types == 'checkbox'" :checked="item.checked" :value="item.id" />
|
|
|
+ </view>
|
|
|
+ <view v-if="checkIconPositon=='left'" class="title">{{ item[titleKeys] }}</view>
|
|
|
</view>
|
|
|
<view class="details" @click="rightClick(item)">
|
|
|
<slot name="right"></slot>
|
|
@@ -46,11 +49,23 @@ export default {
|
|
|
type: Boolean,
|
|
|
default: true
|
|
|
},
|
|
|
+ // 赋值,格式要和backValue 一致
|
|
|
defValue: {
|
|
|
type: Array,
|
|
|
default: function() {
|
|
|
return [];
|
|
|
}
|
|
|
+ },
|
|
|
+ // 返回结果是
|
|
|
+ // idArr: [id,id,id...],objArr:[obj,obj,obj...]
|
|
|
+ backValue:{
|
|
|
+ type: String,
|
|
|
+ default: 'idArr'
|
|
|
+ },
|
|
|
+ // 选择按钮位置,left ,right
|
|
|
+ checkIconPositon:{
|
|
|
+ type: String,
|
|
|
+ default: 'left'
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
@@ -74,16 +89,18 @@ export default {
|
|
|
methods: {
|
|
|
hasCheck() {
|
|
|
this.list.map(item => {
|
|
|
- let a = this.value.indexOf(item.id);
|
|
|
- item.checked = a >= 0;
|
|
|
- });
|
|
|
- this.list.splice();
|
|
|
+ let a = this.value.findIndex(k=>{
|
|
|
+ return this.backValue == 'idArr' ? k == item.id : k.id == item.id
|
|
|
+ })
|
|
|
+ item.checked = a>=0
|
|
|
+ })
|
|
|
+ this.list.splice()
|
|
|
},
|
|
|
// 选中
|
|
|
chooseItem(item) {
|
|
|
// 单选
|
|
|
if (this.types == 'radio') {
|
|
|
- this.value[0] = item.id;
|
|
|
+ this.value[0] = this.backValue == 'idArr' ? item.id : item;
|
|
|
this.$emit('ok', this.value);
|
|
|
} else {
|
|
|
// 取消选中
|
|
@@ -91,7 +108,7 @@ export default {
|
|
|
let index = this.value.indexOf(item.id);
|
|
|
this.value.splice(index, 1);
|
|
|
} else {
|
|
|
- this.value.push(item.id);
|
|
|
+ this.value.push(this.backValue == 'idArr' ? item.id : item);
|
|
|
}
|
|
|
}
|
|
|
this.hasCheck();
|
|
@@ -114,6 +131,7 @@ export default {
|
|
|
> view {
|
|
|
&:first-child {
|
|
|
flex-grow: 1;
|
|
|
+ overflow: auto;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -131,7 +149,7 @@ export default {
|
|
|
&:active {
|
|
|
background-color: #f8f8f8;
|
|
|
}
|
|
|
- text {
|
|
|
+ .title {
|
|
|
word-break: break-all;
|
|
|
}
|
|
|
}
|