|
@@ -19,7 +19,7 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
-import { getChildren, verifyPassword } from '../utils/api.js'
|
|
|
|
|
|
|
+import { getChildren, verifyPassword, switchToFamilyMember } from '../utils/api.js'
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
name: 'ProfileHeader',
|
|
name: 'ProfileHeader',
|
|
@@ -78,13 +78,13 @@ export default {
|
|
|
this.doSwitchMode()
|
|
this.doSwitchMode()
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- doSwitchMode() {
|
|
|
|
|
|
|
+ async doSwitchMode() {
|
|
|
if (this.children.length === 0) {
|
|
if (this.children.length === 0) {
|
|
|
this.loadChildren()
|
|
this.loadChildren()
|
|
|
if (this.children.length === 0) {
|
|
if (this.children.length === 0) {
|
|
|
uni.showModal({
|
|
uni.showModal({
|
|
|
title: '提示',
|
|
title: '提示',
|
|
|
- content: '您还没有添加孩子,请先在家庭成员中添加',
|
|
|
|
|
|
|
+ content: '您还没有添加成员,请先在家庭成员中添加',
|
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
if (res.confirm) {
|
|
|
uni.navigateTo({ url: '/pages/profile-extra/family-members' })
|
|
uni.navigateTo({ url: '/pages/profile-extra/family-members' })
|
|
@@ -94,21 +94,51 @@ export default {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (this.children.length === 1) {
|
|
|
|
|
- this.$store.commit('switchToChild', this.children[0].id)
|
|
|
|
|
- this.role = 'child'
|
|
|
|
|
- this.isSwitchedChild = true
|
|
|
|
|
- uni.showToast({ title: '已切换为孩子模式', icon: 'success' })
|
|
|
|
|
|
|
+ // 优先显示可切换成员(不可登录成员),过滤掉可通过微信登录的成员
|
|
|
|
|
+ var switchable = this.children.filter(function(m) { return m.isSwitchable })
|
|
|
|
|
+ if (switchable.length === 0) {
|
|
|
|
|
+ uni.showToast({ title: '暂无可切换成员', icon: 'none' })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if (switchable.length === 1) {
|
|
|
|
|
+ var member = switchable[0]
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '切换确认',
|
|
|
|
|
+ content: '切换到"' + member.nickname + '"后,退出时需要输入您的密码。是否继续?',
|
|
|
|
|
+ success: async (res) => {
|
|
|
|
|
+ if (!res.confirm) return
|
|
|
|
|
+ try {
|
|
|
|
|
+ var result = await switchToFamilyMember(member.id, member.source || 'family_member')
|
|
|
|
|
+ if (result.code === 200 && result.data) {
|
|
|
|
|
+ this.$store.commit('switchToMember', {
|
|
|
|
|
+ memberId: result.data.memberId,
|
|
|
|
|
+ effectiveRole: result.data.effectiveRole
|
|
|
|
|
+ })
|
|
|
|
|
+ this.isSwitchedChild = true
|
|
|
|
|
+ this.role = result.data.effectiveRole
|
|
|
|
|
+ uni.showToast({ title: '已切换', icon: 'success' })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({ title: result.message || '切换失败', icon: 'none' })
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ uni.showToast({ title: '切换失败', icon: 'none' })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
uni.showActionSheet({
|
|
uni.showActionSheet({
|
|
|
- itemList: this.children.map(c => c.nickname),
|
|
|
|
|
|
|
+ itemList: switchable.map(function(m) { return m.nickname }),
|
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
- const selectedChild = this.children[res.tapIndex]
|
|
|
|
|
- this.$store.commit('switchToChild', selectedChild.id)
|
|
|
|
|
- this.role = 'child'
|
|
|
|
|
|
|
+ if (res.tapIndex < 0) return
|
|
|
|
|
+ var member = switchable[res.tapIndex]
|
|
|
|
|
+ this.$store.commit('switchToMember', {
|
|
|
|
|
+ memberId: member.id,
|
|
|
|
|
+ effectiveRole: member.effectiveRole
|
|
|
|
|
+ })
|
|
|
this.isSwitchedChild = true
|
|
this.isSwitchedChild = true
|
|
|
- uni.showToast({ title: `已切换为${selectedChild.nickname}模式`, icon: 'success' })
|
|
|
|
|
|
|
+ this.role = member.effectiveRole
|
|
|
|
|
+ uni.showToast({ title: '已切换', icon: 'success' })
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|