index.vue
5.3 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
<template>
<div class="app-container">
<div class="filter-container">
<el-input v-model="listQuery.title" placeholder="游戏名称" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
<el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
搜索
</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
新增
</el-button>
</div>
<el-table
v-loading="listLoading"
:data="list"
border
fit
highlight-current-row
style="width: 100%;"
>
<el-table-column label="游戏名称" min-width="150px" align="center">
<template slot-scope="scope">
<span>{{scope.row.gameName}}</span>
</template>
</el-table-column>
<el-table-column label="渠道ID" min-width="150px" align="center">
<template slot-scope="scope">
<span>{{scope.row.channelID}}</span>
</template>
</el-table-column>
<el-table-column label="推广员" min-width="150px" align="center">
<template slot-scope="scope">
<span>{{scope.row.promoters}}</span>
</template>
</el-table-column>
<el-table-column label="操作" min-width="150px" align="center">
<template slot-scope="scope">
<span>{{scope.row.operation}}</span>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
<el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="100px" style="width: 400px; margin-left:30px;">
<el-form-item label="游戏名称" prop="name">
<el-select v-model="temp.name" class="filter-item" placeholder="请选择">
<el-option v-for="item in gameNameList" :key="item" :label="item" :value="item" />
</el-select>
</el-form-item>
<el-form-item label="推广员名称" prop="extensionName">
<el-select v-model="temp.extensionName" class="filter-item" placeholder="请选择">
<el-option v-for="item in extensionList" :key="item" :label="item" :value="item" />
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">
取消
</el-button>
<el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
确定
</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { access } from 'fs'
import Pagination from '@/components/Pagination'
export default {
name:'channels',
components: { Pagination },
data() {
return {
list: null,
total: 0,
listLoading: false,
listQuery:{
page: 1,
limit: 20,
title: undefined,
},
textMap: {
update: '编辑',
create: '创建'
},
dialogPvVisible: false,
dialogFormVisible:false,
rules:{
name:[{required:true, message:"游戏名称是必需的", trigger:'blur'}],
extensionName:[{required:true, message:'推广员名称是必需的',trigger:'blur'}]
},
temp:{
id:undefined,
name:'',
cpName:'',
extensionName:''
},
dialogStatus:'',
gameNameList:['火影','海贼','超人','柯南'],
extensionList:['推广员1','推广员2','推广员3'],
}
},
created(){
this.getList();
},
methods: {
handleFilter(){
console.log("查询游戏")
},
getList(){
// this.listLoading = true
},
handleCreate(){
this.dialogStatus = 'create'
this.dialogFormVisible = true
// this.$nextTick(() => {
// this.$refs['dataForm'].clearValidate()
// })
},
createData(){
this.$refs['dataForm'].validate((valid) => {
if (valid) {
createChannel(this.temp).then(() => {
this.dialogFormVisible = false
this.$notify({
title: 'Success',
message: 'Created Successfully',
type: 'success',
duration: 2000
})
})
}
})
},
updateData(){
this.$refs['dataForm'].validate((valid)=>{
console.log("------", this.temp)
if(valid){
const tempData = Object.assign({}, this.temp)
console.log("------",tempData)
updateChannel(tempData).then(()=>{
for(const v of this.list){
if(v.id === this.temp.id){
const index = this.list.indexOf(v)
this.list.splice(index,1, this.temp)
break
}
}
this.dialogFormVisible = false
this.$notify({
title: 'Success',
message: 'Update Successfully',
type: 'success',
duration: 2000
})
})
}
})
}
},
}
</script>
<style lang="scss" scoped>
.filter-container {
padding-bottom: 10px;
.filter-item {
display: inline-block;
vertical-align: middle;
margin-bottom: 10px;
}
}
</style>