helloworld180 1 month ago
parent 7808e0d3d3
commit 8efd2b19e6

@ -77,7 +77,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="出生日期"> <el-form-item label="出生日期" prop="birthDate">
<el-date-picker <el-date-picker
v-model="currentMember.birthDate" v-model="currentMember.birthDate"
type="date" type="date"
@ -154,6 +154,9 @@ export default {
], ],
relation: [ relation: [
{ required: true, message: '请选择关系', trigger: 'change' } { required: true, message: '请选择关系', trigger: 'change' }
],
birthDate: [
{ required: true, message: '请选择出生日期', trigger: 'change' }
] ]
}, },
treeData :{ treeData :{
@ -380,12 +383,13 @@ export default {
this.currentMember.image_url = e.target.result this.currentMember.image_url = e.target.result
} }
reader.readAsDataURL(file) reader.readAsDataURL(file)
this.currentMember.file = file;
// //
// const formData = new FormData() // const formData = new FormData()
// formData.append('file', file) // formData.append('file', file)
// API... // API...
}, },
// //
async saveMember() { async saveMember() {
const isValid = await new Promise((resolve) => { const isValid = await new Promise((resolve) => {
@ -399,49 +403,18 @@ export default {
} }
try { try {
const formData = new FormData();
// FormData
formData.append('name', this.currentMember.name);
formData.append('parentId', this.currentMember.parentId);
formData.append('relation', this.currentMember.relation);
formData.append('birthDate', this.currentMember.birthDate);
formData.append('phone', this.currentMember.phone);
formData.append('isCurrentUser', this.currentMember.isCurrentUser);
// FormData
if (this.currentMember.file) {
formData.append('file', this.currentMember.file);
}
const url = this.currentMember.id ? const url = this.currentMember.id ?
`/family-tree/${this.currentMember.id}` : `/family-tree/${this.currentMember.id}` :
'/family-tree'; '/family-tree'
await request({ await request({
url, url,
method: this.currentMember.id ? 'put' : 'post', method: this.currentMember.id ? 'put' : 'post',
data: formData, data: this.currentMember
headers: { })
'Content-Type': 'multipart/form-data'
}
});
ElMessage.success('保存成功');
this.dialogVisible = false;
this.fetchTreeData();
// const url = this.currentMember.id ?
// `/family-tree/${this.currentMember.id}` :
// '/family-tree'
// await request({
// url,
// method: this.currentMember.id ? 'put' : 'post',
// data: this.currentMember
// })
// console.log(':',response) response // console.log(':',response) response
// ElMessage.success('') ElMessage.success('保存成功')
// this.dialogVisible = false this.dialogVisible = false
// this.fetchTreeData() this.fetchTreeData()
} catch (error) { } catch (error) {
console.log('新增成员失败', this.currentMember) console.log('新增成员失败', this.currentMember)
ElMessage.error('保存失败') ElMessage.error('保存失败')

Loading…
Cancel
Save