ludc
2023-06-06 e1a2b770a3b9bf440ddccf4518c436e55bdaecda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!-- 高级查询对话框组件
    1、打开与关闭与el-dialog用法一致;
    2、用户编辑好的查询条件通过@echoContion事件绑定相应的函数,实现子组件值传递回父组件;
    3、用户输入的值会以conditionMap[field]的格式拼接好进行回传,然后就需要使用的地方自行进行查询的调用;
 -->
<template>
    <el-dialog 
        title="高级查询"
        append-to-body
        width="55vw"
        style="height: 115vh; margin-top: -10vh; overflow: hidden"
        :visible.sync="isShowDialog"
        @close="recoverPage"
        destroy-on-close>
        <div class="search-total">
            <!-- 头部按钮区域 -->
            <div slot="title" class="dialog-search-button"> 
                <el-button 
                    type="primary"  
                    size="small"
                    icon="el-icon-search"
                    @click="searchSubmit">
                    查询
                </el-button>
                <el-button 
                    type="warning"
                    size="small"
                    icon="el-icon-refresh"
                    @click="resetInput">
                    重置
                </el-button>
            </div>
            <!-- 页面主体内容区域 -->
            <div class="search-content">
                <el-row  
                    v-for="(item,index) in initOptions"
                    :key="item.queryField"
                    v-show="!item.hidden"
                    :span="24">
                    <el-col :span="5">
                        <div class="grid-content">
                            <el-select placeholder="请选择" v-model="searchFormArrays[index].queryField">
                                <el-option
                                    v-for="feildName in initOptions"
                                    :key="feildName.queryField"
                                    :label="feildName.title"
                                    :value="feildName.queryField">
                                </el-option>
                            </el-select>
                        </div>
                    </el-col>
                    <el-col :span="4">
                        <div class="grid-content">
                            <el-select placeholder="请选择" v-model="searchFormArrays[index].condition">
                                <el-option
                                    v-for="condition in item.fieldType=='text' ? searchConditions:switchSearchConditions"
                                    :key="condition.value"
                                    :label="condition.label"
                                    :value="condition.value">
                                </el-option>
                            </el-select>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div class="grid-content">
                            <el-input v-if="item.fieldType==='text' || item.fieldType===''" v-model="searchFormArrays[index].fieldValue" type="text" placeholder="请输入"></el-input>
                            <el-select v-else-if="item.fieldType==='combox'" v-model="searchFormArrays[index].fieldValue" placeholder="请选择">
                                <el-option
                                    v-for="option in item.data"
                                    :key="option.value"
                                    :label="option.key"
                                    :value="option.value">
                                </el-option>
                            </el-select>
                            <el-switch  v-else-if="item.fieldType==='truefalse'" v-model="searchFormArrays[index].fieldValue"></el-switch>
                        </div>
                    </el-col>
                    <el-col :span="2">
                        <div class="grid-content">
                            <i class="el-icon-close" @click="removeInput(index)"></i>
                        </div>
                    </el-col>
                </el-row>
            </div>
        </div>
    </el-dialog>
</template>
 
