form-dialog.vue
8.58 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<template>
<el-dialog
:title="isEdit ? '编辑归属设置' : '新增归属设置'"
:visible.sync="visible"
width="600px"
:close-on-click-modal="false"
@close="handleClose"
>
<el-form
ref="form"
:model="form"
:rules="rules"
label-width="120px"
label-position="right"
>
<el-form-item label="门店" prop="storeId">
<el-select
v-model="form.storeId"
placeholder="请选择门店"
style="width: 100%"
clearable
filterable
>
<el-option
v-for="store in storeList"
:key="store.id"
:label="store.fullName"
:value="store.id"
/>
</el-select>
</el-form-item>
<el-form-item label="年份" prop="year">
<el-date-picker
v-model="form.year"
type="year"
placeholder="请选择年份"
format="yyyy"
value-format="yyyy"
style="width: 100%"
/>
</el-form-item>
<el-form-item label="月份" prop="month">
<el-date-picker
v-model="form.month"
type="month"
placeholder="请选择月份"
format="yyyyMM"
value-format="yyyyMM"
style="width: 100%"
/>
</el-form-item>
<el-form-item label="大项目部老师" prop="teacherId">
<el-select
v-model="form.teacherId"
placeholder="请选择大项目部老师"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="teacher in teacherList"
:key="teacher.id"
:label="teacher.realName"
:value="teacher.id"
/>
</el-select>
</el-form-item>
<el-form-item label="教育部老师" prop="educationTeacherId">
<el-select
v-model="form.educationTeacherId"
placeholder="请选择教育部老师"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="teacher in educationTeacherList"
:key="teacher.id"
:label="teacher.realName"
:value="teacher.id"
/>
</el-select>
</el-form-item>
<el-form-item label="备注说明" prop="remark">
<el-input
v-model="form.remark"
type="textarea"
:rows="3"
placeholder="请输入备注说明"
maxlength="500"
show-word-limit
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleSubmit" :loading="submitLoading">
确定
</el-button>
</div>
</el-dialog>
</template>
<script>
import {
createMajorProjectTeacherAssignment,
updateMajorProjectTeacherAssignment,
getMajorProjectTeacherAssignmentInfo,
getTeacherList
} from '@/api/extend/majorProjectTeacherAssignment'
import { getStoreSelector } from '@/api/extend/store'
import { getUserList } from '@/api/permission/user'
export default {
name: 'MajorProjectTeacherAssignmentFormDialog',
data() {
return {
visible: false,
isEdit: false,
submitLoading: false,
form: {
storeId: '',
year: '',
month: '',
teacherId: '',
educationTeacherId: '',
remark: ''
},
rules: {
storeId: [{ required: true, message: '请选择门店', trigger: 'change' }],
year: [{ required: true, message: '请选择年份', trigger: 'change' }],
month: [{ required: true, message: '请选择月份', trigger: 'change' }],
teacherId: [
{ required: true, message: '请选择大项目部老师', trigger: 'change' }
]
},
storeList: [],
teacherList: [],
educationTeacherList: [],
editId: null
}
},
methods: {
// 打开新增弹窗
openAdd() {
this.isEdit = false
this.editId = null
this.resetForm()
this.loadStoreList()
this.loadTeacherList()
this.loadEducationTeacherList()
this.visible = true
},
// 打开编辑弹窗
async openEdit(id) {
this.isEdit = true
this.editId = id
this.resetForm()
this.loadStoreList()
this.loadTeacherList()
this.loadEducationTeacherList()
this.visible = true
try {
const response = await getMajorProjectTeacherAssignmentInfo(id)
if (response.code === 200 && response.data) {
const data = response.data
this.form = {
storeId: data.storeId || '',
year: data.year || '',
month: data.month || '',
teacherId: data.teacherId || '',
educationTeacherId: data.educationTeacherId || '',
remark: data.remark || ''
}
// 处理月份格式:从MM格式转换为yyyyMM格式(用于日期选择器)
if (this.form.year && this.form.month) {
this.form.month = `${this.form.year}${this.form.month.padStart(2, '0')}`
}
} else {
this.$message.error(response.msg || '获取详情失败')
this.visible = false
}
} catch (error) {
console.error('获取详情失败:', error)
this.$message.error('获取详情失败')
this.visible = false
}
},
// 重置表单
resetForm() {
this.form = {
storeId: '',
year: '',
month: '',
teacherId: '',
educationTeacherId: '',
remark: ''
}
this.$nextTick(() => {
if (this.$refs.form) {
this.$refs.form.clearValidate()
}
})
},
// 加载门店列表
async loadStoreList() {
try {
const response = await getStoreSelector()
if (response.code === 200 && response.data) {
this.storeList = response.data.list || []
}
} catch (error) {
console.error('加载门店列表失败:', error)
this.storeList = []
}
},
// 加载老师列表
async loadTeacherList() {
try {
const response = await getTeacherList({
organizeId: '734725079920805125',
currentPage: 1,
pageSize: 100
})
if (response.code === 200 && response.data) {
this.teacherList = response.data.list || []
}
} catch (error) {
console.error('加载老师列表失败:', error)
this.teacherList = []
}
},
// 加载教育部老师列表
async loadEducationTeacherList() {
try {
const response = await getUserList({
organizeId: '734725010941281541',
currentPage: 1,
pageSize: 500
})
if (response.code === 200 && response.data) {
this.educationTeacherList = response.data.list || []
}
} catch (error) {
console.error('加载教育部老师列表失败:', error)
this.educationTeacherList = []
}
},
// 提交表单
handleSubmit() {
this.$refs.form.validate(async (valid) => {
if (!valid) return
// 处理月份格式:从yyyyMM格式转换为MM格式
let month = this.form.month
if (month && month.length === 6) {
month = month.substring(4, 6)
}
const submitData = {
storeId: this.form.storeId,
year: this.form.year,
month: month,
teacherId: this.form.teacherId,
educationTeacherId: this.form.educationTeacherId,
remark: this.form.remark || ''
}
this.submitLoading = true
try {
let response
if (this.isEdit) {
response = await updateMajorProjectTeacherAssignment(
this.editId,
{...submitData,id:this.editId}
)
} else {
response = await createMajorProjectTeacherAssignment(submitData)
}
if (response.code === 200) {
this.$message.success(this.isEdit ? '更新成功' : '创建成功')
this.handleClose()
this.$emit('refresh')
} else {
this.$message.error(response.msg || '操作失败')
}
} catch (error) {
console.error('提交失败:', error)
this.$message.error(error.message || '操作失败')
} finally {
this.submitLoading = false
}
})
},
// 关闭弹窗
handleClose() {
this.visible = false
this.resetForm()
}
}
}
</script>
<style lang="scss" scoped>
.dialog-footer {
text-align: right;
}
</style>