middleground_code_v2/src/views/integrationOptionV2/compoments/baseNewSelect.vue

233 lines
5.0 KiB
Vue
Raw Normal View History

2024-03-26 11:18:19 +08:00
<template>
<div>
<template v-if="!lookflag">
<el-select
v-loading="selLoading"
class="w-100"
v-model="selectValue"
:placeholder="placeholder"
:clearable="false"
style="width: 240px"
size="mini"
refs="mySelect"
:reserve-keyword="true"
:disabled="disabled"
filterable
popper-class="sele"
:filter-method="filter"
@change="fun"
@focus="funx"
@blur="funb"
@visible-change="hidden"
clearable
>
<el-option
v-for="item in options"
:key="item[itemObj.value]"
:label="item[itemObj.label]"
remote
:value="item[itemObj.value]"
placeholder="请输入"
>
</el-option>
<div style="bottom: -10px">
<el-pagination
v-if="pageModel.total > pageModel.limit"
small
@current-change="handleCurrentChange"
:current-page="pageModel.pageIndex"
:page-size="pageModel.limit"
layout="prev, pager,next,total"
:total="pageModel.total"
>
</el-pagination>
</div>
</el-select>
</template>
<template v-else
>
<div v-loading="selLoading">{{ showValue }}</div>
</template
2024-03-26 11:18:19 +08:00
>
</div>
</template>
<style scoped lang="scss">
::v-deep .el-input--mini .el-input__inner {
height: 38px;
}
2024-03-26 11:18:19 +08:00
.w-100 {
width: 100% !important;
}
.drop > > > .el-input__inner {
2024-03-26 11:18:19 +08:00
background: #5183ff !important;
color: white;
border: none;
height: 26px;
padding: 10px 22px 10px 10px;
text-align: center;
}
2024-03-26 11:18:19 +08:00
.drop {
width: 250px;
}
.drop > > > .el-select .el-input .el-select__caret {
2024-03-26 11:18:19 +08:00
display: none;
}
</style>
<script>
import debounce from 'lodash/debounce'
import { getUserModuleApi } from '@/api/integrationOption/integrationOption.js'
2024-03-26 11:18:19 +08:00
export default {
props: {
ruleForm: {
type: Object,
default: {}
2024-03-26 11:18:19 +08:00
},
selectInfo: {
type: Object,
default: () => {
return {}
}
2024-03-26 11:18:19 +08:00
},
// 是否禁用
disabled: {
type: Boolean,
default: false
2024-03-26 11:18:19 +08:00
},
placeholder: String,
value: {
type: String
2024-03-26 11:18:19 +08:00
},
itemObj: {
type: Object,
default: () => {
return {}
}
2024-03-26 11:18:19 +08:00
},
lookflag: {
type: Boolean,
default: false
}
2024-03-26 11:18:19 +08:00
},
data() {
return {
options: [], //当前页码的数据
pageModel: {
total: 0,
pageIndex: 1,
limit: 10
2024-03-26 11:18:19 +08:00
},
selLoading: false,
showValue: '',
lookLoading: false
}
2024-03-26 11:18:19 +08:00
},
computed: {
selectValue: {
get() {
return this.value
2024-03-26 11:18:19 +08:00
},
set(val) {
this.$emit('input', val)
}
}
2024-03-26 11:18:19 +08:00
},
created() {
if (Object.keys(this.ruleForm).length && this.ruleForm[this.itemObj.id]) {
this.getSelectdata(this.ruleForm[this.itemObj.id]);
2024-03-26 11:18:19 +08:00
}
},
mounted() {
},
methods: {
// 请求select信息分页
async getUserModuleApi(obj = {}) {
this.selLoading = true
2024-03-26 11:18:19 +08:00
const res = await getUserModuleApi(
{
tl: 'mdmService',
as: 'mdmService',
dj: 'queryTemplateData'
2024-03-26 11:18:19 +08:00
},
{
tableName: this.itemObj.service,
value: this.itemObj.value,
label: this.itemObj.label,
pageNum: this.pageModel.pageIndex,
pageSize: this.pageModel.limit,
...obj
2024-03-26 11:18:19 +08:00
}
)
2024-03-26 11:18:19 +08:00
if (res.status === '200') {
console.log(res)
this.pageModel.total = res.attribute.total
this.options = res.attribute.list
2024-03-26 11:18:19 +08:00
}
this.selLoading = false
2024-03-26 11:18:19 +08:00
},
// 根据selectid找到value
async getSelectdata(id) {
this.selLoading = true
2024-03-26 11:18:19 +08:00
const res = await getUserModuleApi(
{
tl: 'mdmService',
as: 'mdmService',
dj: 'queryTemplateData'
2024-03-26 11:18:19 +08:00
},
{
tableName: this.itemObj.service,
id: id,
label: this.itemObj.label,
value: this.itemObj.value
2024-03-26 11:18:19 +08:00
}
)
2024-03-26 11:18:19 +08:00
if (res.status == 200 && res.attribute.length) {
this.selLoading = false
this.options = res.attribute
this.showValue = res.attribute[0][this.itemObj.label]
2024-03-26 11:18:19 +08:00
} else {
this.selLoading = false
2024-03-26 11:18:19 +08:00
this.options.push({
[this.itemObj.label]: '请选择',
[this.itemObj.value]: id
})
2024-03-26 11:18:19 +08:00
}
},
// 页码改变事件
handleCurrentChange(val) {
this.pageModel.pageIndex = val
this.getUserModuleApi()
2024-03-26 11:18:19 +08:00
},
// select选中更改事件
fun(val) {
// this.$emit(`${this.funName}`, arr);
},
// 获得焦点
funx() {
this.getUserModuleApi()
2024-03-26 11:18:19 +08:00
},
// 失去焦点
funb() {
},
hidden() {
},
2024-03-26 11:18:19 +08:00
//搜索方法,将符合的数据存入options中并分页展示
filter: debounce(function(val) {
2024-03-26 11:18:19 +08:00
// this.pageModel.pageIndex = 1;
// this.getUserModuleApi({ lableValue: val });
}, 300)
2024-03-26 11:18:19 +08:00
},
//监听来自父组件的数据,当数据更新时,重置展示
watch: {}
}
2024-03-26 11:18:19 +08:00
</script>