Blame view

ant-design-vue-jeecg/src/views/system/modules/SelectUserModal.vue 7.13 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
<template>
  <div>
    <a-modal
      centered
      :title="title"
      :width="1000"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
谭毅彬 authored
10
      :cancelText="$t('button.close')">
肖超群 authored
11
12
13
14


      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
肖超群 authored
15
        <a-form layout="inline" @keyup.enter.native="searchQuery">
肖超群 authored
16
17
18
          <a-row :gutter="24">

            <a-col :span="10">
曾湘平 authored
19
20
              <a-form-item :label="this.$t('system.userAccount')">
                <a-input :placeholder="this.$t('system.enterUserAccount')" v-model="queryParam.username"></a-input>
肖超群 authored
21
22
23
24
              </a-form-item>
            </a-col>
            <a-col :span="8">
                    <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
25
26
                      <a-button type="primary" @click="searchQuery" icon="search">{{ $t('button.search') }}</a-button>
                      <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('button.reset') }}</a-button>
肖超群 authored
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
                    </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
      <!-- table区域-begin -->
      <div>
        <a-table
          size="small"
          bordered
          rowKey="id"
          :columns="columns1"
          :dataSource="dataSource1"
          :pagination="ipagination"
          :loading="loading"
          :scroll="{ y: 240 }"
          :rowSelection="{selectedRowKeys: selectedRowKeys,onSelectAll:onSelectAll,onSelect:onSelect,onChange: onSelectChange}"
          @change="handleTableChange">

        </a-table>
      </div>
      <!-- table区域-end -->


    </a-modal>
  </div>
</template>

<script>
肖超群 authored
57
58
import {filterObj} from '@/utils/util'
import {getAction} from '@/api/manage'
肖超群 authored
59
肖超群 authored
60
61
62
63
export default {
  name: "SelectUserModal",
  data() {
    return {
曾湘平 authored
64
      title: this.$t('system.addExistingUser'),
肖超群 authored
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
      names: [],
      visible: false,
      placement: 'right',
      description: '',
      // 查询条件
      queryParam: {},
      // 表头
      columns1: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
肖超群 authored
81
          }
肖超群 authored
82
83
        },
        {
曾湘平 authored
84
          title: this.$t('system.userAccount'),
肖超群 authored
85
86
87
88
89
          align: "center",
          width: 100,
          dataIndex: 'username'
        },
        {
曾湘平 authored
90
          title: this.$t('system.userName'),
肖超群 authored
91
92
93
94
95
          align: "center",
          width: 100,
          dataIndex: 'realname'
        },
        {
曾湘平 authored
96
          title: this.$t('system.sex'),
肖超群 authored
97
98
99
100
101
          align: "center",
          width: 100,
          dataIndex: 'sex_dictText'
        },
        {
曾湘平 authored
102
          title: this.$t('system.mobileNumber'),
肖超群 authored
103
104
105
106
107
108
109
          align: "center",
          width: 100,
          dataIndex: 'phone'
        }
      ],
      columns2: [
        {
曾湘平 authored
110
          title: this.$t('system.userAccount'),
肖超群 authored
111
112
          align: "center",
          dataIndex: 'username',
肖超群 authored
113
114

        },
肖超群 authored
115
        {
曾湘平 authored
116
          title: this.$t('system.userName'),
肖超群 authored
117
118
          align: "center",
          dataIndex: 'realname',
肖超群 authored
119
        },
肖超群 authored
120
        {
121
          title: this.$t('system.options'),
肖超群 authored
122
123
124
125
          dataIndex: 'action',
          align: "center",
          width: 100,
          scopedSlots: {customRender: 'action'},
肖超群 authored
126
        }
肖超群 authored
127
128
129
130
131
132
133
134
135
136
      ],
      //数据集
      dataSource1: [],
      dataSource2: [],
      // 分页参数
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
137
          return range[0] + "-" + range[1] + " " + this.$t('list.showing') + " " + total + " " + this.$t('list.records')
