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.

137 lines
2.8 KiB

3 years ago
<template>
<div>
2 years ago
<Input
v-model="select.filter[0].value"
search
enter-button
placeholder="请输入名称搜索"
@on-search="search"
/>
<div class="tags-container" v-loading="loading">
<el-scrollbar wrap-class="scrollbar-wrapper-biaoqian">
<div style="max-height: 180px">
<el-checkbox-group
size="mini"
ref="content"
v-model="value"
v-infinite-scroll="getTags"
infinite-scroll-delay="200"
infinite-scroll-disabled="disabled"
@change="change"
>
<el-checkbox border :label="item.id" v-for="item in tags">{{
item.mingcheng
}}</el-checkbox>
</el-checkbox-group>
<Divider v-if="noMore"></Divider>
</div>
</el-scrollbar>
</div>
3 years ago
</div>
</template>
<script>
2 years ago
import { index } from "@/api/system/baseForm";
3 years ago
export default {
props: {
fieldInfo: Object,
2 years ago
form: Object,
3 years ago
},
data() {
return {
2 years ago
loading: false,
noMore: false,
originalValue: [],
value: [],
3 years ago
tags: [],
2 years ago
select: {
page: 1,
page_size: 20,
table_name: "tags",
filter: [
{
key: "mingcheng",
op: "like",
value: "",
},
],
},
};
3 years ago
},
methods: {
2 years ago
async getTags() {
if (this.noMore) return;
this.loading = true;
const res = await index(this.select);
if (res.data.length < this.select.page_size) {
this.noMore = true;
} else {
this.select.page++;
}
this.tags.push(...res.data);
this.loading = false;
},
search() {
this.noMore = false;
this.select.page = 1;
this.tags = [];
this.loadHeight();
},
loadHeight() {
if (!this.noMore) {
this.$nextTick(() => {
if (this.$refs["content"].$el.getBoundingClientRect().height < 180) {
this.getTags().then((_) => {
this.loadHeight();
});
}
});
}
},
change(e) {
let tagObjs = []
this.value.forEach(i => {
let tag = this.tags.find(tag => tag.id === i)
tagObjs.push({
tag_id: tag.id,
tag
})
3 years ago
})
2 years ago
this.$emit("update", tagObjs);
},
},
computed: {
disabled() {
return this.loading || this.noMore;
3 years ago
},
},
watch: {
2 years ago
"form.biaoqian_tags_id_relation"(newVal) {
this.originalValue = newVal;
this.value = [];
},
3 years ago
},
2 years ago
created() {},
};
3 years ago
</script>
<style scoped lang="scss">
2 years ago
.tags-container {
min-height: 80px;
border-radius: 6px;
border: 1px dotted $primaryColor;
margin: 20px 0;
padding: 10px 20px;
}
</style>
<style>
.scrollbar-wrapper-biaoqian {
overflow-x: hidden;
}
3 years ago
</style>