bodyParams.nvue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="page">
  3. <image class="content-bg" src="/static/device/devicebg.png" mode="scaleToFill"></image>
  4. <view class="pageContent">
  5. <view class="status-bar" :style="{height: statusBarHeight + 'px'}"></view>
  6. <view class="customHead">
  7. <view class="back-wrap" @click="goBack">
  8. <image src="/static/public/back.png" mode="aspectFill" class="backimg"></image>
  9. </view>
  10. <text class="customTitle">体形参数</text>
  11. <view class="placeholder"></view>
  12. </view>
  13. <text class="tipTxt">请录入体形参数,用于精准定位穴位</text>
  14. <scroll-view class="formArea" scroll-y="true">
  15. <view class="formInner">
  16. <!-- 用户姓名 -->
  17. <view class="formItem">
  18. <text class="formLabel">姓名</text>
  19. <view class="inputWrap">
  20. <input class="formInput" v-model="form.name" placeholder="请输入姓名" placeholder-class="pholder" maxlength="10" />
  21. </view>
  22. </view>
  23. <!-- 性别 -->
  24. <view class="formItem">
  25. <text class="formLabel">性别</text>
  26. <view class="genderRow">
  27. <view class="genderBtn" :class="{'genderActive': form.gender === 1}" @click="form.gender = 1">
  28. <text class="genderTxt" :style="{color: form.gender === 1 ? '#FFFFFF' : '#545F71'}">男</text>
  29. </view>
  30. <view class="genderBtn" :class="{'genderActive': form.gender === 2}" @click="form.gender = 2">
  31. <text class="genderTxt" :style="{color: form.gender === 2 ? '#FFFFFF' : '#545F71'}">女</text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 年龄 -->
  36. <view class="formItem">
  37. <text class="formLabel">年龄</text>
  38. <view class="inputWrap">
  39. <input class="formInput" v-model="form.age" type="number" placeholder="例如:28" placeholder-class="pholder" maxlength="3" />
  40. <text class="unitTxt">岁</text>
  41. </view>
  42. </view>
  43. <!-- 手机号 -->
  44. <view class="formItem">
  45. <text class="formLabel">手机号</text>
  46. <view class="inputWrap">
  47. <input class="formInput" v-model="form.phone" type="number" placeholder="请输入手机号" placeholder-class="pholder" maxlength="11" />
  48. </view>
  49. </view>
  50. <!-- 肩宽 -->
  51. <view class="formItem">
  52. <text class="formLabel">肩宽(两肩之间的宽度)</text>
  53. <view class="inputWrap">
  54. <input class="formInput" v-model="form.shoulderWidth" type="digit" placeholder="例如:42" placeholder-class="pholder" />
  55. <text class="unitTxt">cm</text>
  56. </view>
  57. </view>
  58. <!-- 身高 -->
  59. <view class="formItem">
  60. <text class="formLabel">身高</text>
  61. <view class="inputWrap">
  62. <input class="formInput" v-model="form.height" type="digit" placeholder="例如:175" placeholder-class="pholder" />
  63. <text class="unitTxt">cm</text>
  64. </view>
  65. </view>
  66. <!-- 体重 -->
  67. <view class="formItem">
  68. <text class="formLabel">体重</text>
  69. <view class="inputWrap">
  70. <input class="formInput" v-model="form.weight" type="digit" placeholder="例如:65" placeholder-class="pholder" />
  71. <text class="unitTxt">kg</text>
  72. </view>
  73. </view>
  74. <!-- 身长/坐高 -->
  75. <view class="formItem">
  76. <text class="formLabel">坐高(坐姿时头顶到坐面的高度)</text>
  77. <view class="inputWrap">
  78. <input class="formInput" v-model="form.bodyHeight" type="digit" placeholder="例如:85" placeholder-class="pholder" />
  79. <text class="unitTxt">cm</text>
  80. </view>
  81. </view>
  82. <!-- 脊柱长度 -->
  83. <view class="formItem">
  84. <text class="formLabel">C7-S4 脊柱长度</text>
  85. <view class="inputWrap">
  86. <input class="formInput" v-model="form.spineLength" type="digit" placeholder="例如:48" placeholder-class="pholder" />
  87. <text class="unitTxt">cm</text>
  88. </view>
  89. </view>
  90. <!-- 保存按钮 -->
  91. <view class="saveBtn" @click="onSave">
  92. <text class="saveTxt">保存</text>
  93. </view>
  94. <view class="bottomSpace"></view>
  95. </view>
  96. </scroll-view>
  97. </view>
  98. <ay-toast ref="ayToast" />
  99. </view>
  100. </template>
  101. <script>
  102. import ayToast from '@/components/ay-toast/ay-toast.nvue'
  103. import { addGroupMember, updateGroupMember, getGroupMembers } from '@/utils/api/group.js'
  104. import { getProfile, updateProfile } from '@/utils/api/user.js'
  105. export default {
  106. components: {
  107. ayToast
  108. },
  109. data() {
  110. return {
  111. statusBarHeight: 44,
  112. mode: 'add', // add / edit
  113. source: '', // '' = group member, 'profile' = current user profile
  114. groupId: '',
  115. profileId: '',
  116. form: {
  117. name: '',
  118. gender: 1,
  119. age: '',
  120. phone: '',
  121. shoulderWidth: '',
  122. height: '',
  123. weight: '',
  124. bodyHeight: '',
  125. spineLength: ''
  126. }
  127. }
  128. },
  129. onLoad(options) {
  130. const sysInfo = uni.getSystemInfoSync()
  131. this.statusBarHeight = sysInfo.statusBarHeight || 44
  132. this.mode = options.mode || 'add'
  133. this.source = options.source || ''
  134. this.groupId = options.groupId || ''
  135. this.profileId = options.profileId || ''
  136. if (this.source === 'profile') {
  137. // 公共设备:加载当前账号个人资料
  138. this.loadProfileData()
  139. } else if (this.mode === 'edit' && this.profileId) {
  140. this.loadUserData()
  141. }
  142. },
  143. methods: {
  144. goBack() {
  145. uni.navigateBack()
  146. },
  147. /** 加载个人资料数据(公共设备模式) */
  148. async loadProfileData() {
  149. try {
  150. const profile = await getProfile()
  151. if (profile) {
  152. this.form.name = profile.name || ''
  153. this.form.gender = profile.gender || 1
  154. this.form.age = profile.age ? String(profile.age) : ''
  155. this.form.phone = profile.phone || ''
  156. this.form.shoulderWidth = profile.shoulderWidth ? String(profile.shoulderWidth) : ''
  157. this.form.height = profile.height ? String(profile.height) : ''
  158. this.form.weight = profile.weight ? String(profile.weight) : ''
  159. this.form.bodyHeight = profile.bodyHeight ? String(profile.bodyHeight) : ''
  160. this.form.spineLength = profile.spineLength ? String(profile.spineLength) : ''
  161. }
  162. } catch (e) {
  163. console.error('加载个人资料失败:', e)
  164. }
  165. },
  166. /** 加载编辑数据 - 从后端获取群组成员列表中查找当前成员 */
  167. async loadUserData() {
  168. try {
  169. const list = await getGroupMembers(this.groupId)
  170. const user = (list || []).find(u => String(u.profileId) === String(this.profileId))
  171. if (user) {
  172. this.form.name = user.name || ''
  173. this.form.gender = user.gender || 1
  174. this.form.age = user.age ? String(user.age) : ''
  175. this.form.phone = user.phone || ''
  176. this.form.shoulderWidth = user.shoulderWidth ? String(user.shoulderWidth) : ''
  177. this.form.height = user.height ? String(user.height) : ''
  178. this.form.weight = user.weight ? String(user.weight) : ''
  179. this.form.bodyHeight = user.bodyHeight ? String(user.bodyHeight) : ''
  180. this.form.spineLength = user.spineLength ? String(user.spineLength) : ''
  181. }
  182. } catch (e) {
  183. console.error('加载用户数据失败:', e)
  184. }
  185. },
  186. /** 校验并保存 */
  187. async onSave() {
  188. // 校验姓名
  189. if (!this.form.name.trim()) {
  190. this.$refs.ayToast.error('请输入姓名')
  191. return
  192. }
  193. // 构建请求参数
  194. const params = {
  195. name: this.form.name.trim(),
  196. gender: this.form.gender
  197. }
  198. if (this.form.age) params.age = Number(this.form.age)
  199. if (this.form.phone) params.phone = this.form.phone
  200. if (this.form.shoulderWidth) params.shoulderWidth = Number(this.form.shoulderWidth)
  201. if (this.form.height) params.height = Number(this.form.height)
  202. if (this.form.weight) params.weight = Number(this.form.weight)
  203. if (this.form.bodyHeight) params.bodyHeight = Number(this.form.bodyHeight)
  204. if (this.form.spineLength) params.spineLength = Number(this.form.spineLength)
  205. try {
  206. if (this.source === 'profile') {
  207. // 公共设备:调用修改个人资料接口
  208. await updateProfile(params)
  209. this.$refs.ayToast.success('保存成功')
  210. } else if (this.mode === 'add') {
  211. await addGroupMember(this.groupId, params)
  212. this.$refs.ayToast.success('添加成功')
  213. } else {
  214. await updateGroupMember(this.groupId, this.profileId, params)
  215. this.$refs.ayToast.success('保存成功')
  216. }
  217. setTimeout(() => {
  218. uni.navigateBack()
  219. }, 800)
  220. } catch (e) {
  221. console.error('保存失败:', e)
  222. }
  223. }
  224. }
  225. }
  226. </script>
  227. <style>
  228. .page {
  229. flex: 1;
  230. position: relative;
  231. }
  232. .content-bg {
  233. position: absolute;
  234. left: 0;
  235. top: 0;
  236. width: 750rpx;
  237. height: 2000px;
  238. }
  239. .pageContent {
  240. flex: 1;
  241. background-image: linear-gradient(to bottom, rgba(56,149,136,1), rgba(56,149,136,0.5));
  242. }
  243. .status-bar {
  244. background-color: rgba(0,0,0,0);
  245. }
  246. .customHead {
  247. flex-direction: row;
  248. justify-content: space-between;
  249. align-items: center;
  250. height: 88rpx;
  251. padding-left: 30rpx;
  252. padding-right: 30rpx;
  253. }
  254. .back-wrap {
  255. width: 50rpx;
  256. height: 50rpx;
  257. justify-content: center;
  258. align-items: center;
  259. }
  260. .backimg {
  261. width: 50rpx;
  262. height: 50rpx;
  263. }
  264. .customTitle {
  265. font-weight: bold;
  266. font-size: 32rpx;
  267. color: #FFFFFF;
  268. }
  269. .placeholder {
  270. width: 50rpx;
  271. }
  272. .tipTxt {
  273. font-size: 24rpx;
  274. color: rgba(255,255,255,0.7);
  275. margin-left: 38rpx;
  276. margin-top: 10rpx;
  277. margin-bottom: 20rpx;
  278. }
  279. .formArea {
  280. flex: 1;
  281. }
  282. .formInner {
  283. padding-left: 30rpx;
  284. padding-right: 30rpx;
  285. }
  286. .formItem {
  287. background-color: #FFFFFF;
  288. border-radius: 16rpx;
  289. padding: 28rpx;
  290. margin-bottom: 20rpx;
  291. }
  292. .formLabel {
  293. font-size: 26rpx;
  294. color: #9BA5B7;
  295. margin-bottom: 16rpx;
  296. }
  297. .inputWrap {
  298. flex-direction: row;
  299. align-items: center;
  300. background-color: #F5F7FA;
  301. border-radius: 12rpx;
  302. padding-left: 20rpx;
  303. padding-right: 20rpx;
  304. height: 80rpx;
  305. }
  306. .formInput {
  307. flex: 1;
  308. font-size: 30rpx;
  309. color: #333333;
  310. }
  311. .unitTxt {
  312. font-size: 26rpx;
  313. color: #9BA5B7;
  314. margin-left: 10rpx;
  315. }
  316. .genderRow {
  317. flex-direction: row;
  318. }
  319. .genderBtn {
  320. width: 160rpx;
  321. height: 72rpx;
  322. border-radius: 36rpx;
  323. background-color: #F5F7FA;
  324. justify-content: center;
  325. align-items: center;
  326. margin-right: 24rpx;
  327. }
  328. .genderActive {
  329. background-color: #389588;
  330. }
  331. .genderTxt {
  332. font-size: 28rpx;
  333. }
  334. .saveBtn {
  335. background-color: #389588;
  336. border-radius: 44rpx;
  337. height: 88rpx;
  338. justify-content: center;
  339. align-items: center;
  340. margin-top: 30rpx;
  341. margin-left: 20rpx;
  342. margin-right: 20rpx;
  343. }
  344. .saveTxt {
  345. font-size: 32rpx;
  346. color: #FFFFFF;
  347. font-weight: bold;
  348. }
  349. .bottomSpace {
  350. height: 60rpx;
  351. }
  352. </style>