肖超群 authored
138
139
140
141
142
143
144
145
146
147
148
149
150
151
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      isorter: {
        column: 'createTime',
        order: 'desc',
      },
      loading: false,
      selectedRowKeys: [],
      selectedRows: [],
      url: {
        list: "/sys/user/list",
肖超群 authored
152
      }
肖超群 authored
153
154
155
156
157
158
159
160
    }
  },
  created() {
    this.loadData();
  },
  methods: {
    searchQuery() {
      this.loadData(1);
肖超群 authored
161
    },
肖超群 authored
162
163
164
    searchReset() {
      this.queryParam = {};
      this.loadData(1);
肖超群 authored
165
    },
肖超群 authored
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
    handleCancel() {
      this.visible = false;
    },
    handleOk() {
      this.dataSource2 = this.selectedRowKeys;
      console.log("data:" + this.dataSource2);
      this.$emit("selectFinished", this.dataSource2);
      this.visible = false;
    },
    add() {
      this.visible = true;
    },
    loadData(arg) {
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      var params = this.getQueryParams();//查询条件
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource1 = res.result.records;
          this.ipagination.total = res.result.total;
肖超群 authored
188
        }
肖超群 authored
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
      })
    },
    getQueryParams() {
      var param = Object.assign({}, this.queryParam, this.isorter);
      param.field = this.getQueryField();
      param.pageNo = this.ipagination.current;
      param.pageSize = this.ipagination.pageSize;
      return filterObj(param);
    },
    getQueryField() {
      //TODO 字段权限控制
    },
    onSelectAll(selected, selectedRows, changeRows) {
      if (selected === true) {
        for (var a = 0; a < changeRows.length; a++) {
          this.dataSource2.push(changeRows[a]);
肖超群 authored
205
        }
肖超群 authored
206
207
208
      } else {
        for (var b = 0; b < changeRows.length; b++) {
          this.dataSource2.splice(this.dataSource2.indexOf(changeRows[b]), 1);
肖超群 authored
209
        }
肖超群 authored
210
211
212
213
214
215
216
217
218
219
220
      }
      // console.log(selected, selectedRows, changeRows);
    },
    onSelect(record, selected) {
      if (selected === true) {
        this.dataSource2.push(record);
      } else {
        var index = this.dataSource2.indexOf(record);
        //console.log();
        if (index >= 0) {
          this.dataSource2.splice(this.dataSource2.indexOf(record), 1);
肖超群 authored
221
        }
肖超群 authored
222
肖超群 authored
223
      }
肖超群 authored
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectedRows;
    },
    onClearSelected() {
      this.selectedRowKeys = [];
      this.selectionRows = [];
    },
    handleDelete: function (record) {
      this.dataSource2.splice(this.dataSource2.indexOf(record), 1);
    },
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      console.log(sorter);
      //TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.ipagination = pagination;
      this.loadData();
肖超群 authored
246
247
    }
  }
肖超群 authored
248
}
肖超群 authored
249
250
</script>
<style lang="less" scoped>
肖超群 authored
251
252
253
.ant-card-body .table-operator {
  margin-bottom: 18px;
}
肖超群 authored
254
肖超群 authored
255
256
257
258
.ant-table-tbody .ant-table-row td {
  padding-top: 15px;
  padding-bottom: 15px;
}
肖超群 authored
259
肖超群 authored
260
261
262
.anty-row-operator button {
  margin: 0 5px
}
肖超群 authored
263
肖超群 authored
264
265
266
.ant-btn-danger {
  background-color: #ffffff
}
肖超群 authored
267
肖超群 authored
268
269
270
.ant-modal-cust-warp {
  height: 100%
}
肖超群 authored
271
肖超群 authored
272
273
274
275
.ant-modal-cust-warp .ant-modal-body {
  height: calc(100% - 110px) !important;
  overflow-y: auto
}
肖超群 authored
276
肖超群 authored
277
278
279
280
.ant-modal-cust-warp .ant-modal-content {
  height: 90% !important;
  overflow-y: hidden
}
肖超群 authored
281
</style>