|
|
@@ -43,12 +43,11 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
- <!-- 肩高 -->
|
|
|
+ <!-- 手机号 -->
|
|
|
<view class="formItem">
|
|
|
- <text class="formLabel">肩高(地面到肩膀的高度)</text>
|
|
|
+ <text class="formLabel">手机号</text>
|
|
|
<view class="inputWrap">
|
|
|
- <input class="formInput" v-model="form.shoulderHeight" type="digit" placeholder="例如:135" placeholder-class="pholder" />
|
|
|
- <text class="unitTxt">cm</text>
|
|
|
+ <input class="formInput" v-model="form.phone" type="number" placeholder="请输入手机号" placeholder-class="pholder" maxlength="11" />
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
@@ -61,6 +60,15 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
+ <!-- 身高 -->
|
|
|
+ <view class="formItem">
|
|
|
+ <text class="formLabel">身高</text>
|
|
|
+ <view class="inputWrap">
|
|
|
+ <input class="formInput" v-model="form.height" type="digit" placeholder="例如:175" placeholder-class="pholder" />
|
|
|
+ <text class="unitTxt">cm</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
<!-- 体重 -->
|
|
|
<view class="formItem">
|
|
|
<text class="formLabel">体重</text>
|
|
|
@@ -70,6 +78,24 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
+ <!-- 身长/坐高 -->
|
|
|
+ <view class="formItem">
|
|
|
+ <text class="formLabel">坐高(坐姿时头顶到坐面的高度)</text>
|
|
|
+ <view class="inputWrap">
|
|
|
+ <input class="formInput" v-model="form.bodyHeight" type="digit" placeholder="例如:85" placeholder-class="pholder" />
|
|
|
+ <text class="unitTxt">cm</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 脊柱长度 -->
|
|
|
+ <view class="formItem">
|
|
|
+ <text class="formLabel">C7-S4 脊柱长度</text>
|
|
|
+ <view class="inputWrap">
|
|
|
+ <input class="formInput" v-model="form.spineLength" type="digit" placeholder="例如:48" placeholder-class="pholder" />
|
|
|
+ <text class="unitTxt">cm</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
<!-- 保存按钮 -->
|
|
|
<view class="saveBtn" @click="onSave">
|
|
|
<text class="saveTxt">保存</text>
|
|
|
@@ -85,6 +111,7 @@
|
|
|
|
|
|
<script>
|
|
|
import ayToast from '@/components/ay-toast/ay-toast.nvue'
|
|
|
+import { addGroupMember, updateGroupMember, getGroupMembers } from '@/utils/api/group.js'
|
|
|
|
|
|
export default {
|
|
|
components: {
|
|
|
@@ -94,14 +121,18 @@ export default {
|
|
|
return {
|
|
|
statusBarHeight: 44,
|
|
|
mode: 'add', // add / edit
|
|
|
- userId: '',
|
|
|
+ groupId: '',
|
|
|
+ profileId: '',
|
|
|
form: {
|
|
|
name: '',
|
|
|
gender: 1,
|
|
|
age: '',
|
|
|
- shoulderHeight: '',
|
|
|
+ phone: '',
|
|
|
shoulderWidth: '',
|
|
|
- weight: ''
|
|
|
+ height: '',
|
|
|
+ weight: '',
|
|
|
+ bodyHeight: '',
|
|
|
+ spineLength: ''
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
@@ -109,8 +140,9 @@ export default {
|
|
|
const sysInfo = uni.getSystemInfoSync()
|
|
|
this.statusBarHeight = sysInfo.statusBarHeight || 44
|
|
|
this.mode = options.mode || 'add'
|
|
|
- this.userId = options.userId || ''
|
|
|
- if (this.mode === 'edit' && this.userId) {
|
|
|
+ this.groupId = options.groupId || ''
|
|
|
+ this.profileId = options.profileId || ''
|
|
|
+ if (this.mode === 'edit' && this.profileId) {
|
|
|
this.loadUserData()
|
|
|
}
|
|
|
},
|
|
|
@@ -118,96 +150,61 @@ export default {
|
|
|
goBack() {
|
|
|
uni.navigateBack()
|
|
|
},
|
|
|
- /** 加载编辑数据 */
|
|
|
- loadUserData() {
|
|
|
- const list = uni.getStorageSync('user_manage_list') || []
|
|
|
- const user = list.find(u => u.id === this.userId)
|
|
|
- if (user) {
|
|
|
- this.form.name = user.name || ''
|
|
|
- this.form.gender = user.gender || 1
|
|
|
- this.form.age = user.age ? String(user.age) : ''
|
|
|
- this.form.shoulderHeight = user.shoulderHeight ? String(user.shoulderHeight) : ''
|
|
|
- this.form.shoulderWidth = user.shoulderWidth ? String(user.shoulderWidth) : ''
|
|
|
- this.form.weight = user.weight ? String(user.weight) : ''
|
|
|
+ /** 加载编辑数据 - 从后端获取群组成员列表中查找当前成员 */
|
|
|
+ async loadUserData() {
|
|
|
+ try {
|
|
|
+ const list = await getGroupMembers(this.groupId)
|
|
|
+ const user = (list || []).find(u => String(u.profileId) === String(this.profileId))
|
|
|
+ if (user) {
|
|
|
+ this.form.name = user.name || ''
|
|
|
+ this.form.gender = user.gender || 1
|
|
|
+ this.form.age = user.age ? String(user.age) : ''
|
|
|
+ this.form.phone = user.phone || ''
|
|
|
+ this.form.shoulderWidth = user.shoulderWidth ? String(user.shoulderWidth) : ''
|
|
|
+ this.form.height = user.height ? String(user.height) : ''
|
|
|
+ this.form.weight = user.weight ? String(user.weight) : ''
|
|
|
+ this.form.bodyHeight = user.bodyHeight ? String(user.bodyHeight) : ''
|
|
|
+ this.form.spineLength = user.spineLength ? String(user.spineLength) : ''
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error('加载用户数据失败:', e)
|
|
|
}
|
|
|
},
|
|
|
/** 校验并保存 */
|
|
|
- onSave() {
|
|
|
- // 校验
|
|
|
+ async onSave() {
|
|
|
+ // 校验姓名
|
|
|
if (!this.form.name.trim()) {
|
|
|
this.$refs.ayToast.error('请输入姓名')
|
|
|
return
|
|
|
}
|
|
|
- const height = Number(this.form.shoulderHeight)
|
|
|
- if (!height || height < 50 || height > 250) {
|
|
|
- this.$refs.ayToast.error('肩高范围为50-250cm')
|
|
|
- return
|
|
|
- }
|
|
|
- const width = Number(this.form.shoulderWidth)
|
|
|
- if (!width || width < 20 || width > 80) {
|
|
|
- this.$refs.ayToast.error('肩宽范围为20-80cm')
|
|
|
- return
|
|
|
- }
|
|
|
- const weight = Number(this.form.weight)
|
|
|
- if (!weight || weight < 10 || weight > 300) {
|
|
|
- this.$refs.ayToast.error('体重范围为10-300kg')
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
- let list = uni.getStorageSync('user_manage_list') || []
|
|
|
+ // 构建请求参数
|
|
|
+ const params = {
|
|
|
+ name: this.form.name.trim(),
|
|
|
+ gender: this.form.gender
|
|
|
+ }
|
|
|
+ if (this.form.age) params.age = Number(this.form.age)
|
|
|
+ if (this.form.phone) params.phone = this.form.phone
|
|
|
+ if (this.form.shoulderWidth) params.shoulderWidth = Number(this.form.shoulderWidth)
|
|
|
+ if (this.form.height) params.height = Number(this.form.height)
|
|
|
+ if (this.form.weight) params.weight = Number(this.form.weight)
|
|
|
+ if (this.form.bodyHeight) params.bodyHeight = Number(this.form.bodyHeight)
|
|
|
+ if (this.form.spineLength) params.spineLength = Number(this.form.spineLength)
|
|
|
|
|
|
- if (this.mode === 'add') {
|
|
|
- // 再次检查是否超过10个
|
|
|
- if (list.length >= 10) {
|
|
|
- this.$refs.ayToast.error('最多可添加10个用户')
|
|
|
- return
|
|
|
- }
|
|
|
- const newUser = {
|
|
|
- id: 'user_' + Date.now() + '_' + Math.random().toString(36).substr(2, 6),
|
|
|
- name: this.form.name.trim(),
|
|
|
- gender: this.form.gender,
|
|
|
- age: Number(this.form.age) || 0,
|
|
|
- shoulderHeight: height,
|
|
|
- shoulderWidth: width,
|
|
|
- weight: weight,
|
|
|
- createTime: Date.now()
|
|
|
- }
|
|
|
- list.push(newUser)
|
|
|
- uni.setStorageSync('user_manage_list', list)
|
|
|
- // 如果是第一个用户,自动设为当前用户
|
|
|
- if (list.length === 1) {
|
|
|
- uni.setStorageSync('current_manage_user_id', newUser.id)
|
|
|
- uni.setStorageSync('current_manage_user', newUser)
|
|
|
+ try {
|
|
|
+ if (this.mode === 'add') {
|
|
|
+ await addGroupMember(this.groupId, params)
|
|
|
+ this.$refs.ayToast.success('添加成功')
|
|
|
+ } else {
|
|
|
+ await updateGroupMember(this.groupId, this.profileId, params)
|
|
|
+ this.$refs.ayToast.success('保存成功')
|
|
|
}
|
|
|
- this.$refs.ayToast.success('添加成功')
|
|
|
- } else {
|
|
|
- // 编辑模式
|
|
|
- const index = list.findIndex(u => u.id === this.userId)
|
|
|
- if (index === -1) {
|
|
|
- this.$refs.ayToast.error('用户信息已过期,请刷新')
|
|
|
- return
|
|
|
- }
|
|
|
- list[index] = {
|
|
|
- ...list[index],
|
|
|
- name: this.form.name.trim(),
|
|
|
- gender: this.form.gender,
|
|
|
- age: Number(this.form.age) || 0,
|
|
|
- shoulderHeight: height,
|
|
|
- shoulderWidth: width,
|
|
|
- weight: weight
|
|
|
- }
|
|
|
- uni.setStorageSync('user_manage_list', list)
|
|
|
- // 如果编辑的是当前用户,更新当前用户缓存
|
|
|
- const curId = uni.getStorageSync('current_manage_user_id')
|
|
|
- if (curId === this.userId) {
|
|
|
- uni.setStorageSync('current_manage_user', list[index])
|
|
|
- }
|
|
|
- this.$refs.ayToast.success('保存成功')
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.navigateBack()
|
|
|
+ }, 800)
|
|
|
+ } catch (e) {
|
|
|
+ console.error('保存失败:', e)
|
|
|
}
|
|
|
-
|
|
|
- setTimeout(() => {
|
|
|
- uni.navigateBack()
|
|
|
- }, 800)
|
|
|
}
|
|
|
}
|
|
|
}
|