CloseReasonManagement.vue
5.02 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
<template>
<div class="close-reason-management">
<div class="toolbar">
<p class="description">管理商机关闭时可选择的原因</p>
<el-button @click="isAddDialogOpen = true" type="primary" size="small">
<i class="el-icon-plus"></i>
添加原因
</el-button>
</div>
<div class="reason-table">
<el-table :data="reasons" style="width: 100%">
<el-table-column prop="reason" label="关闭原因" width="300"></el-table-column>
<el-table-column prop="category" label="分类" width="200">
<template slot-scope="scope">
<el-tag size="mini">{{ scope.row.category }}</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="150">
<template slot-scope="scope">
<el-button
type="text"
size="small"
@click="editReason(scope.row)"
>
编辑
</el-button>
<el-button
type="text"
size="small"
@click="deleteReason(scope.row.id)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 添加/编辑原因对话框 -->
<el-dialog
:title="editingReason ? '编辑关闭原因' : '添加关闭原因'"
:visible.sync="isAddDialogOpen"
width="500px"
>
<el-form :model="reasonForm" :rules="reasonRules" ref="reasonForm" label-width="100px">
<el-form-item label="关闭原因" prop="reason">
<el-input
v-model="reasonForm.reason"
placeholder="请输入关闭原因"
></el-input>
</el-form-item>
<el-form-item label="分类" prop="category">
<el-input
v-model="reasonForm.category"
placeholder="请输入分类"
></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="isAddDialogOpen = false">取消</el-button>
<el-button type="primary" @click="submitReasonForm">确定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
// 模拟关闭原因数据
const mockCloseReasons = [
{ id: '1', reason: '客户价格不接受', category: '价格因素' },
{ id: '2', reason: '客户暂无需求', category: '需求因素' },
{ id: '3', reason: '竞品已安装', category: '竞争因素' },
{ id: '4', reason: '客户联系不上', category: '联系因素' },
{ id: '5', reason: '技术不支持', category: '技术因素' },
{ id: '6', reason: '其他原因', category: '其他' }
]
export default {
name: 'CloseReasonManagement',
data() {
return {
reasons: mockCloseReasons,
isAddDialogOpen: false,
editingReason: null,
reasonForm: {
reason: '',
category: ''
},
reasonRules: {
reason: [
{ required: true, message: '请输入关闭原因', trigger: 'blur' }
],
category: [
{ required: true, message: '请输入分类', trigger: 'blur' }
]
}
}
},
methods: {
editReason(reason) {
this.editingReason = reason
this.reasonForm = { ...reason }
this.isAddDialogOpen = true
},
deleteReason(id) {
this.$confirm('确定要删除该原因吗?此操作不可撤销。', '确认删除', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.reasons = this.reasons.filter(r => r.id !== id)
this.$message.success('关闭原因删除成功')
}).catch(() => {
// 用户取消删除
})
},
submitReasonForm() {
this.$refs.reasonForm.validate((valid) => {
if (valid) {
if (this.editingReason) {
// 更新原因信息
const index = this.reasons.findIndex(r => r.id === this.editingReason.id)
if (index !== -1) {
this.$set(this.reasons, index, { ...this.editingReason, ...this.reasonForm })
this.$message.success('关闭原因更新成功')
}
} else {
// 添加新原因
const newReason = {
...this.reasonForm,
id: `REASON${Date.now()}`
}
this.reasons.push(newReason)
this.$message.success('关闭原因添加成功')
}
// 重置表单和状态
this.resetReasonForm()
this.isAddDialogOpen = false
this.editingReason = null
}
})
},
resetReasonForm() {
this.reasonForm = {
reason: '',
category: ''
}
}
}
}
</script>
<style lang="scss" scoped>
.close-reason-management {
.toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
.description {
color: #909399;
margin: 0;
}
}
.reason-table {
margin-bottom: 20px;
}
}
</style>