channel.js
2.79 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
import { remove, getList, save } from '@/api/cms/channel'
export default {
data() {
return {
formVisible: false,
formTitle: '添加栏目',
deptList: [],
isAdd: true,
form: {
id: '',
name: '',
code: ''
},
total: 0,
list: null,
listLoading: true,
selRow: {}
}
},
computed: {
rules() {
return {
cfgName: [
{ required: true, message: '名称不能为空', trigger: 'blur' }
],
cfgValue: [
{ required: true, message: '编码不能为空', trigger: 'blur' }
]
}
}
},
created() {
this.init()
},
methods: {
init() {
this.fetchData()
},
fetchData() {
this.listLoading = true
getList().then(response => {
this.list = response.data
this.listLoading = false
})
},
search() {
this.fetchData()
},
reset() {
this.fetchData()
},
handleFilter() {
this.getList()
},
handleCurrentChange(currentRow, oldCurrentRow) {
this.selRow = currentRow
},
resetForm() {
this.form = {
id: '',
name: '',
code: ''
}
},
add() {
this.resetForm()
this.formTitle = '添加栏目'
this.formVisible = true
this.isAdd = true
},
save() {
this.$refs['form'].validate((valid) => {
if (valid) {
save({
id: this.form.id,
name: this.form.name,
code: this.form.code
}).then(response => {
this.$message({
message: this.$t('common.optionSuccess'),
type: 'success'
})
this.fetchData()
this.formVisible = false
})
} else {
return false
}
})
},
checkSel() {
if (this.selRow && this.selRow.id) {
return true
}
this.$message({
message: this.$t('common.mustSelectOne'),
type: 'warning'
})
return false
},
edit() {
if (this.checkSel()) {
this.isAdd = false
this.form = this.selRow
this.formTitle = '编辑栏目'
this.formVisible = true
}
},
remove() {
if (this.checkSel()) {
var id = this.selRow.id
this.$confirm(this.$t('common.deleteConfirm'), this.$t('common.tooltip'), {
confirmButtonText: this.$t('button.submit'),
cancelButtonText: this.$t('button.cancel'),
type: 'warning'
}).then(() => {
remove(id).then(response => {
this.$message({
message: this.$t('common.optionSuccess'),
type: 'success'
})
this.fetchData()
})
}).catch(() => {
})
}
}
}
}