index.vue
10.2 KB
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<template>
<div>
<el-form class="clearfix search-form" id="searchForm" :class="[expande ? 'expande' : 'close']" :model="formModel" :size="size" @submit.native.prevent :label-position="labelPosition" :label-width="labelWidth">
<!-- <div class="expande-button-wrap" @click="openClose">
<i class="el-icon-arrow-down"></i>
<span v-if="expande">展开</span>
<span v-else>收起</span>
</div> -->
<div class="expande-button-wrap" v-if="needShowExpande">
<div class="expande-button" @click="expandeClick" v-if="!expande">
<i class="el-icon-arrow-down"></i>
<span>展开</span>
</div>
<div class="expande-button" @click="expandeClick" v-else>
<i class="el-icon-arrow-up"></i>
<span>收起</span>
</div>
</div>
<div class="firstRowBtn" v-if="!expande && isShowBtns && isNeedThreeBtns">
<el-button plain @click="resetTable" size="small">重置</el-button>
<el-button type="primary" @click="searchTable" size="small">查询</el-button>
<el-button type="primary" size="small" @click="handleExport">导出</el-button>
<!-- v-if="(merchantModel == 1 && accountLevel == 1) || (merchantModel == 2 && accountLevel == 4)" -->
<!-- <el-button type="primary" @click="syncClick" :loading="ploading" size="small" >同步数据</el-button> -->
</div>
<div class="itemWidth">
<el-form-item v-for="(item, index) in formList" :key="index" :label="item.label || ''">
<template>
<template v-if="item.type === 'input'">
<el-input v-model="formModel[item.prop]" :type="item.inputType || 'text'" :placeholder="item.placeholder || '请输入'" :clearable="item.clearable || false" :readonly="item.readonly || false" @keyup.enter.native="onInput" ></el-input>
</template>
<template v-else-if="item.type === 'select'">
<el-select size="small" v-model="formModel[item.prop]" :placeholder="item.placeholder || '请选择'" :filterable="!item.noFilter">
<el-option v-for="i in item.options" :key="i[item.value] || i.value" :label="i[item.key] || i.label" :value="i[item.value] || i.value" :disabled="i.disabled"></el-option>
</el-select>
</template>
<template v-else-if="item.type === 'daterange'">
<!-- :default-value="['2021-10-03', '2021-11-03']" -->
<el-date-picker v-if="showDefaultTime" v-model="formModel[item.prop]" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" :picker-options="item.pickerOptions || {}"></el-date-picker>
<el-date-picker v-else v-model="formModel[item.prop]" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" :picker-options="item.pickerOptions || {}"></el-date-picker>
</template>
</template>
</el-form-item>
<el-form-item style="position:absolute;right:-12px;bottom:0;" v-if="!needShowExpande || expande">
<template>
<slot name="form-slot"></slot>
</template>
</el-form-item>
</div>
</el-form>
</div>
</template>
<script>
export default {
name: 'search-form',
props: {
formModel: {
type: Object,
default: () => {}
},
size: {
type: String,
default: 'small'
},
formList: {
type: Array,
default: () => []
},
labelPosition: {
type: String,
default: 'right'
},
labelWidth: {
type: String,
default: 'auto'
},
ploading: {
type: Boolean,
default: false
},
isHasSyncBtn: {
type: Boolean,
default: false
},
isThreeRowShow:{
type: Boolean,
default: false
},
merchantModel: {
type: Number,
default: 1
},
accountLevel: {
type: Number,
default: 0
},
showDefaultTime: {
type: Boolean,
default: false
},
isNeedThreeBtns:{
type: Boolean,
default: true
}
},
data() {
return {
expande: true,
needShowExpande: false,
FormHeight: 0,
isShowBtns: true
}
},
created() {},
mounted() {
if (this.showDefaultTime) {
//调用默认时间(30天)
this.getPassMonthFormatDate()
}
this.$nextTick(()=>{
var sf = document.getElementById('searchForm')
if (sf.clientWidth < 1280 && this.isHasSyncBtn) {
document.querySelector('.itemWidth').style.maxWidth = 700 + 'px'
}
if (sf.clientWidth < 952 && this.isHasSyncBtn) {
this.isShowBtns = false
}
let lineHeight = 75 //75
if (document.getElementById('searchForm').offsetHeight > lineHeight * 2) {
this.expande = false
this.needShowExpande = true
} else {
this.needShowExpande = false
this.expande = true
}
if( sf.clientWidth< 840 && this.isThreeRowShow){
document.querySelector('.itemWidth').style.minHeight= document.querySelector('.itemWidth').offsetHeight + 50 + 'px'
// 客户群里面四个表做特殊处理,当为苹果笔记本电脑尺寸时,不是现实展开收起按钮
this.needShowExpande = false
this.expande = true
}
})
//有数据不算表格高度,没数据算高度
// setTimeout(() => {
// this.$emit('setTableHeightEvent')
// }, 200)
// })
//-------------------------
// var that = this
// var resizeTimer = null
// 如何实现不管窗口如何改变,只在停止改变之后才执行代码呢?
// $(window).bind('resize', function() {
// if (resizeTimer) clearTimeout(resizeTimer)
// resizeTimer = setTimeout(function() {
//
// }, 100)
// })
// window.onresize = () => {
// return (() => {
// if (resizeTimer) clearTimeout(resizeTimer)
// resizeTimer = setTimeout(function() {
// window.location.reload() //浏览器重新从服务器请求资源,在http请求头中不会包含缓存标记
// // that.FormHeight = document.getElementById('searchForm').offsetHeight
// if (sf.clientWidth < 952 && that.isHasSyncBtn) {
// that.isShowBtns = false
// }
// }, 100)
// })()
// }
// window.addEventListener('resize', () => {
// if (resizeTimer) clearTimeout(resizeTimer)
// resizeTimer = setTimeout(function() {
// window.location.reload() //浏览器重新从服务器请求资源,在http请求头中不会包含缓存标记
// // that.FormHeight = document.getElementById('searchForm').offsetHeight
// if (sf.clientWidth < 952 && that.isHasSyncBtn) {
// that.isShowBtns = false
// }
// }, 100)
// })()
},
watch: {
FormHeight: {
handler(val) {
let lineHeight = 75 //22
if (val > lineHeight * 2) {
this.expande = false
this.needShowExpande = true
} else {
this.needShowExpande = false
this.expande = true
}
}
}
},
methods: {
onInput(e) {
this.$emit('input', e)
},
resetTable() {
this.$emit('resetTable')
},
searchTable() {
this.$emit('searchTable')
},
syncClick() {
this.$emit('syncClick')
},
handleExport(){
this.$emit('handleExport')
},
expandeClick() {
this.expande = !this.expande
// setTimeout(() => {
// this.$emit('setTableHeightEvent')
// }, 200)
},
//时间选择器显示默认一月的时间
/* 获取过去时间,并传值给现在时间 */
getPassMonthFormatDate() {
var nowDate = new Date()
var date = new Date(nowDate)
date.setDate(date.getDate() - 30) //7 30 365
var seperator1 = '-'
var year = date.getFullYear()
var month = date.getMonth() + 1
var strDate = date.getDate()
if (month >= 1 && month <= 9) {
month = '0' + month
}
if (strDate >= 0 && strDate <= 9) {
strDate = '0' + strDate
}
var formatDate = year + seperator1 + month + seperator1 + strDate
this.getNowFormatDate(formatDate)
},
/* 获取现在时间,并接受过去时间的值 */
getNowFormatDate(formatDate) {
var date = new Date()
var seperator1 = '-'
var year = date.getFullYear()
var month = date.getMonth() + 1
var strDate = date.getDate()
if (month >= 1 && month <= 9) {
month = '0' + month
}
if (strDate >= 0 && strDate <= 9) {
strDate = '0' + strDate
}
var nowData = year + seperator1 + month + seperator1 + strDate
this.$set(this.formModel, 'daterange', [formatDate, nowData])
// this.formModel['daterange'] = [formatDate, nowData] // 默认赋值一个月时间,不要直接赋值,不是响应式
}
}
}
</script>
<style lang="scss">
@import '@/styles/variables.scss';
.search-form {
padding: 18px 0 0 0;
position: relative;
overflow: hidden;
min-height: 50px;
/deep/.el-form-item__label-wrap .el-form-item__label {
// display: inline-block;
// width: 110px;
}
.firstRowBtn {
position: absolute;
right: 52px;
z-index: 1;
.el-button + .el-button {
margin-left: 10px;
}
}
.itemWidth {
max-width: 1027px;
min-width: 660px;
}
.expande-button-wrap {
position: absolute;
top: 24px;
right: 0;
z-index: 99;
.expande-button {
color: $btnBlue;
cursor: pointer;
i {
height: 8px;
}
span {
height: 20px;
font-size: 14px;
font-weight: 400;
color: $btnBlue;
line-height: 20px;
}
}
}
.el-form-item {
display: inline-block;
// float: left;
// width: calc(50% - 20px);
// max-width: 350px; //420
margin-right: 15px;
}
.el-range-editor--small.el-input__inner {
width: 215px;
}
.el-input--small .el-input__inner {
width: 215px;
}
.el-select {
width: 215px;
}
.el-select>.el-input{
width: 215px;
}
.el-form-item__content {
width: 100%;
}
}
.expande {
// overflow: auto;
height: auto;
// padding-bottom: 22px;
}
.close {
overflow: hidden;
height: 50px;
// padding-bottom: 0;
}
</style>