bodyParams.nvue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. export default {
  105. components: {
  106. ayToast
  107. },
  108. data() {
  109. return {
  110. statusBarHeight: 44,
  111. mode: 'add', // add / edit
  112. groupId: '',
  113. profileId: '',
  114. form: {
  115. name: '',
  116. gender: 1,
  117. age: '',
  118. phone: '',
  119. shoulderWidth: '',
  120. height: '',
  121. weight: '',
  122. bodyHeight: '',
  123. spineLength: ''
  124. }
  125. }
  126. },
  127. onLoad(options) {
  128. const sysInfo = uni.getSystemInfoSync()
  129. this.statusBarHeight = sysInfo.statusBarHeight || 44
  130. this.mode = options.mode || 'add'
  131. this.groupId = options.groupId || ''
  132. this.profileId = options.profileId || ''
  133. if (this.mode === 'edit' && this.profileId) {
  134. this.loadUserData()
  135. }
  136. },
  137. methods: {
  138. goBack() {
  139. uni.navigateBack()
  140. },
  141. /** 加载编辑数据 - 从后端获取群组成员列表中查找当前成员 */
  142. async loadUserData() {
  143. try {
  144. const list = await getGroupMembers(this.groupId)
  145. const user = (list || []).find(u => String(u.profileId) === String(this.profileId))
  146. if (user) {
  147. this.form.name = user.name || ''
  148. this.form.gender = user.gender || 1
  149. this.form.age = user.age ? String(user.age) : ''
  150. this.form.phone = user.phone || ''
  151. this.form.shoulderWidth = user.shoulderWidth ? String(user.shoulderWidth) : ''
  152. this.form.height = user.height ? String(user.height) : ''
  153. this.form.weight = user.weight ? String(user.weight) : ''
  154. this.form.bodyHeight = user.bodyHeight ? String(user.bodyHeight) : ''
  155. this.form.spineLength = user.spineLength ? String(user.spineLength) : ''
  156. }
  157. } catch (e) {
  158. console.error('加载用户数据失败:', e)
  159. }
  160. },
  161. /** 校验并保存 */
  162. async onSave() {
  163. // 校验姓名
  164. if (!this.form.name.trim()) {
  165. this.$refs.ayToast.error('请输入姓名')
  166. return
  167. }
  168. // 构建请求参数
  169. const params = {
  170. name: this.form.name.trim(),
  171. gender: this.form.gender
  172. }
  173. if (this.form.age) params.age = Number(this.form.age)
  174. if (this.form.phone) params.phone = this.form.phone
  175. if (this.form.shoulderWidth) params.shoulderWidth = Number(this.form.shoulderWidth)
  176. if (this.form.height) params.height = Number(this.form.height)
  177. if (this.form.weight) params.weight = Number(this.form.weight)
  178. if (this.form.bodyHeight) params.bodyHeight = Number(this.form.bodyHeight)
  179. if (this.form.spineLength) params.spineLength = Number(this.form.spineLength)
  180. try {
  181. if (this.mode === 'add') {
  182. await addGroupMember(this.groupId, params)
  183. this.$refs.ayToast.success('添加成功')
  184. } else {
  185. await updateGroupMember(this.groupId, this.profileId, params)
  186. this.$refs.ayToast.success('保存成功')
  187. }
  188. setTimeout(() => {
  189. uni.navigateBack()
  190. }, 800)
  191. } catch (e) {
  192. console.error('保存失败:', e)
  193. }
  194. }
  195. }
  196. }
  197. </script>
  198. <style>
  199. .page {
  200. flex: 1;
  201. position: relative;
  202. }
  203. .content-bg {
  204. position: absolute;
  205. left: 0;
  206. top: 0;
  207. width: 750rpx;
  208. height: 2000px;
  209. }
  210. .pageContent {
  211. flex: 1;
  212. background-image: linear-gradient(to bottom, rgba(56,149,136,1), rgba(56,149,136,0.5));
  213. }
  214. .status-bar {
  215. background-color: rgba(0,0,0,0);
  216. }
  217. .customHead {
  218. flex-direction: row;
  219. justify-content: space-between;
  220. align-items: center;
  221. height: 88rpx;
  222. padding-left: 30rpx;
  223. padding-right: 30rpx;
  224. }
  225. .back-wrap {
  226. width: 50rpx;
  227. height: 50rpx;
  228. justify-content: center;
  229. align-items: center;
  230. }
  231. .backimg {
  232. width: 50rpx;
  233. height: 50rpx;
  234. }
  235. .customTitle {
  236. font-weight: bold;
  237. font-size: 32rpx;
  238. color: #FFFFFF;
  239. }
  240. .placeholder {
  241. width: 50rpx;
  242. }
  243. .tipTxt {
  244. font-size: 24rpx;
  245. color: rgba(255,255,255,0.7);
  246. margin-left: 38rpx;
  247. margin-top: 10rpx;
  248. margin-bottom: 20rpx;
  249. }
  250. .formArea {
  251. flex: 1;
  252. }
  253. .formInner {
  254. padding-left: 30rpx;
  255. padding-right: 30rpx;
  256. }
  257. .formItem {
  258. background-color: #FFFFFF;
  259. border-radius: 16rpx;
  260. padding: 28rpx;
  261. margin-bottom: 20rpx;
  262. }
  263. .formLabel {
  264. font-size: 26rpx;
  265. color: #9BA5B7;
  266. margin-bottom: 16rpx;
  267. }
  268. .inputWrap {
  269. flex-direction: row;
  270. align-items: center;
  271. background-color: #F5F7FA;
  272. border-radius: 12rpx;
  273. padding-left: 20rpx;
  274. padding-right: 20rpx;
  275. height: 80rpx;
  276. }
  277. .formInput {
  278. flex: 1;
  279. font-size: 30rpx;
  280. color: #333333;
  281. }
  282. .unitTxt {
  283. font-size: 26rpx;
  284. color: #9BA5B7;
  285. margin-left: 10rpx;
  286. }
  287. .genderRow {
  288. flex-direction: row;
  289. }
  290. .genderBtn {
  291. width: 160rpx;
  292. height: 72rpx;
  293. border-radius: 36rpx;
  294. background-color: #F5F7FA;
  295. justify-content: center;
  296. align-items: center;
  297. margin-right: 24rpx;
  298. }
  299. .genderActive {
  300. background-color: #389588;
  301. }
  302. .genderTxt {
  303. font-size: 28rpx;
  304. }
  305. .saveBtn {
  306. background-color: #389588;
  307. border-radius: 44rpx;
  308. height: 88rpx;
  309. justify-content: center;
  310. align-items: center;
  311. margin-top: 30rpx;
  312. margin-left: 20rpx;
  313. margin-right: 20rpx;
  314. }
  315. .saveTxt {
  316. font-size: 32rpx;
  317. color: #FFFFFF;
  318. font-weight: bold;
  319. }
  320. .bottomSpace {
  321. height: 60rpx;
  322. }
  323. </style>