2024-08-23 17:06:01 +08:00
|
|
|
<template>
|
|
|
|
<div class="ag-querybox">
|
|
|
|
<el-popover
|
|
|
|
placement="bottom"
|
|
|
|
:width="width"
|
|
|
|
v-model="popState"
|
|
|
|
trigger="click">
|
|
|
|
<ag-input slot="reference" size="small" class="queryplacetext" :style="{width:labelWidth}" :clearable="false" :value="placeholderValue" :placeholder="placeholder"></ag-input>
|
|
|
|
<el-form label-position="left" size="small" :model="values" :inline="false" v-if="inputs.length>0" ref="queryformref">
|
|
|
|
<ag-row>
|
|
|
|
<ag-col :span="12" v-for="(item,index) in inputs" :key="index">
|
2024-09-13 12:04:24 +08:00
|
|
|
<el-form-item :label="item.label" :rules="item.rules" :prop="item.name">
|
|
|
|
<ag-select :placeholder="item.placeholder" :value="item.value||''" closeable :options="item.options" style="width:100%" @change="onSelect($event,item,index)"/>
|
2024-08-23 17:06:01 +08:00
|
|
|
</el-form-item>
|
2024-09-11 17:08:56 +08:00
|
|
|
</ag-col>
|
2024-08-23 17:06:01 +08:00
|
|
|
</ag-row>
|
2024-09-11 17:08:56 +08:00
|
|
|
<div class="footerbox">
|
|
|
|
<el-button size="small" @click="onCancel">取消</el-button>
|
|
|
|
<el-button size="small" type="primary" @click="onQuery">查询</el-button>
|
|
|
|
</div>
|
2024-08-23 17:06:01 +08:00
|
|
|
</el-form>
|
|
|
|
</el-popover>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import agSelect from "../../agSelect/src/index.vue";
|
|
|
|
import agInput from "../../agInput/src/index.vue";
|
|
|
|
import agRow from "./../../agRow/src/index.vue";
|
|
|
|
import AgCol from "./../../agCol/src/index.vue";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "agQuery",
|
|
|
|
components: {
|
|
|
|
agSelect,
|
|
|
|
agInput,
|
|
|
|
AgCol,
|
|
|
|
agRow
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
width:{
|
|
|
|
type: Number,
|
|
|
|
default: 450,
|
|
|
|
},
|
|
|
|
labelWidth:{
|
|
|
|
type: Number,
|
|
|
|
default: 200,
|
|
|
|
},
|
|
|
|
inputs:{
|
|
|
|
type: Array,
|
|
|
|
default: () => {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
},
|
2024-09-13 12:04:24 +08:00
|
|
|
props:{
|
|
|
|
type: Object,
|
|
|
|
default: () => {
|
|
|
|
return {
|
|
|
|
lazyLoad (node, resolve) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
}
|
2024-08-23 17:06:01 +08:00
|
|
|
},
|
2024-09-09 15:13:37 +08:00
|
|
|
model: {
|
|
|
|
prop: 'values', // 明确指定 prop 为 'value'
|
|
|
|
event: 'onSearch' // 自定义事件名,用于更新 value
|
2024-09-09 15:24:33 +08:00
|
|
|
},
|
|
|
|
mounted(){
|
2024-08-23 17:06:01 +08:00
|
|
|
let newinput=this.inputs.map((g)=>g.label);
|
|
|
|
this.placeholder="请选择"+newinput.join("/");
|
2024-09-13 12:04:24 +08:00
|
|
|
if(this.props.lazyLoad){
|
|
|
|
this.props.lazyLoad({level:0,pathLabels:this.values,value:""},(datas)=>{
|
|
|
|
this.inputs[index+1].options=datas;
|
|
|
|
});
|
|
|
|
}
|
2024-08-23 17:06:01 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
values: {},
|
|
|
|
placeholderValue:"",
|
|
|
|
placeholder:"请选择",
|
2024-09-13 12:04:24 +08:00
|
|
|
popState:false,
|
2024-08-23 17:06:01 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2024-09-09 15:24:33 +08:00
|
|
|
onReset(){
|
|
|
|
this.values={};
|
|
|
|
this.$emit('onSearch',this.values);
|
|
|
|
},
|
2024-09-13 12:04:24 +08:00
|
|
|
onSelect(value,item,index){
|
2024-08-23 17:06:01 +08:00
|
|
|
item.value=value;
|
|
|
|
this.$set(this.inputs,index,item);
|
|
|
|
let newvalues={};
|
2024-09-13 12:04:24 +08:00
|
|
|
|
2024-08-23 17:06:01 +08:00
|
|
|
let newplaceholderValue=[];
|
2024-09-13 12:04:24 +08:00
|
|
|
this.inputs.map((g)=>{
|
|
|
|
if(g.value&&g.name){
|
|
|
|
newvalues[g.name]=g.value;
|
|
|
|
g.options.find((f)=>f.value==g.value).label&&(newplaceholderValue.push(g.options.find((f)=>f.value==g.value).label));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.values=newvalues;
|
|
|
|
if(this.$listeners.change){
|
|
|
|
this.$emit('change',newvalues);
|
|
|
|
}
|
|
|
|
this.props.lazyLoad({level:index+1,pathLabels:newvalues,value},(datas)=>{
|
|
|
|
this.inputs[index+1].options=datas;
|
|
|
|
});
|
|
|
|
this.placeholderValue=newplaceholderValue.join("/")
|
2024-08-23 17:06:01 +08:00
|
|
|
},
|
|
|
|
onCancel(){
|
|
|
|
this.popState=false;
|
2024-09-09 15:24:33 +08:00
|
|
|
if(this.$listeners.onCancel){
|
|
|
|
this.$emit('onCancel');
|
|
|
|
}
|
2024-08-23 17:06:01 +08:00
|
|
|
},
|
2024-09-09 15:24:33 +08:00
|
|
|
onQuery(){
|
2024-08-23 17:06:01 +08:00
|
|
|
if(this.$refs.queryformref){
|
2024-09-09 15:24:33 +08:00
|
|
|
this.$refs.queryformref.validate((valid) => {
|
2024-08-23 17:06:01 +08:00
|
|
|
if (valid) {
|
|
|
|
this.$emit('onSearch',this.values);
|
|
|
|
this.popState=false;
|
2024-09-09 15:24:33 +08:00
|
|
|
} else {
|
2024-08-23 17:06:01 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang='scss'>
|
|
|
|
.ag-querybox {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
.queryplacetext{
|
|
|
|
color:#333;
|
|
|
|
max-width:200px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
cursor: pointer;
|
|
|
|
caret-color: transparent; /* 隐藏光标 */
|
|
|
|
}
|
|
|
|
}
|
2024-09-11 17:08:56 +08:00
|
|
|
.footerbox{
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: flex-end;
|
|
|
|
margin-top:5px;
|
|
|
|
}
|
2024-08-23 17:06:01 +08:00
|
|
|
::v-deep {
|
|
|
|
.el-form-item--small .el-form-item__label{
|
|
|
|
line-height: 40px;
|
|
|
|
}
|
|
|
|
.el-form-item--small.el-form-item{
|
|
|
|
margin-bottom:5px;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|