|
|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<view class="container">
|
|
|
<view class="form-container">
|
|
|
-<view class="page-title">添加家庭成员</view>
|
|
|
+<view class="page-title">{{ isEdit ? '编辑成员' : '添加家庭成员' }}</view>
|
|
|
|
|
|
<!-- 昵称(必填) -->
|
|
|
<view class="form-item required">
|
|
|
@@ -87,7 +87,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { addFamilyMember } from '../../utils/api.js'
|
|
|
+import { addFamilyMember, updateFamilyMember } from '../../utils/api.js'
|
|
|
import GenerationPicker from '../../components/GenerationPicker.vue'
|
|
|
|
|
|
export default {
|
|
|
@@ -95,6 +95,8 @@ components: { GenerationPicker },
|
|
|
data() {
|
|
|
return {
|
|
|
submitting: false,
|
|
|
+isEdit: false,
|
|
|
+editMemberId: null,
|
|
|
form: {
|
|
|
nickname: '',
|
|
|
generationLevel: '',
|
|
|
@@ -138,9 +140,17 @@ age--
|
|
|
return age >= 0 ? age + '岁' : ''
|
|
|
}
|
|
|
},
|
|
|
-onLoad() {
|
|
|
-var today = new Date()
|
|
|
-this.todayDate = today.getFullYear() + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0')
|
|
|
+onLoad(options) {
|
|
|
+ var today = new Date()
|
|
|
+ this.todayDate = today.getFullYear() + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0')
|
|
|
+ if (options && options.memberId) {
|
|
|
+ this.isEdit = true
|
|
|
+ this.editMemberId = Number(options.memberId)
|
|
|
+ if (options.nickname) this.form.nickname = decodeURIComponent(options.nickname)
|
|
|
+ if (options.gender) this.form.gender = options.gender
|
|
|
+ if (options.phone) this.form.phone = options.phone
|
|
|
+ if (options.birthday) this.form.birthday = options.birthday
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
onGenderChange(e) {
|
|
|
@@ -169,7 +179,7 @@ if (!this.form.nickname || !this.form.nickname.trim()) {
|
|
|
uni.showToast({ title: '请输入成员昵称', icon: 'none' })
|
|
|
return
|
|
|
}
|
|
|
-if (!this.$refs.generationPicker || !this.$refs.generationPicker.selectedGen) {
|
|
|
+if (!this.isEdit && (!this.$refs.generationPicker || !this.$refs.generationPicker.selectedGen)) {
|
|
|
uni.showToast({ title: '请选择辈分关系', icon: 'none' })
|
|
|
return
|
|
|
}
|
|
|
@@ -188,6 +198,22 @@ return
|
|
|
|
|
|
try {
|
|
|
this.submitting = true
|
|
|
+if (this.isEdit) {
|
|
|
+ var updatePayload = {
|
|
|
+ memberId: this.editMemberId,
|
|
|
+ nickname: this.form.nickname.trim()
|
|
|
+ }
|
|
|
+ if (this.form.gender) updatePayload.gender = this.form.gender
|
|
|
+ if (this.form.birthday) updatePayload.birthday = this.form.birthday
|
|
|
+ if (this.form.phone) updatePayload.phone = this.form.phone
|
|
|
+ var res = await updateFamilyMember(updatePayload)
|
|
|
+ if (res.code === 200) {
|
|
|
+ uni.showToast({ title: '已更新', icon: 'success' })
|
|
|
+ setTimeout(function() { uni.navigateBack() }, 1500)
|
|
|
+ } else {
|
|
|
+ uni.showToast({ title: res.message || '更新失败', icon: 'none' })
|
|
|
+ }
|
|
|
+} else {
|
|
|
var genLevel = (this.$refs.generationPicker && this.$refs.generationPicker.selectedGen) || this.form.generationLevel
|
|
|
var genPeerType = (this.$refs.generationPicker && this.$refs.generationPicker.selectedPeer) || this.form.peerType
|
|
|
var payload = {
|
|
|
@@ -219,8 +245,9 @@ setTimeout(function() { uni.navigateBack() }, 1500)
|
|
|
} else {
|
|
|
uni.showToast({ title: res.message || '添加失败', icon: 'none' })
|
|
|
}
|
|
|
+}
|
|
|
} catch (e) {
|
|
|
-uni.showToast({ title: '添加失败', icon: 'none' })
|
|
|
+uni.showToast({ title: this.isEdit ? '更新失败' : '添加失败', icon: 'none' })
|
|
|
} finally {
|
|
|
this.submitting = false
|
|
|
}
|