<script>
import { getDictionary } from "@/api/omd/enum";
export default {
    name: "advancedQuery",
    props: {
        // 对话框显示隐藏控制
        visible: {
            type: "Boolean",
            default: false,
        },
        // 页面显示配置
        options: {
            type: "Object",
            default: {},
        },
    },
    data() {
        return {
            // 对话框显示控制
            isShowDialog: this.visible,
            initOptions: [],
            // 字段是输入框类型的条件数组
            searchConditions: [
                {
                    value: "_equal",
                    label: "等于",
                },{
                    value: "_notequal",
                    label: "不等于",
                },{
                    value: "_like",
                    label: "包含",
                },{
                    value: "_notlike",
                    label: "不包含",
                },{
                    value: "_ge", //大于,默认为大于等于
                    label: "大于", 
                },{
                    value: "_le", //小于,默认为小于等于
                    label: "小于",
                },
            ],
            // 字段是单选或下拉框类型的条件数组
            switchSearchConditions: [
                {
                    value: "_equal",
                    label: "等于",
                },{
                    value: "_notequal",
                    label: "不等于",
                }
            ],
            searchFormArrays: [],
            fieldValue: '',
        }
    },
    watch: {
        // 监听父组件传的窗口显示隐藏的值
        visible (){
            this.isShowDialog = this.visible;
        },
        // 对话框内容渲染配置
        options(){
            // 将options配置赋值到data中的option中,避免深浅拷贝的问题所以需要转json之后再赋值
            const data = JSON.stringify(this.options);
            this.initOptions = JSON.parse(data);
            //console.log(this.initOptions); 
            this.initOptions.forEach((item,index) => {
                if(item.fieldType==='combox') {
 
                   this.getEnum(item.comboxKey).then(res=>{
                        console.log(res.data);
                   })
                   //item.data = 
                }
                let add = {
                    queryField: String(item.queryField),
                    condition: item.fieldType==='text' ? String("_like"):String("_equal"),
                    fieldValue: item.fieldType==='truefalse' ? Boolean(false):String(""),
                }
                this.searchFormArrays.push(add)
            });
            //console.log(this.searchFormArrays);
        }
    },
    created () {
        
    },
    methods: {
 
        async getEnum(enumText){
            let enumParam = '';
            await getDictionary({code: enumText}).then(res=>{
                enumParam = res.data.data;
                // console.log(res.data);
            })
            //console.log(enumParam);
            return enumParam;
        },
 
        // 移除搜索框
        removeInput(index){
            //console.log(this.initOptions);
            this.$delete(this.initOptions,index);
            this.$delete(this.searchFormArrays,index);
        },
        // 重置当前界面的输入框
        resetInput(){
            const data = JSON.stringify(this.options);
            this.initOptions = JSON.parse(data);
            let array = [];
            this.initOptions.forEach((item,index) => {
                let add = {
                    queryField: String(item.queryField),
                    condition:item.fieldType=='text' ? String("_like"):String("_equal"),
                    fieldValue: item.fieldType=='truefalse' ? Boolean(false):String(''),
                }
                array.push(add)
            });
            this.searchFormArrays = array;
            //console.log(this.initOptions);
            //console.log(this.searchFormArrays);
        },
        // 恢复页面
        recoverPage(){
            this.resetInput();
            this.$emit('update:visible', false);
        },
        // 提交当前页面的输入的查询条件并做对应的过滤与检查
        searchSubmit(){
            let condtionParam = {};
            const searchConditions = this.searchFormArrays;
            for(let index = 0; index < searchConditions.length; index++) {
                //console.log(condtionParam['conditionMap['+searchConditions[index].queryField+']']+'' == 'undefined');
                if(searchConditions[index].fieldValue.trim() != '' || searchConditions[index].fieldValue+''==='false') {
                    // 存在相同的查询条件
                    if(condtionParam['conditionMap['+searchConditions[index].queryField+']']+''.trim() != 'undefined' ) {
                        this.$message.warning("存在重复查询条件,请仔细核对!");
                        return false;
                    }
                    //拼接成map对象,将查询对象和condition拼接在一起,组成高级查询map的key
                    condtionParam['conditionMap['+searchConditions[index].queryField+searchConditions[index].condition+']'] = searchConditions[index].fieldValue;
                }
            }
            // 查询条件没有出现重复属性,并且过滤掉了空值,传递给父组件
            // console.log(condtionParam);
            this.$emit('echoContion',condtionParam)
            this.isShowDialog = false;
        },    
    }
}
</script>
 
<style lang="scss" scoped>
 
    .search-total {
        border-radius: 4px;
        min-height: 70vh;
        // margin-left: 35px;
        margin-top: -8px;
        overflow-y: auto; 
        height: 70vh;
    }
    .dialog-search-button {
        border-top: 1px solid #E9E7E7;
        border-bottom: 1px solid #E9E7E7;
        padding: 10px 10px 10px;
        position: fixed;
        display: block;
        background-color: #fff;
        // top: 10%;
        margin-top: -30px;
        width: 50%;
        z-index: 1000;
    }
    // .search-total > .search-content > .el-row{
    //     margin-bottom: 5px;
    //     &:last-child {
    //         margin-bottom: 0;
    //     }
    // }
    .search-total > .search-content {
        margin-top: 40px;
    }
    .search-total > .search-content > .el-row > .el-col {
        border-radius: 4px;
    }
    .search-total > .search-content > .el-row > .el-col > .grid-content {
        border-radius: 4px;
        min-height: 36px;
    }
    .search-total > .search-content > .el-row > .el-col {
        margin-right: 6px;
        &:last-child {
            margin-right: 0;
        }
    }
    .grid-content > .el-icon-close {
        font-size: 35px;
        cursor: pointer;
        color: rgb(222, 130, 105);
    }
    .grid-content > .el-icon-close:hover{
        font-size: 38px;
        color: rgb(219, 52, 6);
    }
    .grid-content > .el-select {
        width: 100%;
    }
    .grid-content > .el-switch {
        line-height: 40px;
        height: 40px;
    }
 
 
</style>