duhuizhe
2023-10-16 3aa55dd3f62cee2c1c4c0aa74e1570acf83f8927
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
<template>
  <div class="table-page-search-wrapper">
    <el-form :model="form" inline ref="formData" label-width="100px" size="small">
<!--      <el-row :gutter="10">-->
<!--        <el-col :sm="24" :md="24" :lg="24">-->
          <el-form-item :label="item.label" :prop="item.dataIndex" v-for="(item, i) in myItems1" :key="i">
            <search-item :item="item" @change="formChange($event,i)" :value="item.value"/>
          </el-form-item>
          <div v-show="advanced" style="display: inline;">
            <el-form-item :label="item.label" :prop="item.dataIndex" v-for="(item, i) in myItems2" :key="i">
              <search-item :item="item" @change="formChange($event,i+3)" :value="item.value"/>
            </el-form-item>
          </div>
          <div class="table-page-search-submitButtons">
            <a
              @click="toggleAdvanced"
              style="margin-left: 8px"
              v-if="items.length > 4">
              {{ advanced ? "收起" : "展开" }}
              <i :class="advanced?'el-icon-top':'el-icon-bottom'"/>
            </a>
            <el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
            <el-button style="margin-left: 8px" icon="el-icon-refresh" @click="reset">重置</el-button>
          </div>
<!--        </el-col>-->
<!--        <el-col :sm="24" :md="7" :lg="5">-->
<!--          -->
<!--        </el-col>-->
<!--      </el-row>-->
    </el-form>
  </div>
</template>
<script>
import SearchItem from './SearchItem'
 
export default {
  components: { SearchItem },
  name: 'mySearch',
  props: ['items'],
  data () {
    return {
      myItems1: [],
      myItems2: [],
      // 高级搜索 展开/关闭
      advanced: false,
      form:{}
    }
  },
  beforeCreate () {
    this.form = {}
  },
  created () {
    this.items.map((x,i)=>{
      this.form[x.dataIndex] = x.defaultValue ? x.defaultValue:null
    })
    if (this.items.length > 4) {
      this.myItems1 = this.items.slice(0, 4)
      this.myItems2 = this.items.slice(4)
    } else {
      this.myItems1 = this.items
    }
  },
  computed: {
    actionMd: function () {
      if (!this.advanced) {
        return 4
      } else {
        const _b = this.items.length % 3
        if (_b === 0) {
          return 24
        } else {
          return 4
        }
      }
    }
  },
  methods: {
    toggleAdvanced () {
      this.advanced = !this.advanced
      this.$emit('openChange')
    },
    search (e) {
      e.preventDefault()
      this.$refs.formData.validate((valid) => {
        if (valid) {
          this.form.pageNum = 1
          this.$emit('search', this.form)
        } else {
          this.$message.warning('校验未通过,请检查!')
          return false;
        }
      });
    },
    reset () {
      this.$refs['formData'].resetFields();
      this.items.map((x,i)=>{
        x.value = x.defaultValue ? x.defaultValue:null
      })
      if (this.items.length > 3) {
        this.myItems1 = this.items.slice(0, 3)
        this.myItems2 = this.items.slice(3)
      } else {
        this.myItems1 = this.items
      }
      this.$forceUpdate()
     this.$nextTick(()=>{
       this.form.pageNum = 1
       this.$emit('reset')
       this.$emit('search', this.form)
     })
    },
    formChange(e,i){
      this.form[this.items[i].dataIndex] = e
      this.items[i].value = e
      this.$forceUpdate()
    }
  }
}
</script>
 
<style scoped>
/deep/.el-form--inline .el-form-item__label{
  font-weight: normal;
  color: #1D2129;
}
.table-page-search-submitButtons{
  min-width: 160px;
  float: right;
}
 /deep/.el-button--medium{
 padding:10px 12px;
}
</style>