index.vue
8.77 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
<template>
<div>
<el-button v-if="buttonShow" class="mt5" size="mini" style="color:#1890ff" icon="el-icon-edit-outline" circle
@click="visibleOpen">
</el-button>
<el-dialog title="表格显示设置" :visible.sync="open" width="40%" :close-on-click-modal="false" :show-close="false"
append-to-body center @close="close">
<div style="text-align: center">
<el-transfer style="text-align: left; display: inline-block" :data="transferData"
:right-default-checked="rightDefaultChecked" v-model="transferValue" :titles="transferTitle"
:props="props" v-loading="transferLoading" @change="change" @right-check-change="rightCheckChange">
<template slot="left-footer">
<div></div>
</template>
<template slot="right-footer">
<el-button style="margin-left:20px" type="primary" size="mini" icon="el-icon-top"
:disabled="updisabled" @click="up">
</el-button>
<el-button type="primary" size="mini" icon="el-icon-bottom" :disabled="downdisabled"
@click="down"></el-button>
</template>
</el-transfer>
</div>
<div slot="footer" class="dialog-footer">
<el-button type="primary" :loading="loading" @click="submit">确 定</el-button>
<el-button @click="close">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { getHeaderOrder, saveTableHeader } from "@/api/system/user.js";
export default {
props: {
tableName: {
type: String,
default: ''
}
},
data() {
return {
transferData: [],//穿梭框数据
transferValue: [],//已选择数据key
rightDefaultChecked: [],//右侧复选框选中
transferTitle: ['未显示列', '已显示列'],
props: { key: 'id', label: 'columnChineseName' },
open: false,
loading: false,
updisabled: true,
downdisabled: true,
buttonShow: true,
transferLoading: false
}
},
created() {
if (this.$store.getters.tableHeader) {
this.buttonShow = true
} else {
this.buttonShow = false
}
},
watch: {
open(val, oldVal) {
if (val) {
this.transferData = this.$store.getters.tableHeader[this.tableName]
this.transferLoading = true
// 获取用户显示表头
getHeaderOrder(`tableName=${this.tableName}`).then(res => {
this.transferLoading = false
if (res.code == 200) {
this.transferValue = res.data
} else {
this.msgwarning(res.msg)
}
}).catch(err => {
this.transferLoading = false
console.log(err)
})
}
}
},
methods: {
// 确定
submit() {
this.loading = true
let obj = this.$store.getters.tableHeader
// 保存设置
saveTableHeader({ tableName: this.tableName, idList: this.transferValue }).then(res => {
if (res.code === 200) {
obj[this.tableName] = res.data
this.$store.dispatch('SavetableHeader', obj)
this.msgSuccess('操作成功')
this.close(1)
} else {
this.msgWarning(res.msg)
}
this.$nextTick(() => {
this.loading = false
})
}).catch(err => {
this.loading = false
console.log(err)
})
},
//dialog开启
visibleOpen() {
this.open = true
},
// transferChange
change(val) {
let arr = []
let status0 = []
this.transferValue = val
this.transferData.forEach((item, i) => {
if (!this.transferValue.includes(item.id)) {
status0.push(item)
} else {
this.transferValue.forEach((vals, index) => {
if (vals == item.id) {
arr.push(item)
}
})
}
})
this.transferData = arr.concat(status0)
this.rightDefaultChecked = []
this.updisabled = true
this.downdisabled = true
},
//右侧选中,上下移动按钮状态设置
rightCheckChange(val) {
this.rightDefaultChecked = val
if (val.length == 1) {
if (this.transferValue.length > 1) {
this.transferValue.forEach((item, index) => {
if (item === val[0]) {
if (index === 0) {
this.updisabled = true
this.downdisabled = false
} else if (index === this.transferValue.length - 1) {
this.updisabled = false
this.downdisabled = true
} else {
this.updisabled = false
this.downdisabled = false
}
}
})
}
} else {
this.updisabled = true
this.downdisabled = true
}
},
//当前数据整理
tableHeadersSort() {
let arr = []
let status0 = []
this.transferData.forEach((item, i) => {
if (!this.transferValue.includes(item.id)) {
status0.push(item)
} else {
this.transferValue.forEach((val, index) => {
if (val == item.id) {
arr[index] = item
}
})
}
})
arr = arr.concat(status0)
this.transferData = arr
},
//右侧单条数据上移
up() {
if (!this.updisabled) {
let str = ''
this.transferValue.forEach((item, index) => {
if (item == this.rightDefaultChecked[0]) {
str = item
this.transferValue[index] = this.transferValue[index - 1]
this.transferValue[index - 1] = str
return
}
})
this.tableHeadersSort()
this.rightCheckChange([str])
}
},
//右侧单条数据下移
down() {
if (!this.downdisabled) {
let str = ''
let int = 1
this.transferValue.forEach((item, index) => {
if (item == this.rightDefaultChecked[0] && int === 1) {
str = item
this.transferValue[index] = this.transferValue[index + 1]
this.transferValue[index + 1] = str
int++
return
}
})
this.tableHeadersSort()
this.rightCheckChange([str])
}
},
//dialog关闭
close(val) {
this.rightDefaultChecked = []
this.updisabled = true
this.downdisabled = true
this.open = false
this.$emit('close', val)
}
}
}
</script>
<style lang="scss">
.el-transfer-panel__body.is-with-footer {
padding-bottom: 0px;
margin-bottom: 40px
}
.el-transfer {
.el-transfer-panel {
width: 220px;
.el-transfer-panel__list {
overflow-x: hidden;
overflow-y: scroll;
}
.el-transfer-panel__list::-webkit-scrollbar {
width: 5px;
height: 5px;
}
.el-transfer-panel__list::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
background: rgba(0, 0, 0, 0.2);
}
}
.el-transfer__buttons {
.el-button {
display: block;
padding: 9px 15px;
font-size: 12px;
border-radius: 3px;
}
.el-button+.el-button {
margin-left: 0px
}
}
}
</style>